function checklist(id){return typeof(id)=="string"?document.getElementById(id):id;}
function showDIVInfos(DIVID,color,msg){
	checklist(DIVID).innerHTML="<font color='"+color+"'>"+msg+"</font>";
      }
//Email验证
function checkemailp(val,divVal){
	if(val.length==0){
	   showDIVInfos(divVal,"red","请输入有效电子邮件");
	   return false;
	}
	if (val.length>0){
		var email =/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
		if (!email.test(val))
		{
			showDIVInfos(divVal,"red","请输入有效电子邮件");
			return false;
		}

	}
	showDIVInfos(divVal,"green","<b>√</b>");
	return true;
}



//姓名验证
function checkusernamep(val,unameDiv){
	 if (val.length==0||val.value==""){
		 showDIVInfos(unameDiv,"red","请输入您的姓名");
		 return false;
	 } else {
		var badChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
		badChar+="abcdefghijklmnopqrstuvwxyz"; 
		var feifa="0123456789"; 
		feifa += " "+"　";	//半角与全角空格
		feifa += "`~!@#$%^&()-_=+]\\|:;\"\\'<,>?/";	//不包含*或.的英文符号
		for(var i=0;i<val.length;i++) {
			var c = val.charAt(i);	//字符串str中的单个字符
			
			/* 不能输入非法字符 */
			if(feifa.indexOf(c) > -1){
				showDIVInfos(unameDiv,"red","请输入合法姓名");
				return false;
			}
			
			/* 全部为英文字符就当作是英文名处理，长度不能超过20个 */
			if(badChar.indexOf(c) > -1){
				if (val.length>20){
					showDIVInfos(unameDiv,"red","输入的英文名不能超过20个字符");
					return false;
				}
			} else {
				/* 否则，就当作是中文名处理，长度不能超过4个 */
				if (val.length>4){
					showDIVInfos(unameDiv,"red","输入的中文名不能超过4个字符");
					return false;
				}
			}
		}
	 }
	 showDIVInfos(unameDiv,"green","<b>√</b>");
	 return true;
}



function checkjobp(val,unameDiv){
	 if (val.length==0||val.value==""){
		 showDIVInfos(unameDiv,"red","请输入您的职业");
		 return false;
	 } else {
		var badChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
		badChar+="abcdefghijklmnopqrstuvwxyz"; 
		var feifa="0123456789"; 
		feifa += " "+"　";	//半角与全角空格
		feifa += "`~!@#$%^&()-_=+]\\|:;\"\\'<,>?/";	//不包含*或.的英文符号
		for(var i=0;i<val.length;i++) {
			var c = val.charAt(i);	//字符串str中的单个字符
			
			/* 不能输入非法字符 */
			if(feifa.indexOf(c) > -1){
				showDIVInfos(unameDiv,"red","请输入合法职业名称");
				return false;
			}
			
			/* 全部为英文字符就当作是英文名处理，长度不能超过20个 */
			if(badChar.indexOf(c) > -1){
				if (val.length>20){
					showDIVInfos(unameDiv,"red","输入的英文不能超过20个字符");
					return false;
				}
			} else {
				/* 否则，就当作是中文名处理，长度不能超过4个 */
				if (val.length>4){
					showDIVInfos(unameDiv,"red","输入的中文不能超过4个字符");
					return false;
				}
			}
		}
	 }
	 showDIVInfos(unameDiv,"green","<b>√</b>");
	 return true;
}


//收入验证
function shourucheckp(val,unameDiv){	//收入格式判断
  var valitem=/^(\d+\.\d+)|(\d+)$/;//只能输入数字
 if(val<0 || val>999999999){
  showDIVInfos(unameDiv,"red","收入范围：1-999999999元");
  return false;
 }else if(!valitem.test(val)){
  showDIVInfos(unameDiv,"red","请填写数字");
	 return false;
	 }
 else{
   showDIVInfos(unameDiv,"green","<b>√</b>");
   return true;
	 }
}


