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 checkusername(){
	var username = $("#username").val().trim();
	if(username==''){
	   $("#truename").html('');
	   addClass("usernametip","wrong1","请输入购买会员！");
	}else{
	 var url = ajaxurl('&do=chkstore&username='+username+'&floor='+Math.floor(Math.random()*1000+1));
     $.ajax({url:url,type: 'GET',success: function(msg){
	   if(msg.trim()==''){
	      addClass("usernametip","wrong1","对不起，该会员不存在！");
	   }else{
	      addClass("usernametip","chenggong1",msg);
	   }	
	 }});
	}
}


function checkmoney(){
	var money = $("#moneya").val().trim();
	var usermoney = $("#usermoney").val().trim();
	var payment = $("#paymenta").val().trim();
	if(money==''){
	   addClass("moneytip","wrong1","请填写消费金额，必须填写！");
	}else{
	   addClass("moneytip","chenggong1","");
       $.ajax({url:ajaxurl('&do=money&money='+money+'&floor='+Math.floor(Math.random()*1000+1)),type: 'GET',success: function(msg){
		 var yfmoney = msg.trim();
		 $("#yfmoney").val(Math.round(yfmoney*10)/10);
	     if(usermoney>=parseInt(yfmoney)){
	        addClass("yfmoneytip","chenggong1","");
	     }else{
	        addClass("yfmoneytip","wrong1","对不起，你的余额只有"+usermoney+"元，请<a href='"+payment+"'>充值</a>!");
	     }	
	   }});
	}
}



function checkshopname(){
	if(getgm("#shopname").val().length<1){
	   addClass("shopnametip","wrong1","请正确填写商品名称");
	}else{
	   addClass("shopnametip","chenggong1","");
	}
}

function checkshopnum(){
	if(getgm("#shopnum").val().length<1){
	   addClass("shopnumtip","wrong1","请正确填写购买数量");
	}else{
	   addClass("shopnumtip","chenggong1","");
	}
}





function addstore(){
  var post = true; 
  if(strlen($("#username").val()) < 1){
	$("#truename").html('');
	addClass("usernametip","wrong1","请输入购买会员");
    post = false;
  }

  if($("#usernametip").html().indexOf('对不起，该会员不存在！') != -1){
    $("#truename").html('');
	addClass("usernametip","wrong1","对不起，该会员不存在！");
    post = false;
  }
  
  if(post){
	addClass("usernametip","chenggong1","","");
  }
  
  
  if($("#moneya").val().length<1){
	addClass("moneytip","wrong1","请填写消费金额，必须填写！");
    post = false;
  } 
  
  if(post){
	addClass("moneytip","chenggong1","","");
  }
  
  if($("#yfmoneytip").html().indexOf('对不起，你的余额只有') != -1){
    post = false;
  }
  
  
  if(getgm("#shopname").val().length<1){
	 addClass("shopnametip","wrong1","请正确填写商品名称");
	 post = false;
  }
  
  if(getgm("#shopnum").val().length<1){
	 addClass("shopnumtip","wrong1","请正确填写购买数量");
	 post = false;
  }
  
  return post;  
} 