	/*DETECT MOBILE*/
var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
    if (mobile) {  
		if(readCookie('mobile') == null || readCookie('mobile') != 1 || readCookie('mobile') == '' ){
        document.location = "http://www.acquamadre.it/mobile/"; 
					   }
    }
	/*LOOP X INDICATOR*/
		
	function ind(){
	var elsxx = document.getElementsByTagName('A'); // use "*" for all elements
	var elsLenxx = elsxx.length;
	var loczz = window.location.href;
	for (var i=0; i < elsLenxx; i++){
	var xidxx = elsxx[i].getAttribute('id');
	if(loczz.indexOf(xidxx) !=-1 ) elsxx[i].className = 'indicator';
	}
	}
	
function ControllaCF(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return "La lunghezza del codice fiscale non è\ncorretta: il codice fiscale dovrebbe essere lungo\nesattamente 16 caratteri.";
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return "Il codice fiscale contiene un carattere non valido '" +
				cf.charAt(i) +
				"'.\nI caratteri validi sono le lettere e le cifre.\n";
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	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 "Il codice fiscale non è corretto:\n"+
			"il codice di controllo non corrisponde.\n";
	return "";
}


function ControllaPIVA(pi)
{
	if( pi == '' )  return '';
	if( pi.length != 11 )
		return "La lunghezza della partita IVA non è\n" +
			"corretta: la partita IVA dovrebbe essere lunga\n" +
			"esattamente 11 caratteri.\n";
	validi = "0123456789";
	for( i = 0; i < 11; i++ ){
		if( validi.indexOf( pi.charAt(i) ) == -1 )
			return "La partita IVA contiene un carattere non valido `" +
				pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n";
	}
	s = 0;
	for( i = 0; i <= 9; i += 2 )
		s += pi.charCodeAt(i) - '0'.charCodeAt(0);
	for( i = 1; i <= 9; i += 2 ){
		c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
		if( c > 9 )  c = c - 9;
		s += c;
	}
	if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
		return "La partita IVA non è valida:\n" +
			"il codice di controllo non corrisponde.\n";
	return '';
}

var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}

/*FINE AJAX CALLS*/

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function mailPC()
{
var aaaa = "info";
var bbbb = "acquamadre.it";

document.write('<a href=\"mailto:' + aaaa + '@' + bbbb + '?subject=Web Info\">');
document.write(aaaa + '@' + bbbb + '</a>');
}
function mailPC2()
{
var aaaa = "info";
var bbbb = "acquamadre.it";

document.write('<a href=\"mailto:' + aaaa + '@' + bbbb + '?subject=Rimozione\">');
document.write(aaaa + '@' + bbbb + '</a>');
}
function mailBB()
{
var aaaa = "bluebox";
var bbbb = "bbx.it";

document.write('<a href=\"mailto:' + aaaa + '@' + bbbb + '?subject=Hammam Info\">');
document.write(aaaa + '@' + bbbb + '</a>');
}
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve contenere un indirizzo valido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' deve essere un numero.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é obbligatorio.\n'; }
  } if (errors) alert('Errore nella compilazione dei campi:\n'+errors);
  document.MM_returnValue = (errors == '');
}

/*FUNZIONI COOKIES*/

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

/*FUNZIONI CART*/

