/**
	普通用户注册验证
*/
function checkCommon(){
	try{
		var email=$("#email").val();
		var password=$("#password").val();
		var username=$("#username").val();
		var linktel=$("#linktel").val();
		var seccodeverify=$("#seccodeverify").val();
		var flg=true;		
		if(typeof(email)=='undefined' || $.trim(email).length<=0 || $.trim(email).length>50 || !checkMailUtil(email)){				
				$("#emailInfoId").html("请输入正确的邮箱地址。");
				$("#emailInfoId").css("color","red");
				flg=false;
		}
				
		if(typeof(password)=='undefined' || $.trim(password).length<6){
				$("#passwordInfo").css("color","red");
				flg=false;
		}
		
		
		if(typeof(username)=='undefined' || $.trim(username).length<2 || $.trim(username).length>12){
				$("#usernameInfo").html("请输入2-12个字符(包括英文字母、数字及其组合)的用户名");
				$("#usernameInfo").css("color","red");
				flg=false;
		}

		if(!isStrNumber(username)){
			   $("#usernameInfo").html("请输入2-12个字符(包括英文字母、数字及其组合)的用户名");
			   $("#usernameInfo").css("color","red");
			   flg=false;
		}
			
		
		if(typeof(linktel)=='undefined' || !isMobilePhone(linktel)){
			$("#linktelInfoId").html("请输入正确格式的手机号码。");
			$("#linktelInfoId").css("color","red");
			flg=false;
		}

       if(typeof(seccodeverify)=='undefined' || $.trim(seccodeverify).length!=4){
				$("#seccodeverifyInfo").html("请输入校验码。");
				$("#seccodeverifyInfo").css("color","red");
				flg=false;
			}
			else{
				$("#seccodeverifyInfo").html("");
		}

		if($("#acceptid:checked").length!=1){
				alert("阅读并接受《用户服务协议》才能继续操作。");
				flg=false;
			}
		
		return flg;
	}
	catch(e){
		alert(e.message);
		return false;
	}
}

/**
	功能说明： 验证用户名是否已经存在
*/
function isExistUserName(userNamePar){
	var username=userNamePar;
	if(typeof(username)=='undefined' || $.trim(username).length<=0){
		 $("#usernameInfo").html("请输入2-12个字符(包括英文字母、数字及其组合)的用户名");
		 $("#usernameInfo").css("color","red");		  		
		 return;	
	}
	if(typeof(username)=='undefined' || $.trim(username).length<2 || $.trim(username).length>12 || !isStrNumber(username)){
		        $('#usernameInfo').html("请输入2-12个字符(包括英文字母、数字及其组合)的用户名");
		        $("#usernameInfo").css("color","red");				
				return;
		}
	
	$.ajax({
		  	type:"POST",
		    dataType:"json",
		    url:_rootPath+"/v1/member/ajaxUserName",
		    data:{username:username},
		    success:isExistUserNameCallback 
		  });
 }
function isExistUserNameCallback(msg){
	var data=msg;	
	$("#usernameInfo").html(data.infoStr);
	if(data.infoNo=="1"){
	     $("#usernameInfo").css("color","red");
		 $("#username").focus();
	}
	else if(data.infoNo=="0")
	    $("#usernameInfo").css("color","green");
		
} 
/**
	功能说明： ajax验证邮箱地址是否已经存在
*/
function isExistEmail(emailPar){
	var email=emailPar;
	if(typeof(email)=='undefined' || $.trim(email).length<=0){
		return;	
	}
	if(typeof(email)=='undefined' || $.trim(email).length<=0 || $.trim(email).length>50 || !checkMailUtil(email)){				
				$("#emailInfoId").html("请输入正确的邮箱地址。");
				$("#emailInfoId").css("color","red");
				$("#email").focus();
				return;
	 }


	$.ajax({
		  	type:"POST",
		    dataType:"json",
		    url:_rootPath+"/v1/member/ajaxEmail",
		    data:{email:email},
		    success:isExistEmailCallback 
		  });
 }
