﻿
var intTotal            = 0;

function totalEmployees()
{
    var objEmployee         = document.getElementById("QuoteCntl_txtEmployee");
    var objEmpSpouse        = document.getElementById("QuoteCntl_txtEmpSpouse");
    var objEmpChildren      = document.getElementById("QuoteCntl_txtEmpChildren");
    var objEmpFamily        = document.getElementById("QuoteCntl_txtEmpFamily");
    var objTotalEmployees   = document.getElementById("QuoteCntl_txtTotalEmployees");
    var intEmployee   = 0;
    var intEmpSpouse   = 0;
    var intEmpChildren = 0;
    var intEmpFamily   = 0;
    var strEmployee   = 0;
    var strEmpSpouse   = 0;
    var strEmpChildren = 0;
    var strEmpFamily   = 0;
    
    
    if(objEmployee != null)
    {
        strEmployee     = objEmployee.value;
        if(strEmployee != ""  && isWholeNumber(strEmployee))
        {
            intEmployee = parseInt(strEmployee,10);
        }
    }
    if(objEmpSpouse != null)
    {
        strEmpSpouse    = objEmpSpouse.value;
        if(strEmpSpouse != ""  && isWholeNumber(strEmpSpouse))
        {
            intEmpSpouse = parseInt(strEmpSpouse,10);
        }
    }
    if(objEmpChildren != null)
    {
        strEmpChildren  = objEmpChildren.value;
        if(strEmpChildren != ""  &&  isWholeNumber(strEmpChildren))
        {
            intEmpChildren = parseInt(strEmpChildren,10);
        }
    }
    if(objEmpFamily != null)
    {
        strEmpFamily    = objEmpFamily.value;
        if(strEmpFamily != "" && isWholeNumber(strEmpFamily))
        {
            intEmpFamily = parseInt(strEmpFamily,10);
        }
    }
    intTotal = intEmployee + intEmpSpouse + intEmpChildren + intEmpFamily;
    if(objTotalEmployees != null)
    {
        objTotalEmployees.value = intTotal;
    }
    
    return intTotal;
    
}

function isWholeNumber(strNumber)
{
    for (i = 0; i < strNumber.length; i++) {
        ch = strNumber.substring(i, i+1);
        if (ch < "0" || ch > "9")
          {          
            return false;
          }
    }
    return true;
}

function fieldsValidation()
{
    var objZip              = document.getElementById("QuoteCntl_txtZipCode");
    var objOrthodontia      = document.getElementById("QuoteCntl_radOrthodontia_1");
    var objEmployee         = document.getElementById("QuoteCntl_txtEmployee");
    var objEmpSpouse        = document.getElementById("QuoteCntl_txtEmpSpouse");
    var objEmpChildren      = document.getElementById("QuoteCntl_txtEmpChildren");
    var objEmpFamily        = document.getElementById("QuoteCntl_txtEmpFamily");
    var objSICCode          = document.getElementById("QuoteCntl_txtSICCode");
    var objCustomerName     = document.getElementById("QuoteCntl_txtCustomerName");


    var strZip = "";
    var strSICCode = "";
    var blnOrthodontia;
    var strErrorSummary = "";
    
    if(objOrthodontia != null)
    {
        blnOrthodontia = objOrthodontia.checked;
        if(blnOrthodontia && intTotal <10)
        {
            strErrorSummary +=  "<font color='#ff0000'><B>For Orthodontia, you must specify 10 or more total employees.</B></font>&nbsp; ";
            strErrorSummary +=  "If you have any questions, please contact your UnitedHealthcare Specialty Benefits Account Executive.<br>";
        }
    }
    if (intTotal <= 1)
    {
        strErrorSummary +=  "<font color='#ff0000'><B>You must specify more than 1 total employees.</B></font>&nbsp; ";
        strErrorSummary +=  "If you have any questions, please contact your UnitedHealthcare Specialty Benefits Account Executive.<br>";
    }
    if (intTotal >= 100)
    {
        strErrorSummary +=  "<font color='#ff0000'><B>For a Rate Quote for 100 or more total employees,</B></font>&nbsp; ";
        strErrorSummary +=  "please contact your UnitedHealthcare Specialty Benefits Account Executive.<br>";
    }
    if(objZip != null)
    {
        strZip = objZip.value;
        
        if(strZip == "" || strZip.length <5 ||!isWholeNumber(strZip))
            strErrorSummary +=  "<font color='#ff0000'><B>You must enter a valid 5 digit Zip Code.</B></font><br>";
    }    
    if(objSICCode != null)
    {
        strSICCode = objSICCode.value
        if(strSICCode == "" )
        {
          strErrorSummary +=  "<font color='#ff0000'><B>You must enter a valid 4 digit SIC Code.</B></font><br>";  
        }
    }
     var blnSubscribers = true;
    
     if(objEmployee != null && !isWholeNumber(objEmployee.value) )
     {
        blnSubscribers = false;        
     }
     if(objEmpSpouse != null && !isWholeNumber(objEmpSpouse.value) )
     {
        blnSubscribers = false;      
     }
     if(objEmpChildren != null && !isWholeNumber(objEmpChildren.value) )
     {
         blnSubscribers = false;  
     }
     if(objEmpFamily !=null &&  !isWholeNumber(objEmpFamily.value) )
     {
         blnSubscribers = false;     
     }
     
     if(!blnSubscribers)
     {
        strErrorSummary +=  "<font color='#ff0000'><B>You must enter valid whole numbers for number of subscribers.</B></font><br>";
     }
  
    if(strErrorSummary != "")
    {
        document.getElementById("paraError").style.display = "block";
        document.getElementById("divShowError").innerHTML  = strErrorSummary ;//+ "<br>";
        if(document.getElementById("QuoteCntl_pnlError") != null)
        {
            document.getElementById("QuoteCntl_pnlError").style.display = "none";
        }       
        return false;
    }
    else
    {
        document.getElementById("paraError").style.display = "none";
        document.getElementById("divShowError").innerText  = "";
        showPrintPdfEmail();
        return true;
    }
    
}

