// HBP Copier Systems JavaScript Document

function nav(){
	var pageName = document.URL.substring(document.URL.lastIndexOf("/")+1, document.URL.lastIndexOf(".")).replace(/\-/g, "_");

	if(pageName.indexOf("/")!=-1 || document.URL.indexOf("copier-systems-history")!=-1 || document.URL.indexOf("location")!=-1)
	{
		var headerBtn = document.getElementById("header_btn_copiersystems_home");
		var leftBtn = document.getElementById("left_hand_link_" + pageName);
		var footerBtn = document.getElementById("footer_link_" + pageName);
		if(pageName.indexOf("/")!=-1)
		{
			var leftBtn = document.getElementById("left_hand_link_copiersystems_home");
			var footerBtn = document.getElementById("footer_link_copiersystems_home");
		}
		buttonOn(headerBtn, pageName);
		buttonOn(leftBtn, pageName);
		buttonOn(footerBtn, pageName);
		return;  	   
	}
	if(document.URL.indexOf("/print/")!=-1 || document.URL.indexOf("black-white-photocopiers")!=-1 || document.URL.indexOf("colour-photocopiers")!=-1 || document.URL.indexOf("electronic-document-management-software")!=-1)
	{
		pageName = "copier_systems_products";	
	}
	if(document.URL.indexOf("news")!=-1)
	{
		pageName = "news";
		document.getElementById("header_btn_copiersystems_home").className = document.getElementById("header_btn_copiersystems_home").className.replace("off", "on");
		
	}
	
	var headerBtn = document.getElementById("header_btn_" + pageName);
	var leftBtn = document.getElementById("left_hand_link_" + pageName);
	var footerBtn = document.getElementById("footer_link_" + pageName);

	buttonOn(headerBtn, pageName);
	buttonOn(leftBtn, pageName);
	buttonOn(footerBtn, pageName);
	return;
}
function buttonOn(button, pageName){
	if(button!==null)
	{
		button.className = button.className.replace("off", "on");
		return true;
	}
	else
	{
		return;
	}
}
/*


	if(pageName == "search")
			{
				pageName = "copiersystems_home";
			}
	var leftBtnName = document.getElementById("left_hand_link_" + pageName);
	var footerBtnName = document.getElementById("footer_link_" + pageName);
	if(footerBtnName != null)
		{
			if(footerBtnName.className.indexOf("last")!=-1)
				{
					footerBtnName.className = "footer_link_on last_link";	
				}
			else
				{
					footerBtnName.className = "footer_link_on";
				}
		}

	if(pageName == "copier_systems_products" || pageName == "electronic_document_management_software")
			{
				pageName = "copiersystems_products";
			}
	if(pageName == "refurbished_products")
			{
				pageName = "copiersystems_refurbished_offers";
			}
	if(pageName == "our_location" || pageName == "contact_copier_systems")
			{
				pageName = "contact_copiersystems";
			}
	var headerBtnName = document.getElementById("header_btn_" + pageName);
	
	if(headerBtnName != null)
		{
			headerBtnName.className = "btn_on";
		}
	
	if(leftBtnName != null)
		{
			leftBtnName.className = "btn_on";
		}
	
	*/