function isExistEmailCallback(msg){
	var data=msg;	
	$("#emailInfoId").html(data.infoStr);
	if(data.infoNo=="1"){
	     $("#emailInfoId").css("color","red");
		 $("#email").focus();
	}
	else if(data.infoNo=="0")
	    $("#emailInfoId").css("color","green");
		
} 
/**
	功能说明：ajax验证手机号码是否已经存在
*/
function isExistLinktel(linktelPar){
	var linktel=linktelPar;
	if(typeof(linktel)=='undefined' || $.trim(linktel).length<=0){
		return;	
	}
	
	if(typeof(linktel)=='undefined' || !isMobilePhone(linktel)){
			$("#linktelInfoId").html("请输入正确格式的手机号码。");
			$("#linktelInfoId").css("color","red");
			$("#linktel").focus();
			return;
	}
	
	$.ajax({
		  	type:"POST",
		    dataType:"json",
		    url:_rootPath+"/v1/member/ajaxLinktel",
		    data:{linktel:linktel},
		    success:isExistLinktelCallback 
		  });
 }
function isExistLinktelCallback(msg){
	var data=msg;	
	$("#linktelInfoId").html(data.infoStr);
	if(data.infoNo=="1"){
	     $("#linktelInfoId").css("color","red");
		 $("#linktel").focus();
	}
	else if(data.infoNo=="0")
	    $("#linktelInfoId").css("color","green");
		
} 
/***************************************经纪人注册模块****************************/
/**
	功能说明: 经纪人注册js验证
*/
function checkAgentReg(){
    try{	
			var username=$("#username").val();
			var password=$("#password").val();
			var password2=$("#password2").val();
			var email=$("#email").val();
			var realname=$("#realname").val();
			var cityid=$("#cityid").val();
			var areaid=$("#areaid").val();
			var placeid=$("#placeid").val();
			var companyid=$("#companyid").val();
			var linktel=$("#linktel").val();
			var phone=$("#phone").val();
			var seccodeverify=$("#seccodeverify").val();
			
			var flg=true;
			if(typeof(username)=='undefined' || $.trim(username).length<2 || $.trim(username).length>12){
					$("#usernameInfo").html("请输入2-12个字符(包括英文字母、数字及其组合)的用户名");
					$("#usernameInfo").css("color","red");
					flg=false;
			}
			else if(!isStrNumber(username)){
				   $("#usernameInfo").html("请输入2-12个字符(包括英文字母、数字及其组合)的用户名");
				   $("#usernameInfo").css("color","red");
				   flg=false;
		    }
			else{
				$("#usernameInfo").html("");
			}
			
			if(typeof(password)=='undefined' || $.trim(password).length<6){
					$("#passwordInfo").html("6-16个字符，英文字母加数字或符号的组合密码。");
					$("#passwordInfo").css("color","red");
					flg=false;
			}
			else{
					$("#passwordInfo").html("");
			}
		
			if(typeof(password2)=='undefined' || $.trim(password2).length<6){
					$("#password2Info").html("请再输入一遍您的密码。");
					$("#password2Info").css("color","red");
					flg=false;
			}
			else{
					$("#password2Info").html("");
			}

			if($.trim(password)!=$.trim(password2)){
				$("#password2Info").html("两次输入的密码不一致。");
				$("#password2Info").css("color","red");
                $("#password").val("");
				$("#password2").val("");
				flg=false;
			}
			else{
				$("#password2Info").html("");
			}
		
			if(typeof(email)=='undefined' || $.trim(email).length<=0 || $.trim(email).length>50 || !checkMailUtil(email)){				
					$("#emailInfoId").html("请输入正确的邮箱地址。");
					$("#emailInfoId").css("color","red");
					flg=false;
			}
			else{
				   $("#emailInfoId").html("");
			}
					
			if(typeof(realname)=='undefined' || $.trim(realname).length<2 || $.trim(realname)>8){
					$("#realnameInfo").html("请填写身份证上的真实姓名，否则无法通过验证。");
					$("#realnameInfo").css("color","red");
					flg=false;
			}
			else{
				    $("#realnameInfo").html("");
			}
			
			if(typeof(cityid)=='undefined' || parseInt(cityid)<=0){
				   $("#cityidInfo").html("请选择所属城市。");
				   $("#cityidInfo").css("color","red");
				   flg=false;
			}
			else{
				$("#cityidInfo").html("");
			}
			
			if(typeof(areaid)=='undefined' || parseInt(areaid)<=0){
				   $("#areaidInfo").html("请选择所在区。");
				   $("#areaidInfo").css("color","red");
				   flg=false;
			}
			else if(typeof(placeid)=='undefined' || parseInt(placeid)<=0){
				   $("#areaidInfo").html("请选择所属片区。");
				   $("#areaidInfo").css("color","red");
				   flg=false;
			}
			else{
				    $("#areaidInfo").html("");
			}

			if(typeof(companyid)=='undefined' || parseInt(companyid)<=0){
				   $("#companyidInfo").html("请选择所属公司。");
				   $("#companyidInfo").css("color","red");
				   flg=false;
			}
			else{
				   $("#companyidInfo").html("&nbsp;");
			}

			if(typeof(linktel)=='undefined' || !isMobilePhone(linktel)){
				$("#linktelInfoId").html("请输入正确格式的手机号码。");
				$("#linktelInfoId").css("color","red");
				flg=false;
			}
			else{
				$("#linktelInfoId").html("");
			}

			if(typeof(seccodeverify)=='undefined' || $.trim(seccodeverify).length!=4){
				$("#seccodeverifyInfo").html("请输入校验码。");
				$("#seccodeverifyInfo").css("color","red");
				flg=false;
			}
			else{
				$("#seccodeverifyInfo").html("");
			}

            if($("#acceptid:checked").length!=1){
				alert("阅读并接受《用户服务协议》才能继续操作。");
				flg=false;
			}

		return flg;

   }
   catch(e){
		alert(e.message);
		return false;
   }
}

