/**************************************************************
*	主要功能：去除输入字符串变量左右两边包含的空格（功能同上）
*	输入参数：
*		x--字符串变量
*	返回值：
*		去除空格后的字符串变量
**************************************************************/
function Trim(x){
	x = x.replace (/\s/ig,'');
	return x;
}

function CheckMailExists()
{
        var e = document.all("email").value;
        if(e != "") {

            //if(!/(\S)+[@]{1}(\S)+[.]{1}(\w)+/.test(e)) 
            //{
                //alert("请输入格式正确的 Email 地址！");
                //document.all("email").value.focus();
				        //return false;
            //} 
            
			var emailPat =/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; 
            var matchArray=e.match(emailPat);
            if (matchArray==null) 
			{
                 //alert("请输入格式正确的 Email 地址！");
                 return false;
            }
            else 
            {
                //QuickRegisterBox.IsEMailExists(e, CheckExists_Callback);
				return true;
            }
        }
} 

function checkInfo()
{

	var loginName = document.all("loginName").value;
    if(loginName == null || Trim(loginName) == "")
    {
        alert( "注册用户名不能为空！");
		return false;
    }
	if(!/[a-zA-Z][a-zA-Z0-9_]{5,15}/.test(loginName)) 
    {
		alert( "请输入格式正确的注册用户名！");
		return false;
	}

    var password = document.all("password").value;
    var password2 = document.all("password2").value;
    if(password == null || Trim(password) == "")
    {
        alert( "密码不能为空！");
		return false;
    }
    if(password != password2)
    {
        alert( "两次输入的密码不同！");
		return false;
    }
    if(password.length < 5)
    {
        alert( "密码长度不能小于5！");
		return false;
    }

	var question = document.all("question").value;
	if(question == null || Trim(question) == "")
	{
		alert( "密码问题不能为空！");
		return false;
	}
	//if (getStringLength(question) > 40)
	//{
	//	return "密码问题不能超过40个字节（20个汉字）！";
	//}

	var answer = document.all("EncryptedAnswer").value;
	if(answer == null || Trim(answer) == "")
	{
		alert( "问题答案不能为空！");
		return false;
	}
	if(getStringLength(answer) > 40)
	{
		alert( "问题答案不能超过40个字节（20个汉字）！");
		return false;
	}

	var email = document.all("email").value;
	if(email == null || Trim(email) == "")
    {
        alert( "邮箱地址不能为空！");
		return false;
    }

	if(email != null&&Trim(email) != "")
	{
		if(getStringLength(email) > 100)
		{
			alert( "邮箱地址不能超过100个字符！");
			return false;
		}
		if (!CheckMailExists())
		{
		    alert( "邮箱格式不正确！");
		    return false;
		}
	}


/*var issudeYear = document.all("issudeYear").value;
if(issudeYear == null || Trim(issudeYear) == "")
{
	return "订阅年份不能为空！"
}

var userLevel = document.all("userLevel").value;
if(userLevel == null || Trim(userLevel) == "-1")
{
	return "会员级别不能为空！"
}

var issudeCnt = document.all("issudeCnt").value;
if(issudeCnt == null || Trim(issudeCnt) == "")
{
	 document.all("issudeCnt").value = "0" ;
}

var userProvince = document.all("userProvince").value;
if(userProvince == null || Trim(userProvince) == "-1")
{
	return "国家不能为空！"
}

var userArea = document.all("userArea").value;
if(userArea == null || Trim(userArea) == "-1")
{
	return "语言不能为空！"
}

var userAge = document.all("userAge").value;
if(userAge == null || Trim(userAge) == "-1")
{
	return "年龄不能为空！"
}

var userSex = document.all("userSex").value;
if(userSex == null || Trim(userSex) == "-1")
{
	return "性别不能为空！"
}

var userType = document.all("userType").value;
if(userType == null || Trim(userType) == "-1")
{
	return "行业不能为空！"
}*/
 
/*
var department = document.all("department").value;
if(department == null || Trim(department) == "-1")
{
	return "机构类型不能为空！"
}

var company = document.all("company").value;
if(company == null || Trim(company) == "")
{
	return "单位地址不能为空！";
}

var contactName = document.all("contactName").value;
if(contactName == null || Trim(contactName) == "")
{
	return "联系人不能为空！";
}

var address = document.all("address").value;
if(address == null || Trim(address) == "")
{
	return "通信地址不能为空！";
}
if(getStringLength(address) > 100)
{
	return "通信地址不能超过100个字节！";
}
*/
var postcode = document.all("postcode").value;
/*if(postcode == null || Trim(postcode) == "")
{
	return "邮政编码不能为空！";
}*/
if(getStringLength(postcode) > 6)
{
	alert( "邮政编码不能大于6位！");
	return false;
}
if(postcode != null && Trim(postcode) != ""){
    if (!/[0-9]\d{5}(?!\d)/.test(postcode)) {
	    alert( "邮政编码格式不正确！");
		return false;
    }
}
		
//var oTele = document.all("oTele").value;
/*if(oTele == null || Trim(oTele) == "")
{
	return "办公室电话不能为空！";
}*/
/* if (oTele!=null && Trim(oTele)!="" && !/\d+/.test(oTele)) {
	 return "办公室电话格式不正确！";
}
			
var fax = document.all("fax").value;
if (fax!=null && Trim(fax)!="" && !/\d+/.test(fax)) {
	return "传真格式不正确！";
}
			
var mobile = document.all("mobile").value;
if (mobile!=null && Trim(mobile)!="" && !/\d+/.test(mobile)) {
	return "手机格式不正确！";
}*/
    //加密密码
	document.all("password2").value = MD5(document.all("password").value);
	return true;
}