function valori(){
	var stringa = '';
	var totale = 0;
	var quanti = 0;
	var serv = ' servizio';
	var dt = document.getElementById('fixme');
for (var i=0; i < document.forms['form1'].selx.length; i++)
   {	
		  var a = document.forms['form1'].selx[i].value;
		  var cod = a.substring(0, a.indexOf('|') );
		  var elemento = a.substring( a.indexOf('|') + 1 );
		  var x = document.getElementsByName('A'+ a);
		  var importo1 = document.getElementById(document.forms['form1'].selx[i].value).innerHTML.replace('€ ','');
		  var importo1 = importo1.replace('.','');
      if(document.forms['form1'].selx[i].checked == true){
		  var totale = totale + (parseInt(importo1) * parseInt(document.forms[0].elements[elemento].value)) ;
		  var quanti = quanti + (parseInt(document.forms[0].elements[elemento].value));
		  var stringa = stringa + document.forms[0].elements[elemento].value + ':' + cod + '|';
	  }
   }
   if(quanti != 0){
	   if(quanti > 1){serv = ' servizi';}
   var totalino = 'Totale:<br>' + quanti + serv + '<br>€ ' + totale + ',00';
   dt.style.display = 'block';
   dt.innerHTML = totalino;}
   else{
	   dt.style.display = 'none';}
   var stringa = stringa.substr(0,stringa.lastIndexOf("|"));
   eraseCookie('order');
   createCookie('order', stringa, 30);
   resetv();
}
function resetv() {
	setTimeout(function(){reset_valori()},500);
}
function reset_valori(){
for (var i=0; i < document.forms['form1'].selx.length; i++)
   {	
	var m = 1;
		  var a = document.forms['form1'].selx[i].value; 	// Z12|12
		  if(a.indexOf('Z')!=-1 || a.indexOf('X')!=-1) m = 2;
		  var cod = a.substring(0, a.indexOf('|') );		// Z12
		  var elemento = a.substring( a.indexOf('|') + 1 );	// 12
		  var x = document.getElementsByName('A'+ a);		// AZ12|12
      if(document.forms['form1'].selx[i].checked == false){
		  document.forms[0].elements[elemento].value = m;
	  }
   }
}
function eliminaCart(codex) {
	var answer = confirm ("Elimino il prodotto?")
	if (answer){
	var a = readCookie('order');
	var b = a.replace(codex, "");
	var c = b.replace("||", "|");
	if(c.charAt(0) == '|'){
		var c = c.substr(1);
	}
	if(c.lastIndexOf("|") == (c.length - 1)){
		var c = c.substr(0,c.lastIndexOf("|"));
	}
   eraseCookie('order');
   createCookie('order', c, 30);
   location.reload();
}
}
function plus(idx) {
	var df = document.forms['form1'].elements;
	var m = 1;
	if(idx.indexOf('Z')!=-1  || idx.indexOf('X')!=-1) m = 2;
	df[idx].value = parseInt(df[idx].value) + m;
	valori();
}
function minus(idx,numero) {
	var df = document.forms['form1'].elements;
	var m = 1;
	if(idx.indexOf('Z')!=-1  || idx.indexOf('X')!=-1) m = 2;
	if(df[idx].value != 0){
	df[idx].value = parseInt(df[idx].value) - m;
	}
	mettizero(idx,numero);
	valori();
}
function plus_cart(idx) {
	var df = document.forms['form1'].elements;
	var m = 1;
	if(idx.indexOf('Z')!=-1  || idx.indexOf('X')!=-1) m = 2;
	df[idx].value = parseInt(df[idx].value) + m;
	valori_cart(idx);
}
function minus_cart(idx) { //3xH1
	var df = document.forms['form1'].elements;
	var m = 1;
	var k = idx;
	if(k.indexOf('Z')!=-1  || k.indexOf('X')!=-1) m = 2;
	if(df[idx].value != 0){
	df[idx].value = parseInt(df[idx].value) - m;
	if(df[idx].value <= m) df[idx].value = m;
	}
	mettizero_cart(idx);
	valori_cart(idx);
}
function valori_cart(nome){
	var df = document.forms['form1'].elements;
	var a = readCookie('order');
	var b = nome.replace("x", ":");
	var valore = document.forms['form1'][nome].value;
	var c = valore + b.substring( b.indexOf(':') );
	var d = a.replace(b, c);
	eraseCookie('order');
	createCookie('order', d, 30);
	setTimeout("location.reload()",500);
   
}
function mettizero(campo, numero){
	var z = document.form1[campo].value ;
	if (z == 0 ){
	document.form1[campo].value = 1 ;
	document.forms[0].elements[numero].checked = false;
	valori();
	}
//	else
//	{
//		document.forms[0].elements[numero].checked = true;
//	}
	valori();
}
function mettizero_cart(campo){
	var x = parseInt(document.form1[campo].value) ;
	var m = 1;
	if(campo.indexOf('Z')!=-1  || campo.indexOf('X')!=-1) m = 2;
	if (x < m || x == 0 ){
	document.form1[campo].value = m ;
	valori_cart(campo, 1);
	}
	else
	{
		valori_cart(campo, x);
	}
}

