
function viewDescrizione(){


	if (document.getElementById('descrizioneTextArea').style.display == 'none'){


		document.getElementById('descrizioneTextArea').style.display = 'inline';


	}else{


		document.getElementById('descrizioneTextArea').style.display = 'none';


	}


}

function preAddCart(nome,prezzo,idCampoNumero){
	
	var num = document.getElementById(idCampoNumero).value;
	if (parseInt(num)){addToCart_Request(nome,prezzo,num);}
	else alert("Il numero di prodotti inserito non è corretto!");
}


function addToCart_Request(nome,prezzo,numero){

		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
			 alert ("Spiacente, il tuo Browser non supporta JavaScript. Si prega di attivare l'uso di JavaScript o utilizzare un browser pi&uacute; recente");
			 return
		}
		document.getElementById('cart_div').innerHTML = "<p align='center'><img src='./img/loading.gif' alt='Aggiornamento in corso...'/></p>";
		var url="cart_add.php";
		var query = "p="+nome+"&id="+prezzo+"&n="+numero;
		url = url + "?" + query;
		//imposto la funzione di riposta
		xmlHttp.onreadystatechange=function() {
									addToCart_Response();
							};
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
} 

function addToCart_Response(){

	if (xmlHttp.readyState==4){ 	
		if (xmlHttp.status == 200){
			var response = xmlHttp.responseText;
			//alert (response);
			resp = response.split("$");
			if (resp[0] == 'OK'){
				document.getElementById('cart_div').innerHTML = resp[1];
			}
		}
	}

}


function deleteToCart_Request(id){
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
			 alert ("Spiacente, il tuo Browser non supporta JavaScript. Si prega di attivare l'uso di JavaScript o utilizzare un browser pi� recente");
			 return
		}
		var url="cart_delete.php"
		var query = "id="+id;
		url = url + "?" + query;
		//imposto la funzione di riposta
		xmlHttp.onreadystatechange=function() {
									addToCart_Response();
							};
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
} 

function deleteToCart_Response(){

	if (xmlHttp.readyState==4){ 	
		if (xmlHttp.status == 200){
			var response = xmlHttp.responseText;
			//alert (response);
			location.reload();
		}
	}

}


function deleteAdmin(id,type){
	if (confirm("Confermi l'eliminazione dell'oggetto selezionato?")){
		location.href="./admin_delete.php?id="+id+"&type="+type;
	}
}



function updateQuantita(){
	if (document.getElementById("cart_button_submit") != null)
		document.getElementById("cart_button_submit").style.display = "none";
}

function submitCartQuantita(){
	document.getElementById("form_cart").action = "cart_update_quantita.php";
}

function controlloNumeroColli(){
	
	var arrTipo = new Array();
	var bottiglie = 0;
	var strError;
	var str;
	
	arrTipo = document.getElementsByName('tipo');

	for (var i=0; arrTipo.length>i; i++){
		
		var valueInput = arrTipo[i].value;
		var arrValue = valueInput.split("_");

		if (arrValue[0] == "olio"){bottiglie += parseInt(arrValue[1]);}
		if (arrValue[0] == "vini"){bottiglie += parseInt(arrValue[2]);}
		

	}
	
	//alert (bottiglieOlio);
	str="La somma delle bottiglie di olio e vino deve essere un multiplo di 6.\n\n";
	str+="Esempio: \n";
	str+="4 bottiglie di vino rosso +\n";
	str+="5 bottiglie di vino bianco +\n";
	str+="3 bottiglie di olio\n";
	str+="= totale 12 bottiglie.\n\n";
	str+="Modifica i quantitativi nel carrello.";

	(bottiglie%6 == 0) ? strError="" : strError=str;
	//alert(str);
	return strError;
}

function submitCartProsegui(){
	
//verifico che se olio e/o vino devono essere multipli di 6 colli

var verColli = controlloNumeroColli();
	//alert ("verColli");
	if (verColli==""){
		document.getElementById("form_cart").action = "cart_conferma.php";
		document.getElementById("form_cart").submit();}
	else{alert(verColli);}
	
}

function resetCart(){
	document.getElementById('cart_div').innerHTML = "<p>0 Prodotti : 00.00 &euro;</p>";
}

function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
		return 1;
	else
	return 0;
}

function viewFAQ(){
	window.open('./condizioniVenditaFAQ.html','newWin','width=500,height=600,scrollbars=yes,menubar=no');
}

function printDiv(){
	if (document.getElementById('descrizioneID') != null){
	
	var a = window.open('','','width=500,height=600,scrollbars=yes,menubar=no');
	a.document.open("text/html");
	a.document.write(document.getElementById('div_print').innerHTML);
	a.document.getElementById('descrizioneID').style.display = 'inline';
	a.document.close();
	a.print();
	}
else{
	alert('Nessuna descrizione per il contenuto di questa confezione');
	}
}


function subscribeNewsletter(){
}
	
//Funzione per ottenere l'oggetto XMLHTTP di Ajax in base ai diversi browser
// funzione che ricava l'oggetto in base al browser dell'utente
function GetXmlHttpObject(){
	var objXmlHttp = null;
	if(window.XMLHttpRequest){
		objXmlHttp = new XMLHttpRequest(); // code for Mozilla, etc.
	}
	else if(window.ActiveXObject){
		objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); // code for IE7
	}
	return objXmlHttp;
}

function openPopup(pagina, larg, alt){
	document.open(pagina,"","width=" + larg + ",height=" + alt);
}