$(document).ready(function () {
    $('.enteremail').click(function () {
        if ($(this).val() == 'ENTER YOUR EMAIL ADDRESS') {
            $(this).val('');
        }
    });

    //$('#leftnav ul li a').click(function () {
    //    $('#realstyle').attr('href', '/css/style2.css');
    //    return false;
    //});

    if ($('#homebanner').length > 0) {
        $('#homebanner').cycle({ timeout: 8000, speed: 2000, pause: 1 });

        //flowplayer().onBeforeClick(function() {$('#homebanner').cycle('stop');});

    }

    $('#topdivvideolink').click(function () {
        $.scrollTo('#bottomdiv')
        return false;
    });
    $('#topdivimglink').click(function () {
        $.scrollTo('#bottomdiv')
        return false;
    });

    $('#changePass').click(function () {
        $.post("/ajax.aspx?action=sendPassword", { txtEmail: $('#txtEmail').val(),
            md5password: $('#md5password').val(),
            password: $('#password').val()
        },
                function (message) {
                });
    });

    $(".number").keydown(function (event) {
        if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 13) {
        }
        else {
            if ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105)) {
                event.preventDefault();
            }
        }
    });

    $('#sizeselect').change(function () {
        $('#sizeselect option').each(function () {
            if ($(this).attr('value') == $('#sizeselect').val())
                $('.imgdv img').attr('src', '/pimg/' + $(this).attr('class'));
        });
    });

    $('#sizeselect5').change(function () {
        var additional = '';
        var att = '';
        if ($('#sizeselect5') && $('#sizeselect5').val() != '') {
            additional = '&size=' + $('#sizeselect5').val();
        }
        $('.on').each(function () {
            att = $(this).children('img').attr('alt');
        });
        $.ajax({
            url: "/ajax.aspx",
            data: "action=getSwatch&attribute=" + att + "&itemcode=" + $('#swatchestable').attr('class') + additional,
            type: "get",
            dataType: "text",
            success: function (res) {
                $('#swatchestable').html('<tr>' + res + '</tr>');
                $('.colorclick').click(function () {
                    colorclick($(this).attr('id'));
                });
                $('a[rel="swboxy"]').click(function () {
                    boxyclick();
                });
            }
        });
    });
    $('#swatches ul.viewby li a').click(function () {
        if ($(this).attr('class') == 'on') {
            return false;
        }
        else {
            $('#swatches ul.viewby li a.on').removeClass('on').addClass('off');
            $(this).addClass('on').removeClass('off');
            $('#swatches ul.viewby li a.off img').each(function () {
                $(this).attr('src', $(this).attr('src').replace('_on', '_off'));
            });
            $('#swatches ul.viewby li a.on img').each(function () {
                $(this).attr('src', $(this).attr('src').replace('_off', '_on'));
            });
            var additional = '';
            if ($('#sizeselect5') && $('#sizeselect5').val() != '') {
                additional = '&size=' + $('#sizeselect5').val();
            }
            $.ajax({
                url: "/ajax.aspx",
                data: "action=getSwatch&attribute=" + $(this).children('img').attr('alt') + "&itemcode=" + $('#swatchestable').attr('class') + additional,
                type: "get",
                dataType: "text",
                success: function (res) {
                    $('#swatchestable').html('<tr>' + res + '</tr>');
                    $('.colorclick').click(function () {
                        colorclick($(this).attr('id'));
                    });
                    $('a[rel="swboxy"]').click(function () {
                        boxyclick();
                    });
                }
            });
            return false;
        }
    });
    $('#swatches ul.viewby li a img').mouseover(function () {
        $(this).attr('src', $(this).attr('src').replace('_off', '_on'));
    });
    $('#swatches ul.viewby li a img').mouseout(function () {
        if ($(this).parent().attr('class') == 'off') {
            $(this).attr('src', $(this).attr('src').replace('_on', '_off'));
        }
    });

    $('.colorclick').click(function () {
        colorclick($(this).attr('id'));
    });
    $('.colorclick2').click(function () {
        var thecolor = $(this).children('img').attr('alt');
        $('#t4colors option').each(function () {
            if ($(this).val() == thecolor) {
                $(this).attr('selected', 'selected');
            }
        });
        $('#t4colors').change();
        return false;
    });

    if ($('#Addtocart2')) {
        $('#sizeselect').change(function () {
            if ($('#sizeselect option[value="' + $('#sizeselect').val() + '"]').attr('rel') == "0") {
                $('#backordered').show();
                $('#Addtocart2').hide();
            }
            else {
                $('#backordered').hide();
                $('#Addtocart2').show();
            }
        });
        if ($('#sizeselect option[value="' + $('#sizeselect').val() + '"]').attr('rel') == "0") {
            $('#backordered').show();
            $('#Addtocart2').hide();
        }
        else {
            $('#backordered').hide();
            $('#Addtocart2').show();
        }
    }
    $('#Addtocart2').click(function () {
        $('#ProductID').val($('#sizeselect option:selected').val());
    });
    $('#Addtocart4').click(function () {
        var colors = "";
        var sizes = "";
        if ($('#t4colors')) {
            if ($('#t4colors option:selected').text() != "Select Color...") {
                colors = "&color=" + $('#t4colors').val();
            }
            else {
                alert("Please select a size and color");
                return false;
            }
        }
        if ($('#t4sizes')) {
            if ($('#t4sizes option:selected').text() != "Select Size...") {
                sizes = "&size=" + $('#t4sizes').val();
            }
            else {
                alert("Please select a size and color");
                return false;
            }
        }
        if (1 == 1) {
            $.ajax({
                url: "ajax.aspx",
                data: "action=getproductid" + colors + sizes + "&id=" + $('#ProductID').val(),
                type: "get",
                dataType: "text",
                success: function (res) {
                    $.ajax({
                        url: "/cart.asp",
                        data: "Action=AddItem&ProductID=" + res + "&Quantity=" + $('#saleqty').val() + "&nd=" + Math.random(),
                        type: "get",
                        dataType: "text",
                        success: function (res) {
                            window.location = "/checkout.asp?Action=Shipping";
                        }
                    });
                }
            });
        }
        else {
        }
        return false;
    });

    $('#t4sizes').change(function () {
        $.ajax({
            url: "/ajax.aspx",
            data: "action=getColors&size=" + $('#t4sizes').val() + "&id=" + $('#ProductID').val(),
            type: "get",
            dataType: "text",
            success: function (res) {
                var selcolor = $('#t4colors').val();
                $('#t4colors').html(res);
                $('#t4colors option').each(function () {
                    if ($(this).val() == selcolor) {
                        $(this).attr('selected', 'selected');
                    }
                });
            }
        });
    });
    $('#t4colors').change(function () {
        $.ajax({
            url: "/ajax.aspx",
            data: "action=getSizes&color=" + $('#t4colors').val() + "&id=" + $('#ProductID').val(),
            type: "get",
            dataType: "text",
            success: function (res) {
                var selsize = $('#t4sizes').val();
                res = res.split('###image###');
                $('#t4sizes').html(res[0]);
                if (res.length > 1) {
                    if (res[1].length > 0) {
                        $('.imgdv img').attr('src', '/pimg/' + res[1]);
                    }
                }
                $('#t4sizes option').each(function () {
                    if ($(this).val() == selsize) {
                        $(this).attr('selected', 'selected');
                    }
                });
            }
        });
    });

    if ($('#linkstable').length > 0) {
        $('a').click(function () {
            if ($(this).attr('href') == "") {
                var thelink = $(this).attr('name');
                if (thelink == '') {
                    thelink = $(this).text();
                }
                $.ajax({
                    url: "/ajax.aspx",
                    data: "action=getaboutpage&title=" + thelink + "&page=about face&nd=" + Math.random(),
                    type: "get",
                    dataType: "text",
                    success: function (res) {
                        $('#leftdata').html(res);
                    }
                });
                return false;
            }
            else if ($(this).attr('href') == "#" && $(this).attr('id') != 'topdivvideolink') {
                var ValidChars = "0123456789.";
                var IsNumber = true;
                var Char;
                for (i = 0; i < $(this).attr('name').length && IsNumber == true; i++) {
                    Char = $(this).attr('name').charAt(i);
                    if (ValidChars.indexOf(Char) == -1) {
                        IsNumber = false;
                    }
                }
                if (!IsNumber) {
                    $.ajax({
                        url: "/ajax.aspx",
                        data: "action=getaboutpage&title=" + $(this).attr('name') + "&page=about face&nd=" + Math.random(),
                        type: "get",
                        dataType: "text",
                        success: function (res) {
                            $('#leftdata').html(res);
                        }
                    });
                }
                else {
                    $.ajax({
                        url: "/ajax.aspx",
                        data: "action=getpagebyid&title=" + $(this).attr('name') + "&nd=" + Math.random(),
                        type: "get",
                        dataType: "text",
                        success: function (res) {
                            $('.bottomleftdata').html(res);
                        }
                    });
                }
                return false;
            }
        });
    }
    if ($('#midlinksdiv').length > 0) {
        freshfacelinks();
        $('img').each(function () {
            $(this).load(function () {
                if ($(this).height() == 0) {
                    $(this).parent().css('min-height', '180px');
                }
                else {
                    $(this).parent().css('min-height', ($(this).height()) + 'px');
                }
            });
        });
    }
    if ($('#linkstablee').length > 0) {
        $('a').click(function () {
            if ($(this).attr('href') == "") {
                var thelink = $(this).attr('name');
                if (thelink == '') {
                    thelink = $(this).text();
                }
                $.ajax({
                    url: "/ajax.aspx",
                    data: "action=getaboutpage&title=" + thelink + "&page=education&nd=" + Math.random(),
                    type: "get",
                    dataType: "text",
                    success: function (res) {
                        $('#leftdata').html(res);
                    }
                });
                return false;
            }
            else if ($(this).attr('href') == "#" && $(this).attr('id') != 'topdivvideolink') {
                var ValidChars = "0123456789.";
                var IsNumber = true;
                var Char;
                for (i = 0; i < $(this).attr('name').length && IsNumber == true; i++) {
                    Char = $(this).attr('name').charAt(i);
                    if (ValidChars.indexOf(Char) == -1) {
                        IsNumber = false;
                    }
                }
                if (!IsNumber) {
                    $.ajax({
                        url: "/ajax.aspx",
                        data: "action=getaboutpage&title=" + $(this).attr('name') + "&page=education&nd=" + Math.random(),
                        type: "get",
                        dataType: "text",
                        success: function (res) {
                            $('#leftdata').html(res);
                        }
                    });
                }
                else {
                    $.ajax({
                        url: "/ajax.aspx",
                        data: "action=getpagebyid&title=" + $(this).attr('name') + "&nd=" + Math.random(),
                        type: "get",
                        dataType: "text",
                        success: function (res) {
                            $('.bottomleftdata').html(res);
                        }
                    });
                }
                return false;
            }
        });
    }

    // header shopnav item
    $('#shopnav').hover(
		function () { $('#shopnavitem').show(); },
		function () { $('#shopnavitem').hide(); }
	);

    $('#shopnav').click(
		function () { $('#shopnavitem').show(); },
		function () {
		    $('#shopnavitem').hide();
		    return false;
		}
	);

    $('#header li.toplevel').hover(
		function () {
		    var src = $(this).find('a.toplevellink img').attr('src').replace('.png', '-on.png');
		    $(this).find('a.toplevellink img').attr('src', src);
		},
		function () {
		    var src = $(this).find('a.toplevellink img').attr('src').replace('-on.png', '.png');
		    $(this).find('a.toplevellink img').attr('src', src);
		}
	);

    // header cart items popup
    if ($('#header_popup_items').length > 0) {
        $('#header_popup').hover(
			function () { $('#header_popup_items').show(); },
			function () { $('#header_popup_items').hide(); }
		);
    }

    // signin and newuser lightbox
    $('a[rel="boxy"]').boxy();
    //$('a[rel="swboxy"]').boxy();
    $('.Addtocart1').click(function () {
        $.ajax({
            url: "/cart.asp",
            data: "Action=AddItem&ProductID=" + $('.selectedproductid').val() + "&Quantity=" + $('.saleQty').val() + "&nd=" + Math.random(),
            type: "get",
            dataType: "text",
            success: function (res) {
                $('.lblcount').text($('#saleQty').val());
                $('.coloradd').hide();
                $('.colorsubmit').show();
            }
        });
        return false;
    });

    $('.btnCheckout').click(function () {
        window.location = "/checkout.asp?Action=Shipping";
    });
    $('a[rel="swboxy"]').click(function () {
        boxyclick();
    });
    $('.colorhidden').hide();

    $('#emailbtn').click(function () {
        var emailpopup = '<div id="emailboxydiv"><table><tr><td>Share Link</td><td><input type="hidden" id="theurl" value="' + window.location + '" /></td></tr><tr><td>Recipient\'s Email:</td><td><input id="toemail" type="text" /></td></tr><tr><td>Recipient\'s Name:</td><td><input id="toname" type="text" /></td></tr><tr><td>Your Email:</td><td><input id="froemail" type="text" /></td></tr><tr><td>Your Name:</td><td><input id="froname" type="text" /></td></tr><tr><td></td><td><input id="sendtofro" type="button" value="Share Link" /></td></tr></table><a href="#" class="close closeboxy">&nbsp;</a></div>';
        new Boxy(emailpopup, { modal: true });
        $(".boxy-modal-blackout").live("click", function () {
            $(".closeboxy").click();
        });
        $('#sendtofro').click(function () {
            $.post("/ajax.aspx?action=emailtofro", { Emailto: $('#toemail').val(),
                Nameto: $('#toname').val(),
                Emailfrom: $('#froemail').val(),
                Namefrom: $('#froname').val(),
                URL: $('#theurl').val()
            },
                function (message) {
                    $('#emailboxydiv table').html('<tr><td>' + message + '</td></tr><tr></tr><tr><td><input id="donebtn" value="Done" type="button" /></td></tr>');
                    $('#donebtn').click(function () {
                        $('.closeboxy').click();
                    });
                });
            return false;
        });
        return false;
    });

    $('a[id*="popup_removelink"]').click(function () {
        $.post('/cart.asp?rand=' + Math.random(), { 'Action': 'Remove', 'ActionMethod': 'Ajax', 'CartID': $('#popupcartid' + $(this).attr('id').replace('popup_removelink', '')).val() }, function (result) {
            location.reload();
        });
    });

    // for shipping info, billing info, and payment info pages
    $('a[id*="order_summary_removelink"]').click(function () {
        var id = $(this).attr('id').replace('order_summary_removelink', '');
        var oldSubTotal = parseInt($('span.order_summary_subtotal').text().replace('￥', ''));
        var itemSubTotal = parseInt($('span.order_summary_tr_subtotal' + id).text().replace('￥', ''));
        var newSubTotal = '￥' + FormatNumber(oldSubTotal - itemSubTotal, 2).toString();

        $.post('/cart.asp?rand=' + Math.random(), { 'Action': 'Remove', 'ActionMethod': 'Ajax', 'CartID': $('#cartid' + id).val() }, function (result) {
            location.reload();
        });
    });
    $('a').click(function () {
        $.cookie('linked', 'yes');
    });
    $('.shopnavitem .bdv').html("");
    $('#homeshopimg').click(function () {
        $.cookie('path', 'parent1parent7children');
        $.cookie('linked', 'yes');
    });
    $.ajax({
        url: "/ajax.aspx",
        data: "action=getaboutpage&title=ShopNav",
        type: "get",
        dataType: "text",
        success: function (res) {
            $('.shopnavitem .bdv').append(res);
            $('.shopnavitem .bdv li a').each(function () {
                $(this).click(function () {
                    $.cookie('path', $(this).parent().parent().attr('id'));
                    $.cookie('linked', 'yes');
                });
            });
        }
    });
    $.ajax({
        url: "/ajax.aspx",
        data: "action=getaboutpage&title=LeftNav",
        type: "get",
        dataType: "text",
        success: function (res) {
            $('#leftnav').html(res);
            $('#leftnav li').each(function () {
                if ($('#' + $(this).attr('id') + 'children').length > 0 && '#' + $(this).attr('id') + 'children' != '#children') {
                    $('#' + $(this).attr('id') + 'children').hide();
                }
            });
            $('#leftnav a').each(function () {
                $(this).click(function () {
                    $.cookie('path', $(this).parent().parent().attr('id'));
                    $.cookie('linked', 'yes');
                    //if ($('#' + $(this).attr('id') + 'children').attr('class') != 'open') {
                    //    var theid = $(this).parent().attr('id');
                    //    $('.open').each(function () {
                    //        //alert($(this).attr('id') + " " + theid);
                    //        if ($(this).attr('id') != theid)
                    //            $(this).hide().removeClass('open');
                    //    });
                    //    $('#' + $(this).attr('id') + 'children').show().addClass('open');
                    //    return false;
                    //}
                    //else {
                    //    $('#' + $(this).attr('id') + 'children').hide().removeClass('open');
                    //    return false;
                    //}
                });
            });
            var path = '';
            if ($.cookie('linked') == 'yes') {
                path = $.cookie('path');
                $.cookie('linked', '');
            }
            else {
                $.cookie('path', '');
            }
            var breadcrumbs = '';
            if (path != null && path != '') {
                var theobject = '#' + path;
                if ($('.open').length == 0) {
                    $(theobject).show().addClass('open');
                    if (path != 'children') {
                        $(theobject.replace('children', '')).addClass('liselect');
                        var tempbc1 = $(theobject.replace('children', '')).html();
                        breadcrumbs += tempbc1.substring(0, tempbc1.indexOf('</a>') + 4).toUpperCase() + ' // ';
                    }
                    var ulid = path.replace(/parent[0-9]+children/g, 'children');
                    while (ulid != 'children' && ulid != '') {
                        $('#' + ulid).show().addClass('open');
                        $('#' + ulid.replace('children', '')).addClass('liselect');
                        var tempbc2 = $('#' + ulid.replace('children', '')).html();
                        breadcrumbs = tempbc2.substring(0, tempbc2.indexOf('</a>') + 4).toUpperCase() + ' // ' + breadcrumbs;
                        ulid = ulid.replace(/parent[0-9]+children/g, 'children');
                    }
                    $('#' + $('#' + path + ' li a[href="/search.asp?mode=type&typeid=' + $('#hTypeID').val() + '"]').parent().addClass('liselect').attr('id') + 'children').show().addClass('open');
                    var tempbc = ''
                    tempbc = $('#' + path + ' li a[href="/search.asp?mode=type&typeid=' + $('#hTypeID').val() + '"]').parent().html();
                    if ($('#hTypeID').val() == undefined && path != null && path != '') {
                        $('#' + $('#' + path + ' li a[href="/search.asp?mode=type&typeid=62"]').parent().addClass('liselect').attr('id') + 'children').show().addClass('open');
                        tempbc = $('#' + path + ' li a[href="/search.asp?mode=type&typeid=62"]').parent().html();
                    }
                    breadcrumbs += tempbc.substring(0, tempbc.indexOf('</a>') + 4).toUpperCase();
                    $('#productarea .topnav').html(breadcrumbs + $('#productarea .topnav').html());
                }
            }
            else {
                $('#leftnav ul li a').each(function () {
                    if ($('.open').length == 0) {
                        if ($(this).attr('href') == '/search.asp?mode=type&typeid=' + $('#hTypeID').val()) {
                            $(this).parent().parent().show().addClass('open');
                            if ($(this).parent().parent().attr('id') != 'children') {
                                $('#' + $(this).parent().parent().attr('id').replace('children', '')).addClass('liselect');
                                var tempbc1 = $('#' + $(this).parent().parent().attr('id').replace('children', '')).html();
                                breadcrumbs += tempbc1.substring(0, tempbc1.indexOf('</a>') + 4).toUpperCase() + ' // ';
                            }
                            var ulid = $(this).parent().parent().attr('id').replace(/parent[0-9]+children/g, 'children');
                            while (ulid != 'children' && ulid != '') {
                                $('#' + ulid).show().addClass('open');
                                $('#' + ulid.replace('children', '')).addClass('liselect');
                                var tempbc2 = $('#' + ulid.replace('children', '')).html();
                                breadcrumbs = tempbc2.substring(0, tempbc2.indexOf('</a>') + 4).toUpperCase() + ' // ' + breadcrumbs;
                                ulid = ulid.replace(/parent[0-9]+children/g, 'children');
                            }
                            $('#' + $(this).parent().addClass('liselect').attr('id') + 'children').show().addClass('open');
                            var tempbc = $(this).parent().html();
                            breadcrumbs += tempbc.substring(0, tempbc.indexOf('</a>') + 4).toUpperCase();
                            $('#productarea .topnav').html(breadcrumbs + $('#productarea .topnav').html());
                        }
                    }
                });
            }
        }
    });
    //getParentTypes();
    var userAgent = navigator.userAgent.toLowerCase();
    if (/chrome/.test(navigator.userAgent.toLowerCase())) {
        $.browser.chrome = true;
    }

    // Is this a version of Chrome?
    if ($.browser.chrome) {
        userAgent = userAgent.substring(userAgent.indexOf('chrome/') + 7);
        userAgent = userAgent.substring(0, userAgent.indexOf('.'));
        $.browser.version = userAgent;
        // If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
        $.browser.safari = false;
    }

    // Is this a version of Safari?
    if ($.browser.safari) {
        userAgent = userAgent.substring(userAgent.indexOf('safari/') + 7);
        userAgent = userAgent.substring(0, userAgent.indexOf('.'));
        $.browser.version = userAgent;
    }

    if (navigator.platform == 'BlackBerry') {
        $('#dynamicstyle').attr('href', '/wp-content/themes/iphonsta/style.mobile.css');
        $('#mobilevideo').html('<a href="rtsp://cml.delvenetworks.com/a4820/o41/media/8911cba8bf4e4d928387510530c78d73/d93534299a254916b89571a6bf63af96-fd6d61a65be34bcea4ff52fa6d2f7bd5/wddymgm_export3.3gp"><img width="240" height="160" src="http://img.delvenetworks.com/iRHLqL9OTZIg4dRBTDHjXM/2TU0KZolSRYuJVxpr9jr5Y/aYP.120x66.jpeg" alt="video" style="border: 0pt none ; margin: 0px;"/></a>');
    }
    else if (!$.browser.mobile && window.location.href.indexOf('test') == -1) {
    }
    else {
        $('#topdivvideodata').html('<video controls height="338" width="594" src="http://www.facestockholm.com/userfiles/file/about.mp4" poster="http://www.facestockholm.com/userfiles/image/home_vid_screencap.jpg">');
    }

    var thecount = 0;
    $('#home .teaserbar ul li').each(function () {
        if (thecount > 0) {
            $(this).css('border-left', '1px solid black');
        }
        thecount++;
    });
    //alert(Modernizr.video.h264);
    //alert(detectFlash());
});

