// JavaScript Document

<script type="text/javascript" language="JavaScript">
<!--

function validateName(){
    if (!document.survey.visitor.value){
        alert("You must enter your name before submitting this form.");
        document.survey.visitor.focus();
        return false;
    }else{
        return true;
    }
}

function validateEmail(){
	var theEmail = document.survey.email.value;
	var atLoc = theEmail.indexOf("@",1);
	var dotLoc = theEmail.indexOf(".",atLoc+2);
	var len = theEmail.length;
	
	if (atLoc >0 && dotLoc>0 && len > dotLoc+2){
		return true;
	}else{
		alert("Please Enter Your E-mail Address Properly.");
		document.survey.email.focus();
		return false;
	}	
}


function validatePhone(){


	var thePhone = document.survey.phone.value;
	var theChar = "";
	
	if (!document.survey.phone.value){
        	alert("All Required Fields Must Be Completed!");
        	document.survey.phone.focus();
        	return false;
    	}
	else if (thePhone.substring(0,1)=="("){
		return true;
	}
	else if (thePhone.length < 13 || thePhone.length >13){
        	alert("You Must Enter 13 Numbers.");
	        document.survey.phone.focus();
		return false;
	}
	else {
        for (i = 0; i < thePhone.length; i++){
        	theChar = thePhone.substring(i,i+1);
        	if (theChar < "0" || theChar > "9"){
            		alert("Invalid number! You Must Enter Your Phone Number Properly.");
        		document.survey.phone.focus();
        		return false;
		}
	}
       		var countrycode = thePhone.substring(0,2);
		var areacode = thePhone.substring(2,5);
		var exchange = thePhone.substring(5,9);
        	var extension = thePhone.substring(9,13);
	        var newNumber = "(+" + countrycode + ") "+areacode + " "+exchange+" "+extension;
        	document.survey.phone.value = newNumber;
		return true;
    	}

}	

function validate(){
	
	if (validateName() && validateEmail() && validatePhone()){
		return true;
	}else{
		return false;
	}
}

//-->
   </script>
