<!-- Hide script from old browsers

/*
Created By: Ethan Berl
Email: ethanberl@gmail.com
Written in 2004 and added to this website on 12-1-2008
*/

var fieldHandle = new Array();
var fieldName = new Array();
var fieldStatus = new Array();


function indexOfElement(array, element) {
	for(i=0;i<array.length;i++) {
		if(array[i]==element) return i
	}
	return -1
}


function fieldCheck(myform, validvalue, invalidvalue, expression, changeid) {
	var index = indexOfElement(fieldName,changeid)
	if(index==-1) {
		//alert(fieldStatus[changeid])
		fieldStatus[fieldStatus.length]=0
		fieldName[fieldName.length]=changeid
		fieldHandle[fieldHandle.length]=myform
	}
	if(expression.test(myform.value)) {
		fieldStatus[indexOfElement(fieldName,changeid)]=1
		var disptext=document.getElementById(changeid)
		disptext.innerHTML=validvalue
	} else {
		fieldStatus[indexOfElement(fieldName,changeid)]=0
		var disptext=document.getElementById(changeid)
		disptext.innerHTML=invalidvalue
	}
}

function radioCheck(myform, validvalue, invalidvalue, changeid) {
	var index = indexOfElement(fieldName,changeid)
	if(index==-1) {
		fieldStatus[fieldStatus.length]=0
		fieldName[fieldName.length]=changeid
		fieldHandle[fieldHandle.length]=myform
	}
	if(true) {
		fieldStatus[indexOfElement(fieldName,changeid)]=1
		var disptext=document.getElementById(changeid)
		disptext.innerHTML=validvalue
	}
}

function printarrays(value) {
	if(value=="This is just a test.") {
		//alert(fieldStatus['fax'])
		var string = "fieldHandle\n"
		for(i=0;i<fieldHandle.length;i++) {
			string+=fieldHandle[i]+"\n"
		}
		alert(string)	
		var string = "fieldName\n"
		for(i=0;i<fieldName.length;i++) {
			string+=fieldName[i]+"\n"
		}
		alert(string)
		var string = "fieldStatus\n"
		for(i=0;i<fieldStatus.length;i++) {
			string+=fieldStatus[i]+"\n"
		}
		alert(string)
	}
}

function submitCheck(size) {
	if(size>fieldName.length) {
		alert("You must fill in all forms with an asterisk * next to them.")
		return false
	}
	//alert("stop")
	var valid=1;//should be 1
	//alert(fieldStatus.length)
	var i=0;
	for(i=0;i<fieldStatus.length;i++) {
		valid=fieldStatus[i] && valid
		//alert(fieldStatus[i]+' '+valid)
		if(!valid) break
	}
	if(document.getElementById("hphone").value=="123456") {
		alert("That phone number looks pretty fake!");
		return false;
	}
	if(document.getElementById("cphone").value=="123456") {
		alert("That cell number looks pretty fake!");
		return false;
	}
	if(!valid) {
		alert("'"+fieldHandle[i].value+"' is not a valid response for "+fieldName[i])
		return false
	} else {
		return true
	}
}















/******************************************************************************************************************************************************
The following functions are examples of specific uses of the above function to test
specific types of fields and change the color of text to indicate validity.
******************************************************************************************************************************************************/

var re=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/i
var re2=/^\w{6,12}$/i
var re3=/^[\w+\d+]{6,12}$\b/i

function passwordCheck(myform) {
	if(re3.test(myform.value)) {
		passObj=document.getElementById("passcheck").style
		passObj.color="green"
	} else {
		passObj=document.getElementById("passcheck").style
		passObj.color="red"
	}
}

function passwordConfirm(myform) {
	if(re3.test(myform.value)) {
		if(myform.value==form1.password.value) {
			pass2Obj=document.getElementById("passconfirm").style
			pass2Obj.color="green"
		} else {
			pass2Obj=document.getElementById("passconfirm").style
			pass2Obj.color="red"
		}
	}
}

function usernameCheck(myform) {
	if(re2.test(myform.value)) {
		userObj=document.getElementById("usercheck").style
		userObj.color="green"
	} else {
		userObj=document.getElementById("usercheck").style
		userObj.color="red"
	}
}

function emailCheck(myform) {
	if(re.test(myform.value)) {
		emailObj=document.getElementById("emailcheck").style
		emailObj.color="green"
	} else {
		emailObj=document.getElementById("emailcheck").style
		emailObj.color="red"
	}
}

/*
The submit function must make sure that each of the fields is valid and tell the users which ones 
are incorrect and is thus specific to the form.  submitIt() is an example to validate username,
email, and password.  submitCheck() is the actual function used on this site.
*/
		
function submitIt(myform) {
	if(re.test(myform.emailAddr.value)) {
		if(re2.test(myform.username.value)) {
			if(re3.test(myform.password.value)) {
				return true
			} else {
			alert("Invalid password")
			return false
			}
		} else {
		alert("Invalid username")
		return false
		}
	} else {
	alert("Invalid email address")
	return false
	}
}

// End hiding script -->