function detectFlash() {
    if (navigator.plugins) {
        if (navigator.plugins["Shockwave Flash"]) {
            var flashDescription = navigator.plugins["Shockwave Flash"].description;

            var flashVersion = parseInt(flashDescription.substring(16));

            flash2Installed = flashVersion == 2;
            flash3Installed = flashVersion == 3;
            flash4Installed = flashVersion == 4;
            flash5Installed = flashVersion == 5;
            flash6Installed = flashVersion == 6;
            flash7Installed = flashVersion == 7;
            flash8Installed = flashVersion == 8;
            flash9Installed = flashVersion == 9;
            flash10Installed = flashVersion == 10;
            flash11Installed = flashVersion >= 11;
        }
    }

    for (var i = 2; i <= 11; i++) {
        if (eval("flash" + i + "Installed") == true) actualVersion = i;
    }

    return actualVersion;
}
function freshfacelinks() {
    $('a').click(function () {
        if ($(this).attr('href') == "") {
            var thelink = $(this).attr('name');
            if (thelink == '') {
                thelink = $(this).text();
            }
            $.ajax({
                url: "/ajax.aspx",
                data: "action=getaboutpage&title=" + thelink + "&page=fresh face&nd=" + Math.random(),
                type: "get",
                dataType: "text",
                success: function (res) {
                    $('.bottomleftdata').html(res);
                    freshfacelinks();
                    $('img').each(function () {
                        $(this).load(function () {
                            if ($(this).height() == 0) {
                                $(this).parent().css('min-height', '180px');
                            }
                            else {
                                $(this).parent().css('min-height', ($(this).height()) + 'px');
                            }
                        });
                    });
                }
            });
            return false;
        }
        else if ($(this).attr('href') == "#") {
            var ValidChars = "0123456789.";
            var IsNumber = true;
            var Char;
            for (i = 0; i < $(this).attr('name').length && IsNumber == true; i++) {
                Char = $(this).attr('name').charAt(i);
                if (ValidChars.indexOf(Char) == -1) {
                    IsNumber = false;
                }
            }
            if (!IsNumber) {
                $.ajax({
                    url: "/ajax.aspx",
                    data: "action=getaboutpage&title=" + $(this).attr('name') + "&page=fresh face&nd=" + Math.random(),
                    type: "get",
                    dataType: "text",
                    success: function (res) {
                        $('.bottomleftdata').html(res);
                        freshfacelinks();
                        $('img').each(function () {
                            $(this).load(function () {
                                if ($(this).height() == 0) {
                                    $(this).parent().css('min-height', '180px');
                                }
                                else {
                                    $(this).parent().css('min-height', ($(this).height()) + 'px');
                                }
                            });
                        });
                    }
                });
            }
            else {
                $.ajax({
                    url: "/ajax.aspx",
                    data: "action=getpagebyid&title=" + $(this).attr('name') + "&nd=" + Math.random(),
                    type: "get",
                    dataType: "text",
                    success: function (res) {
                        $('.bottomleftdata').html(res);
                        freshfacelinks();
                        $('img').each(function () {
                            $(this).load(function () {
                                if ($(this).height() == 0) {
                                    $(this).parent().css('min-height', '180px');
                                }
                                else {
                                    $(this).parent().css('min-height', ($(this).height()) + 'px');
                                }
                            });
                        });
                    }
                });
            }
            return false;
        }
        else if ($(this).attr('href') == "*") {
            $('#' + $(this).attr('id').replace('link', 'exc').replace('less', 'exc')).toggle(300);
            $('#' + $(this).attr('id').replace('link', 'ent').replace('less', 'ent')).toggle(300);
            return false;
        }
    });
    $('.excerpt').each(function () {
        var theid = $(this).attr('id');
        $(this).find('img').click(function () {
            $('#' + theid).hide(300);
            $('#' + theid.replace('exc', 'ent')).show(300)
        });
    });
}