function weCallYouSubmit(){
	var prefix = "global_we_call_you_";
	var name = document.getElementById(prefix + "name")
	var phone = document.getElementById(prefix + "phone")
	var email = document.getElementById(prefix + "email")
	
	name.style.borderColor = "#008469";
	name.style.backgroundColor = "#ffffff";
	phone.style.borderColor = "#008469";
	phone.style.backgroundColor = "#ffffff";
	email.style.borderColor = "#008469";
	email.style.backgroundColor = "#ffffff";
	
	if(name.value == name.originalValue || name.value == "")
		{
			name.style.borderColor = "#ff0000";
			name.style.backgroundColor = "#ffdfdf";
			alert("You must enter a contact name.");
			return false;
		}
	if(phone.value == phone.originalValue || phone.value == "" || phone.value.length < 11)
		{
			phone.style.borderColor = "#ff0000";
			phone.style.backgroundColor = "#ffdfdf";
			alert("You must enter a phone number including area code.");
			return;
		}
	if(email.value == email.originalValue || email.value == "" || email.value.indexOf("@")==-1)
		{
			email.style.borderColor = "#ff0000";
			email.style.backgroundColor = "#ffdfdf";
			alert("You must enter a valid email address.");
			return;
		}
	document.getElementById("we_call_you_button").disabled = 1;
	document.forms.global_we_call_you.submit();
}
function checkCallBack(){
	var prefix = "inset_we_call_you_";
	var name = document.getElementById(prefix + "name")
	var phone = document.getElementById(prefix + "phone")
	var email = document.getElementById(prefix + "email")
	
	name.style.borderColor = "#008469";
	name.style.backgroundColor = "#ffffff";
	phone.style.borderColor = "#008469";
	phone.style.backgroundColor = "#ffffff";
	email.style.borderColor = "#008469";
	email.style.backgroundColor = "#ffffff";
	
	if(name.value == name.originalValue || name.value == "")
		{
			name.style.borderColor = "#ff0000";
			name.style.backgroundColor = "#ffdfdf";
			alert("You must enter a contact name.");
			return false;
		}
	if(phone.value == phone.originalValue || phone.value == "" || phone.value.length < 11)
		{
			phone.style.borderColor = "#ff0000";
			phone.style.backgroundColor = "#ffdfdf";
			alert("You must enter a phone number including area code.");
			return;
		}
	if(email.value == email.originalValue || email.value == "" || email.value.indexOf("@")==-1)
		{
			email.style.borderColor = "#ff0000";
			email.style.backgroundColor = "#ffdfdf";
			alert("You must enter a valid email address.");
			return;
		}
	document.getElementById("we_call_you_button").disabled = 1;
	document.forms.inset_we_call_you.submit();
}
function resetForm(formName) {
	var answer = confirm("Are you sure you want to reset the form?")
	if(answer)
	{
		document.forms.sage_main_enquiry_form.reset();	
	}
	else {return false}
	}
	