/**
	功能说明:查询城市下的行政区

*/
function getAreaByCityId(cityIdPar){
	try{
		
		var parentId=cityIdPar;
		
		if(typeof(parentId)=='undefined' || isNaN(parentId) || parseInt(parentId)<=0){
			$("#areaid").html("<option value='0'>选择区域</option>");
			$("#placeid").html("<option value='0'>选择片区</option>");
			$("#placeid").hide();
			$("#companyid").html("<option value='0'>选择公司</option>");
			$("#companypicId").html("");
		    $("#vipcompanydiv").css("height","23px");
		    $("#telephone").attr("class","");
			return;
		}
        /**
		$.ajax({
				type:"POST",
				dataType:"json",
				url:_rootPath+"/v1/area/getByParentId",
				data:{parentId:parentId},		
				error:function a(){alert("error");},
				success:getAreaByCityIdCallback 
			   });
	   //查询地产公司
	   getCompanyByCity(parentId);
	   */
	   setSelectOption('areaid', ctiyArr[parentId],'选择区域');
	   setSelectOption('companyid', companyArr[parentId],'选择公司');
        
	   $("#areadiv").show();
	   $("#areadiv2").show();
	   $("#vipcompanydiv").show();
	   $("#vipcompanydiv2").show();

	}
	catch(e){
		alert(e.message);
		return;
	}
	
}
/**
function getAreaByCityIdCallback(msg){
  try{	
		var data=msg;
		if(data.infoNo==1){
			var areaList=data.arrInfo;	
			var contentHTML=[];
			contentHTML.push("<option value='0'>选择区域</option>");
			for(var i=0;i<areaList.length;i++){			
				contentHTML.push("<option value='"+areaList[i].areaId+"'>"+areaList[i].areaName+"</option>");
			}
			$("#areaid").html(contentHTML.join(''));
			$("#areadiv").show();
			$("#areadiv2").show();
			$("#vipcompanydiv").show();
			$("#vipcompanydiv2").show();
		}
		else{
			return;
		}
  }
  catch(e){
	alert(e.message);
	return;
  }
}*/
/**
	功能说明：根据区查询片区
*/
function getPlaceByAreaId(areaIdPar){
	try{
		var areaId=areaIdPar;
		if(typeof(areaId)=='undefined' || isNaN(areaId) || parseInt(areaId)<=0){
			$("#placeid").html("<option value='0'>选择片区</option>");
			$("#placeid").hide();			
			return;
		}
       /**
		$.ajax({
				type:"POST",
				dataType:"json",
				url:_rootPath+"/v1/area/getByParentId",
				data:{parentId:areaId},		
				error:function a(){alert("error");},
				success:getPlaceByAreaIdCallback 
			   });
			   */
	    setSelectOption('placeid', areaArr[areaId],'选择片区'); 
		$("#placeid").show();

	}
	catch(e){
		alert(e.message);
		return;
	}
	
}
/**
function getPlaceByAreaIdCallback(msg){
  try{	
		var data=msg;
		if(data.infoNo==1){
			var areaList=data.arrInfo;	
			var contentHTML=[];
			contentHTML.push("<option value='0'>选择片区</option>");
			for(var i=0;i<areaList.length;i++){			
				contentHTML.push("<option value='"+areaList[i].areaId+"'>"+areaList[i].areaName+"</option>");
			}
			$("#placeid").html(contentHTML.join(''));
			$("#placeid").show();	
		}
		else{
			return;
		}
  }
  catch(e){
	alert(e.message);
	return;
  }
}*/
/**
	功能说明：查询指定城市下的地产中介公司
*/
function getCompanyByCity(cityIdPar){
	try{
		var cityId=cityIdPar;
		if(typeof(cityId)=='undefined' || isNaN(cityId) || parseInt(cityId)<=0){
			$("#companyid").html("<option value='0'>选择公司</option>");
			return;
		}

		$.ajax({			
			  type:"POST",
			  dataType:"json",
			  url:_rootPath+"/v1/company/getByCityId",
			  data:{cityId:cityId},		
			  error:function a(){alert("error");},
			  success:getCompanyByCityCallback 
			
		});
	}
	catch(e){
		alert(e.message);
		return;
	}
}

