//Form validation script
//By: Aaron LaMontagne
//Date: 03-30-05
//File Name: validation.js

function checkForm(){
	var form = document.form;
	var radio = true
	var checkbox = false 
	
	//Check the radio buttons
	if(radio != false){
		var myOption = -1;
		for(var i = 0; i<form.property.length; i++){
			if(form.property[i].checked){
				myOption = i;
			}
		}
		if (myOption == -1) {
			alert("Please select your the location you're interested in.");
			return false;
		}
	}//end check for radio buttons
	
	//check contact fields
	if(form.name.value == ""){
		alert("Please enter a 'Name'");
		form.name.focus()
		return false;
	}//ends if
	
	if(form.address.value == ""){
		alert("Please enter an 'Address'");
		form.address.focus()
		return false;
	}//ends if
	
	if(form.city.value == ""){
		alert("Please enter a 'City'");
		form.city.focus()
		return false;
	}//ends if
	
	if(form.state.value == ""){
		alert("Please enter a 'State'");
		form.state.focus()
		return false;
	}//ends if
	
	if(form.zip.value == ""){
		alert("Please enter a 'Zip Code'");
		form.zip.focus()
		return false;
	}//ends if
	
	if(form.phone.value == ""){
		alert("Please enter a 'Phone Number'");
		form.phone.focus()
		return false;
	}//ends if
	
	
	if(form.email.value == ""){
		alert("Please enter an 'Email Address'");
		form.email.focus()
		return false;
	}//ends if
	if ((form.email.value==null)||(form.email.value=="")){
		alert("Please enter an 'Email Address'")
		form.email.focus()
		return false
	}
	
	if (echeck(form.email.value)==false){
		form.email.value=""
		form.email.focus()
		return false
	}

	
	
/*	
	//Check the check boxes
	if(checkbox != false){
		var myckbox = false;
		for(var i = 0; i<form.risklevel.length; i++){
			if(form.risklevel[i].checked == true){
				myckbox = true;
			}
		}
		if (myckbox == false) {
			alert("Please select your 'Risk Level'");
			return false;
		}
	}//end check for check boxes
	
	*/
}//ends checkform


//This function is used in form validation scripts to check email addresses
//DO NOT REMOVE!!!!!
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
 		 return true					
	}//ends echeck