function leftnavcheck(theObject)
{
}

function colorclick(theObject) {
    $('.leftColorimg').attr("src", "/pimg/" + $('#' + theObject + 'img').attr('alt'));
    $('.leftColorlbl').text($('#' + theObject + 'lbl').attr('class'));
    $('.colorID').text($('#' + theObject + 'lbl').text());
    $('.colorID2').text($('#' + theObject + 'lbl').text());
    $('.priceID').text($('#' + theObject + 'price').val());
    $('.imgrec1').attr('src', '/pimg/' + $('#' + theObject + 'rec1').val());
    $('.imgrec2').attr('src', '/pimg/' + $('#' + theObject + 'rec2').val());
    $('.lblrec1').html($('#' + theObject + 'rec1info').val().replace(': ', ':<br />'));
    $('.lblrec2').html($('#' + theObject + 'rec2info').val().replace(': ', ':<br />'));
    $('.arec1').attr('href', '/search.asp?mode=product&typeid=0&productid=' + $('#' + theObject + 'rec1id').val().replace(': ', ':<br />'));
    $('.arec2').attr('href', '/search.asp?mode=product&typeid=0&productid=' + $('#' + theObject + 'rec2id').val().replace(': ', ':<br />'));
    $('.coloradd').show();
    $('.colorsubmit').hide();
    $('.selectedproductid').val($('#' + theObject + 'id').val())
    $('.lblPN').text($('#' + theObject + 'name').val() + ':')
    $(".boxy-modal-blackout").live("click", function () {
        $(".closeboxy").click();
    });
    if ($('#' + theObject + 'inventory').val() == 0) {
        $('.backordered').show();
    }
    else {
        $('.Addtocart1').show();
    }
}

