﻿
var time=0; //顶部购物衔接闪烁次数
var timeout;
var url = "Ajax.aspx";
var over=true;
var xmlObj = null; 

if(window.XMLHttpRequest)
{
     try {
            xmlObj = new XMLHttpRequest();
         }
     catch(e)
        {
           xmlObj = false;
        }    
}
else if(window.ActiveXObject)
{
    try 
    {
         xmlObj = new ActiveXObject("MSXML2.XMLHTTP");
    }
    catch(e)
    {
      try
       {
          xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
       }
      catch(e)
      {
        xmlObj = null;
      }
    }   
}


//获取控件Id
function $(ctlName)
{
    return document.getElementById(ctlName);
}

function AddCart(id)
{
    //首页异步加入购物车
    time=0;
    clearTimeout(timeout);    
    var tempUrl = url+"?type=addcart&pId="+id+"&time="+Math.random();  
     xmlObj.open("GET",tempUrl,true);                   
        xmlObj.onreadystatechange = function(){
            if(xmlObj.readyState == 4 && xmlObj.status==200)
            {                
                $("top_cart_count").innerHTML=xmlObj.responseText;
                if(xmlObj.responseText.length<10)    
                {
                    alert("Add the product into the cart success!");
                    window.location.href='shopcart.aspx';
                }
                else
                {
                    alert("The product already in the shopping cart！");
                    window.scrollTo(0,0);
                }
                ShowCartLink();              
            }
        }
        xmlObj.send(null); 
}

/*闪烁效果js*/
function ShowCartLink()
{
    if(time<14)    
    {
        if($("top_cart").className=="top_cart")
            $("top_cart").className="top_cart_active";
        else
            $("top_cart").className="top_cart";
            
        timeout = setTimeout("ShowCartLink()",200);
        time=time+1;    
    }
    else    
    {
        clearTimeout(timeout);        
        $("top_cart").className="top_cart";
    }
}

/*判断按键*/
function enterkey(e,url)
{
    if (e==13)
    {
        location.href=url; 
        return false;
    }
}

/*产品展示，信息轮换*/
function DoChange(ctl,part)
{
    $("p1").className="";
    $("p2").className="";
    $("p3").className="";
    $(ctl).className="current";
    $("poverview").style.display='none';
    $("pspec").style.display='none';
    $("preview").style.display='none';
    $(part).style.display="block";
    $(ctl).blur();
    
}

function WinOpen(url,height,width,scroll)
{
    window.open (url, "newwindow", "height="+height+", width="+width+", top=0, lef t=0, toolbar=no, menubar=no, scrollbars="+scroll+",resizable=no,location=no, status=no");
}

//Add View
function AddView(id)
{
    var tempUrl = url+"?type=productview&pId="+id+"&time="+Math.random();  
    xmlObj.open("GET",tempUrl,true);
    xmlObj.send(null); 
}