<!--
/*
back	= new Image(160,50); back.src	= "images/back1.jpg";
back_r 	= new Image(160,50); back_r.src	= "images/back2.jpg";
*/

function imgOn(imgX) {
	document.images [imgX].src = eval(imgX + "_r.src");
}

function imgOff(imgX) {
	document.images [imgX].src = eval(imgX + ".src");
}


function showObj(tabName) {
	if (tabName) {
		if(document.getElementById) {
			document.getElementById(tabName).style.display = "block";
		}
		else if(document.all) {
			document.all[tabName].style.display = "block";
		}
	}
}

function hiddenObj(tabName) {
	if (tabName) {
		if(document.getElementById) {
			document.getElementById(tabName).style.display = "none";
		}
		else if(document.all) {
			document.all[tabName].style.display = "none";
		}
	}
}


function vediGrande(tipo,contenuto) {
	winView=window.open ("", "preview", "toolbar=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,width=650,height=650");
	winView.document.write ("<html><head><title>preview</title>");
	winView.document.write ("<body onLoad='self.focus()' bgcolor='#FFFFFF'>");
	if (tipo==1) {
		if (contenuto) {
			winView.document.write ("<center><img src='" + contenuto + "' border='0'><br>");
		}
		else {
			winView.document.write ("<center>la foto non è stata inserita<br>");
		}
	}
	else {
		if (contenuto) {
			winView.document.write ("<br><ul>" + contenuto + "</ul><br><br><center>");
		}
		else {
			winView.document.write ("<br><center>il testo non è stato inserito<br><br>");
		}
	}
	winView.document.write ("<form><input type='button' value='chiudi' onClick=window.close()>");
	winView.document.write ("</form></center></body></html>");
	winView.document.close ();
}


// funzione di visione dell'immagine in popup adattivo
function vediImg(url, popWidth,popHeight,title) {
	
	if (!title){ title = "Immagine";}
	
	if (popWidth=="") {popWidth=400;}
	if (popHeight=="") {popHeight=400;}
	
	var max = Math.max(popWidth,popHeight);
	
	if(max == popWidth && popWidth>800 ){
		popHeight = (800 * popHeight) / popWidth;
		popWidth=800;
	}else if(max == popHeight && popHeight>600 ){
		popWidth = (600 * popWidth) / popHeight;
		popHeight=600;
	}
	
	//console.log("x: %d, y: %d",popWidth,popHeight);
	
	popWidth += 20;
	popHeight += 20;
	
//	winImg=window.open ("", "image", "toolbar=no,directories=no,menubar=no,status=no,location=no,resizable=yes,scrollbars=yes,width="+ {popWidth+20} +",height="+ popHeight);
//	winImg.close();
	winImg=window.open ("", title, "toolbar=no,directories=no,menubar=no,status=no,location=no,resizable=yes,scrollbars=yes,width="+ popWidth +",height="+ popHeight);
	winImg.document.write ("<html><head><title>"+title+"</title>");
	
	popWidth -= 20;
	popHeight -= 20;
	
	winImg.document.write ("<body onLoad='self.focus()' bgcolor='#EEEEEE'><center><img src='" + url + "' width='"+popWidth+"' height='"+popHeight+"' border='0'></center></body></html>");
	winImg.document.close ();
}


// per aprire un link, anche di file, in un pop-up
function apri(url,popWidth,popHeight) {
	if (popWidth=="") {popWidth=400;}
	if (popHeight=="") {popHeight=400;}
	newin = window.open('','page','scrollbars=yes,resizable=yes, width='+ popWidth +',height='+ popHeight +',status=no,location=no,toolbar=no');
	newin.close();
	newin = window.open(url,'page','scrollbars=yes,resizable=yes, width='+ popWidth +',height='+ popHeight +',status=no,location=no,toolbar=no');
}


// formattazione di un numero in valuta con due decimali arrotondati
function formattazioneEuro(euro) {
	var euroInStringa, stringaEuro, stringaCent = "";
	// check eventuale virgola in punto
	euro = euro.toString();
	euro = euro.replace(RegExp(",", "g"), "\.");
	// check is NAN
	if (isNaN(euro)) {euro=0;}
	// check restrizione a due decimali
	euro = Math.round(euro * 100);
	// trasformazione da intero a stringa
	euroInStringa = euro.toString();
	// suddivisione stringa euro e cent
	n_ris = euroInStringa.length;
	stringaEuro = euroInStringa.substr(0,(n_ris-2));
	stringaCent = euroInStringa.substr((n_ris-2),2);
	if (stringaEuro == '') {stringaEuro="0";}
	if (stringaCent == '0') {stringaCent="00";}
	// restituzione stringa formattata
	return stringaEuro + "." + stringaCent;
}


// elimina gli spazi
function spaceClean(obj) {
	obj.value = obj.value.replace(RegExp(" ", "g"), "");
}


// tutto in maiuscolo
function allUpper(obj) {
	obj.value = obj.value.toUpperCase();
}


// validazione strutturale della mail
function validaEMail(mail) {
	var MailRExp = /^[0-9a-zA-Z_\.\-]{2,}@[0-9a-zA-Z_\.\-]{2,}\.[a-zA-Z]{2,}$/;
	if (MailRExp.test(mail)) {return true;}
	else {return false;}
}



// check numero intero e pulitura dello stesso
function checkInteger(obj) {
	if (Number(obj.value)) {
		obj.value = Math.round(obj.value);
	}
	else {
		obj.value = obj.value.replace(RegExp("[^0-9]", "g"), "");
	}
}


// funzione per svuotare un frame
function pulisciFrame(nomeFrame,id,sessione) {
	parent.frames[nomeFrame].location.href = 'frame_blank.php?id='+ id +'&PHPSESSID='+ sessione;
}


// funzione per aprire in un frame una determinara pagina
function pageFrame(nomeFrame,nomePHP,id,sessione) {
	parent.frames[nomeFrame].location.href = nomePHP +'?id='+ id +'&PHPSESSID='+ sessione;
}


// è possibile stampare solo un'area della pagina
function stampaPagina(area) {
	if (area) {
		if(document.getElementById) {
			var testo = document.getElementById(area).innerHTML;
		}
		else if(document.all) {
			var testo = document.all[area].innerHTML;
		}
		var finestra = window.open("about:blank");
/*
test per inserire un foglio di stile...  ... da finire di testare...
		var finestra=window.open ("", "Stampa", "toolbar=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,width=800,height=600");
		finestra.document.write("<html><head><title>Stampa</title>\n");
//		finestra.document.write('<link rel="stylesheet" type="text/css" href="../celivo.css">');
		finestra.document.write("</head>\n<body onLoad='window.print()' bgcolor='#FFFFFF'>\n");
		finestra.document.write("<table><tr>\n");
		finestra.document.write(testo);
		finestra.document.write("</tr></table></body></html>");
*/
		finestra.document.body.innerHTML = "<table><tr>"+ testo +"</tr></table>";
//		finestra.document.body.innerHTML = testo;
//		finestra.print();
//		finestra.close()
	}
}


