google_ad_client = "pub-1760707669584405";   
google_ad_slot = "8503908025";    
google_ad_width = 150;    
google_ad_height = 150;    


/////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// NO ENGLISH   //////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
function noeng(){
	
alert("Sorry, the english version is not available at the moment we are actually working on it hoping to release it as soon as possibile. If you would like to receive informations about our products or activities please send us your request at info@saporinostri.it We will answer you in the following 24 hours.");
	
}


/////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// CALCOLATRICE //////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
function calcolatot(form){
	
var f=prendi(form);
var valore=0;
var val="";
var vals;
	for(i=0;i<=parseInt(f.cnt.value);i+=1){
	
	valore += parseFloat((f["a"+i].value)*(f["b"+i].value));
	//alert("a"+i);
	}
	
	
	vals=valore.toString();
	
	if(vals.indexOf(".")!=-1){
	
	val=vals.substring(0,vals.indexOf(".")+3);
	
	} else {
	
	val=vals;
	}
	
	var virgola=vals.indexOf(".");
	if (virgola==-1){
		val=vals+".00";
	} 
	
	if (virgola==vals.length-1){
		val=vals+"00";
	}  
	if (virgola==vals.length-2 && vals.length<1){
		//alert(vals.length);
		val=vals+" ";
	}
	
	if (virgola==vals.length-2 && vals.length>1){
		//alert(vals.length);
		val=vals+"0";
	}
	

	
	
	
	valoutput=val.replace(".",",");
	
	//output
	prendi("tot").innerHTML=""+valoutput;
	f.tot.value=val;
}


function moreorless(mode, field, div, frm){
	
	f=prendi(frm);
	
	if (mode=="more"){
		var val=parseInt(f[field].value);
		val+=1;
		f[field].value=val;
		prendi(div).innerHTML=val;
		
	} else  if (mode=="less"){
		if(f[field].value<=1){
			
		return;	
		}else {
			
		var val=parseInt(f[field].value);
		val-=1;
		f[field].value=val;
		prendi(div).innerHTML=val;
		}
	
	
	}
	
	calcolatot(frm);
}
/////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// PRENDI ID ///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

function prendi(id_elemento) {
 var elemento;
 if(document.getElementById)
  elemento = document.getElementById(id_elemento);
 else
  elemento = document.all[id_elemento];
 return elemento;
};


/////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// XHR OBJECT ///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////


// JavaScript Document// funzione per assegnare l'oggetto XMLHttpRequest
// compatibile con i browsers più recenti e diffusi
function assegnaXMLHttpRequest() {

// lista delle variabili locali
var
 // variabile di ritorno, nulla di default
 XHR = null,
 
 // informazioni sul nome del browser
 browserUtente = navigator.userAgent.toUpperCase();


 // browser standard con supporto nativo
 // non importa il tipo di browser
 if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
  XHR = new XMLHttpRequest();

 // browser Internet Explorer
 // è necessario filtrare la versione 4
 else if(
  window.ActiveXObject &&
  browserUtente.indexOf("MSIE 4") < 0
 ) {
 
  // la versione 6 di IE ha un nome differente
  // per il tipo di oggetto ActiveX
  if(browserUtente.indexOf("MSIE 5") < 0)
   XHR = new ActiveXObject("Msxml2.XMLHTTP");

  // le versioni 5 e 5.5 invece sfruttano lo stesso nome
  else
   XHR = new ActiveXObject("Microsoft.XMLHTTP");
 }

 return XHR;
}


