var IsWin=(navigator.userAgent.indexOf('Win')!=-1);
var IsMac=(navigator.userAgent.indexOf('Mac')!=-1);
var isNS4 = (document.layers) ? true : false;
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;
var BV=parseFloat(navigator.appVersion.indexOf("MSIE")>0?navigator.appVersion.split(";")[1].substr(6):navigator.appVersion);
var BN=navigator.appName;
var OP=(navigator.userAgent.indexOf('Opera')!=-1&&BV>=4)?true:false;
var NS=(BN.indexOf('Netscape')!=-1&&(BV>=4&&BV<5)&&!OP)?true:false;
var SM=(BN.indexOf('Netscape')!=-1&&(BV>=5)||OP)?true:false;
var IE=(BN.indexOf('Explorer')!=-1&&(BV>=4)||SM)?true:false;

// Function: spawn_window
// Author: Matt Cooke
// Date: 10/06/2001
// Notes: Opens a new window with the text, content and specifications supplied
function SpawnWindow(sURL, sSize) {
	window.open(sURL,'NewWindow',sSize);
}

// Function: MM_RestoreImage
// Author: Matt Cooke
// Date: 10/06/2001
// Notes: Restoes an image to the original specified src.
function MM_RestoreImage() { 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

// Function: MM_LoadImages
// Author: Matt Cooke
// Date: 10/06/2001
// Notes: Preloads images on a page load event
function MM_LoadImages() { 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_LoadImages.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: MM_findObj
// Author: Matt Cooke
// Date: 10/06/2001
// Notes: find the specified image to replace an elements existing source (mouseovers)
function MM_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

// Function: MM_SwapImage
// Author: Matt Cooke
// Date: 10/06/2001
// Notes: Swaps an elements existing image with the one specified
function MM_SwapImage() { 
  var i,j=0,x,a=MM_SwapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Enquiry form validation
function ValidateFields() { 
	if (document.ContactForm.name.value.length < 1 || isWhitespace(document.ContactForm.name.value) == true) {
		alert("Please enter a contact name.");
		document.ContactForm.name.focus();
		return false;
	}	

	if (document.ContactForm.telephone.value.length < 1 || isWhitespace(document.ContactForm.telephone.value) == true) {
		alert("Please enter a contact telephone number.");
		document.ContactForm.telephone.focus();
		return false;
	}			
				
	if (document.ContactForm.email.value.length < 1 || isWhitespace(document.ContactForm.email.value) == true) {
		alert("Please enter a contact email address.");
		document.ContactForm.email.focus();
		return false;
	}	
	else {
		var invalidChars = " /:,;";
		var email = document.ContactForm.email.value;
		for(i=0; i<invalidChars.length; i++) {
			badChar = invalidChars.charAt(i);
			if(email.indexOf(badChar, 0) > -1) {
				alert("Please enter a valid contact email address (cannot contain any of the following characters /:,; or a space)");
				document.ContactForm.email.focus();
				return false;
			}
		}

		atPos = email.indexOf("@", 1)
		if(atPos == -1) {
			alert("Please enter a valid contact email address.");
			document.ContactForm.email.focus();
			return false;
		}

		if(email.indexOf("@", atPos+1) != -1) {
			alert("Please enter a valid contact email address.");
			document.ContactForm.email.focus();
			return false;
		}

		periodPos = email.indexOf(".", atPos)
		if(periodPos == -1) {
			alert("Please enter a valid contact email address.");
			document.ContactForm.email.focus();
			return false;
			}
		
		if(periodPos+3 > email.length) {
			alert("Please enter a valid contact email address.");
			document.ContactForm.email.focus();
			return false;
		}
	}
}  

// Check whether string s is empty.
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s)

{   

    var i;
    var whitespace = " \t\n\r";

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}