function checkTelephonp(val,teleDiV){//手机号判断
	var valitem=/^\d*$/;
	var valphone=/^((\(\d{3}\))|(\d{3}\-))?13\d{9}|15[89]\d{8}$/;
    if(!valitem.test(val)){
		showDIVInfos(teleDiV,"red","请填写数字");
		return false;
	} if(!valphone.test(val)){
		showDIVInfos(teleDiV,"red","手机号码格式不正确");
		return false;
	
     }
	showDIVInfos(teleDiV,"green","<b>√</b>");
	return true;
}



function agecheckp(val,ageDivVal){//年龄判断	
 var valitem=/^\d+$/;//正则数字判断
 if(!valitem.test(val)){
	showDIVInfos(ageDivVal,"red","请填写数字");
	return false;
	 }
 if(val<0 || val>100){
    showDIVInfos(ageDivVal,"red","年龄范围：0-100岁");
    return false;
   }
   showDIVInfos(ageDivVal,"red","");	 
   return true;
}


function checknullp(val,contentDiv){
if(val==null){
showDIVInfos(contentDiv,"red","内容不能为空");
		return false;
}
if(val.length==0){
showDIVInfos(contentDiv,"red","内容不能为空");
		return false;
}
showDIVInfos(contentDiv,"green","");
	return true;
}	

function checkAll(form){
var uname = document.getElementById("uname").value;
var utelte = document.getElementById("utele").value;
var ucontent =  document.getElementById("ucontent").value;
var uemail =  document.getElementById("uemail").value;
var boo=true;
if(!checkemailp(uemail,'emailDiv')){
boo=false;
}
if(!checkusernamep(uname,'unameDiv')){
boo=false;
}
if(!checkTelephonp(utelte,'teleDiV')){
boo=false;
}
if(!checknullp(ucontent,'contentDiv')){
boo=false;
}
if(boo){
form.submit();
}
}


function checkMyJar(userid,wangmenguserid){
	
	var juserid=document.getElementById("itemjarjaruserid").value;
	var jcontent=document.getElementById("itemjarjarcontent").value;
	
	if(userid==wangmenguserid){
		alert('不能收藏自己的网盟!');
		return;
	}
	
	if(juserid==null || juserid.length==0){
		alert("现在不能收藏");
		return;
	}
	if(jcontent==null || jcontent.length==0){
		alert("现在不能收藏");
		return;
	}
	 checkDoAddMyJar(juserid,jcontent)
}

//收藏操作
function checkDoAddMyJar(juserid,jcontent) {
	$.ajax({
	       type: "POST",
	       url: "/userInfo.do?method=doAddMyjar",
	       data: { "jarid": juserid, "jcontent": jcontent},
	       dataType: "text",
	       success: function(text){
	            if(text == "true"){
	            	alert("收藏成功");
	            } else if(text == "ziji") {
	            	alert("自己不能收藏自己的网盟");
	            }else if (text == "mydl"){
	           	  alert("请先登陆");
	            }else{
	            	alert("你已收藏过此网盟");
	            }
	        }
	    });
}



