//--------------------------------------------------------
//general.js
//CentreMaps
//Lovell Johns Ltd.
//Code for linking to info pages and showing help
//and submitting forms
//--------------------------------------------------------

//Define the main map page to use based on the user's screen resolution
if ((screen.width>=1280) && (screen.height>=1020)){
	var mapToUse = "map2.php";
}else if ((screen.width>=1024) && (screen.height>=768)){
	var mapToUse = "map1.php";
}else{
  	var mapToUse = "map.php";
}
//Ensure the 'mapToUse' variable agrees with the map page that is showing
var currentLoc = String(window.location);
if((currentLoc.indexOf("map.php") != -1) && (mapToUse != "map.php")){
	var mapToUse = "map.php";
}
if((currentLoc.indexOf("map1.php") != -1) && (mapToUse != "map1.php")){
	var mapToUse = "map1.php";
} 
if((currentLoc.indexOf("map2.php") != -1) && (mapToUse != "map2.php")){
	var mapToUse = "map2.php";
} 

//-------------------------------------------------------------------------SHOW HELP SCRIPTS
//****************Display the help info in a new window
function getHelp(theAnchor){
	if (theAnchor == 1){
		theURL = "http://www.centremapslive.co.uk/page/finding_your_area_of_interest";
	}else if (theAnchor == 2){
		theURL = "http://www.centremapslive.co.uk/page/selecting_your_product";
	}else if (theAnchor == 3){
		theURL = "http://www.centremapslive.co.uk/page/selecting_the_coverage_that_your_product_will_show";
	}else if (theAnchor == 4){
		theURL = "http://www.centremapslive.co.uk/page/adding_overlay_information_to_your_product";
	}
	winName =  "help";  
	features = "menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=630,height=500";
	window.open(theURL,winName,features);
}

//****************Display the quick help info on the confirm page
function getquickhelp(evt,theSubject,theAction){
	//Get the layer
	if(is_nav6up){										//Navigator6/Firefox
		var layer = document.getElementById(theSubject);											
	}else{													//Opera/IE			
		var layer = eval('document.all.' + theSubject + '.style');  						
	}
	//Turn on-off	
	if(theAction == "on"){
		if(is_nav6up){
			layer.style.visibility = "visible";
			var toAdd = document.body.scrollTop;
			layer.style.left = Number(evt.clientX) - 80 + "px"; 
			layer.style.top  = Number(evt.clientY) + Number(toAdd) - 50 + "px";
		}else{
			layer.visibility = "visible";
			var toAdd = document.body.scrollTop;
			layer.left = Number(evt.clientX) - 80 + "px"; 
			layer.top  = Number(evt.clientY) + Number(toAdd) - 50 + "px";
		}						
	}else{
		if(is_nav6up){
			layer.style.visibility = "hidden";
		}else{
			layer.visibility = "hidden";
		}	
	}
}

//*******************Opens a new window
function openNew(theURL){
	//Define the URL
	if(theURL == "overlay_info"){
		theURL = "http://www.centremapslive.co.uk/page/mapping_overlay_information_examples";
	}else if(theURL == "format_info"){
		theURL = "http://www.centremapslive.co.uk/page/choosing_the_right_product#format";
	}else if(theURL == "lic_info"){
		theURL = "http://www.centremapslive.co.uk/page/licences";
	}else if(theURL == "terms"){ 
		theURL = "http://www.centremapslive.co.uk/files/cml_data_licence_01072007.pdf";	
	}else if(theURL == "home"){
		theURL = "http://www.centremapslive.co.uk";
	}else{	
		var theURL = theURL + ".php";
	}
	
	var winName =  "newwindow";
	var features = "toolbar=no,scrollbars=yes,resizable=yes,width=600,height=300";
	window.open(theURL,winName,features);
}

