function check(theForm) {
    theForm.name.value = theForm.name.value.trim();
    if(theForm.name.value.length==0) {
        alert("请输入您的姓名！");
        theForm.name.focus();
        return false;
    }
    theForm.email.value = theForm.email.value.trim();
    
    
    if(theForm.email.value.length!=0) {
        if (!isEmail(theForm.email.value))  {
            alert("Email格式不正确！");
            theForm.email.focus();
            return false;
        }
    }
    else {
        alert("请提供Email地址！");
        theForm.email.focus();
        return false;
    }
    
    theForm.phone.value = theForm.phone.value.trim();
    if(theForm.phone.value.length!=0) {
        if (!isTel(theForm.phone.value))  {
            alert("电话号码不正确！");
            theForm.phone.focus();
            return false;
        }
    }
    theForm.address.value = theForm.address.value.trim();
    theForm.postcode.value = theForm.postcode.value.trim();
           
    if(theForm.postcode.value.length!=0) {
        if (!isPostalCode(theForm.postcode.value))  {
            alert("邮政编码不正确！");
            theForm.postcode.focus();
            return false;
        }    
    }     
    theForm.title.value = theForm.title.value.trim();
    if(theForm.title.value.length==0) {
        alert("请输入标题！");
        theForm.title.focus();
        return false;
    }
    if(theForm.content.value.length==0) {
        alert("请输入内容！");
        theForm.content.focus();
        return false;
    }
    theForm.action = "/mail/";
}

//校验e-mail
function isEmail(s) {
    if (s.charAt(0)=="." || s.charAt(0)=="@"|| s.indexOf('@', 0)==-1 || s.indexOf('.', 0)==-1 || s.lastIndexOf("@")==s.length-1 || s.lastIndexOf(".")==s.length-1 )
        return false
    else
        return true
}

//校验普通电话、传真号码：可以“+”开头，除数字外，可含有“-” 
function isTel(s) 
{ 
var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){7,12})+$/;
if (!patrn.exec(s)) return false 
return true 
} 

//校验邮政编码 
function isPostalCode(s) 
{ 
var patrn=/^[0-9]{6,6}$/;
if (!patrn.exec(s)) return false 
return true 
} 

//去除多余空格函数
// trim:去除两边空格 lTrim:去除左空格 rTrim: 去除右空格
// 用法：
String.prototype.trim = function()
{
    return this.replace(/(^[\s]*)|([\s]*$)/g, "");
}
String.prototype.lTrim = function()
{
    return this.replace(/(^[\s]*)/g, "");
}
String.prototype.rTrim = function()
{
    return this.replace(/([\s]*$)/g, "");
}

