function set_div(t){
   return '<span class="action_po"><span class="action_po_top">'+t+'</span><span class="action_po_bot"></span></span></span>';
}
function addClass(id,c,v){
   var value;
   if(v==''){
	  value = '';
   }else{
	  value = set_div(v); 
   }
   $("#"+id).removeClass();
   $("#"+id).addClass(c);
   $("#"+id).html(value);
}

function agreement(){
   if($("#xiy").css("display")=="none"){
      $("#xiy").show(500);
   }else{
      $("#xiy").hide(500);
   }
}

function checkusername(){
	var username = $("#username").val();
	var strleng = strlen(username);
	if(strleng<1){
	   addClass("usernametip","wrong1","您还没有输入用户名");
	}else if(username.match("^[\\d]+$")){
	   addClass("usernametip","wrong1","用户名不能全为数字");
	}else if(strleng>20){
	   addClass("usernametip","wrong1","用户名长度不能大于20个字符");
	}else{
       var url ='/index.php?mod=tools&act=ajax&do=chkusername&username='+encodeURIComponent(username)+'&floor='+Math.floor(Math.random()*1000+1);
       $.ajax({url: url,type: 'GET',success: function(msg){
			if(msg.trim()=='ok'){
	           addClass("usernametip","chenggong1","");
			}else{
	           addClass("usernametip","wrong1","对不起，该用户名已存在");
			}	
	   }});
	}	
}

function checkjsr(){
	var jsr = $("#jsr").val();
	var referrals = $("#referrals").val();
	if(jsr==''){
	   addClass("jsrtip","wrong1","请填写介绍人，没有请填写 "+referrals+" ！");
	}else if(jsr!=referrals){
       $.ajax({url:ajaxurl('&do=chkjsr&username='+encodeURIComponent(jsr)+'&floor='+Math.floor(Math.random()*1000+1)),type: 'GET',success: function(msg){
			if(msg.trim()=='ok'){
	           addClass("jsrtip","chenggong1","");
			}else{
	           addClass("jsrtip","wrong1","对不起，该会员不存在！");
			}	
	   }});
	}else{
	   addClass("jsrtip","chenggong","","");	
	}
}

function checkemail(){
	var email = $("#email").val().trim();
	if(email==''){
	   addClass("emailtip","wrong1","找回密码使用，非常重要！");
	}else if(!isEmail(email)){
	   addClass("emailtip","wrong1","您输入的邮箱格式错误");		
	}else{
       var url ='/index.php?mod=tools&act=ajax&do=chkemail&email='+email+'&floor='+Math.floor(Math.random()*1000+1);
       $.ajax({url: url,type: 'GET',success: function(msg){
			if(msg.trim()=='ok'){
	           addClass("emailtip","chenggong1","");
			}else{
	           addClass("emailtip","wrong1","对不起，该邮箱已存在");
			}	
	   }});
	}
}


function checkpassword(){
	var password = $("#pwd").val();
	var strleng = password.length;
	if(strleng<6){
	   addClass("passwordtip","wrong1","请输入注册密码,不得小于6位");
	}else{
	   addClass("passwordtip","chenggong1","");
	}
}

function checkcpassword(){
	var cpassword = $("#cpassword").val();
	var password = $("#pwd").val();
	if(cpassword==""){
	   addClass("cpasswordtip","wrong1","请输入确认免费注册密码");
	}else if(cpassword!=password){
	   addClass("cpasswordtip","wrong1","对不起，两次输入密码不一致");
	}else{
	   addClass("cpasswordtip","chenggong1","");
	}
}


function checktruename(){
	var truename = $("#truename").val().trim();
	if(!isChinese(truename)){
	   addClass("truenametip","wrong1","联系人必须是中文！");
	}else if(strlen(truename)<4){
	   addClass("truenametip","wrong1","联系人不能少于2个字！");
	}else if(strlen(truename)>10){
	   addClass("truenametip","wrong1","联系人不能多于5个字！");
	}else{
	   addClass("truenametip","chenggong1","","");
	}
}

