    $(document).ready(function()
    {
        function overlayClose()
        {
            $('body').css('overflow','visible');
            $('.overlay').hide();
            $('.mask').hide();
            $('.overlay .description').html("");
        }
        $("input[type=text],input[type=password],textarea,select").focus(
        function()
        {
            $(this).toggleClass("highlight");
        });
        $("input[type=text],input[type=password],textarea,select").blur(
        function()
        {
            $(this).toggleClass("highlight");
        });

        
        $("#btnLoginShow").click(
        function()
        {
            $(".panel .inner").show();
            $(".panel .inner").css({ 'visibility': 'visible' });
            $("div.panel").animate({ height: "110px" });
            $(".search").fadeOut("fast");
            $("#txtusername").focus();
            return false;
        });
        
        $("#btnLoginHide").click(
        function()
        {
            $("div.panel").animate({ height: "0px" });
            $(".search").fadeIn("fast", function () { $(".panel .inner").hide(); $(".panel .inner").css({ 'visibility': 'hidden' }); } );
            
            return false;
        });
        
        $("#btnSubscribeShow").click(
        function()
        {
            $(".subscribe .inner").show();
            $(".subscribe .inner").css({ 'visibility': 'visible' });
            $("div.subscribe").animate({ height: "160px" });
            $(".search").fadeOut("fast");
            
            // Add help captions for name
            //fnResetSubscriberFirstName();
            //fnResetSubscriberLastName();
            return false;
        });
        /*
        $("#txtsubscriberfirstname").focus( function() {
            fnBlankSubscriberFirstName();
        });
        $("#txtsubscriberfirstname").blur( function() {
            fnResetSubscriberFirstName();
        });
        $("#txtsubscriberlastname").focus( function() {
            fnBlankSubscriberLastName();
        });
        $("#txtsubscriberlastname").blur( function() {
            fnResetSubscriberLastName();
        });
        */
        
        function fnResetSubscriberFirstName()
        {
            if($("#txtsubscriberfirstname").val() == '')
            {
                $("#txtsubscriberfirstname").val('First Name');
            }
        }
        function fnBlankSubscriberFirstName()
        {
            if($("#txtsubscriberfirstname").val() == 'First Name')
            {
                $("#txtsubscriberfirstname").val('');
            }
        }
        function fnResetSubscriberLastName()
        {
            if($("#txtsubscriberlastname").val() == '')
            {
                $("#txtsubscriberlastname").val('Last Name');
            }
        }
        function fnBlankSubscriberLastName()
        {
            if($("#txtsubscriberlastname").val() == 'Last Name')
            {
                $("#txtsubscriberlastname").val('');
            }
        }
        
        
        $("#btnSubscriberHide").click(
        function()
        {
            $("div.subscribe").animate({ height: "0px" });
            $(".search").fadeIn("fast", function () { $(".subscribe .inner").hide(); $(".subscribe .inner").css({ 'visibility': 'hidden' }); } );
            return false;
        });  
        
        $("#btnSG_Company").click(
        function()
        {
            SupplierGuideTabHide();
            
            $("#fstSG_Company").show();
            $("#fstSG_Company").css({ 'visibility': 'visible' });
            
            $("#btnSG_Company").addClass("selected");
            return false;
        });  
        
        $("#btnSG_Product").click(
        function()
        {
            SupplierGuideTabHide();

            $("#fstSG_Product").show();
            $("#fstSG_Product").css({ 'visibility': 'visible' });
            
            $("#btnSG_Product").addClass("selected");
            return false;
        });  
        
        $("#btnSG_Brand").click(
        function()
        {
            SupplierGuideTabHide();

            $("#fstSG_Brand").show();
            $("#fstSG_Brand").css({ 'visibility': 'visible' });
            
            $("#btnSG_Brand").addClass("selected");
            return false;
        });  
        
        $("#btnSG_Wholesale").click(
        function()
        {
            SupplierGuideTabHide();
            
            $("#fstSG_Wholesale").show();
            $("#fstSG_Wholesale").css({ 'visibility': 'visible' });
            
            $("#btnSG_Wholesale").addClass("selected");
            
            if($('#cmbcountryid').val() == 215)
            {
                /***    SHOW POSTCODE    ***/
                $("#questionpostcode").show();
            }
            else
            {
                /***    HIDE POSTCODE    ***/
                $("#questionpostcode").hide();
            }
            
            
            return false;
        });
        
        /* show first tab and select it */
        SupplierGuideTabHide();
        $("#fstSG_Company").show();
        $("#fstSG_Company").css({ 'visibility': 'visible' });
        $("#btnSG_Company").addClass("selected");
        
        $("#topreply").click(function ()
        {
            var p = $('#frmContent').position();
            $('html, body').animate({scrollTop: (p.top - 550) }, 'slow', 'swing');             
            $('#txtContent').focus();
            return false;
        });
        
        /* overlay panel */
        $('.popup').click(function ()
        {
            $('.overlay').css(
            {
                top: parseInt($(window).scrollTop() + (($(window).height() - $('.overlay').height())/2)) + 'px',
                left: parseInt($(window).scrollLeft() + (($(window).width() - $('.overlay').width())/2)) + 'px'
            });
            $('body').css('overflow','hidden');
            $('.mask').show();
            $('.overlay').show();
            $('.overlay .progress').show();
                    
            var varFile = '/_download/ms/' + $(this).attr('id') + '.htm';
            var varTitle = $(this).text();
            $.ajax(
            {
                url: varFile,
                global: false,
                //type: "post",
                //dataType: "html",
                success: function(data)
                {
                    $('.overlay .progress').hide();
                    $('.overlay .title').html(varTitle);
                    $('.overlay .description').html(data);
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) { 
                    overlayClose();
                },
                complete: function (XMLHttpRequest, textStatus) { }
            });
            return false;
        });
        $('.overlay .close').click(function ()
        {
            overlayClose();
        });
        
        /* adverts */
        var tmrInterval;
        function advertSwap()
        {
            var lngSlot = 0;
            var lngAdvert = 0;
            var lngShowing = 0;
            var lngNext = 0;
            var lngLog = 0;
            var varAdvertID = "";
            $('.advertslot').each(function(i)
            {
                lngAdvert = 0;
                var lngAdverts = $(this).find('.advert,.advert_big').length;
                if (lngAdverts > 1)
                {
                    for (x=0;x<lngAdverts;x++)
                    {
                        if ($(this).find('.showing:nth-child(' + (x+1) + ')').length > 0)
                        {
                            lngShowing = x;
                        }
                    }
                    if (lngShowing + 1 == (lngAdverts))
                    {
                        lngNext = 0;
                    } else {
                        lngNext = lngShowing + 1;
                    }
                    if ($('#advertslot' + lngSlot).find('div:eq(' + lngShowing + ').log').length)
                    {
                        $('#advertslot' + lngSlot).find('div:eq(' + lngShowing + ')').removeClass('log');
                        varAdvertID = varAdvertID + $('#advertslot' + lngSlot).find('div:eq(' + lngShowing + ')').attr('id') + ',';
                    }
                    $('#advertslot' + lngSlot).find('div:eq(' + lngShowing + ')').removeClass('showing');
                    $('#advertslot' + lngSlot).find('div:eq(' + lngNext + ')').addClass('showing');
                    
                }
                lngSlot++;
            });
            varAdvertID = varAdvertID.replace(/advert/gi, "");
            if (varAdvertID != "")
            {
                $.post("/_admin/_api/advertlog.asp", { ids: varAdvertID } );
            }
        }
        tmrInterval = setInterval(advertSwap, 10000);
        
        if ($.browser.msie === true)
        {
            if ($.browser.version == '6.0')
            {
                $('.button_small').css('paddingTop', '10px');
            }
        }
        
        if ($('#lblRefineResults').length > 0)
        {
            if ($.browser.msie === true)
            {
                $('#searchresults').hide();
            } else {
                $('#searchresults').hide();
                $('#searchresults').animate( {height: '0', opacity: 0 }, 50, 'swing' );
                $('#searchresults').show();
            }
            $('#lblRefineResults').click( function ()
            {
                if ($.browser.msie === true)
                {
                    $('#searchresults').show();
                } else {
                    $('#searchresults').animate( {height: '210px', opacity: 1 }, 500, 'swing' );
                }
                $('#lblRefineResults').hide();
                return false;
            });
        }        
    });
