//  Shop frontend by Novicell - www.novicell.dk - KHA, APN - We love Umbraco + uCommerce
$(document).ready(function () {
    $('#subpage_search').prepareFormFieldsLabelInside();
    $('#search_form').prepareFormFieldsLabelInside();

    $(".productListOnCategoryPage .yellow_button_click").click(function (event) {
        event.preventDefault();
        var cssDisplay = $(this).parent().find("#variantSelectorArea").css("display");
        if (cssDisplay == "none") {
            var displayStatus = "display:block;";
        } else {
            var displayStatus = "display:none;";
        }
        $(this).parent().find("#variantSelectorArea").attr('style', displayStatus);
    });

    $('.left_menu_item b').click(function () {
        $(this).parent().toggleClass('opened').find('.submenu').toggleClass('submenuShow');
    });


    $("#loginForm").submit(function () {
        if ($("#loginBrugernavn").val() != "Brugernavn") {
            return true;
        }
        $("#formErrorMessage").show();
        $("#loginBrugernavn").addClass('error');
        $("#loginKode").addClass('error');
        return false;
    });

});


(function ($) {                                          // Compliant with jquery.noConflict()
    $.fn.prepareFormFieldsLabelInside = function (o) {
        o = $.extend({
            textfield: true,
            textarea: true,
            password: true
        }, o || {});

        return this.each(function () {                           // Returns the element collection. Chainable.


            if (o.textfield)
                doTextfield($(this))

            if (o.textarea)
                doTextarea($(this))

            if (o.password)
                doPassword($(this))

            function doTextfield(objFieldAncestor) {
                $(objFieldAncestor).find('input[type=text][title]').focus(function () { showHideInputValue($(this), 'focus') }).blur(function () { showHideInputValue($(this), 'blur') }).each(function () { showHideInputValue($(this), 'blur') });
            };

            function doTextarea(objFieldAncestor) {
                $(objFieldAncestor).find('textarea[title]').focus(function () { showHideInputValue($(this), 'focus') }).blur(function () { showHideInputValue($(this), 'blur') }).each(function () { showHideInputValue($(this), 'blur') });
            };

            function doPassword(objFieldAncestor) {
                $(objFieldAncestor).find('input[type=password][title]').focus(function () { showHidePasswordLabel($(this), 'focus') }).blur(function () { showHidePasswordLabel($(this), 'blur') }).each(function () { $(this).wrap('<label for="' + $(this).attr('id') + '"></label>'); $(this).before('<span>' + $(this).attr('title') + '</span>'); });
            };

        });
        function showHideInputValue(argObj, argStrType) {
            if (argStrType == 'focus' && $(argObj).val() == $(argObj).attr('title'))
                $(argObj).val('')
            else if ($(argObj).val() == "")
                $(argObj).val($(argObj).attr('title'))
        }

        function showHidePasswordLabel(argObj, argStrType) {
            if (argStrType == 'focus')
                $(argObj).prev().hide()
            else if ($(argObj).val() == "")
                $(argObj).prev().show()
        }
    };

})(jQuery);