function boxyclick() {
    new Boxy($('.colorhidden').html(), { modal: true });
    $('.saleQty').change(function () {
        $('.saleQty').val($(this).val());
    });
    $('.Addtocart1').click(function () {
        $.ajax({
            url: "/cart.asp",
            data: "Action=AddItem&ProductID=" + $('.selectedproductid').val() + "&Quantity=" + $('.saleQty').val() + "&nd=" + Math.random(),
            type: "get",
            dataType: "text",
            success: function (res) {
                $('.lblcount').text($('#saleQty').val());
                $('.coloradd').hide();
                $('.colorsubmit').show();
            }
        });
        return false;
    });

    $('.btnCheckout').click(function () {
        window.location = "/checkout.asp?Action=Shipping";
    });
    return false;
}

function getParentTypes() {
    $.ajax({
        url: "/ajax.aspx",
        data: "action=getShopping&typeid=" + $('#hTypeID').val(),
        type: "get",
        dataType: "text",
        success: function (res) {
            $('#leftnav').html(res);
            $('#leftnav li').each(function () {
                if ($('#' + $(this).attr('id') + 'children').length > 0) {
                    $('#' + $(this).attr('id') + 'children').hide();
                    $(this).click(function () {
                        if ($('#' + $(this).attr('id') + 'children').attr('class') != 'open') {
                            $('.open').hide().removeClass('open');
                            $('#' + $(this).attr('id') + 'children').show().addClass('open');
                            return false;
                        }
                        else {
                            $('#' + $(this).attr('id') + 'children').hide().removeClass('open');
                            return false;
                        }
                    });
                }
            });
        }
    });
}

