﻿$(document).ready(function() {
	//图片闪动
	/*
    $('.pics').each(function() {
		$(this).cycle({
		    fx:    'fade',
		    speed:  2500
		 });
    });
	*/ 	
	$(".thumb").LoadImage(true,160,240); //略所图初始化
	$(".thumb").each(function(){
			//$(this).mouseover(disph(event,$(this).src));
			//$(this).mouseover(function(){disph(event,$(this).attr("src").replace("small","big"))});
			$(this).mouseover(function(){disph(event,$(this).attr("src"))});
			
			$(this).mouseout(function(){closph()});
	
	});

	
	$("#ThisImg").LoadImage(true,400,600);  //大图略所初始化

	if($.cookie('cartnum')=="") $('#cartbox').text("购物篮是空的");
	if($.cookie('cartnum')!="") $('#cartnum').text($.cookie('cartnum'));//购物商品数
	if($.cookie('cartprice')!="") $('#cartprice').text($.cookie('cartprice'));//购物商品数
	
		//自动记录收货信息
		if($.cookie('Company_Address')!="") $('#Company_Address').val($.cookie('Company_Address'));//地址
		if($.cookie('Company_Name')!="") $('#Company_Name').val($.cookie('Company_Name')); //姓名
		if($.cookie('Tel')!="") $('#Tel').val($.cookie('Tel'));
		if($.cookie('Mobile')!="") $('#Mobile').val($.cookie('Mobile'));
		if($.cookie('PostCode')!="") $('#PostCode').val($.cookie('PostCode'));
		if($.cookie('QQ')!="") $('#QQ').val($.cookie('QQ'));
		
		//验证登陆状态
		initLogin();

		//最新销售
    jQuery('#mycarousel').jcarousel({
        auto: 0,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
    
    
   //客服显示隐藏
    
    $("#showkefu").click( function() { 
   				document.getElementById("kefuframe").style.display="";
   				$.cookie('showkefu','yes',{expires:300});
   			  //alert($.cookie('showkefu'));
    });  
    $("#hidekefu").click( function() { 
   				document.getElementById("kefuframe").style.display="none";
   				$.cookie('showkefu','no',{expires:300});
   			 // alert($.cookie('showkefu'));
    });     
     
 
      if($.cookie('showkefu')=="no")
   		{
   		 		document.getElementById("kefuframe").style.display="none";
   		}
   		else
   		{
   				document.getElementById("kefuframe").style.display="";
   		}	
      
   //   alert($.cookie('showkefu'));
   //客服显示隐藏 
  
		
});


function openCart(_productid,_action,_num)
{	
	var _productid,_action,_num;
		//$("#cart").html("购物车加载中...");
			$("#cart").load("/cart.asp?Product_ID="+_productid+"&action="+_action+"&num="+_num); 
		  $('#cart').jqm();
		  $('#cart').jqmShow();
 
}
 
function closeCart()
{
 	$('#cart').jqmHide(); 
}
function closeLoad()
{
 	$('#loading').jqmHide(); 
}

function closeOrder()
{
 	$('#order').jqmHide(); 
}
function openOrder()
{
	$(document).ready(function() { 
		$("#cart").load("/order.asp"); 	 	
		$('#cart').jqm();
 		$('#cart').jqmShow();
	
 	}); 
}

function openImage(_productid)
{
	
	var _productid;
		$("#cart").load("/showpic-"+_productid+".html"); 	 	
		$('#cart').jqm();
 		$('#cart').jqmShow();
}

function login()
{
		$("#cart").load("/content/login.asp"); 	 	
		$('#cart').jqm();
 		$('#cart').jqmShow();
		
}

function checkLogin(_productid)
{
	var _productid;
	if($("#UserName").val()=="")
	{
		alert("请输入姓名");	
		return false;
	}		
	if($("PassWrod").val()=="")
	{
		alert("请输入密码");
		return false;	
	}
	//return false;
			$.post("/ajax.asp?control=company&action=login", { 
					Company_Name:$("#UserName").attr("value"),
					Mobile:$("#PassWord").attr("value")
				},
			  function(_xml){
					if($(_xml).find("Company_SN").text()=="")
					{
						alert("姓名与手机号码不符,请仔细核对。");
						//return false;	
					}
					else
					{
						
						if($(_xml).find("Active").text()=="")
						{
								alert("您的经销商或加盟资格未激活，请联系客服人员进行激活。");
								$.cookie('Active',false,{expires:300});								
								return false;
						}
						else
						{
							if(_productid) 
							{
								$.cookie('Active',true,{expires:300});								
								initLogin();
								openImage(_productid);

							}
							else
							{
								alert("登陆成功");
								$.cookie('Active',true,{expires:300});								
								//closeCart();
							}	
							$.cookie('UserName',$('#UserName').val(),{expires:300});
							$.cookie('PassWord',$('#PassWord').val(),{expires:300});
						}	
						initLogin();

					}

			   });	
}

function offLogin()
{
	$.post("/ajax.asp?control=company&action=offlogin", { 
	},
		function(_xml){
			initLogin();
		}
	);			
}

function initLogin()
{
	if($.cookie('UserName'))
	{
		if($.cookie('Active'))
		{
			$("#loginBar").html("欢迎您,<font color=red>"+$.cookie('UserName')+"</font> <a href=javascript:orderSearch('"+$.cookie('UserName')+"','"+$.cookie('PassWord')+"')>查看我的订单</a>&nbsp;<span align=right>[<a href='javascript:offLogin();'>退出</a>]</span>");	
		}
		else
		{
			$("#loginBar").html("您好,<font color=red>"+$.cookie('UserName')+"</font>,您的帐户未激活&nbsp;<span align=right>[<a href='javascript:offLogin();'>退出</a>]</span>");
		}	
	}
	else
	{
		var str = "";
		str+="<table border=0 width=100% cellpadding=0 cellspacing=0>";
		str+="	<tr>";
		str+="		<td rowspan=2><table border=0 cellpadding=0 cellspacing=0 width=100% id=table1><tr><td>姓名</td><td><input style='height:15px;' type=text size=6 id=UserName name=T1></td><td> 手机</td><td><input type=text size=6 style='height:15px;' id=PassWord></td><td><input  type=button value=登陆 onclick=checkLogin()></td></tr></table></td>";
		str+="		<td><a href=/pifa.html>申请批发</a></td>";
		str+="	</tr>";
		str+="	<tr>";
		str+="		<td><a href=/jiameng.html>申请加盟</a></td>";
		str+="	</tr>";
		str+="</table>		";
		$("#loginBar").html(str);
	}		
}

function orderSearch(c,m)
{
	//alert();
	var f = document.createElement("form");
	f.method="POST";
	document.body.appendChild(f);
	var i = document.createElement("input");
	i.type = "hidden";
	f.appendChild(i);
	i.value = c;
	i.name = "Company_Name";
	var j = document.createElement("input");
	j.type = "hidden";
	f.appendChild(j);
	j.value = m;
	j.name = "Mobile";	
	f.action = "ordersearch.html";
	f.submit();
}

function submitSearch()
{
	if($("#keys").val()=="")
	{
		alert("请输入要搜索的内容");
		return false;
	}
	else
	{
		location.href("/productclass-0-1-Product-"+$('#tbname').val()+"-"+$('#keys').val()+".html");
		//alert("抱歉,搜索功能调整中.");
		return false;
	}	

}

function submitOrder(_action,_type)
{
	var _action;
	if(!_action) _action="product";
		if($("#Company_Address").attr("value")==""){alert('请输入送货地址');return};
		if($("#Company_Name").attr("value")==""){alert('请输入收件人');return};
		if($("#Mobile").attr("value")==""){alert('请输入手机号');return};
		
		if($("#ordermobile").attr("value")==""){alert('手机号码必须填写');return};
		if($("#PostCode").attr("value")==""){alert('请输入邮政编码');return};
		//if($("#orderemail").attr("value")==""){alert('Email地址必须填写');return};
		if(_action=='product')
		{
			$.post("ajax.asp?control=order&action=save", { 
					//contentType: "charset=gb2312",
					Company_Address:$("#Company_Address").attr("value"),
					Company_Name:$("#Company_Name").attr("value"),
					Mobile:$("#Mobile").attr("value"),
					QQ:$("#QQ").attr("value"),
					PostCode:$("#PostCode").attr("value"),
					Tel:$("#Tel").attr("value")
				},
			  function(data){
			    //alert(data);
					//$("#loading").html(data);
				//alert("您的订单已经受理，请根据提示的进行汇款，我们会在收到您的汇款后进行工厂下单进行生产。");
				
					var str=	"<table border=0 width=100% align=center>";
							str+=		"<tr><td colspan=2 align=center>您的订单已经受理，请根据提示的进行汇款，我们会在收到您的汇款后进行工厂下单进行生产。</td></tr>";
							str+=		"<tr>";
							str+=			"<td align=left rowspan=2>付款方式：</td>";
							str+=			"<td align=left valign=middle>";
							str+=			"<a href=ali/index.asp target=_blank><img align=absmiddle src=/alipay/images/alipay_bwrx.gif border=0></a><a target=_blank href=/paybank.asp ><img  align=absmiddle  align=absmiddle src=/alipay/images/bank.gif /></a>";
							str+=			"</td>";
							str+=		"</tr>";
							str+=		"<tr><td colspan=2  align=center>";
							str+=		"</td></tr>";
							str+=	"</table>	";					
					//alert(str);
					/**/
					//$("#orderform").html(str);
					//document.getElementById("ordersearch").submit();
					/*
			 		$("#cart").load("content/huikuan.asp"); 	//登陆初始化
					$('#cart').jqm();
			 		$('#cart').jqmShow();		 		
			   	*/
			   	//银行方式
				   	if(_type=='bank')
				   	{
				   		document.getElementById("ordersearch").submit();
				   	}
				  //支付宝方式 	
				   	if(_type=='alipay')
				   	{
				   		location.href('/alipay/index.asp');	
				   	}
					  //银行付款 	
				   	if(_type=='netbank')
				   	{
				   		location.href('/ali/index.asp');	
				   	}			   	
				   	
			   });
			}
			
		if(_action=='gift')
		{
			var gift_id;
			if(!$('input[@name=Gift_ID][@checked]').val()){
				alert("请选择申请的礼品。");
				return;	
			}

			$.post("ajax.asp?control=gift&action=save", { 
					//contentType: "charset=gb2312",
					Gift_ID:$('input[@name=Gift_ID][@checked]').val(),
					Company_Address:$("#Company_Address").attr("value"),
					Company_Name:$("#Company_Name").attr("value"),
					Mobile:$("#Mobile").attr("value"),
					QQ:$("#QQ").attr("value"),
					PostCode:$("#PostCode").attr("value"),
					Tel:$("#Tel").attr("value")
				},
			  function(data){
			    //alert(data);
					//$("#loading").html(data);
					alert("您的礼品申请信息已经受理，我们会在审核过您的样片后给您邮寄礼品。");
					location.reload();
					//document.getElementById("ordersearch").submit();
					/*
			 		$("#cart").load("content/huikuan.asp"); 	//登陆初始化
					$('#cart').jqm();
			 		$('#cart').jqmShow();		 		
			   	*/
			   });
			}
	if(_action=='company')
		{
			$.post("ajax.asp?control=company&action=save", { 
					//contentType: "charset=gb2312",
					Company_Address:$("#Company_Address").attr("value"),
					Company_Name:$("#Company_Name").attr("value"),
					Mobile:$("#Mobile").attr("value"),
					QQ:$("#QQ").attr("value"),
					PostCode:$("#PostCode").attr("value"),
					Tel:$("#Tel").attr("value")
				},
			  function(data){
			    //alert(data);
					//$("#loading").html(data);
					alert("您的加盟申请已经受理，请联系我们的客服为您激活帐号. ");
					$("#submitorder").attr("disabled","true");
					//document.getElementById("ordersearch").submit();
					/*
			 		$("#cart").load("content/huikuan.asp"); 	//登陆初始化
					$('#cart').jqm();
			 		$('#cart').jqmShow();		 		
			   	*/
			   });
			}						
			
	if(_action=='pifa')
		{
			$.post("/ajax.asp?control=pifa&action=save", { 
					//contentType: "charset=gb2312",
					Company_Address:$("#Company_Address").attr("value"),
					Company_Name:$("#Company_Name").attr("value"),
					Mobile:$("#Mobile").attr("value"),
					QQ:$("#QQ").attr("value"),
					PostCode:$("#PostCode").attr("value"),
					Tel:$("#Tel").attr("value")
				},
			  function(data){
			    //alert(data);
					//$("#loading").html(data);
					alert("您的批发申请已经受理，请尽快和客服联系激活您的查看批发价权限。");
					$("#submitorder").attr("disabled","true");
					//document.getElementById("ordersearch").submit();
					/*
			 		$("#cart").load("content/huikuan.asp"); 	//登陆初始化
					$('#cart').jqm();
			 		$('#cart').jqmShow();		 		
			   	*/
			   });
			}
			
}

function uploadPhoto(_productid)
{
			var _productid;
			$("#loading").load("/photo/?id="+_productid+""); 
		  $('#loading').jqm();
		  $('#loading').jqmShow();
		
}


function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

//图片缩放开始

var xl,xl_img;
var pubtm="close";
function phheight(){
var h=320;
if(xl_img.height<h){
xl_img.height+=15;
setTimeout("phheight()",2);}
}

function disph(a,url){
xl=document.getElementById("viewpic");
xl_img=document.getElementById("viewpic_img");


ev = event || window.event;
var iX = ev.clientX;
var iY = ev.clientY;

var scrollPos; 
if (typeof window.pageYOffset != 'undefined') { 
   scrollPos = window.pageYOffset; 
} 
else if (typeof document.compatMode != 'undefined' && 
     document.compatMode != 'BackCompat') { 
   scrollPos = document.documentElement.scrollTop; 
} 
else if (typeof document.body != 'undefined') { 
   scrollPos = document.body.scrollTop; 
}


if(iX+200>window.screen.availWidth){xl.style.left = (iX-200) + "px";}
else{xl.style.left = (iX-50) + "px";}
xl.style.top = (scrollPos+iY) + "px";

if(pubtm=="close"){
xl_img.height=0;
xl_img.src=url;
xl.style.display="none";
xl.style.display='';
xl.style.overflow='hidden';

phheight();
pubtm="open";
}
}

function closph(){
xl.style.display='none';
pubtm="close";
}

//图片缩放结束