﻿
var needchange = false;
var FormatWideOfContent_Nav_timers = 1;
var PressDlgImgsScroll_timers = 1;
var timerb = (new Date()).valueOf();

$(document).ready(function() {
    //embed
    $('embed').attr('wmode', 'opaque');
    //not leaving site
    $('a').click(function() {
        still_in_site('1');
    });
    $('form').submit(function() { still_in_site('1'); });

    //submitbutton
    $('.submitbutton').click(function() { $(this).parents('form').submit(); });

    try {
        $(".sf-menu").superfish({ delay: 0, speed: 'fast' });
        $('.sf-menu a').click(function() {
            var text = '';
            if ($(this).find('img').length > 0) {
                text = $(this).find('img').attr('alt');
            } else {
                var parenttext = $(this).parent().parent().parent().find('img').attr('alt');
                if (parenttext) parenttext += ' - ';
                text = parenttext + $.trim($(this).text());
            }
            //alert(text);
            gaNavEvent(text);

        });
    } catch (err) { }

    //Timer Display
    if ($.cookie('Debug') == 1) {
        if (window.console && window.console.firebug) {
            console.log($('#timers').html())
        }
    }

    //FormatLinks
    FormatLinks('.text_body');
    //FormatLinks('.press_more'); 
    FormatLinks('.productDescription');
    FormatLinks('.whatsnew_text');
    $('.content p').eq(0).addClass('nop');


    //Content nested
    $('.content .content .content_banner').remove();
    $('.content .content .content_nav').remove();
    $('.content .content').removeClass('content');


    //(click to view)
    if ($('.content:contains("(click to view)")').length == 0 && $('.content .text_header').length > 0) {
        if ($('.content .text_header').eq(0).parent().is('li')) {
            $('.content .text_header').eq(0).parent().parent().before('<p class="nobottom">(click to view)</p>');
        } else {
            $('.content .text_header').eq(0).before('<p class="nobottom">(click to view)</p>');
        }
    }



    //too much space
    var li_length = $('.press_li').length;
    $('.press_li:eq(' + (li_length - 1) + ')').css('margin-bottom', '0px');
    if (li_length % 3 == 0 || li_length % 3 == 2) $('.press_li:eq(' + (li_length - 2) + ')').css('margin-bottom', '0px');
    if (li_length % 3 == 0) $('.press_li:eq(' + (li_length - 3) + ')').css('margin-bottom', '0px');


    li_length = $('.ulcategories li').length;
    $('.ulcategories li:eq(' + (li_length - 1) + ')').css('margin-bottom', '8px');
    if (li_length % 3 == 0 || li_length % 3 == 2) $('.ulcategories li:eq(' + (li_length - 2) + ')').css('margin-bottom', '8px');
    if (li_length % 3 == 0) $('.ulcategories li:eq(' + (li_length - 3) + ')').css('margin-bottom', '8px');

    $('.whatsnew_holder:last').css('margin-bottom', '2px');



    //PDF link
    /*
    $('.content a').each(function(i){
    if($(this).attr('href') )
    if($(this).attr('href').toLowerCase().indexOf('.pdf')==$(this).attr('href').toLowerCase().lastIndexOf('.pdf')&& $(this).attr('href').toLowerCase().indexOf('.pdf')!=-1 && $(this).attr('class')!='nopdficon' ){
    $(this).css('background','url(/images/PDF_icon2.png) left center no-repeat');
    $(this).css({'padding-left':'17px'});
    //$(this).css({'display':'block'});
    }	
    }
    );
    */

    //$('.jqmWindow').css('position','absolute');
    //$('.jqmWindow').css('left','50%');	
    //$('.jqmWindow').css('top','12%');	

    //roll images
    $('.img_roll').hover(function() {
        if ($(this).attr('src'))
            $(this).attr('src', $(this).attr('src').replace('/off/', '/on/'));
    }, function() {
        if ($(this).attr('src'))
            $(this).attr('src', $(this).attr('src').replace('/on/', '/off/'));
    });


    $('.ulsubcategories li').hover(function() {
        var id = $(this).attr('class');
        id = id.substr(id.lastIndexOf('_') + 1);

        if ($('.img_roll_' + id).attr('src'))
            $('.img_roll_' + id).attr('src', $('.img_roll_' + id).attr('src').replace('/off/', '/on/'));
    },
    function() {
        var id = $(this).attr('class');
        id = id.substr(id.lastIndexOf('_') + 1);

        if ($('.img_roll_' + id).attr('src'))
            $('.img_roll_' + id).attr('src', $('.img_roll_' + id).attr('src').replace('/on/', '/off/'));
    }
    );


    //roll end



    //home eyecare link
    $('.home_12').css('cursor', 'pointer');
    $('.home_12').click(function() {
        location.href = '/?PageID=107'
    });


    //show the box

    Highlightcontent_nav_auto();
    $('.content_nav li').hover(function() {
        if (!$(this).attr('class')) {
            $(this).attr('class', 'content_nav_on');
            needchange = true;
        }
    },
    function() {
        if (needchange) {
            $(this).attr('class', '');
            needchange = false;
        }
    }
    );



    //txtKeywords
    $('#txtKeywords').focus(function() {
        if ($('#txtKeywords').val() == 'keywords' || $('#txtKeywords').val() == 'Search') { $('#txtKeywords').val('') }
    });

    $('#txtKeywords').change(function() {
        GotoSearch();
    });

    $('.top_bar_nav_search').click(function() {
        //GotoSearch();		
    });

    //Press images 
    if (location.href.indexOf('press') == -1) {
        $('.press_img').click(function() {
            PressLiClick($(this).parent().parent());
        });
    } else {
        $('.press_li').click(function() {
            PressLiClick(this);
        });
    }




    //clicking on title expands selection
    $('.text_body .text_header').attr('class', 'text_header_sub');
    $('.text_body .text_body').attr('class', 'text_body_sub');

    $('.text_header').each(function(i) {
        $('.text_header').eq(i).click(function() {
            text_header_click(i);
        });
    });

    $('.text_header_sub').each(function(i) {
        $('.text_header_sub').eq(i).click(function() {
            text_header_sub_click(i);
        });
    });

    //slide shows for whats new
    $('.whatsnew_img br').remove();

    $('.whatsnew_img').each(function(i) {
        if ($('.whatsnew_img:eq(' + i + ') img').length > 1)
            $('.whatsnew_img').eq(i).cycle({ fx: 'fade', timeout: 3500, speed: 2000 });
    });


    //home img_homeshopbanner, img_whatnew
    //setTimeout("slideshopbanner()",3500);

    if ($('.shop_slide_fm a').length > 1) {
        $('.shop_slide_fm').cycle({ fx: 'fade', timeout: 3500, speed: 2000 });
    } else {
        $('.shop_slide_fm a').cycle({ fx: 'fade', timeout: 3500, speed: 2000 });
    }

    if ($('.whatnew_slide_fm a').length > 1) {
        $('.whatnew_slide_fm').cycle({ fx: 'fade', timeout: 3500, speed: 2000 });
    } else {
        $('.whatnew_slide_fm a').cycle({ fx: 'fade', timeout: 3500, speed: 2000 });
    }


    if ($('.hm2_welcomeimg').attr('class')) {
        setTimeout("RemoveWelcome()", 4000);
    } else {
        InitHm2Slide();
    }





    $('.content_banner').html('<div class="conent_banner_fm">' + $('.content_banner').html() + '</div>');

    if ($('.conent_banner_fm img').length > 1) {
        $('.conent_banner_fm').cycle({ fx: 'fade', timeout: 3500, speed: 2000 });
    }

    $('.eyecare_1_2_fm').cycle({ fx: 'fade', timeout: 3500, speed: 2000 });

    //gray yellow btn

    $('.btn_gray_yellow').hover(function() {
        $(this).attr('src', $(this).attr('src').replace('_gray', '_yellow'));
    },
    function() {
        $(this).attr('src', $(this).attr('src').replace('_yellow', '_gray'));
    }
    );

    //SysHeight of logo and desc of shop
    setTimeout("SysHeight_logo_des()", 500);

    //Drop down rolling
    $('.text_header').hover(function() { $(this).addClass('CCBFA8'); }, function() { $(this).removeClass('CCBFA8'); });

    $('.lblpop').hover(function() { $(this).addClass('CCBFA8'); }, function() { $(this).removeClass('CCBFA8'); });
    $('.text_header_sub').hover(function() { $(this).addClass('CCBFA8'); }, function() { $(this).removeClass('CCBFA8'); });
    $('#body_fm_115 .text_header').hover(function() { $(this).addClass('C_000'); }, function() { $(this).removeClass('C_000'); });
    $('.black70 .lblpop').hover(function() { $(this).addClass('CCBFA8'); }, function() { $(this).removeClass('CCBFA8'); });

    $('.plfeedbacklink').click(function() {
        window.showModalDialog("feedback.asp?url=" + location.href, null, "dialogWidth:600px; dialogHeight:320px; ");
        /*
        $('#pldlgContent').html('<div class="pldlgfeedback_scroll"></div>');		
        $('#dialog').jqm().jqmShow();	
        $('.pldlgfeedback_scroll').jScrollPane({scrollbarWidth:19});
        */
    });

    //pop-up
    $('.lblpopglossary').click(function() { window.showModalDialog("sizing.asp?show=glossary", null, "dialogWidth:849px; dialogHeight:600px; "); });
    $('.lblpopintakeglossary').click(function() {
        var ant = $(this).text();
        if (ant.indexOf(' ') != -1) {
            ant = ant.substr(ant.lastIndexOf(' ') + 1);
        }
        window.showModalDialog("intakeglossary.asp#" + ant, null, "dialogWidth:849px; dialogHeight:600px; ");
    });
    $('.lblpopsizing').click(function() { window.showModalDialog("sizing.asp?show=size", null, "dialogWidth:849px; dialogHeight:600px; "); });
    $('.lblpopframe').click(function() { window.showModalDialog("sizing.asp?show=frame", null, "dialogWidth:849px; dialogHeight:600px; "); });
    $('.lblpopchat').click(function() { window.showModalDialog("chat.asp", null, "dialogWidth:616px; dialogHeight:760px; "); });
    $('.lblpopdonation').click(function() { window.showModalDialog("donation.asp", null, "dialogWidth:849px; dialogHeight:300px; "); });

    /*
    $('.lblpoptryon').click(function() {
    //window.showModalDialog("tryon_pop.asp?dlg=1&id=" + productID, null, "dialogWidth:849px; dialogHeight:669px; ");
    location.href = 'tryon.asp?id=' + productID;
    });
    */
    $('.lbllensguide').click(function() {
        var show = 'single';
        if ($('#drpFor').val().indexOf('Progressive') != -1) show = 'multi';

        window.showModalDialog('lensguide.asp?show=' + show, null, "dialogWidth:830px; dialogHeight:726px; ");
        /*
        $('#dialog').load('lensguide.asp?dlg=1&show=' + show,
        function() {
        $('#dialog').attr('class', 'jqmWindow jqmWindow_s');
        $('#dialog').jqm().jqmShow();
        }
        );*/
    });


    $('.lblmaillist').click(function() {
        $('#dialog').load('mailinglist.asp?dlg=1',

        function() {
            $('#dialog').css('top', '100px');
            $('#dialog').attr('class', 'jqmWindow jqmWindow_ss');
            $('#dialog').jqm().jqmShow();
        }
        );
    });

    //eyecare_1_3
    $('.eyecare_1_3 a').hover(function() {
        $('.eyecare_1_3').css('background-image', 'url(/images/on/eyecare_1_3.jpg)');
    },
    function() {
        $('.eyecare_1_3').css('background-image', 'url(/images/off/eyecare_1_3.jpg)');
    }
    );

    //input type submit onHovers
    $('input.submit').hover(function() { $(this).addClass('CCBFA8'); }, function() { $(this).removeClass('CCBFA8'); });

    //InitValidation_Gif
    InitValidation_Gif();
    try {
        $('.accountform').submit(function() {
            if ($('.login_shippingaddr_content').css('display').toLowerCase() == 'none') {
                lblSetSameShipping_click();
            }
        });
        $('.accountform').validate({
            rules: {
                Password2: {
                    required: true,
                    equalTo: "#txtAccountPassword"
                }
            },
            messages: {
                Password2: {
                    equalTo: "!="
                }
            }
        });
        $('.validate').validate();
    } catch (err) { }
    //FormatWideOfContent_Nav
    setTimeout("FormatWideOfContent_Nav()", 100);

    //InitFormFields
    InitFormFields();

    //tr01
    $('.tr01 tr:odd').addClass('tr1');
    $('.tr01 tr:even').addClass('tr0');

    $('.tr10 tr:odd').addClass('tr0');
    $('.tr10 tr:even').addClass('tr1');

    //NO12
    $('.lblNO1').click(function() { $('.rdNO1').attr('checked', 'checked') });
    $('.lblNO2').click(function() { $('.rdNO2').attr('checked', 'checked') });

    SysHeight('.content_tleft', '.content_tright', 0);

    //
    if ($('.hide_content').attr('class')) {
        $('.body_fm').addClass('body_fm2');
    }

    //GA event
    InitGAClick('.hm2_slide a', 'HomeSlide', 'Click');
    InitGAClick('.somefutureGA a', 'SomeCat', 'SomeAction');
})

