//********************************* Toggle content for application page *******************************************
function apptoggle()
{
    //**************************** Toggle existing insurance policy *************
    if($('#existingPolicyYes').attr('checked'))
    {
        document.getElementById("policyexists").style.display ="";
    }
    if($('#existingPolicyNo').attr('checked'))
    {
        document.getElementById("policyexists").style.display ="none";
      
        //clear the existing policy information if user clicks 'NO'
        //first policy
        document.forms[0].firstExistingPolicyCompanyName.value = "";
        document.forms[0].firstExistingPolicyIssueYear.value = "";
        document.forms[0].firstExistingPolicyCoverageAmount.value = "";
        document.forms[0].firstExistingPolicyNumber.value = "";
        //second policy
        document.forms[0].secondExistingPolicyCompanyName.value = "";
        document.forms[0].secondExistingPolicyIssueYear.value = "";
        document.forms[0].secondExistingPolicyCoverageAmount.value = "";
        document.forms[0].secondExistingPolicyNumber.value = "";
        //third policy
        document.forms[0].thirdExistingPolicyCompanyName.value = "";
        document.forms[0].thirdExistingPolicyIssueYear.value = "";
        document.forms[0].thirdExistingPolicyCoverageAmount.value = "";
        document.forms[0].thirdExistingPolicyNumber.value = "";
      
    }
   
    //*********************** Toggle content for owner information ************************
   
    //************ Toggle Premium payer information ******************************
    //Yes
    if($('#premiumPayerYes').attr('checked'))
    {
        
        document.getElementById("premiumpayer").style.display ="none";
      
        //clear the information if the client is the premium payer
        document.forms[0].premiumPayerName.value="";
        document.forms[0].premiumPayerAddress.value="";
        document.forms[0].premiumPayerCity.value="";
        document.forms[0].premiumPayerState.value="";
        document.forms[0].premiumPayerZipCode.value="";
        document.forms[0].premiumPayerPhone.value="";
        document.forms[0].premiumPayerTaxID.value="";
    }
    //NO
    if($('#premiumPayerNo').attr('checked'))
    {
        document.getElementById("premiumpayer").style.display ="";
    }
    
    //************ Toggle Business information ******************************
    if($('#businessInsuranceYes').attr('checked'))
    {
        document.getElementById("businessinsurance").style.display ="";
    }
    if($('#businessInsuranceNo').attr('checked'))
    {
        document.getElementById("businessinsurance").style.display ="none";
      
        //clear business information is client checks 'NO'
        document.forms[0].percentageOfBusinessOwned.value="";
        document.forms[0].businessAnnualIncome.value="";
        document.forms[0].businessNetworth.value="";
        document.forms[0].yearBusinessEstablished.value="";
      
        //Set key people covered to 'NO'
        document.forms[0].areKeyPeopleCovered[1].checked = true;
    }
   
    //************ Toggle Key People information ******************************
    if($('#keyPeopleYes').attr('checked'))
    {
        document.getElementById("keypeople").style.display ="";
    }
    if($('#keyPeopleNo').attr('checked'))
    {
        document.getElementById("keypeople").style.display ="none";
      
        //clear the information for key people
        //first person
        document.forms[0].firstKeyPersonName.value="";
        document.forms[0].percentageOwnedByFirstKeyPerson.value="";
        document.forms[0].firstKeyPersonInsuranceCompany.value="";
        document.forms[0].firstKeyPersonCoverageAmount.value="";
        //second person
        document.forms[0].secondKeyPersonName.value="";
        document.forms[0].percentageOwnedBySecondKeyPerson.value="";
        document.forms[0].secondKeyPersonInsuranceCompany.value="";
        document.forms[0].secondKeyPersonCoverageAmount.value="";
        //third person
        document.forms[0].thirdKeyPersonName.value="";
        document.forms[0].percentageOwnedByThirdKeyPerson.value="";
        document.forms[0].thirdKeyPersonInsuranceCompany.value="";
        document.forms[0].thirdKeyPersonCoverageAmount.value="";
      
    }

    //************ Toggle Illustration ****************************************
    if($('#illustrationYes').attr('checked'))
    {
        document.getElementById("illustrationDiv").style.display="";
    }
    if($('#illustrationNo').attr('checked'))
    {
        document.getElementById("illustrationDiv").style.display="none";
        document.getElementById("illustrationProvidedBy").value="";
    }

   
}

