String.prototype.IsPartNumber = function() {
    myReg = /^[0-9a-zA-Z#][0-9a-zA-Z-_\+\/\.\\ \(\)#\=%]{3,49}$/;
    if (myReg.test(this)) {
        return true;
    } else {
        return false;
    }
}



String.prototype.len = function() {
    return this.replace(/[^\x00-\xff]/g, "**").length;
}

String.prototype.IsDate = function() {
    var myReg = /^(\d{4})(-|\/|.)(\d{1,2})\2(\d{1,2})$/;
    var result = this.match(myReg);
    if (result == null) return false;
    var test = new Date(result[1], result[3] - 1, result[4]);
    if ((test.getFullYear() == result[1]) && (test.getMonth() + 1 == result[3]) && (test.getDate() == result[4])) {
        ActRs.Clear();
        ActRs[0] = result[1]; ActRs[1] = result[3]; ActRs[2] = result[4];
        return true;
    }
    else return false;
}

String.prototype.IsTime = function() {
    var myReg = /^(\d{1,2})(:)(\d{1,2})\2(\d{1,2})$/;
    var result = this.match(myReg);
    if (result == null) return false;
    var test = new Date(2000, 1, 1, result[1], result[3], result[4]);
    if ((test.getHours() == result[1]) && (test.getMinutes() == result[3]) && (test.getSeconds() == result[4])) {
        ActRs[3] = result[1]; ActRs[4] = result[3]; ActRs[5] = result[4];
        return true;
    }
    else return false;
}

String.prototype.IsDateTime = function() {
    var myReg = this.split(" ");
    if (myReg.length != 2) return false;
    if (myReg[0].IsDate() && myReg[1].IsTime()) return true;
    return false;
}

String.prototype.IsEmail = function() {
    myReg = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$/;
    if (myReg.test(this)) {
        return true;
    } else {
        return false;
    }

}


String.prototype.IsPassword = function() {
    myReg = /^.{6,16}$/;
    if (myReg.test(this)) {
        return true;
    } else {
        return false;
    }
}



String.prototype.IsIdcard = function() {
    var myReg = /^[1-9][0-9]{14}$|^[1-9][0-9]{16}[0-9a-zA-Z]$/;
    if (myReg.test(this)) return true;
    return false;
}

String.prototype.IsNumber = function() {
    var myReg = /^[0-9]+$/;
    if (!myReg.test(this)) return false;
    ActRd = parseInt(this)
    return true;
}

String.prototype.IsFloat = function() {
    var myReg = /^[0-9.]+$/;
    if (!myReg.test(this)) return false;
    var pos = this.indexOf('.')
    if (pos == -1) return false;
    if (pos != this.lastIndexOf('.')) return false;
    if (pos == 0 || (pos + 1) == this.length) return false;
    ActRd = parseFloat(this)
    return true;
}

String.prototype.IsPhone = function() {
    if (!this.IsNumber()) return false;
    if (this.length != 11 || this < 13000000000 || this > 13999999999) return false;
    return true;
}


String.prototype.IsEn = function() {
    var myReg = /^[a-zA-Z]+$/;
    if (myReg.test(this)) return true;
    return false;
}

String.prototype.IsCn = function() {
    var ch, temp, isCN, isTrue;
    isTrue = true;
    for (var i = 0; i < this.length; i++) {
        ch = this.substring(i, i + 1);
        temp = escape(ch);
        isCN = (temp.length == 6) ? true : false;
        if (!isCN) {
            isTrue = false;
            break;
        }
    }
    return isTrue;
}


String.prototype.Trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.Left = function(n) {
    return strLeft(this, n);
}

String.prototype.Right = function(n) {
    return strRight(this, n);
}

String.prototype.Len = function() {
    var len = 0;
    for (var i = 0; i < this.length; i++) {
        if (this.charCodeAt(i) > 255) len += 2;
        else len++;
    }
    return len;
}



String.prototype.Escape = function() {
    return escape(this);
}

String.prototype.UnEscape = function() {
    return unescape(this);
}

String.prototype.UrlEncode = function() {
    var i, c, p, q, ret = "", strSpecial = "!\"#$%&'()*+,/:;<=>?@[\]^`{|}~%";
    for (i = 0; i < this.length; i++) {
        if (this.charCodeAt(i) >= 0x4e00) {
            var p = GBStr.indexOf(this.charAt(i));
            if (p >= 0) {
                q = p % 94;
                p = (p - q) / 94;
                ret += ("%" + (0xB0 + p).toString(16) + "%" + (0xA1 + q).toString(16)).toUpperCase();
            }
        }
        else {
            c = this.charAt(i);
            if (c == " ")
                ret += "+";
            else if (strSpecial.indexOf(c) != -1)
                ret += "%" + this.charCodeAt(i).toString(16);
            else
                ret += c;
        }
    }
    return ret;
}


String.prototype.toInt = function() {

    return parseInt(this);
}

String.prototype.toFloat = function() {

    return parseFloat(this);
}

String.prototype.toHex = function() {
    if (!this.IsNumber()) return "";
    var x = parseInt(this);
    var out = "";
    var remainder;
    while (x > 0) {
        remainder = x % 16;
        if (remainder < 10) {
            out = remainder + out;
        } else if (remainder == 10) {
            out = "a" + out;
        } else if (remainder == 11) {
            out = "b" + out;
        } else if (remainder == 12) {
            out = "c" + out;
        } else if (remainder == 13) {
            out = "d" + out;
        } else if (remainder == 14) {
            out = "e" + out;
        } else if (remainder == 15) {
            out = "f" + out;
        }
        x = Math.floor(x / 16);
    }
    return out;
}

String.prototype.toDate = function() {
    ActRs.Clear();
    this.IsDate();
    return new Date(ActRs[0], ActRs[1] - 1, ActRs[2]);
}

String.prototype.toSpell = function(sp) {
    var i, t, p, ret = "";
    if (sp == null) sp = "";
    for (i = 0; i < this.length; i++) {
        if (this.charCodeAt(i) >= 0x4e00) {
            p = GBStr.indexOf(this.charAt(i));
            if (p > -1 && p < 3755) {
                for (t = GBSpell.length - 1; t > 0; t = t - 2)
                    if (GBSpell[t] <= p) break;
                if (t > 0)
                    ret += GBSpell[t - 1] + sp;
            }
        }
        else ret += this.charAt(i) + sp;
    }
    return ret.substr(0, ret.length - sp.length);
}



String.prototype.Count = function() {
    var out = new Array(256);
    for (var i = 0; i < this.length; i++) {
        if (out[this.charCodeAt(i)] == undefined) {
            out[this.charCodeAt(i)] = 1;
        } else {
            out[this.charCodeAt(i)]++;
        }
    }
    return out;
}
String.prototype.IsSigKey = function() {
    var regcheck = /^[a-zA-Z0-9]{64}$/;
    if (regcheck.test(this)) {
        return true;
    }
    else {
        return false;
    }
}

function getQQ(QQ) {
    if (QQ == "") {
        return;
    }
    var list = new Array();
    list = QQ.toString().split("/");
    for (ii = 0; ii < list.length; ii++) {
        if (list[ii] != "") {
            document.write("<a target=blank href=http://wpa.qq.com/msgrd?V=1&Uin=" + list[ii] + "&Site=www.icqoso.com&Menu=yes><img border=\"0\" SRC=http://wpa.qq.com/pa?p=1:" + list[ii] + ":4 alt=\"QQ " + list[ii] + "\" onerror=\"this.src=\'http://www.icqoso.com/images/qq.gif\'\"></a> ");
        }
    }
}

function GetQQ(val) {
    var vals = '';
    var qqandkey = '';
    var qq = '';
    var sigkey = '';
    var tempval = val;
    var writeval = '';
    if (tempval.Trim() != "") {
        vals = tempval.split("/");
        if (vals.length > 0) {
            for (var i = 0; i < vals.length; i++) {
                qqandkey = vals[i].split("#");
                if (qqandkey.length == 1 || qqandkey.length == 2) {
                    if (qqandkey.length == 2) {
                        qq = qqandkey[0].Trim();
                        sigkey = qqandkey[1].Trim()
                    }
                    else if (qqandkey.length == 1) {
                        qq = qqandkey[0].Trim();
                    }
                    if (sigkey != "" && qq != "" && qq.IsNumber() && sigkey.IsSigKey()) {
                        writeval = writeval + '<a href="http://sighttp.qq.com/cgi-bin/check?sigkey=' + sigkey.Trim() + '" target="_blank" onclick="var oldscript=document.getElementById(\'testJs\');var newscript=document.createElement(\'script\');newscript.setAttribute(\'type\',\'text/javascript\');newscript.setAttribute(\'id\',\'testJs\');newscript.setAttribute(\'src\',\'http://sighttp.qq.com/wpa.js?rantime=\'+Math.random()+\'&sigkey=' + sigkey.Trim() + '\');if(oldscript ==null){document.body.appendChild(newscript);}else{oldscript.parentNode.replaceChild(newscript, oldscript);};return false;"><img border="0" SRC="http://wpa.qq.com/pa?p=1:' + qq.Trim() + ':4" alt="QQ：' + qq.Trim() + '" onerror="this.src=\'http://www.icqoso.com/images/qq.gif\'" ></a>';
                    }
                    else if (qq != "" && qq.IsNumber()) {
                        writeval = writeval + '<a href="tencent://message/?uin=' + qq.Trim() + '&Site=www.icqoso.com&Menu=yes"><img border="0" SRC="http://wpa.qq.com/pa?p=1:' + qq.Trim() + ':4" alt="QQ：' + qq.Trim() + '" onerror="this.src=\'http://www.icqoso.com/images/qq.gif\'" ></a> ';
                    }
                }
            }
        }
        document.write(writeval);
        return
    }
}

function getMSN(MSN) {
    if (MSN == "") {
        return;
    }
    var list = new Array();
    list = MSN.toString().split("/");
    for (ii = 0; ii < list.length; ii++) {
        if (list[ii] != "") {
            document.writeln("<a href=\"msnim:chat?contact=" + list[ii] + "\"><img src=\"http://www.qooic.com/images/msn.gif\" border=\"0\" alt=\"MSN:" + list[ii] + "\"></a> ");
        }
    }
}

function Check(form) {
    if (form.xinghao.value == "") {
        alert("请填写您需要采购的型号！");
        form.xinghao.focus();
        return false;
    }
    if (!form.xinghao.value.IsPartNumber()) {
        alert("型号填写有误!");
        form.xinghao.focus();
        return false;
    }
    var re = /^[0-9]+.?[0-9]*$/;
    if (form.shuliang.value == "" || !re.test(form.shuliang.value)) {
        alert("请填写数量！");
        form.shuliang.focus();
        return false;
    }
    var reg = /^[^0-9｜\|\*※]{2,}$/;
    if (form.company.value.length < 2 || !reg.test(form.company.value)) {
        alert("请填写正确的公司名称或姓名！");
        form.company.focus();
        return false;
    }
    if (form.contact.value == "") {
        alert("请填写联系人！");
        form.contact.focus();
        return false;
    }
    if (form.tel.value == "") {
        alert("请填写联系电话！");
        form.tel.focus();
        return false;
    }
    if(!re.test(form.tel.value)){
        alert("请填写正确的电话");
        form.tel.focus();
        return false;
    }
    if (!form.mail.value.IsEmail()) {
        alert("请正确填写您的邮件地址！");
        form.mail.focus();
        return false;
    }
    if (!form.password.value.IsPassword()) {
        alert("请填写密码！(6-16个字符)");
        form.password.focus();
        return false;
    }
    if (form.password.value != form.rpassword.value) {
        alert("密码确认和密码不同！");
        form.rpassword.focus();
        return false;
    }
    
    

    if (!CheckComp(form.company.value)) {
        alert("此公司名称已经被注册，所以您不能再次注册，如有疑问请联系我们客服人员！");
        return false;
    }

    
    $.ajax({ url: "/check_username_ajax.asp?username=" + form.mail.value,
        async: false,
        success: function(data) {

            if (data == "Y") {
                alert("此邮箱帐号已经是我们会员,请更换邮箱注册！");
                return false;
            }

        }
    });
    return true;
}

function CheckCompany(form) {
    if (form.company.value.length >= 2) {

        if (!CheckComp(form.company.value)) {
            alert("此公司名称已经被注册，所以您不能再次注册，如有疑问请联系我们客服人员！");
            // form.company.focus();			  
        }


    }

}


function CheckComp(val) {
    if (val.length >= 2) {
        var judge = false;
        $.ajax({ url: "/ajax/check_username_ajax.asp?act=company&username=" + val,
            async: false,
            success: function(data) {
                if (data == "Y") {                    
                    judge = false;
                }
                else {
                    judge = true;
                }
            }

        });
        return judge;
    }
    else {
        return true;
    }

}

function CheckMail(val) {
    if (!val.value.IsEmail()) {
        alert("请正确填写您的邮件地址！");
        // val.focus();
        return false;
    }
    $.ajax({ url: "/ajax/check_username_ajax.asp?username=" + val.value,
        async: false,
        success: function(data) {
            if (data == "Y") {
                alert("此邮箱帐号已经是我们会员,请更换邮箱注册！");
                return false;
            }
        }
    });


}

function check(form) {
    if (form.keyword.value == '' || form.keyword.value == '请输入型号！' || !form.keyword.value.IsPartNumber()) {
        alert("请输入型号！");
        form.keyword.focus();
        return false;
    }
}
