﻿//http://www.daftlogic.com/projects-online-javascript-obfuscator.htm
function pageLoad() {
    if ($(".form") || $(".small-form")) {
        setRegistration(); 
    }
}

//Form logic
function setRegistration() {
    if ((location.toString().toLowerCase().indexOf("booking").toString() > -1) || (location.toString().toLowerCase().indexOf("my").toString() > -1)) {
        if ($("#registration #validation").is(":visible")) {
            $("#registration #validation input[id$='chkTerms']").bind("click", function () { OnChange_ValidationTerms() });
            OnChange_ValidationTerms();
        }

        if ($("#registration #personal").is(":visible")) {
            OnChange_Attendance();
            OnChange_Title();
            OnChange_CountryProvince();
            OnChange_Emergency();

            $("#registration #personal [id$='txtCompany']").keyup(function (evt) { $("#registration #personal [id$='txtBadgeCompany']").val($(this).val()); });
            $("#registration #personal [id$='txtEmail']").keyup(function (evt) {
                var txtUsername = "#registration #personal [id$='txtUsername']";
                if ($(txtUsername).is(":enabled") && ($(txtUsername).val() != "")) {
                    $(txtUsername).val($(this).val());
                }
            });
            $("#registration #personal [id$='txtEmail']").bind("blur", function () { emailAvailability($(this).val(), getParameterByName("id")); });
            $("#registration #personal [id$='txtUsername']").bind("blur", function () { usernameAvailability($(this).val(), getParameterByName("id")); });
        }

        if ($("#registration #billing").is(":visible")) {
            OnChange_Payee();
            OnChange_PaymentMethod();
            OnChange_AccountsManager();
            $("#registration #billing [id$='chkAccountsManager']").bind("click", function () { OnChange_AccountsManager(); OnChange_PaymentMethod(); });
            $("#registration #billing [id$='txtMEmail']").bind("blur", function () { accountsManagerValidity($(this).val(), getParameterByName("id")); });
        }

        if ($("#registration #profiling").is(":visible")) {
            OnChange_Accommodation();
            OnChange_JobClassification();
            OnChange_MicrosoftPartner();
            OnChange_Terms();
            $("#registration #profiling input[id$='chkMicrosoftPartner']").bind("click", function () { OnChange_Terms(); });
            $("#registration #profiling input[id$='chkTerms']").bind("click", function () { OnChange_Terms(); });
        }

        if ($("#registration #substitution").is(":visible")) {
            $("#registration #substitution [id$='txtEmail']").bind("blur", function () { emailAvailability($(this).val(), ""); });
        }

        if ($("#registration #requirements").is(":visible")) {
            OnChange_AVRequireAudioFeed();
            OnChange_AVRequireExtraMicrophones();
            OnChange_AVRequireOtherEquipment();
            OnChange_StagingRequireOtherAdditional();

            if (window.location.toString().toLowerCase().indexOf("section=contact") > -1) {
                if (!$(".contact").is(":visible")) {
                    $("body").scrollTo($("#requirements li a[id$='hypContactDetails'].topLink"), 500);
                }
                $("#requirements li a[id$='hypContactDetails'].topLink").next().show();
            }
            if (window.location.toString().toLowerCase().indexOf("section=technical") > -1) {
                if (!$(".technical").is(":visible")) {
                    $("body").scrollTo($("#requirements li a[id$='hypTechnicalRequirements'].topLink"), 500);
                }
                $("#requirements li a[id$='hypTechnicalRequirements'].topLink").next().show();
            }
        }
    }
}

// OnChange Events //
function OnChange_ValidationTerms() {
    var chkTerms = "#registration #validation input[id$='chkTerms']";
    var cmdContinue = "#registration #validation input[id$='cmdContinue']";
    if ($(chkTerms).is(":visible")) {
        if (!$(chkTerms).attr("checked")) {
            $(cmdContinue).attr("disabled", true);
        } else {
            $(cmdContinue).removeAttr("disabled");
        }
    }
}

