function productSort(){
	$.get("Product.php",{Rtype:"Sort"},
		function(data){
			var cateData = eval('(' + data + ')');
			var cateMsg = '<ul><li><a href="javascript:void(0);" onclick="product(0,0,1,\'\',0)">全部分类</a></li>';
			
			for (var i=0;i<cateData.length;i++){
				cateMsg+='<li><a href="javascript:void(0);" onclick="product('+cateData[i].id+',0,1,\'\',0)">'+cateData[i].sort_name+'</a></li>';
			}
			cateMsg +='</ul>';
			$("#cateMsg").html(cateMsg);
	});

}

function productStyle(){
	$.get("Product.php",{Rtype:"Style"},
		function(data){
			var styleData = eval('(' + data + ')');
			var styleMsg = '';
			for (var i=0;i<styleData.length;i++){
				styleMsg+='<label class="checkbox inline"><input type="radio" name="styleId" value="'+styleData[i].id+'"> <span class="en_a7">'+styleData[i].style_name+'</span></label>';
			}
			$("#styleMsg").html(styleMsg);

	});
}

function product(sortId,styleId,page,product,orderType){
	$.get("Product.php",{Rtype:"product",sortId:sortId,styleId:styleId,page:page,product:product,orderType:orderType},
		function(data){
			showprobox(data,sortId,styleId,page,product,orderType);
	});
}

function showprobox(data,sortId,styleId,page,product,orderType){
var retData = eval('(' + data + ')');
			var lpag,rpage;
			var pagemsg='';
			var pro='';
			var page=retData.page;
			if(retData.Total==0){
				$("#probox").html('No Data');
				$("#pageMsg").html('');
			}else{
			//处理Page
			if (page=="1"){
				pagemsg='<li><a href="javascript:void(0);" onclick="product('+sortId+','+styleId+',1,\''+product+'\','+orderType+')">Prev</a></li>';
			}else{
				pagemsg='<li><a href="javascript:void(0);" onclick="product('+sortId+','+styleId+','+(page-1)+',\''+product+'\','+orderType+')">Prev</a></li>';	
			}
			if(page>3){lpage=(page-3)}else{lpage=1}
			if(page>(retData.TotalPage-3)){rpage=retData.TotalPage}else{rpage=(parseFloat(page)+3)}

			for (var i=lpage;i<=rpage;i++){
				if (page==i){
					pagemsg+='<li class="active"><a href="javascript:void(0);" onclick="product('+sortId+','+styleId+','+i+',\''+product+'\','+orderType+')">'+i+'</a></li>';
					}else{
					pagemsg+='<li><a href="javascript:void(0);" onclick="product('+sortId+','+styleId+','+i+',\''+product+'\','+orderType+')">'+i+'</a></li>';
				}
			}
			if (page==retData.TotalPage){
				pagemsg += '<li><a href="javascript:void(0);" onclick="product('+sortId+','+styleId+','+retData.TotalPage+',\''+product+'\','+orderType+')">Next</a></li>';
			}else{
				pagemsg += '<li><a href="javascript:void(0);" onclick="product('+sortId+','+styleId+','+(parseInt(page)+1)+',\''+product+'\','+orderType+')">Next</a></li>';	
			}
			
		  //处理产品数据
			for (var j=0;j<retData.productGroup.length;j++){
			pro+=Showproduct(retData.productGroup[j].pro_name,retData.productGroup[j].pro_sort,retData.productGroup[j].pro_content,retData.productGroup[j].pro_sn,retData.productGroup[j].pro_picmid,retData.productGroup[j].pro_picbig);
			}
			
			$("#probox").html(pro);
			$("#pageMsg").html(pagemsg);
			}	
	
}


