<!--
isMSIE=(navigator.appName=="Microsoft Internet Explorer");
isMSIE5=this.isMSIE&&(navigator.userAgent.indexOf('MSIE 5')!=-1);
isMSIE5_0=this.isMSIE&&(navigator.userAgent.indexOf('MSIE 5.0')!=-1);
isMSIE7=this.isMSIE&&(navigator.userAgent.indexOf('MSIE 7')!=-1);
isSafari=BrowserDetect.browser=='Safari';
isFirefox=BrowserDetect.browser=='Firefox';
isGecko=navigator.userAgent.indexOf('Gecko')!=-1;

function SwapVisibility(objID)
{
	if (document.getElementById(objID).className=="Hidden")
	{
		document.getElementById(objID).className="Visible";
	}
	else
	{
		document.getElementById(objID).className="Hidden";
	}
}
function SetVisibility(objID, state)
{
	if (state)
	{
		document.getElementById(objID).className="Visible";
	}
	else
	{
		document.getElementById(objID).className="Hidden";
	}
}


function Visibility(objID, visible)
{
	if (visible)
	{
		document.getElementById(objID).style.visibility="visible";
	}
	else
	{
		document.getElementById(objID).style.visibility="hidden";
	}
}

function addOption(nameTarget, txValue, txText)
{
	var oTarget			=	new Object;
	oTarget				=	document.getElementById(nameTarget);
	if (isMSIE || isMSIE5 || isMSIE5_0)
	{
		var oOption 		= 	document.createElement("OPTION");
		oTarget.options.add(oOption) ;
		oOption.innerText 	= 	txValue;
		oOption.value 		= 	txText;
	}
	else
	{
		oTarget.options[oTarget.options.length] = new Option(txValue,txText);
	}
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;	
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			 IsNumber = false;
		}
	}
	return IsNumber;	
}

function mailto(scrivi) {
	var dominio = "spaziografico.it"
	var utente = "info"
	var destinatario = utente + "@" + dominio
	var indirizzo = "mailto:" + destinatario
	if (!scrivi) location.href=indirizzo;
	else document.write(destinatario.link(indirizzo));
}

function apri_fin (url, width, height) {
	var left=(window.screen.availWidth-10-width)/2;
	if (window.screen.availHeight<600) {
		var top=0;
	} else {
		var top=(window.screen.availHeight-55-height)/2;
	}
	window.open(url, '', 'width='+width+',height='+height+',toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars=1,resizable=1,top='+top+',left='+left);
	//window.open(url,'','fullscreen,scrollBars=0,resizable=0')
}


function goto_site (url) {
	window.open(url, '', '');
	//window.open(url,'','fullscreen,scrollBars=0,resizable=0')
}

function checkQuote (txt) {
	if (txt.value.indexOf("'") != -1) {
		alert("Il carattere apice (') non è consentito");
		txt.focus();
	}
}

function filtra_file(mytext, type) {
	mytxt = mytext.value.toLowerCase() ;
	if(mytxt.indexOf(type) == -1) {
		alert("Attenzione file selezionato non corretto.\n\nDeve essere un file di tipo " + type + ".");
		mytext.value="";
		return false ;
	} else {
		return true ;
	}
}

function type_of_file(namefile, span, typeofile)
{
	btn_send_this = document.getElementById('btn_upload_' + span);
	var_send_this = document.getElementById('send_this_' + span);
	id = document.getElementById('type_file_' + span);
	id.className = "typefile";
	if (typeofile=="") ok = true  ;  else ok = false  ;
	namefile = namefile.toLowerCase();
	if (namefile.indexOf(".exe") != -1) {
		if (typeofile==".exe") ok = true;
		typefile = "File EXE / File di Programma";
	} else if (namefile.indexOf(".com") != -1) {
		if (typeofile==".com") ok = true;
		typefile = "File COM / Eseguibile";
	} else if (namefile.indexOf(".zip") != -1) {
		if (typeofile==".zip") ok = true;
		typefile = "File ZIP / Compresso WinZip";
	} else if (namefile.indexOf(".jpg") != -1) {
		if (typeofile==".jpg") ok = true;
		typefile = "File JPEG / Immagine";
	} else if (namefile.indexOf(".gif") != -1) {
		if (typeofile==".gif") ok = true;
		typefile = "File GIF / Immagine";
	} else if (namefile.indexOf(".png") != -1) {
		if (typeofile==".png") ok = true;
		typefile = "File PNG / Immagine";
	} else if (namefile.indexOf(".pdf") != -1) {
		if (typeofile==".pdf") ok = true;
		typefile = "File PDF / Documento Acrobat";
	} else if (namefile.indexOf(".doc") != -1) {
		if (typeofile==".doc") ok = true;
		typefile = "File DOC / Documento Word";
	} else if (namefile.indexOf(".xls") != -1) {
		if (typeofile==".xls") ok = true;
		typefile = "File XLS / Documento Excel";
	} else if (namefile.indexOf(".txt") != -1) {
		if (typeofile==".txt") ok = true;
		typefile = "File TXT / Testo";
	} else {
		typefile = "File non supportato";
		ok = false;
	}	
	if (ok) {
		if (document.getElementById('ok')!=null) document.getElementById('ok').disabled=false;
		id.className = "typefile-ok";
		btn_send_this.disabled = false ;
	}	else {
		if (document.getElementById('ok')!=null) document.getElementById('ok').disabled=true;
		id.className = "typefile-err";
		btn_send_this.disabled = true ;
	}
	//id.innerHTML = '<a href="' + namefile + '" target="_blank">' + typefile + '</a>' ;
	id.innerHTML = typefile ;
}