function reset_regalo(){ 
	for (var i=11; i < 16; i++)
	{ 
	document.forms['form2'].elements[i].value = '';
	}
	document.forms['form2'].msg.value = '';
}
String.prototype.capitalize = function(){
   return this.replace( /(^|\s)([a-z])/g , function(m,p1,p2){ return p1+p2.toUpperCase(); } );
  };
	
function $() {
		var elements = new Array();
		for (var i = 0; i < arguments.length; i++) {
			var element = arguments[i];
			if (typeof element == 'string')
				element = document.getElementById(element);
			if (arguments.length == 1)
				return element;
			elements.push(element);
		}
		return elements;
	}

function toggle(x) {
	var z = document.getElementById(x);
	switch(z.style.display){
	case 'block':
	reset_regalo();
	z.style.display = 'none';
	break;
	
	case 'none':
	for ( var i=0; i < arguments.length; i++ ) {
		$(arguments[i]).style.display = ($(arguments[i]).style.display != 'none' ? 'none' : 'block' );
		}
	break;
	}
}
function validateMulti(tipoPag,formName,sw){
	var nomeForm = formName;
	var classx = 'chk';
	validRegExp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var xx = 0;
	var classElements = new Array();
	var els = document.getElementsByTagName('*'); // use "*" for all elements
	var elsLen = els.length;
	var pattern = new RegExp("\\b"+classx+"\\b");
	var pivax = formName.elements['PartitaIva'].value;
	var cfx = formName.elements['CodiceFiscale'].value;
	var codici = '';
	
	if(formName.elements['pr'].checked == false){
		alert('Per continuare devi sottoscrivere l\'informativa sul trattamento dei dati personali (checkbox a sinistra)');
		return;
	}
	
	if(pivax == cfx){ // controlla solo piva
		codici = ControllaPIVA(pivax);
	}
	if(pivax != '' && pivax != cfx){  // controlla entrambi
		codici = ControllaPIVA(pivax);
		if(codici == ''){
		codici = ControllaCF(cfx);}
	}
	if(pivax == ''){  // controlla solo cf
		codici = ControllaCF(cfx);
	}
	if(codici != ''){
		alert(codici);
		return;
	}
	
		for (i = 0, j = 0; i < elsLen; i++) {
	
			if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			var xid = els[i].getAttribute('id');
			var xclass = els[i].className;
	
				if (els[i].value == "" || els[i].value == null || els[i].value.charAt(0) == ' '){
				alert("Il campo " + els[i].name + " è vuoto.\nRiprova.");
				   els[i].value = '';
				   els[i].focus();
				xx = 1;
				return;
				}
	
				if( xclass.indexOf('xmail') != -1){
					if (els[i].value.search(validRegExp) == -1){
					alert('L\'indirizzo nel campo ' + els[i].name + ' non è valido.\nRiprova.');
					   els[i].value = '';
					   els[i].focus();
						xx = 1;
						return;
					} 
				}
	
				if( xclass.indexOf('cfr') != -1){
				var nextfield = els[i].getAttribute('rel');
				var nextxx = formName.elements[nextfield].value;
				
					if(els[i].value != nextxx){
					alert('I campi Email non corrispondono.\nRiprova');
					   els[i].value = '';
					   formName.elements[nextfield].value = '';
					   els[i].focus();
					xx = 1;
					return;
					}
				}
	
 j++;
 }  // Fine IF Pattern
}	// Fine FOR loop


