// These variables set for use in function changeLayer(layerId)
var layerIndex = 0;
var prevLayerName = "section" + layerIndex;
var prevLayerTabName = "toc_section" + layerIndex;
var theLayerName = "";
var theLayerTabName = "";
/*	to calculate to what value the js variable varsCounter should be set requires server-side scripting. varsCounter should be defined in every page that
	calls changeLayer(layerId).
*/
function changeLayer(layerId)
  {
    var i = 0;
    var layerVar = "";
    if (theLayerName)
    {
    	prevLayerName = theLayerName; //record prev layer to turn off before recording new layer to turn on.
    	prevLayerTabName = "toc_" + theLayerName;
    }
 	theLayerName = layerId;
 	theLayerTabName = "toc_" + theLayerName;
 	layerIndex = layerId.charAt(layerId.length-1);

    // Test to check if browser == IE
    if (document.all)
	{
      eval(prevLayerName).style.visibility = "hidden";
      eval(prevLayerTabName).className = "";
      eval(theLayerName).style.visibility = "visible";
      eval(theLayerName).style.display = "block";
      eval(theLayerTabName).className = "current";
	}
	// Test to check if browser == NN4
	else if (document.layers)
    {
	  document.eval(prevLayerName).visibility = "hidden";
      document.eval(prevLayerTabName).className = "";
	  document.eval(theLayerName).visibility = "visible";
	  document.eval(theLayerName).display = "block";
      document.eval(theLayerTabName).className = "current";
	  
	}
	// Test to check if browser == Mozilla, e.g. NN6 upwards
	else if (! document.all && document.getElementById)
    {
	  document.getElementById(prevLayerName).style.visibility = "hidden";
	  document.getElementById(prevLayerTabName).className = "";
	  document.getElementById(theLayerName).style.visibility = "visible";
      document.getElementById(theLayerName).style.display = "block";
	  document.getElementById(theLayerTabName).className = "current";
	}

    do
    {
	  layerVar = "section" + i;

      if (layerVar != theLayerName)
	  {
	    // Test to check if browser == IE
        if (document.all)
	    {
	      eval(layerVar).style.visibility = "hidden";
	      eval(layerVar).style.display = "none";
	      
		}
	    // Test to check if browser == NN4
	    else if (document.layers)
        {
	      document.eval(layerVar).visibility = "hidden";
	      document.eval(layerVar).display = "none";
	    }
		// Test to check if browser == Mozilla, e.g. NN6 upwards
	    else if (! document.all && document.getElementById)
        {
   		  document.getElementById(layerVar).style.visibility = "hidden";
          document.getElementById(layerVar).style.display = "none";
		}
	  }
	  
	  i++;
    }while (i < varsCounter)
  }
function nodelink(id) {
	link(id);
}

function link_old(id) {
	var newUrl = "old";
	$.ajax({
		url:'http://c1973/corprefocus/contentlocation/index.htm?id=' + id,
		success: function(data){
			var d = data.toString().replace(/\?.*/g,"");
			//alert(d);
			window.location=d;
		},
		error: function(e){
			//alert('error: ' + e);
		}
	});
	//alert(newUrl);
}


$(document).ready(function() {
	//fix 0px lhnav height bug
	var lHeight = $("#lhnav ul").height();
	var saHeight = $("#seealso").height();
	var elHeight = $("#externallinks").height();
	var cHeight = $("#content").height();
	if (lHeight == null) lHeight = 0;
	if (elHeight == null) elHeight = 0;
	if (saHeight == null) saHeight = 0;

	var lhHeight = lHeight + saHeight + elHeight + 70;
	if(lhHeight > cHeight)
		$("#content").css("height",lhHeight + "px");
	
	//open external links in a new window	
	$("a[href^='http']").attr("target","_blank");
});

function checkFeedback(form)
{
	var initVal	= ".";
	var errors		= false;
	var errorMsg 	= "Please complete the following required fields:\t\n\n";

	for (var i=0; i <form.elements.length; i++)
		{
			var formElement 	= form.elements[i].name;
			var formElementVal 	= form.elements[i].value;
			var isReq 			= formElement.indexOf("_req");

			if (isReq > 0 && (formElementVal == initVal || formElementVal == "")) 
				{
					formElement = formElement.substring(0, formElement.length-4);
					errorMsg	= errorMsg += "\t" + formElement + "\n";
					errors 		= true;
				}

		}

   	if (errors)
   		{
   			alert(errorMsg);
		 	return false;
   		}

	return true;

}

function SPINorderCheck(form)
{

		if (form.Title.selectedIndex == 0) {
			form.Title.focus();
			alert("Please select your title.");
			return false;
		}
		
		if (form.Firstname.value.length < 2) {
			alert("Please supply your first name.");
			form.Firstname.focus();
			return false;
		}
		
		if (form.Surname.value.length < 2) {
			alert("Please supply your surname.");
			form.Surname.focus();
			return false;
		}



		if (form.email.value.length < 5) {
			alert("Please supply a valid e-mail address.");
			form.email.focus();
			return false;
		}
		
		
		if (form.email.value.length >= 0) {
		anyspaces = form.email.value.indexOf(" ");
		dot = form.email.value.lastIndexOf(".");
		atsign = form.email.value.indexOf("@");


		}
		
		if ((atsign <= 0)||(dot <= (atsign + 1))||(anyspaces != -1)||(dot == form.email.value.length)){
			alert("The e-mail address given is invalid.");
			form.email.focus();
			return false;
		}

		if (form.Country.selectedIndex == 0) {
			alert("Please include your country.");
			form.Country.focus();
			return false;
		}
		
		if (form.Work_sector.selectedIndex == 0) {
			alert("Please include your work sector.");
			form.Work_sector.focus();
			return false;
		}
			
return true;
}



