/* This function sets the requested componentId(s) for SDC Logging purposes.  */
/* This function is currently called by the anonymous onsubmit event handler. */
/* It MUST be called before the form's inline onSubmit handlers are called.   */
function setComponentId(form) {
    var sdcTags = form.getAttribute("sdcTags");
    if(typeof sdcTags == 'undefined') {
        return;
    }
    if(typeof sdcTags == null) {
        return;
    }
    if(typeof sdcTags == "") {
        return;
    }
    var componentId = "";
    for(var i=0; i<form.elements.length; i++) {
        if(form.elements[i].type == 'checkbox') {
            if(form.elements[i].checked) {
                if(componentId != "") {
                    componentId += ";";
                }
                if(form.elements[i].value == "/zetia/hcp/documents/GoalTracker.pdf") {
                    componentId += "20653019(4)";
                }
                else if(form.elements[i].value == "/zetia/hcp/documents/DietTips.pdf") {
                    componentId += "20653019(2)";
                }
                else if(form.elements[i].value == "/zetia/hcp/documents/ExerciseTips.pdf") {
                    componentId += "20653019(3)";
                }
            }
        }
    }
    sdcTags = sdcTags.replace("'WT.pn_sku':''", "'WT.pn_sku':'" + componentId + "'");
    form.setAttribute("sdcTags", sdcTags);
}
function recvEmail(element)
{
    var notif = document.getElementById('notif');
    if (element.checked)
    {
        notif.className = '';
    }
    else
    {
        notif.className = 'nosee';
    }


    var requiredFields = document.getElementById('reqf');
    var saveRMI = document.getElementById('saveRMI');
    if (notif.className == 'nosee')
    {
        requiredFields.value = document.getElementById('defaultFields').value;
        saveRMI.value='false';
    }
    else
    {
        requiredFields.value += ',firstname,lastname,question(proftype),postalcode,email';
        saveRMI.value='true';
    }
}
function setSiteUpdateFirstName(value)
{
    var firstname = document.getElementsByName('firstname')[0];
    firstname.value = value;
}
function setSiteUpdateLastName(value)
{
    var lastname = document.getElementsByName('lastname')[0];
    lastname.value = value;
}
function setSiteUpdatePostalCode(value)
{
    var postalcode = document.getElementsByName('postalcode')[0];
    postalcode.value = value;
}
function setSiteUpdateEmail(value)
{
    var email = document.getElementsByName('email')[0];
    email.value = value;
}
function submitButtonClick()
{
    //var saveRMICheckbox = document.getElementsByName('saveRMI')[0];
    var theForm = document.getElementsByName('dataBean')[0];
    //if (validate_patient_ed(theForm, saveRMICheckbox))
    //{
        setComponentId(theForm);
        var myWindowHandle = window.open('about:blank','myWindowName');
        setTimeout('',500);
//        theForm.submit();
        window.location="/ezetimibe/zetia/hcp/patient_education/thank_you.jsp";
        return true;
   // }
    //else
    //{
      //  return false;
    //}
}

function initialize()
{   // Display Email form?
    var notif = document.getElementById('notif');
    //var flag_notif = document.getElementById('flag_notif');
    //notif.className = (flag_notif.checked) ? '' : 'nosee';

    var cookieValue=getCookie('contactInfo');
    if (null != cookieValue)
    {
        var contactInfo = cookieValue.split('||');
        var firstNameIndex=0;
        var lastNameIndex=1;
        var profTypeIndex=2;
        var organizationIndex=3;
        var organizationAddressIndex=4;
        var organizationCityIndex=5;
        var organizationStateIndex=6;
        var organizationPostalCodeIndex=7;
        var practicePhoneIndex=8;
        var practiceEmailIndex=9;
        var practiceWebSiteIndex=10;

        // If firstname is empty, populate with value from cookie
        var aField = this.document.getElementsByName('contactInfo(firstname)')[0];
        if (0 == aField.value.length)
        {
            aField.value = contactInfo[firstNameIndex];
            setSiteUpdateFirstName(aField.value);
        }

        // If lastname is empty, populate with value from cookie
        aField = this.document.getElementsByName('contactInfo(lastname)')[0];
        if (0 == aField.value.length)
        {
            aField.value = contactInfo[lastNameIndex];
            setSiteUpdateLastName(aField.value);
        }

        // If professional designation is empty, populate with value from cookie
        aField = this.document.getElementsByName('contactInfo(proftype)')[0];
        if ('Select a Designation' == aField.value)
        {
            aField.value = contactInfo[profTypeIndex];
        }

        // If practice name is empty, populate with value from cookie
        aField = this.document.getElementsByName('contactInfo(organization)')[0];
        if (0 == aField.value.length)
        {
            aField.value = contactInfo[organizationIndex];
        }

        // If practice address is empty, populate with value from cookie
        aField = this.document.getElementsByName('contactInfo(organization_address)')[0];
        if (0 == aField.value.length)
        {
            aField.value = contactInfo[organizationAddressIndex];
        }

        // If practice city is empty, populate with value from cookie
        aField = this.document.getElementsByName('contactInfo(city)')[0];
        if (0 == aField.value.length)
        {
            aField.value = contactInfo[organizationCityIndex];
        }

        // If practice state is empty, populate with value from cookie
        aField = this.document.getElementsByName('contactInfo(state)')[0];
        if (0 == aField.value.length)
        {
            aField.value = contactInfo[organizationStateIndex];
        }

        // If practice zip is empty, populate with value from cookie
        aField = this.document.getElementsByName('contactInfo(postalcode)')[0];
        if (0 == aField.value.length)
        {
            aField.value = contactInfo[organizationPostalCodeIndex];
            setSiteUpdatePostalCode(aField.value);
        }

        // If practice phone is empty, populate with value from cookie
        aField = this.document.getElementsByName('contactInfo(office_phone)')[0];
        if (0 == aField.value.length)
        {
            aField.value = contactInfo[practicePhoneIndex];
        }

        // If practice email is empty, populate with value from cookie
        aField = this.document.getElementsByName('contactInfo(office_email)')[0];
        if (0 == aField.value.length)
        {
            aField.value = contactInfo[practiceEmailIndex];
            setSiteUpdateEmail(aField.value);
        }

        // If practice web site URL is empty, populate with value from cookie
        aField = this.document.getElementsByName('contactInfo(organization_url)')[0];
        if (0 == aField.value.length)
        {
            aField.value = contactInfo[practiceWebSiteIndex];
        }
    }
    return false;
}
