﻿
function AddStylesheet(href) {
    var ss = document.createElement("link");
    ss.type = "text/css";
    ss.rel = "stylesheet";
    ss.href = href;
    document.getElementsByTagName("head")[0].appendChild(ss);
}

function DoWaterMarkOnFocus(txt, text) {
    if (txt.value == text) {
        txt.value = "";
    }
}

function DoWaterMarkOnBlur(txt, text) {
    if (txt.value == "") {
        txt.value = text;
    }
}

function mailPage() {
    mail_str = "mailto:?subject=Check out " + document.title;
    mail_str += "&body=I thought you might be interested in: " + document.title + ".%0D%0A";
    mail_str += "You can view it at, " + location.href;
    location.href = mail_str;
}

function submitFavouriteRecipe() {
    var toAddress = "feedback@buywesteatbest.wa.gov.au";

    mail_str = "mailto:" + toAddress + "?subject=Submit Your Favourite Recipe!";
    mail_str += "&body=";
    location.href = mail_str;
}

/* Simple tabs init, used in:
    Stockist Detail
    Extranet Admin
*/
jQuery(document).ready(function() {

    jQuery(".simple_tab_content").hide(); //Hide all content
    jQuery("ul.simple_tabs li:first").addClass("active").show(); //Activate first tab
    if (jQuery(".tab_content_active").length > 0) {
        jQuery(".tab_content_active").show(); //Show active tab (ie, the one on which an item has just been saved)
    } else {
        jQuery(".simple_tab_content:first").show(); //Show first tab content
    }

    //On Click Event
    jQuery("ul.simple_tabs li").click(function() {

        jQuery("ul.simple_tabs li").removeClass("active"); //Remove any "active" class
        jQuery(this).addClass("active"); //Add "active" class to selected tab
        jQuery(".simple_tab_content").hide(); //Hide all tab content

        var activeTab = jQuery(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        jQuery(activeTab).fadeIn(); //Fade in the active ID content

        // turn off any confirmation messages for the extranet (so user's don't think it's been saved multiple times)
        jQuery(".simple_tab_content .successBox").hide();

        return false;
    });

});

/* Show / Hide panel regions, used in:
    Extranet Admin
*/
jQuery(document).ready(function() {
    jQuery('.ProductHeader').click(function() {
        if (jQuery(this).hasClass('ProductHeaderSelected')) {
            jQuery(this).removeClass('ProductHeaderSelected');
            jQuery(this).next().hide();
        } else {
            jQuery(this).next().toggle('slow');
            jQuery(this).addClass('ProductHeaderSelected');
        }
    });
});

/* Extranet admin specific */
jQuery(document).ready(function() {
    if (jQuery("#SelectedProductId").length > 0) {
        jQuery("#ProductHeader" + jQuery("#SelectedProductId").val()).addClass("ProductHeaderSelected");
        jQuery("#Product" + jQuery("#SelectedProductId").val()).show();
    }
});