function OnChange_Attendance() {
    var cboAttending = "#registration #personal [id$='cboAttending']";
    var lblAttendance = "#registration #personal [id$='lblAttendance']";
    var trBadgeCompany = "#registration #personal [id$='trBadgeCompany']";
    var tblRequirements = "#registration #personal [id$='tblRequirements']";
    var pPreCon = "#registration #personal [id$='pPreCon']";
    var pEmergency = "#registration #personal [id$='pEmergency']";
    var pDeliveryAddress = "#registration #personal [id$='pDeliveryAddress']";

    var isDelegate = true;
    if ($(cboAttending).is(":visible")) {
        isDelegate = ($(cboAttending).val().toString().toLowerCase() == "yes")
    }
    if (isDelegate) {
        $(trBadgeCompany).show();
        $(tblRequirements).show();
        $(pPreCon).show();
        $(pEmergency).show();
        $(pDeliveryAddress).show();
        if (location.toString().toLowerCase().indexOf("my").toString() == -1) {
            $(lblAttendance).html("<br/>You have indicated that you will be <strong style='color:steelblue;'>ATTENDING</strong> the conference. If you are not attending, please amend the selection above before proceeding.");
        } else {
            $(lblAttendance).html("<br/>You have indicated that you will be <strong style='color:steelblue;'>ATTENDING</strong> the conference. If you are not attending, please contact the Support Centre to amend the selection.");
        }
    } else {
        $(trBadgeCompany).hide();
        $(tblRequirements).hide();
        $(pPreCon).hide();
        $(pEmergency).hide();
        $(pDeliveryAddress).hide();
        if ($(cboAttending).val().toString().toLowerCase() == "---") {
            $(lblAttendance).html("");
        } else {
            if (location.toString().toLowerCase().indexOf("my").toString() == -1) {
                $(lblAttendance).html("<br/>You have indicated that you will <strong style='color:red;'>NOT ATTEND</strong> the conference. <strong style='color:red;'>You will be the Registration Manager for this group only.</strong> If you are attending, please amend the selection above before proceeding.");
            } else {
                $(lblAttendance).html("<br/>You have indicated that you will <strong style='color:red;'>NOT ATTEND</strong> the conference. <strong style='color:red;'>You will be the Registration Manager for this group only.</strong> If you are attending, please contact the Support Centre to amend the selection.");
            }
        }
    }
    SetRequirements();
}

function OnChange_Title() {
    var txtTitle = "#registration #personal [id$='txtTitle']";
    var cboTitle = "#registration #personal [id$='cboTitle']";
    $(txtTitle).hide();
    if ($(cboTitle).attr("id") != undefined) {
        if ($(cboTitle).val().toLowerCase() == 'other') { $(txtTitle).show(); }
    }
}

function OnChange_UpdateGender() {
    var cboTitle = "#registration #personal [id$='cboTitle']";
    var cboGender = "#registration #personal [id$='cboGender']";
    switch ($(cboTitle).val().toLowerCase()) {
        case "mr":
            $(cboGender).val("Male");
            return;
        case "mrs":
        case "ms":
            $(cboGender).val("Female");
            return;
        default:
            $(cboGender).val("Please Specify...");
            return;
    }
}

function OnChange_Country() {
    var cboCountryCodes = "#registration #personal [id$='cboCountryCodes']";
    var cboCountry = "#registration #personal [id$='cboCountry']";
    var cboDeliveryCountry = "#registration #personal [id$='cboDeliveryCountry']";
    var txtPhoneCC = "#registration #personal [id$='txtPhoneCC']";
    var txtDPhoneCC = "#registration #personal [id$='txtDPhoneCC']";
    var txtEPhoneCC = "#registration #personal [id$='txtEPhoneCC']";

    $(cboCountryCodes).get(0).selectedIndex = $(cboCountry).get(0).selectedIndex - 1;
    if ($(cboDeliveryCountry).is(":visible")) $(cboDeliveryCountry).get(0).selectedIndex = $(cboCountry).get(0).selectedIndex;

    $(txtPhoneCC).val($(cboCountryCodes).val());
    if ($(txtDPhoneCC).is(":visible")) $(txtDPhoneCC).val($(cboCountryCodes).val());
    if ($(txtEPhoneCC).is(":visible")) $(txtEPhoneCC).val($(cboCountryCodes).val());
}

function OnChange_CountryProvince() {
    var cboCountry = "#registration #personal [id$='cboCountry']";
    var trProvince = "#registration #personal [id$='trProvince']";

    if ($(cboCountry).val() == "South Africa") {
        $(trProvince).show();
    } else {
        $(trProvince).hide();
    }
}

