String.prototype.trim1 = 
 function trimblanks() { return this.split(/\s/).join(''); };
function valid() {
		  if(!(document.getElementsByName("interested1")[0].checked || document.getElementsByName("interested2")[0].checked || document.getElementsByName("interested3")[0].checked || document.getElementsByName("interested4")[0].checked )){
		alert("Please Select Type of facility you are interested in");
		document.getElementsByName("interested1")[0].focus();
		return false;
	}
	
if(document.getElementsByName("city")[0].value.trim1()=="" && document.getElementsByName("zip")[0].value=="" && document.getElementsByName("state")[0].value=="")
	{
		alert("Please Enter Either City and State Or Zip");
		document.getElementsByName("city")[0].focus();
		document.getElementsByName("city")[0].select();
		return false;
	}

	if(document.getElementsByName("city")[0].value.trim1()!=""){
		if(!(isNaN(document.getElementsByName("city")[0].value)))
		{
         alert("Please Enter Either Valid City  Name");
		document.getElementsByName("city")[0].focus();
		document.getElementsByName("city")[0].select();
		 return false;
		}
		if(document.getElementsByName("state")[0].value.trim1()=="" && document.getElementsByName("zip")[0].value.trim1()==""){
			 alert("Please Enter Either State or Zip");
			 document.getElementsByName("state")[0].focus();
			 return false;
		}

	}
if(document.getElementsByName("state")[0].value.trim1()!=""){
		if(document.getElementsByName("zip")[0].value.trim1()=="" && document.getElementsByName("city")[0].value.trim1()==""){
			 alert("Please Enter Either City or Zip");
			 document.getElementsByName("zip")[0].focus();
			 return false;
		}

	}
if(document.getElementsByName("city")[0].value.trim1()=="" && document.getElementsByName("state")[0].value.trim1()==""){
if(document.getElementsByName("zip")[0].value.trim1()==""){
	 alert("Please Enter a Valid Zip Code");
             document.getElementsByName("zip")[0].focus();
			  document.getElementsByName("zip")[0].select();
			 return false;
	}
	if(document.getElementsByName("zip")[0].value.trim1()!=""){

	zipval=document.getElementsByName("zip")[0].value
var zipPat=/^\d{5}$/;
var matchArray = zipval.match(zipPat);
if(!zipPat.test(zipval))
{
	   alert("Please Enter a Valid Zip Number ");
	 document.getElementsByName("zip")[0].focus();
	 document.getElementsByName("zip")[0].select();
     return false;
}
}
}
	if(document.getElementsByName("zip")[0].value.trim1()!=""){
	if(document.getElementsByName("zip")[0].value.trim1()=="")
	{
            alert("Please Enter a Valid Zip Code");
             document.getElementsByName("zip")[0].focus();
			 return false;
	}
	
		if(isNaN(document.getElementsByName("zip")[0].value.trim1()))
		{
			alert("Please Enter a Valid Zip Code");
             document.getElementsByName("zip")[0].focus();
			 document.getElementsByName("zip")[0].select();
			 return false;
      

	}
      if(document.getElementsByName("zip")[0].value.trim1().length!=5)
		{
		  alert("Please Enter a Valid Zip Code");
          document.getElementsByName("zip")[0].focus();
			 document.getElementsByName("zip")[0].select();
			 return false;
		}
	
	}
	if(document.getElementsByName("zip")[0].value!="" && document.getElementsByName("state")[0].value=="")
		{
	 var a=document.getElementsByName("zip")[0].value;
	// alert(getstateforzip(a));
		getstateforzip(a);
		
		}
		
		 if(document.getElementsByName("resident_name")[0].value.trim1()==""){
		 alert("Please Enter Name of the Senior");
		 document.getElementsByName("resident_name")[0].focus();
		  document.getElementsByName("resident_name")[0].select();
		 return false;
	 }
	  if(!(isNaN(document.getElementsByName("resident_name")[0].value))) {
		 alert("Please Enter Valid Senior Name");
		 document.getElementsByName("resident_name")[0].focus();
		 		  document.getElementsByName("resident_name")[0].select();

		 return false;
	 }
	  if(document.getElementsByName("relation")[0].value.trim1()=="")
	{
		alert("Please Select Relationship to Senior");
		document.getElementsByName("relation")[0].focus();
		return false;
	}

	 if(document.getElementsByName("fname")[0].value.trim1()==""){
		 alert("Please Enter First Name");
		 document.getElementsByName("fname")[0].focus();
		  document.getElementsByName("fname")[0].select();
		 return false;
	 }
	  if(!(isNaN(document.getElementsByName("fname")[0].value))) {
		 alert("Please Enter Valid First Name");
		 document.getElementsByName("fname")[0].focus();
		 		  document.getElementsByName("fname")[0].select();

		 return false;
	 }
	 if(document.getElementsByName("lname")[0].value.trim1()==""){
		 alert("Please Enter Last Name");
		 document.getElementsByName("lname")[0].focus();
		 document.getElementsByName("lname")[0].select();
		 return false;
	 }
	  if(!(isNaN(document.getElementsByName("lname")[0].value))){
		 alert("Please Enter Valid Last Name");
		 document.getElementsByName("lname")[0].focus();
		 document.getElementsByName("lname")[0].select();
		 return false;
	 }
	  if(document.getElementsByName("email")[0].value.trim1()==""){
		 alert("Please Enter Email");
		 document.getElementsByName("email")[0].focus();
		 return false;
	 }
	  var EmailPat = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/; 
//	                  A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	 if(!EmailPat.test(document.getElementsByName("email")[0].value.trim1()))
		{
			alert("Email address is invalid.  Please try again !!");			
 			document.getElementsByName("email")[0].focus();
           document.getElementsByName("email")[0].select();
  			return false ;
	    }
     if(document.getElementsByName("phone")[0].value.trim1()==""){
		 alert("Please Enter Phone Number");
		 document.getElementsByName("phone")[0].focus();
		 return false;
	 }
	 if(document.getElementsByName("phone")[0].value.trim1()!=""){

	zipval=document.getElementsByName("phone")[0].value
var zipPat=/^\d{10}$/;
var matchArray = zipval.match(zipPat);
if(!zipPat.test(zipval))
{
	   alert("Please Enter a Valid Phone Number ");
	 document.getElementsByName("phone")[0].focus();
	 document.getElementsByName("phone")[0].select();
     return false;
}
}
	
if(document.getElementsByName("city1")[0].value.trim1()=="")
	{
         alert("Please Enter City");
         document.getElementsByName("city1")[0].focus();
         document.getElementsByName("city1")[0].select();
         return false;
    }
	if(!(isNaN(document.getElementsByName("city1")[0].value)))
	{
         alert("Please Enter Valid City");
         document.getElementsByName("city1")[0].focus();
         document.getElementsByName("city1")[0].select();
         return false;
    }
if(document.getElementsByName("state1")[0].value.trim1()=="")
	{
         alert("Please Select State");
         document.getElementsByName("state1")[0].focus();
      
         return false;
    }

if(document.getElementsByName("zip1")[0].value.trim1()=="")
	{
         alert("Please Enter Zip");
         document.getElementsByName("zip1")[0].focus();
         document.getElementsByName("zip1")[0].select();
         return false;
    }



	if(document.getElementsByName("zip1")[0].value.trim1()!=""){

	zipval=document.getElementsByName("zip1")[0].value
var zipPat=/^\d{5}$/;
var matchArray = zipval.match(zipPat);
if(!zipPat.test(zipval))
{
	   alert("Please Enter a Valid Zip Code ");
	 document.getElementsByName("zip1")[0].focus();
	 document.getElementsByName("zip1")[0].select();
     return false;
}
}
 
	 if(document.getElementsByName("budget")[0].value.trim1()=="")
	{
		alert("Please Enter your Monthly Budget");
		document.getElementsByName("budget")[0].focus();
		return false;

	}
 if(document.getElementsByName("moveintimeframe")[0].value.trim1()=="")
	{
		alert("Please Select Move In Timeframe");
		document.getElementsByName("moveintimeframe")[0].focus();
		return false;
	}
	
	
	if(document.getElementsByName("veteran")[0].value=="")
	{
		alert("Please Select Is your Senior a Veteran or a Spouse of a Veteran");
document.getElementsByName("veteran")[0].focus();
return false;
	}
   document.getElementById("rep").innerHTML="<div align='center'><font color='red'>.....Processing Please Wait.</font></div>";
	
}
function valid1()
{
 if(document.getElementsByName("cname")[0].value.trim1()==""){
		 alert("Please Enter  Name");
		 document.getElementsByName("cname")[0].focus();
		  document.getElementsByName("cname")[0].select();
		 return false;
	 }
	 if(!isNaN(document.getElementsByName("cname")[0].value.trim1())){
            alert("Please Enter Valid  Name");
		  document.getElementsByName("cname")[0].focus();
		  document.getElementsByName("cname")[0].select();
		 return false;
	 }
	 if(document.getElementsByName("cemail")[0].value.trim1()==""){
		 alert("Please Enter Email");
		 document.getElementsByName("cemail")[0].focus();
		 document.getElementsByName("cemail")[0].select();
		 return false;
	 }
	 if(document.getElementsByName("cemail")[0].value.trim1()!=""){
	  var emailPat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/; 
	 if(!emailPat.test(document.getElementsByName("cemail")[0].value.trim1()))
		{
			alert("Your email address is invalid. Please try again !!");			
 			document.getElementsByName("cemail")[0].focus();
           document.getElementsByName("cemail")[0].select();
  			return false ;
	    }
	 }
	 if(document.getElementsByName("subject")[0].value.trim1()==""){
		 alert("Please Enter Subject");
		 document.getElementsByName("subject")[0].focus();
		 document.getElementsByName("subject")[0].select();
		 return false;
	 }
	  if(document.getElementsByName("message")[0].value.trim1()==""){
		 alert("Please Enter Message");
		 document.getElementsByName("message")[0].focus();
		 document.getElementsByName("message")[0].select();
		 return false;
	 }
}

