var DLN = DLN || {};
DLN.utils = DLN.utils || {};

DLN.utils.getProductCodeWithColour = function(productCode) {
    var result = "";

    if (typeof productCode === 'string') {
        result = productCode;
        var codeParts = productCode.split('-');
        if (codeParts.length >= 3) {
            result = codeParts[0] + '-' + codeParts[1];
        }
    }

    return result;
};

DLN.utils.getProductSpinnerCode = function(productCode) {
    return DLN.utils.getProductCodeWithColour(productCode) + '_Spin';
};

DLN.utils.getProductCarouselCode = function(productCode) {
    return DLN.utils.getProductCodeWithColour(productCode) + '_Carousel';
};

/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/
(function(c){c.fn.hint=function(b){b||(b="blur");return this.each(function(){function d(){a.val()===e&&a.hasClass(b)&&a.val("").removeClass(b)}var a=c(this),e=a.attr("title"),f=c(this.form),g=c(window);e&&(a.blur(function(){""===this.value&&a.val(e).addClass(b)}).focus(d).blur(),f.submit(d),g.unload(d))})}})(jQuery);


$(document).ready(function() {
    /*
        This function attaches a click handler to all children of a product listing container.
        IE7 doesn't appreciate us wrapping an entire content block in an anchor tag, so
        we force the issue.
     */
    if ( $.browser.msie && parseInt($.browser.version) <= 8) {
        $('.product-listing-link *, a button').each(function(){
            if ($(this).parents('li').parents('ul').parents('div.related').length > 0) {
            	return;
            }
        	$(this).css({
                cursor: 'pointer'
            });
            $(this).click(function(e){
                e.stopPropagation();
                document.location.href = $(this).parents('a').attr('href');
            });
        });
    }

    $('input[title!=""]').hint();

    if ( $.browser.msie && parseInt($.browser.version) <= 7) {
        window.jscript/*@cc_on=@_jscript_version@*/
        if (jscript == 5.7)
        {//if IE7
            var inputs = document.getElementsByTagName("input"), i = -1, l = inputs.length;
            while (++i !== l)
            {
                var inputs_i = inputs[i];
                if ((inputs_i.type == "checkbox") && inputs_i.onchange)
                {
                    inputs_i._onchange = inputs_i.onchange;
                    inputs_i.onchange = null;
                    inputs_i.onpropertychange = function()
                    {
                        if (event.propertyName == 'checked') this._onchange();
                    };
                }
            }
        }
    }
});

