//This is an image preload script
var pix0 = new Array();
var pix1 = new Array();

for (var i=0; i<=2; i++){
pix0[i]="";
pix1[i]="";
}

function preloadButtonSet(num,dark,light) {
    if(document.images){
        pix0[num] = new Image();
        pix0[num].src = dark;
        pix1[num] = new Image();
        pix1[num].src = light;

    }
}

//This is the rollover part

function over(num) {
 if (document.images)
  eval("document.button"+num+".src = pix1["+num+"].src;");
 return false;
}

function out(num) {
 if (document.images)
  eval("document.button"+num+".src = pix0["+num+"].src;");
 return false;
}


//*************************
// Browser-independent method of getting an object
// borrowed from http://www.xs4all.nl/~ppk/js/
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];
	}
}


//This function to be removed when all pages are updated
function bgImage(id,image)
	{
		if (navigator.appVersion.indexOf("MSIE 6") != -1 || (navigator.appVersion.indexOf("MSIE 5.5") !=-1  || ((navigator.appVersion.indexOf("MSIE")==-1 && parseInt(navigator.appVersion) >4)))){
		var objControl = new getObj(id);
		
		objControl.style.backgroundImage= 'url('+image+')' ;
		}
	//document.getElementById(id).style.backgroundImage = 'url('+image+')'  ; 
 	} 


//Function to open a new window because strict doctype does not support target
function load(target) {
var load = window.open(target,'');
}


function doPopup(URL,winName,features,obj) {
	if( (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)==4 ))
	{
		obj.href='Javascript:var j=0';
	}
	else
	{
		obj.setAttribute('href','Javascript:var j=0');
	}
	pwin=window.open(URL,winName,features);
	pwin.moveTo(10,10);
	pwin.focus();
}


function AddressWindow(strUrl, obj)
{
	var strParameters = 'scrollbars=yes, ' + 
							'resizable=yes, ' +
							'width=420, ' +
							'height=400';

	doPopup('../addr/' + strUrl, 'contact', strParameters, obj); 
}


// Function to make Interrnet Explorer recognise hover
// on elements other than anchors

function startList(id) {

if (document.all&&document.getElementById) {
  navRoot = document.getElementById(id);
  for (i=0; i<navRoot.childNodes.length; i++) {
    node = navRoot.childNodes[i];
    if (node.nodeName=="LI") {
      node.onmouseover=function() { this.className+=" over";}
      node.onmouseout=function() {this.className=this.className.replace(" over", "");}
   }
  }
 }
}


//Function to colour form input and textarea fields on focus
function FormColour() {
	if (document.getElementsByTagName) {
		navRoot = document.getElementsByTagName("INPUT");
		for (i=0; i<navRoot.length; i++) {
			node=navRoot[i];
			if (node.type =="text"){
				node.onfocus=function() { this.className="foc"; }
				node.onblur=function()  { this.className="blu"; }
			}
		}
		navRoot = document.getElementsByTagName("TEXTAREA");
		for (i=0; i<navRoot.length; i++) {
			node=navRoot[i];
				node.onfocus=function() { this.className="foc"; }
				node.onblur=function()  { this.className="blu"; }
			}
	}
}

//#########################
// Form validation routines
//#########################
//*************************
// Check that an input field is not blank
function FValidateControl(control){
  if ( control.value == " " ) {
    control.value = "";
  }
  if (control.value==""){
    alert(control.id+" must be filled in before your form can be sent.");
    control.focus();
    return false;
  }
  return true;
}
//*************************

//*************************
// Check that the email address is of the right form
// The email field must be called email
	function MailValidate(myForm){
		var re = /^\s?\w+([\.\-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/
		if (re.test(myForm.email.value))
		{
			return true
		}
		alert("Invalid form of email address.\n\nIf it appears correct, check for spaces.");
		myForm.email.focus();
		myForm.email.select();
		return false;
}
//*************************
