//Feature sensing DOM
var isDHTML = 0;
var isLayers = 0;
var isAll = 0;
var isID = 0;
var isNet = 0;

//alert(a_all)

if (document.getElementById) {
	isID = 1; isDHTML = 1;
}
else {
	if (document.all) {
		isAll = 1; isDHTML = 1;
	}
	else {
		browserVersion = parseInt(navigator.appVersion);
		if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) { 
			isLayers = 1; isDHTML = 1; 
		}
	}
}
if (navigator.appName.indexOf('Netscape') != -1) {
	isNet=1;
}

//Finds correct DOM path
function findDOM(objectID,withStyle) {
	if (withStyle == 1) {
		if (isID) { return(document.getElementById(objectID).style) ; }
		else {
			if (isAll) { return(document.all[objectID].style); }
		else {
			if (isLayers) { return(document.layers[objectID]); }
		};}
	}
	else {
		if (isID) { return(document.getElementById(objectID)); }
		else {
			if (isAll) { return(document.all[objectID]); }
		else {
			if (isLayers) { return(document.layers[objectID]); }
		};}
	}
}

function setVisibility(objectID,state) {
		var dom = findDOM(objectID,1);
	if (dom != null) dom.visibility = state;
	}


function openWindow() {
		newWindow = window.open("forgotten.asp","ForgottenPassword","width=480,height=170");
		newWindow.focus();}
		

function closeWindow() {
		if (newWindow != null) {
			newWindow.close();
			newWindow = null;
		}
}


function validEmail(email)

{
invalidChars="/:,;"

if (email =="")
{return true}

//check for invalid chars
   for (i=0;i<invalidChars.length;i++)
     { badChar = invalidChars.charAt(i)
	 if(email.indexOf(badChar,0) > -1)
	   {return false}
	 }
	 
// must be an @
atPos = email.indexOf("@",1)
if(atPos==-1)
{return false}

// only one @
if(email.indexOf("@",atPos+1)!=-1)
{return false}

// at least one . after the @
periodPos = email.indexOf(".",atPos)
if(periodPos ==-1)
{return false}

// at least 2 chars after the .
if (periodPos+3 >email.length)
{return false}

return true
}


 
function CheckInput(parm,set) {


	var use 
	var val
	var msg
	var a_all = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!,£.?@-() ";
	var numb = '0123456789';
	var lwr = 'abcdefghijklmnopqrstuvwxyz';
	var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

	val = parm.value
//	alert(val)

	switch(set) {
		case "all":
			use = a_all
			msg = "Please only use standard english characters ( a-z, A-Z, <space> and ' )"
			break
		case "numb":
			use = numb
			msg = "Please only use numbers"
			break
		default: set = a_all
	}

  if (val == "") return true;
  
  for (i=0; i<val.length; i++) {
//	 alert("got " && i);
    if (use.indexOf(val.charAt(i),0) == -1) {
		alert(msg);
		parm.focus()
		return false;
	}
  }
  return true;
}
	


function IsName ( str ) {
	//PURPOSE: validate name entries into enquiries forms
	//Return immediatly if invalid value passed in
	var num = '0123456789';

	if( str + "" == "undefined" || str + "" == "null" || str + "" == "") {
		alert("Please only use standard english characters ( a-z, A-Z, <space> and ' )");
		return false;
	}

//	alert(str);

	var isValid = true;

	str += "" 	//Convert to string
	
	for (i = 0; i < str.length; i++) {
		if (!(	
			((str.charAt(i) >= "A") &&	//uppercase 
			(str.charAt(i) <= "Z")) ||
			((str.charAt(i) >= "a") &&	//lowercase
			(str.charAt(i) <= "z")) ||	
			(str.charAt(i) <= " ") ||	//space
			(str.charAt(i) <= "-") ||	//dash
			(str.charAt(i) <= "'") 	//apostrophe
  			//(num.indexOf(str.charAt(i),0)!=-1)
		)) {
			isValid = false;
			alert("Please only use standard english characters (a-z; A-Z, <space> and ')");
			break;
		}
	}
	return isValid;
}

function mustHave(a_obj,a_msg) {
	if(a_obj.value.length<1 || a_obj.value=="Enter other details") {
		alert(a_msg)
		a_obj.focus()
		return false
	}
	return true
}

function pageVisibility(a_val,what,obj) {
	if (a_val==what) {
		setVisibility(obj,'visible');
	} 

	else {
		setVisibility(obj,'hidden');
	}
}

function setClass(objectID,newClass) {
	var dom = findDOM(objectID,0);
	dom.className = newClass;
}	

	function illegal(str) {
		var chars = /[^\w\s\.,@-]/;
			//allow only letters, numbers and underscores, spaces, 
			if (chars.test(e.value)) {
				alert("This field contains illegal characters. Please only use a - z, 0 - 9, @, commas, full-stops and spaces")
				e.focus()
				return false
			}
		return true
		}

	//tests all elements
	function testElements(theForm) {   
	
		for (i = 0; i < theForm.length; i++) { // iterate through form fields
			e = theForm.elements[i];
			if(!illegal(e.value)) return false // check only valid characters
			if (e.className == "mandat") { // check all mandatory fields are filled in
				if (e.value == "") {
					alert("This field is mandatory.")
					e.focus()
					return false
					break
				}
			}
		}
		return true
	}
	
	function displayProperties(inputObject, inputObjectName) {
		var result = " "
		for (var eachProperty in inputObject) {
			result += inputObjectName + "." + eachProperty + " = " + inputObject[eachProperty] + "<BR>"
		}
		result += "<hr>"
		alert(result)
		return result
	}

	function testEmail(str) {
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(str))) { 
			   alert("Please enter a valid email address.\n");
			   return false
		}
	return true
	}
	
	function theSame(s1,s2) {if (s1 != s2) return false; return true}
				
					