// JavaScript Document - Vincenzo Trapani
// Ecommerce v2.0 24/03/2010


function aggiungiAlCarrelloVG(c)
{
	showAjaxLoader(true);
	c=c==""?"":c;
	 $.post("/addToBasket.php",{codice:c}, function(xml) {
												   doStandardOperation(xml)
													showAjaxLoader(false);
												// document.body.innerHTML+="";
												 
												 centerElement("#imgProdottoAggiunto");
												 $("#imgProdottoAggiunto").fadeIn();
												 
												 setTimeout(function(){$("#imgProdottoAggiunto").fadeOut();},3000);
												 var loc=window.location.toString();
												  if(loc.indexOf("toBasket.php")!=-1)
												  {
													  window.location.reload();
												  }
												  
												  });
}

function rimuoviDalCarrello(c)
{
	c=c==""?"":c;
	 $.post("/removeItemBasket.php",{codice:c}, function(xml) {
										doStandardOperation(xml);  
													  
												   
												   var loc=window.location.toString();
												  if(loc.indexOf("toBasket.php")!=-1)
												  {
													  window.location.reload();
												  }
												  });
}
function initBasket()
{

	 $.post("/initBasket.php",{a:1}, function(xml) {
												   doStandardOperation(xml);
												    
												
												});
}

function doStandardOperation(xml)
{
	 												var b=xml.split('|');
												   var txtArt=b[1]=="1"?"articolo":"articoli";
												   var totale=parseFloat(b[2])+parseFloat(b[3]);
												   totale=totale.toFixed(2);
													 document.getElementById("eCommerceMyProfileBasket").innerHTML=b[0];
												    document.getElementById("eCommerceMyProfileTotale").innerHTML="<b>"+b[1]+" "+txtArt+":</b> &euro; "+b[2];
												   document.getElementById("eCommerceMyProfileTotaleSpedizione").innerHTML=b[5];
												   document.getElementById("eCommerceMyProfileTotaleTotaleCarrello").innerHTML="<b>Totale carrello:</b> &euro; "+totale+b[4];
												   if(b[1]!="0")
													  {
													  document.getElementById('eCommerceMyProfileCassa').style.display='block';
													try
													{
													document.getElementById('concludiAcquistoScheda').style.display='block';
													}
													catch(EX)
													{
													}
													  
													  }
													  else
													  {
														document.getElementById('eCommerceMyProfileCassa').style.display='none';
														try
													{
													document.getElementById('concludiAcquistoScheda').style.display='none';
													}
													catch(EX)
													{
													}
													  }
												
}
function centerElement(id)
{
	  var box= $(id);
	 box.css("position","absolute");
	
	 
     box.css("top", ( $(window).height() - box.height() ) / 2+$(window).scrollTop() + "px");
     box.css("left", ( $(window).width() - box.width() ) / 2+$(window).scrollLeft() + "px");
}
function showAjaxLoader(flag)
{
	if(flag)
	{
		centerElement("#imgAjaxLoader");
		$("#imgAjaxLoader").fadeIn();
	}
	else
	{
		 $("#imgAjaxLoader").hide();
	}
	 
	
}