function checkuserphone(){
	if(getgm("#userphone").val().length<7){
	   addClass("userphonetip","wrong1","请填写代理商的联系电话");
	}else{
	   addClass("userphonetip","chenggong1","");
	}
}

function checkaddress(){
	if(getgm("#address").val().length<7){
	   addClass("addresstip","wrong1","请详细填写代理商的联系地址");
	}else{
	   addClass("addresstip","chenggong1","");
	}
}
function checks_county(){
	var province = $("#s_province").val();
	var city = $("#s_city").val();
	var county = $("#s_county").val();
    if($("#s_county").val()=='市、县级市'){
	 addClass("s_countytip","wrong1","请正确填写你的区域信息！");
    }else{

	           addClass("s_countytip","chenggong1","","");

    }	
}


function addywy(){
  var post = true; 
  if(strlen($("#username").val()) < 1){
	addClass("usernametip","wrong1","您还没有输入用户名");
    post = false;
  }
  if(strlen($("#username").val()) > 20){
	addClass("usernametip","wrong1","用户名长度不能大于10个字符");
    post = false;
  }
  
  if($("#username").val().match("^[\\d]+$")){
	addClass("usernametip","wrong1","用户名不能全为数字"); 
    post = false;
  }
  
  if($("#usernametip").html().indexOf('对不起，该用户名已存在') != -1){
	addClass("usernametip","wrong1","对不起，该用户名已存在");
    post = false;
  }
  
  if(post){
	addClass("usernametip","chenggong1","","");
  }
  
  if($("#email").val().length<1){
	addClass("emailtip","wrong1","找回密码使用，非常重要！");
    post = false;
  }else if(!isEmail($("#email").val())){
	addClass("emailtip","wrong1","您输入的邮箱格式错误");
    post = false;
  }else if($("#emailtip").html().indexOf('对不起，该邮箱已存在') != -1){
	addClass("emailtip","wrong1","对不起，该邮箱已存在");
    post = false;
  }else{
	addClass("emailtip","chenggong1","","");
  }  
   
  if($("#pwd").val().length<6){
	addClass("passwordtip","wrong1","请输入注册密码,不得小于6位");
    post = false;
  } 
  
  if(post){
	addClass("passwordtip","chenggong1","","");
  }
  
  if($("#cpassword").val()==''){
	addClass("cpasswordtip","wrong1","请输入确认免费注册密码");
    post = false;
  } 
  if($("#cpassword").val()!=$("#pwd").val()){
	addClass("cpasswordtip","wrong1","对不起，两次输入密码不一致");
    post = false;
  } 
  

  if($("#s_county").val()=='市、县级市'){
	 addClass("s_countytip","wrong1","请正确填写你的区域信息！");
     post = false;
  }else{
	 addClass("s_countytip","chenggong1","","");
  }

 
  if(!isChinese($("#truename").val().trim())){
	 addClass("truenametip","wrong1","联系人必须是中文！");
  }else if(strlen($("#truename").val().trim())<4){
	 addClass("truenametip","wrong1","联系人不能少于2个字！");
  }else if(strlen($("#truename").val().trim())>10){
	 addClass("truenametip","wrong1","联系人不能多于5个字！");
  }
  
  if(getgm("#userphone").val().length<7){
	 addClass("userphonetip","wrong1","请填写联系电话");
	 post = false;
  }
  
  if(getgm("#address").val().length<7){
	 addClass("addresstip","wrong1","请详细填写联系地址");
	 post = false;
  }
  
    if($("#jsr").val().length<1){
	addClass("jsrtip","wrong1","请填写介绍人，没有请填写 admin ！");
    post = false;
  }else if($("#jsrtip").html().indexOf('对不起，该会员不存在！') != -1){
	addClass("jsrtip","wrong1","对不起，该会员不存在！");
    post = false;
  }  
  
  return post;  
} 