function submitForm(formName) {
	var mf = 'main_form_';
	var cl = 'main_form_text_input';
	var d = document.getElementById;
	var nameField = document.getElementById(mf + 'name');
	var nameContent = document.getElementById(mf + 'name').value;
	var emailField = document.getElementById(mf + 'email');
	var emailContent = document.getElementById(mf + 'email').value;
	var phoneField = document.getElementById(mf + 'phone');
	var phoneContent = document.getElementById(mf + 'phone').value;
	var defaultEnquiryContent = 'Type your enquiry in here, remember the more information that you can give us, the more efficiently we can deal with your enquiry.';
	var noEnquiry = 'No Enquiry Was Left';
	var enquiryContent = document.getElementById(mf + 'enquiry').innerHTML;
	
	if(formName == 'enquiry')
		{
			if(enquiryContent == defaultEnquiryContent)
				{
					document.getElementById(mf + 'enquiry').innerHTML = '';
					document.getElementById(mf + 'enquiry').title = defaultEnquiryContent;
					return;
				}
			if(enquiryContent == '')
				{
					document.getElementById(mf + 'enquiry').innerHTML = defaultEnquiryContent;
					document.getElementById(mf + 'enquiry').title = ''
					return;
				}
			return;
		}
		
	if(formName == 'completesage')
	{
		var disabledTitle = 'To untick this selection, you must untick "Complete Sage 200 Suite" above';
		var resetTitle = 'Tick if you want to recieve information specifically about Sage 200 ';
		var currentForm = document.forms.sage_main_enquiry_form;
 		 
		{
			if(d(mf + 'entire_sage_suite').checked == false)
				{
					
					var i;
					for(i=0;i<=currentForm.elements.length;i++)
					{
						control = currentForm.elements[i];
						if(control != null) {
							if(control.type == 'checkbox' && control.module != null) {
								if(control.module == 'true') {
									control.checked = false;
									control.disabled = false;
									control.title = control.uncheckedTitle;
								}
							}
						}
					}
					
					return;
				}
			else
				{
					
					var i;
					for(i=0;i<=currentForm.elements.length;i++)
					{
						control = currentForm.elements[i];
						
						if(control != null) {
							if(control.type == 'checkbox' && control.module != null) {
								if(control.module == 'true') {
									control.checked = true;
									control.disabled = true;
									control.title = disabledTitle;
								}
							}
						}
					}
					
					return	;
				}
			return;
		}
	}

	setupForm();

	if(nameContent == '')
		{
			ScrollToElement(nameField);
			nameField.className='revise';
		 	alert("You must enter a name");
			nameField.focus();
			return;
		}
	if(emailContent == '' || emailContent.indexOf("@")==-1)
		{
			ScrollToElement(emailField);
			emailField.className='revise';
		 	alert("You must enter a valid email address");
			emailField.focus();
			return;
		}
	if(phoneContent == '' || phoneContent.length < 11)
		{
			ScrollToElement(phoneField);
			phoneField.className='revise';
		 	alert("You must enter a contact phone number including area code");
			phoneField.focus();
			return;
		}
	if(enquiryContent == defaultEnquiryContent)
		{
			var question = confirm("Are you sure you don't want to leave a written enquiry?")
			if(question)
				{document.getElementById(mf + 'enquiry').value = 'No Enquiry Was Left';}
			else{return;}
		}
	
	
	
	//submit form
	document.getElementById("submit_btn").disabled = 1
	var currentForm = document.forms.sage_main_enquiry_form;
	var i;
	for(i=0;i<=currentForm.elements.length;i++)
	{
		control = currentForm.elements[i];
		if(control != null) 
		{
			if(control.type == 'checkbox' && control.module != null) 
			{
				if(control.module == 'true') 
				{
					control.disabled = 0;
				}
			}
		}
	}
	document.forms.sage_main_enquiry_form.submit();
	return;

	
		function setupForm(){
			document.getElementById(mf + 'name').className=cl;
			document.getElementById(mf + 'email').className=cl;
			document.getElementById(mf + 'phone').className=cl;
			if(enquiryContent == '' || enquiryContent == noEnquiry)
				{
					document.getElementById(mf + 'enquiry').innerHTML = defaultEnquiryContent;
				}
			}
	}

function ScrollToElement(theElement){

  var selectedPosX = 0;
  var selectedPosY = 0;
              
  while(theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop - 45;
    theElement = theElement.offsetParent;
  }
                        		      
 window.scrollTo(selectedPosX,selectedPosY);

}