//登陆验证
function userLogin(){
   if(document.loginform.userId.value==""||document.loginform.userpsw.value==""){
    showDIVInfos("userDiv","red","用户名或密码不能为空");
   return false;
   }
}
//Email验证
function checkemail(val){
	if(val.length==0){
	   showDIVInfos("emailDIV","red","请输入有效电子邮件");
	   return false;
	}
	if (val.length>0){
		var email =/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
		if (!email.test(val))
		{
			showDIVInfos("emailDIV","red","请输入有效电子邮件");
			return false;
		}
		//检查邮箱地址是否唯一
		checkEmailIsExist(val);

	} else {
		showDIVInfos("emailDIV","green","");
	}
	return true;
}
//密码长度及一致验证
function checkLength(){
   if(document.register.pssword.value.length<6||document.register.pssword.value.length>14){
     showDIVInfos("passwordDIV","red","密码长度6-14位字符");
	 return false;
   }else{
  	 showDIVInfos("passwordDIV","green","<b>√</b>");
   }
  	 return true;
}
function pass_word(){
   if(document.register.pssword.value!=document.register.queren.value){
      showDIVInfos("passwordDIV1","red","两次密码不一致");
	  return false;
   }else if(document.register.queren.value==""){
   showDIVInfos("passwordDIV","red","密码不能为空");
     return false;
   }else{
   showDIVInfos("passwordDIV1","green","<b>√</b>");
   }
   return true;
}
//验证姓名
function checkusername(val){
	 if (val.length==0||val.value==""){
		 showDIVInfos("usernameDIV","red","请输入您的姓名");
		 return false;
	 } else {
		var badChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
		badChar+="abcdefghijklmnopqrstuvwxyz"; 
		var feifa="0123456789"; 
		feifa += " "+"　";	//半角与全角空格
		feifa += "`~!@#$%^&()-_=+]\\|:;\"\\'<,>?/";	//不包含*或.的英文符号
		for(var i=0;i<val.length;i++) {
			var c = val.charAt(i);	//字符串str中的单个字符
			
			/* 不能输入非法字符 */
			if(feifa.indexOf(c) > -1){
				showDIVInfos("usernameDIV","red","请输入合法姓名，不能带数字或标点符号等");
				return false;
			}
			
			/* 全部为英文字符就当作是英文名处理，长度不能超过20个 */
			if(badChar.indexOf(c) > -1){
				if (val.length>20){
					showDIVInfos("usernameDIV","red","输入的英文名不能超过20个字符");
					return false;
				}
			} else {
				/* 否则，就当作是中文名处理，长度不能超过4个 */
				if (val.length>4){
					showDIVInfos("usernameDIV","red","输入的中文名不能超过4个字符");
					return false;
				}
			}
		}
	 }
	 showDIVInfos("usernameDIV","green","<b>√</b>");
	 return true;
}
function checklose(divid){
	showDIVInfos(divid,"red","<b>Ｘ</b>");
}
function checksuss(divid){
	showDIVInfos(divid,"green","<b>√</b>");
}
function checkmingzhi(val){
	if(val.length==0||val.value==""){
		showDIVInfos("mingziDIV","red","用户昵称必须填写..");
		return false;
	}else{
		showDIVInfos("mingziDIV","green","<b>√</b>");
	}
		return true;
}

function checappcomplany(val){
	if(val.length==0||val.value==""){
		showDIVInfos("appcomplanyDIV1","red","所在公司必须填写..");
		return false;
	}else{
		showDIVInfos("appcomplanyDIV1","green","<b>√</b>");
	}
		return true;
}
function checmimaemail(val){
	if(val.length==0||val==""){
		 showDIVInfos("mimaemailDIV1","red","请填写邮件地址..");
		 return false;
	}
		return true;
}

function checusertel(val){
	
	if(val.length==0||val.value==""){
		showDIVInfos("usertelDIV1","red","联系电话必须填写..");
		return false;
	}else{
		showDIVInfos("usertelDIV1","green","<b>√</b>");
	}
		return true;
}

//验证整体
function checkregisterForm(){
	
	var username = document.getElementById("username");
	var email = document.getElementById("id");
	var mingzi = document.getElementById("mzi");
	var appcomplany = document.getElementById("appcomplany");
	var usertel = document.getElementById("usertel");
	var a2 = document.getElementById("a2");
	
	var selectedIndexp = -1;
	var selectedIndexc = -1;
	var pvic=document.getElementById("provinceId");
	var citys=document.getElementById("cityId");
	
	if (!checkemail(email.value)){
		checklose("emailDIV");
		return false;
	}else{
		checksuss("emailDIV");
	}
	if (!checkusername(username)){
		checklose("mingziDIV");
		return false;
	}else{
		checksuss("mingziDIV");
	}
	if(!checkLength()){
		return false;
	}
	if(!pass_word()){
		return false;
	}
	for (var i=1; i<pvic.length; i++){
        if (pvic[i].selected) {
          	selectedIndexp=2;
             break;
  }
}
	for (var i=1; i<citys.length; i++){
	        if (citys[i].selected) {
	          	selectedIndexc=2;
	             break;
	  }
	}
	if(selectedIndexp<0){
	   document.getElementById("privodiv").innerHTML = "请选择省份";
	   document.getElementById('privodiv').style.color = "red";
	   return false;
	}else{
	document.getElementById("privodiv").style.display="none";
	}
	if(selectedIndexc<0){
	   document.getElementById("cityiddiv").innerHTML = "请选择城市";
	   document.getElementById('cityiddiv').style.color = "red";
	return false;
	}else{
	document.getElementById("cityiddiv").style.display="none";
	}
	if(a2.checked){
		if(mingzi.length==0||mingzi.value==""){
			checklose("usernameDIV");
			return false;
		}else{
			checksuss("usernameDIV");
		}
		if(appcomplany.length==0||appcomplany.value==""){
			checklose("appcomplanyDIV1");
			return false;
		}else{
			checksuss("appcomplanyDIV1");
		}
		if(usertel.length==0||usertel.value==""){
			checklose("usertelDIV1");
			return false;
		}else{
			checksuss("usertelDIV1");
		}
	}
	return true;
}

