function removetip(id){
 $("#"+id+"tip").removeClass('correct').removeClass('error').html('').hide();
 $("#"+id).removeClass('inerror');
}
function addtip(id,message){
 $("#"+id+"tip").removeClass('correct').addClass('error').html(message).show();
 $("#"+id).addClass('inerror');
}
function showtip(id,message){
 $("#"+id).removeClass('inerror').addClass("hover");
 $("#"+id+"tip").removeClass('correct').removeClass('error').show().html(message);
}
function yestip(id,message,is){
 $("#"+id).removeClass('inerror');
 $("#"+id+"tip").removeClass('error').addClass('correct').html(message).show();
 if(is!=null){
   for(i=0;i<10;i++){
     $('#'+id).animate({marginLeft:"2px"},20,function(){
       $("#"+id+"tip").css("color","red");									  
	 });
     $('#'+id).animate({marginLeft:"0px"},20,function(){
       $("#"+id+"tip").css("color","#666");											  
	 });
   }
 }
}
function clickrow(obj){
  if($(".cat"+obj.id).is(":hidden")){
	 $(".cat"+obj.id).show();
	 var src = $("#"+obj.id).attr("src").replace("images/menu_plus.gif","images/menu_minus.gif");
	 $("#"+obj.id).attr("src",src);
  }else{
     $(".cat"+obj.id).each(function(){
       $(this).hide();
	   var span = $(this).find("span").html();
	   if(span){
		 $(".cat"+span).hide();
	     var _src = $("#"+span).attr("src").replace("images/menu_minus.gif","images/menu_plus.gif");
	     $("#"+span).attr("src",_src);
	   }
     });
	 var src = $("#"+obj.id).attr("src").replace("images/menu_minus.gif","images/menu_plus.gif");
	 $("#"+obj.id).attr("src",src);
  }
}
function get_path_url(parmat){
 return '/index.php'+parmat+'&floor='+getRandom(5);	
}

function addfavorite(siteName, url) {
	CloseNLRAF(true);
	if (!siteName){siteName=webname;}
	if (!url){url=weburl;}
    if (document.all)
        window.external.addFavorite(url, siteName);
    else if (window.sidebar)
        window.sidebar.addPanel(siteName, url, "");
}

function setClass(obj,myclass){
   var classname = $(obj).attr("class")+" "+myclass;	
   $(obj).removeClass();
   $(obj).addClass(classname);
}

function rmClass(obj,myclass){
   var classname = $(obj).attr("class").replace(" "+myclass,"");
   $(obj).removeClass();
   $(obj).addClass(classname);
}
function polang_box(title,url,width,height,scrolling){	
  var scrolling = scrolling ? scrolling : 'no';
  Iframe({
    Title:title,
    Url:url,
	Width:width,
	Height:height,
	scrolling:scrolling,
	isShowIframeTitle:true
  });	
}

function removeclass(id){
 $("#"+id).removeClass();
 $("#"+id).html('');
}
function addClass(id,myclass,message){
 var value = message=='' ? '' : '<span class="action_po"><span class="action_po_top">'+message+'</span><span class="action_po_bot"></span></span></span>'; 
 $("#"+id).removeClass();
 $("#"+id).addClass(myclass);
 $("#"+id).html(value);
}
function reSeccode(obj){
 var src = $(obj).attr("src");
 var str = src.split("&"); 
 var img = str[0]+'&'+str[1]+"&"+getRandom(5);
 $(obj).attr("src",img);
}
function isLogin(){
 $.ajax({url:get_url('&act=isLogin'),type:'GET',success:function(isLogin){$("#isLogin").html(isLogin);}});	
}
function sinAlert(message,fun){
 var msg = message ? message : '确定操作吗？';
 if(confirm(msg)){
   if(fun==true){
				                                        $("#button").attr("disabled",true);
														$("#button").val("数据提交并处理中。。。请千万不要刷新");
   }
   return true;
 }
 return false;
}

function Ale(message,url){
 if(confirm(message)){
location.href = url;
 }else{
	 
 }
}

