//---------------------------------------------------------------------------------------
// 1999 - 2008 (c) Total Travel Insurance
//---------------------------------------------------------------------------------------

function Validate_health()
{
//.......................................................................................
//... 1. Applicant's zip code.
//.......................................................................................
	if (document.QuoteHealth.txt_primary_zip.value < 0 || document.QuoteHealth.txt_primary_zip.value == "")
	{
        alert("Please enter valid 'Zip Code'.");
        document.QuoteHealth.txt_primary_zip.focus();
        return (false);
	}

	var l_zip = /^\d{5}$/;
	
	if (document.QuoteHealth.txt_primary_zip.value.search(l_zip) == -1)
	{
        alert("Please enter complete 'Zip Code'.");
        document.QuoteHealth.txt_primary_zip.focus();
        return (false);
	}
//.......................................................................................
//... 3. Validate all dates.
//.......................................................................................
    if (!IsDate(document.QuoteHealth.txt_cov_start_date.value))
    {
        alert("Please input valid 'Coverage Start Date'.");
        document.QuoteHealth.txt_cov_start_date.focus();
        return (false);
    }
    
    var l_cov_start_date = new Date(document.QuoteHealth.txt_cov_start_date.value);

//.......................................................................................
    if (document.QuoteHealth.txt_pay_option[1].checked == true)
	{
		if (!IsDate(document.QuoteHealth.txt_cov_end_date.value))
		{
			alert("Please input valid 'Coverage End Date'.");
			document.QuoteHealth.txt_cov_end_date.focus();
			return (false);
		}
	    
		var l_cov_end_date = new Date (document.QuoteHealth.txt_cov_end_date.value);
	}
//.......................................................................................
//... 3b. Validate departure date vs. today.
//.......................................................................................
	var l_app_date = new Date();

	var w_depart_date;
	var w_app_date;
	
	w_depart_date = l_cov_start_date.getFullYear();
	
	if (l_cov_start_date.getMonth() < 9)	w_depart_date = w_depart_date + '/0' + (l_cov_start_date.getMonth() + 1)
	else									w_depart_date = w_depart_date + '/'  + (l_cov_start_date.getMonth() + 1);
	
	if (l_cov_start_date.getDate() < 10)	w_depart_date = w_depart_date + '/0' + l_cov_start_date.getDate()
	else									w_depart_date = w_depart_date + '/'  + l_cov_start_date.getDate();
	
	w_app_date = l_app_date.getFullYear();
	
	if (l_app_date.getMonth() < 9)		w_app_date = w_app_date + '/0' + (l_app_date.getMonth() + 1)
	else								w_app_date = w_app_date + '/'  + (l_app_date.getMonth() + 1);
	
	if (l_app_date.getDate() < 10)		w_app_date = w_app_date + '/0' + l_app_date.getDate()
	else								w_app_date = w_app_date + '/'  + l_app_date.getDate();
    
    if (w_depart_date < w_app_date)
    {
        alert("'Coverage Start Date' cannot be prior to Today.");
        document.QuoteHealth.txt_cov_start_date.focus();
        return (false);
    }

	if (l_app_date.getHours() > 21)
	{
		if (w_depart_date == w_app_date)
	    {
	        alert("'Coverage Start Date' cannot be prior to today.");
	        document.QuoteHealth.txt_cov_start_date.focus();
	        return (false);
	    }
    }
//.......................................................................................
//... 3c. Validate return date vs. departure date.
//.......................................................................................
    if (document.QuoteHealth.txt_pay_option[1].checked == true)
	{
		if (l_cov_end_date.valueOf() < l_cov_start_date.valueOf())
		{
			alert("'Coverage Start Date' cannot be after 'Coverage End Date'.");
			document.QuoteHealth.txt_cov_end_date.focus();
			return (false);
		}
	}
//.......................................................................................
//... 4. Validate Applicant's Date of Birth.
//.......................................................................................
    if (!IsDate(document.QuoteHealth.txt_primary_dob.value))
    {
        alert("Please input valid 'Applicant's Date of Birth'.");
        document.QuoteHealth.txt_primary_dob.focus();
        return (false);
    }
//.......................................................................................
	return (true);
}
//.......................................................................................
//... Single/monthly payment options.
//.......................................................................................

function pay_option_change()
{
    if (document.QuoteHealth.txt_pay_option[0].checked == true)
    {
            document.getElementById("lbl_cov_end").style.visibility = "hidden";
            document.getElementById("lbl_cov_end2").style.visibility = "hidden";
            document.getElementById("lbl_cov_end3").style.visibility = "hidden";
    }
    if (document.QuoteHealth.txt_pay_option[1].checked == true)
    {
            document.getElementById("lbl_cov_end").style.visibility = "visible";
            document.getElementById("lbl_cov_end2").style.visibility = "visible";
            document.getElementById("lbl_cov_end3").style.visibility = "visible";
   }	
}
//---------------------------------------------------------------------------------------
