//Code to chk proper e mail type
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("Enter a Valid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Enter a Valid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Enter a Valid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Enter a Valid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Enter a Valid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Enter a Valid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Enter a Valid E-mail ID")
		    return false
		 }

 		 return true					
	}

// form validation code
function validate()
{
	var housing=document.form1.seniorhr;
	var name=document.form1.name;
	var city=document.form1.city;
	var state=document.form1.state;
	var email=document.form1.email;
	var ph=document.form1.phone;
	var srname=document.form1.seniorname;
	var srage=document.form1.seniorage;
	var needs1=document.form1.needs1;
	var needs2=document.form1.needs2;
	var needs3=document.form1.needs3;
	var needs4=document.form1.needs4;
	var needs5=document.form1.needs5;
	var budget=document.form1.monthlybud;
	var location=document.form1.location;
	var comment=document.form1.comments;
	
	
	if (housing.value=="sel"){
		alert("Please Choose When will you need senior housing");
		housing.focus();
		return false;
	}
	if ((name.value==null)||(name.value=="")){
		alert("Please Enter your Full Name");
		name.focus();
		return false;
	}
	if ((city.value==null)||(city.value=="")){
		alert("Please Enter your City");
		city.focus();
		return false;
	}
	if (state.value=="sel"){
		alert("Please Choose your State ");
		state.focus();
		return false;
	}
	if ((email.value==null)||(email.value=="")){
		alert("Please Enter your E-Mail ID");
		email.focus();
		return false;
	}
	if (echeck(email.value)==false){
		email.value="";
		email.focus();
		return false
	}
	if ((ph.value==null)||(ph.value=="")){
		alert("Please Enter your Phone Number");
		ph.focus();
		return false;
	}
	if (isNaN(ph.value)){
		alert("Please Enter a Numerical Phone Number");
		ph.value="";
		ph.focus();
		return false;
	}
	if ((srname.value==null)||(srname.value=="")){
		alert("Please Enter your Senior Name");
		srname.focus();
		return false;
	}
	if ((srage.value==null)||(srage.value=="")){
		alert("Please Enter your Senior's Age");
		srage.focus();
		return false;
	}
	if (isNaN(srage.value)){
		alert("Please Enter a Numerical Age");
		srage.value="";
		srage.focus();
		return false;
	}
	if ((needs1.checked==false)&&(needs2.checked==false)&&(needs3.checked==false)&&(needs4.checked==false)&&(needs5.checked==false)){
		alert("Please Enter your Senior Care Needs");
		budget.focus();
		return false;
	}
	if ((budget.value==null)||(budget.value=="")){
		alert("Please Enter your Budget");
		budget.focus();
		return false;
	}
	if ((location.value==null)||(location.value=="")){
		alert("Please Enter your Desired Facility Location");
		location.focus();
		return false;
	}
	if ((comment.value==null)||(comment.value=="")){
		alert("Please Enter your Comments");
		comment.focus();
		return false;
	}
	else
	document.form1.submit();
	return true;
}



