﻿function addfavorite(){
    if (document.all) {
        window.external.addFavorite('http://www.edomall.com', '东方衣都');
    }
    else if (window.sidebar) {
        window.sidebar.addPanel('东方衣都', 'http://www.edomall.com', "");
    }
}
function head_Search_keys_onmouseover(obj) {
    if (obj.value == "请输入关键字")
        obj.value = ""
}
function head_Search_keys_onmouseout(obj) {
    if (obj.value == "")
        obj.value = "请输入关键字";
}
function head_Search_keys_keydown(e, obj) {
    var evt = e || window.event;
    if (evt.keyCode == 13) {
        head_search(obj);
    }
    return false;
}
function head_search(obj) {
    if (document.getElementById("head_Search_keys").value == "" || document.getElementById("head_Search_keys").value == "请输入关键字") {
        alert("请输入关键字");
    }
    else {
        document.getElementById(obj).click();
    }
}
function validateDay(str) {
    var r = str.split("-");
    if (r == null) return false;
    var d = new Date(r[0], r[1] - 1, r[2]);
    return (d.getFullYear() == r[0] && (d.getMonth() + 1) == r[1] && d.getDate() == r[2]);
}
function getBodyObj() {
    return (document.documentElement) ? document.documentElement : document.body;
}
function IsNumber(v) {
    var re = /^-?[\d]+$/;
    return re.test(v);
}
function IsDecimal(v) {
    var re = /^-?[\d]+\.?[\d]*$/;
    return re.test(v);
}
function IsEmail(v) {
    var re = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    return re.test(v);
}
function CheckIDCard(strID) {
    //验证各位字符是否合法的正则表达式   
    ReDigital15 = /\d{15}/;
    ReDigital18 = /\d{17}[0-9xX]{1}/;
    //提取日期和校验的正则表达式   
    ReDate15 = /\d{6}(\d{6})\d{3}/;
    ReDate18 = /\d{6}(\d{8})\d{3}/;
    switch (strID.length) {
        case 15:
            if (ReDigital15.test(strID) == false)
                return "非法字符";
            Arr = ReDate15.exec(strID);
            strDate = "19" + Arr[1];
            if (CheckDate(strDate, new Date(1900, 0, 1), new Date(1999, 11, 31)) == false)
                return "日期无效";
            break;
        case 18:
            if (ReDigital18.test(strID) == false)
                return "非法字符";
            Arr = ReDate18.exec(strID);
            strDate = Arr[1];
            if (CheckDate(strDate, new Date(1900, 0, 1), new Date()) == false)
                return "日期无效";
            if (CheckSum(strID) == false)
                return "校验错误";
            break;
        default:
            return "位数不对";
            break;
    }
    return "";
}
//对身份证的校验位进行验证   
function CheckSum(strID) {
    //debugger;   
    //18位数字提取正则表达式   
    Re18Digital = /(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})([0-9xX]{1})/;
    Arr = Re18Digital.exec(strID);
    var Wi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
    Sum = 0;
    for (i = 0; i <= 16; i++)
        Sum += Arr[i + 1] * Wi[i];
    ArrCheckSum = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
    strCheckSum = ArrCheckSum[Sum % 11];
    if (strCheckSum == Arr[18].toUpperCase())
        return true;
    else
        return false;
}
function SetAllCheckboxStatus(b) {
    for (i = 0; i < document.form1.elements.length; i++) {
        curObj = document.form1.elements(i);
        if (curObj.type == "checkbox")
            curObj.checked = b;
    }
}
function openMaxwindow(url) {
    var newwin = window.open(url, "", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
    newwin.moveTo(0, 0)
    newwin.resizeTo(screen.width, screen.height - 40)
    newwin.focus();
    return false;
}
function username_chk(username) {
    if (username != "") {
        $.ajax({
            type: "POST",
            url: "Register.aspx",
            data: "chkusername=" + username,
            success: function (msg) {
                if (msg == "")
                    usernamechkpass = true;
                else {
                    usernamechkpass = false;
                    alert(msg);
                    document.getElementById("tb_username").focus();
                }
            }
        });
    }
}

function isSecurity(v) {
    if (v.length < 6) {
        document.getElementById("IsWeak").style.backgroundColor = "#cccccc";
        document.getElementById("IsMiddle").style.backgroundColor = "#cccccc";
        document.getElementById("IsStrong").style.backgroundColor = "#cccccc";
        return false;
    }
    var lv = -1;
    if (v.match(/[a-z]/ig)) { lv++; }
    if (v.match(/[0-9]/ig)) { lv++; }
    if (v.match(/(.[^a-z0-9])/ig)) { lv++; }
    switch (lv) {
        case 0:
            document.getElementById("IsWeak").style.backgroundColor = "#990000"
            document.getElementById("IsMiddle").style.backgroundColor = "#cccccc";
            document.getElementById("IsStrong").style.backgroundColor = "#cccccc";
            break;
        case 1:
            document.getElementById("IsWeak").style.backgroundColor = "#990000"
            document.getElementById("IsMiddle").style.backgroundColor = "#990000";
            document.getElementById("IsStrong").style.backgroundColor = "#cccccc";
            break;
        case 2:
            document.getElementById("IsWeak").style.backgroundColor = "#990000"
            document.getElementById("IsMiddle").style.backgroundColor = "#990000";
            document.getElementById("IsStrong").style.backgroundColor = "#990000";
            break;
        default:
            document.getElementById("IsWeak").style.backgroundColor = "#cccccc";
            document.getElementById("IsMiddle").style.backgroundColor = "#cccccc";
            document.getElementById("IsStrong").style.backgroundColor = "#cccccc";
    }
}

function getTargetObj(w) { return (w.documentElement) ? w.documentElement : w.body; }

function isgotopay(id) {window.open('/Customer_Centre/zhifubaopay.aspx?id=' + id);return false; }

function AddMaskBoard() {
    var targetobj = getTargetObj(document)
    var dialogdiv = document.createElement("div");
    dialogdiv.id = "dialogdiv";
    dialogdiv.className = 'MaskBoard';
    dialogdiv.style.top = "0px";
    dialogdiv.style.left = "0px";
    dialogdiv.style.width = targetobj.scrollWidth + 'px';
    dialogdiv.style.height = targetobj.scrollHeight + 'px';
    document.body.appendChild(dialogdiv);
}
function DeleteMaskBoard() {
    if (document.getElementById("dialogdiv") != null)
        document.body.removeChild(document.getElementById("dialogdiv"));
}
function discountenddateshow(d, h, m, s, id) {
    var str
    if (d > 0 || h > 0 || m > 0 || s > 0) {
        s = s - 1;
        if (s < 0) {
            s = 59;
            m = m - 1
            if (m < 0) {
                h = h - 1
                m = 59
                if (h < 0) {
                    d = d - 1
                    h = 59
                    if (d < 0) {
                        $("#" + id).css("display", "none");
                        return false;
                    }
                }
            }
        }
        if (d > 0) {
            str = d + "天" + h + ":" + to2length(m) + ":" + to2length(s);            
        }
        else {
            str = h + ":" + to2length(m) + ":" + to2length(s);
        }
        $("#" + id).html(str);
        setTimeout(function () { discountenddateshow(d, h, m, s, id); }, 1000); 
        //        setTimeout("discountenddateshow(" + d + "," + h + "," + m + "," + s + "," + id + ")", 1000);
    }
}
function to2length(s)
{
    if (s < 10)
        return "0" + s;
    else
        return s;
}
function IssueEval(sid,me) {
    var url = "Evaluationin.aspx?sid=" + sid;
    $().openwindow({ title: '发表评价', url: url, width: 550, height: 400, elemobj_offsetTop: 5, elemobj_offsetLeft: 20, ismove: true, elemobj: me, elemobj_position: 'bottomright' });
    return false;
}
function ProductshowByID(id) {
    window.location.href = '/Goods/productshow.aspx?pid=' + id;
}
$(document).ready(function () {
    $("body").append("<div id='loading" + "' style='position:absolute;width:" + $(document).width() + "px;height:" + $(document).height() + "px;top:0px;left:0px;zindex:100;display:none'><img id='loadingimg' src='/images/loading.gif' style='position:relative;top:" + ($(window).height()-24) / 2 + "px;left:" + ($(window).width()-24) / 2 + "px'></div>");
    $("#loading")
		.ajaxStart(function () {
		    $(this).show();
		})
		.ajaxComplete(function () {
		    $(this).hide();
		});
}); 