function OnChange_Province() {
    var cboProvince = "#registration #personal [id$='cboProvince']";
    var txtProvince = "#registration #personal [id$='txtProvince']";
    if ($(cboProvince).attr("id") != undefined) {
        if ($(cboProvince).val() != "Please Specify...") { $(txtProvince).val($(cboProvince).val()); } else { $(txtProvince).val(""); }
    }
}

function SetRequirements() {
    OnChange_Dietary();
    OnChange_Disability();
    OnChange_Government();
    OnChange_PreConferences();
}

function OnChange_Dietary() {
    var txtDietary = "#registration #personal [id$='txtDietary']";
    var cboDietary = "#registration #personal [id$='cboDietary']";
    $(txtDietary).hide()
    if ($(cboDietary).attr("id") != undefined) {
        if ($(cboDietary).val().toLowerCase() == 'other') { $(txtDietary).show(); }
    }
}

function OnChange_Disability() {
    var txtDisability = "#registration #personal [id$='txtDisability']";
    var cboDisability = "#registration #personal [id$='cboDisability']";
    $(txtDisability).hide();
    if ($(cboDisability).attr("id") != undefined) {
        if ($(cboDisability).val().toLowerCase() == 'other') { $(txtDisability).show(); }
    }
}

function OnChange_Government() {
    var pGovernment = "#registration #personal [id$='pGovernment']";
    var cboGovernment = "#registration #personal [id$='cboGovernment']";
    $(pGovernment).hide()
    if ($(cboGovernment).attr("id") != undefined) {
        if ($(cboGovernment).val().toLowerCase() == 'yes') { $(pGovernment).show(); }
    }
}

function OnChange_PreConferences() {
    var pPreCons = "#registration #personal [id$='pPreCons']";
    var cboPreCons = "#registration #personal [id$='cboPreCons']";
    $(pPreCons).hide();
    if ($(cboPreCons).attr("id") != undefined) {
        if ($(cboPreCons).val().toLowerCase() == 'yes') { $(pPreCons).show(); }
    }
}

function OnChange_Emergency() {
    var tblEmergency = "#registration #personal [id$='tblEmergency']";
    var chkEmergency = "#registration #personal [id$='chkEmergency']";

    if ($(chkEmergency).attr("id") != undefined) {
        if ($(chkEmergency).is(":checked")) {
            $(tblEmergency).show();
        } else {
            $(tblEmergency).hide();
        }
    }
}

function OnChange_Payee() {
    var trCompany = "#registration #billing [id$='trCompany']";
    var trVat = "#registration #billing [id$='trVat']";
    var trPO = "#registration #billing [id$='trPO']";
    var trJobTitle = "#registration #billing [id$='trJobTitle']";
    var trAddressedTo = "#registration #billing [id$='rblAddressedTo'] input";

    var value = "individual";
    if (!$("#registration #billing [id$='rblPayee']").is(":visible")) return;
    value = $("#registration #billing [id$='rblPayee'] input:checked").val().toLowerCase();
    if (value == "company") {
        $(trCompany).show();
        $(trVat).show();
        $(trPO).show();
        $(trJobTitle).show();

        var company, jobtitle;
        if ($(trAddressedTo + ":checked").val().toLowerCase() == "myself") {
            $("#registration #billing [id$='txtCompany']").val($("#registration #billing [id$='hCompany']").val());
            $("#registration #billing [id$='txtJobTitle']").val($("#registration #billing [id$='hJobTitle']").val());
        } else {
            $("#registration #billing [id$='txtCompany']").val($("#registration #billing [id$='hCompanyOther']").val());
            $("#registration #billing [id$='txtJobTitle']").val($("#registration #billing [id$='hJobTitleOther']").val());
        }
    } else {
        $(trCompany).hide();
        $(trVat).hide();
        $(trPO).hide();
        $(trJobTitle).hide();
        $("#registration #billing [id$='txtCompany']").val("");
        $("#registration #billing [id$='txtVAT']").val("");
        $("#registration #billing [id$='txtPONumber']").val("");
        $("#registration #billing [id$='txtJobTitle']").val("");
    }
}

