﻿$(document).ready(function () {
    //top_car///////////////////////////
    $('#cart_t').mousemove(function () {
        $('.lv_cart').css({ 'border-bottom': 'none' });
        $('#cart').slideDown(320);
    });
    $('#cart_t').mouseleave(function () {
        $('#cart').slideUp(200);
        $('.lv_cart').css({ 'border-bottom': '1px solid #b4dae6' });
    });
    //nav///////////////////////////////////
    $('.mainlevel').hover(function () {
        $(this).find('a:first').css({ background: '#fff', color: '#199400' });
        $(this).find('ul').stop(true, true).slideDown(320);
    }, function () {
        $(this).find('a:first').css({ background: 'none', color: '#fff' });
        $(this).find('ul').stop(true, true).slideUp(200);
    });
    $(".mainlevel li a").hover(function () {
        $(this).stop().animate({ marginLeft: "8px" }, 300);
    }, function () {
        $(this).stop().animate({ marginLeft: "0px" }, 300);
    });
    //jfnav///////////////////////////////////

    $('.jf_ce').hover(function () {
        $(this).find('a:first').css({ background: 'url(../images/jifen_08.jpg) no-repeat left #fff', color: '#E2144A', border: '1px solid #4ab809' });
        $(this).find('ul').stop(true, true).slideDown(320);
    }, function () {
        $(this).find('a:first').css({ background: 'url(../images/jifen_08.jpg) no-repeat left #fff', color: '#000', border: '0' });
        $(this).find('ul').stop(true, true).slideUp(200);
    });
    //abc/////////////////////////////////////
    $('.abc').hover(function () {
        $(this).find('a:first').css({ background: 'url(http://images.lvshou.com/nav_06.gif) no-repeat', color: '#000' });
        $(this).find('ul').stop(true, true).slideDown(320);
    }, function () {
        $(this).find('a:first').css({ background: 'none', color: '#fff' });
        $(this).find('ul').stop(true, true).slideUp(200);
    });
    $(".abc li a").hover(function () {
        $(this).stop().animate({ marginLeft: "13px" }, 300);
    }, function () {
        $(this).stop().animate({ marginLeft: "5px" }, 300);
    }); 
    //menu///////////////////////////////////
    $('.menu1,.menu1_div').hover(function () { $('.menu1_div').stop(true, true).slideDown(300); }, function () { $('.menu1_div').stop(true, true).slideUp(100); })
    $('.menu2,.menu2_div').hover(function () { $('.index_menu ul').addClass('menu_2'); $('.menu2_div').stop(true, true).slideDown(300) }, function () { $('.index_menu ul').removeClass('menu_2'); $('.menu2_div').slideUp(100); })
    $('.menu3,.menu3_div').hover(function () { $('.index_menu ul').addClass('menu_3'); $('.menu3_div').stop(true, true).slideDown(300) }, function () { $('.index_menu ul').removeClass('menu_3'); $('.menu3_div').slideUp(100); })
    $('.menu4,.menu4_div').hover(function () { $('.index_menu ul').addClass('menu_4'); $('.menu4_div').stop(true, true).slideDown(300) }, function () { $('.index_menu ul').removeClass('menu_4'); $('.menu4_div').slideUp(100); })
    $('.menu5,.menu5_div').hover(function () { $('.index_menu ul').addClass('menu_5'); $('.menu5_div').stop(true, true).slideDown(300) }, function () { $('.index_menu ul').removeClass('menu_5'); $('.menu5_div').slideUp(100); })
    //web_bank ////////////////////////////
    $("#web_bank li s").hover(function () { $(this).css({ 'border-color': '#2b9e05' }) }, function () { $(this).css({ 'border-color': '#ccc' }); $("#web_bank input:checked").next().css({ 'border-color': '#ff6600' }); });
    $("#web_bank input:checked").next().css({ 'border-color': '#ff6600' });
    $("#web_bank li").click(function () { $('#web_bank li').find('s').css({ 'border-color': '#ccc' }); $(this).find('input').attr("checked", true); $(this).find('s').css({ 'border-color': '#ff6600' }) });
    //xin_bank ///////////////////////
    $("#xin_bank li s").hover(function () { $(this).css({ 'border-color': '#2b9e05' }) }, function () { $(this).css({ 'border-color': '#ccc' }); $("#xin_bank input:checked").next().css({ 'border-color': '#ff6600' }); });
    $("#xin_bank input:checked").next().css({ 'border-color': '#ff6600' });
    $("#xin_bank li").click(function () { $('#xin_bank li').find('s').css({ 'border-color': '#ccc' }); $(this).find('input').attr("checked", true); $(this).find('s').css({ 'border-color': '#ff6600' }) });
	//foot_menu 2012-01-09///////////////////////////
var navCookie = getCookie('navFix');
if(navCookie){
	$('.au_bzhu').stop().css('height','170px');
	$('.au_bzhu').unbind();
	}else{
	$('.au_bzhu').stop().css('height','22px');
	navAnimate();
		}
		
function navAnimate(){
	$('.au_bzhu').hover(
		function(){
			$(this).stop().animate({height: '170px'}, "fast");
		},
		function(){
			$(this).stop().animate({height: '22px'}, "fast");
		});
	}

function getCookie(Name) { 
var re=new RegExp(Name+"=[^;]+", "i"); 
if (document.cookie.match(re))
return document.cookie.match(re)[0].split("=")[1] 
return null 
}
});