function getChildTypes(parent, parentid, parentparent) {
    $.ajax({
        url: "/ajax.aspx",
        data: "action=getShoppingChild&parent=" + parent.replace('&', 'andand') + "&parentparent=" + parentparent,
        type: "get",
        dataType: "text",
        success: function (res) {
            if (res.length > 0) {
                var ares = res.split(',');
                for (var t in ares) {
                    if (ares[t].length > 0) {
                        $('#' + parentid).append('<td id="parent' + t + parentid + '"><a href="/properties.aspx?action=' + ares[t].substring(0, ares[t].indexOf('<')) + '">' + ares[t].substring(0, ares[t].indexOf('<')) + '</a></td>');
                    }
                }
            }
        }
    });
}

function getChildChildTypes(parent, parentid, parentparent) {
    $('#' + parentid).append('<ul id="' + parentid + 'children"></ul>');
    $.ajax({
        url: "/ajax.aspx",
        data: "action=getShoppingChild&parent=" + parent.replace('&', 'andand') + "&parentparent=" + parentparent,
        type: "get",
        dataType: "text",
        success: function (res) {
            if (res.length > 0) {
                var ares = res.split(',');
                for (var t in ares) {
                    if (ares[t].length > 0) {
                        $('#' + parentid + 'children').append('<li id="parent' + t + parentid + '"><a href="/properties.aspx?action=' + ares[t].substring(0, ares[t].indexOf('<')) + '">' + ares[t].substring(0, ares[t].indexOf('<')) + '</a></li>');
                    }
                }
            }
            else
                $('#' + parentid).remove('#' + parentid + 'children');
        }
    });
}