if (isNaN(formName.elements['Telefono'].value)){ 
alert("Il campo Telefono deve essere numerico.\nIl numero di telefono ci è necessario per contattarti in caso di problemi di email.");
				   formName.elements['Telefono'].value = '';
				   formName.elements['Telefono'].focus();
				return;
				}

		if(formName.elements['PartitaIva'].value == ''){
			formName.elements['RagioneSociale'].value = '';
		}

if(xx == 0){
	
	if(sw != 0){
	var nx = escape(formName.elements['Nome'].value + ' ' + formName.elements['Cognome'].value);
	var destx = escape(formName.elements['NomeDestinatario'].value + ' ' + formName.elements['CognomeDestinatario'].value);
	var emailx = formName.elements['EmailDestinatario'].value;
	var msgx = formName.elements['msg'].value;
	var msgx = msgx.replace( new RegExp( "\n", "gi" ), "<br>" );
		var msgx = escape(msgx);
		alert('L\'anteprima verrà aperta in una nuova finestra.\nPer tornare a questa pagina chiudila.');
	var newWindow = window.open('/calls/mail_preview_cart.php?dest='+destx+'&msg='+msgx+'&nx='+nx, '_blank');
	newWindow.focus();
	return ;
	}
	
	document.getElementById('bnbtn').disabled=true;
	document.getElementById('ccbtn').disabled=true;
	
usr(tipoPag);  //  Fine VALIDAZIONE
}

	
function usr(tipoPag){ 
	eraseCookie('usr');
	//var ax = 'bxb';
	var ax = document.forms['form3'].ax.value;
	var struser = '';
	for (var i=0; i < formName.elements.length; i++)
	{ 
	if(formName.elements[i].type != 'button' && formName.elements[i].type != 'checkbox' && formName.elements[i].name != 'mem' && formName.elements[i].name != 'privacy'){
	var struser = struser + formName.elements[i].value + '|';
		}
	}
	var struser = escape(struser);
	//var struser = Encoder.htmlEncode(struser);
	createCookie('usr', struser, 30);
	
	var cfx = document.forms['form2'].CodiceFiscale.value;
	var cfcheck = sendCF(cfx);
	document.forms['form3'].ax.value = cfcheck;
	
	var ax = cfcheck;
	
	var struser = struser +  ax + '|' + tipoPag;
	if(document.forms['form2'].mem.checked == false)
	{ var struser = struser.substring(0, (struser.length)) + '|0';}
	else
	{ var struser = struser.substring(0, (struser.length)) + '|1';}
	eraseCookie('usr');
	createCookie('usr', struser, 30);
	
	if(ax == 2){
		var cffx = document.forms['form2'].CodiceFiscale.value;
		var rn = Math.random();
		var totxxx = document.forms['form3'].totx.value;
		var src = 'boxcf.php?cf='+cffx+'&tp='+tipoPag+'&ax='+ax+'&x='+rn+'&tot='+totxxx;
		$.modal('<iframe src="' + src + '" height="430" width="650" style="border:0">', {
		closeHTML:"",
		containerCss:{
		backgroundColor:"#F7FBEC",
		borderColor:"#004384",
		height:430,
		padding:0,
		width:650
	},
	overlayClose:true
});

		return;
	}
	if(tipoPag != 1){
	self.location ='/Hammam-Roma-Online-Shop/cart_checkout.php?x=' + document.forms['form3'].totx.value ;}
	else{
	self.location ='/mm/cart_bonifico_checkout.php?x=' + document.forms['form3'].totx.value ;}
	
	
//	self.location ='/mm/dump.php?x=' + document.forms['form3'].totx.value ;}
//	else{
//	self.location ='/mm/dump.php?x=' + document.forms['form3'].totx.value ;}
	
}
}
function sendCF(cfx) {
//	var tipo = tipoPag;
//	var formName2 = formName;
	var requ = createXMLHTTPObject();
	var cf = cfx;
	if (!requ) return;
	requ.open('POST','/calls/cf.php',false);
	requ.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (cf)
		requ.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		postData2 ='cf='+cf;
	requ.onreadystatechange = function () {
		if (requ.readyState != 4) return;
		if (requ.status != 200 && requ.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}
		//alert(requ.responseText);
	}
	if (requ.readyState == 4) return;
	requ.send(postData2);	
		return(requ.responseText);									
}
function resp(tipoPag,formName,requ) {
		usr(tipo,formName2,response);
}