function ownertoggle()
{
    //No
    if($('#policyOwnerNo').attr('checked'))
    {
        document.getElementById("ownerinfo").style.display ="";
        document.getElementById("trustQuestion").style.display = "";
        document.getElementById("otrusts").style.display =""; 
    }
    //Yes
    if($('#policyOwnerYes').attr('checked'))
    {
        document.getElementById("ownerinfo").style.display ="none";
        document.getElementById("otrusts").style.display = "none";
        document.getElementById("trustQuestion").style.display = "none";
      
        document.forms[0].isPolicyForTrust[1].checked = true;
      
      
        //clear the owner information if user checks 'Yes'
        document.forms[0].policyOwnerFirstName.value="";
        document.forms[0].policyOwnerLastName.value="";
        document.forms[0].policyOwnerMiddleInitial.value="";
        document.forms[0].policyOwnerSSN.value="";
        document.forms[0].policyOwnerRelationship.value="";
        document.forms[0].policyOwnerHomePhone.value="";
        document.forms[0].policyOwnerWorkPhone.value="";
      
      
        //clear the trust information if use checks 'NO'
        document.forms[0].policyTrustName.value="";
        document.forms[0].policyTrustTaxID.value="";
        document.forms[0].policyTrustTrustee.value="";
        document.forms[0].policyTrustDate.value="";
    }
   
    //************ Toggle owner trust information ******************************
    if($('#policyForTrustYes').attr('checked'))
    {
        document.getElementById("otrusts").style.display ="";
      
        document.getElementById("ownerinfo").style.display ="none";
      
        //clear the owner information if user checks 'Yes'
        document.forms[0].policyOwnerFirstName.value="";
        document.forms[0].policyOwnerLastName.value="";
        document.forms[0].policyOwnerMiddleInitial.value="";
        document.forms[0].policyOwnerSSN.value="";
        document.forms[0].policyOwnerRelationship.value="";
        document.forms[0].policyOwnerHomePhone.value="";
        document.forms[0].policyOwnerWorkPhone.value="";
      
    }
    if($('#policyForTrustNo').attr('checked'))
    {
        document.getElementById("otrusts").style.display ="none";
      
        //clear the trust information if use checks 'NO'
        document.forms[0].policyTrustName.value="";
        document.forms[0].policyTrustTaxID.value="";
        document.forms[0].policyTrustTrustee.value="";
        document.forms[0].policyTrustDate.value="";
    } 
    
}
function writeCookies()
{
    if(document.forms[0].agentCookieCheckbox != null && document.forms[0].agentCookieCheckbox.checked == true)
    {
        var expireDate = new Date();
        expireDate.setDate(expireDate.getDate()+100000);
        if (document.forms[0].agentFirstName != null) {
            document.cookie="agentFirstName="+document.forms[0].agentFirstName.value+";expires="+expireDate.toGMTString();
            document.cookie="agentLastName="+document.forms[0].agentLastName.value+";expires="+expireDate.toGMTString();
            document.cookie="agentPhoneNumber="+document.forms[0].agentPhoneNumber.value+";expires="+expireDate.toGMTString();
            document.cookie="agentEmail="+document.forms[0].agentEmail.value+";expires="+expireDate.toGMTString();
            document.cookie="checkbox=checked;expires="+expireDate.toGMTString();
        }
    }
    else
    {
        expireDate = new Date();
        expireDate.setDate(-1);

        if (document.forms[0].agentFirstName != null) {
            document.cookie="agentFirstName="+document.forms[0].agentFirstName.value+";expires="+expireDate.toGMTString();
            document.cookie="agentLastName="+document.forms[0].agentLastName.value+";expires="+expireDate.toGMTString();
            document.cookie="agentPhoneNumber="+document.forms[0].agentPhoneNumber.value+";expires="+expireDate.toGMTString();
            document.cookie="agentEmail="+document.forms[0].agentEmail.value+";expires="+expireDate.toGMTString();
            document.cookie="checkbox=checked;expires="+expireDate.toGMTString();
        }
    }
}

function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)
        { 
            c_start=c_start + c_name.length+1; 
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        } 
    }
    return "";
}

function getCookieValue()
{
    if(getCookie("checkbox") == "checked")
    {
        document.forms[0].agentFirstName.value = getCookie("agentFirstName");
        document.forms[0].agentLastName.value = getCookie("agentLastName");
        document.forms[0].agentPhoneNumber.value = getCookie("agentPhoneNumber");
        document.forms[0].agentEmail.value = getCookie("agentEmail");
        if (document.forms[0].agentCookieCheckbox != null) {
            document.forms[0].agentCookieCheckbox.checked=true;
        }
    }
}

