﻿function HighlightBrand(BrandIndex) {

    var Brand = $(".BrandText a").get(BrandIndex);

    ClearBrand();
    $(Brand).css("color", "#f5224e");

}

function ClearBrand() {
    $(".BrandText a").css("color", "#000");
}

function InitializeMailingValidator() {
    $("#aspnetForm").validate({
        rules: {
            Email: { required: true, email: true },
            Name: { required: true }
        },
        messages: {
            Email: { required: "Please enter your email address", email: "Please enter a valid email address." },
            Name: { required: "Please enter your name" }
        },
        showErrors: function(errorMap, errorList) {
            ShowValidationErrors(errorList);
        },
        submitHandler: function(form) {
            $.ajax({
                type: "POST",
                url: "JoinMailingList.aspx",
                data: "Name=" + $("#Name").val() + "&EMail=" + $("#Email").val(),
                success: function(msg) {

                    $("#Name").val("");
                    $("#Email").val("");

                    $("#dlgConfirmation").dialog({
                        bgiframe: true,
                        height: 173,
                        width: 400,
                        modal: true,
                        title: "Mailing List Signup",
                        resizable: false,
                        closeOnEscape: false,
                        beforeclose: function(event, ui) { $(this).dialog('destroy'); },
                        buttons: {
                            Close: function() {
                                $(this).dialog('destroy');
                            }
                        }
                    });
                }
            });
        },
        onkeyup: false,
        onfocusout: false,
        onclick: false
    });
}

function ShowValidationErrors(errorList) {
    var ErrorMessage = "";
    if (errorList.length > 0) {
        for (var i = 0; i < errorList.length; i++) {
            ErrorMessage = ErrorMessage + "- " + errorList[i].message + "<br>";
        }
        $("#dlgFind").html(ErrorMessage);
        
        $("#dlgFind").dialog({
            bgiframe: true,
            height: 173,
            width: 400,
            modal: true,
            title: "Mailing List Signup",
            resizable: false,
            closeOnEscape: false,
            beforeclose: function(event, ui) { $(this).dialog('destroy'); },
            buttons: {
                Close: function() {
                    $(this).dialog('destroy');
                }
            }
        });        
    }
}

/// <summary>
/// Show Error displays the "You must be 21..." dialog box
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
function ShowError() {

    $("#dlgMessage").dialog({
        bgiframe: true,
        height: 173,
        width: 400,
        modal: true,
        resizable: false,
        closeOnEscape: false,
        beforeclose: function(event, ui) { $(this).dialog('destroy'); },
        buttons: {
            Close: function() {
                $(this).dialog('destroy');
            }
        }
    });

}
function ShowFanboxDialog() {
    $("#dlgFanbox").dialog({
        bgiframe: true,
        height: 673,
        width: 400,
        modal: true,
        resizable: false,
        closeOnEscape: false,
        beforeclose: function(event, ui) { $(this).dialog('destroy'); },
        buttons: {
            Close: function() {
                $(this).dialog('destroy');
            }
        }
    });
}
function ShowTerms() {
    $("#dlgTerms").dialog({
        bgiframe: true,
        height: 573,
        width: 810,
        modal: true,
        resizable: false,
        closeOnEscape: false,
        beforeclose: function(event, ui) { $(this).dialog('destroy'); },
        buttons: {
            Close: function() {
                $(this).dialog('destroy');
            }
        }
    });

    document.getElementById("dlgTerms").scrollTop = 0;
}
function ShowPrivacy() {
    $("#dlgPrivacy").dialog({
        bgiframe: true,
        height: 573,
        width: 800,
        modal: true,
        resizable: false,
        closeOnEscape: false,
        beforeclose: function(event, ui) { $(this).dialog('destroy'); },
        buttons: {
            Close: function() {
                $(this).dialog('destroy');
            }
        }
    });
}
function JoinMailing() {

    $("#aspnetForm").submit();
}

function ShowLocatorDialog() {

    $("#LocatorFrame").attr("src", "storelocator/locator.aspx?zip=" + $("#Zipcode").val());

    $("#dlgLocator").dialog({
        bgiframe: true,
        height: 673,
        width: 800,
        modal: true,
        resizable: false,
        closeOnEscape: false,
        beforeclose: function(event, ui) { $(this).dialog('destroy'); },
        buttons: {
            Close: function() {
                $(this).dialog('destroy');
            }
        }
    });
}

function ShowFindDialog() {

    $("#dlgFind").dialog({
        bgiframe: true,
        height: 173,
        width: 400,
        modal: true,
        resizable: false,
        closeOnEscape: false,
        beforeclose: function(event, ui) { $(this).dialog('destroy'); },
        buttons: {
            Close: function() {
                $(this).dialog('destroy');
            }
        }
    });
}

function SubmitAgeValidation() {

    if ($("#Yes")[0].checked == false && $("#No")[0].checked == false) {

        $("#dlgMessage").dialog({
            bgiframe: true,
            height: 173,
            width: 400,
            modal: true,
            resizable: false,
            closeOnEscape: false,
            beforeclose: function(event, ui) { $(this).dialog('destroy'); },
            buttons: {
                Close: function() {
                    $(this).dialog('destroy');
                }
            }
        });

    }
    else {
        $("#aspnetForm").submit();
    }

}

function InitializeAgeValidation() {

    $("#Month").focus(function() {
        if ($(this).val() == "MM") {
            $(this).val("");
        }
    });

    $("#Month").blur(function() {
        if ($(this).val() == "") {
            $(this).val("MM");
        }
    });  
    
    $("#Day").focus(function() {
        if ($(this).val() == "DD") {
            $(this).val("");
        }
    });

    $("#Day").blur(function() {
        if ($(this).val() == "") {
            $(this).val("DD");
        }
    });
    
    $("#Year").focus(function() {
        if ($(this).val() == "YYYY") {
            $(this).val("");
        }
    });

    $("#Year").blur(function() {
        if ($(this).val() == "") {
            $(this).val("YYYY");
        }
    });    
}
