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(strleng>20){
	   addClass("usernametip","wrong1","用户名长度不能大于20个字符");
	}else{
       $.ajax({url:ajaxurl('&do=chkusername&username='+encodeURIComponent(username)+'&floor='+Math.floor(Math.random()*1000+1)),type: 'GET',success: function(msg){
			if(msg.trim()=='ok'){
	           addClass("usernametip","chenggong1","");
			}else{
	           addClass("usernametip","wrong1","对不起，该用户名已存在");
			}	
	   }});
	}	
}



function checkemail(){
	var email = $("#email").val().trim();
	if(email==''){
	   addClass("emailtip","wrong1","请输入注册邮箱,找回密码使用，非常重要！");
	}else if(!isEmail(email)){
	   addClass("emailtip","wrong1","您输入的邮箱格式错误");		
	}else{
	   var url = ajaxurl('&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 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 checkpassword(){
	var password = $("#password").val();
	var strleng = password.length;
	if(strleng<6){
	   addClass("passwordtip","wrong1","请输入您的免费注册密码,长度不得小于6位");
	}else{
	   addClass("passwordtip","chenggong1","");
	}
}

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


function checks_county(){
    if($("#s_county").val()=='市、县级市'){
	 addClass("s_countytip","wrong1","对不起，请正确填写你的区域信息！");
    }else{
	 addClass("s_countytip","chenggong","","");
    }	
}


function checkuserphone(){
	if(getgm("#userphone").val().length<7){
	   addClass("userphonetip","wrong1","请填写您的联系电话，方便我们与您联系");
	}else{
	   addClass("userphonetip","chenggong1","");
	}
}

function checkseccode(){
	var seccode = $("#seccode").val();
	var strleng = seccode.length;
	if(strleng!=4){
	   addClass("seccodetip","wrong1","请输入验证码，验证码为4个非中文字符！");
	}else{
	   var url = ajaxurl('&do=seccode&seccode='+seccode+'&floor='+Math.floor(Math.random()*1000+1));
       $.ajax({url:url,type: 'GET',success: function(msg){
			if(msg.trim()=='yes'){
	           addClass("seccodetip","chenggong1","");
			}else{
	           addClass("seccodetip","wrong1","对不起，您输入的验证码有误");
			}										  
	   }});
	}
}

function checkform(){
  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($("#usernametip").html().indexOf('对不起，该用户名已存在') != -1){
	addClass("usernametip","wrong1","对不起，该用户名已存在");
    post = false;
  }  
  
  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;
  }  
   
  if($("#password").val().length<6){
	addClass("passwordtip","wrong1","请输入您的免费注册密码,长度不得小于6位");
    post = false;
  }  
  
  if($("#cpassword").val()==''){
	addClass("cpasswordtip","wrong1","请输入确认免费注册密码");
    post = false;
  } 
  if($("#cpassword").val()!=$("#password").val()){
	addClass("cpasswordtip","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;
  }  
  if($("#seccode").val().length != 4){
	addClass("seccodetip","wrong1","请输入验证码，验证码为4个非中文字符！");
    post = false;
  }
  if($("#seccodetip").html().indexOf('对不起，您输入的验证码有误') != -1){
	addClass("seccodetip","wrong1","对不起，您输入的验证码有误");
    post = false;
  }
  if($("#s_county").val()=='市、县级市'){
	 addClass("s_countytip","wrong1","对不起，请正确填写你的区域信息！");
     post = false;
  }else{
	 addClass("s_countytip","chenggong","","");
  }
  if($("#checkbox").attr("checked") == false){
	addClass("chkagreementtip","wrong1","必须同意免费注册使用协议后才能正确免费注册");
    post = false;
  }  
  return post;  
} 