// Browser Detection and general page layout code NEW
// *** BROWSER VERSION ***

//Browser = {
//    isSupported : function(){
//            return (Boolean(document.getElementsByTagName)
//                        && Boolean(document.getElementById));
//        },
//    id : new function() {

//            var ua= navigator.userAgent;
//            var OMNI = ua.indexOf("Omni") > 0;

//            this.OP5 = ua.indexOf("Opera 5") >= 0 || ua.indexOf("Opera 6") >= 0;
//            this.OP7 = ua.indexOf("Opera 7") >= 0;
//            this.MAC = ua.indexOf("Mac") > 0;

//            if(!this.OP5 && !OMNI){
//                this.IE5 = ua.indexOf("MSIE 5") > 0;
//                this.IE5_0 = ua.indexOf("MSIE 5.0") > 0;
//                this.NS6 = ua.indexOf("Gecko") > 0;
//                this.MOZ = this.NS6 && ua.indexOf("Netscape") == -1;
//                this.MAC_IE5 = this.MAC && this.IE5;
//                this.IE6 = ua.indexOf("MSIE 6") > 0;
//                this.KONQUEROR = ua.indexOf("Konqueror/") > 0;
//            }
//        }        
//};
//var px = "px";



// Browser Detection and general page layout code
// *** BROWSER VERSION ***

var browser="";

if(navigator.appVersion.indexOf("Opera 6") == -1) { browser="o6"; }
if(navigator.appVersion.indexOf("Opera 7") == -1) { browser="o7"; }
if(navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 2) { browser="n2"; }
if(navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 3) { browser="n3"; }
if(navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4) { browser="n4"; }
if(navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 5) { browser="n4"; }
if(navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 6) { browser="n7"; }
if(navigator.appVersion.indexOf("MSIE 3.0") != -1) { browser="ie3"; }
if(navigator.appVersion.indexOf("MSIE 4.0") != -1) { browser="ie4"; }
if(navigator.appVersion.indexOf("MSIE 5.0") != -1) { browser="ie5"; }
if(navigator.appVersion.indexOf("MSIE 5.5") != -1) { browser="ie5"; }
if(navigator.appVersion.indexOf("MSIE 6") != -1) { browser="ie5"; }

var topBarHeight = 180;
var bottomBarHeight = 10;
var sideBarWidth = 250;

// This function creates a new pop-up window.
function openPopup(pg){
	
	if (browser == "ie3"){ 
	var newWind=window.open(pg, "newPopUp","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=480,top=50,left=175");
	}
	
	else{
	
	if ( browser=="n3"  ||  browser=="n4"  ||  browser=="ie4"  ||  browser=="ie5"  ||  browser=="o7" ){
	var newWind=window.open(pg, "newPopUp","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=480,top=50,left=175");
	}
	}
	
		if (newWind.opener == null){
			newWind.opener = window;
			}

			else{ 
			
      		if ( browser=="n3"  ||  browser=="n4"  ||  browser=="ie4" )
	        newWind.focus();
			}
	}

