﻿$(document).ready(function() {
    overrideJqueryXhr();

    $("#homeHeader").supersleight();
    $("#retailersHeader").supersleight();
    $("#mfgPics a").fancybox();

    Date.firstDayOfWeek = 0; Date.format = "mm/dd/yyyy";
    $("#bootPurchaseDate").datePicker({ clickInput: true, startDate: "01/01/2009", endDate: (new Date()).asString() })

    $("#ctl00_navHunting").hover(function() { $("#huntingMenu").toggle(); }, function() { });
    $("#ctl00_navFashion").hover(function() { $("#fashionMenu").toggle(); }, function() { });
    $("#retailerList span a, #media a, #newsitems a, #articleCollection a").click(function() { window.open(this.href); return false; });

    $("#slider").easySlider({ auto: true, controlsShow: false, pause: 4000, continuous: true });
    $("#newsitems").easySlider({ auto: true, prevText: '&nbsp;', nextText: '&nbsp;', controlsBefore: '<b><a title="Le Chameau Headlines" href="/news">Le Chameau Headlines</a> ', controlsAfter: '</b>', pause: 6500, continuous: true });

    $(".column li").hover(function() { $(this).addClass("hilite"); }, function() { $(this).removeClass("hilite"); });

    $("#ocRegister, #ocRegLink").click(function() {
        $("#ocWelcome, #ocLogin").removeClass("current");
        $("#ocRegister").addClass("current");
        $("#ocWelcomeMessage, #ocLoginBox").hide();
        $("#ocRegisterForm").show();
        return false;
    });

    $("#ocWelcome").click(function() {
        $("#ocWelcome, #ocLogin").addClass("current");
        $("#ocRegister, #ocLogin").removeClass("current");
        $("#ocWelcomeMessage").show();
        $("#ocRegisterForm, #ocLoginBox").hide();
        return false;
    });

    $("#ocLogin").click(function() {
        $("#ocWelcome, #ocRegister").removeClass("current");
        $("#ocLogin").addClass("current");
        $("#ocWelcomeMessage, #ocRegisterForm").hide();
        $("#ocLoginBox").show();
        return false;
    });

    $("#ocRegSubmitButton").click(function() {
        $("#regPersonalError, #regPurchaseError, #regCodeError").hide()

        var name = $("#ocRegName").val();
        if (name == "") {
            $("#regPersonalError").show()
            $("#ocRegName").focus()
            return false;
        }

        var add1 = $("#ocAdd1").val();
        if (add1 == "") {
            $("#regPersonalError").show()
            $("#ocAdd1").focus()
            return false;
        }

        var city = $("#ocCity").val();
        if (city == "") {
            $("#regPersonalError").show()
            $("#ocCity").focus()
            return false;
        }

        var state = $("#ocState").val();
        if (state == "") {
            $("#regPersonalError").show()
            $("#ocState").focus()
            return false;
        }

        var zip = $("#ocZip").val();
        if (zip != "" && zip.length == 5) {
            if (isNumeric(zip) == false) {
                $("#regPersonalError").show().html("Zipcode must be numbers only.")
                $("#ocZip").focus()
                return false;
            }
        } else {
            $("#regPersonalError").show().html("Please complete all required fields.")
            $("#ocZip").focus()
            return false;
        }

        var email = $("#ocEmail").val();
        if (email != "") {
            if (isValidEmailAddress(email) == false) {
                $("#regPersonalError").show().html("Valid email addresses only.")
                $("#ocEmail").focus()
                return false;
            }
        } else {
            $("#regPersonalError").show().html("Please complete all required fields.")
            $("#ocEmail").focus()
            return false;
        }

        var model = $("#ctl00_pageContent_bootModelList").val();
        if (model == "") {
            $("#regPurchaseError").show()
            $("#ctl00_pageContent_bootModelList").focus()
            return false;
        }

        var size = $("#bootSizeList").val();
        if (size == "") {
            $("#regPurchaseError").show()
            $("#bootSizeList").focus()
            return false;
        }

        var pDate = $("#bootPurchaseDate").val();
        if (pDate == "") {
            $("#regPurchaseError").show()
            $("#bootPurchaseDate").focus()
            return false;
        }

        var reg = $("#bootPurchaseCode").val();
        if (reg == "") {
            $("#regCodeError").show()
            $("bootPurchaseCode").focus()
            return false;
        }

        var sex = $("input[name='ocGroup']:checked").val();
        var add2 = $("#ocAdd2").val();
        var phone = $("#ocPhone").val();
        var loc = $("#bootPurchaseLoc").val();
        var test = escape($("#ocTest").val());

        $("#sendingMessage").show();
        $("#ocRegSubmitButton").val("registering ...").attr("disabled", "disabled");

        $.ajax({
            type: "POST",
            url: "/s/processRegistration.aspx",
            data: "n=" + name + "&a1=" + add1 + "&r=" + reg + "&c=" + city + "&s=" + state + "&z=" + zip + "&e=" + email + "&m=" + model + "&sz=" + size + "&d=" + pDate + "&sx=" + sex + "&a2=" + add2 + "&p=" + phone + "&l=" + loc + "&t=" + test,
            dataType: "text",
            cache: false,
            success: function(response) {
                if (response == "y") {
                    $("#ocRegisterForm").html($("#ocRegSuccess").html());
                } else if (response == "e") {
                    $("#regCodeError").show()
                    $("#bootPurchaseCode").focus();
                    resultReset()
                } else if (response == "i") {
                    $("#regPersonalError").show().html("Please complete all required fields.")
                    $("#regPurchaseError").show().html("Please complete all required fields.")
                    resultReset()
                } else if (response == "n") { resultError() }
            },
            error: function() { resultError() }
        });
        return false;
    });


    $("#contactSubmit").click(function() {
        $("#formHolder span").hide();
        var name = $("#contactName").val();
        if (name == "") {
            $("#nameError").show()
            $("#contactName").focus()
            return false;
        }

        var email = $("#emailContact").val();
        if (email != "") {
            if (isValidEmailAddress(email) == false) {
                $("#emailError").show().html("Valid email addresses only.")
                $("#emailContact").focus()
                return false;
            }
        } else {
            $("#emailContact").focus()
            $("#emailError").show()
            return false;
        }

        var contactType = $("#contactType").val();
        if (contactType == "") {
            $("#typeError").show()
            return false;
        }

        var refer = $("#ctl00_pageContent_referList").val();
        if (refer == "") {
            $("#referError").show()
            return false;
        }

        var message = $("#contactMessage").val();
        if (message == "") {
            $("#messageError").show()
            $("#contactMessage").focus()
            return false;
        }

        $("#sendingMessage").show();
        $("#contactSubmit").val("sending ...").attr("disabled", "disabled");

        $.ajax({
            type: "GET",
            url: "/s/processMessage.aspx",
            data: "name=" + name + "&email=" + email + "&type=" + contactType + "&refer=" + refer + "&message=" + escape(message),
            dataType: "text",
            cache: false,
            success: function(response) {
                if (response == "y") {
                    $("#formHolder fieldset").hide()
                    $("#formSuccess").show()
                } else {
                    $("#sendingMessage, #contactSubmit").hide()
                    $("#sendError").show()
                }
            },
            error: function() {
                $("#sendingMessage, #contactSubmit").hide()
                $("#sendError").show()
            }
        });
        return false;
    });
});

function resultReset() { $("#sendingMessage").hide(); $("#ocRegSubmitButton").val("Submit Registration").removeAttr("disabled"); }
function resultError() { $("#sendingMessage").hide(); $("#ocRegSubmitButton").hide(); $("#sendError").show() }