function getstateforzip(zi)
  {
	  zi=zi*1;
	  zi=zi+"";
	 //alert(zi.length);
     // var ZIP = substr(zi,0,3);
	  var ZIP = zi.substr(0,3);     
      var ZIP2 = zi.substr(0,2);
      var ZIP1 = zi.substr(0,1);

//echo $zip;

 if(zi.length=='4')
	  {
		  if (ZIP2 >= 60 && ZIP2 <= 69)return showpop("CT");
		  if (ZIP2 >= 39 && ZIP2 <= 49)return showpop("ME");
		  if ((ZIP2 >= 10 && ZIP2 <= 27) || (ZIP == 55))return showpop("MA");
		  if (ZIP2 >= 30 && ZIP2 <= 38)return showpop("NH");
		  if ((ZIP2 >= 90 && ZIP <= 149) || (ZIP2 == 63) ) return showpop("NY");
          if (ZIP2 >= 70 && ZIP2 <= 89)return showpop("NJ");
          if (ZIP2 >= 28 && ZIP2 <= 29) return showpop("RI");
          if (ZIP2 >= 50 && ZIP2 <= 59) return showpop("VT");
		  if (ZIP2 >= 90 && ZIP2 <= 98) return showpop("AE");
		  return showpop('1');

  }
  else  if(zi.length=='3')
	  {
	   if (ZIP1 >= 6 && ZIP1 <= 9) return showpop("PR");
	   if (ZIP1 == 8) return showpop("VI");
       if(ZIP1 == 4 || ZIP1 == 5) return showpop("NY");
	   return showpop('1');

	  }
	  else{
		   if (ZIP >= 100 && ZIP <= 149)return showpop("NY");
if (ZIP >= 350 && ZIP <= 369)return showpop("AL");
if (ZIP >= 995 && ZIP <= 999)return showpop("AK");
if (ZIP >= 850 && ZIP <= 865)return showpop("AZ");
if ( (ZIP >= 716 && ZIP <= 729) || (ZIP == 755) )return showpop("AR");
//if (ZIP == 967)return showpop("AS");
if (ZIP >= 900 && ZIP <= 966)return showpop("CA");

if (ZIP >= 800 && ZIP <= 816)return showpop("CO");
if ((ZIP >= 220 && ZIP <= 246) || (ZIP == 201)) return showpop("VA");


if(ZIP >= 200 && ZIP <= 205)return showpop("DC");

if(ZIP >= 197 && ZIP <= 199)return showpop("DE");

if ((ZIP >= 320 && ZIP <= 349) && (ZIP != 343 && ZIP !=345 && ZIP!=348) )return showpop("FL");

if (ZIP >= 300 && ZIP <= 319)return showpop("GA");
if (ZIP == 969)return showpop("GU");

if (ZIP >= 967 && ZIP <= 968)return showpop("HI");

if (ZIP >= 832 && ZIP <= 838)return showpop("ID");

if (ZIP >= 600 && ZIP <= 629)return showpop("IL");

if (ZIP >= 460 && ZIP <= 479)return showpop("IN");

if (ZIP >= 500 && ZIP <= 528)return showpop("IA");

if (ZIP >= 660 && ZIP <= 679)return showpop("KS");

if (ZIP >= 400 && ZIP <= 427)return showpop("KY");

if (ZIP >= 700 && ZIP <= 714)return showpop("LA");



if (ZIP == 969)return showpop("MH");

if (ZIP >= 206 && ZIP <= 219)return showpop("MD");

if (ZIP >= 480 && ZIP <= 499)return showpop("MI");
if (ZIP >= 550 && ZIP <= 567)return showpop("MN");
if (ZIP >= 386 && ZIP <= 397)return showpop("MS");

if (ZIP >= 630 && ZIP <= 658)return showpop("MO");

if (ZIP >= 590 && ZIP <= 599)return showpop("MT");
if (ZIP >= 680 && ZIP <= 693)return showpop("NE");

if (ZIP >= 889 && ZIP <= 898)return showpop("NV");

if (ZIP >= 870 && ZIP <= 884)return showpop("NM");


if (ZIP >= 269 && ZIP <= 289) return showpop("NC");

if (ZIP >= 580 && ZIP <= 588) return showpop("ND");

if (ZIP == 969) return showpop("MP");

if (ZIP >= 430 && ZIP <= 458) return showpop("OH");
if ((ZIP >= 750 && ZIP <= 799 ) || (ZIP == 885) || (ZIP == 733) ) return showpop("TX");

if (ZIP >= 730 && ZIP <= 749) return showpop("OK");
if (ZIP >= 970 && ZIP <= 979) return showpop("OR");
if (ZIP >= 150 && ZIP <= 196) return showpop("PA");


if (ZIP >= 290 && ZIP <= 299) return showpop("SC");

if (ZIP >= 570 && ZIP <= 577) return showpop("SD");

if (ZIP >= 370 && ZIP <= 385) return showpop("TN");


if (ZIP >= 840 && ZIP <= 847) return showpop("UT");






if (ZIP >= 980 && ZIP <= 994) return showpop("WA");

if (ZIP >= 530 && ZIP <= 549) return showpop("WI");

if (ZIP >= 247 && ZIP <= 268) return showpop("WV");

if (ZIP >= 820 && ZIP <= 831) return showpop("WY");

return showpop('1');
//if (ZIP >= 340) return showpop("AA");

//if (ZIP >= 962 && ZIP <= 966) return showpop("AP");
  }
  }

