//<![CDATA[
var d = new Date();
var year = d.getFullYear();

var menu;
var theTop = 95;
var menuHeight = 430;
var old = theTop;

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function MM_preloadImages()
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function doSetupContainer()
{
	var doc;
	if (self.innerHeight) // all except Explorer
	{
		doc = document.documentElement.scrollHeight;
		container.style.height = (doc-theTop)+"px";
	}
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		doc = document.documentElement.offsetHeight;
		container.style.height = (doc-theTop)+"px";
	}
	else if (document.body) // other Explorers
	{
		doc = document.body.scrollHeight;
		container.style.height = (doc-theTop)+"px";
	}
}

function movemenu()
{
	//Determine document height
	var doc;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight
	if (test1 > test2) // all but Explorer Mac
	{
		doc = document.body.scrollHeight;
	}
	else // Explorer Mac;
     //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		doc = document.body.offsetHeight;
	}
	//Determine current scroll top
	if (window.innerHeight)
	{
		pos = window.pageYOffset
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		pos = document.documentElement.scrollTop
	}
	else if (document.body)
	{
		pos = document.body.scrollTop
	}
	if (pos < theTop) pos = theTop;
	else pos += 0;
	if (pos > doc-menuHeight) pos = doc-menuHeight;
	if (pos < theTop) pos = theTop;
	if (pos == old)
	{
		rightmenu.style.top = pos+"px";
	}
	old = pos;
	temp = setTimeout('movemenu()',500);
}

function doPopups()
{
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("popup")) {
      links[i].onclick = function() {
        window.open(this.href);
        return false;
      }
    }
  }
}

function clearOnFocus(type)
{
  if (!document.getElementsByTagName) return false;
  var fields = document.getElementsByTagName(type);
  for (var i=0; i < fields.length; i++) {
    if (fields[i].className.match("clearonfocus")) {
      fields[i].onfocus = function() {
        if (this.value == this.defaultValue) {
          this.value = "";
          return false;
		}
      }
	  fields[i].onblur = function() {
        if (this.value == "") {
          this.value = this.defaultValue;
          return false;
		}
      }
    }
  }
}

//More information form validation
var rxEmailAddress	= /^(\w+|[.]|[-]+)+[@](\w+|[-]+)+[.](\w+|[.]|[-]+)+$/;
var rxTelephone		= /^[\(\)\+ 0-9]*$/;

function submitMoreInfo(valType)
{
	var txtName				= document.getElementById('txtName');
	var txtEmail			= document.getElementById('txtEmail');
	var txtTelephone		= document.getElementById('txtTelephone');
	var txaComments			= document.getElementById('txaComments');
	var txtAddress			= document.getElementById('txtAddress');
	if (valType) {
	var selProduct			= document.getElementById('selProduct');
	}
	var frmMoreInformation	= document.getElementById('frmMoreInformation');


	// WARNING: do not change the error checking below other than the messages without matching the changes in the
	//			asp.net thank_you class, otherwise exceptions will be generated by the class
	
	var errors			= '';

	if (txtName.value.length < 3 || txtName.value.length > 40 || txtName.value == "Full Name")
	{
		errors = errors + '- enter a name between 3 and 40 characters in length\r\n';
	}
	
	if (txtEmail.value.length < 6 || txtEmail.value.length > 255 || !rxEmailAddress.test(txtEmail.value))
	{
		errors = errors + '- enter a valid email address between 6 and 255 characters in length\r\n';
	}
	
	if (txtTelephone.value.length < 6 || txtTelephone.value.length > 40 || !rxTelephone.test(txtTelephone.value))
	{
		errors = errors + '- enter a valid telephone between 6 and 40 characters in length\r\n';
	}
	
	if (txtAddress.value.length < 20 || txtAddress.value.length > 255)
	{
		errors = errors + '- enter a valid full address including postcode\r\n';
	}
	
	if (valType && selProduct.selectedIndex == 0)
	{
		errors = errors + '- select the product of interest\r\n';
	}

	if (errors.length > 0)
	{
		window.alert('Sorry, please correct the following before submitting the More Information form:\r\n\r\n' + errors);
	}
	else
	{
		frmMoreInformation.submit();
	}
}

//Email Newsletter Subscription form validation
function submitEmailNewsletter()
{
	var txtName				= document.getElementById('txtSubscribeName');
	var txtEmail			= document.getElementById('txtSubscribeEmail');
	var frmSubscribeForm	= document.getElementById('frmSubscribeForm');
	
	var errors			= '';

	if (txtName.value.length < 3 || txtName.value.length > 40 || txtName.value == "Full Name")
	{
		errors = errors + '- enter a name between 3 and 40 characters in length\r\n';
	}
	
	if (txtEmail.value.length < 6 || txtEmail.value.length > 255 || !rxEmailAddress.test(txtEmail.value))
	{
		errors = errors + '- enter a valid email address between 6 and 255 characters in length\r\n';
	}

	if (errors.length > 0)
	{
		window.alert('Sorry, please correct the following before submitting the Email Newsletter Subscription form:\r\n\r\n' + errors);
	}
	else
	{
		frmSubscribeForm.submit();
	}
}

function submitSearch()
{
	var selStockGroup				= document.getElementById('selStockGroup');
	var txtItemNoAndNameSearch		= document.getElementById('txtItemNoAndNameSearch');
	var frmSearch					= document.getElementById('frmSearch');
	
	var errors			= '';

	if (selStockGroup.selectedIndex == 0)
	{
		errors = errors + '- select the light tower\r\n';
	}
	
	if (txtItemNoAndNameSearch.value.length < 2 || txtItemNoAndNameSearch.value.length > 40 || txtItemNoAndNameSearch.value == "Enter search string")
	{
		errors = errors + '- enter a valid search string between 2 and 40 characters in length\r\n';
	}

	if (errors.length > 0)
	{
		window.alert('Sorry, please correct the following before submitting the search form:\r\n\r\n' + errors);
	}
	else
	{
		frmSearch.submit();
	}
}

window.onload = function ()
{
	MM_preloadImages('images/body_btm.gif','news_arrow_on.gif');	
	rightmenu = new getObj('right');
	container = new getObj('main2');
	doSetupContainer();
	movemenu();
	doPopups();
	clearOnFocus('input');
	clearOnFocus('textarea');
	
	var exists = false;
	
	try
	{
		if (customOnLoad)
			exists = true;
	}
	catch(e){}

	if (exists)
		customOnLoad();
	
}

window.onresize = function ()
{
	doSetupContainer();
}
//]]>