function getCompanyByCityCallback(msg){
	var data=msg;
	if(data.infoNo==1){
		var companyList=data.arrInfo;
		var contentHTML=[];
		contentHTML.push("<option value='0'>选择公司</option>");
		for(var i=0;i<companyList.length;i++){
			contentHTML.push("<option value='"+companyList[i].companyId+"'  title='"+companyList[i].companyPic+"'>"+companyList[i].companyName+"</option>");
		}
		$("#companyid").html(contentHTML.join(''));
	}
	else{
		return;
	}
}
/**
	功能说明: 读取公司图片
*/
function getCompanyPic(companyId){
	//var t=obj.options[obj.selectedIndex].title;
	
	if(typeof(companyId)=='undefined' || $.trim(companyId).length<=0 || parseInt(companyId)<=0){
		$("#companypicId").html("");
		$("#vipcompanydiv").css("height","23px");
		$("#telephone").attr("class","");
		return;
	}
	var picObject=picArr[companyId];
	if(typeof(picObject)=='undefined'){
		$("#companypicId").html("");
		$("#vipcompanydiv").css("height","23px");
		$("#telephone").attr("class","");
		return;
	}
	var t=picObject.val;
	if(typeof(t)!='undefined' && t.length>4){
	    $("#companypicId").html("<img src='"+t+"' />");
		$("#vipcompanydiv").css("height","112px");
		$("#telephone").attr("class","ddother1");
	}
	else{
		$("#companypicId").html("");
		$("#vipcompanydiv").css("height","23px");
		$("#telephone").attr("class","");
	}
}
/***************************************登陆模块*********************************/
/**
	功能说明： 登陆验证
*/
function checkLogin(){
	try{
		var useremail=$("#useremail").val();
		var password=$("#password").val();
		var seccodeverify=$("#seccodeverify").val();
		
		if(typeof(useremail)=='undefined' || $.trim(useremail).length<=0){
			$("#loginerrorId").html("请填写用户名。");
			return false;
		 }		
		 
		if(typeof(password)=='undefined' || $.trim(password).length<=0){
			$("#loginerrorId").html("请填写密码。");
			return false;
		}
	   if(typeof(seccodeverify)=='undefined' || $.trim(seccodeverify).length!=4){
		    $("#loginerrorId").html("请填写正确的校验码。");
			return false;
		}
		
		$("#loginerrorId").html("");
		return true;
	}
	catch(e){
		alert(e.message);
		return false;
	}	
	
}
/***************************************************老用户完善注册资料验证*************************************************/
/**
	功能说明: 普通老用户资料验证
*/
function checkOldCommon(){
	try{
		var email=$("#email").val();		
		var linktel=$("#linktel").val();
		var seccodeverify=$("#seccodeverify").val();
		var flg=true;		
		if(typeof(email)=='undefined' || $.trim(email).length<=0 || $.trim(email).length>50 || !checkMailUtil(email)){				
				$("#emailInfoId").html("请输入正确的邮箱地址。");
				$("#emailInfoId").css("color","red");
				flg=false;
		}		
			
		if(typeof(linktel)=='undefined' || !isMobilePhone(linktel)){
			$("#linktelInfoId").html("请输入正确格式的手机号码。");
			$("#linktelInfoId").css("color","red");
			flg=false;
		}
        if(typeof(seccodeverify)=='undefined' || $.trim(seccodeverify).length!=4){
				$("#seccodeverifyInfo").html("请输入校验码。");
				$("#seccodeverifyInfo").css("color","red");
				flg=false;
			}
			else{
				$("#seccodeverifyInfo").html("");
		}

		if($("#acceptid:checked").length!=1){
				alert("阅读并接受《用户服务协议》才能继续操作。");
				flg=false;
			}
		
		return flg;
	}
	catch(e){
		alert(e.message);
		return false;
	}
}
/**
	功能说明: 验证老经纪人完善注册信息
*/
function checkOldAgent(){
    try{	
			
			var email=$("#email").val();
			var realname=$("#realname").val();
			var cityid=$("#cityid").val();
			var areaid=$("#areaid").val();
			var placeid=$("#placeid").val();
			var companyid=$("#companyid").val();
			var linktel=$("#linktel").val();
			var phone=$("#phone").val();
			var seccodeverify=$("#seccodeverify").val();
			
			var flg=true;		
		
			if(typeof(email)=='undefined' || $.trim(email).length<=0 || $.trim(email).length>50 || !checkMailUtil(email)){				
					$("#emailInfoId").html("请输入正确的邮箱地址。");
					$("#emailInfoId").css("color","red");
					flg=false;
			}
			else{
				   $("#emailInfoId").html("");
			}
					
			if(typeof(realname)=='undefined' || $.trim(realname).length<2 || $.trim(realname)>8){
					$("#realnameInfo").html("请填写身份证上的真实姓名，否则无法通过验证。");
					$("#realnameInfo").css("color","red");
					flg=false;
			}
			else{
				    $("#realnameInfo").html("");
			}
			
			if(typeof(cityid)=='undefined' || parseInt(cityid)<=0){
				   $("#cityidInfo").html("请选择所属城市。");
				   $("#cityidInfo").css("color","red");
				   flg=false;
			}
			else{
				$("#cityidInfo").html("");
			}
			
			if(typeof(areaid)=='undefined' || parseInt(areaid)<=0){
				   $("#areaidInfo").html("请选择所在区。");
				   $("#areaidInfo").css("color","red");
				   flg=false;
			}
			else if(typeof(placeid)=='undefined' || parseInt(placeid)<=0){
				   $("#areaidInfo").html("请选择所属片区。");
				   $("#areaidInfo").css("color","red");
				   flg=false;
			}
			else{
				    $("#areaidInfo").html("");
			}

			if(typeof(companyid)=='undefined' || parseInt(companyid)<=0){
				   $("#companyidInfo").html("请选择所属公司。");
				   $("#companyidInfo").css("color","red");
				   flg=false;
			}
			else{
				   $("#companyidInfo").html("&nbsp;");
			}

			if(typeof(linktel)=='undefined' || !isMobilePhone(linktel)){
				$("#linktelInfoId").html("请输入正确格式的手机号码。");
				$("#linktelInfoId").css("color","red");
				flg=false;
			}
			else{
				$("#linktelInfoId").html("");
			}

			if(typeof(seccodeverify)=='undefined' || $.trim(seccodeverify).length!=4){
				$("#seccodeverifyInfo").html("请输入正确的校验码。");
				$("#seccodeverifyInfo").css("color","red");
				flg=false;
			}
			else{
				$("#seccodeverifyInfo").html("");
			}

            if($("#acceptid:checked").length!=1){
				alert("阅读并接受《用户服务协议》才能继续操作。");
				flg=false;
			}

		return flg;

   }
   catch(e){
		alert(e.message);
		return false;
   }
}
/**
	功能说明：提交找回密码信息
*/
function getBackPwd(){
   try{
		var username=$("#username").val();
		var useremail=$("#useremail").val();
		var seccodeverify=$("#seccodeverify").val(); 

        if(typeof(username)=='undefined' || $.trim(username).length<=0){
			$("#loginerrorId").html("请输入用户名");
			return;
		}
        
		if(typeof(useremail)=='undefined' || $.trim(useremail).length<=0){
			$("#loginerrorId").html("请输入邮箱地址");
			return;
		}
        
		if(!checkMailUtil(useremail)){
			$("#loginerrorId").html("请输入正确格式的邮箱地址");
			return;
		}

		if(typeof(seccodeverify)=='undefined' || $.trim(seccodeverify).length!=4){
				$("#loginerrorId").html("请输入正确的校验码。");
				return;
		}
		$("#loginerrorId").html("");
		//
		$.ajax({
				type:'POST',
				dataType:'json',
				url:_rootPath+"/v1/member/getbackpwd",
			    data:{username:username,useremail:useremail,seccodeverify:seccodeverify},		
			    error:function a(){alert("error");},
			    success:getBackPwdCallback 
			  });
   }
   catch(e){
	  alert(e.message);
	  return;
   }
}
function getBackPwdCallback(msg){
	var data=msg;
	if(data.infoNo==1){
		if(confirm("您的登录密码已被系统初始化并发送到了您的邮箱\r\n\r\n是否立即登录邮箱查收？"))
			location.href="http://"+data.infoStr;
		else
			return;
	}
	else{
		alert(data.infoStr);
		return;
	}
}