function InitGAClick(select, category, action) {
    $(select).click(function() {
        // txt, alt, filename
        var lbl = $.trim($(this).text());
        if (lbl.length == 0 && $(this).find('img').length > 0) {
            lbl = $(this).find('img').attr('alt');
            if (lbl.length == 0) {
                lbl = $(this).find('img').attr('src');
                if (lbl.indexOf('/') != -1) {
                    lbl = lbl.substr(lbl.lastIndexOf('/') + 1);
                }
            }
        }
        //and link
        var link = $(this).attr('href');
        if (link.indexOf('/') != -1) {
            link = link.substr(link.lastIndexOf('/') + 1);
        }
        lbl = lbl + '-' + link;
        GAClick(category, action, lbl);
    });
}

function GAClick(category, action, optional_label) {
    try {
        if (location.href.indexOf('lamp') != -1) {
            alert(category + ',' + action + ',' + optional_label);
        }
        pageTracker._trackEvent(category, action, optional_label);
    } catch (err) { }
}

function lblEnterShipping_click() {
    $('.lblSetSameShipping').show();
    $('.login_shippingaddr_content').show();
    $('.lblEnterShipping').hide();
    $('.lblbillingshipping').html('Billing');
}

function lblSetSameShipping_click() {
    $('#drpShipState').val($('#drpState').val());
    try { FillFields(this); } catch (err) { };
    selectShipCountry_change();
}
function AccountLoginPress(event) {
    var keyCode = (event) ? event.keyCode : keyStroke.which;
    //alert(keyCode);

    if (keyCode == 13) {
        AccountLogin();
        return false;
    }
    return true;
}



