/*-------------------------------------------------------------------
general.js
For CentreMapsLive Ver. 2
General cross page scripts
Lovell Jonhs Ltd.
01/01/10
//------------------------------------------------------------------*/

//-------------------------------------------------------------------------GENERAL SCRIPTS

//************************Removes leading and trailing spaces from the passed string.
function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while ((ch == " ") || (ch.charCodeAt(0) == 9)) { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while ((ch == " ") || (ch.charCodeAt(0) == 9)) { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   //Remove return/new line characters from front of string
   var testCode = retValue.charCodeAt(0);
   var testCode2 = retValue.charCodeAt(1);
   if((testCode == "13") || (testCode2 == 10)){
   		retValue = retValue.substring(2, retValue.length);
   }
   return retValue;
} 
//****************Stop a form being submitted when enter is pressed
function checkEnter(e){
	evt = e || window.event;
	var characterCode = evt.keyCode? evt.keyCode : evt.charCode
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		return false; 
	}else{
		return true;
	}
}
//******************Stores if the shift key is pressed down - used in drawing circles and rectangle anno elements
function keyPressDown(e){
	evt = e || window.event;
	if(evt.shiftKey){
		shiftIsDown = true;		
		if(document.varform.selectedTool.value == "drawcircle"){
			drawAnnoCircleControl.activate();
			drawAnnoLabelControl.deactivate();
		}else if(document.varform.selectedTool.value == "drawrect"){
			drawAnnoRectControl.activate();
			drawAnnoLabelControl.deactivate();
		}
	}	
}
function keyReleased(e){
	shiftIsDown = false;
}
//******************Submits text box when return key pressed
function submitIt(theControl,e){		
	//Check if a return has been pressed to submit a textbox	
	evt = e || window.event;
	var unicode=evt.keyCode? evt.keyCode : evt.charCode
	if(unicode == 13){
		if(is_chrome){
			return false;
		}else{
			if(theControl == "login"){				//Run login
				runLogin('in');	
			}else if(theControl == "search"){			//Run the search
				showSearchOptions();
			}
			return true;
		}	
	}
}
//****************Goto user's home page
function goToHome(){
	document.varform.action = "account_home.php";
	document.varform.submit();
}
//****************Run Logout - called from all pages except the main map page
function runLogout(){	
	var qstring = "name=&pwd=&login=out&type=normal";		
	var logoutReq = new ajaxObject('runlogin.php', logoutResponse);
	logoutReq.update(qstring,'POST');	
}
//****************Response from running the logout
function logoutResponse(responseText, responseStatus){
	if(responseStatus == 200){	
		//Get the returned values
		if(responseText != ""){
			var tempArray = new Array();
			tempArray = responseText.split("|");	
			if(tempArray[0] == "ok"){								
				submittheform('ordergb');		//Go back to home page							
			}
		}
	}
}
//****************Run Cufon styling
function callCufon(){
	Cufon.replace("h1");
	Cufon.replace('h1', { fontWeight: 'bold', fontSize: '18px', color: '#24318D'}); 
	Cufon.replace("h2");
	Cufon.replace('h2', { fontWeight: 'bold', fontSize: '16px', color: '#24318D'}); 
	Cufon.replace("h3");
	Cufon.replace('h3', { fontWeight: 'bold', fontSize: '14px', color: '#24318D'});  
	Cufon.replace("h4");
	Cufon.replace('h4', { fontWeight: 'bold', fontSize: '11px', color: '#ED0489'});  //lineHeight: '30px'  pink '#ED0489'
	Cufon.replace("h5");
	Cufon.replace('h5', { fontWeight: 'bold', fontSize: '10px', color: '#24318D'});  	
	Cufon.now();
}

//-------------------------------------------------End of file.
