function GetShoppingCart()
{
    var CartId = GetUrlParameter("CartId");
    var RecordCount = GetUrlParameter("RecordCount");
    var Device="";
  try{
      Device=document.getElementById("txtGetDeviceValue").value;
     }catch(e){}
     var Page="";
     if(top.location.pathname=="/ShoppingCart.aspx")
      Page="true";
     else
      Page="false";
    var ajax = new AJAX( GetAbsoluteUrl("/ShoppingCartAJAX.aspx?CartId=" + CartId + "&RecordCount=" + RecordCount+"&Device="+Device+"&Page="+Page) );
    ajax.SetCallbackFun(_GetShoppingCartCallback);
    
    ajax.Send(null);
}
function _GetShoppingCartCallback(ajax)
{
    var objDOM = ajax.GetXmlDoc();
    var isZero;
    document.getElementById("CartPanel").innerHTML = objDOM.selectSingleNode("//xmlRoot/html").text;
    document.getElementById("spnCount").innerHTML = objDOM.selectSingleNode("//xmlRoot/count").text;
    isZero = objDOM.selectSingleNode("//xmlRoot/isZero").text;
    if(isZero=="True")
    {
        try
        {
            $(CHECK_SAVETOPROFILE).checked = false;
            $(CHECK_SAVETOPROFILE).disabled="disabled";
            
            $(CTRL_Name_ID).disabled = "disabled";
            $(CTRL_Card_Verification_Code_ID).disabled = "disabled";
            $(CTRL_CARD_TYPE_ID).disabled = "disabled";
            $(CTRL_ExpireMonth_ID).disabled = "disabled";
            $(CTRL_ExpireYear_ID).disabled = "disabled";
            $(CTRL_CARD_NUMBER_ID).disabled = "disabled";
            $(BTNORIGINALCARD).disabled = "disabled";
            
            
            $(CTRL_PayPal_ID).checked = "checked";
            $(CTRL_PayPal_ID).checked = "";
            
            $(CTRL_NEW_CART_ID).disabled="disabled";
            $(CTRL_PayPal_ID).disabled="disabled";
            
            
        }
        catch(e)
        {}
    }
    
    if (document.getElementById("spnCount").innerHTML == "0") {
    
        document.getElementById('divDataShow1').style.display = 'none';
        document.getElementById('divDataShow2').style.display = 'none';
        
        document.getElementById('spnCartSubTotal').style.display = 'none';
        document.getElementById('spnSubtotal').style.display = 'none';
        document.getElementById('spnCount2').style.display = 'none';
        var str_message = (top.strLang=="English")?"You have no items in your cart":"Votre panier ne contient aucun article.";
        document.getElementById('spnItems').innerHTML = str_message;
        document.getElementById('CartPanel').style.height = '80px';
        
    } else if (document.getElementById("spnCount").innerHTML == "1") {
    
        document.getElementById('divDataShow1').style.display = 'block';
        document.getElementById('divDataShow2').style.display = 'none';
        document.getElementById('CartPanel').style.height = '300px';
        
        document.getElementById('spnCartSubTotal').style.display = 'inline';
        document.getElementById('spnSubtotal').style.display = 'inline';
        document.getElementById('spnCount2').style.display = 'inline';
        
    } else if (document.getElementById("spnCount").innerHTML > "1") {
    
        document.getElementById('divDataShow1').style.display = "block";
        document.getElementById('divDataShow2').style.display = "block";
        document.getElementById('CartPanel').style.height = '400px';
        
        document.getElementById('spnCartSubTotal').style.display = 'inline';
        document.getElementById('spnSubtotal').style.display = 'inline';
        document.getElementById('spnCount2').style.display = 'inline';
    }
//	Event.observe('cartBtn', 'click', function() 
//	{
//		// make sure there's no other effects happening on the page
//		if (Effect.Queue.effects.length > 0) return;
//		
//		if (!$('cartBody').visible()) 
//		{
//			openCart();
//		}
//		else 
//		{
//			closeCart();
//		}
//	});
}
//function openCart() 
//{
//	if(!$('cartTop').visible()) 
//	{
//		Effect.SlideDown('cartBody', {duration: 0.6});
//		$('cartBtn').style.background = "url(/img/btnCartOutBg.gif) no-repeat";
//		$('cartTop').show();
//	}
//}
//function closeCart() 
//{
//	if($('cartTop').visible()) 
//	{
//		$('cartBtn').style.background = "url(/img/btnCartBg.gif) no-repeat";
//		Effect.SlideUp('cartBody', {duration: 0.6});
//		setTimeout (function() 
//		{
//			$('cartTop').hide();
//		}, 600);
//	}
//}
function closeTheCart() 
{
	if($('cartTop').visible()) 
	{
		$('cartBtn').style.background = "url(/img/btnCartBg.gif) no-repeat";
		Effect.SlideUp('cartBody', {duration: 0.6});
		setTimeout (function() 
		{
			$('cartTop').hide();
		}, 600);
		alert(GetStr(2503));
		setTimeout(function(){ShowLoginRegister();},800);
	}
}
function closeTheCarts(CartId,RecordCount) 
{
	if($('cartTop').visible()) 
	{
		$('cartBtn').style.background = "url(/img/btnCartBg.gif) no-repeat";
		Effect.SlideUp('cartBody', {duration: 0.6});
		setTimeout (function() 
		{
			$('cartTop').hide();
		}, 600);
		alert(GetStr(2503));
		setTimeout(function(){ShowLoginRegisterbyShopCart(CartId,RecordCount);},800);

	}
}
function ShowLoginRegisterbyShopCart(CartId,RecordCount)
{
    var logOrReg=true;
    try{
        logOrReg=obj!="reg"?true:false;
    }catch(err){
        logOrReg = true;
    }
    var httppost = top.location.protocol+"//";
    
    var querys = "/ShoppingCart.aspx?CartId=" + CartId + "&RecordCount=" + RecordCount;
    if(logOrReg)
    {
        var logcurUrl=httppost+top.location.host+"/Login.aspx?targeturl="+querys;
        top.location = logcurUrl; 
    }
    else
    {
        var regcurUrl=httppost+top.location.host+"/Registration.aspx?targeturl="+querys;
        top.location = regcurUrl; 
    }
}
function closeTheCart2() 
{
	if($('cartTop').visible()) 
	{
		$('cartBtn').style.background = "url(/img/btnCartBg.gif) no-repeat";
		Effect.SlideUp('cartBody', {duration: 0.6});
		setTimeout (function() 
		{
			$('cartTop').hide();
		}, 600);
	}
}
function _AddToCartCallback(unused) 
{
   GetShoppingCart();
}
var g_strLast = "";
function AddToTheCart(productPk)
{
    if( g_strLast == productPk )
        return;
        
    g_strLast = productPk;
   
    productPk = productPk.substring( 3 );
    if(!proxies.ProxyService.ValidateProductId(parseInt(productPk, 10)))
   {
      alert(GetStr(2504));
      return;
   }
    proxies.ProxyService.AddToCart.func = _AddToCartCallback;
    proxies.ProxyService.AddToCart( parseInt(productPk, 10) );
    
    proxies.ProxyService.AddToCart.onException = function (e1) { alert(e1); }
    s_pageState="sc:add";
    s_sendPageName("ShoppingCart:AddToCart","ShoppingCart","sc:add",";"+productPk);//add by paul.liu
   ak()
}