function OnChange_Populate() {
    var tblAddressedTo = "#registration #billing [id$='rblAddressedTo'] input";
    var txtCompany = "#registration #billing [id$='txtCompany']";
    var txtFirstName = "#registration #billing [id$='txtFirstName']";
    var txtSurname = "#registration #billing [id$='txtSurname']";
    var txtJobTitle = "#registration #billing [id$='txtJobTitle']";
    var txtPhoneCC = "#registration #billing [id$='txtPhoneCC']";
    var txtPhoneA = "#registration #billing [id$='txtPhoneA']";
    var txtPhone = "#registration #billing [id$='txtPhone']";
    var txtEmail = "#registration #billing [id$='txtEmail']";

    if (!$("#registration #billing [id$='rblAddressedTo']").is(":visible")) return;
    if ($(tblAddressedTo + ":checked").val() != undefined) {
        value = $(tblAddressedTo + ":checked").val().toLowerCase();
        if (value == "myself") {
            $(txtCompany).val($("#registration #billing [id$='hCompany']").val());
            $(txtFirstName).val($("#registration #billing [id$='hFirstName']").val());
            $(txtSurname).val($("#registration #billing [id$='hSurname']").val());
            $(txtJobTitle).val($("#registration #billing [id$='hJobTitle']").val());
            $(txtPhoneCC).val($("#registration #billing [id$='hPhoneCC']").val());
            $(txtPhoneA).val($("#registration #billing [id$='hPhoneA']").val());
            $(txtPhone).val($("#registration #billing [id$='hPhone']").val());
            $(txtEmail).val($("#registration #billing [id$='hEmail']").val());
        } else {
            if ($("#registration #billing [id$='hCompanyOther']").val() != "") {
                $(txtCompany).val($("#registration #billing [id$='hCompanyOther']").val());
            }
            $(txtFirstName).val($("#registration #billing [id$='hFirstNameOther']").val());
            $(txtSurname).val($("#registration #billing [id$='hSurnameOther']").val());
            $(txtJobTitle).val($("#registration #billing [id$='hJobTitleOther']").val());
            $(txtPhoneCC).val($("#registration #billing [id$='hPhoneCCOther']").val());
            $(txtPhoneA).val($("#registration #billing [id$='hPhoneAOther']").val());
            $(txtPhone).val($("#registration #billing [id$='hPhoneOther']").val());
            $(txtEmail).val($("#registration #billing [id$='hEmailOther']").val());
        }
    }
}

function OnChange_AccountsManager() {
    var pAccountsManager = "#registration #billing [id$='pAccountsManager']";
    var chkAccountsManager = "#registration #billing [id$='chkAccountsManager']";
    var txtMFirstName = "#registration #billing [id$='txtMFirstName']";
    var txtMSurname = "#registration #billing [id$='txtMSurname']";
    var txtMFirstName = "#registration #billing [id$='txtMFirstName']";
    var txtMCompany = "#registration #billing [id$='txtMCompany']";
    var txtMEmail = "#registration #billing [id$='txtMEmail']";
    var txtMPhoneCC = "#registration #billing [id$='txtMPhoneCC']";
    var txtMPhoneA = "#registration #billing [id$='txtMPhoneA']";
    var txtMPhone = "#registration #billing [id$='txtMPhone']";
    var cmdUpdate = "#registration #billing [id$='cmdUpdate']";

    if (!$(chkAccountsManager).is(":visible")) return;
    $(pAccountsManager).hide();
    if ($(chkAccountsManager).is(":checked")) {
        if ($(cmdUpdate).attr("id") != undefined) { $(cmdUpdate).show(); }
        $(pAccountsManager).show();
        if ($("#registration #billing [id$='rblAddressedTo'] input:checked").val() != undefined) {
            value = $("#registration #billing [id$='rblAddressedTo'] input:checked").val().toLowerCase();
            if (value != "myself") {
                if ($(txtMFirstName).val().toLowerCase() == "") { $(txtMFirstName).val($("#registration #billing [id$='txtFirstName']").val()); }
                if ($(txtMSurname).val().toLowerCase() == "") { $(txtMSurname).val($("#registration #billing [id$='txtSurname']").val()); }
                if ($(txtMCompany).val().toLowerCase() == "") { $(txtMCompany).val($("#registration #billing [id$='txtCompany']").val()); }
                if ($(txtMEmail).val().toLowerCase() == "") { $(txtMEmail).val($("#registration #billing [id$='txtEmail']").val()); }
                if ($(txtMPhoneCC).val().toLowerCase() == "") { $(txtMPhoneCC).val($("#registration #billing [id$='txtPhoneCC']").val()); }
                if ($(txtMPhoneA).val().toLowerCase() == "") { $(txtMPhoneA).val($("#registration #billing [id$='txtPhoneA']").val()); }
                if ($(txtMPhone).val().toLowerCase() == "") { $(txtMPhone).val($("#registration #billing [id$='txtPhone']").val()); }
            }
        }
    } else {
        if ($(cmdUpdate).attr("id") != undefined) { $(cmdUpdate).hide(); }
        $(pAccountsManager).hide();
        if ($(txtMFirstName).val().toLowerCase() == "") { $(txtMFirstName).val(""); }
        if ($(txtMSurname).val().toLowerCase() == "") { $(txtMSurname).val(""); }
        if ($(txtMCompany).val().toLowerCase() == "") { $(txtMCompany).val(""); }
        if ($(txtMEmail).val().toLowerCase() == "") { $(txtMEmail).val(""); }
        if ($(txtMPhoneCC).val().toLowerCase() == "") { $(txtMPhoneCC).val(""); }
        if ($(txtMPhoneA).val().toLowerCase() == "") { $(txtMPhoneA).val(""); }
        if ($(txtMPhone).val().toLowerCase() == "") { $(txtMPhone).val(""); }
    }
}