// popup di stampa pagina ordine
function stampaPaginaOrdine(area1,area2) {
	if(document.getElementById) {
		var testo1 = document.getElementById(area1).innerHTML;
		var testo2 = document.getElementById(area2).innerHTML;
	}
	else if(document.all) {
		var testo1 = document.all[area1].innerHTML;
		var testo2 = document.all[area2].innerHTML;
	}
	var finestra=window.open ("", "Stampa_Ordine", "toolbar=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,width=800,height=720");
	finestra.document.write("<html><head><title>Stampa Ordine</title>");
	finestra.document.write("<link rel='stylesheet' type='text/css' href='gedion.css'>");
	finestra.document.write("</head>\n<body onLoad='self.focus()'>");
	finestra.document.write("<p align='center'><img src='images/header_cat_stampa.jpg' width='708' height='72' border='0' alt='La Coloniale snc - Catalogo Online'></p>");
	finestra.document.write("<table width='708' cellpadding='0' cellspacing='0' border='0' align='center'><tr><td width='450' align='center' valign='top'>");
	finestra.document.write(testo1);
	finestra.document.write("</td><td width='10'>&nbsp;</td><td width='248' align='left' valign='top' class=''>");
	finestra.document.write(testo2);
	finestra.document.write("</td></tr></table>");
	finestra.document.write("<form><p align='center'><input type='button' name='stampa' value=' stampa ' onClick='window.print()' class='formMiniBott'> &nbsp; ");
	finestra.document.write("<input type='button' name='chiudi' value=' chiudi ' onClick='window.close()' class='formMiniBott'>");
	finestra.document.write("</p></form></body></html>");
	finestra.document.close();
}










////// FUNZIONI PER LA REGISTRAZIONE UTENTE //////

// accesso utente
function ckLogin() {
	if ((!document.accesso.user.value)||(!document.accesso.pass.value)) {
		alert('ATTENZIONE !\n\nè necessario inserire username e password per poter proseguire.');
		return false;
	}
	else {
		return true;
	}
}

// accesso utente Header
function ckLoginHeader() {
	if ((!document.accessoHeader.user.value)||(!document.accessoHeader.pass.value)) {
		alert('ATTENZIONE !\n\nè necessario inserire username e password per poter proseguire.');
		return false;
	}
	else {
		return true;
	}
}

// tipo registrazione nello step b
function regUte_PFSoc() {
	var classeBlank = "formMini";
	document.reg_b.azienda.className = classeBlank;
	document.reg_b.p_iva.className = classeBlank;
	document.reg_b.nome.className = classeBlank;
	document.reg_b.cognome.className = classeBlank;

	if (document.reg_b.pf_soc.value=="1") {
		// azienda
		if (document.getElementById) {
			document.getElementById("campo_azienda").style.display = "block";
			document.getElementById("campo_nome").style.display = "none";
			document.getElementById("campo_cognome").style.display = "none";
//			document.getElementById("campo_p_iva").style.display = "block";
		}
		else if (document.all) {
			document.all["campo_azienda"].style.display = "block";
			document.all["campo_nome"].style.display = "none";
			document.all["campo_cognome"].style.display = "none";
//			document.all["campo_p_iva"].style.display = "block";
		}
	}
	else {
		// persona
		if (document.getElementById) {
			document.getElementById("campo_azienda").style.display = "none";
			document.getElementById("campo_nome").style.display = "block";
			document.getElementById("campo_cognome").style.display = "block";
//			document.getElementById("campo_p_iva").style.display = "none";
		}
		else if (document.all) {
			document.all["campo_azienda"].style.display = "none";
			document.all["campo_nome"].style.display = "block";
			document.all["campo_cognome"].style.display = "block";
//			document.all["campo_p_iva"].style.display = "none";
		}
	}
}


// controllo obbligatorietà, privacy e altro
function reg_checkFormB() {
	var errore = '';
	var classeObb = "formMiniObbligatorio";
	var classeBlank = "formMini";
	var checkSoc = 0;
	var checkIVA = 0;
	var checkCF = 0;

	// società
	if (document.reg_b.pf_soc.value=="1") {
		if (!(document.reg_b.azienda.value)) {
			errore = '\n - Ragione Sociale non presente';
			checkSoc = 1;
		}
		if (document.reg_b.nazione.value == "ITA") {
			if (!(document.reg_b.p_iva.value)) {
				errore += '\n - Partita IVA non presente';
				checkIVA = 1;
			}
			else if (!check_piva(document.reg_b.p_iva.value)) {
				errore += '\n - Partita IVA non corretta';
				checkIVA = 1;
			}
		}
	}
	else {
		// persona
		if (!(document.reg_b.nome.value)) {
			errore += '\n - Nome non presente';
			document.reg_b.nome.className = classeObb;
		}
		else {document.reg_b.nome.className = classeBlank;}

		if (!(document.reg_b.cognome.value)) {
			errore += '\n - Cognome non presente';
			document.reg_b.cognome.className = classeObb;
		}
		else {document.reg_b.cognome.className = classeBlank;}

		// check eventuale inserimento della p.iva
		if ((document.reg_b.nazione.value == "ITA")&&(document.reg_b.p_iva.value)&&(!check_piva(document.reg_b.p_iva.value))) {
			errore += '\n - Partita IVA non corretta';
		}
	}

	if (!(document.reg_b.indirizzo.value)) {
		errore += '\n - Indirizzo non presente';
		document.reg_b.indirizzo.className = classeObb;
	}
	else {document.reg_b.indirizzo.className = classeBlank;}

	if (!(document.reg_b.cap.value)) {
		errore += '\n - CAP non presente';
		document.reg_b.cap.className = classeObb;
	}
	else {document.reg_b.cap.className = classeBlank;}

	if (!(document.reg_b.comune.value)) {
		errore += '\n - Comune non presente';
		document.reg_b.comune.className = classeObb;
	}else if((document.reg_b.nazione.value == "ITA") && !(document.reg_b.comune_istat.value)){
		errore += '\n - Comune non riconosciuto';
		document.reg_b.comune.className = classeObb;
	}
	else {document.reg_b.comune.className = classeBlank;}
	
	if (!(document.reg_b.provincia.value)) {
		errore += '\n - Provincia non presente';
		document.reg_b.provincia.className = classeObb;
	}else if((document.reg_b.nazione.value == "ITA") && !(document.reg_b.provincia_istat.value)){
		errore += '\n - Provincia non riconosciuta';
		document.reg_b.provincia.className = classeObb;
	}
	else {document.reg_b.provincia.className = classeBlank;}

	if ((document.reg_b.nazione.value == "ITA")&&((document.reg_b.pf_soc.value == "1")||(document.reg_b.flag_fattura.value == "1"))) {
		if (!(document.reg_b.cod_fiscale.value)) {
			errore += '\n - Codice Fiscale non presente';
			checkCF = 1;
		}
		else {
			if (document.reg_b.cod_fiscale.value.length==16) {
				if (!check_cf(document.reg_b.cod_fiscale.value)) {
					errore += '\n - Codice Fiscale non corretto';
					checkCF = 1;
				}
			}
			else if ((document.reg_b.cod_fiscale.value.length==11)||(document.reg_b.cod_fiscale.value.length==13)) {
				if (!check_piva(document.reg_b.cod_fiscale.value)) {
					errore += '\n - Codice Fiscale non corretto';
					checkCF = 1;
				}
			}
			else {
				errore += '\n - Codice Fiscale non valido';
				checkCF = 1;
			}
		}
	}
	else if ((document.reg_b.nazione.value == "ITA")&&(document.reg_b.cod_fiscale.value)) {
		if (document.reg_b.cod_fiscale.value.length==16) {
			if (!check_cf(document.reg_b.cod_fiscale.value)) {
				errore += '\n - Codice Fiscale non corretto';
			}
		}
		else if ((document.reg_b.cod_fiscale.value.length==11)||(document.reg_b.cod_fiscale.value.length==13)) {
			if (!check_piva(document.reg_b.cod_fiscale.value)) {
				errore += '\n - Codice Fiscale non corretto';
			}
		}
		else {
			errore += '\n - Codice Fiscale non valido';
		}
	}

	var checkEmail = 0;
	if (!(document.reg_b.email.value)) {
		errore += '\n - Email non presente';
		checkEmail = 1;
	}
	else if (!validaEMail(document.reg_b.email.value)) {
		errore += '\n - Email non corretta';
		checkEmail = 1;
	}
	else if (document.reg_b.ckuser.value == "0") {
		errore += '\n - Email già utilizzata come username da un altro utente';
		checkEmail = 1;
	}

	// controllo password
	var checkPsw = 0;
	if (!(document.reg_b.pass.value)) {
		errore += '\n - Password non presente';
		checkPsw = 1;
	}
	else if (document.reg_b.pass.value != document.reg_b.repass.value) {
		errore += '\n - la Password non è confermata';
		checkPsw = 1;
	}
	else if (document.reg_b.pass.value.length < 6) {
		errore += '\n - la Password deve essere di almeno 6 caratteri';
		checkPsw = 1;
	}

	if (checkPsw==1) {
		document.reg_b.pass.className = classeObb;
		document.reg_b.repass.className = classeObb;
		document.reg_b.repass.value = '';
	}
	else {
		document.reg_b.pass.className = classeBlank;
		document.reg_b.repass.className = classeBlank;
	}

	if (checkSoc == 1) {document.reg_b.azienda.className = classeObb;}
	else {document.reg_b.azienda.className = classeBlank;}

	if (checkIVA == 1) {document.reg_b.p_iva.className = classeObb;}
	else {document.reg_b.p_iva.className = classeBlank;}

	if (checkCF == 1) {document.reg_b.cod_fiscale.className = classeObb;}
	else {document.reg_b.cod_fiscale.className = classeBlank;}

	if (checkEmail == 1) {document.reg_b.email.className = classeObb;}
	else {document.reg_b.email.className = classeBlank;}
	
	
	if (errore) {
		alert('ATTENZIONE !!!\n\nper proseguire devi controllare i seguenti dati:\n' + errore + '\n\nTutti i campi in rosso sono obbligatori.');
		return false;
	}
	else {
		if (!(document.reg_b.privacy[0].checked)) {
			alert('ATTENZIONE !!!\n\nse non si consente al trattamento dei dati personali secondo la legge 196/03, non è possibile proseguire.');
			return false;
		}
		else {
			return true;
		}
	}
}