function swap(img, id){
	var str1 = img.substr(0, img.lastIndexOf('.'));
	var str2 = img.substr(img.lastIndexOf('.'));
	if(str1.charAt(str1.length-1) == 2)
	{var str3 = str1.substr(0, str1.length-1);}
	else
	{var str3 = str1 + 2;}
	var x = str3 + str2;
	document.getElementById(id).src = x;
	//alert(x);
}
function validateBox(tipoPag,formName){
	var nomeForm = formName;
	var classx = 'chk';
	validRegExp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var xx = 0;
	var classElements = new Array();
	var els = document.forms['formcf'].elements; // use "*" for all elements
	var elsLen = document.forms['formcf'].elements.length;
	var pattern = new RegExp("\\b"+classx+"\\b");
	
		for (i = 0, j = 0; i < elsLen; i++) {
	
			if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			var xid = els[i].getAttribute('id');
			var xclass = els[i].className;
	
				if (els[i].value == "" || els[i].value == null || els[i].value.charAt(0) == ' '){
				alert("Il campo " + els[i].name + " è vuoto.\nRiprova.");
				   els[i].value = '';
				   els[i].focus();
				xx = 1;
				return;
				}
	
				if( xclass.indexOf('xmail') != -1){
					if (els[i].value.search(validRegExp) == -1){
					alert('L\'indirizzo nel campo ' + els[i].name + ' non è valido.\nRiprova.');
					   els[i].value = '';
					   els[i].focus();
						xx = 1;
						return;
					} 
				}
	
				if( xclass.indexOf('cfr') != -1){
				var nextfield = els[i].getAttribute('rel');
				var nextxx = document.forms['formcf'][nextfield].value;
				
					if(els[i].value != nextxx){
					alert('I campi Email non corrispondono.\nRiprova');
					   els[i].value = '';
					   document.forms['formcf'][nextfield].value = '';
					   els[i].focus();
					xx = 1;
					return;
					}
				}
 j++;
 }  // Fine IF Pattern
}	// Fine FOR loop