//Generic form validation functions.
// 
//validateInput V1.0
//
//ABOUT.
//
//These routines are called from a forms onSubmit event and test for 
//appropriate data values in corresponding fields, if any of the values are 
//missing or of the wrong type the user is prompted and submission halted.
//
//The actual validation functions are intentionally simple, the purpose of
//this code is to provide a generic form validation handler that will work
//in MSIE 3.0x/4.x/5.x and NS Navigator 3.x/4.x/5.x/6.x and Communicator.
//
//The handler function - validateInput() accepts two parameters, the name of
//the form to be processed and a string that provides a mask against which 
//each field on the named form can be validated.
//
//This mask is the key to the functionality of this script. For each field on the form
//the corresponding character in the mask string tells the handler how to perform the 
//validation.
//
//The mask string can contain the following characters;
//
//	d = validate value as a date
//	t = validate value as text
//	n = validate value as a whole number (1234567890)
//	p = validate value as a phone number (+,(), 1234567890)
//	e = validate value as an e-mail address (@, .)
//  s = validate selection list
//	u = unrequired - do not validate
//
//The function can be used to process multiple forms on a single page, 
//this is useful for ASP developers who commonly generate input and
//confirmation forms within a single .asp file.
//
//----------------------------------------------------------------------
//
function validateInput(frm, mask){

	//Count the number of form elements
	var FrmLen = frm.elements.length;
 
	//Get the validation mask string
	var maskarr = mask;
	
	//Loop through all the form elements
	for (var i = 0; i < FrmLen; i++)
	{
		//obtain the validation mask character
		maskarr = mask.substring(i,i+1)

		//Initialise local variables
		var valdate = 1;
		var valtext = 1;
		var valnum = 1;
		var valtelenum = 1;
		var valemail = 1;
		var valselect = 1;

	//Test field against validation mask character
	if (maskarr == "d")
	{
		valdate = validateDate(frm.elements[i].value);
	}
	if (maskarr == "t")
	{
		valtext = validateText(frm.elements[i].value);
	}
	if (maskarr == "n")
	{
		valnum = validateNum(frm.elements[i].value);
	}
	if (maskarr == "p")
	{
		valtelenum = validateTeleNum(frm.elements[i].value);
	}
	if (maskarr == "e")
	{
		valemail = validateEmail(frm.elements[i].value);
	}
	if (maskarr == "s")
	{
		valselect = validateSelect(frm.elements[i].value);
	}

	//If the validation fails prompt the user
	if (! valdate)
	{
		alert("The date you have entered is invalid");
		putFocus(frm.elements[i]);
		return false;
	}
	if (! valtext)
	{
		alert("Please complete all fields");
		putFocus(frm.elements[i]);
		return false;
	}
	if (! valnum)
	{
		alert("Please enter a valid number");
		putFocus(frm.elements[i]);
		return false;
	}
	if (! valtelenum)
	{
		alert("Please enter a valid telephone or extension number");
		putFocus(frm.elements[i]);
		return false;
	}
	if (! valemail)
	{
		alert("The Email address you have entered is invalid");
		putFocus(frm.elements[i]);
		return false;
	}
	if (! valselect)
	{
		alert("You must make a valid selection from the list");
		putFocus(frm.elements[i]);
		return false;
	}
	}
	return true;
}

//Date validation function
function validateDate(s)
{
	//Test for a string
	if (s.length > 0)
	{
		//Create an array to split the date into (dd/mm/yy)
		strarr = new Array ()

		//Use own split function as JScript does not include JavaScripts split function
		own_split(strarr, s, "/");
		
		//3 array elements means day, month, and year
		if (strarr.length == 3)
		{
			//Test the value of each element falls in an acceptable range
			for (var i = 0; i < strarr.length; i++)
			{
				if ((strarr[0] < 0) || (strarr[0] >31)){
					return false;
				}
				if ((strarr[1] < 0) || (strarr[1] >12)){
					return false;
				}
				if ((strarr[2] <= 1899) || (strarr[2] > 2099)){
					return false;
				}
			}
			return true;
		}
		return false;
	}
	return false;
}

//Text validation function
function validateText(s)
{
	//test for a string
	if (s.length > 0)
	{
		return true;
	}
	return false;
}

//Number validation function
function validateNum(s)
{
	//Test to see if the value converts to a number
	if (parseInt(s) > 0)
	{
		return true;
	}
	return false;
}

//Telephone Number validation function
function validateTeleNum(s)
{
	//Test for a string
	if (s.length > 0)
	{
		for (i = 0;  i < s.length;  i++)
 		{
		    	ch = s.charAt(i);
			if(! own_instring(ch))
			{
			return false;
			}
		}
		return true;
	}
	return false;
}

//E-Mail address validation function
function validateEmail(s)
{
	//Test for a string
	if (s.length > 0)
	{
		// Return false if e-mail field does not contain a '@' and '.' .
		if (s.indexOf ('@',0) == -1 || s.indexOf ('.',0) == -1)
      			{
			return false;
			}
		return true;
	}
	return false;
}

//Select list validation function
function validateSelect(s)
{
	//Test for a string
	if (s == 'null')
    {
		return false;
		}
	return true;
}