// controllo p.iva
function reg_checkPIVA(campo) {
	if ((document.reg_b.nazione.value == "ITA")&&(campo)&&(!check_piva(campo))) {
		alert('ATTENZIONE!!!\n\nPartita IVA non corretta.');
	}
}

// controllo c.f.
function reg_checkCF(campo) {
	if ((document.reg_b.nazione.value == "ITA")&&(campo.length==16)) {
		if (!check_cf(campo)) {alert('ATTENZIONE!!!\n\nCodice Fiscale non corretto.');}
	}
	else if ((document.reg_b.nazione.value == "ITA")&&((campo.length==11)||(campo.length==13))) {
		if (!check_piva(campo)) {alert('ATTENZIONE!!!\n\nCodice Fiscale non corretto.');}
	}
	else if ((document.reg_b.nazione.value == "ITA")&&(campo)) {
		alert('ATTENZIONE!!!\n\nCodice Fiscale non valido.');
	}
}

// controllo email
function reg_checkMAIL(email) {
	if ((email)&&(!validaEMail(email))) {
		alert('ATTENZIONE!!!\n\nEmail non corretta.');
	}
}

// controllo validità email e che non esista già come user negli utenti
function regUte_ckmail(obj) {
	if (obj.value) {
		if (!validaEMail(obj.value)) {
			alert('ATTENZIONE!!!\n\nEmail non corretta.');
		}
		else {
			// check preesistenza username
			regUte_ckUser(obj);
		}
	}
}

// controllo che non esista già come user negli utenti - con Ajax
function regUte_ckUser(obj) {
	var url_php = "cerca_ajax.php?op=cercaUser&email="+ obj.value;
	if (httpPHP) {
		httpPHP.open('GET', url_php, true);
		httpPHP.onreadystatechange = ajaxResponse_cercaUser;
		httpPHP.send(null);
	}
}

// ritorno dati per controllo preesistenza user
function ajaxResponse_cercaUser() {
	if (httpPHP.readyState == 4) {
		if (httpPHP.status == 200) {
//			alert(httpPHP.responseText);

			// Use the XML DOM
			var xmlDoc = httpPHP.responseXML;
 			var errore_dati = xmlDoc.getElementsByTagName('errore_dati').item(0).firstChild;
			if (errore_dati) {
				alert(errore_dati.textContent);
			}
			else {
				// conferma esito
				var esito = xmlDoc.getElementsByTagName('esito').item(0).firstChild.textContent;
				if (esito == "1") {
					alert('ATTENZIONE!!!\n\nusername non utilizzabile perchè già presente\n\nInserire una email nuova.');
					document.reg_b.ckuser.value="0";
				}
				else {
					document.reg_b.ckuser.value="1";
				}
			}
		}
		else {
			alert('There was a problem with the request.');
		}
	}
}









////// FUNZIONI PER IL CONTROLLO DATI ACCOUNT REGISTRATO //////

// funzione di controllo per il cambio password
function checkCambioPsw() {
	var errore = '';
	var classeObb = "formMiniObbligatorio";
	var classeBlank = "formMini";
	var checkPsw = 0;

	if (!(document.cngpsw.oldpassw.value)) {
		errore += '\n - Password attuale non presente';
		document.cngpsw.oldpassw.className = classeObb;
	}
	else {
		document.cngpsw.oldpassw.className = classeBlank;
	}

	if (!(document.cngpsw.passw.value)) {
		errore += '\n - Nuova password non presente';
		checkPsw = 1;
	}
	else if (document.cngpsw.passw.value != document.cngpsw.confpassw.value) {
		errore += '\n - la nuova password non è confermata';
		checkPsw = 1;
	}
	else if (document.cngpsw.passw.value.length < 6) {
		errore += '\n - la nuova password deve essere di almeno 6 caratteri';
		checkPsw = 1;
	}

	if (checkPsw==1) {
		document.cngpsw.passw.className = classeObb;
		document.cngpsw.confpassw.className = classeObb;
		document.cngpsw.confpassw.value = '';
	}
	else {
		document.cngpsw.passw.className = classeBlank;
		document.cngpsw.confpassw.className = classeBlank;
	}

	if (errore) {
		alert('ATTENZIONE !!!\n\nper proseguire devi controllare i seguenti dati:\n' + errore + '\n\nTutti i campi sono obbligatori.');
		return false;
	}
	else {
		return true;
	}
}










////// FUNZIONI PER IL CARRELLO ELETTRONICO //////

// funzione per far apparire una immagine
function updateArticolo(art) {
	hiddenObj("upd"+ art +"_off");
	showObj("upd"+ art +"_on");
}

// funzione di controllo quantità per l'inserimento nel carrello
function ckInsCar() {
	if (!((document.inCarrello.qnt.value)&&(document.inCarrello.qnt.value>0))) {
		document.inCarrello.qnt.value = 1;
	}
	return true;
}
function ckInsCar_pre() {
	if (ckInsCar()) {
		document.inCarrello.submit();
	}
}