if(xx == 0)
{
	document.getElementById('ccbtn2').disabled=true;
var elsLen2 = document.forms['formcf'].elements.length;
var newcookie = '';
for (i = 0; i < elsLen2; i++) {
	if(document.forms['formcf'].elements[i].type != 'button'){
	var newcookie = newcookie + document.forms['formcf'].elements[i].value + '|';
	}
}
var newcookie = newcookie.substring(0, (newcookie.length - 1)) + document.forms['form33'].codax.value;
eraseCookie('usr');
createCookie('usr',newcookie,30);
	if(tipoPag != 1){
	top.location ='/Hammam-Roma-Online-Shop/cart_checkout.php?x=' + document.forms['form3'].totx.value ;}
	else{
	top.location ='/mm/cart_bonifico_checkout.php?x=' + document.forms['form3'].totx.value ;}
	
	
//	self.location ='/mm/dump.php?x=' + document.forms['form3'].totx.value ;}
//	else{
//	self.location ='/mm/dump.php?x=' + document.forms['form3'].totx.value ;}
}
}
function validate_mail(formN,sw){
	var formName = document.forms[formN];
	var struser = '';
	var classx = 'chk';
	validRegExp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var xx = 0;
	var classElements = new Array();
	var els = document.forms['formcf'].elements; // use "*" for all elements
	var elsLen = document.forms['formcf'].elements.length;
	var pattern = new RegExp("\\b"+classx+"\\b");
	
		for (i = 0, j = 0; i < elsLen; i++) {
	
			if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			var xid = els[i].getAttribute('id');
			var xclass = els[i].className;
	
				if (els[i].value == "" || els[i].value == null || els[i].value.charAt(0) == ' '){
				alert("Il campo " + els[i].name + " è vuoto.\nRiprova.");
				   els[i].value = '';
				   els[i].focus();
				xx = 1;
				return;
				}
	
				if( xclass.indexOf('xmail') != -1){
					if (els[i].value.search(validRegExp) == -1){
					alert('L\'indirizzo nel campo ' + els[i].name + ' non è valido.\nRiprova.');
					   els[i].value = '';
					   els[i].focus();
						xx = 1;
						return;
					} 
				}
	
				if( xclass.indexOf('cfr') != -1){
				var nextfield = els[i].getAttribute('rel');
				var nextxx = document.forms['formcf'][nextfield].value;
				
					if(els[i].value != nextxx){
					alert('I campi Email non corrispondono.\nRiprova');
					   els[i].value = '';
					   document.forms['formcf'][nextfield].value = '';
					   els[i].focus();
					xx = 1;
					return;
					}
				}
 j++;
 }  // Fine IF Pattern
}	// Fine FOR loop
if(xx == 0)
{
		for (var i=0; i < formName.elements.length; i++)
	{ 
	if(formName.elements[i].type == 'checkbox' && formName.elements[i].checked == true && formName.elements[i].name != 'seltutti'){
	var struser = struser + formName.elements[i].value + "|";
		}
	}
	if(struser == ''){
		alert('Devi scegliere almeno un servizio!');
		return;
	}
	var struser = struser.substring(0, (struser.length - 1));
	var destx = escape(document.forms['formcf']['Nome'].value + ' ' + document.forms['formcf']['Cognome'].value);
	var emailx = document.forms['formcf']['Email'].value;
	var msgx = document.forms['formcf']['mess'].value;
	var nd = document.forms['formcf']['nuovadata'].value;
	//var msgx = msgx.replace( new RegExp( "\n", "gi" ), "<br>" );
	var msgx = escape(msgx);
	if(sw == 1){
		alert('L\'anteprima verrà aperta in una nuova finestra.\nPer tornare a questa pagina chiudila.');
	var newWindow = window.open('/calls/mail_preview.php?dest='+destx+'&msg='+msgx+'&id='+struser, '_blank');
	newWindow.focus();
	return ;
	}
	var requ = createXMLHTTPObject();	if (!requ) return;
	requ.open('POST','/calls/mail.php',true);
	requ.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (struser)
		requ.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		postData2 ='id='+struser+'&nome='+destx+'&email='+emailx+'&msg='+msgx+'&nuovadata='+nd;
	requ.onreadystatechange = function () {
		if (requ.readyState != 4) return;
		if (requ.status != 200 && requ.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}
		var risposta = requ.responseText.replace( new RegExp( "xxx", "gi" ), "\n" );
		alert(risposta);
		formName.reset();
		location.reload();
	}
	if (requ.readyState == 4) return;
	requ.send(postData2);
}
}
function cancella_cart(){
	var r=confirm("Cancello tutto?");
if (r==true)
  {
//	  alert('cancellato');
  eraseCookie('order');
  self.location='/Hammam-Roma-Online-Shop/';
  }
}
function gocart(){
	var xorder = document.cookie.indexOf("order=");
	if(xorder!=-1 && readCookie('order') != ''){
		self.location='cart.php';
	}else{
		alert('Il carrello è vuoto!');
	}
}
function resetForm(){
  eraseCookie('order');
	var f = document.forms['form1'].elements;
	var flen = f.length;
		for (var i=0; i < flen; i++){
				if(f[i].type == 'text'){
					f[i].value = 1;
				}else if( f[i].checked == true){
							f[i].checked = false;
				}
					
		}
	valori();
}
function shopNext(pin){
	eraseCookie('usr');
	var pincode = pin;
	var newck = sendpincode(pincode);
//	alert(newck);
//	return;
	createCookie('pin',pincode,0);
	createCookie('usr',newck,30);
	self.location='/Hammam-Roma-Online-Shop/?id='+pincode;
}
function sendpincode(pin) {
	var requ = createXMLHTTPObject();
	var cf = pin;
	if (!requ) return;
	requ.open('POST','/calls/usernext.php',false);
	requ.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (cf)
		requ.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		postData2 ='cf='+cf;
	requ.onreadystatechange = function () {
		if (requ.readyState != 4) return;
		if (requ.status != 200 && requ.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}
		//alert(requ.responseText);
	}
	if (requ.readyState == 4) return;
	requ.send(postData2);	
		return(requ.responseText);									
}



