var mydate= new Date()

chk1="1234567890-";

var day_31 = new Array(1,3,5,7,8,10,12);

function showAge(dob){
	
var d =dob.split('/');
var now=new Date();
var today=new Date(now.getFullYear(),now.getMonth()+1,now.getDate());

var bday=new Date(d[2],d[0],d[1]);
var by=bday.getFullYear();
var bm=bday.getMonth();
var bd=bday.getDate();
/*age=today.getFullYear()-by;
alert(now.getMonth());
if(bm>today.getMonth()){age=age-1;}
alert(age);
return age;*/
var age=0;
var dif=bday;
if(dif>today){return -10;}
while(dif<=today){
var dif = new Date(by+age,bm,bd);
age++;
}
age +=-2 ;
return age;
} 

function agec()
{
	if(document.frmlist.t1.value!="" && document.frmlist.t2.value!="" && document.frmlist.t3.value!="")
	{
		var apdob=document.frmlist.t2.value+'/'+document.frmlist.t1.value+'/'+document.frmlist.t3.value;
		document.frmlist.sAge.value=showAge(apdob);
	}
	//return true;
}

function isNumber(val,msg)
{

	//alert(val.value.length);

	for(i=0;i < val.value.length;i++)
	{
		ch1=val.value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
		{
			alert(msg);
			val.focus();
			return false;
		}

	}
	return true;

}

function check_medicare()
{

	if(document.frmlist.sSex.options[document.frmlist.sSex.selectedIndex].value=="")
	{
		alert("Please Select Applicant's Gender");
		document.frmlist.sSex.focus();
		return false;
	}
	if(document.frmlist.t1.value=="")
	{
		alert("Please Enter Applicant's Date of Birth");
		document.frmlist.t1.focus();
		return false;
	}
	if(document.frmlist.t2.value=="")
	{
		alert("Please Enter Applicant's Month of Birth");
		document.frmlist.t2.focus();
		return false;

	}
	if(document.frmlist.t3.value=="")	
	{
		alert("Please Enter Applicant's Year of Birth");
		document.frmlist.t3.focus();
		return false;
	}
	
	

	if(document.frmlist.t1.value > 12 || document.frmlist.t1.value <1) 
		{alert("Please Enter valid Month between 1 to 12 !"); document.frmlist.t1.focus(); return false;}

	var day = 0;
	if(document.frmlist.t1.value != 0 )
	{	

		var count = 0;
		for(i=0;i< day_31.length;i++)
		{

			//alert(day_31[i]);
			if(document.frmlist.t1.value == day_31[i])
				{day = 31;break;}

			else if(document.frmlist.t1.value == 2)
				{day = 28;break;}
			
		}
		if(day==0){day=30;}
		//alert(day);

	}


		


	if(document.frmlist.t2.value < 1 || document.frmlist.t2.value > day)
		{alert("Please Enter valid Day Between 1 to "+day); document.frmlist.t2.focus(); return false;}

	if(!isNumber(document.frmlist.t3,"Please Enter Number in Year Field!"))
		{return false;}

	else if(document.frmlist.t3.value.length < 4)
		{alert("Please Enter Valid Year !"); document.frmlist.t3.focus(); return false;}
		
	/*var apdob=document.frmlist.t1.value+'/'+document.frmlist.t2.value+'/'+document.frmlist.t3.value;
	var apage=showAge(apdob);
	if(apage<65 || apage>99)
	{
		alert("Please Enter Applicant's Age Between 65 - 99");
		document.frmlist.t1.focus();
		return false;
	
	}*/
	if(document.frmlist.sAge.value=="")	
	{
		alert("Please Enter Applicant's Age");
		document.frmlist.sAge.focus();
		return false;
	}
	
	if(document.frmlist.sAge.value < 65 || document.frmlist.sAge.value > 99)
	{
		alert("Please Enter Applicant's Age Between 65 - 99");
		document.frmlist.sAge.focus();
		return false;
	
	}
	if(document.frmlist.zipCode.value=="")
	{
		alert("Please Enter ZIP Code");
		document.frmlist.zipCode.focus();
		return false;
	}	
	if(document.frmlist.zipCode.value!="")
	{
		if(document.frmlist.zipCode.value > 96162)
		{
			alert("PLEASE ENTER A CA ZIP CODE !");
			document.frmlist.zipCode.focus();	
			return false;
		}

		if(document.frmlist.zipCode.value < 90001)
		{

			alert("PLEASE ENTER A CA ZIP CODE !");
			document.frmlist.zipCode.focus();	
			return false;
		}

	}	
}