/*************************************用户没接收到激活邮件，重新发送激活邮件或者修改邮箱后发送激活邮件**********************************************/
/**
	功能说明: 重新发送激活邮件
*/
function reSendMail(userId,userEmail){
	try{
		var id=userId;
		var email=userEmail;
		if(typeof(email)=='undefined' || $.trim(email).length<=0 || typeof(id)=='undefined' || parseInt(id)<=0){
			alert('参数不正确');
			return;
		}
		//
		$.ajax({
		       type:'POST',
			   dataType:'json',
			   url:_rootPath+"/v1/member/reSendMail",
		       data:{id:id,email:email,type:0},
			   success:reSendMailCallback
			  });
		
	}
	catch(e){
		alert(e.message);
		return;
	}
}
/**
	功能说明: 修改邮箱地址并重新发送激活邮件
*/
function updateEmailAndSend(userId){
	try{
	     var id=userId;
		 var email=$('#updateemail').val();
		 if(typeof(id)=='undefined' || parseInt(id)<=0){
			alert('参数不正确');
			return;
		 }
		 if(typeof(email)=='undefined' || $.trim(email).length<=0 || $.trim(email).length>50 || !checkMailUtil(email)){				
			alert('请输入正确格式的电子邮箱地址');
			return;	
		 }
		 //
		$.ajax({
		       type:'POST',
			   dataType:'json',
			   url:_rootPath+"/v1/member/reSendMail",
		       data:{id:id,email:email,type:1},
			   success:reSendMailCallback
			  });
	}
	catch(e){
		alert(e.message);
		return;
	}

}
function reSendMailCallback(msg){
	var data=msg;
	if(data.infoNo==1){
		if(confirm("邮件发送成功！\r\n\r\n立即登录邮箱激活帐户？"))
			location.href='http://'+data.infoStr;
		else
			return;
	}
	else{
		alert(data.infoStr);
		return;
	}
}