function car_cambioClasse(n) {
	hiddenObj("corpo1");
	hiddenObj("corpo2");
	hiddenObj("corpo3");
	showObj("corpo"+n);

	if (n==1) {
		if(document.getElementById) {
			document.getElementById("cell_c1").className = "cellStyle4";
			document.getElementById("cell_c2").className = "bordo1_basso bordo1_sx cellStyle7";
			document.getElementById("cell_c3").className = "bordo1_basso bordo1_sx cellStyle6";
			document.getElementById("cell_c").className = "cellStyle4";
		}
		else if(document.all) {
			document.all("cell_c1").className = "cellStyle4";
			document.all("cell_c2").className = "bordo1_basso bordo1_sx cellStyle7";
			document.all("cell_c3").className = "bordo1_basso bordo1_sx cellStyle6";
			document.all("cell_c").className = "cellStyle4";
		}
	}
	else if (n==2) {
		if(document.getElementById) {
			document.getElementById("cell_c1").className = "bordo1_basso cellStyle4";
			document.getElementById("cell_c2").className = "bordo1_sx cellStyle7";
			document.getElementById("cell_c3").className = "bordo1_basso bordo1_sx cellStyle6";
			document.getElementById("cell_c").className = "cellStyle7";
		}
		else if(document.all) {
			document.all("cell_c1").className = "bordo1_basso cellStyle4";
			document.all("cell_c2").className = "bordo1_sx cellStyle7";
			document.all("cell_c3").className = "bordo1_basso bordo1_sx cellStyle6";
			document.all("cell_c").className = "cellStyle7";
		}
	}
	else if (n==3) {
		if(document.getElementById) {
			document.getElementById("cell_c1").className = "bordo1_basso cellStyle4";
			document.getElementById("cell_c2").className = "bordo1_basso bordo1_sx cellStyle7";
			document.getElementById("cell_c3").className = "bordo1_sx cellStyle6";
			document.getElementById("cell_c").className = "cellStyle6";
		}
		else if(document.all) {
			document.all("cell_c1").className = "bordo1_basso cellStyle4";
			document.all("cell_c2").className = "bordo1_basso bordo1_sx cellStyle7";
			document.all("cell_c3").className = "bordo1_sx cellStyle6";
			document.all("cell_c").className = "cellStyle6";
		}
	}
}


function getSplash() {
	var url_php = "showSplash.php";
	if (httpPHP) {
		httpPHP.open('GET', url_php, true);
		httpPHP.onreadystatechange = showSplash;
		httpPHP.send(null);
	}
}

function showSplash() {
	if (httpPHP.readyState == 4) {
		if (httpPHP.status == 200) {
		//	alert(httpPHP.responseText);
			var splashHTML = httpPHP.responseText;
			var body = document.getElementsByTagName('body')[0];
			var container = document.createElement('div');
			body.appendChild(container);
			
			container.innerHTML=splashHTML;
		}
	}
}

function closeSplash(){
	var splash = document.getElementById('splash');
	if(splash!=null){
		splash.style.display='none';
	}
}

function clickSplash(id_cat){
	var splash = document.getElementById('splash');
	if(splash!=null){
		splash.style.display='none';
	}
	location=('catalogo.php?id_cat='+id_cat);
}

////// FUNZIONI PER LA CONFERMA D'ORDINE //////

// emette le spese per tipo di spedizione
function ordTipoSpedizione() {
	var sped = Number(document.ordinePag.tipo_spedizione.options[document.ordinePag.tipo_spedizione.selectedIndex].getAttribute('spese'));
	sped = formattazioneEuro(sped);
	sped = sped.toString();
	document.ordinePag.spese_spedizione.value = sped.replace(RegExp("\\.", "g"), ",");

	// disattivo il pulsante se viene azzerata la scelta
	if (document.ordinePag.tipo_spedizione.value=="0") {
		document.ordinePag.salva.disabled = "disabled";
	}

	// ricalcola il totale
	ordTotaleOrdine();
}


// valorizza le spese per tipo di pagamento
function ordTipoPagamento() {
	var spese_pagamento = 0;
	var tipo_pagamento = 0;
	var label_pagamento = '';

	for ($i=0; $i<document.ordinePag.tipo_pagamento.length; $i++) {
		if (document.ordinePag.tipo_pagamento[$i].checked) {
			tipo_pagamento = document.ordinePag.tipo_pagamento[$i].value;
			spese_pagamento = Number(document.ordinePag.elements["spese_" + tipo_pagamento].value);
		}
	}

	if (tipo_pagamento=="1") {
		// conto corrente postale
		label_pagamento = "Spese pagamento con conto corrente postale";
	}
	else if (tipo_pagamento=="3") {
		// carta di credito
		label_pagamento = "Spese pagamento con carta di credito";
	}
	else if (tipo_pagamento=="4") {
		// contrassegno
		label_pagamento = "Spese pagamento in contrassegno";
	}
	else if (tipo_pagamento=="7") {
		// bonifico
		label_pagamento = "Spese pagamento con bonifico bancario";
	}

	if (spese_pagamento>0) {
		spese_pagamento = formattazioneEuro(spese_pagamento);
		spese_pagamento = spese_pagamento.toString();
		document.ordinePag.spese_pagamento.value = spese_pagamento.replace(RegExp("\\.", "g"), ",");
		document.ordinePag.descrSpesePag.value = label_pagamento;
		showObj('descrSpesePag');
		showObj('euro');
		showObj('spese_pagamento');
	}
	else {
		document.ordinePag.spese_pagamento.value = 0;
		document.ordinePag.descrSpesePag.value = '';
		hiddenObj('descrSpesePag');
		hiddenObj('euro');
		hiddenObj('spese_pagamento');
	}

	// ricalcola il totale
	ordTotaleOrdine();
}


// calcolo del totale dell'ordine
function ordTotaleOrdine() {
	var	spese_spedizione = Number(document.ordinePag.spese_spedizione.value.replace(RegExp(",", "g"), "\."));
	var spese_pagamento = Number(document.ordinePag.spese_pagamento.value.replace(RegExp(",", "g"), "\."));
	var totale_car = Number(document.ordinePag.totale_car.value.replace(RegExp(",", "g"), "\."));
	var totale = formattazioneEuro(totale_car + spese_spedizione + spese_pagamento);
	totale = totale.toString();
	document.ordinePag.totale.value = totale.replace(RegExp("\\.", "g"), ",");

	// se è selezionato sia il pagamento che la spedizione allora far proseguire
	var CKpagamento = 0;
	for (var i=0; i<document.ordinePag.tipo_pagamento.length; i++) {
		if (document.ordinePag.tipo_pagamento[i].checked) {
			CKpagamento = 1;
		}
	}
	if ((!CKpagamento)&&(document.ordinePag.tipo_pagamento.checked)) {
		CKpagamento = 1;
	}

	if ((CKpagamento)&&((document.ordinePag.tipo_spedizione.value != "0")||(document.ordinePag.flag_spese_spedizione.value == "0"))) {
		document.ordinePag.salva.disabled = "";
	}
}


// controllo ordine, per conferma dati 1°step
function ordCkOrdineConfdati() {
	var errore = '';
	var pagamento_presente = 0;
	var classeObb = "formMiniObbligatorio";
	var classeBlank = "formMini";

	for ($i=0; $i<document.ordinePag.tipo_pagamento.length; $i++) {
		if (document.ordinePag.tipo_pagamento[$i].checked) {pagamento_presente = 1;}
	}
	if (!pagamento_presente) {errore += '\n - tipo pagamento non selezionato';}
	if ((document.ordinePag.tipo_spedizione.value=="0")&&(document.ordinePag.flag_spese_spedizione.value != "0")) {errore += '\n - tipo spedizione non selezionato';}

	var CKdati_sped = 0;
	if (!(document.ordinePag.nome_spedizione.value)) {document.ordinePag.nome_spedizione.className = classeObb; CKdati_sped = 1;}
	else {document.ordinePag.nome_spedizione.className = classeBlank;}

	if (!(document.ordinePag.indirizzo_spedizione.value)) {document.ordinePag.indirizzo_spedizione.className = classeObb; CKdati_sped = 1;}
	else {document.ordinePag.indirizzo_spedizione.className = classeBlank;}

	if (!(document.ordinePag.cap_spedizione.value)) {document.ordinePag.cap_spedizione.className = classeObb; CKdati_sped = 1;}
	else {document.ordinePag.cap_spedizione.className = classeBlank;}

	if (!(document.ordinePag.comune_spedizione.value)) {document.ordinePag.comune_spedizione.className = classeObb; CKdati_sped = 1;}
	else {document.ordinePag.comune_spedizione.className = classeBlank;}

	if (!(document.ordinePag.provincia_spedizione.value)) {document.ordinePag.provincia_spedizione.className = classeObb; CKdati_sped = 1;}
	else {document.ordinePag.provincia_spedizione.className = classeBlank;}

	if (CKdati_sped == 1) {
		errore += '\n - i dati per la spedizione non sono completi\n\nI campi in rosso sono obbligatori per poter proseguire.';
	}

	if (errore) {
		alert('ATTENZIONE !!!\n\nper proseguire devi controllare i seguenti dati:\n' + errore);
		return false;
	}
	else {
		return true;
	}
}


