var XMLHTTP

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 imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length < MaxLen);
}

function getElementPosition(elemID) 
{
var offsetTrail = document.getElementById(elemID);
var offsetLeft = 0;
var offsetTop = 0;
 
while (offsetTrail) {
offsetLeft += offsetTrail.offsetLeft;
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
}
 
if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") {
offsetLeft += document.body.leftMargin;
offsetTop += document.body.topMargin;
}
 
return {left:offsetLeft, top:offsetTop};
}

function WinCarrello()
{
  RecuperoPassword(1);  
  $(document).ready(function(){
	$(".riepilogocarrello").colorbox({width:"1100px", inline:true, href:"#riepilogocarrello"});
	$(".riepilogocarrello").css("top","200px");
  });
  $(".riepilogocarrello").colorbox({open:true});
}
function ChiudiWinCarrello()
{
  $(".riepilogocarrello").colorbox.close()
}

function ImpostaSessioneVisualizza(tipo)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_raffina.asp";
  url=url+"?tipo=13&idtipo="+tipo;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
      return(XMLHTTP.responseText);
      //INSERISCI RICHIESTA	  
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function ImpostaSessioneAvvisami(idArticolo)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=27&idarticolo="+idArticolo;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
      return(XMLHTTP.responseText);
      //INSERISCI RICHIESTA	  
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function RiepilogoOrdini()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=29";
  url=url+"&sid="+Math.random();
	//alert(url);
    XMLHTTP.open("GET",url,false);
    XMLHTTP.send(null);
    if(XMLHTTP.status == 200) 
    {
	  document.getElementById("riepilogo_ordini").innerHTML = XMLHTTP.responseText;
      //INSERISCI RICHIESTA	  
    } 
    else 
    {
      alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
    }

}

function RiepilogoOrdini2()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=29";
  url=url+"&sid="+Math.random();
	//alert(url);
    XMLHTTP.open("GET",url,false);
    XMLHTTP.send(null);
    if(XMLHTTP.status == 200) 
    {
	  document.getElementById("riepilogo_ordini").innerHTML = XMLHTTP.responseText;
      //INSERISCI RICHIESTA	  
    } 
    else 
    {
      alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
    }

}
function ListaNozze(idlista)
{
 // document.getElementById("riepilogo_ordini").style.display = "none";
 // document.getElementById("cont_dx").style.backgroundImage = "url(/images/ajax_wait.gif)";

  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=49&idlista="+idlista;
  url=url+"&sid="+Math.random();
	//alert(url);
    XMLHTTP.open("GET",url,false);
    XMLHTTP.send(null);
    if(XMLHTTP.status == 200) 
    {
	  //document.getElementById("cont_dx").style.backgroundImage = "";
	  //document.getElementById("riepilogo_ordini").style.display = "block";
	  document.getElementById("riepilogo_ordini").innerHTML = XMLHTTP.responseText;
	  allunga();
      //INSERISCI RICHIESTA	  
    } 
    else 
    {
      alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
    }

}

function OrdiniListaNozze(idlista)
{
 // document.getElementById("riepilogo_ordini").style.display = "none";
  //document.getElementById("cont_dx").style.backgroundImage = "url(/images/ajax_wait.gif)";

  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=51&lista="+idlista;
  url=url+"&sid="+Math.random();
	//alert(url);
    XMLHTTP.open("GET",url,false);
    XMLHTTP.send(null);
    if(XMLHTTP.status == 200) 
    {
	 /* document.getElementById("cont_dx").style.backgroundImage = "";
	  document.getElementById("riepilogo_ordini").style.display = "block";*/
	  document.getElementById("riepilogo_ordini").innerHTML = XMLHTTP.responseText;
	  allunga();
      //INSERISCI RICHIESTA	  
    } 
    else 
    {
      alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
    }
}
function WinPassword(init)
{
 // alert(init);
  document.getElementById("OverlayContent").innerHTML=RecuperoPassword(init);  
  $(document).ready(function(){
	$(".Overlay").colorbox({width:"300px",height:"280px", inline:true, href:"#OverlayContent"});
  });
  $(".Overlay").colorbox({open:true});
}
function ChiudiLoginWin()
{
  $(".recuperopassword").colorbox.close()
}

function RecuperoPassword(init)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var indemail;
  if(init==0)
  {
    indemail = document.getElementById("indemail").value;
  }
  var url="ajax_carrello.asp";
  url=url+"?tipo=31&init="+init+"&email="+indemail;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	return(XMLHTTP.responseText);
      //INSERISCI RICHIESTA	  
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function InviaRichiesta()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  if((user!="")&&(password!=""))
  {
	url=url+"?tipo=26";
	url=url+"&sid="+Math.random();
	//alert(url);
    XMLHTTP.open("GET",url,false);
    XMLHTTP.send(null);
    if(XMLHTTP.status == 200) 
    {
      return(XMLHTTP.responseText);
	  
      //INSERISCI RICHIESTA	  
    } 
    else 
    {
      alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
    }
  }
}

function statologin()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=32";
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);

  if(XMLHTTP.status == 200) 
  {
	//alert(XMLHTTP.responseText);
    return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
 
}
function statologin2()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=32";
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);

  if(XMLHTTP.status == 200) 
  {
	//alert(XMLHTTP.responseText);
    document.getElementById("divlogin").innerHTML = XMLHTTP.responseText;
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
 
}


function logout()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=20";
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
    document.getElementById("divlogin").innerHTML = XMLHTTP.responseText;
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}
function logout2()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=20";
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
    document.getElementById("divlogin").innerHTML = XMLHTTP.responseText;
	window.location = "http://www.kikaustore.it/index.asp"

	
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}
function loggami()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var user,password;
  var url="ajax_carrello.asp";
  user = document.getElementById("user").value;
  password = document.getElementById("password").value;
  //alert("User = "+user+" Pass = "+password);
  if((user!="")&&(password!=""))
  {
	url=url+"?tipo=19&user="+user+"&password="+password;
	url=url+"&sid="+Math.random();
	//alert(url);
    XMLHTTP.open("GET",url,false);
	XMLHTTP.send(null);
	if(XMLHTTP.status == 200) 
	{
	  //alert(XMLHTTP.responseText);
	  if((XMLHTTP.responseText==1)||(XMLHTTP.responseText==2))
	  {
		
		ErroreLogin(XMLHTTP.responseText);  
	  }
	  else
	  {
	    document.getElementById("divlogin").innerHTML = XMLHTTP.responseText;
	  }
	} 
    else 
	{
	  alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
	}
  }
}

function loggamiReg()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  //alert("User = "+user+" Pass = "+password);

	url=url+"?tipo=53";
	url=url+"&sid="+Math.random();
	//alert(url);
    XMLHTTP.open("GET",url,false);
	XMLHTTP.send(null);
	if(XMLHTTP.status == 200) 
	{
	  document.getElementById("divlogin").innerHTML = XMLHTTP.responseText;
	} 
    else 
	{
	  alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
	}

}

function WinLogin()
{
	$(document).ready(function(){
	  $(".errorelogin").colorbox({width:"300px", inline:true, href:"#errorelogin"});
	});
	$(".errorelogin").colorbox({open:true});
}
function ChiudiLoginWin()
{
  $(".errorelogin").colorbox.close()
}


function ErroreLogin(id)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var user,password;
  var url="ajax_carrello.asp";
  url=url+"?tipo=33&id="+id;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	document.getElementById("errorelogin").innerHTML = XMLHTTP.responseText;
	WinLogin();
  } 
  else 
  {
	alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }

}

function loggamiavviso()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var user,password,K;
  var url="ajax_carrello.asp";
  user = document.getElementById("useravviso").value;
  password = document.getElementById("passwordavviso").value;
  if((user!="")&&(password!=""))
  {
	url=url+"?tipo=19&user="+user+"&password="+password;
	url=url+"&sid="+Math.random();
	//alert(url);
    XMLHTTP.open("GET",url,false);
    XMLHTTP.send(null);
    if(XMLHTTP.status == 200) 
    {
      //return(XMLHTTP.responseText);
	  K=document.getElementById("divlogin");
	  K.innerHTML=XMLHTTP.responseText;
      //INSERISCI RICHIESTA	  
    } 
    else 
    {
      alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
    }
  }
  if((user!="")&&(password!=""))
  {
	var url="ajax_carrello.asp";
	url=url+"?tipo=25&user="+user+"&password="+password;
	url=url+"&sid="+Math.random();
	//alert(url);
    XMLHTTP.open("GET",url,false);
    XMLHTTP.send(null);
    if(XMLHTTP.status == 200) 
    {
      //return(XMLHTTP.responseText);
	  K=document.getElementById("avvisalog2");
	  K.innerHTML=XMLHTTP.responseText;
	  //INSERISCI RICHIESTA	  
    } 
    else 
    {
      alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
    }
  }
}