function OnChange_PaymentMethod() {
    var pPaymentMethod = "#registration #billing [id$='pPaymentMethod']";
    var chkAccountsManager = "#registration #billing [id$='chkAccountsManager']";
    var pOther = "#registration #billing [id$='pOther']";
    var pCreditCard = "#registration #billing [id$='pCreditCard']";
    var cboPaymentMethod = "#registration #billing [id$='cboPaymentMethod']";

    if (!$(cboPaymentMethod).is(":visible")) return;
    $(pPaymentMethod).hide();
    $(pCreditCard).hide();
    $(pOther).hide();
    switch ($(cboPaymentMethod).val().toLowerCase()) {
        case "please specify...":
            break;
        case "credit card":
            if (!$(chkAccountsManager).is(":checked")) {
                $(pPaymentMethod).show();
                $(pCreditCard).show();
            }
            break;
        default:
            $(pPaymentMethod).show();
            $(pOther).show();
            break;
    }
}

function OnChange_Accommodation() {
    var chkAccommodation = "#registration #profiling [id$='chkAccommodation']";
    var tblAccommodation = "#registration #profiling [id$='tblAccommodation']";
    if (!$(chkAccommodation).is(":visible")) return;

    if ($(chkAccommodation).attr("checked")) {
        $(tblAccommodation).hide();
    } else {
        $(tblAccommodation).show();
        if ($("#registration #profiling [id$='txtArrival']").val() == "1900/01/01") { $("#registration #profiling [id$='txtArrival']").val(""); }
        if ($("#registration #profiling [id$='txtDeparture']").val() == "1900/01/01") { $("#registration #profiling [id$='txtDeparture']").val(""); }
    }
    OnChange_Flights();
}

function OnChange_Flights() {
    var cboFlights = "#registration #profiling [id$='cboFlights']";
    if (!$(cboFlights).is(":visible")) return;

    var trAiportTransfers = "#registration #profiling [id$='trAiportTransfers']";
    var trArrivalFlightNo = "#registration #profiling [id$='trArrivalFlightNo']";
    var trDepartureFlightNo = "#registration #profiling [id$='trDepartureFlightNo']";
    var trArrivalTime = "#registration #profiling [id$='trArrivalTime']";
    var trDepartureTime = "#registration #profiling [id$='trDepartureTime']";

    $(trAiportTransfers).show();
    $(trArrivalFlightNo).hide();
    $(trArrivalTime).hide();
    $(trDepartureFlightNo).hide();
    $(trDepartureTime).hide();
    switch ($(cboFlights).val().toLowerCase()) {
        case "please specify...":
        case "i will not travel by air":
            $(trAiportTransfers).hide();
            break;
        case "my flights are already booked":
            $(trArrivalFlightNo).show();
            $(trDepartureFlightNo).show();
            $(trArrivalTime).show();
            $(trDepartureTime).show();
            break;
    }
    OnChange_AirportTransfers()
}

