//验证邮编
// style="border-color: red"
function checkPostNumber(postId,showId)
{
	var obj=document.getElementById(postId);
	var postNumber=obj.value;
	var showobj=document.getElementById(showId);
	if(postNumber.length==0)
	{
		obj.style.borderColor="red";
		showobj.innerHTML="<font color='red'>邮政编码不能为空</font>";
		return;
	}else if(postNumber.length!=6)
	{
		showobj.innerHTML="<font color='red'>邮政编码的长度不对</font>";
		obj.style.borderColor="red";
		return;
	}else if(isNaN(postNumber))
	{
		showobj.innerHTML="<font color='red'>邮政编码只能是数字</font>";
		obj.style.borderColor="red";
		return;
	}
	obj.style.borderColor="#dddddd";
	showobj.innerHTML="";
}

//验证ＱＱ号
function checkQQ(qqid,showId)
{
	var obj=document.getElementById(qqid);
	var qq=obj.value;
	var showobj=document.getElementById(showId);
	if(qq.length==0)
	{
		obj.style.borderColor="red";
		showobj.innerHTML="<font color='red'>QQ号码不能为空</font>";
		return;
	}
	else if(qq.length>=11)
	{
		obj.style.borderColor="red";
		showobj.innerHTML="<font color='red'>QQ号码的长度不对</font>";
		return;
	}
	else if(isNaN(qq))
	{
		obj.style.borderColor="red";
		showobj.innerHTML="<font color='red'>QQ号码格式不正确</font>";
		return;
	}
	obj.style.borderColor="#DDDDDD";
	showobj.innerHTML="";
}

//电话号码验证
function checkPhone(phoneId,showId)
{
	var showObject=document.getElementById(showId);
	var obj=document.getElementById(phoneId);
	var pno=obj.value;
	if(pno.length!=7 && pno.length!=8 && pno.length!=11 && pno.length!=12 && pno.length!=13)
	{
		obj.style.borderColor="red";
		showObject.innerHTML="<font color='red'>电话号码无效，正确的格式：[xxx-]nnnnnnn</font>"; 
		return;
	}
	else if (pno.match(/^\d+-\d+$/) || pno.match(/^\d+$/))
	{ 
		obj.style.borderColor="#DDDDDD";
		showObject.innerHTML="<font color='green'>电话号码格式正确</font>";
		return;
	}
	else
	{
		obj.style.borderColor="red";
		showObject.innerHTML="<font color='red'>电话号码无效，正确的格式：[xxx-]nnnnnnn</font>"; 
		return;
	}
	obj.style.borderColor="#DDDDDD";
	showObject.innerHTML="";
}
//邮箱验证
function isEmail(email,showId) {
	var showObject=document.getElementById(showId);
	var obj=document.getElementById(email);
	var strEmail=obj.value; 
	if(strEmail.length==0)
	{
		obj.style.borderColor="red";
		showObject.innerHTML="<font color='red'>邮箱不能为空！！</font>";
		return;
	}
	else if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
		obj.style.borderColor="#DDDDDD";
		showObject.innerHTML="<font color='green'>邮箱格式正确！！</font>";
		return;
		}
	else{
		obj.style.borderColor="red";
		showObject.innerHTML="<font color='red'>邮箱格式错误！！</font>";
		return;
		}
		obj.style.borderColor="#DDDDDD";
}
//验证确认密码
function checkPwdOK(pwd1,pwd2,showId)
{
	var obj1=document.getElementById(pwd1);
	var pwd1Value=obj1.value
	var obj2=document.getElementById(pwd2);
	var pwd2Value=obj2.value
	var showObject=document.getElementById(showId);
	if(pwd1Value!=pwd2Value)
	{
		obj1.style.borderColor="red";
		obj2.style.borderColor="red";
		showObject.innerHTML="<font color='red'>两次输入密码不一样</font>";
		return;
	}
	checkLength(pwd2,showId,6,15);
}

