// JavaScript Document
    
	//打开弹出层
    function showLayer(){
      document.getElementById('alogin_div_box').style.display='block';
      document.getElementById('bg').style.display='block';
    }
    //关闭弹出层
    function closeLayer(){
      document.getElementById('alogin_div_box').style.display='none';
      document.getElementById('bg').style.display='none';
    }
	//首页商城图片效果
    function showDiv(a,b){
		$('#'+a).show();
		$('#'+a).css('margin-top','75px');
		$('#'+a).css('margin-left','98px');
		$('#'+b).css('border','3px solid #f9a255');
		}
		//关闭首页商城图片效果
	function hideDiv(a,b){
		$('#'+a).hide();
		$('#'+b).css('border','3px solid #ffffff');
		}
		//检查搜索框的值
	function checkInput(a){
		if($('#'+a).val()=='输入您想要的宝贝' || $('#'+a).val()==''){alert('输入您想搜的宝贝名'); return false;}
        else{return true;}
		}
		//检查登陆
	function checklogin(url){
		username=$('#username').val();
		password=$('#password').val();
		savelogin=$('#savelogin').val();
		if(username==''){alert('用户名不能为空！'); $('#username').focus();return false;}
		if(password==''){alert('密码不能为空！'); $('#password').focus();return false;}
		$.post('ajax.php?fun=login', {'p1':username,'p2':password,'p3': savelogin,'fresh':Math.random()}, function(data){
		    if(data==1){
			    location.href=url;
		    }
			else{
			    alert("账号或密码错误");
			}
	    });
		return false;
	}
		//站内信全选
	function checkAll(str)   
      {
        var a = document.getElementsByName(str);   
        var n = a.length;   
        for(var i=0; i<n; i++)   
        a[i].checked = window.event.srcElement.checked;   
      } 
	
	$(document).ready(function(){
	//切换搜索
	  $("#sel").toggle(function(){
        $('#gw_button1').val("搜索掌柜");
		$('#sb').attr('action','shop.php');
		$('#query1').attr('name','nick');
		$('#query1').val('输入您想要搜的掌柜');
        },function(){
        $('#gw_button1').val("搜索商品");
		$('#sb').attr('action','list.php');
		$('#query1').attr('name','q');
		$('#query1').val('输入您想要搜的宝贝');
      });
	  
	  $("#sel2").toggle(function(){
        $('#gw_button12').val("搜索掌柜");
		$('#sb2').attr('action','shop.php');
		$('#query2').attr('name','nick');
		$('#query2').val('输入您想要搜的掌柜');
        },function(){
        $('#gw_button12').val("搜索商品");
		$('#sb2').attr('action','list.php');
		$('#query2').attr('name','q');
		$('#query2').val('输入您想要搜的宝贝');
      });
	  //打开关闭常见问题
	  $('.open').click(function(){
	    var index=$(this).val();
	    $('#aa li:eq('+index+')').attr('class','');
	  });
	  $('.close').click(function(){
	    var index=$(this).val();
	    $('#aa li:eq('+index+')').attr('class','collapsed');
	  });
	  //打开隐藏会员中心隐藏的小帮助
	  $('.seeHelp').toggle(function(){
	    $('#fxuc_ordersHelper').attr('class','bd');
	    },function(){
		$('#fxuc_ordersHelper').attr('class','collapsed');
		});
	});
	//介绍返现 商城介绍 支付配送 的滑动门切换
	function chooseTab(tab){
    // hide all
    $("#tab_content_cps").css("display", "none");
    $("#tab_title_cps").attr("class","tab-unchosed");    
    $("#tab_content_desc").css("display", "none");  
    $("#tab_content_pay").css("display", "none"); 
    $("#tab_title_desc").attr("class","tab-unchosed");  
    $("#tab_title_pay").attr("class","tab-unchosed");  
    // view  
    $("#tab_content_"+tab).css("display", "block"); 
    $("#tab_title_"+tab).attr("class","tab-chosed"); 
  }
  //顶一下 踩一下
  function vote(p1,p2){
	  $.post('ajax.php?fun=vote', {'p1':p1,'p2':p2, 'fresh':Math.random()}, function(data){
		if(data!=''){
			$('.'+p1+' .vote_num').text(data);
		}
	  });
  }
  //评论重置
  function clearScore(){
    $("#deliverDiv").attr("class","rating-stars");
    $("#deliverScore").val(-1);
    $("#productDiv").attr("class","rating-stars");
    $("#productScore").val(-1);
    $("#serviceDiv").attr("class","rating-stars");
    $("#serviceScore").val(-1);
    $("#remLenComment").html("<font color=red>0</font>");
    $("#commentText").focus();
  }
  //鼠标放在评价级别上的汉子说明
  var tipContents = ["", "很差", "较差", "一般", "较好", "很好"];
  function displayTip(type, index){
    $("#"+type+"Tip").html(tipContents[index]);
  }
  //清楚
  function clearTip(type){
    $("#"+type+"Tip").html("<span style='visibility:hidden'>很好</span>");
  }
  //保存评价，用于提交表单
  function saveV(type, value){
    $("#"+type+"Score").val(value);
    $("#"+type+"Div").attr("class","rating-stars rating"+value);
  }
  //检查评论字数
  var currentLen = 0;
  function textCounter(field, msgId, maxlimit) {
	var filed=document.getElementById(field);
    var trimed=field.value.replace(/^\s+|\s+$/g, '');
    if (trimed.length > maxlimit) {
        field.value = trimed.substring(0, maxlimit);
    }
    if (currentLen != trimed.length) {
        var msgId=document.getElementById(msgId);
        if (msgId) {
            msgId.innerHTML=trimed.length;
        }
        currentLen = trimed.length;
    }
  }