function showPrintPdfEmail()
{
    var objPrint = document.getElementById("QuoteCntl_btnPrintQuote");
    var objPdf   = document.getElementById("QuoteCntl_btnDownloadPDF");
    var objEmail = document.getElementById("QuoteCntl_btnEmailQuote"); 
    
     if(objPrint != null)
     {
       objPrint.style.display   ="block";
     } 
       
     if(objPdf != null)
     {
        objPdf.style.display    ="block";
     } 
     
     if(objEmail != null)
     {
        objEmail.style.display  ="block";
     }          
}

function hidePrintPdfEmail()
{
    var objPrint = document.getElementById("QuoteCntl_btnPrintQuote");
    var objPdf   = document.getElementById("QuoteCntl_btnDownloadPDF");
    var objEmail = document.getElementById("QuoteCntl_btnEmailQuote"); 
    var objpnlPostQuote = document.getElementById("QuoteCntl_pnlPostQuote"); 
    

     if(objPrint != null)
     {
       objPrint.style.display   =   "none";
     } 
       
     if(objPdf != null)
     {
        objPdf.style.display    =   "none";
     } 
     
     if(objEmail != null)
     {
        objEmail.style.display  =   "none";
     }       
     if(objpnlPostQuote != null)
     {
        objpnlPostQuote.style.display  =   "none";
     }      
}

function printPage()
{
	var objHTM = document.getElementById("QuoteCntl_hdnHTMLCode");
	var strHTM = "";
	if(objHTM !=null)
	stHTM = objHTM.value;
    
    printWindow = window.open("","printWindow","status=no,scrollbars=yes,width=640,height=500");
    if(navigator.appName.indexOf("Netscape") != -1) 
    {
        stHTM += ('<scr'+'ipt language="javascript">'+'window.print()'+'</scr'+'ipt>');
        printWindow.document.writeln(stHTM)
        printWindow.focus();
        printWindow.print()
        printWindow.document.close();
        printWindow.document = null;
        printWindow.close();
        printWindow = null;
    } 
    else 
    {
        if(this.ie4 ){stHTM += ('\r<scr'+'ipt language="javascript">\r'+'alert("In IE4.0 you must right click and select print, then close window.")\r'+'</scr'+'ipt>\r');}
        stHTM += ('<scr'+'ipt language="javascript">'+'window.print()'+'</scr'+'ipt>');
        printWindow.focus();
        printWindow.document.writeln(stHTM)
        printWindow.document.close();   
        printWindow.close();     
    }

}

function openWarningWindow()
{
 if( confirm("Proceed to Online Application?"))
  return true;
 else
  return false;
}

function openConfirmationPageWindow(strPlanID)
{
    var objCustomerName         = document.getElementById("QuoteCntl_txtCustomerName");
    var objMonth                = document.getElementById("QuoteCntl_ddlEffectiveMonth");
    var objYear                 = document.getElementById("QuoteCntl_ddlEffectiveYear");
    var objZipCode              = document.getElementById("QuoteCntl_txtZipCode");
    var objOrtho                = document.getElementById("QuoteCntl_radOrthodontia_1");
    var objDental               = document.getElementById("QuoteCntl_radDentalBenefit_1");
    var objWWP                  = document.getElementById("QuoteCntl_radWaivePeriod_1");
    var objRenewal              = document.getElementById("QuoteCntl_radRenewal_1");
    var objEmployee             = document.getElementById("QuoteCntl_txtEmployee");
    var objEmpSpouse            = document.getElementById("QuoteCntl_txtEmpSpouse");
    var objEmpChildren          = document.getElementById("QuoteCntl_txtEmpChildren");
    var objEmpFamily            = document.getElementById("QuoteCntl_txtEmpFamily");
    var objSicCode              = document.getElementById("QuoteCntl_txtSICCode");
  	 var strHTM                  = "";

    var strOrtho   = 'N';
    var strDental  = 'N';
    var strWWP     = 'N';
    var strRenewal = 'N';

    if(objOrtho.checked)
     strOrtho  = 'Y';
    if(objDental.checked)
     strDental = 'Y'; 
    if(objWWP.checked)
     strWWP    = 'Y';
 if (objRenewal != null &&  objRenewal.checked)
     strRenewal    = 'Y';

      
    /* Add a business rule that if Waive Waiting Period is selected as a buy-up,
    then the group must choose either a Contrib. Elite or Contrib. Preferred 
    plan */

    if (strWWP == 'N' || strPlanID == 1 || strPlanID == 2) {
        strHTM = 'CustName=' + escape(objCustomerName.value) + '&Month=' + objMonth.value + '&Year=' + objYear.value + '&Zip=' + objZipCode.value + '&Ortho=' + strOrtho + '&Dental=' + strDental + '&WWP=' + strWWP + '&Employee=' + objEmployee.value + '&EmpSpouse=' + objEmpSpouse.value + '&EmpChildren=' + objEmpChildren.value + '&EmpFamily=' + objEmpFamily.value + '&SICCode=' + objSicCode.value + '&PlanID=' + strPlanID+"&Renewal="+strRenewal;
    location.href = 'Confirmation.aspx?' + strHTM;
    }
    else {
    alert('If Waive Waiting Period is selected as a buy-up, then \n the group must choose either a Contributory Elite or Contributory Preferred plan.')
    } 
 
}