//car//////////////////////////////////
function sum(buy) {
    var total = 0;
    for (var i = 1; i <= buy; i++) {
        var m = $('#jia_goods_' + i).val();
        var mm = m.substr(1, m.length);
        total += Number(mm);
    }
    $('#total').text(total);
}
function change(goods, jia, jia_goods, buy) {
    var num = Number($('#' + goods).val());
    if (num < 1) { alert("已经只剩一件了，不买请点击删除！"); num = 1; $('#' + goods).val(num); }
    else {
        $('#' + goods).val(num);
    }
    $('#' + jia_goods).val('￥' + num * jia + '.00');
    return sum(buy);
}
function change_jian(g_id) {
    var num = Number($('#' + g_id).val());
    num--;
    if (num < 1) { alert("已经只剩一件了，不买请点击删除！"); num = 1; $('#' + g_id).val(num); }
    else {
        $('#' + g_id).val(num);
    }
    ChangeProductQuantity(num);
}
function change_add(g_id) {
    var num = Number($('#' + g_id).val());
    num++;
    $('#' + g_id).val(num);
    ChangeProductQuantity(num);
}
//check adress///////////////////////////////
function check(name, n) {
    if ($('#' + name).val() == '') {
        switch (n) {
            case 1:
                $('#error' + name).text('收货人不能为空');
                break;
            case 2:
                $('#error' + name).text('详细邮寄地址不能为空');
                break;
            case 3:
                $('#error' + name).text('邮箱地址不能为空');
                break;
            case 4:
                $('#error' + name).text('手机号码不能为空');
                break;
        }
    }
    else {
        $('#error' + name).text('*');
    }
}

function check_ok() {
    if ($('#Name').val() == '') {
        check('Name', 1);
        return false;
    }
    if ($('#Address').val() == '') {
        check('Address', 2);
        return false;
    }
    if ($('#Mobile').val() == '') {
        check('Mobile', 4);
        return false;
    }
}