function OnChange_AirportTransfers() {
    var cboFlights = "#registration #profiling [id$='cboFlights']";
    var cboAirportTransfers = "#registration #profiling [id$='cboAirportTransfers']";

    var trAiportTransfers = "#registration #profiling [id$='trAiportTransfers']";
    var trArrivalFlightNo = "#registration #profiling [id$='trArrivalFlightNo']";
    var trDepartureFlightNo = "#registration #profiling [id$='trDepartureFlightNo']";
    var trArrivalTime = "#registration #profiling [id$='trArrivalTime']";
    var trDepartureTime = "#registration #profiling [id$='trDepartureTime']";

    $(trArrivalFlightNo).hide();
    $(trArrivalTime).hide();
    $(trDepartureFlightNo).hide();
    $(trDepartureTime).hide();
    if (!$(cboAirportTransfers).is(":visible")) return;
    switch ($(cboAirportTransfers).val().toLowerCase()) {
        case "i require airport transfers":
            if ($(cboFlights).val().toLowerCase() == "my flights are already booked") {
                $(trArrivalFlightNo).show();
                $(trArrivalTime).show();
                $(trDepartureFlightNo).show();
                $(trDepartureTime).show();
            }
            break;
    }
}

function OnChange_JobClassification() {
    var cboJobClassification = "#registration #profiling [id$='cboJobClassification']";
    var tblITPro = "#registration #profiling [id$='tblITPro']";
    var tblDeveloper = "#registration #profiling [id$='tblDeveloper']";

    if ($(cboJobClassification).attr("id") != undefined) {
        $(tblITPro).hide();
        $(tblDeveloper).hide();
        switch ($(cboJobClassification).val().toLowerCase()) {
            case "please specify...":
                break;
            case "it pro":
                $(tblITPro).show();
                break;
            case "developer":
                $(tblDeveloper).show();
                break;
            default:
                break;
        }
    }
}

function OnChange_MicrosoftPartner() {
    var cboMicrosoftPartner = "#registration #profiling [id$='cboMicrosoftPartner']";
    var pMicrosoftPartner = "#registration #profiling [id$='pMicrosoftPartner']";
    if ($(cboMicrosoftPartner).attr("id") != undefined) {
        $(pMicrosoftPartner).hide();
        if ($(cboMicrosoftPartner).val() == "Yes" || $(cboMicrosoftPartner).val() == "Not Sure") {
            $(pMicrosoftPartner).show();
        }
    }
    OnChange_Terms();
}

function OnChange_Terms() {
    var chkTerms = "#registration #profiling input[id$='chkTerms']";
    var chkMicrosoftPartner = "#registration #profiling input[id$='chkMicrosoftPartner']";
    var cmdFinish = "#registration #profiling input[id$='cmdFinish']";

    var partnerChecked = true;
    if ($(chkMicrosoftPartner).is(":visible")) {
        partnerChecked = $(chkMicrosoftPartner).attr("checked");
    }

    if (!$(chkTerms).attr("checked") || !partnerChecked) {
        $(cmdFinish).attr("disabled", true);
        $("#lblReasonDisabled").html("In order to proceed, please revise the following:")
        if (!$(chkTerms).attr("checked")) $("#lblReasonDisabled").html($("#lblReasonDisabled").html() + "<br/> &bull; read and accept the Terms and Conditions.")
        if (!partnerChecked) $("#lblReasonDisabled").html($("#lblReasonDisabled").html() + "<br/> &bull; read and accept the Microsoft Partner Summit disclaimer.")
    } else {
        $(cmdFinish).removeAttr("disabled");
        $("#lblReasonDisabled").html("");
    }
}

function OnChange_AVRequireAudioFeed() {
    var cboAVRequireAudioFeed = "#registration #requirements [id$='cboAVRequireAudioFeed']";
    var trAVAudioFeedQ = "#registration #requirements [id$='trAVAudioFeedQ']";
    var trAVAudioFeedA = "#registration #requirements [id$='trAVAudioFeedA']";

    $(trAVAudioFeedQ).hide();
    $(trAVAudioFeedA).hide();
    if ($(cboAVRequireAudioFeed).attr("id") != undefined) {
        if ($(cboAVRequireAudioFeed).val().toLowerCase() == "yes") {
            $(trAVAudioFeedQ).show();
            $(trAVAudioFeedA).show();
        }
    }
}