/*map*/
/*function load() {
      if (GBrowserIsCompatible()) {
		 alert("load 2")
        var map = GMap2(document.getElementById("map"));
        var center = new GLatLng(53.5744, -0.6231);
		map.setCenter(center, 13);
		alert(4)
		map.addControl(new GSmallMapControl());
		map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
		map.addControl( new GOverviewMapControl(new GSize(100,100)) );
		 
        map.setMapType(G_NORMAL_MAP);
        map.enableDoubleClickZoom();
		map.scrollWheelZoomEnabled();
		map.setZoom(7)
		var marker = new GMarker(center);
        map.addOverlay(marker);
        marker.openInfoWindowHtml("<span id='map_marker'><img src='/images/layout/map_logo.jpg' id='hbp_map_logo' /><span class='map_text'><h1 class='map_title'>HBP Systems Ltd</h1><br />Enterprise House, Scunthorpe Technology Park, Woodhouse Road, DN16 1BD, UK<span class='map_links'><a href='mailto:info@hbpsystems.com' title='Send Email to HBP Systems Now' class='map_text_link'>info@hbpsystems.com</a> | <a href='http://www.hbpsystems.com' title='Go to HBP Corporate Website Now' target='_blank' class='map_text_link'>www.hbpsystems.com</a></span></span></span>");
      }
    }
*/

 /*  function initialize(action, directions) {
	
      if (GBrowserIsCompatible()) { 
	  	var map;
		var gdir;
		var geocoder = null;
		var addressMarker;
		var center = new GLatLng(53.5744, -0.6231);
		map = new GMap2(document.getElementById("map"));
		gdir = new GDirections(map, document.getElementById("directions"));
		map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
		map.addControl( new GOverviewMapControl(new GSize(100,100)) );
		GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
        map.enableDoubleClickZoom();
		map.scrollWheelZoomEnabled();
		map.setCenter(center, 7);
		if(action == "resetMap")
			{
				var marker = new GMarker(center);
				map.addOverlay(marker);
        		marker.openInfoWindowHtml("<span id='map_marker'><img src='/images/layout/map_logo.jpg' id='hbp_map_logo' /><span class='map_text'><h1 class='map_title'>HBP Systems Ltd</h1><br />Enterprise House, Scunthorpe Technology Park, Woodhouse Road, DN16 1BD, UK<span class='map_links'><a href='mailto:info@hbpsystems.com' title='Send Email to HBP Systems Now' class='map_text_link'>info@hbpsystems.com</a> | <a href='http://www.hbpsystems.com' title='Go to HBP Corporate Website Now' target='_blank' class='map_text_link'>www.hbpsystems.com</a></span></span></span>");
				return;
			}
		if(directions == 'true')
			{

	

				var toAddress = document.getElementById("toAddress").value;
				var fromAddress = document.getElementById("fromAddress").value;
				if(fromAddress == "")
					{
						var marker = new GMarker(center);
						map.addOverlay(marker);
						marker.openInfoWindowHtml("<span id='map_marker'><img src='/images/layout/map_logo.jpg' id='hbp_map_logo' /><span class='map_text'><h1 class='map_title'>HBP Systems Ltd</h1><br />Enterprise House, Scunthorpe Technology Park, Woodhouse Road, DN16 1BD, UK<span class='map_links'><a href='mailto:info@hbpsystems.com' title='Send Email to HBP Systems Now' class='map_text_link'>info@hbpsystems.com</a> | <a href='http://www.hbpsystems.com' title='Go to HBP Corporate Website Now' target='_blank' class='map_text_link'>www.hbpsystems.com</a></span></span></span>");
						alert("Please add your postcode or street and town to the \"Get Directions\" box, and click \"Go\"")	
						return;
					}
				GEvent.addListener(gdir, "load", onGDirectionsLoad);
        		GEvent.addListener(gdir, "error", handleErrors);
				
				setDirections("lincoln", "woodhouse rd, scunthorpe", "");
				/*if(gdir.getStatus().code!==200)
					{
						var marker = new GMarker(center);
						map.addOverlay(marker);
						marker.openInfoWindowHtml("<span id='map_marker'><img src='/images/layout/map_logo.jpg' id='hbp_map_logo' /><span class='map_text'><h1 class='map_title'>HBP Systems Ltd</h1><br />Enterprise House, Scunthorpe Technology Park, Woodhouse Road, DN16 1BD, UK<span class='map_links'><a href='mailto:info@hbpsystems.com' title='Send Email to HBP Systems Now' class='map_text_link'>info@hbpsystems.com</a> | <a href='http://www.hbpsystems.com' title='Go to HBP Corporate Website Now' target='_blank' class='map_text_link'>www.hbpsystems.com</a></span></span></span>");
						alert("There was an error, and your directions could not be processed.\n\n Please check the address that you input and try and again.\n\nIf this error persists, please contact HBP on 01724 400 300 and quote \"Error Code: " + gdir.getStatus().code + "\"")	
						return;	
					}*/