// controllo del flag di dichiarazione di preso visione delle condizioni di fornitura
function ordConfermaDef(nomeForm) {
	if (!document.forms[nomeForm].flag_condizioni.checked) {
		alert('ATTENZIONE !!!\n\nper proseguire è necessario dichiarare di aver preso visione delle condizioni di fornitura.');
		return false;
	}
	else {
		return true;
	}
}


// controllo del flag di dichiarazione di preso visione delle condizioni di fornitura
function ordFlagCondizioni(nomeForm) {
	alert(nomeForm);
	if (document.forms[nomeForm].flag_condizioni.checked) {
		document.forms[nomeForm].submit.disabled = '';
		//document.forms[nomeForm].submit.removeClass('disabled');
		alert('abilito');
	}
	else {
		document.forms[nomeForm].submit.disabled = 'disabled';
		alert('sisabilito');
		//document.forms[nomeForm].submit.addClass('disabled');
	}
}


// controllo nazione di spedizione
function ordSpedEstero() {
	// disattivo il pulsante di invio
	document.ordinePag.salva.disabled = "disabled";
	document.ordinePag.spese_spedizione.value = "0.00";
	document.ordinePag.spese_pagamento.value = "0.00";

	// cancella tutte le item per le spese spedizione
	var maxitem = document.getElementById('tipo_spedizione').length;
	maxitem = maxitem - 1;
	for (var i=0; i<maxitem; i++) {
		document.getElementById('tipo_spedizione').remove(1);
	}

	// spedizione estera o nazionale
	if (document.ordinePag.nazione_spedizione.value != "ITA") {
		// ricrea le scelte del tipo spedizione estera
		for (var i=0; i<spedEXTvalue.length; i++) {
			addToSelect('tipo_spedizione',spedEXTvalue[i],spedEXTlabel[i]);
			document.ordinePag.tipo_spedizione.options[i+1].setAttribute('spese',spedEXTspese[i]);
		}

		// nascondi tipi pagamento
		if (document.ordinePag.pag_estero_1.value == "0") {
			hiddenObj('rigaPag1');
		}
		if (document.ordinePag.pag_estero_3.value == "0") {
			hiddenObj('rigaPag3');
		}
		if (document.ordinePag.pag_estero_4.value == "0") {
			hiddenObj('rigaPag4');
		}
		if (document.ordinePag.pag_estero_7.value == "0") {
			hiddenObj('rigaPag7');
		}
	}
	else {
		// ricrea le scelte del tipo spedizione nazionale
		for (var i=0; i<spedITvalue.length; i++) {
			addToSelect('tipo_spedizione',spedITvalue[i],spedITlabel[i]);
			document.ordinePag.tipo_spedizione.options[i+1].setAttribute('spese',spedITspese[i]);
		}

		// visualizza tutti i tipi pagamento
		showObj('rigaPag1');
		showObj('rigaPag3');
		showObj('rigaPag4');
		showObj('rigaPag7');
	}
}


// per aggiungere valori in un elemento select
function addToSelect(oggetto,valore,etichetta) {
	var newOption = document.createElement("option");
	newOption.value = valore;
	newOption.text = etichetta;
	document.getElementById(oggetto).options[document.getElementById(oggetto).length] = new Option(etichetta,valore);
//	document.getElementById(oggetto).add(newOption);
//	document.getElementById(oggetto).options[item] = new Option(valore,etichetta);		// per inserire in un preciso punto (item)
}



// funzione per la conversione delle lettere accentate
function encode(str){
	return encodeURIComponent(escape(str));
}

function decode(str){
	return decodeURIComponent(unescape(str));
}

function htmlspecialchars (string, quote_style, charset, double_encode) {
    // http://kevin.vanzonneveld.net
    // +   original by: Mirek Slugen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Nathan
    // +   bugfixed by: Arno
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Ratheous
    // +      input by: Mailfaker (http://www.weedem.fr/)
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +      input by: felix
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // %        note 1: charset argument not supported
    // *     example 1: htmlspecialchars("<a href='test'>Test</a>", 'ENT_QUOTES');
    // *     returns 1: '&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;'
    // *     example 2: htmlspecialchars("ab\"c'd", ['ENT_NOQUOTES', 'ENT_QUOTES']);
    // *     returns 2: 'ab"c&#039;d'
    // *     example 3: htmlspecialchars("my "&entity;" is still here", null, null, false);
    // *     returns 3: 'my &quot;&entity;&quot; is still here'

    var optTemp = 0, i = 0, noquotes= false;
    if (typeof quote_style === 'undefined' || quote_style === null) {
        quote_style = 2;
    }
    string = string.toString();
    if (double_encode !== false) { // Put this first to avoid double-encoding
        string = string.replace(/&/g, '&amp;');
    }
    string = string.replace(/</g, '&lt;').replace(/>/g, '&gt;');

    var OPTS = {
        'ENT_NOQUOTES': 0,
        'ENT_HTML_QUOTE_SINGLE' : 1,
        'ENT_HTML_QUOTE_DOUBLE' : 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE' : 4
    };
    if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
        quote_style = [].concat(quote_style);
        for (i=0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;
            }
            else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }
        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/'/g, '&#039;');
    }
    if (!noquotes) {
        string = string.replace(/"/g, '&quot;');
    }

    return string;
}


