// JavaScript Document

function submit_search(){
	document.frmSearch.submit()
}
 

function validate_email_form(){ 
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	
	tForm = document.frmEmail
	
	if (trim(tForm.your_name.value)  == ""){
		tMessage += "          Your Name\n"
		tValidatedOK = false
	} 
	
	if (trim(tForm.email.value)  == ""){
		tMessage += "          Your Email Address\n"
		tValidatedOK = false
	} else 	if (!check_email(tForm.email.value)  ){
		tMessage += "          A Valid Email Address\n"
		tValidatedOK = false
	} 
	 
	
	if (trim(tForm.msg.value)  == ""){
		tMessage += "          Your Message\n"
		tValidatedOK = false
	} 
			
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
	
		tForm.submit()
	}
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function check_email(aVal){
	var tValidatedOK = true
	if(aVal != 0){
		var error = false
		email = aVal
		var at="@"
		var dot="."
		var lat=email.indexOf(at)
		var lstr=email.length
		var ldot=email.indexOf(dot)
		if (email.indexOf(at)==-1){
		   error = true;
		}

		if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr){
		   error = true;
		}

		if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr){
		   error = true;
		}

		 if (email.indexOf(at,(lat+1))!=-1){
		   error = true;
		 }

		 if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot){
		   error = true;
		 }

		 if (email.indexOf(dot,(lat+2))==-1){
		   error = true;
		 }
		
		 if (email.indexOf(" ")!=-1){
		   error = true;
		 }

		if(error){
			tValidatedOK = false;
		} 
	}
	
	return tValidatedOK;
}