//check reg///////////////////////////////
function check_reg(name, n) {
    if ($('#' + name).val() == '') {
        switch (n) {
            case 1:
                $('#error' + name).html('<span class="color4">* 用户名不能为空</span>');
                break;
            case 2:
                $('#error' + name).html('<span class="color4">* 请设置密码</span>');
                break;
            case 3:
                $('#error' + name).html('<span class="color4">* 请再输入一次密码</span>');
                break;
            case 4:
                $('#error' + name).html('<span class="color4">* 邮箱地址不能为空</span>');
                break;
        }
    }
    else {
        switch (n) {
            case 1:
                if ($('#' + name).val().length > 14 || $('#' + name).val().length < 6)
                { $('#error' + name).html('<span class="color4">* 用户名范围在6~14位之间</span>'); }
                else { $('#error' + name).html('<span class="color4">*</span>'); }
                break;
            case 2:
                if ($('#' + name).val().length > 16 || $('#' + name).val().length < 6)
                { $('#error' + name).html('<span class="color4">* 密码范围在6~16位之间</span>'); }
                else { $('#error' + name).html('<span class="color4">*</span>'); }
                break;
            case 3:
                if ($('#' + name).val() == $('#Pw').val())
                { $('#error' + name).html('<span class="color4">*</span>'); }
                else { $('#error' + name).html('<span class="color4">* 两次输入的密码不一致</span>'); }
                break;
            case 4:
                $('#error' + name).html('<span class="color4">*</span>');
                break;
            case 5:
                if ($('#' + name).val() == $('#newPwd').val())
                { $('#error' + name).html('<span class="color4">*</span>'); }
                else { $('#error' + name).html('<span class="color4">* 两次输入的密码不一致</span>'); }
                break;
        }
    }
}

function reg_ok() {
    var reg_Email = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    var str = $('#User').val();
    var reLen = 0;
    for (var i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) < 27 || str.charCodeAt(i) > 126) {
            // 全角    
            reLen += 2;
        }
        else {
            reLen++;
        }
    }
    if ($('#User').val() == ''||reLen>16||reLen<6) {
        check_reg('User', 1);
        return false;
    }
    if ($('#Pw').val() == '') {
        check_reg('Pw', 2);
        return false;
    }
    if ($('#Pw').val().length > 16 || $('#Pw').val().length < 6) {
        check_reg('Pw', 2);
        return false;
    }
    if ($('#Pw_ok').val() !== $('#Pw').val()) {
        check_reg('Pw_ok', 3);
        return false;
    }
    if ($('#Email').val() !== "") {
        if (!reg_Email.test($('#Email').val())) {
            $('#errorEmail').html('<span class="color4">* 邮箱格式不正确</span>');
            return false;
        }
    }
    if ($('#Email').val() == "") {

        check_reg('Email', 4);
        return false;

    }
    if ($('#Mobile').val() != '' && $('#Mobile').val().length != 11) {
        $('#errorMobile').html('<span class="color4">* 手机号码非法</span>');
        return false;
    }
}

function change_ok() {
    if ($('#oldPwd').val() == '') {
        check_reg('oldPwd', 2);
        return false;
    }
    if ($('#oldPwd').val().length > 16 || $('#oldPwd').val().length < 6) {
        check_reg('oldPwd', 2);
        return false;
    }
    if ($('#newPwd').val() !== $('#newPwd').val()) {
        check_reg('newPwd', 2);
        return false;
    }
    if ($('#newPwd').val().length > 16 || $('#newPwd').val().length < 6) {
        check_reg('newPwd', 2);
        return false;
    }
    if ($('#confirmPwd').val() == '') {
        check_reg('confirmPwd', 2);
        return false;
    }
    if ($('#confirmPwd').val() !== $('#newPwd').val()) {
        check_reg('confirmPwd', 5);
        return false;
    }
    if ($('#confirmPwd').val().length > 16 || $('#confirmPwd').val().length < 6) {
        check_reg('confirmPwd', 2);
        return false;
    }
}

//check goods_comments/////////////////////////
function check_comments() {
    if ($('#comments_info').val().length < 6) {
        alert('您的评论内容太短或者为空')
        return false;
    }
}