function AccountLogin() {
    var username = $('#txtUsername').val();
    var password = $('#txtPassword').val();


    if (username.indexOf('@') != -1 && username.indexOf('.') != -1) {
        location.href = 'login.asp?username=' + $('#txtUsername').val() + '&Password=' + $('#txtPassword').val() + '&TargetPage=cart.asp';
    }
    else {
        $('#txtUsername').focus();
        return;
    }

    if (password.length == 0) {
        $('#txtPassword').focus();
        return;
    }
}
function PopUp(url, w, h) {
    window.showModalDialog(url, null, "dialogWidth:" + w + "px; dialogHeight:" + h + "px; ");
    return false;
}

function Highlightcontent_nav_auto() {
    var loc = location.href;
    loc = loc.substr(loc.lastIndexOf('/'));
    $('.content_nav_auto a[href="' + loc + '"]').parent().not($('.content_nav_auto li').eq(0)).addClass('content_nav_on');

}


function InitHm2Slide() {
    $('.hm2_welcomeimg').remove();
    $('.hm2_welcome').remove();



    var cycleid = '.hm2_slide';

    if ($('.hm2_slide a').length > 1 || $('.hm2_slide a').length == 0) {
    } else {
        cycleid = '.hm2_slide a';
    }

    $(cycleid).cycle({ fx: 'fade', timeout: 7500, speed: 2000,
        prev: '#hm2_slide_prev',
        next: '#hm2_slide_next'
    });

    $('#hm2_slide_play').click(function() {
        $(cycleid).cycle('resume', true);
        $('#hm2_slide_play').hide();
        $('#hm2_slide_pause').show();
    });

    $('#hm2_slide_pause').click(function() {
        $(cycleid).cycle('pause');
        $('#hm2_slide_play').show();
        $('#hm2_slide_pause').hide();
    });
}

