﻿//addEvent(window, 'load', SwitchPassword(false));
//addEvent(window, 'load', 'SelectPrimaryAddress(document.getElementById("BillingAddress2"))');

// JS to hide/show password fields
function SwitchPassword(manual,strEnableText,strDisableText) {
    var passwordField = document.getElementById("PasswordContainer");
    var confirmPasswordField = document.getElementById("ConfirmPasswordContainer");
    var switchPasswordLink = document.getElementById("SwitchPasswordLink");
    var switchPasswordContainer = document.getElementById("SwitchPasswordContainer");
    
    if (!strEnableText) {
        strEnableText = "Change password...";
    }
    if (!strDisableText) {
        strDisableText = "Leave password unchanged";
    }
    
    if (passwordField && confirmPasswordField && switchPasswordLink && switchPasswordContainer) {
        switchPasswordContainer.style.display = "block";
        //alert("style=" + passwordField.style.display + " manual=" + manual + " value=" + document.forms[0].elements["submittedpassword"].value);
        if (passwordField.style.display == "block" && (manual || (!manual && document.forms[0].elements["submittedpassword"].value == ""))) {
            // passwords were visible - hide them now unless it is a form submission result with "non-empty" password
            passwordField.style.display = "none";
            confirmPasswordField.style.display = "none";
            switchPasswordLink.innerHTML = strEnableText;
            switchPasswordLink.className = "disabled";
            document.forms[0].elements["ctl00$cplPage$Password"].value = "";
            document.forms[0].elements["ctl00$cplPage$ConfirmPassword"].value = "";
        } else {
            // passwords were not visible - display them now
            passwordField.style.display = "block";
            confirmPasswordField.style.display = "block";
            switchPasswordLink.innerHTML = strDisableText;
            switchPasswordLink.className = "enabled";
        }
    }
}

function SelectPrimaryAddress(oField) {
    oHelpElement = document.getElementById("PrimaryAddressMessage");
    
    if (oHelpElement) {
        switch (oField.value.toLowerCase()){
            case "postal" :
                oHelpElement.style.display = "block";
                break;
            default :
                oHelpElement.style.display = "none";
                break;
        }
    }
}

function SelectMembershipType(oMemberShipType) {
    // This function is overridden from an element loaded from the CMS within the page content
    // but is defined here so that the page doesn't break on slow loads. Strange, but true!
}