function avvisologgato()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=28";
  url=url+"&sid="+Math.random();
	//alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
    return(XMLHTTP.responseText);
	/*K=document.getElementById("avvisalog");
    K.innerHTML=XMLHTTP.responseText;*/
    //INSERISCI RICHIESTA	  
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }

}

function stateChangedLogin() 
{ 
  var K;
  if (XMLHTTP.readyState==4)
  { 
	K=document.getElementById("divlogin");
	K.innerHTML=XMLHTTP.responseText;
    if(window.location.pathname=="/clienti2.asp")
	{
	  RiepilogoOrdini();
	}
  }
}

function Conta(tipo,idcategoria,marchio,linea,saldo)
{ 
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  //alert("IDCategoria = "+idcategoria+"  Marchio = "+marchio);
  marchio2 = marchio.replace("&","038");  
  var url="ajax_raffina.asp";
  url=url+"?tipo="+tipo+"&idcategoria="+idcategoria+"&marchio="+marchio2+"&linea="+linea+"&saldo="+saldo;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function QualeMarchio(idmarchio)
{ 
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  //alert("IDCategoria = "+idcategoria+"  Marchio = "+marchio);
  var url="ajax_raffina.asp";
  url=url+"?tipo=12&idmarchio="+idmarchio;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}


function ApriTendina(id,idcategoria,idmarchio,linea,saldo)
{
  var altdiv;
  idconta = parseInt(id) + 3;
  if(idmarchio!="")
  {
    marchio = QualeMarchio(idmarchio);
  }
  else
  {
	marchio =""  
  }
  marchio2 = marchio.replace(" & ","_038_")
  marchio = marchio2 
  numero = Conta(idconta,idcategoria,marchio,linea,saldo);
  colonne = Math.ceil(parseInt(numero)/10);
  //alert("ID = "+id+" IDCAT = "+idcategoria+" MARCHIO = "+marchio+" linea = "+linea+" idconta ="+idconta+" saldo="+saldo+" Colonne "+colonne+" Numero = "+numero);
  //alert("Colonne "+colonne+" Numero = "+numero);
  if(numero>10)
  {
    if(colonne>2)
	{
	  altdiv = parseInt(200);
	  altcont = altdiv + 90;
	  oggetto = document.getElementById("cont"+id).style.height=altcont+"px";
	}
	else
	{
	  altdiv = parseInt(150);
	  altcont = altdiv + 40;
	  oggetto = document.getElementById("cont"+id).style.height=altcont+"px";
	}
  } 
  else
  {
	  altdiv = parseInt(numero)*24;
	  altcont = altdiv + 40;
	  oggetto = document.getElementById("cont"+id).style.height=altcont+"px";
  }
  if(id==1)
  {
    oggetto = document.getElementById("categoriaraff").style.height=altdiv+"px";
    oggetto = document.getElementById("beltcategoria").style.height=altdiv+"px";
	if(colonne<3)
    {
  	  oggetto = document.getElementById("mygallery_paginazione_categoria").style.display="none";
    }
  }
  if(id==2)
  {
	oggetto = document.getElementById("marcaraff").style.height=altdiv+"px";
	oggetto = document.getElementById("beltmarca").style.height=altdiv+"px";
    if(colonne<3)
    {
      oggetto = document.getElementById("mygallery_paginazione_marca").style.display="none";
    }
  }
  if(id==3)
  {
    oggetto = document.getElementById("lineeraff").style.height=altdiv+"px";
    oggetto = document.getElementById("beltlinee").style.height=altdiv+"px";
	if(colonne<3)
    {
  	  oggetto = document.getElementById("mygallery_paginazione_linee").style.display="none";
    }
  }
  

  elemento = document.getElementById("clickme"+id);
  alt = $('#cont'+id).height();
  alt = alt + 60;
  //alert("ALT "+alt);
  /*elemento2 = document.getElementById("cont"+id);
  alert(elemento2.style.clientHeight);*/
  for (var i = 1; i <= 3; i++) 
  {
    if(i!=id)
	{
      elemento = document.getElementById("clickme"+i);
      alt = $('#cont'+i).height();
      alt = alt + 60;
      if(elemento.style.height == alt+'px')
      {
	    oggetto = document.getElementById("campo"+i);
        oggetto.style.backgroundImage="url('/images/campi-tendina.png')";
        $('#cont'+i).hide();
        $('#clickme'+i).animate({
	    'height' : '28px'
        });
	  }
    }
  }
  elemento = document.getElementById("clickme"+id);
  alt = $('#cont'+id).height();
  alt = alt + 60;
  if(elemento.style.height == alt+'px')
  {
    oggetto = document.getElementById("campo"+id);
    oggetto.style.backgroundImage="url('/images/campi-tendina.png')";
    $('#cont'+id).hide();
	if(id==1)
	{
      $('#clickme'+id).animate({
	   'height' : '28px'
       });
	}
	else
	{
      $('#clickme'+id).animate({
	   'height' : '29px'
       });
	}
  }
  else
  {
   // alert(idconta+"   "+numero);
	//if(numero>1)
    //{ 
      oggetto = document.getElementById("campo"+id);
      oggetto.style.backgroundImage="url('/images/campi-tendina-up.png')";
	  
	  if(id==1)
	  {
		marchio2 = marchio.replace("&","038");
	    //alert('ajax_raffina.asp?tipo=1&idcategoria='+idcategoria+'&marchio='+marchio+'&linea='+linea+'&altdiv='+altdiv);
	    stepcarousel.loadcontent('categoriaraff', 'ajax_raffina.asp?tipo=1&idcategoria='+idcategoria+'&marchio='+marchio2+'&linea='+linea+'&altdiv='+altdiv+'&saldo='+saldo);
	  }
	  if(id==2)
	  {
		marchio2 = marchio.replace("&","038");  
		//alert('ajax_raffina.asp?tipo=2&idcategoria='+idcategoria+'&marchio='+marchio+'');
		stepcarousel.loadcontent('marcaraff', 'ajax_raffina.asp?tipo=2&idcategoria='+idcategoria+'&marchio='+marchio2+'&linea='+linea+'&altdiv='+altdiv+'&saldo='+saldo);
	  }
	  if(id==3)
	  {
		marchio2 = marchio.replace("&","038");
	    //alert('ajax_raffina.asp?tipo=3&idcategoria='+idcategoria+'&marchio='+marchio2+'&linea='+linea+'&altdiv='+altdiv+'&saldo='+saldo);
	    stepcarousel.loadcontent('lineeraff', 'ajax_raffina.asp?tipo=3&idcategoria='+idcategoria+'&marchio='+marchio2+'&linea='+linea+'&altdiv='+altdiv+'&saldo='+saldo);
	  }        
	  $('#clickme'+id).animate({
	    'height' : alt+'px'
      });
           					  
	  $('#cont'+id).show();
	//}
  }
}

  COLORI = new Array(); //viene creato l'array
	COLORI[0]="E2001A";
	COLORI[1]="E2001A";
	COLORI[2]="F08D5D";
	COLORI[3]="F19402";
	COLORI[4]="F3BC47";
	COLORI[5]="D94A6E";
	COLORI[6]="CCB986";
	COLORI[7]="47ACB1";
	COLORI[8]="7CC5BA";
	COLORI[9]="66B8DC";
	COLORI[10]="80A91F";
	COLORI[11]="AB8ABB";
	COLORI[12]="D08097";
	COLORI[13]="008181";
	COLORI[14]="786454";
	COLORI[15]="7C7C7C";


function Dec2Hex (Dec) 
{
  var hexChars = "0123456789ABCDEF";
  var a = Dec % 16;
  var b = (Dec - a)/16;
  hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
  return hex;
}

function rgbToHex(rgb)
{
  if (rgb.indexOf("#") == 0)
  {
    var rgb = rgb.toUpperCase();
    return rgb;
  }

  var str = rgb.replace(/rgb\(/,"").replace(/\)/,"");
  var arr = str.split(", ");

  var r = arr[0];
  var g = arr[1];
  var b = arr[2]; 

  return "#" + Dec2Hex(r) + Dec2Hex(g) + Dec2Hex(b);
}
function cambia(k,tipo)
{
  var oggetto,elemento,wht;
  elemento= "menu_"+k;
  oggetto = document.getElementById(elemento);
  if(tipo==1)
  {
    if(rgbToHex(oggetto.style.color)=='#666666')
	{
	  oggetto.style.backgroundColor="#"+COLORI[k];
	  oggetto.style.color="#FFFFFF";
    }
  }
  if(tipo==2)
  {
    if(rgbToHex(oggetto.style.color)=='#FFFFFF')
	{
	  if(parseInt(oggetto.offsetWidth)==200)
	  {
	    oggetto.style.backgroundImage="";
	    oggetto.style.color="#666666";
	    oggetto.style.backgroundColor="";
      }
	}
  }
}

/*
function cambia(k,tipo)
{
  var oggetto,elemento;
  elemento= "menu_"+k;
  oggetto = document.getElementById(elemento);
  if(tipo==1)
  {
    //alert(rgbToHex(oggetto.style.color));
    if(rgbToHex(oggetto.style.color)=='#666666')
	{
	
	  //oggetto.style.backgroundImage="url('/images/baffo.png')";
	  //oggetto.style.backgroundRepeat="no-repeat";
	  //alert("#"+COLORI[k]);
	  oggetto.style.backgroundColor="#"+COLORI[k];
	  oggetto.style.color="#FFFFFF";
	  //oggetto.style.color="#000000";
    }
  }
  if(tipo==2)
  {
    if(rgbToHex(oggetto.style.color)=='#FFFFFF')
	{
	  if(oggetto.style.width=='200px')
	  {
	    oggetto.style.backgroundImage="";
	    oggetto.style.color="#666666";
		//oggetto.style.backgroundRepeat="no-repeat";
        //oggetto.style.color="#666666";
	    oggetto.style.backgroundColor="";
      }
	}
  }
}*/

function chiudi_tutti2()
{
  var vchiudi;
  vchiudi = 0;
  for (var i = 1; i < 17; i++) 
  {
    if(document.getElementById("example_"+i).style.width=='705px')
	{
	  vchiudi=i;
	}
  }
  if(vchiudi!=0)
    chiudi2(vchiudi);
  alert("chiudi_tutti");
}

function sposta(num)
{
  //alert(top);
  var vchiudi = new Array();
  k=0;
  if(document.getElementById("menu_"+num).style.width=='216px')
  {
    chiudi2(num);
  }
  else
  {
	for (var i = 1; i < 16; i++) 
	{
	  if(document.getElementById("menu_"+i).style.width=='216px')
	  {
	    vchiudi[i]=1;
	  }
	  else
	  {
	    vchiudi[i]=0;
	  }
	}
	
	for (var i = 1; i < 16; i++) 
	{
	  if((vchiudi[i]==1)&&(i!=parseInt(num)))
	  {
	  
	    chiudi2(i);
	  }
	}
  apri(num);
  }
  
}

function sposta2(num)
{
  //alert(top);
  var vchiudi = new Array();
  k=0;
  if(document.getElementById("menu_"+num).style.width=='216px')
  {
    chiudi2(num);
  }
  else
  {
	for (var i = 1; i < 16; i++) 
	{
	  if(document.getElementById("menu_"+i).style.width=='216px')
	  {
	    vchiudi[i]=1;
	  }
	  else
	  {
	    vchiudi[i]=0;
	  }
	}
	
	for (var i = 1; i < 16; i++) 
	{
	  if((vchiudi[i]==1)&&(i!=parseInt(num)))
	  {
	  
	    chiudi2(i);
	  }
	}
  apri(num);
  }
  
}

function apri(num)
{
    elemento = document.getElementById("menu_"+num);
    elemento.style.width = "216px";
	  //elemento.style.backgroundImage="url('/images/baffo2.png')";
      //elemento.style.border = "1px solid #"+colori[num];
	if(num!=16)
	{
	  elemento.style.borderRight = "";
	  elemento.style.backgroundColor="#"+COLORI[num];
	  elemento.style.color="#FFFFFF";
	}
    $('#example_'+num).show();
    $('#example_'+num).animate({
	  'height' : '410px'
    });
    $('#example_'+num).animate({
      'width' : '745px'
    });
	$('#cont_'+num).show();
}

function AjaxSposta(num,codice)
{
  //alert(top);
  var vchiudi = new Array();
  k=0;
  if(document.getElementById("menu_"+num).style.width=='216px')
  {
    chiudi2(num);
  }
  else
  {
	for (var i = 1; i < 16; i++) 
	{
	  if(document.getElementById("menu_"+i).style.width=='216px')
	  {
	    vchiudi[i]=1;
	  }
	  else
	  {
	    vchiudi[i]=0;
	  }
	}
	
	for (var i = 1; i < 16; i++) 
	{
	  if((vchiudi[i]==1)&&(i!=parseInt(num)))
	  {
	  
	    chiudi2(i);
	  }
	}
  ApriAjax(num,codice);
  }
  
}

function ApriAjax(num,codice)
{
    elemento = document.getElementById("menu_"+num);
    elemento.style.width = "216px";
	  //elemento.style.backgroundImage="url('/images/baffo2.png')";
      //elemento.style.border = "1px solid #"+colori[num];
	if(num!=16)
	{
	  elemento.style.borderRight = "";
	  elemento.style.backgroundColor="#"+COLORI[num];
	  elemento.style.color="#FFFFFF";
	}
    $('#example_'+num).show();
    $('#example_'+num).animate({
	  'height' : '410px'
    });
    $('#example_'+num).animate({
      'width' : '745px'
    });
	$('.contpanel').css('left',0);
	$('.slidepanel').remove();
	document.getElementById("example_"+num).innerHTML=CaricaTendina(num,codice);
	//$('#cont_'+num).show();
}

function CaricaTendina(numero,codice)
{ 
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  //alert("IDCategoria = "+idcategoria+"  Marchio = "+marchio);
  var spese,valore;
  var url="ajax_tendina.asp";
  url=url+"?id=1&numero="+numero+"&codice="+codice;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	/* valore = XMLHTTP.responseText;
     spese = valore.split("-");*/
	 return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}
function ChiudiAjax(num)
{
  //alert(vchiudi);
 // alert(num);
  $('#cont_'+num).fadeOut('slow');
  //$('#menu_'+num).fadeOut('slow',function () 
  //{
  if(num!=16)
  {
    document.getElementById("menu_"+num).style.border = "";
	document.getElementById("menu_"+num).style.backgroundImage="";
    document.getElementById("menu_"+num).style.backgroundColor="";
    document.getElementById("menu_"+num).style.color="#666666";
    document.getElementById("menu_"+num).style.borderBottom = '1px solid #CCCCCC';
	document.getElementById("menu_"+num).style.width = '200px';
  //});
    $('#menu_'+num).show(0);
  }
  else
  {
    document.getElementById("menu_"+num).style.width = '210px';  
  }
  
  
  $('#example_'+num).fadeOut('slow',function () 
  {
    document.getElementById("example_"+num).style.height = '1px';
    document.getElementById("example_"+num).style.width = '1px';
  });
}
function FrecciaSlide(verso)
{ 
  var numrodiv = 0;
  var maxright = 0;
  var left = 0;
  numerodiv = $(".contpanel > .slidepanel").length;
  maxright = (parseInt(numerodiv)-1) * 240;
 // alert(numerodiv+"  "+maxright)
  if(parseInt(verso)==1)
  {  
	  
    left=$(".contpanel").css("left");
  
    if(parseInt(left)!=0)
    {
	  left2=left.replace("px","");
	  left=parseInt(left2)+240;
	  $(".contpanel").animate({
	    left: left
	  });
    }
  }
  else
  {
    left=$(".contpanel").css("left");
	//alert(left);
    if(left=="auto")
	{
	  position = $(".contpanel").position();
	  left = position.left;
	  left=parseInt(left);
	}
	else
	{
      left2=left.replace("px","");
	  left=parseInt(left2);
	}
    left=parseInt(left)-240;
	//alert(left);
    //alert("GIU "+top);
    if(parseInt(left)>-maxright)
    {
	  //alert("GIU "+top);
	  //$(".slidepanel").css("left", left);
	  $(".contpanel").animate({
	    left: left
	  });
    }
  }
}


function CaricaSpese()
{ 
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  //alert("IDCategoria = "+idcategoria+"  Marchio = "+marchio);
  var spese,valore;
  var url="ajax_carrello.asp";
  url=url+"?tipo=56";
  url=url+"&sid="+Math.random();
 // alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	 valore = XMLHTTP.responseText;
     spese = valore.split("-");
	 return {spedizione:spese[0], contrassegno:spese[1], spesegratis:spese[2]};
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}


function chiudi2(num)
{
  //alert(vchiudi);
 // alert(num);
  $('#cont_'+num).fadeOut('slow');
  //$('#menu_'+num).fadeOut('slow',function () 
  //{
  if(num!=16)
  {
    document.getElementById("menu_"+num).style.border = "";
	document.getElementById("menu_"+num).style.backgroundImage="";
    document.getElementById("menu_"+num).style.backgroundColor="";
    document.getElementById("menu_"+num).style.color="#666666";
    document.getElementById("menu_"+num).style.borderBottom = '1px solid #CCCCCC';
	document.getElementById("menu_"+num).style.width = '200px';
  //});
    $('#menu_'+num).show(0);
  }
  else
  {
    document.getElementById("menu_"+num).style.width = '210px';  
  }
  
  
  $('#example_'+num).fadeOut('slow',function () 
  {
    document.getElementById("example_"+num).style.height = '1px';
    document.getElementById("example_"+num).style.width = '1px';
  });
}
function handleEnter (field, event) 
{
  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  if (keyCode == 13)  
  {
	var i;
	for (i = 0; i < field.form.elements.length; i++)
	  if (field == field.form.elements[i])
		break;
	  i = (i + 1) % field.form.elements.length;
	  field.form.elements[i].focus();
	  return false;
  }
  else
	return true;
}

function pulisci(str)
{
  k=str.replace(/[\']/g,"`")
  n=k.replace(/[\"]/g,"`")
  return(n)
}

function MostraComuni(str)
{ 

  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=9&q="+str;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	 document.getElementById("ListaComuni").innerHTML = XMLHTTP.responseText;
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function VerificaLog()
{ 
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  //alert("IDCategoria = "+idcategoria+"  Marchio = "+marchio);
  var url="ajax.asp";
  url=url+"?id=21";
  url=url+"&sid="+Math.random();
 // alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function CaricaContenuto(content)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  //alert("IDCategoria = "+idcategoria+"  Marchio = "+marchio);
  var url="overlay2.asp";
  url=url+"?contenuto="+content;
  url=url+"&sid="+Math.random();
 // alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	 //alert(XMLHTTP.responseText);
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
	
}
function RegistrazioneOK()
{
  //alert("OK");
  $(document).ready(function(){
	$(".registrazione2").colorbox({width:"500px",height:"400px", inline:true, href:"#formregistrazione"});
  });
  document.getElementById("formregistrazione").innerHTML=CaricaContenuto('registrazioneOK');
  $(".registrazione2").colorbox({open:true});

  loggamiReg();
}

function LoginRegistrazione()
{
	
  $(document).ready(function(){
	$(".registrazione2").colorbox({width:"825px", height:"680px", inline:true, href:"#formregistrazione"});
  });
  document.getElementById("formregistrazione").innerHTML=CaricaContenuto('registrazione');
  $(".registrazione2").colorbox({open:true});
  MostraComuni('AG');
  
}


function RegistrazioneCliente()
{
	
  $(document).ready(function(){
	$(".registrazione2").colorbox({width:"825px", height:"680px", inline:true, href:"#formregistrazione"});
  });
  document.getElementById("formregistrazione").innerHTML=CaricaContenuto('registrazione2');
  $(".registrazione2").colorbox({open:true});
  MostraComuni('AG');
  
}

function RegistrazioneClienteOK()
{
  //alert("OK");
  $(document).ready(function(){
	$(".registrazione2").colorbox({width:"500px",height:"400px", inline:true, href:"#formregistrazione"});
  });
  document.getElementById("formregistrazione").innerHTML=CaricaContenuto('registrazione2OK');
  $(".registrazione2").colorbox({open:true});

  loggamiReg();
}

function ModificaFatturazione(idditta)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
	return;
  } 
   var url="ajax_carrello.asp";
	url=url+"?tipo=37&idditta="+idditta;
	url=url+"&sid="+Math.random();
   // alert(url);
	XMLHTTP.open("GET",url,false);
	XMLHTTP.send(null);
	if(XMLHTTP.status == 200) 
	{
	  document.getElementById("modfatt").innerHTML = "<a href='#' style='text-decoration:none; color:#FFFFFF;' onclick = 'javascript:SalvaFatturazione("+idditta+");'>Salva</a>";
      document.getElementById("dati_fatturazione").innerHTML = XMLHTTP.responseText;
	} 
	else 
	{
	  alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
	}	

}


function ModificaFatturazione2(idditta)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
	return;
  } 
   var url="ajax_carrello.asp";
	url=url+"?tipo=54&idditta="+idditta;
	url=url+"&sid="+Math.random();
   // alert(url);
	XMLHTTP.open("GET",url,false);
	XMLHTTP.send(null);
	if(XMLHTTP.status == 200) 
	{
      return(XMLHTTP.responseText);
	} 
	else 
	{
	  alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
	}	

}

function CaricaFatturazione(idditta)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
	return;
  } 
   var url="ajax_carrello.asp";
	url=url+"?tipo=39&idditta="+idditta;
	url=url+"&sid="+Math.random();
   // alert(url);
	XMLHTTP.open("GET",url,false);
	XMLHTTP.send(null);
	if(XMLHTTP.status == 200) 
	{
      return(XMLHTTP.responseText);
	} 
	else 
	{
	  alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
	}	

}


function onValidateFormFatt() 
{
    valore = document.getElementById("valore").value;
	//alert(valore);
	if(valore==1)
	{
	  //alert(form['ragione']);
	  if (!(validateRequiredField(document.getElementById("ragione"), 'Ragione Sociale'))) {
		return false;
	  }
	  //alert("ragione");
	  if (!(validateMinLength(document.getElementById("ragione"), 'Ragione Sociale','4'))) {
		return false;
	  }
	  if (!(validateRequiredField(document.getElementById("Partita_IVA"), 'Partita IVA'))) {
		return false;
	  }
	  //alert("Partita IVA");
	  if (!(validateMinLength(document.getElementById("Partita_IVA"), 'Partita IVA','11'))) {
		return false;
	  }
	}
	if(valore==2)
	{
	  //alert(form['iCognome']);
	  if (!(validateRequiredField(document.getElementById("iCognome"), 'Cognome'))) {
		return false;
	  }
	  //alert("iCognome");
	  if (!(validateMinLength(document.getElementById("iCognome"), 'Cognome','4'))) {
		return false;
	  }
	  if (!(validateRequiredField(document.getElementById("iAnno"), 'Anno'))) {
		return false;
	  }
	  
	  //alert("iAnno");
	  if (!(validateMinLength(document.getElementById("iAnno"), 'Anno','4'))) {
		return false;
	  }
	  var data = new Date();
	  annoc = data.getFullYear();
	  if((document.getElementById("iAnno").value>=annoc)||(document.getElementById("iAnno").value<1900)){
		alert("Inserire un valore corretto per l'Anno di nascita");
		return false;
	  }
	  if (!(validateRequiredField(document.getElementById("iComune"), 'Comune di Nascita'))) {
		return false;
	  }
	  else
	  {
	    document.getElementById("comunenascita").value=document.getElementById("iComune").value;
	  }
		  
	  if (!(validateRequiredField(document.getElementById("cod_fisc"), 'Codice Fiscale'))) {
		return false;
	  }
	  //alert("cod_fisc");
	  if (!(validateMinLength(document.getElementById("cod_fisc"), 'Codice Fiscale','16'))) {
		return false;
	  } 
	 /* if(form['cod_fisc'].value!=document.getElementById("Codice_Fiscale").value){
		alert("Verificate il codice fiscale inserito");
		return false;
	  }*/
	  
	}
	if (!(validateRequiredField(document.getElementById("indirizzo"), 'Indirizzo'))) {
	 return false;
	}
	//alert("indirizzo");
	if (!(validateRequiredField(document.getElementById("CAP"), 'CAP'))) {
	  return false;
	}
	//alert("cap");
	if (!(validateMinLength(document.getElementById("CAP"), 'CAP','5'))) {
	  return false;
	}
	if (!(validateRequiredField(document.getElementById("Provincia"), 'Provincia'))) {
	  return false;
	}
	//alert("provincia");
	if (!(validateMinLength(document.getElementById("Provincia"), 'Provincia','2'))) {
	  return false;
	}
	if (!(validateRequiredField(document.getElementById("Comune"), 'Comune'))) {
	  return false;
	}
	//alert("comune");
	if (!(validateMinLength(document.getElementById("Comune"), 'Comune','4'))) {
	  return false;
	}
	if (!(validateAlpha(document.getElementById("Comune"), 'Comune'))) {
	  return false;
	}
	if (!(validateRequiredField(document.getElementById("Telefono"), 'Telefono'))) {
	  return false;
	}
	//alert("telefono");
	if (!(validateMinLength(document.getElementById("Telefono"), 'Telefono','6'))) {
	  return false;
	}
	if (!(validateRequiredField(document.getElementById("Cellulare"), 'Cellulare'))) {
	  return false;
	}
	//alert("Cellulare");
	if(document.getElementById("Cellulare").length>0)
	{
	  if (!(validateMinLength(document.getElementById("Cellulare"), 'Cellulare','6'))) {
		return false;
	  }
	}
	
						
    return true;
  }

  function validateFormFatt() 
  {
	blockSubmission = true;
	if (typeof beforeJoinFormValidation != 'undefined') 
	{
	  beforeJoinFormValidation();
	}
	var validated = onValidateFormFatt();
	if (validated && (typeof uponSuccessfulJoinFormValidation != 'undefined')) 
	{
	  validated = uponSuccessfulJoinFormValidation();
	}
	else if (!validated && (typeof uponUnsuccessfulJoinFormValidation != 'undefined')) 
	{
	  uponUnsuccessfulJoinFormValidation();
	}
	if (!validated) 
	{

	}
	return validated;
  }

function SalvaFatturazione2(idditta)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
	return;
  } 
  
  if (validateFormFatt()) 
  {
	//alert("SalvaFatturazione"); 
	valore = document.getElementById("valore").value;
    var url="ajax_carrello.asp";
    url=url+"?tipo=38&idditta="+idditta+"&tipologia="+valore;
    if(valore==2)
	{
	    url=url+"&icognome="+pulisci(document.getElementById("iCognome").value);
		url=url+"&igender="+document.getElementById("iGender").value;
		url=url+"&pronas="+document.getElementById("pronas").value;
		url=url+"&comunenascita="+document.getElementById("comunenascita").value;
		url=url+"&igiorno="+document.getElementById("iGiorno").value;
		url=url+"&imese="+document.getElementById("iMese").value;
		url=url+"&ianno="+document.getElementById("iAnno").value;
		url=url+"&cod_fisc="+document.getElementById("cod_fisc").value;
		url=url+"&indirizzo="+pulisci(document.getElementById("indirizzo").value);
		url=url+"&cap="+document.getElementById("CAP").value;
		url=url+"&provincia="+document.getElementById("Provincia").value;
		url=url+"&comune="+pulisci(document.getElementById("Comune").value);
		url=url+"&nazione="+document.getElementById("Nazione").value;
		url=url+"&telefono="+document.getElementById("Telefono").value;
		url=url+"&cellulare="+document.getElementById("Cellulare").value;
	}
	else
	{
		url=url+"&icognome="+pulisci(document.getElementById("ragione").value);
		url=url+"&p_iva="+document.getElementById("Partita_IVA").value;
		url=url+"&indirizzo="+pulisci(document.getElementById("indirizzo").value);
		url=url+"&cap="+document.getElementById("CAP").value;
		url=url+"&provincia="+document.getElementById("Provincia").value;
		url=url+"&comune="+pulisci(document.getElementById("Comune").value);
		url=url+"&nazione="+document.getElementById("Nazione").value;
		url=url+"&telefono="+document.getElementById("Telefono").value;
		url=url+"&cellulare="+document.getElementById("Cellulare").value;
	}
	url=url+"&sid="+Math.random();
    //alert("SalvaFatturazione "+url);  
	  //alert("SalvaAnagrafica "+url);
	  XMLHTTP.open("GET",url,false);
	  XMLHTTP.send(null);
	  if(XMLHTTP.status == 200) 
	  {
		 //return(XMLHTTP.responseText);
		document.getElementById("riepilogo_ordini").innerHTML = ModificaFatturazione2(idditta);
	  } 
	  else 
	  {
		alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
	  }

  }
  

}


function SalvaFatturazione(idditta)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
	return;
  } 
  
  if (validateFormFatt()) 
  {
	//alert("SalvaFatturazione"); 
	valore = document.getElementById("valore").value;
    var url="ajax_carrello.asp";
    url=url+"?tipo=38&idditta="+idditta+"&tipologia="+valore;
    if(valore==2)
	{
	    url=url+"&icognome="+pulisci(document.getElementById("iCognome").value);
		url=url+"&igender="+document.getElementById("iGender").value;
		url=url+"&pronas="+document.getElementById("pronas").value;
		url=url+"&comunenascita="+document.getElementById("comunenascita").value;
		url=url+"&igiorno="+document.getElementById("iGiorno").value;
		url=url+"&imese="+document.getElementById("iMese").value;
		url=url+"&ianno="+document.getElementById("iAnno").value;
		url=url+"&cod_fisc="+document.getElementById("cod_fisc").value;
		url=url+"&indirizzo="+pulisci(document.getElementById("indirizzo").value);
		url=url+"&cap="+document.getElementById("CAP").value;
		url=url+"&provincia="+document.getElementById("Provincia").value;
		url=url+"&comune="+pulisci(document.getElementById("Comune").value);
		url=url+"&nazione="+document.getElementById("Nazione").value;
		url=url+"&telefono="+document.getElementById("Telefono").value;
		url=url+"&cellulare="+document.getElementById("Cellulare").value;
	}
	else
	{
		url=url+"&icognome="+pulisci(document.getElementById("ragione").value);
		url=url+"&p_iva="+document.getElementById("Partita_IVA").value;
		url=url+"&indirizzo="+pulisci(document.getElementById("indirizzo").value);
		url=url+"&cap="+document.getElementById("CAP").value;
		url=url+"&provincia="+document.getElementById("Provincia").value;
		url=url+"&comune="+pulisci(document.getElementById("Comune").value);
		url=url+"&nazione="+document.getElementById("Nazione").value;
		url=url+"&telefono="+document.getElementById("Telefono").value;
		url=url+"&cellulare="+document.getElementById("Cellulare").value;
	}
	url=url+"&sid="+Math.random();
    //alert("SalvaFatturazione "+url);  
	  //alert("SalvaAnagrafica "+url);
	  XMLHTTP.open("GET",url,false);
	  XMLHTTP.send(null);
	  if(XMLHTTP.status == 200) 
	  {
		 //return(XMLHTTP.responseText);
		 document.getElementById("modfatt").innerHTML = "<a href='#' style='text-decoration:none; color:#FFFFFF;' onclick = 'javascript:ModificaFatturazione("+idditta+");'>Modifica</a>";
		 document.getElementById("dati_fatturazione").innerHTML = CaricaFatturazione(idditta);
	  } 
	  else 
	  {
		alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
	  }

  }
  

}

function GuardaCarrello(idart)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
	return;
  } 
   var url="ajax_carrello.asp";
	url=url+"?tipo=36&idart="+idart;
	url=url+"&sid="+Math.random();
   // alert(url);
	XMLHTTP.open("GET",url,false);
	XMLHTTP.send(null);
	if(XMLHTTP.status == 200) 
	{
      return(XMLHTTP.responseText);
	} 
	else 
	{
	  alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
	}	
}

function AggiornaQuantita(id,n,prezzo,bloccato,valore,multipli)
{
  //alert("AJAX ID = "+id+"  N = "+n+"  Quantità = "+quantita);
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
	return;
  } 

	var elemento,tiptquantita,semaforo;
	elemento = "Quantita_"+n;
	importoelemento = "importo_"+n;
	tiptquantita = "testoesaurito_"+n;
	semaforo = "divsemaforo_"+n;
    quantita = GuardaCarrello(id);
    if(valore==0)
	{
	  EliminaCarrello(id);
	}
	else
	{
	  //alert("Valore ="+valore+" Quantita="+quantita);
	  if(bloccato>-1)
	  {
		 if(valore>quantita)
		 {
			valoremax = parseInt(quantita) + parseInt(DispImmediata(id));
			//alert(quantita+"  "+DispImmediata(id)+" = "+valoremax);
			valore = valoremax;
			quantita = valore;
			document.getElementById(elemento).value = quantita;
			/*qua = quantita.replace(",",".");
			pre = prezzo.replace(",",".");*/
			importo = quantita * prezzo;
			 // alert(bloccato);
			document.getElementById(importoelemento).innerHTML = "&euro;&nbsp;"+nimporto(importo);
			valore = quantita;
			if(quantita==1)
			{
			  descqua = "1 Pezzo"
			}
			else
			{
			  descqua = quantita + " Pezzi"
			}
			document.getElementById(tiptquantita).innerHTML = "<br>La quantit&agrave; massima <br>acquistabile per questo articolo <br>&egrave; "+descqua;
			
			ApriTool(n);
			document.getElementById(semaforo).innerHTML=CambiaSemaforo(1,n,1);
			
			//alert("QUANTITA' INSERITA NEL CARRELLO MAGGIORE DEL DISPONIBILE PER ARTICOLO ESAURITO") 
		 }
	  }
	  
	  if(multipli>1)
	  {
		ris = valore / multipli;
		g = Math.floor(ris);
		f = valore % multipli
		if (f>0)
		{
		  //alert("Ris = "+ris+"  G =  "+g);
		  if(g>0)
		  {
			s = g + 1
			k = multipli * (s)
		  }
		  else
		  {
			k = multipli
		  }
		
		  document.getElementById(elemento).value = k;
		  valore = k;

		  importo = k * prezzo;
			 // alert(bloccato);
		  document.getElementById(importoelemento).innerHTML = "&euro;&nbsp;"+nimporto(importo); 
		  document.getElementById(tiptquantita).innerHTML = "<br>Articolo acquistabile in quantit&agrave; multiple di "+multipli+" pezzi.<br>Sono stati aggiunti al carrello <br>"+k+" pezzi";
		  ApriTool(n);
		}
	  }
	
	

	   var url="ajax_carrello.asp";
		url=url+"?tipo=35&idart="+id+"&quantita="+valore;
		url=url+"&sid="+Math.random();
	   // alert(url);
		XMLHTTP.open("GET",url,false);
		XMLHTTP.send(null);
		if(XMLHTTP.status == 200) 
		{
		  AggiornaTempiConsegna();
		} 
		else 
		{
		  alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
		}

	//quantita = document.getElementById('Quantita_'+n).value;
   // alert("ID = "+id+"  N = "+n+"  Quantità = "+quantita);
	

	//alert(quantita);
	}
}

function stateChanged() 
{ 

}

function ChiudiLoginWin()
{
  $(".recuperopassword").colorbox.close()
}

function RecuperoPassword(init)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var indemail;
  if(init==0)
  {
    indemail = document.getElementById("indemail").value;
  }
  var url="ajax_carrello.asp";
  url=url+"?tipo=31&init="+init+"&email="+indemail;
  url=url+"&sid="+Math.random();
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function VerificaMultiplo(id,quantita,quale)
{ 
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  //alert("IDCategoria = "+idcategoria+"  Marchio = "+marchio);
  var url="ajax_carrello.asp";
  url=url+"?tipo=3&idart="+id+"&quantita="+quantita+"&quale="+quale;
  url=url+"&sid="+Math.random();
 // alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function AggiornaTempiConsegna()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
	return;
  } 
  var url="ajax_carrello.asp";
  //alert(email+'  '+pass);
  url=url+"?tipo=2";
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
    var K=document.getElementById("imgconsegna");
	K.src="/images/disp/"+XMLHTTP.responseText+".png"; 
	//alert(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }

}

function stateChanged2() 
{ 
  var K=document.getElementById("divspedizione");
  //alert(XMLHTTP.responseText);
  if (XMLHTTP.readyState==4)
  { 
    var K=document.getElementById("divspedizione");
	K.innerHTML=XMLHTTP.responseText;
	//alert(XMLHTTP.responseText);
    $(function() 
    {
      $('.bubbleInfo').each(function () {
		var distance = 30;
		var time = 50;
		var hideDelay = 200;

		var hideDelayTimer = null;

		var beingShown = false;
		var shown = false;
		var trigger = $('.trigger', this);
		var info = $('.tooltip', this).css('opacity', 0);


		$([trigger.get(0), info.get(0)]).mouseover(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown) {
				// don't trigger the animation again
				return;
			} else {
				// reset position of info box
				beingShown = true;

				info.css({
					top: -90,
					left: 40,
					display: 'block'
				}).animate({
					top: '-=' + distance + 'px',
					opacity: 1
				}, time, 'swing', function() {
					beingShown = false;
					shown = true;
				});
			}

			return false;
		}).mouseout(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				info.animate({
					top: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
					shown = false;
					info.css('display', 'none');
				});

			}, hideDelay);

			return false;
            });
        });
		$('.bubblefoto').each(function () {
            var distance = 30;
            var time = 50;
            var hideDelay = 200;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var info = $('.tooltipfoto', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: -190,
                        left: -85,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
    });

  }
}

function AggiornaCarrello()
{
  //var form = document.forms['JoinForm'];
  //alert(form['NEmail'].value);
  //alert("AJAX ID = "+id+"  N = "+n+"  Quantità = "+quantita);
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
	return;
  } 
  var url="ajax_carrello.asp";
  //alert(email+'  '+pass);
  url=url+"?tipo=4";
  url=url+"&sid="+Math.random();
  //alert(url);
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function stateChangedAggCarr() 
{ 
  if (XMLHTTP.readyState==4)
  { 
    var stringa, K;
	K=document.getElementById("numeroarticoli");
	K.innerHTML=XMLHTTP.responseText;
  }
}
function TempiConsegna(idart)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
	alert ("Your browser does not support AJAX!");
	return;
  } 
  var numero,semaforo,url="ajax_carrello.asp";
  
  //alert(email+'  '+pass);
  url=url+"?tipo=44&idart="+idart;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	return(XMLHTTP.responseText);
  } 
  else 
  {
	alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function AggiornaSemafori(idarticolo)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
	alert ("Your browser does not support AJAX!");
	return;
  } 
  var tempiconsegna;
  var numero;
  var semaforo,dimm;
  var url="ajax_carrello.asp";
  
  //alert(email+'  '+pass);
  url=url+"?tipo=43&idart="+idarticolo;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	numero = XMLHTTP.responseText;
	//alert(numero);
	if(numero>0)
	{
	  semaforo = "riedivsemaforo_"+numero;
	  tcons = TempiConsegna(idarticolo);
	  dimm = DispImmediata(idarticolo);
	  if(dimm>0)
	  {
		tcons = 1;
	  }
	 // alert("N="+numero+"semaforo = "+semaforo+"Tempi="+tcons);
	  document.getElementById(semaforo).innerHTML=CambiaSemaforo(tcons,numero,0);
	}
  } 
  else 
  {
	alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}
		
function EliminaCarrello(id)
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
	alert ("Your browser does not support AJAX!");
	return;
  } 
  var url="ajax_carrello.asp";
  //alert(email+'  '+pass);
  url=url+"?tipo=5&idart="+id;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	if(id!="SVUOTA")
	{
	  AggiornaRiepilogo();
	}
	else
	{
	  $(".riepilogocarrello").colorbox.close();
	  window.location = "http://www.kikaustore.it/index.asp"
	}

  } 
  else 
  {
	alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function AggiungiCarrello(id,quantita,prezzo)
{
  //var form = document.forms['JoinForm'];
  //alert(form['NEmail'].value);
  //alert("AJAX ID = "+id+"  N = "+n+"  Quantità = "+quantita);
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
	return;
  } 
  var url="ajax_carrello.asp";
  //alert(email+'  '+pass);
  url=url+"?tipo=45&idart="+id+'&quantita='+quantita+'&prezzo='+prezzo;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	document.getElementById("articoloaggiunto").innerHTML = XMLHTTP.responseText;
  }
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function AggiornaRiepilogo()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
	return;
  } 
  var url="ajax_carrello.asp";
  //alert(email+'  '+pass);
  url=url+"?tipo=6";
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
    if(XMLHTTP.responseText!='0')
	{
	  
      document.getElementById("contenutocarrello").innerHTML=XMLHTTP.responseText;
	  CalcolaTotale();
	}
	else
	{
	  window.location = "http://www.kikaustore.it/index.asp"
	}
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function CalcolaImporto(id,n,prezzo,bloccato,quantita,multipli,tipo)
{
  var importo,quantita,elequa,eleimp,qua,pre,k;
  k = 0;
  elequa = "Quantita_"+n;
  eleimp = "importo_"+n;
  //alert("id = "+id);
  quantita = document.getElementById(elequa).value;
  
  //alert("quantita = "+quantita+" Prezzo = "+prezzo);
  
  qua = quantita.replace(",",".");
  pre = prezzo.replace(",",".");
  importo = qua * pre;
  document.getElementById(eleimp).innerHTML = "&euro;&nbsp;"+nimporto(importo);
  if(tipo==1)
  { 
	AggiornaQuantita(id,n,pre,bloccato,qua,multipli);
	totsped = CalcolaSubtotale();
	document.getElementById("divsubtotale").innerHTML = "&euro;&nbsp;"+nimporto(totsped);
	if(parseInt(totsped) > 150)
	{
	  document.getElementById("labelspedizione").innerHTML = "Spedizione Gratuita";
	}
	else
	{
	  document.getElementById("labelspedizione").innerHTML = "";
	}

	CalcolaTotale();
  }
}

function RiepilogoTotale(tipopagamento,paccoregalo)
{
  var subtotale,spesegratis,spesevisualizza;
  subtotale = CalcolaSubtotale();
  spesegratis = (CaricaSpese().spesegratis)*1.21;
  spesegratis = Math.round(spesegratis*100)/100;

  if(subtotale<spesegratis) 
  {
	spesevisualizza = (CaricaSpese().spedizione)*1.21;
	spesevisualizza = Math.round(spesevisualizza*100)/100;
    subtotale = parseFloat(subtotale)+parseFloat(spesevisualizza);
  }
  if(tipopagamento=="contrassegno")
  {
	spesevisualizza = (CaricaSpese().contrassegno)*1.21;
	spesevisualizza = Math.round(spesevisualizza*100)/100;
    subtotale = parseFloat(subtotale)+parseFloat(spesevisualizza);
  }
  if(paccoregalo!="")
  {
    subtotale = parseFloat(subtotale)+2;
  }
  document.getElementById("riepilogosubtotale").innerHTML="Totale Ordine  &euro; "+nimporto(subtotale);
}

function ImportoTotale(tipopagamento,paccoregalo)
{
  var subtotale,spesegratis,spesevisualizza;
  subtotale = CalcolaSubtotale();
  spesegratis = (CaricaSpese().spesegratis)*1.21;
  spesegratis = Math.round(spesegratis*100)/100;

  if(subtotale<spesegratis) 
  {
	spesevisualizza = (CaricaSpese().spedizione)*1.21;
	spesevisualizza = Math.round(spesevisualizza*100)/100;
    subtotale = parseFloat(subtotale)+parseFloat(spesevisualizza);
  }
  if(tipopagamento=="contrassegno")
  {
	spesevisualizza = (CaricaSpese().contrassegno)*1.21;
	spesevisualizza = Math.round(spesevisualizza*100)/100;
    subtotale = parseFloat(subtotale)+parseFloat(spesevisualizza);
  }
  if(paccoregalo!="")
  {
    subtotale = parseFloat(subtotale)+2;
  }
  return(nimporto(subtotale));
}

function CalcolaSubtotale()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  //alert("IDCategoria = "+idcategoria+"  Marchio = "+marchio);
  var url="ajax_carrello.asp";
  url=url+"?tipo=7";
  url=url+"&sid="+Math.random();
 // alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
	 //alert(XMLHTTP.responseText);
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function ControllaLogin()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var user,password;
  var url="ajax_carrello.asp";
  user = document.getElementById("user").value;
  password = document.getElementById("password").value;
  if((user!="")&&(password!=""))
  {
	url=url+"?tipo=12&user="+user+"&password="+password;
	url=url+"&sid="+Math.random();
	// alert(url);
	XMLHTTP.open("GET",url,false);
	XMLHTTP.send(null);
	if(XMLHTTP.status == 200) 
	{
	  return(XMLHTTP.responseText);
	} 
	else 
	{
	  alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
	}
  }
}

function CalcolaTempiConsegna()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  //alert("IDCategoria = "+idcategoria+"  Marchio = "+marchio);
  var url="ajax_carrello.asp";
  url=url+"?tipo=8";
  url=url+"&sid="+Math.random();
 // alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function nimporto(prezzo)
{
    num=Math.round(parseFloat(prezzo)*100)/100;
    num=""+num;
    if(num.indexOf(".") == -1)
    {
        num=num+".00";
    }
    else
    {
        var splitted=num.split(".");
        if(splitted[1].length < 2)splitted[1]=splitted[1]+"0";
        num=splitted[0]+"."+splitted[1];
    }
    num = num.replace(".",",");
	return num;
	
}
function SalvaImpostazioni()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  //alert("IDCategoria = "+idcategoria+"  Marchio = "+marchio);
  var url="ajax_carrello.asp?tipo=10";
  url=url+"&sid="+Math.random();
  var pagamento, paccoregalo, messaggioregalo, noteconsegna;
  var form = document.forms['JoinForm'];
  var rr = form['pagamento'];
	
  for(var i=0; i<rr.length; i++) 
  {
    if(rr[i].checked) 
    {
     valore = rr[i].value;
	  break;
	} 
  }
	
  pagamento = valore
  //alert("PACCOREGALO = "+document.getElementById("paccoregalo").checked);
  if(document.getElementById("paccoregalo").checked==true)
  {
	paccoregalo = document.getElementById("paccoregalo").value;
  }
  else
  {
	paccoregalo="";
  }
  //alert("PACCOREGALO = "+paccoregalo);
  if(document.getElementById("messaggioauguri"))
  {
	messaggioauguri = document.getElementById("messaggioauguri").value;
  }
  else
  {
	messaggioauguri="";
  }
    
  url=url+"&pagamento="+valore+"&paccoregalo="+paccoregalo+"&messaggioauguri="+messaggioauguri;
  url=url+"&sid="+Math.random();
//alert("PACCOREGALO = "+paccoregalo);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }

}

function SalvaDati()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  //alert("IDCategoria = "+idcategoria+"  Marchio = "+marchio);
  var url="ajax_carrello.asp?tipo=17";
  url=url+"&sid="+Math.random();
//alert("PACCOREGALO = "+paccoregalo);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }

}
function PrendiUser()
{
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  //alert("IDCategoria = "+idcategoria+"  Marchio = "+marchio);
  var url="ajax_carrello.asp?tipo=59";
  url=url+"&sid="+Math.random();
//alert("PACCOREGALO = "+paccoregalo);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }

}

function CalcolaTotale()
{

	var valore = "";
	var errorecontrassegno="NO";
	var form = document.forms['JoinForm'];
	var rr = form['pagamento'];
	
	for(var i=0; i<rr.length; i++) 
	{
	  if(rr[i].checked) 
	  {
		valore = rr[i].value;
		break;
	  }
	}
	if(valore=="contrassegno")
	{
	  document.getElementById("costopagamentocarta").innerHTML="";
	  document.getElementById("costopagamentopaypal").innerHTML="";
      document.getElementById("costopagamentobonifico").innerHTML="";
	  spesevisualizza = (CaricaSpese().contrassegno)*1.21;
	  spesevisualizza = Math.round(spesevisualizza*100)/100;
	  document.getElementById("costopagamentocontr").innerHTML="&euro;&nbsp;"+nimporto(spesevisualizza);
	  valorepagamento = spesevisualizza;
	}
	if(valore=="carta")
	{
	  document.getElementById("costopagamentocarta").innerHTML="GRATUITO";
	  document.getElementById("costopagamentopaypal").innerHTML="";
      document.getElementById("costopagamentobonifico").innerHTML="";
	  document.getElementById("costopagamentocontr").innerHTML="";
	  valorepagamento = 0;
	}
	if(valore=="paypal")
	{
	  document.getElementById("costopagamentocarta").innerHTML="";
	  document.getElementById("costopagamentopaypal").innerHTML="GRATUITO";
      document.getElementById("costopagamentobonifico").innerHTML="";
	  document.getElementById("costopagamentocontr").innerHTML="";
	  valorepagamento = 0;
	}
	if(valore=="bonifico")
	{ 
	  document.getElementById("costopagamentocarta").innerHTML="";
	  document.getElementById("costopagamentopaypal").innerHTML="";
      document.getElementById("costopagamentobonifico").innerHTML="GRATUITO";
	  document.getElementById("costopagamentocontr").innerHTML=""; 
	  valorepagamento = 0;
	}
	totale = CalcolaSubtotale();
	
	tempiconsegna = CalcolaTempiConsegna();
	//alert(parseFloat(totale));
	if(tempiconsegna>1)
	{
	  errorecontrassegno = "SI";
	}
	
	if((parseFloat(totale)>500)&&(valore=="contrassegno"))
	{
	  errorecontrassegno = "SI";
	}
	
	if(valore=="contrassegno")
	{
	  if(errorecontrassegno=="SI")
	  {
	    document.getElementById("pagamentocarta").checked="checked";
	    document.getElementById("costopagamentocarta").innerHTML="GRATUITO";
	    document.getElementById("costopagamentopaypal").innerHTML="";
        document.getElementById("costopagamentobonifico").innerHTML="";
	    document.getElementById("costopagamentocontr").innerHTML="";
	    valorepagamento = 0;
		Aprierrorecontrassegno();
	  }
	}
	
    spesegratis = (CaricaSpese().spesegratis)*1.21;
    spesegratis = Math.round(spesegratis*100)/100;
	//alert(totale+"  "+spesegratis);
	if(totale<spesegratis)
	{
	  spesevisualizza = (CaricaSpese().spedizione)*1.21;
	  spesevisualizza = Math.round(spesevisualizza*100)/100;
	  document.getElementById("importospedizione").innerHTML="&euro; "+nimporto(spesevisualizza);
	  totale = parseFloat(totale) + parseFloat(spesevisualizza);
	  document.getElementById("labelspedizione").innerHTML = "";
	}
	else
	{
	  document.getElementById("importospedizione").innerHTML="GRATUITA";
	  document.getElementById("labelspedizione").innerHTML = "Spedizione Gratuita";
	}
	var rr = form['paccoregalo'];
	valoreregalo = 0;
	if(rr.checked) 
	{
	  valoreregalo = 2;
	  //document.getElementById("messaggio_regalo").style.display = "block";
	  //CalcolAltezza("PIU");
	}
	else
	{
	  valoreregalo = 0;
	  //document.getElementById("messaggio_regalo").style.display = "none";
	  //CalcolAltezza("MENO");
	}
	if(valoreregalo==2)
	{
	  totale = parseFloat(totale) + parseFloat(valorepagamento) + parseFloat(valoreregalo);
	  document.getElementById("importoregalo").innerHTML="&euro; 2,00";
	}
	else
	{
	  totale = parseFloat(totale) + parseFloat(valorepagamento);
	  document.getElementById("importoregalo").innerHTML="";
	}
	
	document.getElementById("importototale").innerHTML="&euro; "+nimporto(totale);
	
	
}


function SalvaAnagrafica()
{ 
  //alert("Ciao a tutti "+document.getElementById("NEmail").value);
  //alert(document.getElementById("spedifatt").checked);
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  //alert(document.getElementById("Tipologia").value);
  var form = document.getElementById("JoinForm");
  var valore = ""
  document.getElementById("comunenascita").value=document.getElementById("iComune").value;
   
  var radioObj = document.getElementsByName("Tipologia");
  var radioLength = radioObj.length;
  for(var i = 0; i < radioLength; i++) 
  {
	if(radioObj[i].checked) 
	{
	  valore = radioObj[i].value;
	}
  }
  var radioObj =  document.getElementsByName("iGender");
  var radioLength = radioObj.length;
  var sesso;
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			sesso = radioObj[i].value;
		}
	}
  //alert(document.getElementById("iGender").value);
  if(parseInt(valore)==2)
  {
    url=url+"?tipo=13";
	url=url+"&nemail="+pulisci(document.getElementById("NEmail").value);
	url=url+"&npass="+pulisci(document.getElementById("NPass").value);
	url=url+"&tipologia="+valore;
	url=url+"&icognome="+pulisci(document.getElementById("iCognome").value);
	url=url+"&inome="+pulisci(document.getElementById("iNome").value);
	url=url+"&igender="+sesso;
	url=url+"&pronas="+document.getElementById("pronas").value;
	url=url+"&comunenascita="+document.getElementById("comunenascita").value;
    url=url+"&igiorno="+document.getElementById("iGiorno").value;
	url=url+"&imese="+document.getElementById("iMese").value;
	url=url+"&ianno="+document.getElementById("iAnno").value;
	url=url+"&cod_fisc="+document.getElementById("cod_fisc").value;
	url=url+"&indirizzo="+pulisci(document.getElementById("indirizzo").value)+" "+pulisci(document.getElementById("civico").value);
	url=url+"&cap="+document.getElementById("CAP").value;
	url=url+"&provincia="+document.getElementById("Provincia").value;
	url=url+"&comune="+pulisci(document.getElementById("Comune").value);
	url=url+"&nazione="+document.getElementById("Nazione").value;
	url=url+"&telefono="+document.getElementById("Telefono").value;
	url=url+"&cellulare="+document.getElementById("Cellulare").value;
	if(document.getElementById("spedifatt")!= null)
	{
	  if(document.getElementById("spedifatt").checked==false)
	  {
		  url=url+"&spedizione=OK&referente="+pulisci(document.getElementById("referente").value);
		  url=url+"&indirizzospedi="+pulisci(document.getElementById("indirizzospedi").value)+" "+pulisci(document.getElementById("civicospedi").value);
		  url=url+"&capspedi="+document.getElementById("capspedi").value;
		  url=url+"&provspedi="+document.getElementById("provspedi").value;
		  url=url+"&comspedi="+pulisci(document.getElementById("comspedi").value);
		  url=url+"&nazspedi="+document.getElementById("nazspedi").value;
		  url=url+"&telspedi="+document.getElementById("telspedi").value;
	  }
	}
	url=url+"&sid="+Math.random();
  }
  else
  {
    url=url+"?tipo=13&nemail="+document.getElementById("NEmail").value;
	url=url+"&npass="+pulisci(document.getElementById("NPass").value);
	url=url+"&tipologia="+valore;
	url=url+"&icognome="+pulisci(document.getElementById("ragione").value.toUpperCase());
	url=url+"&p_iva="+document.getElementById("Partita_IVA").value;
    url=url+"&indirizzo="+pulisci(document.getElementById("indirizzo").value)+" "+pulisci(document.getElementById("civico").value);
	url=url+"&cap="+document.getElementById("CAP").value;
	url=url+"&provincia="+document.getElementById("Provincia").value;
	url=url+"&comune="+pulisci(document.getElementById("Comune").value);
	url=url+"&nazione="+document.getElementById("Nazione").value;
	url=url+"&telefono="+document.getElementById("Telefono").value;
	url=url+"&cellulare="+document.getElementById("Cellulare").value;
	if(document.getElementById("spedifatt")!= null)
	{
      if(document.getElementById("spedifatt").checked==false)
	  {
		  url=url+"&spedizione=OK&referente="+pulisci(document.getElementById("referente").value);
		  url=url+"&indirizzospedi="+pulisci(document.getElementById("indirizzospedi").value)+" "+pulisci(document.getElementById("civicospedi").value);
		  url=url+"&capspedi="+document.getElementById("capspedi").value;
		  url=url+"&provspedi="+document.getElementById("provspedi").value;
		  url=url+"&comspedi="+pulisci(document.getElementById("comspedi").value);
		  url=url+"&nazspedi="+document.getElementById("nazspedi").value;
		  url=url+"&telspedi="+document.getElementById("telspedi").value;
	  }
	}
	url=url+"&sid="+Math.random();
  }
  //alert("SalvaAnagrafica "+url);  
  //alert("SalvaAnagrafica "+url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function InserisciAlternativa(user)
{ 
  //alert("Ciao a tutti "+document.getElementById("NEmail").value);
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  //alert(document.getElementById("indspedi").value);
  url=url+"?tipo=14&userid="+user+"&referente="+document.getElementById("referente").value+"&indirizzospedi="+document.getElementById("indirizzospedi").value+" "+document.getElementById("civicospedi").value+"&capspedi="+document.getElementById("capspedi").value+"&provspedi="+document.getElementById("provspedi").value+"&comspedi="+document.getElementById("comspedi").value+"&nazspedi="+document.getElementById("nazspedi").value+"&telspedi="+document.getElementById("telspedi").value;
  url=url+"&sid="+Math.random();
  //alert("Ins Alternativa = "+url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}
function EliminaAlternativa(user)
{ 
  //alert("Ciao a tutti "+document.getElementById("NEmail").value);
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  //alert(document.getElementById("indspedi").value);
  url=url+"?tipo=15&userid="+user;
  url=url+"&sid="+Math.random();
  //alert("Elimina Alternativa = "+url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}

function ControllaMail()
{ 
  //alert("Ciao a tutti "+document.getElementById("NEmail").value);
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var email, url="ajax_carrello.asp";
  email = document.getElementById("NEmail").value;
  url=url+"?tipo=16&email="+email;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     return(XMLHTTP.responseText);
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }
}
function CambiaUtente(step)
{
  //alert("Ciao a tutti "+document.getElementById("NEmail").value);
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=18&step="+step;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     window.location = "http://www.kikaustore.it/carrello2.asp"
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }	
	
}
function CambiaUtente2(step)
{
  //alert("Ciao a tutti "+document.getElementById("NEmail").value);
  XMLHTTP=GetXmlHttpObject();
  if (XMLHTTP==null)
  {
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="ajax_carrello.asp";
  url=url+"?tipo=18&step="+step;
  url=url+"&sid="+Math.random();
  //alert(url);
  XMLHTTP.open("GET",url,false);
  XMLHTTP.send(null);
  if(XMLHTTP.status == 200) 
  {
     window.location = "http://www.kikaustore.it/carrello3.asp"
  } 
  else 
  {
    alert("Si è verificato un errore: \n" + XMLHTTP.status + " - " + XMLHTTP.statusText)
  }	
	
}