function OnChange_AVRequireExtraMicrophones() {
    var cboAVRequireAudioFeed = "#registration #requirements [id$='cboAVRequireExtraMicrophones']";
    var trAVExtraMicrophones = "#registration #requirements [id$='trAVExtraMicrophones']";

    $(trAVExtraMicrophones).hide();
    if ($(cboAVRequireAudioFeed).attr("id") != undefined) {
        if ($(cboAVRequireAudioFeed).val().toLowerCase() == "yes") {
            $(trAVExtraMicrophones).show();
        }
    }
}

function OnChange_AVRequireOtherEquipment() {
    var cboAVRequireOtherEquipment = "#registration #requirements [id$='cboAVRequireOtherEquipment']";
    var trAVOtherEquipment = "#registration #requirements [id$='trAVOtherEquipment']";

    $(trAVOtherEquipment).hide();
    if ($(cboAVRequireOtherEquipment).attr("id") != undefined) {
        if ($(cboAVRequireOtherEquipment).val().toLowerCase() == "yes") {
            $(trAVOtherEquipment).show();
        }
    }
}

function OnChange_StagingRequireOtherAdditional() {
    var cboStagingRequireOtherAdditional = "#registration #requirements [id$='cboStagingRequireOtherAdditional']";
    var trStagingOtherAdditionalQ = "#registration #requirements [id$='trStagingOtherAdditionalQ']";
    var trStagingOtherAdditionalA = "#registration #requirements [id$='trStagingOtherAdditionalA']";

    $(trStagingOtherAdditionalQ).hide();
    $(trStagingOtherAdditionalA).hide();
    if ($(cboStagingRequireOtherAdditional).attr("id") != undefined) {
        if ($(cboStagingRequireOtherAdditional).val().toLowerCase() == "yes") {
            $(trStagingOtherAdditionalQ).show();
            $(trStagingOtherAdditionalA).show();
        }
    }
}

//AJAX Calls
function emailCheck(response) {
    switch (response.d) {
        case "1":
            MsgInvalid("The e-mail address you have entered is already registered.");
            break;
    }
}

function usernameCheck(response) {
    switch (response.d) {
        case "1":
            MsgInvalid("The username you have entered is already registered.");
            break;
    }
}

function accountsManagerEmailCheck(response) {
    switch (response.d) {
        case "1":
            MsgInvalid("By default, you have access to the accounts including all automated accounts correspondence sent to your registered e-mail address. Please specify a different e-mail address for this user or opt-out of creating one.");
            break;
    }
}

function emailAvailability(email, d) {
    callPageMethod(getRootPath() + "ws/registration.aspx", "EmailExists", emailCheck, "Email", email, "d", d);
}

function usernameAvailability(username, d, p) {
    callPageMethod(getRootPath() + "ws/registration.aspx", "UsernameExists", usernameCheck, "Username", username, "d", d);
}

function accountsManagerValidity(email, d) {
    callPageMethod(getRootPath() + "ws/registration.aspx", "AccountsManagerEmailValid", accountsManagerEmailCheck, "Email", email, "d", d);
}

function callPageMethod(loc, methodName, onSuccess) {
    var args = '';
    var l = arguments.length;
    if (l > 3) {
        for (var i = 3; i < l - 1; i += 2) {
            if (args.length != 0) args += ',';
            args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"';
        }
    }
    if (args.length > 0) { args = "{" + args + "}"; }
    $.ajax({
        type: "POST",
        url: loc + "/" + methodName,
        beforeSend: function () { $(this).data("timer", setTimeout(function () { showLoading(); }, 1000)); },
        complete: function () { clearTimeout($(this).data("timer")); hideLoading(); },
        cache: false,
        contentType: "application/json; charset=utf-8",
        data: args,
        dataType: "json",
        success: onSuccess,
        error: function (xhr, status, error) {
            MsgInvalid('Asynchronous request could not be completed.');
            //MsgInvalid(loc + "/" + methodName + "\n" + xhr.responseText + "\n" + args.toString());
        }
    });
}
