﻿
/*
搜索
*/

window.document.onkeydown = KeyStroke; 
function KeyStroke(){          
    if(event.keyCode == 13)             
         window.event.returnValue = false;               
}

function changeCode()
{
    if(event.keyCode==13 && (event.srcElement.id == "word" || event.srcElement.id == "word")){
        document.getElementById("header_search").focus();
        go_Search();
    } 
    else
    {
        document.getElementById("header_search").value +="";
//        alert(event.keyCode);
        //ajax_url = "../ajaxServer/AutoText.aspx?Action=Header";
    }
}


/*
header search
*/
function go_Search()
{
    var keys = document.getElementById("word");   
    
    var url = '/list.aspx?s=1';
    
    if(keys.value != "" && keys !="请输入关键字(支持中文/简拼/全拼搜索)")
    {
        url += "&key=" + escape(keys.value) + "";
    }  
    window.location.href = url; 
   
}




/*
header Popup Div 头部弹出层显示购物车中商品
*/
var Dtimer=null;
var Dtimer2=null;
var Mdisplay=false;
var hideDiv;
var Container;
var button;
var jqShowObj;
var offset;
var height;
var width;
var btnHeight;
var btnWidth;
var CartCnt=0;
function initDMenu(obj,showobj){
	hideDiv=$("<div style='z-index:10000'></div>");
	Container=$("<div id=\"Container\" ></div>");
	hideDiv.append(Container);
	button=$(obj);
	jqShowObj=$(showobj);
	offset=button.offset();
	height=jqShowObj.height();
    width=320;
	btnHeight=button.height();
	btnWidth=button.width();
	$(document.body).prepend(hideDiv);
}
//显示层
function showDMenu(){
	if (Mdisplay==true){
		return false;
	}else{
		Mdisplay=true;
		OpenDiv_Press();
		 if(CartCnt==0)
        {
            height=70;
        }
        else{
            height=(CartCnt-1)*80+130;
         
        }
		Container.css({padding:"0 auto",width:btnWidth+"px",height:btnHeight+"px"});
		hideDiv.css({position:"absolute",top:offset.top+7+"px",left:button.offset().left-130+"px",height:height+"px",width:width+"px"}).show();                
		Container.css({border:"1px solid #666666"});
		Container.animate({marginTop:10,height:height+4,width:width+4,opacity:'100'},100,function(){	
		    //jqShowObj.html("aaa，赶快去购物吧！<br/>aaa，赶快去购物吧！<br/>aaa，赶快去购物吧！<br/>");	
		   // OpenDiv_Press();													
			jqShowObj.show();
			Container.append(jqShowObj);
			Container.css({border:"0px"});
			jqShowObj.mouseover(function(){
				clearTimeout(Dtimer);clearTimeout(Dtimer2);
			}).mouseout(function(){
				hideDMenu();
			});			
		});
	}
}
//隐藏层
function hideDMenu(){
	clearTimeout(Dtimer);
	clearTimeout(Dtimer2);
	Dtimer=setTimeout(function(){
		Container.css({border:"1px solid #666666"});
		$(document.body).prepend(jqShowObj);
		jqShowObj.hide();
		Container.empty();
		Container.animate({width:btnWidth,height:btnHeight,marginTop:'0'},100,function(){
			Container.hide();
			hideDiv.hide();
			Mdisplay=false;
			});
		}, 100); 
}
//header carShow
function OpenDiv_Press()
{ 
    var ajaxUrl = "/ajaxServer/ForShoppingCart.aspx";
    var request = "action=isShopCart";
    var cartNumber = document.getElementById("header1_lbl_cartNumber");
//    if(cartNumber==null)
//    {
//        cartNumber = document.getElementById("dheader_lbl_cartNumber");
//    }
    var Msg = returnState(ajaxUrl,request);
    var ArrayMsg = new Array();
    ArrayMsg = Msg.split("※");
    jqShowObj.html(ArrayMsg[0]);
    cartNumber.innerHTML = ArrayMsg[1]; 
    CartCnt=Number(cartNumber.innerHTML);
}

/*
header carDel
*/
function Header_CartDel(id)
{
   var ajaxUrl = "/ajaxServer/ForShoppingCart.aspx";
   var request = "action=isDel&pressid="+id;
   var val =  returnState(ajaxUrl,request);
   OpenDiv_Press();
}

//动态体验
$(function(){
    //initDMenu(document.getElementById("CartSwitch_wrap"),document.getElementById("div_ShopCartMsg"));
	initDMenu("#CartSwitch_wrap","#div_ShopCartMsg");
	$("#CartSwitch_wrap").mouseover(function(){
		clearTimeout(Dtimer);
		height=$("#div_ShopCartMsg").height();
		Dtimer=setTimeout("showDMenu()",200); 
	}).bind("mouseout",function(){
		clearTimeout(Dtimer); 
		if(Mdisplay==true){
			Dtimer2=setTimeout("hideDMenu()",200);
		}
	}); 
})

$(function(){
    //initDMenu(document.getElementById("CartSwitch_wrap"),document.getElementById("div_ShopCartMsg"));
	initDMenu("#CartSwitch_img","#div_ShopCartMsg");
	$("#CartSwitch_img").mouseover(function(){
		clearTimeout(Dtimer);
		height=$("#div_ShopCartMsg").height();
		Dtimer=setTimeout("showDMenu()",200); 
	}).bind("mouseout",function(){
		clearTimeout(Dtimer); 
		if(Mdisplay==true){
			Dtimer2=setTimeout("hideDMenu()",200);
		}
	}); 
})
//集订单 用户是否登录
 function IsLogin()
 {
   var islog=isLoginUser();
   if(islog.toString()=="false")
   {
        location.href="../Member/Order_Login.aspx?action=Collect";
   }
   else
   {
       location.href="../CollectOrd/index.aspx"; 
   }
 }
 
 function IsCartNull()
 {
    var iscart = cartIsNull();
    if(iscart.toString() == "false")
    {
       alert('请先购物！');
    }
    else
    {
        location.href="/Press/Address.aspx";
    }
 }
 function returnword()
{
    if(document.getElementById("word").value == "")
        document.getElementById("word").value="请输入关键字(支持中文/简拼/全拼搜索)";
}
function delword()
{
    if(document.getElementById("word").value == "请输入关键字(支持中文/简拼/全拼搜索)")
        document.getElementById("word").value="";
}