function foto_admin(param)
{
	window.open('../foto.php?id='+param,'FotoAdmin'+param,'scrollbars=yes,resizable=yes,width=550,height=550,status=no,location=no,toolbar=no');
}
function view(param)
{
	window.open('view.php?id='+param,'Foto'+param,'scrollbars=yes,resizable=yes,width=550,height=550,status=no,location=no,toolbar=no');
}

function stampa(id)
{
	window.open('stampa_prev.php?id='+id,'StampaPrev'+id,'scrollbars=yes,resizable=no,width=550,height=450,status=no,location=no,toolbar=no');
}
function stampa_ord(id)
{
	window.open('stampa_ord.php?id='+id,'StampaOrdine'+id,'scrollbars=yes,resizable=no,width=550,height=450,status=no,location=no,toolbar=no');
}
// richiamata per visualizzare una pop-up
function utente(id)
{
	window.open('dettagli_ut.php?id='+id,'DettagliUtente'+id,'scrollbars=yes,resizable=no,width=550,height=450,status=no,location=no,toolbar=no');
}
function lettersOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 65 || charCode > 90) && 
        (charCode < 97 || charCode > 122)) {
        alert("Puoi inserire solo lettere!");
        return false;
    }
    return true;
}

function numeralsOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        alert("Puoi inserire solo numeri!");
        return false;
    }
    return true;
}


// richiamata per verificare che abbia immesso i dati nel form codice cliente di cash.php per completare l'ordine
function cod_validate(form)
{
	if (form.cod_utente.value.length == 0)
		{
			alert('Nessun codice inserito!');
			return false;
		}
}

// richiamata per verificare che abbia immesso i dati nel form
function valid(form)
{

	titolo = form.titolo.value;
	testo_ann = form.testo_ann.value;
	
	if (titolo == '' || testo_ann=='')
		{
			alert('Attenzione, dati mancanti nella compilazione!');
			return false;
		}
}
// richiamata per verificare che abbia immesso i dati nel form
function valid2(form)
{

	tipo_ann = form.tipo_ann.value;
	
	if (tipo_ann=='')
		{
			alert('Attenzione, dati mancanti nella compilazione!');
			return false;
		}
}
// richiamata per verificare che abbia immesso i dati nel form
function valid3(form)
{

	nome = form.nome.value;
	msg = form.msg.value;
	email = form.email.value;
	
	if (nome=='' || msg=='' || email =='')
		{
			alert('Attenzione, dati mancanti nella compilazione!');
			return false;
		}
}
// richiamata per verificare che abbia immesso i dati nel form
function valid4(form)
{
	nome = form.nome.value;
	cognome = form.cognome.value;
	indirizzo = form.indirizzo.value;
	cap = form.cap.value;
	citta = form.citta.value;
	prov = form.prov.value;
	piva = form.piva.value;
	stato = form.stato.value;

	str_out='Attenzione, dati mancanti nella compilazione!';
		
	
	if (nome=='' || cognome=='' || indirizzo=='' || cap=='' || citta=='' || prov==''|| piva==''|| stato=='')
	{
			alert(str_out);
			return false;
	}
	
	return true;
}
// richiamata per verificare che abbia immesso i dati nel form
function valid5(form)
{
		
	email = form.email.value;
	pwd = form.pwd.value;
	conf_pwd = form.conf_pwd.value;

	str_out='Attenzione, dati mancanti nella compilazione!';
	
	if ( pwd==''|| conf_pwd==''|| email =='')
	{
			alert(str_out);
			return false;
	}
	
	return true;
}
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function disab(bott)
{
	bott.disabled = true;
	if(valid_form("1") == true)
	{
		return true;
	}
	else
	{
		bott.disabled = false;
		return false;
	}
}