//tab//////////////////////////////////
var ID = function id(id) {
    return document.getElementById(id);
}
function setTab(m, n, tname, iname) {
    var title = ID("tab" + m).getElementsByTagName(tname);
    var info = ID("tabi" + m).getElementsByTagName(iname);
    for (i = 0; i < title.length; i++) {
        title[i].className = i == n ? "hover" : "";
        info[i].style.display = i == n ? "block" : "none";
    }
}

//Dialog box ////////////////////////////////////////////////
(function ($) {
    var openedPopups = [];
    var popupLayerScreenLocker = false;
    var focusableElement = [];
    var setupJqueryMPopups = {
        screenLockerBackground: "#fff",
        screenLockerOpacity: "0.4"
    };

    $.setupJMPopups = function (settings) {
        setupJqueryMPopups = jQuery.extend(setupJqueryMPopups, settings);
        return this;
    }

    $.openPopupLayer = function (settings) {
        if (typeof (settings.name) != "undefined" && !checkIfItExists(settings.name)) {
            settings = jQuery.extend({
                width: "auto",
                height: "auto",
                parameters: {},
                target: "",
                success: function () { },
                error: function () { },
                beforeClose: function () { },
                afterClose: function () { },
                reloadSuccess: null,
                cache: false
            }, settings);
            loadPopupLayerContent(settings, true);
            return this;
        }
    }

    $.closePopupLayer = function (name) {
        if (name) {
            for (var i = 0; i < openedPopups.length; i++) {
                if (openedPopups[i].name == name) {
                    var thisPopup = openedPopups[i];

                    openedPopups.splice(i, 1)

                    thisPopup.beforeClose();

                    $("#popupLayer_" + name).fadeOut(function () {
                        $("#popupLayer_" + name).remove();

                        focusableElement.pop();

                        if (focusableElement.length > 0) {
                            $(focusableElement[focusableElement.length - 1]).focus();
                        }

                        thisPopup.afterClose();
                        hideScreenLocker(name);
                    });
                    break;
                }
            }
        } else {
            if (openedPopups.length > 0) {
                $.closePopupLayer(openedPopups[openedPopups.length - 1].name);
            }
        }

        return this;
    }

    $.reloadPopupLayer = function (name, callback) {
        if (name) {
            for (var i = 0; i < openedPopups.length; i++) {
                if (openedPopups[i].name == name) {
                    if (callback) {
                        openedPopups[i].reloadSuccess = callback;
                    }

                    loadPopupLayerContent(openedPopups[i], false);
                    break;
                }
            }
        } else {
            if (openedPopups.length > 0) {
                $.reloadPopupLayer(openedPopups[openedPopups.length - 1].name);
            }
        }

        return this;
    }

    function setScreenLockerSize() {
        if (popupLayerScreenLocker) {
            $('#popupLayerScreenLocker').height($(document).height() + "px");
            $('#popupLayerScreenLocker').width($(document.body).outerWidth(true) + "px");
        }
    }

    function checkIfItExists(name) {
        if (name) {
            for (var i = 0; i < openedPopups.length; i++) {
                if (openedPopups[i].name == name) {
                    return true;
                }
            }
        }
        return false;
    }

    function showScreenLocker() {
        if ($("#popupLayerScreenLocker").length) {
            if (openedPopups.length == 1) {
                popupLayerScreenLocker = true;
                setScreenLockerSize();
                $('#popupLayerScreenLocker').fadeIn();
            }

            if ($.browser.msie && $.browser.version < 7) {
                $("select:not(.hidden-by-jmp)").addClass("hidden-by-jmp hidden-by-" + openedPopups[openedPopups.length - 1].name).css("visibility", "hidden");
            }

            $('#popupLayerScreenLocker').css("z-index", parseInt(openedPopups.length == 1 ? 999 : $("#popupLayer_" + openedPopups[openedPopups.length - 2].name).css("z-index")) + 1);
        } else {
            $("body").append("<div id='popupLayerScreenLocker'><!-- --></div>");
            $("#popupLayerScreenLocker").css({
                position: "absolute",
                background: setupJqueryMPopups.screenLockerBackground,
                left: "0",
                top: "0",
                opacity: setupJqueryMPopups.screenLockerOpacity,
                display: "none"
            });
            showScreenLocker();

            $("#popupLayerScreenLocker").click(function () {
                $.closePopupLayer();
            });
        }
    }

    function hideScreenLocker(popupName) {
        if (openedPopups.length == 0) {
            screenlocker = false;
            $('#popupLayerScreenLocker').fadeOut();
        } else {
            $('#popupLayerScreenLocker').css("z-index", parseInt($("#popupLayer_" + openedPopups[openedPopups.length - 1].name).css("z-index")) - 1);
        }

        if ($.browser.msie && $.browser.version < 7) {
            $("select.hidden-by-" + popupName).removeClass("hidden-by-jmp hidden-by-" + popupName).css("visibility", "visible");
        }
    }

    function setPopupLayersPosition(popupElement, animate) {
        if (popupElement) {
            if (popupElement.width() < $(window).width()) {
                var leftPosition = (document.documentElement.offsetWidth - popupElement.width()) / 2;
            } else {
                var leftPosition = document.documentElement.scrollLeft + 5;
            }

            if (popupElement.height() < $(window).height()) {
                var topPosition = document.documentElement.scrollTop + ($(window).height() - popupElement.height()) / 5;
            } else {
                var topPosition = document.documentElement.scrollTop + 5;
            }

            var positions = {
                left: leftPosition + "px",
                top: topPosition + "px"
            };

            if (!animate) {
                popupElement.css(positions);
            } else {
                popupElement.animate(positions, "slow");
            }

            setScreenLockerSize();
        } else {
            for (var i = 0; i < openedPopups.length; i++) {
                setPopupLayersPosition($("#popupLayer_" + openedPopups[i].name), true);
            }
        }
    }

    function showPopupLayerContent(popupObject, newElement, data) {
        var idElement = "popupLayer_" + popupObject.name;

        if (newElement) {
            showScreenLocker();

            $("body").append("<div id='" + idElement + "'><!-- --></div>");

            var zIndex = parseInt(openedPopups.length == 1 ? 1000 : $("#popupLayer_" + openedPopups[openedPopups.length - 2].name).css("z-index")) + 2;
        } else {
            var zIndex = $("#" + idElement).css("z-index");
        }

        var popupElement = $("#" + idElement);

        popupElement.css({
            visibility: "hidden",
            width: popupObject.width == "auto" ? "" : popupObject.width + "px",
            height: popupObject.height == "auto" ? "" : popupObject.height + "px",
            position: "absolute",
            "z-index": zIndex
        });

        var linkAtTop = "<a href='#' class='jmp-link-at-top' style='position:absolute; left:-9999px; top:-1px;'>&nbsp;</a><input class='jmp-link-at-top' style='position:absolute; left:-9999px; top:-1px;' />";
        var linkAtBottom = "<a href='#' class='jmp-link-at-bottom' style='position:absolute; left:-9999px; bottom:-1px;'>&nbsp;</a><input class='jmp-link-at-bottom' style='position:absolute; left:-9999px; top:-1px;' />";

        popupElement.html(linkAtTop + data + linkAtBottom);

        setPopupLayersPosition(popupElement);

        popupElement.css("display", "none");
        popupElement.css("visibility", "visible");

        if (newElement) {
            popupElement.fadeIn();
        } else {
            popupElement.show();
        }

        $("#" + idElement + " .jmp-link-at-top, " +
		  "#" + idElement + " .jmp-link-at-bottom").focus(function () {
		      $(focusableElement[focusableElement.length - 1]).focus();
		  });

        var jFocusableElements = $("#" + idElement + " a:visible:not(.jmp-link-at-top, .jmp-link-at-bottom), " +
								   "#" + idElement + " *:input:visible:not(.jmp-link-at-top, .jmp-link-at-bottom)");

        if (jFocusableElements.length == 0) {
            var linkInsidePopup = "<a href='#' class='jmp-link-inside-popup' style='position:absolute; left:-9999px;'>&nbsp;</a>";
            popupElement.find(".jmp-link-at-top").after(linkInsidePopup);
            focusableElement.push($(popupElement).find(".jmp-link-inside-popup")[0]);
        } else {
            jFocusableElements.each(function () {
                if (!$(this).hasClass("jmp-link-at-top") && !$(this).hasClass("jmp-link-at-bottom")) {
                    focusableElement.push(this);
                    return false;
                }
            });
        }

        $(focusableElement[focusableElement.length - 1]).focus();

        popupObject.success();

        if (popupObject.reloadSuccess) {
            popupObject.reloadSuccess();
            popupObject.reloadSuccess = null;
        }
    }

    function loadPopupLayerContent(popupObject, newElement) {
        if (newElement) {
            openedPopups.push(popupObject);
        }

        if (popupObject.target != "") {
            showPopupLayerContent(popupObject, newElement, $("#" + popupObject.target).html());
        } else {
            $.ajax({
                url: popupObject.url,
                data: popupObject.parameters,
                cache: popupObject.cache,
                dataType: "html",
                method: "GET",
                success: function (data) {
                    showPopupLayerContent(popupObject, newElement, data);
                },
                error: popupObject.error
            });
        }
    }

    $(window).resize(function () {
        setScreenLockerSize();
        setPopupLayersPosition();
    });

    $(document).keydown(function (e) {
        if (e.keyCode == 27) {
            $.closePopupLayer();
        }
    });
})(jQuery);
//ajax login Dialog box 
function login() {
    $.openPopupLayer({
        name: "login",
        width: 288,
        url: WebSite + "/Member/login.aspx"
    });
}