function sinbox(title,url,width,height,scrolling,isShow){	
 var scrolling = scrolling ? scrolling : 'no';
 var show = !isShow ? true : false;
 Iframe({
  Title:title,
  Url:url,
  Width:width,
  Height:height,
  scrolling:scrolling,
  isShowIframeTitle:show
 });	
}
function showImg(obj,left){
 var image = new Image();
 image.src = obj.src;
 left = left ? left : 5;
 html = "<img src='"+obj.src+"' width='"+image.width+"' height='"+image.height+"' onmouseout='Close();'/>";
 showDiv(html,image.width,image.height,0,$(obj).offset().left+obj.width+left,$(obj).offset().top+obj.height);
}

function in_array(arr,val){
 var re = false;
 if(arr!=null) for(i=0;i<arr.length;i++) if(arr[i]==val) re = true;
 return re;
}
function Msg(message,url){
 var message = message ? message : '确定操作吗？';
 Ask({Msg:message,callback:'location.href = \''+url+'\';'});
}
var isArray = function(obj) { 
 return Object.prototype.toString.call(obj) === '[object Array]'; 
} 

var isObject = function(obj) { 
 return Object.prototype.toString.call(obj) === '[object Object]'; 
} 


function checkall(form, name) {
 for(var i = 0; i < form.elements.length; i++) {
  var e = form.elements[i];
  if(e.name.match(name)) e.checked = form.elements['chkall'].checked;
 }
}
function getRandom(n){
 var rnd="";
 for(var i=0;i<n;i++) rnd += Math.floor(Math.random()*10);
 return rnd;
}
function ajaxurl(parmat){
  return '/index.php?mod=tools&act=ajax&'+parmat+'&floor='+getRandom(5);	
}

function ajax(url){
 var url = url+'&floor='+Math.floor(Math.random()*10000+1),value;
 $.ajax({url:url,type: 'GET',success: function(msg){value = msg;},async:false,dataType:"json"});
 return value;
}
function get_url(parmat){
 return '/index.php?mod=tools&'+parmat+'&floor='+getRandom(5);	
}

function ajaxHtml(url){
 var url = url+'&floor='+Math.floor(Math.random()*10000+1),value;
 $.ajax({url:url,type: 'GET',success: function(msg){value = msg;},async:false});
 return value;
}
function strlen(str){
 var strlength=0;
 for(i=0;i<str.length;i++){
  if(isChinese(str.charAt(i))==true){
   strlength=strlength + 2;
  }else{
   strlength=strlength + 1;
  }
 }
 return strlength;
}
String.prototype.trim = function(){
  return this.replace(/(^\s*)|(\s*$)/g, "");
}
function isChinese(str){
  var reg = /[u00-uFF]/;       
  return !reg.test(str);      
}

function isSpecial(str){
  var reg =  /^([a-z0-9]|[_]){0,10000}$/;       
  return reg.test(str);      
}

function isinCn(str){
 var pattern=/[^\x00-\xff]/g;
 if(pattern.test(str)){
  return true;
 }else{
  return false;
 }
} 
function isEmail(email){
  var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  return reg.test(email);
}
function isNum(str){
  return !isNaN(str);
}

function isFirstNum(str){
  return !isNaN(str.charAt(0));
}
function ishttp(str){
  str = str.match(/http:\/\/.+/);
  return !(str==null);
}
function isIcq(str){
  var reg = /^[1-9]\d{4,9}$/;
  return  reg.test(str);
}
function isPhone(str){
  var reg = /([1-9]{1,3}\-[1-9]{7,8}$)|(1[0-9]{10,10}$)/;
  return  reg.test(str.trim());
}
function getid(id){
  return document.getElementById(id);	
}
function getgm(id){
  return $(id);
}
function checkId(pId){
  var arrVerifyCode = [1,0,"x",9,8,7,6,5,4,3,2];
  var Wi = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
  var Checker = [1,9,8,7,6,5,4,3,2,1,1];
  if(pId.length != 15 && pId.length != 18)    return false;
  var Ai=pId.length==18 ?  pId.substring(0,17)   :   pId.slice(0,6)+"19"+pId.slice(6,16);
  if (!/^\d+$/.test(Ai))  return false;
  var yyyy=Ai.slice(6,10) ,  mm=Ai.slice(10,12)-1  ,  dd=Ai.slice(12,14);
  var d=new Date(yyyy,mm,dd) ,  now=new Date();
  var year=d.getFullYear() ,  mon=d.getMonth() , day=d.getDate();
  if (year!=yyyy || mon!=mm || day!=dd || d>now || year<1940) return false;
  for(var i=0,ret=0;i<17;i++)  ret+=Ai.charAt(i)*Wi[i];
  Ai+=arrVerifyCode[ret %=11];     
  return pId.length ==18 && pId != Ai ? false : true;        
}