function check_comment(){
	if($('#commentText').val().length<10){
		alert('您输入的字数太少了！'); $('#commentText').focus();
	}
	else{
	    var commentText = $('#commentText').val();
		var serviceScore = $('#serviceScore').val();
		var productScore = $('#productScore').val();
		var deliverScore = $('#deliverScore').val();
		var mall_name = $('#mall_name').val();
		var mall_id = $('#mall_id').val();
		var user_name = $('#user_name').val();
		$.post('ajax.php?fun=comment', {'p1':commentText,'p2':serviceScore,'p3':productScore,'p4':deliverScore,
			                            'p5':mall_name,'p6':user_name, 'fresh':Math.random()}, function(data){
		    if(data!=''){
			    clearScore();
				alert('评论完毕');
				window.location="mall.php?id="+mall_id+"&page=1";
		    }
			else{
			    alert('错误');
			}
	    });
	}
}

function call_user_func (cb) {//模拟php的call_user_func，用参数名调用函数
	if (typeof cb === 'string') {
		func = (typeof this[cb] === 'function') ? this[cb] : func = (new Function(null, 'return ' + cb))();
	} else if (cb instanceof Array) {        
		func = ( typeof cb[0] == 'string' ) ? eval(cb[0]+"['"+cb[1]+"']") : func = cb[0][cb[1]];
	} else if (typeof cb === 'function') {
		func = cb;
	}
	if (typeof func != 'function') {
		throw new Error(func + ' is not a valid function');
	}
	var parameters = Array.prototype.slice.call(arguments, 1);    return (typeof cb[0] === 'string') ? func.apply(eval(cb[0]), parameters) :
		( typeof cb[0] !== 'object' ) ? func.apply(null, parameters) : func.apply(cb[0], parameters);
} 

function ajax_post(url,postArr,cFun,eFun){//ajax的post提交，url是post的网址，postArr是参数数组，默认了7个参数名，abcdefg，cFun是有返回值的时的处理函数，eFun是无返回值的处理函数
	$.post(url,{'a':postArr[0],'b':postArr[1],'c':postArr[2],'d':postArr[3],'e':postArr[4],'f':postArr[5],'g':postArr[6],'h':postArr[7],'i':postArr[8],'k':postArr[9],'fresh':Math.random()}, function(data){
	   if(data){
	   if(cFun==undefined){alert('OK');}
			else{call_user_func(cFun,data);}
	   }
	   else{
		   if(eFun!=undefined){call_user_func(eFun);}
	   }
	});
}

$(document).ready(function(){
    $('#PB_Page_Select').change(function(){
	    var sel_val = $('#PB_Page_Select').val();
		url=window.location.href;
		var param = url.split('&page');
		if(param[0]!=''){
		    location.href=param[0]+"&page="+sel_val;
		}
		else{
		    location.href=url+"&page="+sel_val; 
		}
	});
});