function login2() {
    $.openPopupLayer({
        name: "login2",
        width: 625,
        url: WebSite + "/Measurement/Default.aspx"
    });
}

var DEFAULT_LENGTH = 14;
function lengthValidate() {

    var len = 0;
    var reLen = 0;
    var chaju = 0;
    var str = document.getElementById('cName').value;
    len = str.length;
    for (var i = 0; i < len; i++) {
        if (str.charCodeAt(i) < 27 || str.charCodeAt(i) > 126) {
            // 全角    
            reLen += 2;
        }
        else {
            reLen++;
        }
    }
    chaju = reLen - len;
    //alert(len+"|"+reLen+"|"+chaju);
    document.getElementById('cName').maxLength = DEFAULT_LENGTH - chaju;
}

function lengthValidateUser() {

    var len = 0;
    var reLen = 0;
    var chaju = 0;
    var str = document.getElementById('User').value;
    len = str.length;
    for (var i = 0; i < len; i++) {
        if (str.charCodeAt(i) < 27 || str.charCodeAt(i) > 126) {
            // 全角    
            reLen += 2;
        }
        else {
            reLen++;
        }
    }
    chaju = reLen - len;
    //alert(len+"|"+reLen+"|"+chaju);
    document.getElementById('User').maxLength = DEFAULT_LENGTH - chaju;
}
//scores_tips////////
function scores_tips() {
    $('#scores').animate({ opacity: 'show' }, { duration: 500 });
}
function close_scores() {
    $('#scores').animate({ opacity: 'hide' }, { duration: 500 });
}

//function addrress() {
//    var _address = $("input[name='address']:checked").val();
//    if (_address == -1) {
//        $('#post_other').show();
//        return check_ok();
//    }
//    else { $('#post_other').hide(); }
//}
//function addrress_reset() {
//    document.form1.reset();
//    $("input[type=radio]").attr("checked", '-1')
//}
