// JavaScript Document


function display() {
		//var theform;
		/*if(navigator.appName.toLowerCase().indexOf("netscape") > -1)
			{ theform=document.forms["SendMe"];
			 }
		else { theform=document.SendMe;
		     }  */
//			 alert(theform);
//alert(navigator.appName);		
effstr=document.SendMe.effdate.value;
expstr=document.SendMe.expdate.value;
if (isValidDate(effstr) != true) {
  return false;
 }
if (isValidDate(expstr) != true) {
 return false;
 }

if(expstr.length<10 || effstr.length<10)
{ alert("Required date format: MM/DD/YYYY, i.e. 01/01/2005");
  return false;
 }

yreffstr=effstr.substring(6,10);
yrexpstr=expstr.substring(6,10);	
moneffstr=effstr.substring(0,2);	
monexpstr=expstr.substring(0,2);
dayeffstr=effstr.substring(3,5);
dayexpstr=expstr.substring(3,5);
if (moneffstr.substring(0,1)==0)
   moneffstr=moneffstr.substring(1,2);
if (monexpstr.substring(0,1)==0)
   monexpstr=monexpstr.substring(1,2);
   
if (dayeffstr.substring(0,1)==0)
   dayeffstr=dayeffstr.substring(1,2);
if (dayexpstr.substring(0,1)==0)
   dayexpstr=dayexpstr.substring(1,2);

daydiff=parseInt(dayexpstr)-parseInt(dayeffstr);
mondiff=parseInt(monexpstr)-parseInt(moneffstr);
yrdiff=parseInt(yrexpstr)-parseInt(yreffstr);
if (yrdiff >1) {
alert("you cannot buy more than 12 months insurance");
document.SendMe.expdate.focus();
return false;

}

if ((yrdiff >=1 && mondiff >0) || (yrdiff >=1 && mondiff ==0 && daydiff>=0))
{
  alert("you cannot buy more than 12 months insurance");
  document.SendMe.expdate.focus();
  return false;
  }
if ((yrdiff <1 && mondiff <0) || yrdiff <0) {
  alert("expiration date cannot be earlier than effective date");
  document.SendMe.expdate.focus();
  return false;
  }
if (yrdiff==1) {
  if (parseInt(monexpstr)<= parseInt(moneffstr))
 	nummon=12-parseInt(moneffstr)+parseInt(monexpstr);
  else
    nummon=parseInt(monexpstr)-parseInt(moneffstr)+1;
	}
else 
   { if (yrdiff==0 && parseInt(monexpstr) > parseInt(moneffstr))
 		nummon=parseInt(monexpstr) - parseInt(moneffstr)-1;
 	}
	
calday=assignday(parseInt(moneffstr), parseInt(yreffstr));
expcalday=assignday(parseInt(monexpstr), parseInt(yrexpstr));	
if ( yrdiff==1 ) {
    
    if (parseInt(dayexpstr) <= parseInt(dayeffstr)) {
    //	calday=assignday(parseInt(moneffstr), parseInt(yreffstr));
		if ((calday-parseInt(dayeffstr)+1+parseInt(dayexpstr)) >15)
			{nummon=nummon;
			//if (calday==parseInt(dayeffstr) && ((calday-parseInt(dayeffstr)+1+parseInt(dayexpstr)) !=expcalday))
			//	rate_15day=1;
			//else
				rate_15day=0; }
		else
	 		{nummon=nummon-1;
			rate_15day=1; }
		}
	else {  if ( parseInt(dayexpstr)-parseInt(dayeffstr)+1 >15)
				{ nummon=nummon+1;
				  rate_15day=0; }
			else { //if ((calday==parseInt(dayeffstr)) && (expcalday==parseInt(dayexpstr)))
						//handle end of month
					//	{ nummon=nummon; 
					//	  rate_15day=0; }
				  //else 
				  rate_15day=1; 
				  }
	      } 
}
else  { if (yrdiff==0) 
		  { if (parseInt(monexpstr) >  parseInt(moneffstr)) {
		  	  if (parseInt(dayexpstr) <= parseInt(dayeffstr))
	    		{	calday=assignday(parseInt(moneffstr), parseInt(yreffstr));
						if  ((calday-parseInt(dayeffstr)+parseInt(dayexpstr)+1) >15)
	    					{ nummon=nummon+1;
							 // if (calday==parseInt(dayeffstr) && ((calday-parseInt(dayeffstr)+1+parseInt(dayexpstr)) !=expcalday)) 
							//		rate_15day=1;
		 	  				 // else
							  		rate_15day=0; }
	  		 			else
						//count one 15 days
						rate_15day=1;
		 		}
			 else
			    { if ( parseInt(dayexpstr)-parseInt(dayeffstr)+1 >15)
					{ nummon=nummon+2;
				  	rate_15day=0; }
				  else  {
				  		 nummon=nummon+1;
						 //handle endofmonth case
						// if ((calday==parseInt(dayeffstr)) && (expcalday==parseInt(dayexpstr)))
						 //	rate_15day=0;
						// else
				            rate_15day=1;
						 }
	       		}   }
		   else {   //handle case same month/same year
		   			if ( parseInt(dayexpstr)-parseInt(dayeffstr)+1 >15)
						{ nummon=1;
						  rate_15day=0; }
					else { nummon=0;
							rate_15day=1; }
				  }
		  }
		
		
				
	}
	if (parseInt(dayexpstr)==parseInt(dayeffstr))
			rate_15day=1;
	if( (parseInt(dayexpstr)==expcalday) && (parseInt(dayeffstr)==calday))
			rate_15day=1; 
	var arr=new Array(2);
		arr[0]=nummon;
		arr[1]=rate_15day;
		return arr;  
}