/** OGGETTI / ARRAY */

	// oggetto di verifica stato
		var readyState = {
			INATTIVO:	0,
			INIZIALIZZATO:	1,
			RICHIESTA:	2,
			RISPOSTA:	3,
			COMPLETATO:	4
		};

	// array descrittivo dei codici restituiti dal server
	// [la scelta dell' array è per evitare problemi con vecchi browsers]
		var statusText = new Array();
		statusText[100] = "Continue";
		statusText[101] = "Switching Protocols";
		statusText[200] = "OK";
		statusText[201] = "Created";
		statusText[202] = "Accepted";
		statusText[203] = "Non-Authoritative Information";
		statusText[204] = "No Content";
		statusText[205] = "Reset Content";
		statusText[206] = "Partial Content";
		statusText[300] = "Multiple Choices";
		statusText[301] = "Moved Permanently";
		statusText[302] = "Found";
		statusText[303] = "See Other";
		statusText[304] = "Not Modified";
		statusText[305] = "Use Proxy";
		statusText[306] = "(unused, but reserved)";
		statusText[307] = "Temporary Redirect";
		statusText[400] = "Bad Request";
		statusText[401] = "Unauthorized";
		statusText[402] = "Payment Required";
		statusText[403] = "Forbidden";
		statusText[404] = "Not Found";
		statusText[405] = "Method Not Allowed";
		statusText[406] = "Not Acceptable";
		statusText[407] = "Proxy Authentication Required";
		statusText[408] = "Request Timeout";
		statusText[409] = "Conflict";
		statusText[410] = "Gone";
		statusText[411] = "Length Required";
		statusText[412] = "Precondition Failed";
		statusText[413] = "Request Entity Too Large";
		statusText[414] = "Request-URI Too Long";
		statusText[415] = "Unsupported Media Type";
		statusText[416] = "Requested Range Not Satisfiable";
		statusText[417] = "Expectation Failed";
		statusText[500] = "Internal Server Error";
		statusText[501] = "Not Implemented";
		statusText[502] = "Bad Gateway";
		statusText[503] = "Service Unavailable";
		statusText[504] = "Gateway Timeout";
		statusText[505] = "HTTP Version Not Supported";
		statusText[509] = "Bandwidth Limit Exceeded";
		
		
/////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// AJAX FUNCTIONS   /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
function caricaTesto(nomeFile, idel, terzocaso) {
	
  var
    ajax = assegnaXMLHttpRequest(),
    elemento = prendi(idel),
    usaLink = true;
  
 
  if(ajax) {

    usaLink = false;
    ajax.open("get", nomeFile, true);

    ajax.setRequestHeader("connection", "close");
    ajax.onreadystatechange = function() {
        


      if(ajax.readyState === readyState.COMPLETATO) {

        if(statusText[ajax.status] === "OK")
	

		  if(terzocaso=="true"){
	
			showthematter(); 
			elemento.innerHTML = ajax.responseText;
			showthematter(); 
			  
		  } else {
			  
			  elemento.innerHTML = ajax.responseText;
			  
		  }
			  
        else {
          elemento.innerHTML = "Impossibile effettuare l'operazione richiesta.<br />";
          elemento.innerHTML += "Errore riscontrato: " + statusText[ajax.status];
        }
      } else  if(ajax.readyState === readyState.INIZIALIZZATO){
		    elemento.innerHTML ="<div align=center><img src='loader.gif'></div>";
		  
	  }
    }
    ajax.send(null);
  }
   
  return usaLink;
} 

/////////////////////////////////////////////////////////////

