﻿
function updateCheck()
{
     if (IfTextBoxEmpty( "tb_cp_name", "企业名称")) return false;
     if (!CheckInput( "tb_cp_name", "企业名称")) return false;
     if (IfTextBoxEmpty( "tb_cp_loginname", "企业登录名称")) return false; 
     if (!CheckUserName("tb_cp_loginname")) return false;
     if (IfTextBoxEmpty( "tb_cp_password", "企业登录密码")) return false;
     if (IfTextBoxEmpty( "tb_cp_password_2", "确认登录密码")) return false;
     if ($get("tb_cp_password").value != $get("tb_cp_password_2").value)
     {
        alert('密码输入不一致,请重新输入!')
        return false;
     }
     if (IfTextBoxEmpty( "tb_cp_address", "企业地址")) return false;
     if (!CheckInput("tb_cp_address", "企业地址")) return false;
     if (IfTextBoxEmpty( "tb_cp_email", "企业Email地址")) return false;
     if (!CheckEmail("tb_cp_email")) return false;
     if (IfTextBoxEmpty( "tb_cp_postcode", "邮编")) return false;
     if (!CheckZipCode("tb_cp_postcode")) return false;
     if (IfTextBoxEmpty( "tb_cp_phone", "企业电话")) return false;
     if (!CheckPhone("tb_cp_phone")) return false;      
     if (IfTextBoxEmpty( "tb_cp_fax", "企业传真")) return false;
     if (!CheckPhone("tb_cp_fax")) return false;
     if (IfTextBoxEmpty( "tb_cp_contact", "联系人")) return false;
     if (!CheckInput("tb_cp_contact", "联系人")) return false;
     if (IfTextBoxEmpty( "tb_cp_contact_phone", "联系人电话")) return false;
     if (!CheckPhone("tb_cp_contact_phone")) return false;
     
    return true;
}
function Reset()
{
    $get("tb_cp_name").value = "";
    $get("tb_cp_loginname").value = "";
    $get("tb_cp_password").value = "";
    $get("tb_cp_password_2").value = "";
    $get("ddl_cp_type").value = "";
    $get("ddl_cp_field").value = "";
    $get("tb_cp_address").value = "";
    $get("tb_cp_postcode").value = "";
    $get("tb_cp_phone").value = "";
    $get("tb_cp_fax").value = "";
    $get("tb_cp_contact").value = "";
    $get("tb_cp_contact_phone").value = "";
    $get("tb_cp_website").value = "";
    $get("tb_cp_email").value = "";
}

function CheckEmail(field)
{
    var e = document.getElementById(field);

    if(!/(\S)+[@]{1}(\S)+[.]{1}(\w)+/.test(e.value)) 
    {
        alert("请输入格式正确的 e-mail 地址！");
        e.focus();
        return false; 
    }
    return true;
}

function CheckUserName(field)   
{   
    var e = document.getElementById(field);
    var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;   
    if (!patrn.exec(e.value))
    {
        alert("无效的登录名称,请重新输入！");
        e.focus();
        return false;  
    }
    return true;  
} 

function CheckInput(field, name)
{
    var e = document.getElementById(field);
    var patrn=/^[^`~!@$%^*+=|\\\][\]\{\}:;'\,.<>/?]{1}[^`~!@$%^+=|\\\][\]\{\}:;'\,.<>?]{0,19}$/;   
    if (!patrn.exec(e.value))
    {
        alert("您输入的" + name + "中包含不允许使用的字符,请重新输入！");
        e.focus();
        return false;
    }
    return true  
}

function CheckPhone(field)   
{   
    var e = document.getElementById(field);  
    var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;   
    if (!patrn.exec(e.value))
    {
        alert("无效的电话/传真号码,请重新输入！");
        e.focus();
        return false;
    }  
    return true  
}  

function CheckZipCode(field)   
{   
    var e = document.getElementById(field);    
    var patrn=/^[a-zA-Z0-9 ]{3,12}$/;   
    if (!patrn.exec(e.value))
    {
        alert("无效的邮政编码,请重新输入！");
        e.focus();
        return false;
    }  
    return true  
}   
 