function getLocalTime(nS,format){  
 format = format ? format : "y-m-d h:i:s";
 var getdate = new Date(parseInt(nS) * 1000);
 var year = getdate.getFullYear();
 var month = getdate.getMonth()+1;
 month = month<10 ? "0"+month : month;
 var date = getdate.getDate();
 date = date<10 ? "0"+date : date;
 var hours = getdate.getHours();
 hours = hours<10 ? "0"+hours : hours;
 var minutes = getdate.getMinutes();
 minutes = minutes<10 ? "0"+minutes : minutes;
 var seconds = getdate.getSeconds();
 seconds = seconds<10 ? "0"+seconds : seconds;
 var time = format.replace("y",year);
 time = time.replace("m",month);
 time = time.replace("d",date);
 time = time.replace("h",hours);
 time = time.replace("i",minutes);
 time = time.replace("s",seconds);
 return time;
} 


function doget(key){
 var key = "mod,act,"+key;
 var arr = key.split(",");
 var val = new Array();
 for(var i=0;i<arr.length;i++){
   val[i] = $("#"+arr[i]).val();	 
 }
 $.getScript(get_url('&act=request&key='+encodeURIComponent(key)+'&val='+encodeURIComponent(val)),function(){
   if(res.error){
	 Wrong(res.error); 
   }else{																									   
     location.href = res.url;		
   }
 });
}
function autoTop(id,classname){
  var head = document.getElementById(id);
  var height = head.getBoundingClientRect().top;
  window.onscroll = function(){
    var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
    if(scrollTop > height){
      head.className = classname+' autoTop';
    }else{
      head.className = classname;
    }
  }
}
$(function(){
  $("#setmypage").change(function(){
  
var url = location.href;
url = url.replace('&setmypage=',"&noy=")+"&setmypage="+$(this).val();
location.href = url;
  
  })
  $("#mymiane").change(function(){
  
var url = location.href;
url = url.replace('&mymiane=',"&nomy=")+"&mymiane="+$(this).val();
location.href = url;
  
  })
})

function __actcard(){
  return sinAlert($("#getlh").html()+"给"+$("#username").val());
}

function actcard(type){
 var number = $('input[name="id[]"]:checked').length;
 var username = $("#username").val();
 var n = type=='a' ? '商家' : '消费者';
 
 
 if(type=='m') {
	 if(number<1){
	   alert('请选择要归属的排队卡');	
	   return false; 
	 }
 if(username==''){
   alert('请输入代理用户名');
   return false;	 
 }
	 return sinAlert('确认要把'+number+'张排队卡发给代理'+username+'吗？');
 }
 
 if(type=='u') {
	 if(number<1){
	   alert('请选择要排队的排队卡');	
	   return false; 
	 }
	 return sinAlert('确认要把'+number+'张排队卡排上队吗？',true);
 }
 if(username==''){
   alert('请输入'+n+'用户名');
   return false;	 
 }else{
	 if(number<1){
	   alert('请选择要归属的排队卡');	
	   return false; 
	 }
   if(type=='a') return sinAlert('确认要把'+number+'张排队卡发给商家'+username+'吗？');
   if(type=='c') {
	   if(username==selfusername){
	   alert('不能送卡给自己');	
	   return false;  
	   }
	   return sinAlert('确认要把'+number+'张排队卡送给消费者'+username+'吗？');
   }
 }

}

function getlh(){
  if($("#one").val()&&$("#two").val()){
    $.getJSON(get_url("act=getlh&one="+encodeURIComponent($("#one").val())+"&two="+encodeURIComponent($("#two").val())),function(res){
      $("#getlh").html(res.message);
    }); 
  }
}