function RemoveWelcome() {




    $('#imgWelcome').animate({ opacity: 'toggle' }, 2000, function() {

    });
    $('.hm2_welcome').animate({ opacity: 'toggle' }, 1000, function() {

    });

    setTimeout("InitHm2Slide()", 2000);
}


function still_in_site(val) {
    if ($('#still_in_site').attr('id')) {
        $('#still_in_site').val(val + '');
    }
}


function LeavingSite() {
    //leaving site
    if ($('#still_in_site').val() == '0') {
        try {
            if (document.height) {
                window.showModalDialog('/cartmsg.asp', null, 'dialogWidth:400px; dialogHeight:135px; center:yes');
            } else {
                window.showModalDialog('/cartmsg.asp', null, 'dialogWidth:400px; dialogHeight:170px; center:yes');
            }
        } catch (err) {
        }
    }
}

function Keypress(e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    if (keycode == 116) {
        still_in_site('1');
    }
}


function InitFormFields() {
    var isLocal = false;
    if (location.href.indexOf('localhost') != -1) { isLocal = true }

    if ($('.autofields').html()) {
        if (!$('.autofields input[name=_fieldOrder]').attr('type')) {
            var fields = ',';
            $('.autofields :input').each(function(i) {
                var fname = $('.autofields :input').eq(i).attr('name');
                if (fname) {
                    fname = $.trim(fname).replace(/[^a-zA-Z0-9\-_]/g, '_').replace(/_+/g, '_');
                    $('.autofields :input').eq(i).attr('name', fname);

                    if (isLocal) {
                        if (fields.indexOf(',' + fname + ',') != -1) {
                            if ($('.autofields :input').eq(i).attr('type') == 'text') {
                                //   alert(fname);
                                $('.autofields :input').eq(i).css('background', 'red');
                            }
                        }

                        if ($('.autofields :input').eq(i).attr('type') == 'radio' || $('.autofields :input').eq(i).attr('type') == 'checkbox') {
                            if (!$('.autofields :input').eq(i).attr('value')) {
                                //alert(fname+'  11');
                            }

                        }

                    }

                    if (fname.substr(0, 1) != '_' && fields.indexOf(',' + fname + ',') == -1 && (',form_redirect,submit,submitbutton,FORM_ID,NEXT_PAGE,').indexOf(',' + fname + ',') == -1) {
                        fields = fields + fname + ',';
                    }
                } else {
                    if (isLocal) {
                        alert(fields);
                        $('.autofields :input').eq(i).css('background', 'green');
                    }
                }
            });
            fields = fields.substr(1);
            if (fields.substr(fields.length - 1) == ',') {
                fields = fields.substr(0, fields.length - 1);
            }
            $('.autofields').append('<input type="hidden" name="_fieldOrder" value="' + fields + '" /> ');
        }
    }

}