function htmlDecode(s) {
	var out = "";
   if (s==null) return;
   var l = s.length;
   for (var i=0; i<l; i++)
   {
		var ch = s.charAt(i);
      if (ch == '&') {
			var semicolonIndex = s.indexOf(';', i+1);
         if (semicolonIndex > 0) {
				var entity = s.substring(i + 1, semicolonIndex);
            if (entity.length > 1 && entity.charAt(0) == '#') {
					if (entity.charAt(1) == 'x' || entity.charAt(1) == 'X')
               	ch = String.fromCharCode(eval('0'+entity.substring(1)));
               else
               	ch = String.fromCharCode(eval(entity.substring(1)));
            } else {
               switch (entity) {
						case 'quot': ch = String.fromCharCode(0x0022); break;
						case 'amp': ch = String.fromCharCode(0x0026); break;
						case 'lt': ch = String.fromCharCode(0x003c); break;
						case 'gt': ch = String.fromCharCode(0x003e); break;
						case 'nbsp': ch = String.fromCharCode(0x00a0); break;
						case 'iexcl': ch = String.fromCharCode(0x00a1); break;
						case 'cent': ch = String.fromCharCode(0x00a2); break;
						case 'pound': ch = String.fromCharCode(0x00a3); break;
						case 'curren': ch = String.fromCharCode(0x00a4); break;
						case 'yen': ch = String.fromCharCode(0x00a5); break;
						case 'brvbar': ch = String.fromCharCode(0x00a6); break;
						case 'sect': ch = String.fromCharCode(0x00a7); break;
						case 'uml': ch = String.fromCharCode(0x00a8); break;
						case 'copy': ch = String.fromCharCode(0x00a9); break;
						case 'ordf': ch = String.fromCharCode(0x00aa); break;
						case 'laquo': ch = String.fromCharCode(0x00ab); break;
						case 'not': ch = String.fromCharCode(0x00ac); break;
						case 'shy': ch = String.fromCharCode(0x00ad); break;
						case 'reg': ch = String.fromCharCode(0x00ae); break;
						case 'macr': ch = String.fromCharCode(0x00af); break;
						case 'deg': ch = String.fromCharCode(0x00b0); break;
						case 'plusmn': ch = String.fromCharCode(0x00b1); break;
						case 'sup2': ch = String.fromCharCode(0x00b2); break;
						case 'sup3': ch = String.fromCharCode(0x00b3); break;
						case 'acute': ch = String.fromCharCode(0x00b4); break;
						case 'micro': ch = String.fromCharCode(0x00b5); break;
						case 'para': ch = String.fromCharCode(0x00b6); break;
						case 'middot': ch = String.fromCharCode(0x00b7); break;
						case 'cedil': ch = String.fromCharCode(0x00b8); break;
						case 'sup1': ch = String.fromCharCode(0x00b9); break;
						case 'ordm': ch = String.fromCharCode(0x00ba); break;
						case 'raquo': ch = String.fromCharCode(0x00bb); break;
						case 'frac14': ch = String.fromCharCode(0x00bc); break;
						case 'frac12': ch = String.fromCharCode(0x00bd); break;
						case 'frac34': ch = String.fromCharCode(0x00be); break;
						case 'iquest': ch = String.fromCharCode(0x00bf); break;
						case 'Agrave': ch = String.fromCharCode(0x00c0); break;
						case 'Aacute': ch = String.fromCharCode(0x00c1); break;
						case 'Acirc': ch = String.fromCharCode(0x00c2); break;
						case 'Atilde': ch = String.fromCharCode(0x00c3); break;
						case 'Auml': ch = String.fromCharCode(0x00c4); break;
						case 'Aring': ch = String.fromCharCode(0x00c5); break;
						case 'AElig': ch = String.fromCharCode(0x00c6); break;
						case 'Ccedil': ch = String.fromCharCode(0x00c7); break;
						case 'Egrave': ch = String.fromCharCode(0x00c8); break;
						case 'Eacute': ch = String.fromCharCode(0x00c9); break;
						case 'Ecirc': ch = String.fromCharCode(0x00ca); break;
						case 'Euml': ch = String.fromCharCode(0x00cb); break;
						case 'Igrave': ch = String.fromCharCode(0x00cc); break;
						case 'Iacute': ch = String.fromCharCode(0x00cd); break;
						case 'Icirc': ch = String.fromCharCode(0x00ce ); break;
						case 'Iuml': ch = String.fromCharCode(0x00cf); break;
						case 'ETH': ch = String.fromCharCode(0x00d0); break;
						case 'Ntilde': ch = String.fromCharCode(0x00d1); break;
						case 'Ograve': ch = String.fromCharCode(0x00d2); break;
						case 'Oacute': ch = String.fromCharCode(0x00d3); break;
						case 'Ocirc': ch = String.fromCharCode(0x00d4); break;
						case 'Otilde': ch = String.fromCharCode(0x00d5); break;
						case 'Ouml': ch = String.fromCharCode(0x00d6); break;
						case 'times': ch = String.fromCharCode(0x00d7); break;
						case 'Oslash': ch = String.fromCharCode(0x00d8); break;
						case 'Ugrave': ch = String.fromCharCode(0x00d9); break;
						case 'Uacute': ch = String.fromCharCode(0x00da); break;
						case 'Ucirc': ch = String.fromCharCode(0x00db); break;
						case 'Uuml': ch = String.fromCharCode(0x00dc); break;
						case 'Yacute': ch = String.fromCharCode(0x00dd); break;
						case 'THORN': ch = String.fromCharCode(0x00de); break;
						case 'szlig': ch = String.fromCharCode(0x00df); break;
						case 'agrave': ch = String.fromCharCode(0x00e0); break;
						case 'aacute': ch = String.fromCharCode(0x00e1); break;
						case 'acirc': ch = String.fromCharCode(0x00e2); break;
						case 'atilde': ch = String.fromCharCode(0x00e3); break;
						case 'auml': ch = String.fromCharCode(0x00e4); break;
						case 'aring': ch = String.fromCharCode(0x00e5); break;
						case 'aelig': ch = String.fromCharCode(0x00e6); break;
						case 'ccedil': ch = String.fromCharCode(0x00e7); break;
						case 'egrave': ch = String.fromCharCode(0x00e8); break;
						case 'eacute': ch = String.fromCharCode(0x00e9); break;
						case 'ecirc': ch = String.fromCharCode(0x00ea); break;
						case 'euml': ch = String.fromCharCode(0x00eb); break;
						case 'igrave': ch = String.fromCharCode(0x00ec); break;
						case 'iacute': ch = String.fromCharCode(0x00ed); break;
						case 'icirc': ch = String.fromCharCode(0x00ee); break;
						case 'iuml': ch = String.fromCharCode(0x00ef); break;
						case 'eth': ch = String.fromCharCode(0x00f0); break;
						case 'ntilde': ch = String.fromCharCode(0x00f1); break;
						case 'ograve': ch = String.fromCharCode(0x00f2); break;
						case 'oacute': ch = String.fromCharCode(0x00f3); break;
						case 'ocirc': ch = String.fromCharCode(0x00f4); break;
						case 'otilde': ch = String.fromCharCode(0x00f5); break;
						case 'ouml': ch = String.fromCharCode(0x00f6); break;
						case 'divide': ch = String.fromCharCode(0x00f7); break;
						case 'oslash': ch = String.fromCharCode(0x00f8); break;
						case 'ugrave': ch = String.fromCharCode(0x00f9); break;
						case 'uacute': ch = String.fromCharCode(0x00fa); break;
						case 'ucirc': ch = String.fromCharCode(0x00fb); break;
						case 'uuml': ch = String.fromCharCode(0x00fc); break;
						case 'yacute': ch = String.fromCharCode(0x00fd); break;
						case 'thorn': ch = String.fromCharCode(0x00fe); break;
						case 'yuml': ch = String.fromCharCode(0x00ff); break;
						case 'OElig': ch = String.fromCharCode(0x0152); break;
						case 'oelig': ch = String.fromCharCode(0x0153); break;
						case 'Scaron': ch = String.fromCharCode(0x0160); break;
						case 'scaron': ch = String.fromCharCode(0x0161); break;
						case 'Yuml': ch = String.fromCharCode(0x0178); break;
						case 'fnof': ch = String.fromCharCode(0x0192); break;
						case 'circ': ch = String.fromCharCode(0x02c6); break;
						case 'tilde': ch = String.fromCharCode(0x02dc); break;
						case 'Alpha': ch = String.fromCharCode(0x0391); break;
						case 'Beta': ch = String.fromCharCode(0x0392); break;
						case 'Gamma': ch = String.fromCharCode(0x0393); break;
						case 'Delta': ch = String.fromCharCode(0x0394); break;
						case 'Epsilon': ch = String.fromCharCode(0x0395); break;
						case 'Zeta': ch = String.fromCharCode(0x0396); break;
						case 'Eta': ch = String.fromCharCode(0x0397); break;
						case 'Theta': ch = String.fromCharCode(0x0398); break;
						case 'Iota': ch = String.fromCharCode(0x0399); break;
						case 'Kappa': ch = String.fromCharCode(0x039a); break;
						case 'Lambda': ch = String.fromCharCode(0x039b); break;
						case 'Mu': ch = String.fromCharCode(0x039c); break;
						case 'Nu': ch = String.fromCharCode(0x039d); break;
						case 'Xi': ch = String.fromCharCode(0x039e); break;
						case 'Omicron': ch = String.fromCharCode(0x039f); break;
						case 'Pi': ch = String.fromCharCode(0x03a0); break;
						case ' Rho ': ch = String.fromCharCode(0x03a1); break;
						case 'Sigma': ch = String.fromCharCode(0x03a3); break;
						case 'Tau': ch = String.fromCharCode(0x03a4); break;
						case 'Upsilon': ch = String.fromCharCode(0x03a5); break;
						case 'Phi': ch = String.fromCharCode(0x03a6); break;
						case 'Chi': ch = String.fromCharCode(0x03a7); break;
						case 'Psi': ch = String.fromCharCode(0x03a8); break;
						case 'Omega': ch = String.fromCharCode(0x03a9); break;
						case 'alpha': ch = String.fromCharCode(0x03b1); break;
						case 'beta': ch = String.fromCharCode(0x03b2); break;
						case 'gamma': ch = String.fromCharCode(0x03b3); break;
						case 'delta': ch = String.fromCharCode(0x03b4); break;
						case 'epsilon': ch = String.fromCharCode(0x03b5); break;
						case 'zeta': ch = String.fromCharCode(0x03b6); break;
						case 'eta': ch = String.fromCharCode(0x03b7); break;
						case 'theta': ch = String.fromCharCode(0x03b8); break;
						case 'iota': ch = String.fromCharCode(0x03b9); break;
						case 'kappa': ch = String.fromCharCode(0x03ba); break;
						case 'lambda': ch = String.fromCharCode(0x03bb); break;
						case 'mu': ch = String.fromCharCode(0x03bc); break;
						case 'nu': ch = String.fromCharCode(0x03bd); break;
						case 'xi': ch = String.fromCharCode(0x03be); break;
						case 'omicron': ch = String.fromCharCode(0x03bf); break;
						case 'pi': ch = String.fromCharCode(0x03c0); break;
						case 'rho': ch = String.fromCharCode(0x03c1); break;
						case 'sigmaf': ch = String.fromCharCode(0x03c2); break;
						case 'sigma': ch = String.fromCharCode(0x03c3); break;
						case 'tau': ch = String.fromCharCode(0x03c4); break;
						case 'upsilon': ch = String.fromCharCode(0x03c5); break;
						case 'phi': ch = String.fromCharCode(0x03c6); break;
						case 'chi': ch = String.fromCharCode(0x03c7); break;
						case 'psi': ch = String.fromCharCode(0x03c8); break;
						case 'omega': ch = String.fromCharCode(0x03c9); break;
						case 'thetasym': ch = String.fromCharCode(0x03d1); break;
						case 'upsih': ch = String.fromCharCode(0x03d2); break;
						case 'piv': ch = String.fromCharCode(0x03d6); break;
						case 'ensp': ch = String.fromCharCode(0x2002); break;
						case 'emsp': ch = String.fromCharCode(0x2003); break;
						case 'thinsp': ch = String.fromCharCode(0x2009); break;
						case 'zwnj': ch = String.fromCharCode(0x200c); break;
						case 'zwj': ch = String.fromCharCode(0x200d); break;
						case 'lrm': ch = String.fromCharCode(0x200e); break;
						case 'rlm': ch = String.fromCharCode(0x200f); break;
						case 'ndash': ch = String.fromCharCode(0x2013); break;
						case 'mdash': ch = String.fromCharCode(0x2014); break;
						case 'lsquo': ch = String.fromCharCode(0x2018); break;
						case 'rsquo': ch = String.fromCharCode(0x2019); break;
						case 'sbquo': ch = String.fromCharCode(0x201a); break;
						case 'ldquo': ch = String.fromCharCode(0x201c); break;
						case 'rdquo': ch = String.fromCharCode(0x201d); break;
						case 'bdquo': ch = String.fromCharCode(0x201e); break;
						case 'dagger': ch = String.fromCharCode(0x2020); break;
						case 'Dagger': ch = String.fromCharCode(0x2021); break;
						case 'bull': ch = String.fromCharCode(0x2022); break;
						case 'hellip': ch = String.fromCharCode(0x2026); break;
						case 'permil': ch = String.fromCharCode(0x2030); break;
						case 'prime': ch = String.fromCharCode(0x2032); break;
						case 'Prime': ch = String.fromCharCode(0x2033); break;
						case 'lsaquo': ch = String.fromCharCode(0x2039); break;
						case 'rsaquo': ch = String.fromCharCode(0x203a); break;
						case 'oline': ch = String.fromCharCode(0x203e); break;
						case 'frasl': ch = String.fromCharCode(0x2044); break;
						case 'euro': ch = String.fromCharCode(0x20ac); break;
						case 'image': ch = String.fromCharCode(0x2111); break;
						case 'weierp': ch = String.fromCharCode(0x2118); break;
						case 'real': ch = String.fromCharCode(0x211c); break;
						case 'trade': ch = String.fromCharCode(0x2122); break;
						case 'alefsym': ch = String.fromCharCode(0x2135); break;
						case 'larr': ch = String.fromCharCode(0x2190); break;
						case 'uarr': ch = String.fromCharCode(0x2191); break;
						case 'rarr': ch = String.fromCharCode(0x2192); break;
						case 'darr': ch = String.fromCharCode(0x2193); break;
						case 'harr': ch = String.fromCharCode(0x2194); break;
						case 'crarr': ch = String.fromCharCode(0x21b5); break;
						case 'lArr': ch = String.fromCharCode(0x21d0); break;
						case 'uArr': ch = String.fromCharCode(0x21d1); break;
						case 'rArr': ch = String.fromCharCode(0x21d2); break;
						case 'dArr': ch = String.fromCharCode(0x21d3); break;
						case 'hArr': ch = String.fromCharCode(0x21d4); break;
						case 'forall': ch = String.fromCharCode(0x2200); break;
						case 'part': ch = String.fromCharCode(0x2202); break;
						case 'exist': ch = String.fromCharCode(0x2203); break;
						case 'empty': ch = String.fromCharCode(0x2205); break;
						case 'nabla': ch = String.fromCharCode(0x2207); break;
						case 'isin': ch = String.fromCharCode(0x2208); break;
						case 'notin': ch = String.fromCharCode(0x2209); break;
						case 'ni': ch = String.fromCharCode(0x220b); break;
						case 'prod': ch = String.fromCharCode(0x220f); break;
						case 'sum': ch = String.fromCharCode(0x2211); break;
						case 'minus': ch = String.fromCharCode(0x2212); break;
						case 'lowast': ch = String.fromCharCode(0x2217); break;
						case 'radic': ch = String.fromCharCode(0x221a); break;
						case 'prop': ch = String.fromCharCode(0x221d); break;
						case 'infin': ch = String.fromCharCode(0x221e); break;
						case 'ang': ch = String.fromCharCode(0x2220); break;
						case 'and': ch = String.fromCharCode(0x2227); break;
						case 'or': ch = String.fromCharCode(0x2228); break;
						case 'cap': ch = String.fromCharCode(0x2229); break;
						case 'cup': ch = String.fromCharCode(0x222a); break;
						case 'int': ch = String.fromCharCode(0x222b); break;
						case 'there4': ch = String.fromCharCode(0x2234); break;
						case 'sim': ch = String.fromCharCode(0x223c); break;
						case 'cong': ch = String.fromCharCode(0x2245); break;
						case 'asymp': ch = String.fromCharCode(0x2248); break;
						case 'ne': ch = String.fromCharCode(0x2260); break;
						case 'equiv': ch = String.fromCharCode(0x2261); break;
						case 'le': ch = String.fromCharCode(0x2264); break;
						case 'ge': ch = String.fromCharCode(0x2265); break;
						case 'sub': ch = String.fromCharCode(0x2282); break;
						case 'sup': ch = String.fromCharCode(0x2283); break;
						case 'nsub': ch = String.fromCharCode(0x2284); break;
						case 'sube': ch = String.fromCharCode(0x2286); break;
						case 'supe': ch = String.fromCharCode(0x2287); break;
						case 'oplus': ch = String.fromCharCode(0x2295); break;
						case 'otimes': ch = String.fromCharCode(0x2297); break;
						case 'perp': ch = String.fromCharCode(0x22a5); break;
						case 'sdot': ch = String.fromCharCode(0x22c5); break;
						case 'lceil': ch = String.fromCharCode(0x2308); break;
						case 'rceil': ch = String.fromCharCode(0x2309); break;
						case 'lfloor': ch = String.fromCharCode(0x230a); break;
						case 'rfloor': ch = String.fromCharCode(0x230b); break;
						case 'lang': ch = String.fromCharCode(0x2329); break;
						case 'rang': ch = String.fromCharCode(0x232a); break;
						case 'loz': ch = String.fromCharCode(0x25ca); break;
						case 'spades': ch = String.fromCharCode(0x2660); break;
						case 'clubs': ch = String.fromCharCode(0x2663); break;
						case 'hearts': ch = String.fromCharCode(0x2665); break;
						case 'diams': ch = String.fromCharCode(0x2666); break;
						default: ch = ''; break;
					}
				}
				i = semicolonIndex;
			}
		}
		out += ch;
	}
	return out;
}

