var xmlHttp;
var timer;

function shopcart_additem(code,tpe)
{
alert("qui!!");
 var qty=document.getElementById("f_shop_"+tpe+"_"+code).getElementsByTagName("input")[0].value;
 var url=document.getElementById("f_shop_"+tpe+"_"+code).action+"?additem="+code+"&type="+tpe+"&qty="+qty;

 if((isNaN(qty)) || (qty==0))
 {
  alert("Inserire un numero valido");
  document.getElementById("f_shop_"+tpe+"_"+code).getElementsByTagName("input")[1].value=0;
 }
 else
 {
  alert("Prodotto aggiunto al carrello");
  document.getElementById("f_shop_"+tpe+"_"+code).getElementsByTagName("input")[1].value=0;
  ajax_g(url,"shopcartBox");    
 }
}

function shopcart_deleteitem(code,tpe)
{
 var url=document.getElementById("f_shopcart").action+"?deleteitem="+code+"&type="+tpe;
 ajax_g(url,"maincontentbox");
}

function shopcart_emptycart()
{
/*
 var url=document.getElementById("f_shopcart").action+"?emptycart=1";

 ajax_g(url,"maincontentbox");
*/
}

function shopcart_updatecart()
{
 var url=document.getElementById("f_shopcart").action+"?updatecart=1";
 var cart=document.getElementById("f_shopcart").getElementsByTagName("input");
 var i=0;

 while(i < cart.length)
 {
  url=url+"&"+cart[i].name+"="+cart[i].value;
  i=i+1;
 }

 ajax_g(url,"maincontentbox");
}

function order_transportcost(choice,payment)
{
 var url=document.getElementById("f_shopcart").action+"?select_paymethod="+payment+"&transport_cost="+choice;

 ajax_g(url,"maincontentbox");
}

function ajax_p(url,vars,area)
{
 xmlHttp=GetXmlHttpObject();

 if (xmlHttp==null)
 {
  alert ("Browser does not support HTTP Request");
  return true;
 }

 xmlHttp.onreadystatechange=function(){ stateChanged(area); }

 xmlHttp.open("POST",url,true);
 var timeout=setTimeout("xmlHttp=null",500);
 xmlHttp.send(vars);
 clearTimeout(timeout);
}

function ajax_g(url,area)
{
 xmlHttp=GetXmlHttpObject();

 if (xmlHttp==null)
 {
  alert ("Browser does not support HTTP Request");
  return true;
 }

 xmlHttp.onreadystatechange=function(){ stateChanged(area); }

 url=url+"&ajax="+area;

 xmlHttp.open("GET",url,true);
 var timeout=setTimeout("xmlHttp=null",500);
 xmlHttp.send("1");
 clearTimeout(timeout);
}

function stateChanged(area) 
{
 if ((xmlHttp.readyState==4 || xmlHttp.readyState=="complete") && xmlHttp.status==200)
 {
  document.getElementById(area).innerHTML=xmlHttp.responseText;
 }
}

function GetXmlHttpObject()
{
 var xmlHttp=null;
 try
 {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
 }
 catch (e)
 {
  //Internet Explorer
  try
  {
   xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e)
  {
   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function clitype_toggle(selector)
{
 var trlist = document.getElementById("f_newuser").getElementsByTagName("tr");

 var i = 0;

 while(i <= trlist.length)
 {
  if(trlist[i].className == "toggledblock block_clitype_private")
  {
   if(selector == "private")
   {
    trlist[i].style.display = "table-row";
   }
   else
   {
    trlist[i].style.display = "none";
   }
  }
  else if(trlist[i].className == "toggledblock block_clitype_company")
  {
   if(selector == "company")
   {
    trlist[i].style.display = "table-row";
   }
   else
   {
    trlist[i].style.display = "none";
   }
  }
  i++;
 }
}

function clidest_toggle(selector)
{
	if(selector==='true')
	{
		//document.getElementById("newuserBlock_clidest").style.display = "table-row";
		document.getElementById("newuserBlock_clidest").style.display = "";
	}
	else
	{
		document.getElementById("newuserBlock_clidest").style.display = "none";
	}
}

function shopcart_enableProvinces(nation){

	if(nation && nation==='000')
	{ // if ITALIA
		document.getElementById("newuser_prov_row").style.display = "table-row";
	}
	else
	{
		document.getElementById("newuser_prov_row").style.display = "none";
	}
	
}

function shopcart_enableProvinces2(nation){

	if(nation && nation==='000')
	{ // if ITALIA
		document.getElementById("newuser_prov_row_2").style.display = "table-row";
	}
	else
	{
		document.getElementById("newuser_prov_row_2").style.display = "none";
	}
	
}