function SupplierGuideTabShow()
{
    $("#fstSG_Company").show();
    $("#fstSG_Company").css({ 'visibility': 'visible' });
    
    $("#fstSG_Product").show();
    $("#fstSG_Product").css({ 'visibility': 'visible' });
    
    $("#fstSG_Brand").show();
    $("#fstSG_Brand").css({ 'visibility': 'visible' });
    $("#btnSG_Company").toggleClass("selected");
    
    $("#fstSG_Wholesale").show();
    $("#fstSG_Wholesale").css({ 'visibility': 'visible' });
    $("#btnSG_Company").toggleClass("selected");
}
function SupplierGuideTabHide()
{
    SupplierGuideTabSelections();
    
    $("#fstSG_Company").hide();
    $("#fstSG_Company").css({ 'visibility': 'hidden' });
    
    $("#fstSG_Product").hide();
    $("#fstSG_Product").css({ 'visibility': 'hidden' });
    
    $("#fstSG_Brand").hide();
    $("#fstSG_Brand").css({ 'visibility': 'hidden' });
    
    $("#fstSG_Wholesale").hide();
    $("#fstSG_Wholesale").css({ 'visibility': 'hidden' });
}
function SupplierGuideTabSelections()
{
    $("#btnSG_Company").removeClass("selected");
    $("#btnSG_Product").removeClass("selected");
    $("#btnSG_Brand").removeClass("selected");
    $("#btnSG_Wholesale").removeClass("selected");
}