function valid_form(view)
{
	var err=0;
	var msg='Sono stati riscontrati i seguenti errori di inserimento:\n\n';
	
	if (trim(document.registr.nome.value) == "")
		{
			err=1;
			var msg=msg+'- Nome non indicato'+'\n';		
		}
	if (trim(document.registr.cognome.value) == "")
		{
			err=1;
			var msg=msg+'- Cognome non indicato'+'\n';		
		}	
	if (trim(document.registr.indirizzo.value) == "")
		{
			var err=1;
			var msg=msg+'- Indirizzo non indicato'+'\n';		
		}
			
	if (trim(document.registr.cap.value) == "" || (document.registr.cap.value.length < 5))
		{
			var err=1;
			var msg=msg+'- CAP non indicato oppure non corretto'+'\n';		
		}
	if (trim(document.registr.citta.value) == "")
		{
			var err=1;
			var msg=msg+'- Citta non indicata'+'\n';		
		}	
		
	if (trim(document.registr.telefono.value) == "" && trim(document.registr.cellulare.value) == "")
		{
			var err=1;
			var msg=msg+'- Indicare almeno un recapito telefonico fisso o cellulare'+'\n';		
		}
	if (trim(document.registr.email.value) == "")
		{
			var err=1;
			var msg=msg+'- Non hai indicato il tuo indirizzo eMail'+'\n';		
		}
	else
		{
			var x = document.registr.email.value;
			var filter  = /^([a-zA-Z0-9_\.\-\'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
			if (filter.test(x)) var emailgiusto=1;
			else 
				{
					var err=1;
					var msg=msg+'- L\'indirizzo email ha un formato non corretto'+'\n';		
				
				}		
		}			
	if (trim(document.registr.conf_email.value) == "")
		{
			var err=1;
			var msg=msg+'- Non hai indicato il tuo indirizzo eMail di conferma'+'\n';		
		}
	else
		{
			
			var x = document.registr.conf_email.value;
			var filter  = /^([a-zA-Z0-9_\.\-\'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
			if (filter.test(x)) var emailgiusto=1;
			else 
				{
					var err=1;
					var msg=msg+'- L\'indirizzo email di conferma ha un formato non corretto'+'\n';		
				
				}
			if (document.registr.conf_email.value  != document.registr.email.value)
			{
				var err=1;
					var msg=msg+'- Gli indirizzi email inseriti non corriscondono'+'\n';	
				}
		}	
	if(!document.registr.pry.checked)
	{	
		var err=1;
		var msg=msg+'- Non e\' possibile accettare la registrazione se non viene dato il consenso al trattamento dei dati personali'+'\n';	
	}
		if (err == 0)
		{
			//alert(msg);
			document.registr.brg.disabled = true;
			return true;	
		}
		else
		{
			var msg=msg+'\n'+'Corregere i dati prima di procedere';
			if(view == 1)
				alert(msg);
			return false;
		}	
}
function valid_form_new(view)
{
	var err=0;
	var msg='Sono stati riscontrati i seguenti errori di inserimento:\n\n';
	
	if (trim(document.registr.nome.value) == "")
		{
			err=1;
			var msg=msg+'- Nome non indicato'+'\n';		
		}
	if (trim(document.registr.cognome.value) == "")
		{
			err=1;
			var msg=msg+'- Cognome non indicato'+'\n';		
		}
	if (document.registr.privato.checked)
	{
	}
		var lencf = registr.code_fisc.value;	
		if ((trim(document.registr.code_fisc.value) == "") || ((lencf.length != 16) && (lencf.length != 11)) || (lencf.indexOf(' ') > -1))
		{
			var err=1;
			var msg=msg+'- Codice fiscale non indicato o non corretto'+lencf.length+'\n';		
		}
	
	if (document.registr.azienda.checked)
	{
		if (trim(document.registr.azi.value) == "")
		{
			err=1;
			var msg=msg+'- Azienda non indicato'+'\n';		
		}
		var leniva = registr.piva.value;
		if ((trim(document.registr.piva.value) == "") || (leniva.length < 11))
			{
				var err=1;
				var msg=msg+'- Partita IVA non indicata o non corretta'+'\n';		
			}
		
	}
	if (trim(document.registr.indirizzo.value) == "")
		{
			var err=1;
			var msg=msg+'- Indirizzo non indicato'+'\n';		
		}
			
	if (trim(document.registr.cap.value) == "" || (document.registr.cap.value.length < 5))
		{
			var err=1;
			var msg=msg+'- CAP non indicato oppure non corretto'+'\n';		
		}
	if (trim(document.registr.citta.value) == "")
		{
			var err=1;
			var msg=msg+'- Citta non indicata'+'\n';		
		}	
		
	if (document.registr.prov.selectedIndex == 0)
		{
			var err=1;
			var msg=msg+'- Provincia non indicata'+'\n';		
		}
	if (document.registr.stato.selectedIndex == 0)
		{
			var err=1;
			var msg=msg+'- Stato di residenza non indicato'+'\n';		
		}	 
		
	if (trim(document.registr.telefono.value) == "" && trim(document.registr.cellulare.value) == "")
		{
			var err=1;
			var msg=msg+'- Indicare almeno un recapito telefonico fisso o cellulare'+'\n';		
		}
	if (trim(document.registr.email.value) == "")
		{
			var err=1;
			var msg=msg+'- Non hai indicato il tuo indirizzo eMail'+'\n';		
		}
	else
		{
			var x = document.registr.email.value;
			var filter  = /^([a-zA-Z0-9_\.\-\'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
			if (filter.test(x)) var emailgiusto=1;
			else 
				{
					var err=1;
					var msg=msg+'- L\'indirizzo email ha un formato non corretto'+'\n';		
				
				}		
		}			
	if (trim(document.registr.conf_email.value) == "")
		{
			var err=1;
			var msg=msg+'- Non hai indicato il tuo indirizzo eMail di conferma'+'\n';		
		}
	else
		{
			
			var x = document.registr.conf_email.value;
			var filter  = /^([a-zA-Z0-9_\.\-\'])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
			if (filter.test(x)) var emailgiusto=1;
			else 
				{
					var err=1;
					var msg=msg+'- L\'indirizzo email di conferma ha un formato non corretto'+'\n';		
				
				}
			if (document.registr.conf_email.value  != document.registr.email.value)
			{
				var err=1;
					var msg=msg+'- Gli indirizzi email inseriti non corriscondono'+'\n';	
				}
		}
	// SPEDIZIONE	
		if (trim(document.registr.nome2.value) == "")
		{
			err=1;
			var msg=msg+'- Nome per Spedizione non indicato'+'\n';		
		}
	if (trim(document.registr.cognome2.value) == "")
		{
			err=1;
			var msg=msg+'- Cognome per Spedizione non indicato'+'\n';		
		}
	if (document.registr.azienda.checked)
	{		
		if (trim(document.registr.azi2.value) == "")
		{
			err=1;
			var msg=msg+'- Azienda per Spedizione non indicato'+'\n';		
		}
	}
	if (trim(document.registr.indirizzo2.value) == "")
		{
			var err=1;
			var msg=msg+'- Indirizzo per Spedizione non indicato'+'\n';		
		}
			
	if (trim(document.registr.cap2.value) == "" || (document.registr.cap2.value.length < 5))
		{
			var err=1;
			var msg=msg+'- CAP per Spedizione non indicato oppure non corretto'+'\n';		
		}
	if (trim(document.registr.citta2.value) == "")
		{
			var err=1;
			var msg=msg+'- Citta per Spedizione non indicata'+'\n';		
		}
	if (document.registr.prov2.selectedIndex == 0)
		{
			var err=1;
			var msg=msg+'- Provincia per Spedizione non indicata'+'\n';		
		}
	if (document.registr.stato2.selectedIndex == 0)
		{
			var err=1;
			var msg=msg+'- Stato di residenza per Spedizione non indicato'+'\n';		
		}	 
	if(!document.registr.pry.checked)
	{	
		var err=1;
		var msg=msg+'- Non e\' possibile accettare la registrazione se non viene dato il consenso al trattamento dei dati personali'+'\n';	
	}
		if (err == 0)
		{
			//alert(msg);
			document.registr.brg.disabled = true;
			return true;	
		}
		else
		{
			var msg=msg+'\n'+'Corregere i dati prima di procedere';
			if(view == 1)
				alert(msg);
			return false;
		}	
}

function update_form(val)
{
	if(val == 'P')
	{	
		document.registr.azi.disabled = true;
		document.registr.azi.className = 'textboxdisabled';
	    document.registr.piva.disabled = true;
		document.registr.piva.className = 'textboxdisabled';
		document.registr.azi2.disabled = true;
		document.registr.azi2.className = 'textboxdisabled';
		 
	}
	else
	{
		document.registr.azi.disabled = false;
		document.registr.azi.className = '';
	    document.registr.piva.disabled = false;
		document.registr.piva.className = '';			
		document.registr.azi2.disabled = false;
		document.registr.azi2.className = '';
		
	}
}

function copia_dati()
{	
	if(document.registr.idem.checked)
	{
		document.registr.nome2.value = document.registr.nome.value;
		document.registr.cognome2.value = document.registr.cognome.value;
		document.registr.azi2.value = document.registr.azi.value;
		document.registr.indirizzo2.value = document.registr.indirizzo.value;
		document.registr.cap2.value = document.registr.cap.value;
		document.registr.citta2.value = document.registr.citta.value;
		document.registr.prov2.selectedIndex = document.registr.prov.selectedIndex;		
		document.registr.stato2.selectedIndex = document.registr.stato.selectedIndex;
	}
	else
	{
		document.registr.nome2.value = '';
		document.registr.cognome2.value = '';
		document.registr.azi2.value = '';
		document.registr.indirizzo2.value = '';
		document.registr.cap2.value = '';
		document.registr.citta2.value = '';
		document.registr.prov2.selectedIndex = 0;
		document.registr.stato2.selectedIndex = 0;
	}
}

function UploadComplete()
{	
//	document.formfile.submit();
}
function setta(varia, valore, varia2, varia3, valore3)
{
	document.getElementById(varia).value = valore;	

	if(confirm("Confermi di eliminare questo file?"))
	{
		document.getElementById(varia2).value = "si";	
		document.getElementById(varia3).value = valore3;	
	}
	
}

function salva() { 
if (document.all) { 
	document.execCommand("SaveAs");  
}else{ 
	alert('Con il tuo Browser non funziona.'); 
} 
} 
window.onresize = function()
{
	if(document.getElementById("td_home"))
		document.getElementById("td_home").className = document.getElementById("td_home").className;
}
function apri(cat,num) {
	
	for (i= 1; i <= num; i++) 
	{
		if(document.getElementById('tr_'+cat +'_'+i).className == "bott_vis")
			document.getElementById('tr_'+cat +'_'+i).className ="bott_nasc";
		else
			document.getElementById('tr_'+cat +'_'+i).className ="bott_vis";		
	}
	document.getElementById('td_'+cat).className ="bott_vis";		
}

var ios = 0;
var aos = 0;
function insertOldSchool(theSel, var_1, var_2,var_3)
{
	var val_1 = document.getElementById(var_1).value;
	var val_2 = document.getElementById(var_2).value;
	var val_3 = document.getElementById(var_3).value;
	
	newValue = newText =val_1 + "-" + val_2 + "-" + val_3;	
	
	if (theSel.length == 0) 
	{
		var newOpt1 = new Option(newText, newValue);
		theSel.options[0] = newOpt1;
		theSel.selectedIndex = 0;
	} else if (theSel.selectedIndex != -1) {
		var selText = new Array();
		var selValues = new Array();
		var selIsSel = new Array();
		var newCount = -1;
		var newSelected = -1;
		var i;
		for(i=0; i<theSel.length; i++)
		{
			newCount++;
			if (newCount == theSel.selectedIndex) {
				selText[newCount] = newText;
				selValues[newCount] = newValue;
				selIsSel[newCount] = false;
				newCount++;
				newSelected = newCount;
			}
			selText[newCount] = theSel.options[i].text;
			selValues[newCount] = theSel.options[i].value;
			selIsSel[newCount] = theSel.options[i].selected;
		}
		for(i=0; i<=newCount; i++)
		{
			var newOpt = new Option(selText[i], selValues[i]);
			theSel.options[i] = newOpt;
			theSel.options[i].selected = selIsSel[i];
		}
	}
}

function appendOldSchool(theSel, var_1, var_2,var_3)
{
	var val_1 = document.getElementById(var_1).value;
	var val_2 = document.getElementById(var_2).value;
	var val_3 = document.getElementById(var_3).value;
	
	newValue = newText =val_1 + "-" + val_2 + "-" + val_3;
//	newText = val_1 + "-" + val_2 + "-" + val_3;
	
	if (theSel.length == 0) 
	{
		var newOpt1 = new Option(newText, newValue);
		theSel.options[0] = newOpt1;
		theSel.selectedIndex = 0;
	} 
	else if (theSel.selectedIndex != -1) 
	{
		var selText = new Array();
		var selValues = new Array();
		var selIsSel = new Array();
		var newCount = -1;
		var newSelected = -1;
		var i;
		for(i=0; i<theSel.length; i++)
		{
			newCount++;
			selText[newCount] = theSel.options[i].text;
			selValues[newCount] = theSel.options[i].value;
			selIsSel[newCount] = theSel.options[i].selected;
			
			if (newCount == theSel.selectedIndex) 
			{
				newCount++;
				selText[newCount] = newText;
				selValues[newCount] = newValue;
				selIsSel[newCount] = false;
				newSelected = newCount - 1;
			}
		}
		for(i=0; i<=newCount; i++)
		{
			var newOpt = new Option(selText[i], selValues[i]);
			theSel.options[i] = newOpt;
			theSel.options[i].selected = selIsSel[i];
		}
	}
}

function removeOldSchool(theSel)
{
	var selIndex = theSel.selectedIndex;
	if (selIndex != -1) {
		for(i=theSel.length-1; i>=0; i--)
		{
			if(theSel.options[i].selected)
			{
				theSel.options[i] = null;
			}
		}
		if (theSel.length > 0) {
			theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
		}
	}
}
function selectAllOptions(selStr)
{
	var selObj = document.getElementById(selStr);
	for (var i=0; i<selObj.options.length; i++) {
		selObj.options[i].selected = true;
	}
}
function placeInHidden2(delim, selStr, hidStr)
{
//	alert("selStr "+selStr);
//	var selObj = window.document.getElementById(selStr);
//	var hideObj = window.document.getElementById(hidStr);
	
	hidStr.value = '';
	for (var i=0; i<selStr.options.length; i++) {
		hidStr.value = hidStr.value ==
			'' ? selStr.options[i].value : hidStr.value + delim + selStr.options[i].value;
	}
}

function placeInHidden(delim, selStr, hidStr)
{
	var selObj = window.document.getElementById(selStr);
/*	if (selObj != null)
	{*/
		alert("lista " +selObj.options.length);
		var hideObj = document.getElementById(hidStr);
		hideObj.value = '';
		for (var i=0; i<selObj.options.length; i++) {
			hideObj.value = hideObj.value ==
				'' ? selObj.options[i].value : hideObj.value + delim + selObj.options[i].value;
		}
	//}
}
function SelectFilter (theKind, theSelect, source, theSelIndex)
{
		//alert('Source: '+source);
	if (source)
	{
		if (theSelIndex == '')	theSelIndex = 0;
		theComList = (document.getElementById(theKind + 'data').value).match (new RegExp ('#' + source + '[^#]*'));
		
		if (theComList)
		{
			theComItems = theComList[0].split ('|');
			with (theSelect.form[theKind])
			{
				options.length = 0;
				options[0] = new Option( '', '')
				
				for ( theIndex = 1; theIndex < theComItems.length -1; theIndex++) 
				{
					options[theIndex] = new Option( theComItems[theIndex], theComItems[theIndex])
					if (theComItems[theIndex] == theSelIndex)	
					{
						options.selectedIndex=theIndex;
					}
				}
			}
		}
		else
			theSelect.form[theKind].options.length = 0;
	}
	else
		theSelect.form[theKind].options.length = 0;
}
function ca(var1,var2)
{ 
	//alert("entrato"+provincia+ " "+ comune);
//	document.getElementById('provinc_ann').selectedIndex = provincia;
	SelectFilter('quantita', document.getElementById('misura_car'), var1,var2);
}