function showpop(str)
{
//  alert(str);
var st='';
if(str=="AL"){
st =(83*30);
}
if(str=="AK"){
st =(111*30);
}
if(str=="AZ"){
st =(91*30);
}
if(str=="AR"){
st =(86*30);
}
if(str=="CA"){
st =(90*30);
}
if(str=="CO"){
st =(97*30);
}
if(str=="CT"){
st =(135*30);
}
if(str=="DE"){
st =(135*30);
}
if(str=="FL"){
st =(89*30);
}
if(str=="GA"){
st =(97*30);
}
if(str=="HI"){
st =(114*30);
}
if(str=="ID"){
st =(94*30);
}
if(str=="IL"){
st =(113*30);
}
if(str=="IN"){
st =(79*30);
}
if(str=="IA"){
st =(87*30);
}
if(str=="KS"){
st =(93*30);
}
if(str=="KY"){
st =(91*30);
}
if(str=="LA"){
st =(76*30);
}
if(str=="ME"){
st =(135*30);
}
if(str=="MD"){
st =(136*30);
}
if(str=="MA"){
st =(134*30);
}
if(str=="MI"){
st =(91*30);
}
if(str=="MN"){
st =(91*30);
}
if(str=="MS"){
st =(73*30);
}
if(str=="MO"){
st =(100*30);
}
if(str=="MT"){
st =(93*30);
}
if(str=="NE"){
st =(90*30);
}
if(str=="NV"){
st =(87*30);
}
if(str=="NH"){
st =(121*30);
}
if(str=="NJ"){
st =(146*30);
}
if(str=="NM"){
st =(84*30);
}
if(str=="NY"){
st =(98*30);
}
if(str=="NC"){
st =(99*30);
}
if(str=="ND"){
st =(58*30);
}
if(str=="OH"){
st =(101*30);
}
if(str=="OK"){
st =(83*30);
}
if(str=="OR"){
st =(94*30);
}
if(str=="PA"){
st =(89*30);
}
if(str=="RI"){
st =(105*30);
}
if(str=="SC"){
st =(87*30);
}
if(str=="SD"){
st =(66*30);
}
if(str=="TN"){
st =(99*30);
}
if(str=="TX"){
st =(100*30);
}
if(str=="UT"){
st =(79*30);
}
if(str=="VT"){
st =(113*30);
}
if(str=="VA"){
st =(114*30);
}
if(str=="WA"){
st =(88*30);
}
if(str=="WV"){
st =(97*30);
}
if(str=="WI"){
st =(102*30);
}
if(str=="WY"){
st =(81*30);
}
if(str=="DC"){
st =(138*30);
}
if(st!='' && document.getElementsByName("zip")[0].value!=''){
	document.getElementById("cost").innerHTML=st;
	 document.getElementById("cost1").style.display="";
}
else if(st!='' && document.getElementsByName("state")[0].value!=''){
	document.getElementById("cost2").innerHTML=st;
	 document.getElementById("cost3").style.display="";
}
else if (st=='' ){
	 document.getElementById("cost1").style.display="none";
	  document.getElementById("cost3").style.display="none";
}
}

function dd()
{
	//alert(document.getElementsByName("zip")[0].value.length);
if(document.getElementsByName("zip")[0].value.length=='5')
	{
	
	 var a=document.getElementsByName("zip")[0].value;
//	alert(getstateforzip(a));
		getstateforzip(a);
	}
}
// JavaScript Document