function checkloginform(){
	var loginid = document.getElementById("loginid");
	var loginpass = document.getElementById("loginpass");
	if(!checloginid(loginid)){
		return false;
	}
	if(!checloginpass(loginpass)){
		return false;
	}
		return true;
}


function checkname(val){//真实姓名判断
var varlength=val.replace(/[^\x00-\xFF]/g,'**').length;//检查字符长度一个汉字等于两个字符
var valitem=/^[\u4e00-\u9fa5]+$/;//不包含英文及其他任何符号和数字
if(!valitem.test(val)){
showDIVInfos("cuname","red","请填写中文字符");
return false;
}else if(varlength<4 || varlength>8){
showDIVInfos("cuname","red","长度为2－4个汉字");
return false;
	}else{
showDIVInfos("cuname","green","");
return true;
	}
}
function checknicheng(val){//昵称验证
   var varlength=val.replace(/[^\x00-\xFF]/g,'**').length;
   if(varlength<4 || varlength>20){
    showDIVInfos("nichengid","red","长度4－20个字符，一个汉字为两个字符");
     return false;
	}else{
    showDIVInfos("nichengid","green","");
       return true;
	   }
	}
function shourucheck(){	//收入格式判断
 var shouru = checklist("demanddeincome").value;
  var valitem=/^\d+\.?\d+$/;//只能输入数字
 if(shouru<1 || shouru>999999999){
  showDIVInfos("shouru","red","收入范围：1-999999999元");
  return false;
 }else if(!valitem.test(shouru)){
  showDIVInfos("shouru","red","请填写数字");
	 return false;
	 }
 else{
   showDIVInfos("shouru","red","");	 
   return true;
	 }
}
function agecheck(){//年龄判断	
 var ages =checklist("ageNum").value;
 var valitem=/^\d+$/;//正则数字判断
 if(!valitem.test(ages)){
	showDIVInfos("agediv","red","请填写数字");
	return false;
	 }
 if(ages<0 || ages>100){
    showDIVInfos("agediv","red","年龄范围：0-100岁");
    return false;
   }
   showDIVInfos("agediv","red","");	 
   return true;
}
function checkTelephon(){//手机号判断
	var mobile=checklist("shouji").value;
	var valitem=/^\d*$/;
	var valphone=/^((\(\d{3}\))|(\d{3}\-))?13\d{9}|15[89]\d{8}$/;
    if(!valitem.test(mobile)){
		showDIVInfos("telep","red","请填写数字");
		return false;
	}else if(!valphone.test(mobile)){
		showDIVInfos("telep","red","手机号码格式不正确");
		return false;
		}else{
	    showDIVInfos("telep","red","");
		return true;
		}
	}
function checkyoubian(){//邮编验证
	var numyb=checklist("youbian").value;
	var valyb=/^[1-9]{1}[0-9]{5}$/;
	if(!valyb.test(numyb)){
	      showDIVInfos("youbianid","red","邮编格式不正确");
	      return false;
		}else{
		    showDIVInfos("youbianid","red","");	
		     return true;
			}
	}
function checnUpform(){
var ni_cheng=document.form1.nicheng.value;
var name_true = document.form1.nametrue.value;
var demand_deincome=document.form1.demanddeincome.value;
var age_Num=document.form1.ageNum.value;
var shou_ji=document.form1.shouji.value;
var you_bian=document.form1.youbian.value;
var boo=true;
if(!checkname(name_true)){
	boo=false;
}
if(!checknicheng(ni_cheng)){
	boo=false;
	}
if(!shourucheck()){
	boo=false;
	}	
if(!agecheck()){
	boo=false;
	}
if(!checkTelephon()){
	boo=false;
	}
if(!checkyoubian()){
	boo=false;
	}
	
if(boo){
document.form1.submit();
}
}