//-------------------------------------------------------------------------SUBMITTING FORMS
//*******************Code to submit the variables Form
function submittheform(theAction){

	// Define where the submit action has bee invoked from
	if(theAction == "order"){
		document.varform.action = mapToUse; 		//Set the map page to use "map" - normal, "map1" - medium res, "map2" - high res
		document.varform.interface.value = "basic";
		document.varform.region.value = "gb";
		document.varform.submit();
		
	}else if(theAction == "orderplusgb"){
		document.varform.action = mapToUse; 		//Set the map page to use "map" - normal, "map1" - medium res, "map2" - high res
		document.varform.interface.value = "advanced";
		document.varform.region.value = "gb";
		document.varform.submit();	
	}else if(theAction == "orderplusni"){
		document.varform.action = mapToUse; 		//Set the map page to use "map" - normal, "map1" - medium res, "map2" - high res
		document.varform.interface.value = "advanced";
		document.varform.region.value = "ni";
		document.varform.submit();	
	}else if(theAction == "reorder"){
		if(document.varform.mapsize.value != ""){
			mapToUse = document.varform.mapsize.value;
		}
		document.varform.action = mapToUse; 		//Set the map page to use "map" - normal, "map1" - medium res, "map2" - high res
		document.varform.submit();			
	}else if(theAction == "reshow"){					//Called when reshowing order from Shopping Basket
		if(document.varform.mapsize.value != ""){
			mapToUse = document.varform.mapsize.value;
		}
		document.confirmform.action = mapToUse; 		//Set the map page to use "map" - normal, "map1" - medium res, "map2" - high res
		document.confirmform.submit();			
	}else if(theAction == "confirm"){
		var test1 = document.getElementById("add");			 
		if(test1 != null){
			document.varform.add.value = "";
		}
		var test2 = document.getElementById("alter");
		if(test2 != null){
			document.varform.alter.value = "";
		}		
		document.varform.action = "basket.php";	
		document.varform.submit();
	}else if(theAction == "login"){
		document.varform.action = "login.php";	
		document.varform.submit();
	}else if(theAction == "logout"){
		document.varform.login.value = "out";
		document.varform.action = "login.php";	
		document.varform.submit();
	}else if(theAction == "resupply"){
		document.prevorderform.action = "resupply.php";
		document.prevorderform.target = "_self";
		document.prevorderform.submit();
	}else if(theAction == "user"){
		document.varform.action = "user.php";
		document.varform.submit();
	//}else if(theAction == "userorders"){
	//	document.varform.action = "userorders.php";
	//	document.varform.submit();
	//}else if(theAction == "savedorders"){
	//	document.varform.action = "usersavedorders.php";
	//	document.varform.submit();
				
	//Upadte code to used passed variable	
	}else if(theAction == "userorders2"){
		document.varform.action = "userorders2.php";
		document.varform.submit();
	}else if(theAction == "usersavedorders2"){
		document.varform.action = "usersavedorders2.php";
		document.varform.submit();			
	}else if(theAction == "user2"){
		document.varform.action = "user2.php";
		document.varform.submit();	
	}else if(theAction == "licencemanagement"){
		document.varform.action = "licencemanagement.php";
		document.varform.submit();
	}else if(theAction == "costmanagement"){
		document.varform.action = "costmanagement.php";
		document.varform.submit();
	}else if(theAction == "usermanagement"){
		document.varform.action = "usermanagement.php";
		document.varform.submit();
	}else if(theAction == "invoicing"){
		document.varform.action = "invoicing.php";
		document.varform.submit();	
		
	}else if(theAction == "companyinfo"){
		document.varform.action = "companyinfo.php";	
		document.varform.submit();	
	}else if(theAction == "newcompany"){
		document.varform.action = "newcompany.php";	
		document.varform.submit();
	}else if(theAction == "new_company"){
		document.custform.action = "new_office.php";	
		document.custform.submit();
			
	//}else if(theAction == "payments_results2"){
	//	document.varform.action = "payments_results2.php";
	//	document.varform.submit();
	
	
	}else if(theAction == "loggedin"){
		document.varform.action = "loggedin.php";
		document.varform.submit();
		
	}else if(theAction == "payments_results"){
		document.varform.action = "payments_results.php";
		document.varform.submit();
	}else if(theAction == "register"){
		var theForm = eval("document.custform");
		if(form_validator1(theForm,'new')){
			document.custform.cadd.value = "register";
			document.custform.action = "upcustomer.php";
			document.custform.submit();
		}	
	/*}else if(theAction == "multiregister"){
		var theForm = eval("document.custform");
		if(form_validator1(theForm,'multi')){
			document.custform.cadd.value = "register";
			document.custform.action = "upmultiuser.php";
			document.custform.submit();
		}	*/
	}else if(theAction == "reminder"){
		var isOK = true;
		// Name field must not be empty
		if (document.varform.name.value == "") {
			alert("Please enter your registered Email in the \"Email address\" field.");
			isOK = false;
		}
		if(isOK){
			document.varform.action = "reminder.php";	
			document.varform.submit();
		}
	}else if(theAction == "newuser"){
		document.varform.action = "newuser.php";	
		document.varform.submit();	
		
	/*}else if(theAction == "newmultiuser"){
		document.varform.action = "newmultiuser.php";	
		document.varform.submit();	
	}else if(theAction == "reviewusers"){
		document.varform.action = "multiusers.php";	
		document.varform.submit();
	*/	
			
	}else if(theAction == "buynow"){							//Adds selected saved items to the shopping basket for purchase		
		if(document.saveorderform.tobuynow.value == ""){
			alert("Please ensure that items to buy are selecetd.")
		}else{
			document.varform.addSaved.value = document.saveorderform.tobuynow.value;   //Flag that when we get to shopping basket we need to transfer contents to temp table to continue with the order
			document.varform.action = "basket.php";	
			document.varform.submit();
		}	
	}
}

//*******************Login from choice where user has more than one account with the same password and id
function reLogin(itemNo){
	document.varform.cid.value = itemNo;
	document.varform.refreshpage.value = "no";
	document.varform.action = "loggedin.php";	
	document.varform.submit();					
}		

//------------------End of file