function TL_swapImage(iname, image){
	document.images[iname].src=image;
}

function form(){
	var f = document.forms[0];
	var err = "";
	var captcha = f.elements["captcha"].value;
	if(captcha == ""){
		err += "Please fill out the captcha field\n";
	}else if(captcha != "046e5"){
		err += "You did not fill out the captcha field correctly\n";
	}
	if(checkEmail(f.elements["email"].value)){
		err += "Enter a valid E-mail Address\n";
	}
	if(f.elements["name"].value == ""){
		err += "Enter your name\n";
	}
	if(f.elements["Tel"].value == ""){
		err += "Enter a phone number\n";
	}
	
	if(err != ""){
		alert("Sorry, we were unable to process your request.\nPlease complete the following:\n\n"+err);
		return false;
	}else{
		return true;
	}
}

function checkEmail(strVal){
	var blnErr = false;

	if(strVal.length < 6)
		blnErr = true;
	else if(strVal.lastIndexOf("@") - strVal.indexOf("@") == 1)
		blnErr = true;
	else if(strVal.lastIndexOf(".") - strVal.indexOf(".") == 1)
		blnErr = true;
	else if(strVal.indexOf("@") == 0 || strVal.lastIndexOf("@") == strVal.length-1)
		blnErr = true;
	else if(strVal.indexOf(".") == 0 || strVal.lastIndexOf(".") >= strVal.length-2)
		blnErr = true;
	else if(strVal.lastIndexOf(".") < strVal.lastIndexOf("@"))
		blnErr = true;
	else if(strVal.indexOf("@") < strVal.lastIndexOf("@"))
		blnErr = true;
	else if((strVal.indexOf(".") - strVal.indexOf("@")) == 1)
		blnErr = true;
	else if(strVal.indexOf("@") < strVal.lastIndexOf("@"))
		blnErr = true;
	else if(strVal.indexOf("@") < 0 || strVal.indexOf(".") < 0)
		blnErr = true;
	else if(strVal.indexOf(" ") > 0 || strVal.indexOf(" ") == 0)
		blnErr = true;
	if(!blnErr)
		blnErr = checkEmailChars(strVal);
	return blnErr;
}

function checkEmailChars(theText){
	var compareString1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-_.&";
	var compareString2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890.-";
	var pos = theText.indexOf("@");
	var found = false;

	/****Check front portion of email before @ sign*******/
	for(i = 0;i<pos;i++){
		if(compareString1.indexOf(theText.charAt(i)) < 0){
			found = true;
			break;
		}
	}

	if(!found){
		/****Check email address after @ sign*******/
		for(j = pos + 1 ;j<theText.length;j++){
			if(compareString2.indexOf(theText.charAt(j)) < 0){
				found = true;
				break;
			}
		}
	}

	return(found);
}
