﻿var appRelativeUrl = "http://localhost/OLSC/";
var completeUrl = null;
var disclaimerUrl = null;
clientKey = "PpYGPtU0jYf9xK6Jr7vpXQ==";
$(document).ready(function () {
    ShowLoader();
    if (disclaimerUrl == null) {
        $("#disclaimerRow1").hide();
        $("#disclaimerRow2").hide();
        $("#btnContinue").removeAttr("disabled");
    } else {
        $("#disclaimerRow1").show();
        $("#disclaimerRow2").show();
        $("#btnContinue").attr("disabled", "disabled");
    }
    validateSteps = {};
    validateSteps.txtUsername = "Username";
    validateSteps.txtEmailAddress = "Email Address";
    validateSteps.txtPassword = "Password";
    validateSteps.txtFirstName = "First Name";
    validateSteps.txtLastName = "Last Name";
    validateSteps.txtPhone = "Phone";
    validateSteps.txtAddress = "Address";
    validateSteps.txtSuburb = "Suburb";
    validateSteps.txtState = "State";
    show = true;
    validateSteps.txtPostcode = "Postcode";
    validateSteps.txtVerificationCode = "Verification Code. Please enter the code to the right in the text box.";
    ORCA.UserServices.LoadInitialJoinData(function (json) {
        LoadInitialJoinData_Complete(json);
    });
});
function LoadInitialData() { }
function LoadInitialJoinData_Complete(json) {
    var output = [];
    $.each(json.Countries, function (i, val) {
        output.push("<option value=\"" + val.ISO + "\">" + val.Name + "</option>");
    });
    $("#ddlCountries").html(output.join(""));
    $("#ddlCountries").val("AU");
    $("#hdnVerificationCodeKey").val(json.VerificationKey);
    $("#verificationCodeImg").attr("src", appRelativeUrl + "/Connectors/Scripts/RandomImage.aspx?key=" + json.VerificationKey);
    HideLoader();
}
function VerifyNewMembershipData() {
    ShowLoader();
    var validationData = ValidateStep();
    if (validationData.length == 0) {
        var txtPassword = $("#txtPassword");
        var txtPasswordAgain = $("#txtPasswordAgain");
        if (txtPassword.val() != txtPasswordAgain.val()) {
            validationData += "Passwords Do Not Match.\n";
        }
        if (validationData.length > 0) {
            alert("The Following Errors Occurred:\n\n" + validationData);
            HideLoader();
        } else {
            ORCA.UserServices.VerifyNewMembershipData($("#txtUsername").val(), $("#txtEmailAddress").val(), txtPassword.val(), $("#txtCompany").val(), $("#txtFirstName").val(), $("#txtLastName").val(), $("#txtPhone").val(), $("#txtFax").val(), $("#txtMobile").val(), $("#txtAddress").val(), $("#txtAddress2").val(), $("#txtSuburb").val(), $("#txtState").val(), $("#txtPostcode").val(), $("#ddlCountries").val().split("|")[0], $("#txtPromotionCode").val(), $("#txtVerificationCode").val(), $("#hdnVerificationCodeKey").val(), function (json) {
                VerifyNewMembershipData_Complete(json);
            });
        }
    } else {
        alert("The Following Fields Are Required:\n\n" + validationData);
        HideLoader();
    }
    return false;
}
function VerifyNewMembershipData_Complete(json) {
    if (json.ErrorMessages.length > 0) {
        var output = [];
        $.each(json.ErrorMessages, function (i, val) {
            output.push("- " + val + ". \n");
        });
        alert("The following errors occurred: \n\n" + output.join(""));
        HideLoader();
    } else {
        window.location = completeUrl;
    }
}