/* non usato
// per rimuovere tutti gli elementi da una select
function pulisciSelect(oggetto) {
	if(document.getElementById(oggetto).options.length > 0){
		while (document.getElementById(oggetto).options.length) {
			document.getElementById(oggetto).remove(0);
		}
	}
}
*/
//------ NON TESTATO ------
// per disabilitare elementi da una select
//function disabledElement(ogg,val){
//	document.getElementById(ogg).disabled = val;
//}
//------











////// FUNZIONI PER ALTRI CONTROLLI SUI MODULI //////

// controllo obbligatorietà, privacy e altro
function info_ckform() {
	var errore = '';
	var classeObb = "formMiniObbligatorio";
	var classeBlank = "formMini";
	var checkEmail = 0;
	var checkIVA = 0;
	var checkCF = 0;

	if (!(document.ricInfo.nome.value)) {
		errore += '\n - Nome non presente';
		document.ricInfo.nome.className = classeObb;
	}
	else {document.ricInfo.nome.className = classeBlank;}

	if (!(document.ricInfo.cognome.value)) {
		errore += '\n - Cognome non presente';
		document.ricInfo.cognome.className = classeObb;
	}
	else {document.ricInfo.cognome.className = classeBlank;}

	if (!(document.ricInfo.telefono.value)) {
		errore += '\n - Telefono non presente';
		document.ricInfo.telefono.className = classeObb;
	}
	else {document.ricInfo.telefono.className = classeBlank;}

	if (!(document.ricInfo.email.value)) {
		errore += '\n - Email non presente';
		checkEmail = 1;
	}
	else if (!validaEMail(document.ricInfo.email.value)) {
		errore += '\n - Email non corretta';
		checkEmail = 1;
	}

	// se italiano
	if (document.ricInfo.nazione.value == "ITA") {
		// check codice fiscale
		if (document.ricInfo.codice_fiscale.value.length==16) {
			if (!check_cf(document.ricInfo.codice_fiscale.value)) {
				errore += '\n - Codice Fiscale non corretto';
//				checkCF = 1;
			}
		}
		else if ((document.ricInfo.codice_fiscale.value.length==11)||(document.ricInfo.codice_fiscale.value.length==13)) {
			if (!check_piva(document.ricInfo.codice_fiscale.value)) {
				errore += '\n - Codice Fiscale non corretto';
//				checkCF = 1;
			}
		}
		else if (document.ricInfo.codice_fiscale.value) {
			errore += '\n - Codice Fiscale non valido';
//			checkCF = 1;
		}

		// check partita iva
		if (document.ricInfo.p_iva.value) {
			if (!check_piva(document.ricInfo.p_iva.value)) {
				errore += '\n - Partita IVA non valida';
//				checkIVA = 1;
			}
		}
	}

//	if (checkIVA == 1) {document.ricInfo.p_iva.className = classeObb;}
//	else {document.ricInfo.p_iva.className = classeBlank;}
//	if (checkCF == 1) {document.ricInfo.codice_fiscale.className = classeObb;}
//	else {document.ricInfo.codice_fiscale.className = classeBlank;}

	if (checkEmail == 1) {document.ricInfo.email.className = classeObb;}
	else {document.ricInfo.email.className = classeBlank;}


	if (errore) {
		alert('ATTENZIONE !!!\n\nper proseguire devi controllare i seguenti dati:\n' + errore + '\n\nTutti i campi in rosso sono obbligatori.');
		return false;
	}
	else {
		if (!(document.ricInfo.privacy[0].checked)) {
			alert('ATTENZIONE !!!\n\nse non si consente al trattamento dei dati personali secondo la legge 196/03, non è possibile proseguire.');
			return false;
		}
		else {
			return true;
		}
	}
}












