// Validation by Henrik Petersen / NetKontoret Explained at www.echoecho.com/jsforms.htm
//Functions: do not change
function emailvalidation(entered, alertbox){
with (entered){
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2)
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}
}

function valuevalidation(entered, min, max, alertbox, datatype){
with (entered){
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
}
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}

function digitvalidation(entered, min, max, alertbox, datatype){
with (entered){
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i")
{checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
}
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}

function emptyvalidation(entered, alertbox){
with (entered){
if (value==null || value=="")
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}

// Ajax Loader - Modified by Travis Repetto - 2006 - Insert this code at the bottom of the page to have it execute on page load: window.onload=function(){ ajaxload('examplepage.html','ExampleHtmlTagId') }
function ajaxload(url,containerid){
	try { // Browser object detection
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
		new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e){} // browser doesn't support ajax. handle however you want
	xmlhttp.onreadystatechange = function(){statuschanged(containerid)}; // every time ready status changes, statuschanged() function executes
	xmlhttp.open("GET", url, true); // Usage: open(HTTP method, url, and asynchronous = true or false)
	xmlhttp.send(null); // send the request.
}
function statuschanged(containerid){
	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)){ // readyState codes: 0=Uninitialised 1=Loading 2=Loaded 3=Interactive 4=Completed; status code: 200=OK
		document.getElementById(containerid).innerHTML = xmlhttp.responseText; // xmlhttp.responseText object contains the text of 'url'
	}else{ // else, readyState is not yet Completed and status is not yet OK, so here we display loading text
		//document.getElementById(containerid).innerHTML = "Sending...";
	}
}
//End Functions

//Customize Here
function formvalidation(thisform){
	with (thisform){
		if (emptyvalidation(fname,"Please fill out your first name.")==false) {fname.focus(); return false;};
		if (emptyvalidation(lname,"Please fill out your last name.")==false) {lname.focus(); return false;};
		if (emailvalidation(email,"Please enter a valid E-mail address.")==false) {email.focus(); return false;};
		if (emptyvalidation(phone,"Please enter your telephone number.")==false) {phone.focus(); return false;};
		if (emptyvalidation(hear,"Please tell us how you heard about us.")==false) {hear.focus(); return false;};
		if (emptyvalidation(assist,"Please tell us how we can assist you.")==false) {assist.focus(); return false;};
		if (emptyvalidation(message,"Please enter your message.")==false) {message.focus(); return false;};
		
		//Ajax added by Travis Repetto
		var myPath = "form2mail.asp"
		myPath = myPath + "?fname="+fname.value
		myPath = myPath + "&lname="+lname.value
		myPath = myPath + "&email="+email.value
		myPath = myPath + "&phone="+phone.value
		myPath = myPath + "&hear="+hear.value
		myPath = myPath + "&assist="+assist.value
		myPath = myPath + "&message="+message.value
		ajaxload(myPath,'contactform');
	}
}