//In string function to test for valid substring, accomodates JavaScripts lack of VBScripts InStr() function
function own_instring(c)
{
	var checkOK = "0123456789-+-. ()\t\r\n\f";
	var ret  = false;

  		for (j = 0;  j < checkOK.length;  j++)
		{
      			if (c != checkOK.charAt(j))
			{
			continue;
			}
			else
			{
			ret = true;
			break;
			}
		}
	return ret;
}

//String split function to accomodate JScripts lack of JavaScripts split function
function own_split(arr, str, delim)
{
	//Initialise local variables
	var pos = 0;
	var num = 0;
	var start = 0;
	
	//Loop while there are characters in the string
	while (pos < str.length)
	{
		//Loop while there are delimiters in the string
		while((str.substring (pos, pos+1) != delim) && (pos < str.length))
		{
		pos++;
		}
		//Add the new characters to the output array
		arr[num] = str.substring(start,pos);
		num++;
		start = pos+1;
		pos++;
	}
}
//--------------------------------------------------------------------------------------------------------------------
//
//JavaScript form focus handler
//
//This function is called by the validateInput() function. 
//
//It sets focus on the text box that fails the validation test (from the call in validateInput()).
//
//--------------------------------------------------------------------------------------------------------------------
function putFocus(elementStr){
   	
   	if (elementStr.value == 1 || elementStr.value == 'null')
	   	{
  		elementStr.focus();
   		}
		else
		{
    	elementStr.value="";
	   	elementStr.focus();
		}
}	

// Function to handle submenu slide effects
function slideMenus(nummenus, id) {

	if (document.all["menu"+id].style.display =='block')
		{
		document.all["menu"+id].style.display ='none';
		}
	else
		{
		document.all["menu"+id].style.display ='block';
		}

		for (i=0; i<nummenus; i++)
			if (i != id)
			{
				if (!(document.all["menu"+i]))
					{
					}
				else
					{
					document.all["menu"+i].style.display ='none';
					}
			}
}

// Function to set the position and size of the body area layer.
function setbodyArea(e) {

	if (browser=="n7"  ||  browser=="ie4"  ||  browser=="ie5"  ||  browser=="o7" )
	{

    var h = document.body.clientHeight;
    var w = document.body.clientWidth;
    document.all["bodysect"].style.pixelLeft = 250;
    document.all["bodysect"].style.pixelTop = 180;
//		if (browser=="n4")
//		{ 	
//	    document.all["bodysect"].style.clientHeight = h - (topBarHeight + bottomBarHeight);
//	    document.all["bodysect"].style.clientWidth = w - sideBarWidth - 160;
//	    document.all["bulletbar"].style.clientLeft = w - 140;
//	    document.all["bulletbar"].style.clientTop = 180;
//	   document.all["bulletbar"].style.clientHeight = h - 190;
//		}
//		else
//		{
	    document.all["bodysect"].style.pixelHeight = h - (topBarHeight + bottomBarHeight);
	    document.all["bodysect"].style.pixelWidth = w - sideBarWidth - 160;
	    document.all["bulletbar"].style.pixelLeft = w - 163;
	    document.all["bulletbar"].style.pixelTop = 180;
	    document.all["bulletbar"].style.pixelHeight = h - 190;
//		}
    document.all["bodysect"].style.visibility = "visible";
    document.all["bulletbar"].style.visibility = "visible";
	}
}

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 MM_swapImgRestore() { //v3.0
  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_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  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];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;

  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) 
  { v=args[i+2];
    if (obj.style) 
	{ 
	obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; 
	}
    obj.visibility=v; 
	}
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

// ImageReady Preload Script

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		graphic_01_over = newImage("images/graphic_01-over.gif");
		graphic_02_over = newImage("images/graphic_02-over.gif");
		graphic_03_over = newImage("images/graphic_03-over.gif");
		graphic_04_over = newImage("images/graphic_04-over.gif");
		graphic_06_over = newImage("images/graphic_06-over.gif");
		graphic_07_over = newImage("images/graphic_07-over.gif");
		graphic_08_over = newImage("images/graphic_08-over.gif");
		graphic_09_over = newImage("images/graphic_09-over.gif");
		preloadFlag = true;
	}
}