/*				return;
			}
		map.setMapType(G_NORMAL_MAP);
		map.setZoom(7)
		var marker = new GMarker(center);
        map.addOverlay(marker);
        marker.openInfoWindowHtml("<span id='map_marker'><img src='/images/layout/map_logo.jpg' id='hbp_map_logo' /><span class='map_text'><h1 class='map_title'>HBP Systems Ltd</h1><br />Enterprise House, Scunthorpe Technology Park, Woodhouse Road, DN16 1BD, UK<span class='map_links'><a href='mailto:info@hbpsystems.com' title='Send Email to HBP Systems Now' class='map_text_link'>info@hbpsystems.com</a> | <a href='http://www.hbpsystems.com' title='Go to HBP Corporate Website Now' target='_blank' class='map_text_link'>www.hbpsystems.com</a></span></span></span>");
		
		return;
		}
		
	  else {
	  	document.getElementById("google_map_container").style.display = "none";
		document.getElementById("map_image").style.display = "block";
	  }
    }
	
	function resetMap() {
		initialize('resetMap');
		return;
	}
	
    function setDirections(fromAddress, toAddress, locale) {
		var map;
		var gdir;
		var geocoder = null;
		var addressMarker;
		var center = new GLatLng(53.5744, -0.6231);
		map = new GMap2(document.getElementById("map"));
		gdir = new GDirections(map, document.getElementById("directions"));
		
		var toAddress = "Woodhouse Road, Scunthorpe";
		var locale = "en_US";
		map.clearOverlays();
      	gdir.load("from: " + fromAddress + " to: " + toAddress);
		alert(gdir.getStatus().code)

    }

    function handleErrors(){
		gdir = new GDirections(map, document.getElementById("directions"));
		var map;
 		var gdir;
 		var geocoder = null;
 		var addressMarker;
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	   {
	     alert("We couldn't find your exact address. This may be because the address you specified is relatively new, or it may be incorrect.\n\nPlease try again.\n\nIf this problem persists, please contact HBP on 01724 400 300");
		 return;
	   }
	   if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	   {	
	   		initialize('resetMap');
	     	alert("Your directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code + "\n\nPlease try again, putting either postcode or street and town in to the directions box");
			return;
	   }
	   if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	   {
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
		 return;
	   }
	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	  if (gdir.getStatus().code == G_GEO_BAD_KEY)
	  {
	     alert("We could not process your query at this present time.\n\n Please contact HBP on 01724 400 300 with the following error:\n\n Error code: " + gdir.getStatus().code + " - Map Key Invalid");
		 return;
	  }
	  if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	  {
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
		 return;
	  }
	   else {alert("An unknown error occurred. Please try again.");}
	   
		}

	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}


/*if (GBrowserIsCompatible()) {

      // ===== request the directions =====
      function getDirections() {
        var saddr = "Grimsby"
        var daddr = "Woodhouse Road, Scunthorpe"
        gdir.load("from: "+saddr+" to: "+daddr);
      }
	  
      // create the map
      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng(53.5744, -0.6231), 13);

      // === create a GDirections Object ===
      var gdir=new GDirections(map, document.getElementById("directions"));

      // === Array for decoding the failure codes ===
      var reasons=[];
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";

      reasons[G_GEO_BAD_REQUEST]        = "A directions request could not be successfully parsed.";
      reasons[G_GEO_MISSING_QUERY]      = "No query was specified in the input.";
      reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points.";

      // === catch Directions errors ===
      GEvent.addListener(gdir, "error", function() {
        var code = gdir.getStatus().code;
        var reason="Code "+code;
        if (reasons[code]) {
          reason = reasons[code]
        } 

        alert("Failed to obtain directions, "+reason);
      });
	  // Read the data from example.xml
      var request = GXmlHttp.create();
      request.open("GET", "example.xml", true);
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          var xmlDoc = GXml.parse(request.responseText);
          // obtain the array of markers and loop through it
          var markers = xmlDoc.documentElement.getElementsByTagName("marker");
          
          for (var i = 0; i < markers.length; i++) {
            // obtain the attribues of each marker
            var lat = parseFloat(markers[i].getAttribute("lat"));
            var lng = parseFloat(markers[i].getAttribute("lng"));
            var point = new GLatLng(lat,lng);
            var html = markers[i].getAttribute("html");
            var label = markers[i].getAttribute("label");
            // create the marker
            var marker = createMarker(point,label,html);
            map.addOverlay(marker);
          }
          // put the assembled side_bar_html contents into the side_bar div
          document.getElementById("side_bar").innerHTML = side_bar_html;
        }
      }
      request.send(null);
    }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }

    // This Javascript is based on code provided by the
    // Blackpool Community Church Javascript Team
    // http://www.commchurch.freeserve.co.uk/   
    // http://econym.googlepages.com/index.htm
*/