function Showproduct(pro_name,pro_sort,pro_content,pro_sn,pro_picmid,pro_picbig){
var ShowStr='';
ShowStr+='<li><a href="#" class="en_a3"><img src="http://img.zhihuiapp.com'+pro_picmid+'" /></a> ';
ShowStr+='<p class="en_a4">'+pro_name+'</p> ';
ShowStr+='<p class="en_a5">产品编号：'+pro_sn+'</p>';
ShowStr+='<p class="en_a5">行业分类：'+pro_sort+'</p>';
ShowStr+='<p class="en_a5">购买咨询：'+contactTel+'</p>';
ShowStr+='<p class="en_a6">简介：'+pro_content+'</p>';
ShowStr+='<p>';
ShowStr+='<a href="javascript:void(0);" data-reveal-id="myModal-'+pro_sn+'" class="btn btn-primary" >查看</a> ';
ShowStr+='<a href="javascript:void(0);" data-reveal-id="myModal1-'+pro_sn+'" class="btn" >试用</a>';
ShowStr+='</p>';
ShowStr+='<div id="myModal-'+pro_sn+'" class="reveal-modal">';
ShowStr+='<div class="container-fluid">';
ShowStr+='<div class="row-fluid">';
ShowStr+='<div class="span12">';
ShowStr+='<div id="slideBox-'+pro_sn+'"><div class="bdbox">';
ShowStr+='<div class="picleft"><ul>';
if (pro_picbig.length>0){
	var strs= new Array();
	strs=pro_picbig.split(",");
	for (var i=0;i<strs.length;i++){
		ShowStr+='<li><img alt="" src="http://img.zhihuiapp.com'+strs[i]+'" /></li>';
	}
}else{
ShowStr+='';
}
ShowStr+='</ul></div></div> <a class="prev left carousel-control" href="javascript:void(0)"><</a>';
ShowStr+='<a class="next right carousel-control" href="javascript:void(0)">></a>';
ShowStr+='</div>';
ShowStr+='<script type="text/javascript">';
ShowStr+='jQuery("#slideBox-'+pro_sn+'").slide({mainCell:".picleft ul",effect:"leftLoop",autoPlay:false,delayTime:1000})';
ShowStr+='</script>';
ShowStr+='</div>';
ShowStr+='</div>';
ShowStr+='</div>';
ShowStr+='<a class="close-reveal-modal">&#215;</a>';
ShowStr+='</div>';
ShowStr+='<div id="myModal1-'+pro_sn+'" class="reveal-modal1">';
ShowStr+='<div class="container-fluid">';
ShowStr+='<div class="row-fluid">';
ShowStr+='<div class="span12">';
ShowStr+='<h4  style="margin-left:13%;">企业app账户注册</h4>';
ShowStr+='<form class="form-horizontal" name="form" action="Reg.asp" method="post">';
ShowStr+='<input type="hidden" name="mbId" value="'+pro_sn+'" /><div class="control-group">';
ShowStr+='<label class="control-label" for="inputEmail">用户名</label>';
ShowStr+='<div class="controls"><input id="inputEmail" type="text" name="userName" /></div>';
ShowStr+='</div>';
ShowStr+='<div class="control-group">';
ShowStr+='<label class="control-label" for="inputPassword">密码</label>';
ShowStr+='<div class="controls"><input id="inputPassword" type="password" name="userPass" /></div>';
ShowStr+='</div>';
ShowStr+='<div class="control-group">';
ShowStr+='<label class="control-label" for="inputPassword">确认密码</label>';
ShowStr+='<div class="controls"><input id="inputPassword" type="password" name="userPass2" /></div>';
ShowStr+='</div>';
ShowStr+='<div class="control-group">';
ShowStr+='<div class="controls"> ';
ShowStr+='<button type="submit" class="btn btn-primary">立即注册</button> ';
ShowStr+='<a href="http://admin.lanhaipingtai.com/adminclient/TestApp.asp?MbSn='+pro_sn+'" target="_blank" class="btn">直接进入测试</a>';
ShowStr+='</div></div>';
ShowStr+='</form>';
ShowStr+='</div></div></div></div>';		  
ShowStr+='</li>';

return ShowStr;
}

function sear(sortId,styleId,page,product,orderType){
	var styleId=$('input[name="styleId"]:checked').val();
	var ordertype=$("#ordertype").val();
	var product=$('input[name="product"]').val();
	$.get("Product.php",{Rtype:"product",sortId:0,styleId:styleId,page:1,product:product,orderType:ordertype},
		function(data){
			showprobox(data,0,styleId,1,product,ordertype);
	});
}

$(document).ready(function(){
	productSort();productStyle();product(0,0,1,'',0);
});