function HomepageSlideShow()
{
    var flashvars = {};
    var params = {};
    params.wmode = "transparent",
    params.menu = "false";
    params.allowScriptAccess = "always";
    var attributes = {};
    swfobject.embedSWF("/assets/flash/BachmanSlideShow.swf", "slide-show-content", "460", "560", "10.0.0", "false", flashvars, params, attributes);
}

function HomepageCallouts()
{
    var flashvars = {};
    var params = {};
    params.wmode = "transparent",
    params.menu = "false";
    params.allowScriptAccess = "always";
    var attributes = {};
    swfobject.embedSWF("/assets/flash/CalloutRotator.swf", "callouts-content", "349", "345", "10.0.0", "false", flashvars, params, attributes);
}

function ScrollContent()
{
    $('#overflow-content').jScrollPane({
        scrollbarWidth:8,
        dragMaxHeight :30
    });
}

function InitPopupLinks()
{
    $('a[rel~="popup"]').click(function() {

        var w_Width = 600;
        var w_Height = 600;
        var scrollbars = 1;

        if($(this).closest('li').attr('id') == 'nutritional-information'){
            w_Width = 335;
            w_Height = 600;
        }

        if($(this).closest('li').attr('id') == 'kidzels-zone'){
            w_Width = 650;
            w_Height = 450;
            scrollbars = 0;
        }

        window.open($(this).attr('href'), 'popup', 'width=' + w_Width + ',height=' +  w_Height + ',scrollbars='+ scrollbars + ', resizable=0');
        return false;
    });
}

function InitPrintLink()
{
    $('a[rel$="print"]').click(function(){
        
        var id = $(this).attr('href');

        var win = window.open("");
        win.document.write($(id).html());
        win.print();

        return false;
    });
}

function InitCardPrinkLink()
{
    $('a[rel$="recipe-card"]').click(function(){

        var id = $(this).attr('href');

        var win = window.open("");
        win.document.write("<html><head><style type='text/css'>body{font-size:62.5%;font-family:Georgia;margin:0;padding:0;}ul{float:left;width:30%;list-style:none;margin:0 10px 10px 0;padding:0;height:100%;}h2{font-size:12px;margin-top:0;padding-top:0;}</style></head><body><div style='height:3in;width:5in;overflow:hidden;border:.0125in dashed #000;'>" + $(id).html() + "</div></body></html>");
        win.print();

        return false;
    });
}

function confirm_delete(message)
{
    $('#form_delete').click(function(){
        return confirm(message);
    });
    
}

function ValidateAdminForm(_id)
{
    $(_id).validate(
        {rules: {
                form_edit_first_name:{
                    required:true
                },
                form_first_name:{
                    required:true
                },
                form_edit_last_name:{
                    required:true
                },
                form_last_name:{
                    required:true
                },
                 form_email_address:{
                     required:true,
                     email:true
                 },
                 form_edit_email_address:{
                     required:true,
                     email:true
                 },
                 form_edit_password_confirmation: {
                    required: "#form_edit_password:filled",
                    equalTo: "#form_edit_password"
                },
                 form_password_confirmation: {
                    required: "#form_password:filled",
                    equalTo: "#form_password"
                },
                form_edit_phone_number:{
                     required: true,
                     minlength:10,
                     phoneUS: true
                },
                form_phone_number:{
                     required: true,
                     minlength:10,
                     phoneUS: true
                 },
                 form_edit_address:{
                     required: true
                 },
                 form_address:{
                     required: true
                 },
                 form_date_of_birth:{
                     required: true,
                     maxlength: 10,
                     date:true
                 },
                 form_edit_date_of_birth:{
                     required: true,
                     maxlength: 10,
                     date:true
                 }
             },
             messages:  {
                form_edit_first_name: "<span class='error-notice'>First name is required.</span>",
                form_first_name: "<span class='error-notice'>First name is required.</span>",
                form_edit_last_name: "<span class='error-notice'>Last name is required.</span>",
                form_last_name: "<span class='error-notice'>Last name is required.</span>",
                form_edit_address: "<span class='error-notice'>Address is required.</span>",
                form_address: "<span class='error-notice'>Address is required.</span>",
                form_edit_date_of_birth: {
                    required: "<span class='error-notice'>DOB is required.</span>",
                    maxlength: "<span class='error-notice'>DOB is too long.</span>",
                    date: "<span class='error-notice'>DOB must be a valid date (mm/dd/yyyy).</span>"
                },
                form_date_of_birth: {
                    required: "<span class='error-notice'>DOB is required.</span>",
                    maxlength: "<span class='error-notice'>DOB is too long.</span>",
                    date: "<span class='error-notice'>DOB must be a valid date (mm/dd/yyyy).</span>"
                },
                form_edit_email_address: {
                    required: "<span class='error-notice'>Email Address required.</span>",
                    email: "<span class='error-notice'>Email must be a valid email.</span>"
                },
                form_email_address: {
                    required: "<span class='error-notice'>Email Address required.</span>",
                    email: "<span class='error-notice'>Email must be a valid email.</span>"
                },
                form_edit_password_confirmation: {
                    required: "<span class='error-notice'>Password confirmation required.</span>",
                    equalTo: "<span class='error-notice'>Password confirmation must match password.</span>"
                },
                form_password_confirmation: {
                    required: "<span class='error-notice'>Password confirmation required.</span>",
                    equalTo: "<span class='error-notice'>Password confirmation must match password.</span>"
                }
             }
         }
    );
        
    jQuery.validator.addMethod("phoneUS", function(phone_number, element)
    {
            phone_number = phone_number.replace(/\s+/g, "");
            return this.optional(element) || phone_number.length > 9 &&
            phone_number.match(/^(1-?)?(\([1-9]\d{2}\)|[1-9]\d{2})-?[1-9]\d{2}-?\d{4}$/);

    }, "<span class='error-notice'>Phone number is not valid format.</span>");
}