function aggiungi(nomeFile,imgdiv) {
	
	

  var
    ajax = assegnaXMLHttpRequest(),
    usaLink = true;
  
 
  if(ajax) {

    usaLink = false;
    ajax.open("get", nomeFile, true);

    ajax.setRequestHeader("connection", "close");
    ajax.onreadystatechange = function() {
      

      if(ajax.readyState === readyState.COMPLETATO) {

        if(statusText[ajax.status] === "OK"){
          success="ok";
		if(prendi(imgdiv)){
		
		var mgdv=prendi(imgdiv);
		
			if(imgdiv=="addcartimg" || imgdiv.indexOf("arrow")==-1){
			mgdv.src="http://www.saporinostri.it/layout/cart_added.gif";
			mgdv.parentNode.removeAttribute('onclick');
			mgdv.parentNode.href="javascript:;";
			mgdv.parentNode.removeAttribute('onkeypress');
			} else {
			mgdv.src="http://www.saporinostri.it/box/icon_arr2.gif";
			mgdv.parentNode.removeAttribute('onclick');
			mgdv.parentNode.href="javascript:;";
			mgdv.parentNode.removeAttribute('onkeypress');
			}
		
		}

		}
        else {
          return;
        }
      } else if(ajax.readyState === readyState.INIZIALIZZATO){
		 	if(prendi(imgdiv)){
		
		var mgdv=prendi(imgdiv);
		
		/*var mgdv=prendi(imgdiv);
		mgdv.src="http://www.saporinostri.it/pre/loader.gif";
		mgdv.parentNode.removeAttribute('onclick');
		mgdv.parentNode.href="javascript:;";
		mgdv.parentNode.removeAttribute('onkeypress');*/
		
			if(imgdiv=="addcartimg" || imgdiv.indexOf("arrow")==-1){
			mgdv.src="http://www.saporinostri.it/pre/loader.gif";
			mgdv.parentNode.removeAttribute('onclick');
			mgdv.parentNode.href="javascript:;";
			mgdv.parentNode.removeAttribute('onkeypress');
			} else {
			mgdv.src="http://www.saporinostri.it/box/icon_arr2.gif";
			mgdv.parentNode.removeAttribute('onclick');
			mgdv.parentNode.href="javascript:;";
			mgdv.parentNode.removeAttribute('onkeypress');
			}
		
		
		
		} 
		  
		  
	  }
    }
    ajax.send(null);
  }
   
  return usaLink;
} 


/////////////////////////////////////////////////////////////
function caricaTestopost(nomeFile, idel, form) {
	
  var ajax = assegnaXMLHttpRequest();
  var elemento = prendi(idel);
  var usaLink = true;
  var dati="sd=true";
  var f=prendi(form); 
  var formkey=Array();
  var formval=Array();
  var lng=f.elements.length;
	//alert(lng);

	
	for(k=0;k<=lng-1;k++){
		
		if(f[k].type!="submit" && f[k].type!="clear"){
		formkey[k]=f[k].name;
		formval[k]=f[k].value;
		dati=dati+"&"+formkey[k]+"="+escape(formval[k]);
		}
	}
	
	dati=dati.toString();
 
  if(ajax) {

    usaLink = false;
	
    ajax.open("POST", nomeFile, true);
	ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");   
    ajax.onreadystatechange = function() {
      

      if(ajax.readyState === readyState.COMPLETATO) {

        if(statusText[ajax.status] === "OK")
          elemento.innerHTML = ajax.responseText;

      } else  if(ajax.readyState === readyState.INIZIALIZZATO){
		    elemento.innerHTML ="<div align=center><img src='loader.gif'></div>";
		  
	  }
    }
	ajax.setRequestHeader("connection", "close");
	//alert(dati);

    ajax.send(dati);
  }
   
  return usaLink;
} 
/////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// IMAGE PRELOADER ///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
function alertComplete()
{
var lngS=document.images.length-1;
for(i=0;i<=lngS;i++){
if(i==lngS){
if(document.images[i].complete){
var showbody=prendi("index_body");
clearInterval(intervallo);
showbody.style.visibility="visible";
}
}
}
}

function invl(){
intervallo=setInterval("alertComplete()", 1000);	
}

/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////    AJAX BOXES   ///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
var thepuzz="undefined";
var thepuzza="undefined";
var showprodotti="undefined";
var prodcount=0;

