//去左右空格 add by yang
function trim(str) {
    str += "";
    while ((str.charAt(0) == ' ') || (str.charAt(0) == '　') || (escape(str.charAt(0)) == '%u3000'))
        str = str.substring(1, str.length);
    while ((str.charAt(str.length - 1) == ' ') || (str.charAt(str.length - 1) == '　') || (escape(str.charAt(str.length - 1)) == '%u3000'))
        str = str.substring(0, str.length - 1);
    return str;
}

//检查E-mail add by yang
function isEmail(s) {
    if (s.length > 100) return false;
    if (s.indexOf("'") != -1 || s.indexOf("/") != -1 || s.indexOf("\\") != -1 || s.indexOf("<") != -1 || s.indexOf(">") != -1) return false;
    s = s.replace('(', '');
    s = s.replace(')', '');
    s = s.replace('（', '');
    s = s.replace('）', '');

    var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[_.0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([^\.]+)$";

    var result = true;
    var arrayStr = s.split(";");
    var i = 0;
    for (; i < arrayStr.length; i++) {
        if (s.charAt(0) == " ") {
            result = false;
            break;
        }
        if (s.charAt(s.length - 1) == " ") {
            result = false;
            break;
        }
        var re = new RegExp(regu);
        if (arrayStr[i].search(re) == -1) {
            result = false;
            break;
        }
    }
    return result;
}

//校验手机号码：必须以数字开头，除数字外，可含有“-” add by yang
function isMobil(s) {
    var patrn = /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
    if (!patrn.exec(s)) return false
    return true
}

//校验是否全由数字组成 add by yang
function isDigit(s) {
    var patrn = /^[0-9]{1,20}$/;
    if (!patrn.exec(s)) return false
    return true
}

function ShowTime(obj)//显示时间 
{
    var now_time = new Date();
    var years = now_time.getFullYear();
    var months = now_time.getMonth();
    var dates = now_time.getDate();
    var days = now_time.getDay();
    var today = (months + 1) + "月" + dates + "日";
    var weeks;
    if (days == 0)
        weeks = "星期日";
    if (days == 1)
        weeks = "星期一";
    if (days == 2)
        weeks = "星期二";
    if (days == 3)
        weeks = "星期三";
    if (days == 4)
        weeks = "星期四";
    if (days == 5)
        weeks = "星期五";
    if (days == 6)
        weeks = "星期六";
    var doc = document.getElementById(obj);
    doc.innerHTML = "<span>" + today + "</span>" + "<span>" + weeks + "</span>";
}

//邮件订阅
function CollectMail() {
    $.ajax({
        type: "POST",
        url: "Ajax/Ajax_CollectEmail.ashx",
        data: "txtEmail=" + $("#txtEmail").val(),
        beforeSend:
            function () {
            },
        success:
            function (data) {
                alert(data);
            }
    });
}

//收藏
function Collection(ProductID) {
    $.ajax({
        type: "GET",
        url: "Ajax/Ajax_Collection.ashx",
        data: "ProductID=" + ProductID + "&rnd=" + Math.round(Math.random() * 500),
        beforeSend:
			function () {
			},
        success:
			function (data) {
			    alert(data);
			}
    });
}

//首页二级联动
function GetChildClass() {
    $.ajax({
        type: "GET",
        url: "Ajax/Ajax_GetChildClass.ashx",
        data: "ParentID=" + $("#SelectParent").val() + "&rnd=" + Math.round(Math.random() * 500),
        beforeSend:
			function () {
			},
        success:
			function (data) {
			    $("#SelectChild").empty();
			    $("#SelectChild").append(data);
			}
    });
}

function Search() {
    if ($("#SearchKey").val() == "") {
        alert("请输入搜索关键字!");
        $("#SearchKey").focus();
        return false;
    }
}