function GotoShopCartPage(CartId,RecordCount)
{
    if(!proxies.ProxyService.HasDevices(proxies.ProxyService.CurrentCustomerID()))
    {
          DownloadToWac();
    }
    else
    { 
         if(proxies.ProxyService.EnableSSL())
          {
              var webSSLPort=null;
              try{
                   webSSLPort=":"+proxies.ProxyService.GetWebServerSSLPort();  
                 }
              catch(e)
                 {
                   webSSLPort=":443";  
                 }
                var url = "/ShoppingCart.aspx?CartId=" + CartId + "&RecordCount=" + RecordCount;
                var curUrl="https://"+top.location.hostname+webSSLPort+url;
                top.location = curUrl;   
          }
          else
          {
              var url = "/ShoppingCart.aspx?CartId=" + CartId + "&RecordCount=" + RecordCount;
              top.location = url;
          }
     }
}
function ak()
{
    var akApiKey = 'RecEngine-80464A94-1CC5-4EE5-4D16-0FE51C2270F5';
    var akRegion = 'AddToCart';
    var akTarget = [window.location.href];
    var akItemQuantity = [1,1];
    var akIntent = 'ADD'
    var akScript = document.createElement('script');
    akScript.setAttribute('src','http://api.aggregateknowledge.com/2007/01/15/js/' + (new Date()).valueOf() % 3600000 + '.js');
    document.getElementsByTagName('head')[0].appendChild(akScript);
}
function SslSwitch()
{
    if(top.location.href.substring(0,5)!="https" && proxies.ProxyService.EnableSSL())
    {
        var CartId = GetUrlParameter("CartId");
        var RecordCount = GetUrlParameter("RecordCount");
        var webSSLPort=null;
        try{
           webSSLPort=":"+proxies.ProxyService.GetWebServerSSLPort();  
         }catch(e)
         {
           webSSLPort=":443/";  
         }
        var url = "/ShoppingCart.aspx?CartId=" + CartId + "&RecordCount=" + RecordCount;
        var curUrl="https://"+top.location.hostname+webSSLPort+url;
        top.location = curUrl;
      }
}
function DownloadToWac()
{
    var agt = navigator.userAgent.toLowerCase();
	var is_mac = (agt.indexOf("mac") != -1);
    if (is_mac) 
    {
        top.location.href=top.location.protocol+'//'+top.location.host+'/PlayerNotSupported.aspx';
        return;
    }
    top.location.href=top.location.protocol+'//'+top.location.host+'/PlayerDownload.aspx';
}