function showthematter(){
	
	var contz=prendi("overconteiner");
	contz.style.display="block";
	contz.style.visibility="visible";
	contz.style.zIndex="100";
	contz.style.lineHeight="normal";
	
	var ctd=prendi("contentdivv");
	var bgd=prendi("backgrounddiv");


	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
	
	var dsoctop=document.all? iebody.scrollTop : pageYOffset;


	if(dsoctop>=0){
		
		
	
		var ch=ctd.offsetHeight;
		var cw=ctd.offsetWidth;
		var bh=bgd.offsetHeight;
	/*
		ctd.style.top="-"+ch-228+"px";
		bgd.style.height=ch+245+"px";
		bgd.style.width=cw+245+"px";
		
		contz.style.height=ch+250+"px";
		contz.style.top=dsoctop+"px";
		contz.style.overflow="hidden";
		*/
	    if(prendi("imageconteiner")){
			
			var imc=prendi("theimage");
			var imcc=prendi("chiudibutt");
			var imh=imc.offsetWidth;

			if(thepuzza=="undefined"){
			thepuzza=setInterval("showthematter()",100);
			
			}
			
			if(thepuzza!="undefined"){
				if(imc.complete==true && imcc.complete==true){

						
							imc=prendi("theimage");
							imcc=prendi("chiudibutt");
							imh=imc.offsetWidth;
							
						
							ctd.style.width=imh+"px";	
										
				
							ctd.style.top="-"+ch-28+"px";
							bgd.style.height=ch+45+"px";
							bgd.style.width=imh+45+"px";
							
							contz.style.height=ch+50+"px";
							contz.style.top=dsoctop+"px";
							contz.style.overflow="hidden";
			
						clearInterval(thepuzza);
						thepuzza="undefined";
						
				}
			}
			
		}
		
		if(prendi("productconteiner")){
			var imc=prendi("productconteiner");
			var imh=imc.offsetWidth;
			
			ctd.style.width=imh+"px";	
				
			ctd.style.top="-"+ch-28+"px";
			bgd.style.height=ch+45+"px";
			bgd.style.width=imh+45+"px";
			
			contz.style.height=ch+50+"px";
			contz.style.top=dsoctop+"px";
			contz.style.overflow="hidden";
			
			if(showprodotti=="undefined"){
			showprodotti=setInterval("showthematter()",400);
			
			
			} else {
				
				if(prendi("prodimg")){
					
					
					var cbutton=prendi("prodimg");
					var cbutton2=prendi("chiudibutton");
					
					if(cbutton.complete==true && cbutton2.complete==true){
						
						
									ctd.style.width=imh+"px";	
				
									ctd.style.top="-"+ch-28+"px";
									bgd.style.height=ch+45+"px";
									bgd.style.width=imh+45+"px";
			
									contz.style.height=ch+50+"px";
									contz.style.top=dsoctop+"px";
									contz.style.overflow="hidden";
						
						
						
						
						clearInterval(showprodotti);
						showprodotti="undefined";
						
					}
					
				}

				
			
				}
			} // productconteiner
			
			
	
	
	
	}// dsoctop

}//function

/////////////////

function closethematter(){

	var contz=prendi("overconteiner");
	contz.style.display="none";
	contz.style.visibility="hidden";
}


/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////  ECOMMERCE FUNCTIONS   ////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
function caricaProd(nomeFile, idel) {
	
  var
    ajax = assegnaXMLHttpRequest(),
    elemento = prendi(idel),
    usaLink = true;
  
 
  if(ajax) {

    usaLink = false;
    ajax.open("get", nomeFile, true);

    ajax.setRequestHeader("connection", "close");
    ajax.onreadystatechange = function() {
        


      if(ajax.readyState === readyState.COMPLETATO) {

        if(statusText[ajax.status] === "OK"){
	

			  
			  elemento.innerHTML = ajax.responseText;

		} else {
          elemento.innerHTML = "Impossibile effettuare l'operazione richiesta.<br />";
          elemento.innerHTML += "Errore riscontrato: " + statusText[ajax.status];
        }
		
		
      } else  if(ajax.readyState === readyState.INIZIALIZZATO){
		    elemento.innerHTML ="<div align=center><img src='loader.gif'></div>";
		  
	  }
    }
    ajax.send(null);
  }
   
  return usaLink;
} 
/////////////////////////////////////////////////////////////////////////////////////

function assign(addr,frm,nome){
	
if(prendi(frm)){
	
	var f=prendi(frm);
	f.action=addr;
	
	inp=prendi("cnf");
	inp.style.display="block";
	
	
	pt=prendi("paytype");
	pt.innerHTML=" "+ nome +" ";
	
}
}
///////////////////////////////////////