////////////////  FUNZIONI CHECK PARTITA IVA E CODICE FISCALE  ////////////////
// far girare preventivamente le funzioni di pulitura spazi e di uppercase, che comunque girano qui dentro
// il codice fiscale deve essere di 16 caratteri, se è di 11 o di 13 far girare il controllo della partita iva

// rivisto per il funzionamento della partite iva internazionali, con la sigla davanti (controllo validità solo sulle IT)
function check_piva(pivains) {
	var piva = pivains.toUpperCase();
	var pivaReg = /^[A-Z]{2}\d+$/;
	var pivaITReg = /^IT\d+$/;
	piva = piva.replace(RegExp(" ", "g"), "");
	piva = piva.replace(RegExp("\t", "g"), "");
	if ((!pivaReg.test(piva))||(pivaITReg.test(piva))) {
		// p.iva italiana
		piva = piva.replace(RegExp("IT", "g"), "");
		var n_Val=0,n_Som1=0,n_Som2=0,lcv=0;
		if (piva.length!=11 || isNaN(parseFloat(piva)) || parseFloat(piva)<parseFloat(0)) {
			return false;
		}
		for (lcv=0;lcv<9;lcv+=2) {
			n_Val=parseInt(piva.charAt(lcv));
			n_Som1+=n_Val;
			n_Val=parseInt(piva.charAt(lcv+1));
			n_Som1+=Math.floor(n_Val/5) + (n_Val<<1) % 10;
		}
		n_Som2 = 10 - (n_Som1 % 10);
		if (n_Som2 == 10) {n_Som2 = 0;}
		n_Val=parseInt(piva.charAt(10));
		if (n_Som2==n_Val) {
			return true;
		}
		else {
			return false;
		}
	}
	else {
		// p.iva estera
		return true;
	}
}

function check_cf(cfins) {
	var cf = cfins.toUpperCase();
	var cfReg = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
	cf = cf.replace(RegExp(" ", "g"), "");
	if (!cfReg.test(cf)) {
		return false;
	}
	var set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	var s = 0;
	for(i=1; i<=13; i+=2) {
		s += setpari.indexOf(set2.charAt(set1.indexOf(cf.charAt(i))));
	}
	for(i=0; i<=14; i+=2) {
		s += setdisp.indexOf(set2.charAt(set1.indexOf(cf.charAt(i))));
	}
	if (s%26!=cf.charCodeAt(15)-'A'.charCodeAt(0)) {
		return false;
	}
	else {
		return true;
	}
}







//////////////////////////////////
// FUNZIONI PER AJAX E XML
//
// creo l'oggetto http
var httpPHP = getHTTPObject();

// crea l'oggetto XMLHttpRequest
function getHTTPObject() {
	var httpPHP = false;
	if (window.XMLHttpRequest) {
		// Mozilla, Safari,...
		httpPHP = new XMLHttpRequest();
		if (httpPHP.overrideMimeType) {httpPHP.overrideMimeType('text/xml');}
	}
	else if (window.ActiveXObject) {
		// IE
		try {httpPHP = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try {httpPHP = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (e) {httpPHP = false;}
		}
	}
	// check
	if (!httpPHP) {
		alert('Cannot create an XMLHTTP instance');
		return false;
	}
	return httpPHP;
}




//-->