function validate_contact_form(_id)
{
    $(_id).validate(
        {rules: {
                form_name:{
                    required:true
                },
                form_email_address:{
                     required:true,
                     email:true
                },
                form_phone_number:{
                     minlength:10,
                     phoneUS: true
                },
                form_product: {
                    required: true
                },
                form_message:{
                    required: true
                },
                form_zip_code:{
                    required: true,
                    minLength: 5,
                    maxLength: 5,
                    regex: {
                        regexp: "^[a-zA-Z'.\s]{1,40}$",
                        message: "Zip code is not formatted correctly."
                    }
                }
             },
             messages:  {
                form_name: "<span class='error-notice'>*</span>",
                form_message: "<span class='error-notice'>*</span>",
                form_phone_number: {
                    minlength: "<span class='error-notice'>*</span>",
                    phoneUS: "<span class='error-notice'>Phone Number is not valid phone number.</span>"
                },
                form_email_address: {
                    required: "<span class='error-notice'>*</span>",
                    email: "<span class='error-notice'>Email must be a valid email.</span>"
                },
                form_zip_code: {
                    required: "<span class='error-notice'>*</span>",
                    minLength: "<span class='error-notice'>Five digit zip code only.</span>",
                    maxLength: "<span class='error-notice'>Five digit zip code only.</span>",
                    regex: "<span class='error-notice'>Zip code is not formatted correctly.</span>"
                }
             }
         }
    );

    jQuery.validator.addMethod("phoneUS", function(phone_number, element)
    {
            phone_number = phone_number.replace(/\s+/g, "");
            return this.optional(element) || phone_number.length > 9 &&
            phone_number.match(/^(1-?)?(\([1-9]\d{2}\)|[1-9]\d{2})-?[1-9]\d{2}-?\d{4}$/);

    }, "<span class='error-notice'>*</span>");

    jQuery.validator.addMethod("regex", function(value, element, regexp){
       var re = new RegExp(regexp);
       return this.optional(element) || re.test(value);
    }, "<span class='error-message'>a</span>")
}

/*
 * Old but still used
 * Guess for sweepstakes due to the lack of space
 */
function ValidateForm(_id)
{
    $(_id).validate(
        {rules: {
                 form_email_address:{
                     required:true,
                     email:true
                 },
                 form_password_confirmation: {
                    required: true,
                    equalTo: "#form_password"
                },
                form_date_of_birth:{
                    required: true,
                    maxlength: 10,
                    date: true
                },
                form_phone_number:{
                     required: true,
                     minlength:10,
                     phoneUS: true,
                     messages:{
                         required: "*",
                         minlength: "*",
                         phoneUS: "*"
                     }
                 }
             }
         }
    );

    jQuery.validator.addMethod("phoneUS", function(phone_number, element)
    {
            phone_number = phone_number.replace(/\s+/g, "");
            return this.optional(element) || phone_number.length > 9 &&
            phone_number.match(/^(1-?)?(\([1-9]\d{2}\)|[1-9]\d{2})-?[1-9]\d{2}-?\d{4}$/);

    }, "<span class='error-notice'>*</span>");

//The Phone Number is not valid, e.g. 123-456-7890

    jQuery.extend(jQuery.validator.messages, {
        required: "<span class='error-notice'>*</span>",
        email: "<span class='error-notice'>*</span>",
        minlength: "<span class='error-notice'>*</span>",
        maxlength: "<span class='error-notice'>*</span>",
        date: "<span class='error-notice'>*</span>"
        //,phoneUS: "<span class='error-notice'>Phone not valid</span>"
    });
}

function InitIE6DropDowns()
{
    var sfEls = document.getElementById("primary-navigation").getElementsByTagName("LI");
    for (var i = 0; i < sfEls.length; i++) {
        sfEls[i].onmouseover = function() {
            this.className += " sfhover";
        }
        sfEls[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}