function valuta(price) 
{
   string = "" + price ;
   if (string=="") {
		return '0.00' ;		
   } else {
		number = string.length - string.indexOf('.');
		if (string.indexOf('.') == -1)
		  return string + '.00';
		if (number == 1)
		  return string + '00';
		if (number == 2)
		  return string + '0';
		if (number > 3)
		  return string.substring(0,string.length-number+3);
		return string;
	}

}

function verificaEt(myEmail){
	mail = myEmail.value;
	if (mail!="") {
		if ( mail.indexOf("@",1)==-1 || mail.indexOf(".",1)==-1) {
			myEmail.value="";
			myEmail.focus();				
			alert("Il formato dell'e-mail non è valido");
		}
	}
}


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 è\n"
		+"corretta: il codice fiscale dovrebbe essere lungo\n"
		+"esattamente 16 caratteri.\n";
	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 '';
}


function verifica_cfpiva()
{
	cod = document.form1.cod.value;
	document.form1.cod.focus();

	if( cod == '' )
		err = "hai lasciato in bianco il campo!\n";
	else if( cod.length == 16 )
		err = ControllaCF(cod);
	else if( cod.length == 11 )
		err = ControllaPIVA(cod);
	else
		err = "Il codice introdotto non è valido:\n\n" +
			"  - un codice fiscale deve essere lungo 16 caratteri;\n\n" +
			"  - una partita IVA deve essere lunga 11 caratteri.\n";

	if( err > '' )
		alert("VALORE ERRATO\n\n" + err + "\nCorreggi e riprova!");
	else
		alert("Il codice è valido.");
}

// Converte una stringa data in un oggetto data
function StrDate( str_date )
{
	str_date = str_date || '';
	var partOfDate = str_date.split("/");
	var d = partOfDate[0];
	var m = partOfDate[1] - 1;
	var y = partOfDate[2];
	var objDate = new Date(y, m, d);
	return objDate ;
}
// Converte una stringa data in un oggetto data
function StrDateTime( str_date_time )
{
	str_date_time = str_date_time || '';
	var partOfDateTime = str_date_time.split(" ");
	var partOfDate = partOfDateTime[0].split("/");
	var partOfTime = partOfDateTime[1].split(":");	
	var d = partOfDate[0];
	var m = partOfDate[1] - 1;
	var y = partOfDate[2];
	var hh = partOfTime[0];
	var mm = partOfTime[1];
	var ss = partOfTime[2];	
	var objDate = new Date(y,m,d,hh,mm,ss);
	return objDate ;
}
// Visualizzazione standard della data partendo da un oggetto data
function ViewDate( obj_date )
{
	var d = obj_date.getDate().toString();
	d = (d.length==1) ? "0"+d : d;
	var m = (obj_date.getMonth()+1).toString();
	m = (m.length==1) ? "0"+m : m;
	var y = obj_date.getFullYear().toString();
	var str_date = d +'/'+ m +'/'+ y;
	return str_date;
}
// stringa data in formato GG/MM/YYYY
function IsDate(str_date)
{
	var partOfDate = str_date.split("/");
	var d = partOfDate[0];
	var m = partOfDate[1] - 1;
	var y = partOfDate[2];
	var objDate = new Date(y, m, d);
	if (d != objDate.getDate() || m != objDate.getMonth() || y != objDate.getFullYear()) return false;
	else {
		if (objDate.getFullYear() > 1900 && objDate.getFullYear() < 2079) return true;
		else return false;
	}
}





