// --- 获取ClassName
document.getElementsByClassName = function(cl) {
    var retnode = [];
    var myclass = new RegExp('\\b'+cl+'\\b');
    var elem = this.getElementsByTagName('*');
    for (var i = 0; i < elem.length; i++) {
        var classes = elem[i].className;
        if (myclass.test(classes)) retnode.push(elem[i]);
    }
    return retnode;
}
//初始化
function init()
{
    try {
        ReSizeImg("product_img2",104,79); //调整产品缩略图大小
        time_rota();
        if(document.getElementById("Main_table")){
            var MH=document.getElementById("Main_table").clientHeight;
            var LH=document.getElementById("Left_table").clientHeight;
            if (MH>LH){
                if(document.getElementById("Left_bottom")){
                    document.getElementById("Left_bottom").style.display='';
                    document.getElementById("Left_bottom").style.height=(MH-LH-15)+'px';
                }
            }
        }
        var dimgs=document.getElementsByClassName("product_img3");
        ReSizeImg("product_img3",106,106);
        for (var i=0;i<dimgs.length;i++) {
            dimgs[i].onmouseover = function() {
                this.width = this.width+3;
                this.height = this.height+3;
            }
            dimgs[i].onmouseout = function() {
                this.width = this.width-3;
                this.height = this.height-3;
            }
        }
  }
  catch(e){}
}
//动态时间
function time_rota()
{
    now = new Date();
    var y=now.getYear();
    var m=now.getMonth();
    var d=now.getDate();
    var h=now.getHours();
    var i=now.getMinutes();
    var s=now.getSeconds();
    document.getElementById("Time").innerHTML = y+"年"+m+"月"+d+"日 "+h+":"+i+":"+s;
    setTimeout( 'time_rota()', 1000)
}
//URL跳转
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
// --- 自动缩放图片大小
function ReSizeImg(cName,w,h){
    var reImgs = document.getElementsByTagName("img");
    for (i=0;i<reImgs.length;i++){
        if (reImgs[i].className==cName && (reImgs[i].height>h || reImgs[i].width>w)) {
            if (reImgs[i].height==reImgs[i].width) {
                reImgs[i].height=h;reImgs[i].width=w;
            } else if (reImgs[i].height>reImgs[i].width) {
                reImgs[i].height=h;
            } else if (reImgs[i].height<reImgs[i].width){
                reImgs[i].width=w;
            }
        }
    }
}
//检测登陆表单
function checkLoginForm(obj){
    if(obj.username.value==''){
        alert('请输入您的用户名');
        obj.username.focus();
        return false;
    }
    if(obj.password.value==''){
        alert('请输入您的密码');
        obj.password.focus();
        return false;
    }
}
//检测搜索表单
function checkSearchForm(obj){
    if(obj.search_key.value==''){
        alert('请输入搜索关键字');
        obj.search_key.focus();
        return false;
    }
}
//检测邮箱登陆表单
function checkMail_LoginForm(obj){
    if(obj.user.value==''){
        alert('请输入您的用户名');
        obj.user.focus();
        return false;
    }
    if(obj.pass.value==''){
        alert('请输入您的密码');
        obj.pass.focus();
        return false;
    }
}
//检测用户注册表单
function checkRegFrom(obj){
    if (obj.Company_CN.value.length<4 && obj.Company_EN.value.length<4){
        alert("公司名称不能为空或长度必须大于4个字符!");
        obj.Company_CN.focus();
        return false;
    }
    if (obj.UserName.value.length<4){
        alert("用户名不能为空或长度必须大于4个字符!");
        obj.UserName.focus();
        return false;
    }
    if (obj.Password.value.length<5){
        alert("密码不能为空或必须大于6个字符!");
        obj.Password.focus();
        return false;
    }
    if (obj.PwdConfirm.value != obj.Password.value){
        alert("两次输入的密码不一致!");
        obj.PwdConfirm.focus();
        return false;
    }
    if (obj.Question.value.length<6){
        alert("密码问题不能为空或大于6个字符!");
        obj.Question.focus();
        return false;
    }
    if (obj.Answer.value.length<4){
        alert("密码问题答案不能为空或大于4个字符!");
        obj.Answer.focus();
        return false;
    }
    if (obj.Email.value.length<1 || !IsMail(obj.Email.value)){
        alert("请输入有效的E-Mail地址!");
        obj.Email.focus();
        return false;
    }
    if (obj.Country_CN.value.length<1 && obj.Country_EN.value.length<1){
        alert("请输入国家名称!");
        obj.Country_CN.focus();
        return false;
    }
    if (obj.Province.value.length<1 && obj.Pro_City.value.length<1){
        alert("请选择省份名称!");
        obj.Province.focus();
        return false;
    }
    if (obj.City.value.length<1 && obj.Pro_City.value.length<1){
        alert("请选择城市名称!");
        obj.City.focus();
        return false;
    }
    if (obj.Address_CN.value.length<10 && obj.Address_EN.value.length<10){
        alert("请输入详细的联系地址!");
        obj.Address_CN.focus();
        return false;
    }
    if (obj.Somane.value.length<1){
        alert("请输入联系人!");
        obj.Somane.focus();
        return false;
    }
    if (obj.Zip.value.length<6 || isNaN(obj.Zip.value)){
        alert("请输入有效的邮政编码!");
        obj.Zip.focus();
        return false;
    }
    if (obj.Phone1.value.length<2){
        alert("请输入国家区位!");
        obj.Phone1.focus();
        return false;
    }
    if (obj.Phone2.value.length<3 || isNaN(obj.Phone2.value)){
        alert("请输入区号!");
        obj.Phone2.focus();
        return false;
    }
    if (obj.Phone3.value.length<6 || isNaN(obj.Phone3.value)){
        alert("请输入电话号码!");
        obj.Phone3.focus();
        return false;
    }
    if (isNaN(obj.Phone4.value)){
        alert("请输入正确的分机号!");
        obj.Phone4.focus();
        return false;
    }
    if (obj.Fax1.value.length<2){
        alert("请输入国家区位!");
        obj.Fax1.focus();
        return false;
    }
    if (isNaN(obj.Fax2.value)){
        alert("请输入正确的区号!");
        obj.Fax2.focus();
        return false;
    }
    if (isNaN(obj.Fax3.value)){
        alert("请输入正确的传真号码!");
        obj.Fax3.focus();
        return false;
    }
}
//检测修改用户信息表单
function checkChangeInfo(obj){
    if (obj.Company_CN.value.length<4 && obj.Company_EN.value.length<4){
        alert("公司名称不能为空或长度必须大于4个字符!");
        obj.Company_CN.focus();
        return false;
    }
    if (obj.Password.value.length<5 && obj.Password.value.length>1 ){
        alert("密码不能为空或必须大于6个字符!");
        obj.Password.focus();
        return false;
    }
    if (obj.PwdConfirm.value != obj.Password.value){
        alert("两次输入的密码不一致!");
        obj.PwdConfirm.focus();
        return false;
    }
    if (obj.Question.value.length<6){
        alert("密码问题不能为空或大于6个字符!");
        obj.Question.focus();
        return false;
    }
    if (obj.Answer.value.length<4){
        alert("密码问题答案不能为空或大于4个字符!");
        obj.Answer.focus();
        return false;
    }
    if (obj.Somane.value.length<1){
        alert("请输入联系人!");
        obj.Somane.focus();
        return false;
    }
    if (obj.Email.value.length<1 || !IsMail(obj.Email.value)){
        alert("请输入有效的E-Mail地址!");
        obj.Email.focus();
        return false;
    }
    if (obj.Country_CN.value.length<1 && obj.Country_EN.value.length<1){
        alert("请输入国家名称!");
        obj.Country_CN.focus();
        return false;
    }
    if (obj.Province.value.length<1 && obj.Pro_City.value.length<1){
        alert("请选择省份名称!");
        obj.Province.focus();
        return false;
    }
    if (obj.City.value.length<1 && obj.Pro_City.value.length<1){
        alert("请选择城市名称!");
        obj.City.focus();
        return false;
    }
    if (obj.Address_CN.value.length<10 && obj.Address_EN.value.length<10){
        alert("请输入详细的联系地址!");
        obj.Address_CN.focus();
        return false;
    }
    if (obj.Zip.value.length<6 || isNaN(obj.Zip.value)){
        alert("请输入有效的邮政编码!");
        obj.Zip.focus();
        return false;
    }
    if (obj.Phone1.value.length<2){
        alert("请输入国家区位!");
        obj.Phone1.focus();
        return false;
    }
    if (obj.Phone2.value.length<3 || isNaN(obj.Phone2.value)){
        alert("请输入区号!");
        obj.Phone2.focus();
        return false;
    }
    if (obj.Phone3.value.length<6 || isNaN(obj.Phone3.value)){
        alert("请输入电话号码!");
        obj.Phone3.focus();
        return false;
    }
    if (isNaN(obj.Phone4.value)){
        alert("请输入正确的分机号!");
        obj.Phone4.focus();
        return false;
    }
    if (obj.Fax1.value.length<2){
        alert("请输入国家区位!");
        obj.Fax1.focus();
        return false;
    }
    if (isNaN(obj.Fax2.value)){
        alert("请输入正确的区号!");
        obj.Fax2.focus();
        return false;
    }
    if (isNaN(obj.Fax3.value)){
        alert("请输入正确的传真号码!");
        obj.Fax3.focus();
        return false;
    }
}
//检测订单步骤1
function checkFormStep1(obj){
    if (obj.Comane.value.length<4){
        alert("请输入公司名称!");
        obj.Comane.focus();
        return false;
    }
    if (obj.Somane.value.length<4){
        alert("请输入收货人名称!");
        obj.Somane.focus();
        return false;
    }
    if (obj.Add.value.length<10){
        alert("请输入详细的收货地址!");
        obj.Add.focus();
        return false;
    }
    if (obj.Zip.value.length<6 || isNaN(obj.Zip.value)){
        alert("请输入有效的邮政编码!");
        obj.Zip.focus();
        return false;
    }
    if (obj.Phone.value.length<6){
        alert("请输入有效的联系电话!");
        obj.Phone.focus();
        return false;
    }
    if (obj.Email.value.length<1 || !IsMail(obj.Email.value)){
        alert("请输入有效的E-Mail地址!");
        obj.Email.focus();
        return false;
    }
}
//打开订购窗口
function openShopWindow(p_id){
    window.open("e_shop.asp?p_id="+p_id+"&action=joinBag","","height=400,width=640,left=200,top=0,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
//
function openOrderWin(o_id){
window.open("changeOrderStatus.asp?id="+o_id,"","height=121,width=300,resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no");
}
//openViewOrderWin
function openViewOrderWin(o_id){
    window.open("vieworder.asp?id="+o_id,"","height=400,width=615,resizable=no,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
//是否为正确的Email地址
function IsMail(mail)
{
    var patrn = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    if (!patrn.test(mail))
        return false;
    else
        return true;
}