function checloginid(val){
	
	if(val.length==0||val.value==""){
		showDIVInfos("loginidDIV1","red","登陆必须填写");
		return false;
	}else if(!checkemail(val)){
		showDIVInfos("loginidDIV1","red","请输入有效的用户名");
		return false;
	}else{
	showDIVInfos("loginidDIV1","green","");
//		showDIVInfos("loginidDIV1","green","<b>√</b>");
	}
		return true;
}
function checloginpass(val){
	
	if(val.length==0||val.value==""){
		showDIVInfos("loginpassDIV1","red","登陆密码必须填写");
		return false;
	}else{
	showDIVInfos("loginpassDIV1","green","");
//		showDIVInfos("loginpassDIV1","green","<b>√</b>");
	}
		return true;
}


function age_check(){	
 var ages = checklist("demanddeage").value;
 var valitem=/^\d+$/;
  if(!valitem.test(ages)){
	    showDIVInfos("agediv","red","请填写数字");
	    return false;
  }
  if(ages<0 || ages>100){
        showDIVInfos("agediv","red","年龄范围：0-100岁");
        return false;
  } 
 showDIVInfos("agediv","red","");	 
 return true;  
}
//检查指定邮件地址是否己存在，存在为true，不存在为false
function checkEmailIsExist(val) {
	$.ajax({
	       type: "POST",
	       url: "/user.do?method=checkEmailisExist",
	       data: "email=" + val,
	       dataType: "text",
	       success: function(text){
	            if(text == "true"){
	            	showDIVInfos("emailDIV","red","该电子邮件地址己经注册");
	            } else {
	            	showDIVInfos("emailDIV","green","该电子邮件地址可用");
	            }
	        }
	    });
}






//提交验证登陆
function checkDoLogin() {
var username = document.loginform.loginid.value;
var paswd = document.loginform.loginpass.value;
var srand = document.loginform.yanzma.value;
	$.ajax({
	       type: "POST",
	       url: "/user.do?method=checkDoLogin",
	       data: { "username": username, "password": paswd,"sRand":srand },
	       dataType: "text",
	       success: function(text){
	            if(text == "false"){
	            	showDIVInfos("checklogin","red","验证码或密码错误");
	            } else {
	            	document.loginform.action="/userInfo.do?method=doLogKdunion";
					document.loginform.submit();
	            }
	        }
	    });
}



//提交验证登陆
function checkDoLoginKdunion() {
var username = document.loginform.loginid.value;
var paswd = document.loginform.loginpass.value;
var srand = document.loginform.yanzma.value;
	$.ajax({
	       type: "POST",
	       url: "/userInfo.do?method=checkDoLogin",
	       data: { "username": username, "password": paswd,"sRand":srand },
	       dataType: "text",
	       success: function(text){
	            if(text == "false"){
	            	showDIVInfos("checklogin","red","验证码或密码错误");
	            } else {
	            	login.hide();
	            	window.location.reload();
	            }
	        }
	    });
}



//动态检查文本长度
function checkTxtLength(which,maxChars,span_id) {
if (which.value.length > maxChars)
which.value = which.value.substring(0,maxChars);
var curr = maxChars - which.value.length;
document.getElementById(span_id).innerHTML = curr.toString();
}



function changeDiv(val){
var keyid=document.form1.elements["keyid"];
for (i=0; i<keyid.length; i++){
        if (keyid[i].checked)
         {
          	keyid[i].checked=false;
            
         }
}
if(val==1){
	document.getElementById("sbaoxian").style.display="block";
}else{
document.getElementById("sbaoxian").style.display="none";
}
if(val==2){
	document.getElementById("sjijin").style.display="block";
}else{
document.getElementById("sjijin").style.display="none";
}
if(val==3){
	document.getElementById("shuangjin").style.display="block";
}else{
document.getElementById("shuangjin").style.display="none";
}
if(val==4){
	document.getElementById("szhengjuan").style.display="block";
}else{
document.getElementById("szhengjuan").style.display="none";
}
if(val==5){
	document.getElementById("sqita").style.display="block";
}else{
document.getElementById("sqita").style.display="none";
}
}