﻿ var purl="http://shop.qumei.com/";
 
 
function clickHandler(menuId) 
{
for(var i=1;i<=4;i++)
{document.getElementById("details"+i).style.display='none'}
for(var i=1;i<=4;i++)
	if(i+1==menuId)
	    {document.getElementById("details"+menuId).style.display='none';
	}
	else
	{
	    document.getElementById("details"+menuId).style.display=''
	}
}
function HidHandler()
{
  for(var i=1;i<=4;i++)
    {document.getElementById("details"+i).style.display='none'}  
}
/*---------------------------------------MyCart------------------------------------------*/
//var Dtimeout;
//var Dspeed;
var Dtimer=null;
var Dtimer2=null;
var IsGetCart = true;
var Mdisplay=false;
var hideDiv;
var Container;
var button;
var jqShowObj;
var offset;
var height;
var width;
var btnHeight;
var btnWidth;
function initDMenu(obj,showobj,Dtimeout,Dspeed){
//	Dtimeout=Dtimeout?Dtimeout:300;
//	Dspeed=Dspeed?Dspeed:100;
	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=jqShowObj.width();
	btnHeight=button.height();
	btnWidth=button.width();
	$(document.body).prepend(hideDiv);
}
function showDMenu(){
	if (Mdisplay==true){
		return false;
	}else{
		Mdisplay=true;
		Container.css({margin:"0 auto",width:btnWidth+"px",height:btnHeight+"px"});
		hideDiv.css({position:"absolute",top:offset.top+16+"px",left:button.offset().left-35+"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.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',opacity:'0'},100,function(){
			Container.hide();
			hideDiv.hide();
			Mdisplay=false;
			});
		}, 100); 
}


$(document).ready(function(){
    if(IsGetCart)
    {
        initDMenu("#CartSwitch_wrap","#MiniCartDiv");
        $("#CartSwitch_wrap").mouseover(function(){
        clearTimeout(Dtimer);
            height=$("#MiniCartDiv").height();
            Dtimer=setTimeout("showDMenu()",100); 
        }).bind("mouseleave",function(){
            clearTimeout(Dtimer); 
            if(Mdisplay==true){
                Dtimer2=setTimeout("hideDMenu()",100);
            }
        }); 
        ShowMiniCart();        
    }
 
    $("#textfield").keydown(function(event){
        if(event.keyCode==13){ $("#imgSearch").click();return false;}}).mousemove(function(){if($("#textfield").val() == "输入产品编码查询"){ $("#textfield").val("");}$("#textfield").focus()}).mouseout(function(){if($.trim($("#textfield").val()).length<=0){$("#textfield").val("输入产品编码查询");}$("#textfield").blur()}); 
    $("#imgSearch").click(function()
    {
        if($("#textfield").val()!= "输入产品编码查询" && $.trim($("#textfield").val()).length>0)
        {
            location.href=purl+"Customer/CustomerSearchProduct.aspx?productcode="+escape($("#textfield").val());
        }
        else
        {
            alert("请输入产品编号！");
        }
    });
    $("#logout").click(function()
    {
        if(confirm("确认要退出么？"))
        {
            $.ajax({
                type: "GET",
                url: purl+"ajaxServer/ajaxCommon.aspx",
                data: "action=logout&Id=0",
                dataType:"text",
                cache:false,
                success:  function(result){
                     //alert(result);
                     location.href=purl+"index.shtml";
                }
            }); 
        }
    });
}); 


function ShowMiniCart()
{
    $.ajax({
        type: "GET",
        url: purl+"ajaxServer/ForShoppingCart.aspx",
        data: "action=minicart&ID=0&productCount=0",
        dataType:"html",
        cache:false,
        success:  function(result){
            $("#MiniCartDiv").html(result);
       }
    }); 
}

function removeMiniProduct(ID)
{
    if(confirm('确定不购买该商品？'))
    {
        $.ajax({
            type: "GET",
            url: purl+"ajaxServer/ForShoppingCart.aspx",
            data: "action=remove&ID="+ID+"&productCount=0",
            dataType:"html",
            cache:false,
            success:  function(result){
                ShowMiniCart();
           }
        }); 
    }
}

function removeMiniProductTaoCan(strIDold,btcdDetailID,tcType)
{
    if(confirm('确定不购买该商品？'))
    {
        $.ajax({
            type: "GET",
            url: purl+"ajaxServer/ForShoppingCart.aspx",
            data: "action=removeTC&ID=0&productCount=0&strIDold="+strIDold+"&tcType="+tcType+"&btcdDetailID="+btcdDetailID,
            dataType:"html",
            cache:false,
            success:  function(result){
                ShowMiniCart();
           }
        }); 
    }
}