function SwitchFLV_src_vars(src, vars, obj) {
    var html = '<embed width="470" height="375" align="middle" flashvars="' + vars + '" src="' + src + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" play="true" loop="true" scale="showall" wmode="opaque" devicefont="false" bgcolor="#ffffff" name="flvplayer" id="flvplayer" menu="true" allowfullscreen="true" allowscriptaccess="sameDomain"  salign="" type="application/x-shockwave-flash"></embed>';


    if (location.href.indexOf('wnarchives.html') != -1 || location.href.indexOf('?') != -1) {
        $(obj).parents('.whatsnew_holder').find('.whatsnew_img').html(html);

    } else {
        if (!$('.plflvplayer:eq(0)').html()) {
            $('.whatsnew_img').eq(0).html('<div class="plflvplayer">' + $('.whatsnew_img').eq(0).html() + '</div>');
            //$('embed').wrap('<div class="plflvplayer"></div>');
        }
        $('.plflvplayer:eq(0)').html(html);

        $('.whatsnew_text').eq(0).html($(obj).parent().parent().find('.whatsnew_text').html());
        $('.whatsnew_text').eq(0).find('strong').removeAttr('onclick');
        $('.whatsnew_text').eq(0).find('strong').removeAttr('class');
    }
}


function SwitchFLV(flv, obj) {
    if (flv.indexOf('/') == -1)
        flv = '/userfiles/File/videos/' + flv;
    SwitchFLV_src_vars('flvplayer.swf', 'flvPath=' + flv + '&amp;flvTitle=&amp;autoPlay=true&amp;autoBuffer=true', obj);
}



function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}



function ShowGiftImg(id) {
    $('#tdGiftImg').html('<img src="/pimg.asp?id=' + id + '" alt="" />');
    $('#txtGiftID').val(id + '');
}



function FormatLinks(obj) {
    if (obj.indexOf('.') == 0) {
        $(obj).each(function(i) {
            FormatLink($(obj).eq(i));
        });
    } else {
        FormatLink(obj);
    }

    $(obj + ' a').each(function(i) {
        if ($.trim($(obj + ' a').eq(i).html()).length == 0) $(obj + ' a').eq(i).remove();
    });

}