function verificaDataMag(myDate, preDate, nowData) {
	
	if (verificaData(myDate)) {
	
		obj=myDate.value.replace(/[^\d]/g,"0");
		gg=obj.substr(0,2)
		mm=obj.substr(3,2);
		aa=obj.substr(6,4);
		data = new Date(aa,mm,gg);

		obj_pre=preDate.replace(/[^\d]/g,"0");
		gg_pre=obj_pre.substr(0,2)
		mm_pre=obj_pre.substr(3,2);
		aa_pre=obj_pre.substr(6,4);
		data_pre = new Date(aa_pre,mm_pre,gg_pre);

		obj_now=preDate.replace(/[^\d]/g,"0");
		gg_now=obj_now.substr(0,2)
		mm_now=obj_now.substr(3,2);
		aa_now=obj_now.substr(6,4);
		data_now = new Date(aa_now,mm_now,gg_now);

		data_ = (data_pre > data_now)?data_pre:data_now;
		strData = data_.getDate().toString() + "/" + data_.getMonth().toString() + "/" + data_.getFullYear().toString();
		if (data_ > data) {
			alert("Attenzione la data inserita non è valida\ninserire una data superiore a:\n\n" + strData);
			return false ;
		} else {
			return true ;
		}

	}
	
}

function verificaData(myDate)
{
	if (myDate.value!="")
	{
		var date_correct = isDate(myDate.value);
		if ( !date_correct )
		{
			alert("Verificare la data inserita\n" + "La data deve essere nel formato gg/mm/aaaa");
			myDate.focus(); //...viene ridato il focus per il reinserimento		
		}
	}
}

function isDate( myDate )
{
	if (myDate!="")
	{
		obj=myDate.replace(/[^\d]/g,"0");
		obj = obj.toString();
		
		if (obj.length != 10) return false;
		
		gg=obj.substr(0,2)
		mm=obj.substr(3,2);
		aa=obj.substr(6,4);
		
		strdata=gg+"/"+mm+"/"+aa;
		
		data = new Date(aa,mm-1,gg);
		daa=data.getFullYear().toString() ; 
		dmm=(data.getMonth()+1).toString();
		dmm=dmm.length==1?"0"+dmm:dmm
		dgg=data.getDate().toString();
		dgg=dgg.length==1?"0"+dgg:dgg
		dddata=dgg+"/"+dmm+"/"+daa
		
		return true; // Nel campo viene scritta la data generata	
	
	} else {
		return false;
	}
	return false;
}
function check_keycode(myText) {
	myText.value = event.keyCode ;
	event.returnValue=false;
}

function invio2tab(me, next) {
	if (event.keyCode==13) {
		event.returnValue=false;
		if (next!=null) next.focus();
							else	me.blur();
	}
}

function solo_numeri(e) {
	e = e || event;
	var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	if ( !( charCode<=47 || (charCode>=48 && charCode<=57) || (charCode>=96 && charCode<=105) ) ) {
		e.returnValue=false;
	  	alert ("Attenzione puoi inserire solo i caratteri\n1234567890");
		return false;
	}
}

function solo_tel(e) {
	e = e || event;
	var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	if ( !( charCode<=47 || charCode==109 || charCode==189 || (charCode>=48 && charCode<=57) || (charCode>=96 && charCode<=105) ) ) {
		e.returnValue=false;
		alert ("Attenzione il formato di un n.ro di telefonico deve essere\n####-#######");
		return false;
	}
}

function solo_data(e) {
	e = e || event;
	var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	if ( !( charCode<=47 || charCode==55 || charCode==111 || (charCode>=48 && charCode<=57) || (charCode>=96 && charCode<=105) ) ) {
		e.returnValue=false;
  		alert ("Attenzione il formato della data deve essere\n##/##/####");
		return false;		
	}
}

function solo_valuta(e) {
	e = e || event;
	var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	if ( !( charCode<=47 || (charCode>=48 && charCode<=57) || (charCode>=96 && charCode<=105) || charCode==190 || charCode==110 )) {
		e.returnValue=false;
  		alert ("Attenzione puoi inserire solo i caratteri\n1234567890 ed il . per i decimali.");
		return false;
	}
}

function stampa() {
	document['go_stampa'].style.visibility = 'hidden';
	window.print();
	document['go_stampa'].style.visibility = 'visible';		
}

function apri_popup (url, id, width, height) {
	if (width=='') width='600';
	if (height=='') height='440';
	if (id=='') id='' ;
	window.open(url, id, 'width=' + width + ',height=' + height + ',toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars=1,resizable=1');
}
function zoom_popup (url) {
	width='720';
	height='580';
	id='zoomphoto';
	window.open(url, id, 'width=' + width + ',height=' + height + ',toolbar=0,location=0,directories=0,status=1,menuBar=0,scrollBars=0,resizable=0');
}
//-->