function validate_stampabile(formN){
//	alert('x');
//	return;
	var formName2 = document.forms['formcf'];
	var formName = document.forms[formN];
	var struser = '';
	for (var i=0; i < formName.elements.length; i++){
	if(formName.elements[i].type == 'text' && formName.elements[i].value == "" || formName.elements[i].value == null || formName.elements[i].value.charAt(0) == ' '){
				alert("Il campo " + formName.elements[i].name + " è vuoto.\nRiprova.");
				   formName.elements[i].value = '';
				   formName.elements[i].focus();
				return;
				}	
	}
		for (var i=0; i < formName2.elements.length; i++)
	{ 
	
	if(formName2.elements[i].type == 'checkbox' && formName2.elements[i].name != 'seltutti' && formName2.elements[i].checked == true){
	var struser = struser + formName2.elements[i].value + "|";
		}  // if
	}  // for
	if(struser == ''){
		alert('Devi scegliere almeno un servizio!');
		return;
	}
	var struser = struser.substring(0, (struser.length - 1));
	var destx = escape(document.forms['formbr']['Nome'].value + ' ' + document.forms['formbr']['Cognome'].value);

	var requ = createXMLHTTPObject();	
	if (!requ) return;
	requ.open('POST','/calls/stampa.php',true);
	requ.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (struser)
		requ.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		postData2 ='id='+struser+'&nome='+destx;
	requ.onreadystatechange = function () {
		if (requ.readyState != 4) return;
		if (requ.status != 200 && requ.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}
		var risposta = requ.responseText;
		alert(risposta);
		formName.reset();
		location.reload();
	}
	if (requ.readyState == 4) return;
	requ.send(postData2);
}
function selTuttix(){
	 if (checkedx == false)
          {
           checkedx = true;
          }
        else
          {
          checkedx = false;
          }
	var f = document.forms['formcf'].elements;
	var flen = f.length;
		for (var i=0; i < flen; i++){
				 if( f[i].type == 'checkbox' && f[i].name != 'seltutti' && f[i].disabled == false){
							f[i].checked = checkedx;
				}
					
		}
}
checkedx=false;
function tables(t1,t2){
	if(document.getElementById(t1).style.display == 'block'){
	document.getElementById(t1).style.display = 'none';}
	else{
	document.getElementById(t1).style.display = 'block';
	document.getElementById(t2).style.display = 'none';
	}
}

function accesso() {
var name = prompt("Digita il Codice Pin del tuo Buono","");
	if (!name) return;
	var req2 = createXMLHTTPObject();
	if (!req2) return;
	req2.open('POST','/calls/accesso.php',true);
	req2.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (name)
		req2.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		postData2='pin='+name;
	req2.onreadystatechange = function () {
		if (req2.readyState != 4) return;
		if (req2.status != 200 && req2.status != 304) {
//			alert(idx3);
//			return;
		}
		if(req2.responseText != '1') {
		alert('Questo codice PIN non ci risulta, controlla e riprova.');
		return;
		}
		self.location='/user.php?id='+name;
	}
	if (req2.readyState == 4) return;
	req2.send(postData2);
}