function check(value,length){

//	alert(value);

	var v=0;

	var j= 0;

	var k=0;

	//alert(document.frmlist.radiobutton[3].value);

	for (var i=0; i < document.frmlist.radiobutton.length; i++)

   	{

		if (document.frmlist.radiobutton[i].checked==true)

       	{	v = v + 1;}

		if(document.frmlist.radiobutton[4].checked==true)

		{

			for(k=0;k< document.frmlist.radiobutton.length; k++)

			{

				if(document.frmlist.radiobutton4[0].checked==true){	j = 1; }

				if(document.frmlist.radiobutton4[1].checked==true){	j = 1; }

			}

		}

	}			

		if(v<="0")

		{

			alert("Please Select Any One Option!");

			document.frmlist.radiobutton4[0].focus();			

			return false;

		}

		

		if(k > "0" && j==0)

		{

			alert("Please Select Any Sub Option!");

			document.frmlist.radiobutton4[0].focus();
			
			document.frmlist.radiobutton1.focus();

			return false;

		}

   	if(value!="")

	{

	//	

	//}

		

		chk1="1234567890-";

		for(i=0;i<length;i++)

		{

			ch1=value.charAt(i);

			rtn1=chk1.indexOf(ch1);

			if(rtn1==-1)

			{

				alert("PLEASE ENTER A CA ZIP CODE !");

				document.frmlist.textfield.focus();	

				return false;

			}
			
            
			   
			//if(value > '96162')
//
//			{
//
//				alert("PLEASE ENTER A CA ZIP CODE !");
//
//				document.frmlist.textfield.focus();	
//
//				return false;
//
//			}
//             
//			if(value < '90001')
//
//			{
//
//				alert("PLEASE ENTER A CA ZIP CODE !");
//
//				document.frmlist.textfield.focus();	
//
//				return false;
//
//			}

		}

		

	}

	else

		{

			alert("Please Enter ZIP Code");

			document.frmlist.textfield.focus();

			return false;

		}

	//alert(document.getElementsByTagName("t1").classname );
          if(value>0)
			  {
				  
				$.ajax({
				type: "POST",
				url: "chkZipCode.php",
				data: {
				'value' : value
				},
				success: function(Msg){
					
					
					if(Msg == "true")
					{				
						if(document.frmlist.radiobutton[0].checked==true)
						window.location = 'PPO-Plans-HMO-Plans.php?page=1&zip='+value;
						
						if(document.frmlist.radiobutton[1].checked==true)
						window.location = 'dental-insurance.php?page=8&zip='+value;
						
						
						if(document.frmlist.radiobutton[2].checked==true)
						window.location = 'HSA-Compatible-Health-Plans.php?page=2&zip='+value;
						
						if(document.frmlist.radiobutton[3].checked==true)
						window.location = 'Medicare-Supplement-Plans.php?page=3&zip='+value;
						
						
						
						if(document.frmlist.radiobutton[4].checked==true)
						{
						if(document.frmlist.radiobutton4[0].checked==true)
						
						window.location = 'Small-Business-Health-Insurance.php?page=4';
						
						if(document.frmlist.radiobutton4[1].checked==true)
						
						window.location = 'Large-Group-Employee-Benefits.php?page=5';
						
						}
					return true;
					
					} else {
						
						 alert("PLEASE ENTER A CA ZIP CODE !");
											
						return false;
						
					}
				
				
				}
				
			   
			   });return false;
								 
			   }
			   else
			   {
				   alert("PLEASE ENTER A CA ZIP CODE !");
				    return false;
			   }
			   
	
}