// JavaScript Document
	
	/* =======================ajax===================================
		Grobal declares
	================================================================*/
	var xmlHttp
	var whichID
	var strString	
	var gCode
	var compwindow
	var count = "1";
	var lookupid


	
	//================================draw editor=====================================================================
	function drawBasicEditor(wd,ht){
		var sBasePath = document.location.href.substring(0,document.location.href.lastIndexOf('modules')) + "fckeditor/" ;
		var oFCKeditor = new FCKeditor( 'editfield' ) ;
		oFCKeditor.BasePath	= sBasePath ;
		oFCKeditor.ToolbarSet = 'Basic';
		oFCKeditor.Width	= wd ;
		oFCKeditor.Height	= ht ;
		oFCKeditor.Value	= '';
		oFCKeditor.Create() ;
		}
	/* =======================ajax===================================
		AJAX functions
	================================================================*/
	
	function ajaxGetFunction(surl,str,objID1,objID2,ref1,ref2,ref3,ref4,qStr1,qStr2,qStr3,qStr4){ 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		var url=surl;
		url=url+"?wit="+str;
		url=url+"&"+ref1+"="+qStr1
		url=url+"&"+ref2+"="+qStr2
		url=url+"&"+ref3+"="+qStr3
		url=url+"&"+ref4+"="+qStr4
		url=url+"&sid="+Math.random();
		whichID = objID1
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		document.getElementById(whichID).innerHTML="<img src='images/loading.gif' border=0> Generating Data ...";
	}
	
	function stateChanged(){ 
	if (xmlHttp.readyState==4){ 
	document.getElementById(whichID).innerHTML=xmlHttp.responseText;
	}
	}
	
	function GetXmlHttpObject()
	{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
	}
	//======================POST METHOD
	function getXMLObject()  //XML OBJECT
	{
	   var xmlHttp = false;
	   try {
		 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
	   }
	   catch (e) {
		 try {
		   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
		 }
		 catch (e2) {
		   xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
		 }
	   }
	   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
		 xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
	   }
	   return xmlHttp;  // Mandatory Statement returning the ajax object created
	}
	
	var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object
 
	function ajaxPostFunction(surl,str,objID1,sdata) {
	  var getdate = new Date();  //Used to prevent caching during ajax call
	  whichID = objID1;
	  if(xmlhttp) { 
		var txtname = document.getElementById("txtname");
		xmlhttp.open("POST",surl,true); //calling testing.php using POST method
		xmlhttp.onreadystatechange  = handleServerResponse;
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.send("wit=" + str+"||"+sdata); //Posting txtname to PHP File
	  }
	}
	 
	function handleServerResponse() {
	   if (xmlhttp.readyState == 4) {
		 if(xmlhttp.status == 200) {
		   document.getElementById(whichID).innerHTML=xmlhttp.responseText; //Update the HTML Form element 
		 }
		 else {
			alert("Error during AJAX call. Please try again");
		 }
	   }
	}
	// ==============================================end====================================================================
	//=======================================TEXT MANIPULATION =============================================================
	function doBlink() {
	  // Blink, Blink, Blink...
	  var blink = document.all.tags("BLINK")
	  for (var i=0; i < blink.length; i++)
		blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
		}
	
	function startBlink() {
	  // Make sure it is IE4
	  if (document.all)
		setInterval("doBlink()",500)
		}
		
	//========================================================VALIDATIONS===================================================
	function validateForgotAccount() {
		if (!validEmail(frmMain.txt[0],"Your email address",true)) {
		return false;
		}

		}
	function validateTell() {
		
		if (!validRequired(frmMain.name,"Your name")) {
		return false;
		}
		if (!validEmail(frmMain.email,"Your email address",true)) {
		return false;
		}
		
		if (!validEmail(frmMain.fmail1,"Friend's email address",true)) {
		return false;
		}
	//document.tellafriend.submit()
	postRequest("popup.php?linkid=sendtell")
	return true;
	}
	
	//************validate login form **************************************************************************************
	 function validateEnquiry(){
		 lblArray = Array("Your Name","Email Address","","Subject","Content")
		 var ctrl;
		 for (i=1;i<=5;i++){
			 ctrl = document.getElementById("etxt"+i)
		 	if (i!=3){
				if(i==2){
					if (!validEmail(ctrl,lblArray[i-1]))
					return false;
					}
				else{
					if (!validRequired(ctrl,lblArray[i-1]))
					return false;
					}		
		 		}
		 	}
			var arrayEnq = Array(frmMain.etxt1.value,frmMain.etxt2.value,frmMain.etxt3.value+"|"+frmMain.etxt4.value,frmMain.etxt5.value)
			frmMain.etxt1.value = ""
			frmMain.etxt2.value = ""
			frmMain.etxt3.value = ""
			frmMain.etxt4.value = ""
			frmMain.etxt5.value = ""
			ajaxGetFunction('modules/mod_ajax_1.php','enq','sendmail','','etxt1','etxt2','etxt4','etxt5',arrayEnq[0],arrayEnq[1],arrayEnq[2],arrayEnq[3])
		}
		
	//************validate login form **************************************************************************************
	 function validateRegistration(){
		 lblArray = Array("","Contact Person","","Mobile Phone","","Category","Username","Password","Confirm Password")
		 var sval="";
		 
		 for (i=0;i<frmMain.rtxt.length;i++){
				if(i==6){
					if (!validEmail(frmMain.rtxt[i],lblArray[i]))
					return false;
					}
				else if(i==4 && trimAll(frmMain.rtxt[4].value)!=""){
					if(!validateUrl(frmMain.rtxt[4]))
					return false;
				}
				else if (i!=0&&i!=2&&i!=4){
					if (!validRequired(frmMain.rtxt[i],lblArray[i]))
					return false;
					}		
		 	sval += frmMain.rtxt[i].value+"||"
			}
			if (frmMain.rtxt[7].value != frmMain.rtxt[8].value ){
				alert ("Passwords do not match.  Please re-enter.")
				frmMain.rtxt[7].focus();
				return false;
				}
			
			var oEditor = FCKeditorAPI.GetInstance('txtadd') ;
			sval += oEditor.GetXHTML(true)
			if(!MPFSValidate()){;
		 	return false;}
			//alert(sval)
			sval = URLEncode(sval)
			ajaxGetFunction('modules/mod_updates.php','preg||','cfirmation','','sval','axn','','',sval,'new','','')
		}
		
	function validateEvtRegistration(evid){
		 lblArray = Array("Contact Person","No of Participants","Name(s) of Participants","","Contact Email","Contact No.")
		 var sval="";
		 
		 for (i=0;i<frmMain.rtxt.length;i++){
				if(i==4){
					if (!validEmail(frmMain.rtxt[i],lblArray[i]))
					return false;
					}
				else if (i!=3){
					if (!validRequired(frmMain.rtxt[i],lblArray[i]))
					return false;
					}		
		 	sval += frmMain.rtxt[i].value+"||"
			}
			
			//if(!MPFSValidate()){;
		 	//return false;}
			//alert(sval)
			sval = URLEncode(sval)
			for (i=0;i<frmMain.rtxt.length;i++){frmMain.rtxt[i].value=""}
			ajaxGetFunction('modules/mod_updates.php','evtreg||','newsarea','','sval','evid','','',sval,evid,'','');
		}
	 
	 function checkForm(theForm)
		{
			// Start ------->
			if (!validRequired(theForm.Username,"Username"))
				return false;
			if (!validRequired(theForm.uPassword,"Password"))
				return false;
			ajaxGetFunction('../../admin/modules/mod_ajax_1.php','validateuser','login','','uname','pword','','',frmMain.Username.value,frmMain.uPassword.value,'','')
			// <--------- End
			return true;
		}
	//=====================================================MENU CALLS =======================================================
	function getNews($url,$linkid,$item){
		frmMain.action=$url+"?linkid="+$linkid+"&nid="+$item;
		frmMain.method="post";
		frmMain.submit();
		}
		
	function postRequest($url){
		frmMain.action=$url;
		frmMain.method="post";
		frmMain.submit();
		}	
		
	function getRequest($url){
		frmMain.action=$url+"test=test";
		frmMain.method="get";
		frmMain.submit();
		}	
	
	function callNewsItems(mth,yr){ 
		ajaxGetFunction('modules/mod_ajax_1.php','listnewsitems','newsarea','','mth','yr','','',mth,yr,'','')
	 	}
	function callEvents(mth,yr){ 
		ajaxGetFunction('modules/mod_ajax_1.php','listevents','newsarea','','mth','yr','','',mth,yr,'','')
	 	}
	//open a modal window
	function openmodal(page,iWidth,iHeight,iCaption){
		compwindow=dhtmlmodal.open('compbox', 'iframe', page, iCaption , 'width=' + iWidth + 'px,height=' + iHeight + 'px,center=1,resize=0,scrolling=1')
		
		compwindow.onclose=function(){
				return true;
			}
		}
	//open as a  normal popup
	function popupnormal(page,wd,ht){
		window.open(page,'self','width='+wd+',height='+ht+',scrollbars=yes,status=yes,resizable=yes,top=0,left=0');
		return;
		
		}
	function printPage(){
		print();
		}
	function callSearch(page,keyword){
		frmMain.action=page+"?query="+keyword+"&search=1";
		frmMain.method="post";
		frmMain.submit();
		}
	//=========================================================encode script ========================================================
	function URLEncode(clearString) {
	  var output = '';
	  var x = 0;
	  clearString = clearString.toString();
	  var regex = /(^[a-zA-Z0-9_.]*)/;
	  while (x < clearString.length) {
		var match = regex.exec(clearString.substr(x));
		if (match != null && match.length > 1 && match[1] != '') {
			output += match[1];
		  x += match[1].length;
		} else {
		  if (clearString[x] == ' ')
			output += '+';
		  else {
			var charCode = clearString.charCodeAt(x);
			var hexVal = charCode.toString(16);
			output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
		  }
		  x++;
		}
	  }
	  return output;
	}
	
	//=====================================STRING MANIPULATION===============================================================
	function resetSearch(){
		if(trimAll(frmMain.sitesearch.value) == "")
		frmMain.sitesearch.value = "search ..."
		}
	function clearSearchBox(){
		if(frmMain.sitesearch.value == "search ...")
			frmMain.sitesearch.value = ""
		}
	function trimAll(sString){
		while (sString.substring(0,1) == ' '){
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' '){
			sString = sString.substring(0,sString.length-1);
		}
		return sString;
	}
	
	function highlight(syr,intI,yr,axn){
		var yrs = ""
		var colid = ""
		//<a href="javascript:alert('<?php echo gmdate("Y")?>')"><?php echo gmdate('Y',$year);?></a
		for (i=0;i<6;i++){
			yrs = Number(syr)+i
			if (Number(yrs) == Number(yr)) {
				tdid[i].style.background = "#cccccc"
				tdid[i].innerHTML = yr
				}
			else{
				tdid[i].style.background = '';
				tdid[i].innerHTML = "<a class='mainnews' href=\"javascript:highlight('"+syr+"','"+intI+"','"+yrs+"','"+axn+"')\">"+yrs+"</a>"
				}
			}
			newsarea.innerHTML = ""
			ajaxGetFunction('modules/mod_ajax_1.php',axn,'mths','','yr','','','',yr,'','','')
		}
		
	function validateListLogin(ctrl1,ctrl2,axn){
		if (!validEmail(ctrl1,"Email",true))
		return false;
		if (!validRequired(ctrl2,"Password"))
		return false;
		postRequest("main.php?linkid="+axn)
		}
		
		
	function forgotPassword(){
		if (!validEmail(frmMain.txtlst1,"Email"))
		return false;
		ajaxGetFunction("modules/mod_ajax_1.php","getpword","sent","","email","","","",frmMain.txtlst1.value,"","","");
		//postRequest("property.php?linkid=pf")
		}