// JavaScript Document
function isEmail(strEmail) {
    var patrn = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
    return patrn.test(strEmail);
}

function isValidDigit(s) {
    var patrn = /^[0-9]{1,20}$/;
    if (!patrn.exec(s)) return false;
    return true;
}

function isValidInput(s) {
    var patrn = /^([a-zA-Z0-9]|[. ,-]){1,}$/;
    if (!patrn.exec(s)) return false;
    return true;
}

function FormatNumber(srcStr, nAfterDot) {
    var srcStr, nAfterDot;
    var resultStr, nTen;
    srcStr = "" + srcStr + "";
    strLen = srcStr.length;
    dotPos = srcStr.indexOf(".", 0);
    if (dotPos == -1) {
        resultStr = srcStr + ".";
        for (i = 0; i < nAfterDot; i++) {
            resultStr = resultStr + "0";
        }
        return resultStr;
    }
    else {
        if ((strLen - dotPos - 1) >= nAfterDot) {
            nAfter = dotPos + nAfterDot + 1;
            nTen = 1;
            for (j = 0; j < nAfterDot; j++) {
                nTen = nTen * 10;
            }
            resultStr = Math.round(parseFloat(srcStr) * nTen) / nTen;
            return resultStr;
        }
        else {
            resultStr = srcStr;
            for (i = 0; i < (nAfterDot - strLen + dotPos + 1); i++) {
                resultStr = resultStr + "0";
            }
            return resultStr;
        }
    }
}