//验证密码
function checkPwd(objId,showId)
{
	checkLength(objId,showId,'6','15');
}
//验证用户名
function checkUserNameRegPage(objId,showId)
{
	var uservalue=document.getElementById(objId).value;
	var showojb=document.getElementById(showId);
	checkreg(objId,showId);
	f_check_ZhOrNumOrLett(uservalue,showojb);
	checkLength(objId,showId,'0','15');		
}
//验证长度在哪一个范围之中
function checkLength(objId,showId,minlength,maxlength)
{
	var showObj=document.getElementById(showId);
	var object=document.getElementById(objId);	
		if(object.value.length==0)
		{
			object.style.borderColor="red";
			showObj.innerHTML="<font color='red'>不能为空</font>";
			return;
		}else{
			if(minlength!=0){
				if(object.value.length<minlength)
				{
					object.style.borderColor="red";
					showObj.innerHTML="<font color='red'>长度必须大于"+minlength+"位</font>";
					return;
				}
			}
			if(object.value.length>maxlength)
			{
				object.style.borderColor="red";
				showObj.innerHTML="<font color='red'>长度必须小于"+maxlength+"位</font>";
				return;
			}
		}
		object.style.borderColor="#DDDDDD";
	showObj.innerHTML="";
}
//验证身份证号
function checkIDNumber(objValue,showId)
{
	var number=document.getElementById(objValue);
	var show=document.getElementById(showId);
	
	if(number.value.length==0)
	{
		number.style.borderColor="red";
		show.innerHTML="<font color='red'>身份证号必须填写</font>";
		return;
	}else if(number.value.length!=15 && number.value.length!=18)
	{
		number.style.borderColor="red";
		show.innerHTML="<font color='red'>身份证号长度必须等于15位或者等于18位</font>";
		return;
	}
	else
	{
		test(number,number,show);
	}
	//show.innerHTML="";
	//number.style.borderColor="#DDDDDD";
}
//身份证全法性验证
function test(card,obj,showobj){
	var n;
	 
	if(/^\d{15}$/.test(card.value)) n = /^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d{3})$/.exec(card.value);
	if(/^\d{17}(\d|x|X)$/.test(card.value)) n = /^(\d\d)(\d\d)(\d\d)(\d{4})(\d\d)(\d\d)(\d{3})(\d|x|X)$/.exec(card.value);
	if(!n){
		obj.style.borderColor="red";
		//alert('没有正确输入');
		showobj.innerHTML="<font color='red'>没有正确输入</font>";
		return;
		}
		else
		{
			doPost(showobj.id, 'login.do?op=checkUserCoard&userid='+card.value, false);
			obj.style.borderColor="#DDDDDD";
		}
}
//验证是否有汉字
function f_check_ZhOrNumOrLett(str,showObj){    //判断是否是汉字组成 
	var obj=str.replace(/(.)(?=[^$])/g,"$1,").split(",");
	var regu = "^[\u4e00-\u9fa5]+$";      
	var re = new RegExp(regu); 
	var bool=false;
	for(var i=0;i<obj.length;i++)
	{		 
	  
    	bool=false;
	}
	if(!bool){
		showObj.innerHTML="<font color='green'>用户名格式输入正确</font>";
	}
	else if(bool){
		return;
	}
}  
//验证是否为空
function checkreg(objid,showid)
{
	var showObj=document.getElementById(showid);
	var object=document.getElementById(objid);
	if(object.value==""){
	object.style.borderColor="red";
		showObj.innerHTML="<font color='red'>不能为空！！！</font>";
		return;
	}
}
//验证用户名是否存在
function checkRegUserName(showid,userName)
{
	//doSubmit(formId,showId);
	var object=document.getElementById(userName);
	var showObj=document.getElementById(showid);
	f_check_ZhOrNumOrLett(object.value,showObj);
	doPost(showid, 'login.do?op=checkUserName&userName='+object.value, false);
}
//清空提示信息
function checkname(showId1)
{
	var showObj1=document.getElementById(showId1);
	showObj1.innerHTML="";
}
//更换验证码
function getimgcode()
        {        	
             var getimagecode = document.getElementById("divImg");
             getimagecode.innerHTML = "<img src=\"image.jsp\" alt=\"点击刷新验证码\" onclick=\"getimgcode();\"/>";
        }
        
//登录验证
        function checkform(formname)
        {
        	var username=document.getElementById("username").value;
        	var password=document.getElementById("password").value;
        	var checknumber=document.getElementById("checkNumber").value; 
        	if(username=="")
        	{
        		alert("请输入用户名！");
        		getimgcode();
        		document.getElementById("username").focus();
        		return;
        	}
        	else if(password=="")
        	{
        		alert("请输入密码！");
        		getimgcode();
        		document.getElementById("password").focus();
        		return;
        	}
        	else if(checknumber=="")
        	{
        		alert("请输入验证码！");
        		getimgcode();
        		document.getElementById("checkNumber").focus();
        		return;
        	}
        	else
        	{
        		document.getElementById(formname).submit();
        	}
        }