function FormatLink(obj) {
    if ($(obj).html()) {
        var html = $(obj).html();
        html = html.replace(/(\s|^|\(|\)|>)(http:|https:|www\.)([^\s^$<>\(\)]*?)(\.)([^\s^$<>\(\)]*?)(\s|$|<|\(|\))/img, '$1<a href="$2$3$4$5" target="_blank" class="autolink">$2$3$4$5<\/a>$6');
        html = html.replace(/(\s|^|\(|\))(http:|https:|www\.)([^\s^$<>\(\)]*?)(\.)([^\s^$<>\(\)]*?)(\s|$|\(|\))/img, '$1<a href="$2$3$4$5" target="_blank" class="autolink">$2$3$4$5<\/a>$6');
        html = html.replace(/ href="www./img, ' href="http://www.');
        $(obj).html(html);

    }
}




function SysHeight_logo_des() {
    SysHeight('.sub_des_logo', '.sub_des_text', 0);
    if (!$('.sub_des_text .sub_des_text_left').html()) {
        //$('.sub_des_logo').width(200);
    }

    setTimeout("SysHeight_logo_des()", 3000);

}
function CheckSizeDrp() {
    //
    var selectedsize = $('#drpSize_YN').val();
    var selectedcolor = $('#drpFColor_YN option[value="' + $('#drpFColor_YN').val() + '"]').html();
    if ($('.ul_colors_sizes li[title="' + selectedcolor + '"]').html()) {
        var productsizes = $('.ul_colors_sizes li[title="' + selectedcolor + '"]').html().split(',');
        var html = '<select id="drpSize_YN">';
        for (var i = 0; i < productsizes.length; i++) {
            html += '<option>' + productsizes[i] + '</option>';
        }
        html += '</select>';
        if ($('.pldrpSize_YN').html()) {
            $('.pldrpSize_YN').html(html);
            $('#drpSize_YN').val(selectedsize);
        }
    }
    //
}
function drpFColor_YN_change() {
    $('.txtProductID').val(productID);
    CheckAvailable();
    //
    CheckSizeDrp();
    //
    selected_img_productID = productID;
    ShowImageProduct('');
}
function ShowImageDetail(pid, imgid, ourl) {
    selected_img_productID = pid;
    selected_img_imageID = imgid;
    ShowImageProduct(ourl);

    $('.txtProductID').val('' + pid);
    CheckAvailable();
    $('#drpFColor_YN').val(pid + '');
    CheckSizeDrp();
}

 

function CheckAvailable() {
    var pid = $('.txtProductID').val();
    if ($('.productstatus').html()) {

        if ($.trim($('.pa_' + pid).text()) == '3') {
            $('.btnAddToCart').hide();
            $('.lblBackOrder').show();

			if(subcatID==12){
			    $('.lblBackOrder').html('<span class="lblBackOrderText">This product is not available yet.</span><br /><br /><form action="/preorder.asp?submit=1" method="post" id="fmtitanium">Sign up to be alerted when MOSCOT Titanium Second Edition is available for order online and in stores.<br /><br />EMAIL: <input type="text" name="Email" class="email required" /><input type="hidden" name="Content" value="Titanium Second Edition" /><input type="submit" value="Submit" class="submit" name="submit" /><br /></form>');
				 $('#ulcho').after($('.lblBackOrder'));
				 $('#ulcho').hide();
			}else{
                $('.lblBackOrder').html('<span class="lblBackOrderText">This product is back-ordered.</span>');
			}
           
        } else {
            if ($('.btnAddToCart').css('display').toLowerCase() == 'none') {
            
                $('.btnAddToCart').show();
                $('.lblBackOrder').hide();
                $('.lblBackOrder').html('');
            }
        }



    }
}

/*
-------Type1 same lens----
143 Jordan Gold G-15
144 Jordan Silver G-15

248 Simmons Matte Grey G-15
249 Simmons Matte Black G-15

237 Zulu Black G-15
238 Zula Gold G-15

-----Type2 cross lens----
141 Kaycee Black G-15
142 Kaycee Blonde Brown

251 Danie Black with Pear White G-15
255 Danie Brown Calibar Green
*/

function NeedJumpLocation() { //Show two frames cross lens and check lensexceptions.asp!!!
    if ((' 141 142 251 255 283 287 ').indexOf(oproductID + '') != -1) return true;
    return false;
}

function IsNo30UpgradeProducts() { //Lens upgrade and check cart.asp //Or we can check if there is a clear option in select
    if (' 143 144 248 249 237 238 141 142 251 255 273 '.indexOf('' + productID) != -1) {
        $('#txtIsNo30UpgradeProducts').val('1');
        return true;
    }
    $('#txtIsNo30UpgradeProducts').val('0');
    return false;
}

function ShowImageProduct(ourl) {
    var caption = $('.drpLColor').val();

    var cid = '.plImages_ul  .li_set_' + showset + '_' + selected_img_productID;
    if (subcatID > 3) cid = '.plImages_ul  .images_id_' + selected_img_imageID;

    var url = $(cid + ' img').attr('alt');

    if (!url || NeedJumpLocation()) {
        if (($('#drpFColor_YN option').length > 0 || NeedJumpLocation()) && oproductID != selected_img_productID) {
            location.href = '/product.asp?id=' + selected_img_productID;
            return;
        }
    }
    if (!url) return;

    $(cid).each(function(i) {
        if ($(cid).eq(i).attr('title') == caption) {
            url = $(cid + ':eq(' + i + ') img').attr('alt');
        }
    });


    if (ourl.length > 0) url = '/pimg/med_' + ourl;


    //   alert(selected_img_imageID);
    $('#plProductMainShow_img').attr('src', url.replace('/th_', '/med_'));
    $('.plImages_ul li .plImages_text').css('font-weight', 'normal');

    if (url.length > 0) {
        url = url.replace('/med_', '/th_');
        $('.plImages_th img[alt="' + url + '"]').parents('li').children('.plImages_text').css('font-weight', 'bold');
    } else {
        $(cid + ' .plImages_text').css('font-weight', 'bold');
    }

}

var shopbannercur = 1;
function slideshopbanner() {
    shopbannercur++;

    $('#img_shopbanner').animate({
        opacity: 'toggle'
    }, 2000, function() {
        $('#img_shopbanner').attr('src', '/images/shopbanner-' + ((whatnewcur + 1) % 2 + 1) + '.jpg');
        $('#img_shopbanner').show();
        $('.shop_slide_fm').css({ 'background': 'url(/images/shopbanner-' + ((whatnewcur) % 2 + 1) + '.jpg) no-repeat' });
        setTimeout("slideshopbanner()", 3500);
    });

}





var whatnewcur = 1;
function slidewhatnew() {
    whatnewcur++;

    $('#img_whatnew').animate({
        opacity: 'toggle'
    }, 2000, function() {
        $('#img_whatnew').attr('src', '/images/whats-new-homepage' + ((whatnewcur + 1) % 2 + 1) + '.jpg');
        $('#img_whatnew').show();
        $('.whatnew_slide_fm').css({ 'background': 'url(/images/whats-new-homepage' + ((whatnewcur) % 2 + 1) + '.jpg) no-repeat' });
        setTimeout("slidewhatnew()", 3500);
    });


}


function text_header_click(hi) {
    for (var i = 0; i < $('.text_body').length; i++) {
        if (i != hi) {
            $('.text_body').eq(i).hide();
        }
    }
    $('.text_body').eq(hi).slideToggle("slow");
}

function text_header_sub_click(hi) {
    for (var i = 0; i < $('.text_body_sub').length; i++) {
        if (i != hi) {
            $('.text_body_sub').eq(i).hide();
        }
    }
    $('.text_body_sub').eq(hi).slideToggle("slow");
}

function GotoSearch() {
    if ($('#txtKeywords').val().toLowerCase() != 'keywords' && $('#txtKeywords').val().toLowerCase() != 'search' && $('#txtKeywords').val().length > 0)
        location.href = 'search.asp?keywords=' + $('#txtKeywords').val();
}






function SysHeight(ida, idb, inith) {
    var maxh = inith;
    if ($(ida).height() > maxh) maxh = $(ida).height();
    if ($(idb).height() > maxh) maxh = $(idb).height();

    $(idb).height(maxh);
    $(ida).height(maxh);
}


function PressLiClick(obj) {
    var id = $(obj).attr('id');
    id = id.substr(id.lastIndexOf('_') + 1);


    var t = 0;
    if (document.documentElement && document.documentElement.scrollTop) {
        t = document.documentElement.scrollTop;
    } else if (document.body) {
        t = document.body.scrollTop;
    }


    if (t < 0) t = 0;
    t = t + 5;

    $('#dialog').html('<div class="jqwinhead"><div class="jqlogo"> <img src="/images/logo.png" alt="" /> </div>    <div class="pljqmclose"> <a href="#" class="jqmClose">close</a> </div>  </div> <div class="jqwincontent">  <div id="pldlgContent_fm">      <div id="pldlgContent"><img src="/images/loading.gif" alt="" /></div> </div>  </div>  <div class="jqwinfoot"></div>');
    $('#dialog').css('top', t + 'px');

    var dlgid = 'press_li_' + id + ' .press_more';

    if (location.href.indexOf('press') != -1) {

        $('#' + dlgid).load('ajax_getpressmore.asp?id=' + id,
		  function() { SetMoreDlg(dlgid, id); }
		);
    } else {
        SetMoreDlg(dlgid, id);
    }
}


function SetMoreDlg(dlgid, id) {
    if (!$('#' + dlgid).html()) return;
    if ($('#' + dlgid).html().length > 0) {
        var html = $('#' + dlgid).html().replace(/(<ul>)|(<\/ul>)|(<li>)|(<\/li>)/img, '');
        var images = '';

        if ($('#' + dlgid).html().indexOf('class="pldlgImg_holder"') == -1) {
            $('#' + dlgid + ' img').wrap('<div class="pldlgImg_holder"></div>');
        }

        $('#' + dlgid + ' .pldlgImg_holder').each(function(i) {
            images += $('#' + dlgid + ' .pldlgImg_holder').eq(i).html();
        });


        if (images.length == 0) {
            images = $('#press_li_' + id + ' .press_img').html().replace('/pimg/press/', '/pimg/press/med/');
        }

        $('#pldlgContent').html('<ul><li class="pldlgContent_text"><div class="pldlgContent_text_scroll">' + html + '</div></li><li class="pldlgContent_imgs"><div class="pldlgContent_imgs_scroll">' + images + '</div></li></ul>');

        $('.pldlgContent_text_scroll img').remove();
        FormatLinks('#dialog');

        $('#dialog').removeClass('jqmWindow_ss');
        $('#dialog').jqm().jqmShow();

        $('.pldlgContent_text_scroll').jScrollPane({ scrollbarWidth: 19 });
        PressDlgImgsScroll_timers = 1;
        PressDlgImgsScroll();
    }
}

function PressDlgImgsScroll() {
    if (PressDlgImgsScroll_timers > 10) return;
    PressDlgImgsScroll_timers++;
    $('.pldlgContent_imgs_scroll').jScrollPane({ scrollbarWidth: 19 });

    setTimeout("PressDlgImgsScroll()", 250 * PressDlgImgsScroll_timers)

}





function InitValidation_Gif() {
    $(document).ready(function() {
        // validate signup form on keyup and submit

        $('#fmtitanium').validate({
            messages: {
                Email: { email: '', required: '' }
            }
        });

        var formgif = $("#formgif").validate({


            errorLabelContainer: $('.gif_error'),
            rules: {
                RecepientName: "required",
                RecepientEmail: {
                    required: true,
                    email: true
                },
                SenderName: "required",
                SenderEmail: {
                    required: true,
                    email: true
                },

                Amount: "required"
            },
            messages: {
                Amount: "Please enter amount such as $9.99. ",
                RecepientName: "Please enter recepient. ",
                SenderName: "Please enter sender. ",
                RecepientEmail: {
                    required: "Please enter recepient email address. ",
                    email: "Please enter a valid recepient email address. "
                },
                SenderEmail: {
                    required: "Please enter sender email address. ",
                    email: "Please enter a valid sender email address. "
                }
            }
        });

    });

}

function Alert() {
    alert((new Date()).valueOf() - timerb);
    timerb = (new Date()).valueOf();
}

function FormatWideOfContent_Nav() {

    if (!$('.content_nav').html()) return;
    if ($('.content_nav li').length == 1) return;
    if (FormatWideOfContent_Nav_timers > 10) return;
    FormatWideOfContent_Nav_timers++;

    $('.content_nav li').css({ 'margin-left': '0px', 'margin-right': '0px' });
    var totalwidth = 0;
    $('.content_nav li').each(function(i) {
        $('.content_nav li').eq(i).width($('.content_nav li:eq(' + i + ') img').width());
        totalwidth += $('.content_nav li:eq(' + i + ') img').width();
    });

    if ($('.content_nav li').length > 1) {
        if ($('.content_nav').attr('id') == 'ulshopnav') {
            totalwidth += ($('.content_nav li').length - 1) * 6; //padding 12
        }
        else {
            totalwidth += ($('.content_nav li').length - 1) * 12;
        }
        totalwidth += 2; //eq0 border
    }



    var dwidth = $('.content_nav').width() - totalwidth;
    var pwidth = (dwidth + 0.0) / ($('.content_nav li').length - 1 + 0.0);
    var pwidth_i = parseInt(pwidth);



    $('.content_nav li').each(function(i) {
        $('.content_nav li').eq(i).css('margin-left', pwidth_i + 'px');
    });

    var marginr = dwidth - pwidth_i * ($('.content_nav li').length - 1);

    $('.content_nav li').eq(0).css({ 'margin-left': '0px', 'margin-right': marginr + 'px' });
    setTimeout("FormatWideOfContent_Nav()", 250 * FormatWideOfContent_Nav_timers);
}

function gaNavEvent(link) {
    try {
        pageTracker._trackEvent('TopNav', 'Click', link);
    } catch (err) { }
}