function submitForm()
{

    var flag = checkInfo();
    var myFace;
    if(flag == false)
    {
		//加密密码
		document.all("password2").value = MD5(document.all("password").value);
        //加密问题答案
        //document.all("EncryptedAnswer").value = MD5(document.all("answer").value);
        //document.theForm.submit();
		return true;
    }
    else
    {
        //alert(errMsg);
		return false;
    }
}

function checkExist(v)
{
    document.forms[1].loginName2.value = document.forms[0].loginName.value;

    if(document.forms[1].loginName2.value == null || Trim(document.forms[1].loginName2.value) == "")
    {
        alert("注册用户名不能为空！");
    }else if(!/[a-zA-Z][a-zA-Z0-9_]{5,15}/.test(document.forms[1].loginName2.value)) 
    {
		alert("请输入格式正确的注册用户名！");
	}
	else{
		document.forms[1].Email2.value = document.forms[0].email.value;
		//document.forms[1].UserNo2.value = document.forms[0].UserNo.value;
		document.forms[1].checktype.value = v;
		
		//alert(document.forms[1].checktype.value);
		var popupWin = window.open('', 'checkExistWindow', 'scrollbars=yes,width=500,height=300');
		document.forms[1].action = "regCheckExist.jsp";
		document.forms[1].submit();
	}
}
function checkExistMd(v)
{
	//alert(document.all.theForm.loginName.value);
    document.all.theForm.loginName2.value = document.all.theForm.loginName.value;
    document.all.theForm.Email2.value = document.all.theForm.email.value;
	//document.forms[1].UserNo2.value = document.forms[0].UserNo.value;
    document.all.theForm.checktype.value = v;
	if (v==1)
	{
		if ( document.all.theForm.loginName2.value ==  document.all.theForm.loginName3.value)
		{
			alert("没有修改用户名，不必检测！");
			return false;
			}
		
	}else
	{
				if ( document.all.theForm.Email2.value ==  document.all.theForm.Email3.value)
		{
			alert("没有修改电子邮件地址，不必检测！");
			return false;
			}	
	}
	//alert(document.forms[1].checktype.value);
    var popupWin = window.open('regCheckExist.jsp?loginName2='+document.all.theForm.loginName2.value+'&Email2='+document.all.theForm.Email2.value+'&checktype='+ document.all.theForm.checktype.value, 'checkExistWindow', 'scrollbars=yes,width=500,height=300');
     //document.all.theForm.action = "regCheckExist.jsp";
     //document.all.theForm.submit();
}

