

/*-------- GUIDA OPERAZIONI --------------*/
var horizontal_offset="9px"; //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0px"; //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all;
var ns6=document.getElementById&&!document.all;

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1;
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40;
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset);
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight;
}
return edgeoffset;
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox");
dropmenuobj.innerHTML=menucontents;
dropmenuobj.style.left=dropmenuobj.style.top=-500;
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style;
dropmenuobj.widthobj.width=tipwidth;
}
dropmenuobj.x=getposOffset(obj, "left");
dropmenuobj.y=getposOffset(obj, "top");
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px";
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px";
dropmenuobj.style.visibility="visible";
obj.onmouseout=hidetip;
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden";
dropmenuobj.style.left="-500px";
}

function createhintbox(){
var divblock=document.createElement("div");
divblock.setAttribute("id", "hintbox");
document.body.appendChild(divblock);
}

if (window.addEventListener){
window.addEventListener("load", createhintbox, false);
}
else if (window.attachEvent){
window.attachEvent("onload", createhintbox);
}
else if (document.getElementById){
window.onload=createhintbox;
}

//************************************************************************//



function toupper(obj)
{
	var valore=obj.value;
	
	var new_valore = valore.toUpperCase();
	
	obj.value=new_valore;
}



function show_dati(id,valore)
{
	
	if(document.getElementById(id).style.display=='none')
	{
		document.getElementById(id).style.display='block';
		document.getElementById(valore).innerHTML='Nascondi';
		
	}
	else if(document.getElementById(id).style.display=='block')
	{
		document.getElementById(id).style.display='none';
		document.getElementById(valore).innerHTML='Visualizza';
		
	}
	
}



function mod_pass()
{
	var old_pass = document.form_modpsw.old_psw.value;
	var new_pass = document.form_modpsw.new_psw;
	var re_pass = document.form_modpsw.re_psw;
	
	if((old_pass=="") || (new_pass=="") || (re_pass==""))
	{
		document.getElementById('error_list').style.display='block';
		document.getElementById('error_list').innerHTML='I dati inseriti non sono validi';
	}
	else
	{
		modpass();
	}
}




function show_item(item)
{
	
	if((document.getElementById(item).style.display=='none') || (document.getElementById(item).style.display==''))
	{
		document.getElementById(item).style.display='block'
	}
	else
	{
		document.getElementById(item).style.display='none'
	}


}



function open_extpage(page)
{
	window.open(page,'','width=640,height=500,scrollbars=1');
}



function ck_insforum(obj,val)
{
	
	if(val==1)
	{
		document.getElementById('error_ins').style.display='none';
		var titolo = obj.titolo.value;
		var messaggio = obj.messaggio.value;
	}
	else if(val==2)
	{
		document.getElementById('error_ris').style.display='none';
		var titolo = obj.titolo_ris.value;
		var messaggio = obj.messaggio_ris.value;
	}
	
	if((titolo=='') || (messaggio==""))
	{
		if(val==1)
		{
			document.getElementById('error_ins').style.display='block';
			document.getElementById('error_ins').innerHTML='Tutti i campi sono obbligatori';
		}
		else if(val==2)
		{
			document.getElementById('error_ris').style.display='block';
			document.getElementById('error_ris').innerHTML='Tutti i campi sono obbligatori';
		}
		
		return false;
	}
	else
	{
		return true;
	}
}


function ck_search(obj)
{
	document.getElementById('error_sc').style.display='none';
	var mese = obj.sc_mese.value;
	var anno = obj.sc_anno.value;
	
	if((mese=="") || (anno==""))
	{
		document.getElementById('error_sc').style.display='block';
		
		return false;
	}
	else
	{
		return true;
	}
}



function conf_redir(el,id)
{
	if (confirm("Attenzione eliminando questo messaggio verranno eliminate tutte le risposte correlate"))
	{
		document.location.href="forum.php?delid="+id;
	}
}



////////////////////////PAGAMENTO ONLINE////////////////////////////////

function RFill(Stringa, N, X) {
	Result = Stringa.replace(/\s+$|^\s+/g, '');
	if (!(Result.length >= N)) {
		for (i = Result.length; i < N; i++) {
			Result =  Result + X;
		}
	}
	return Result;
}


function FormattaEuro(Stringa) {
	Stringa = Stringa.toString();
	Stringa = Stringa.replace(/[,]/g, '.');
	if (!(isNaN(Stringa))) {
		if (Stringa.indexOf('.') != -1) {
			ParteIntera = Stringa.substring(0, Stringa.indexOf('.'));
			ParteDecimale = RFill(Stringa.substr(Stringa.indexOf('.') + 1, 2), 2, '0');
			return ParteIntera + ',' + ParteDecimale;
		} else {
			return Stringa + ',00';
		}
	} else {
		return '0,00';
	}
}


function FormattaCentesimi(Stringa) {
	Stringa = Stringa.toString();
	Stringa = Stringa.replace(/[,]/g, '.');
	if (Stringa.indexOf('.') != -1) {
		ParteIntera = Stringa.substring(0, Stringa.indexOf('.'));
		ParteDecimale = RFill(Stringa.substr(Stringa.indexOf('.') + 1), 2, '0');
		return ParteIntera + '' + ParteDecimale;
	} else {
		return Stringa + '' + '00';
	}
}



function calcolo()
{
	imp01=0;
	imp02=0;
	imp03=0;
	
	if(document.form_key.IMPO1.checked)
	{
		imp01=100;
	}
	
	if(document.form_key.IMPO2.checked)
	{
		imp02=350;
	}
	
	if((document.form_key.IMPO1.checked) || (document.form_key.IMPO2.checked))
	{
		document.form_key.IMPO3.disabled=true;
	}
	else
	{
		document.form_key.IMPO3.disabled=false;
	}
	
	if(document.form_key.IMPO3.checked)
	{
		imp03=450;
		document.form_key.IMPO1.disabled=true;
		document.form_key.IMPO2.disabled=true;
	}
	else
	{
		document.form_key.IMPO1.disabled=false;
		document.form_key.IMPO2.disabled=false;
	}
	
	var donazione = document.form_key.IMPO4.value;
	
	if(donazione!="")
	{
		
		if (isNaN(donazione.replace(",","."))) {
				alert('Devi inserire un valore numerico per l\'importo libero!');
				donazione.focus();
			}else {
				impo4Tmp = FormattaEuro(donazione);
				arrayTmp = impo4Tmp.split(",");
				if(arrayTmp[0].length > 5) {
					alert('Hai inserito un importo maggiore del previsto. Hai la possibilit� di inserire un importo massimo di 99999,00�');
					donazione.focus();
				}
				if(arrayTmp[1].length > 2) {
					alert('Hai inserito un importo decimale maggiore di 2 cifre significative. Correggere tale valore');
					donazione.focus();
				}			
				
				donazione = FormattaEuro(donazione);			
			}
	}
	else
	{
		donazione=0;
	}

	document.form_key.TOTALE.value = FormattaEuro(imp01+imp02+imp03+parseFloat(donazione));
	document.form_key.IMPORTO.value = FormattaCentesimi(imp01+imp02+imp03+parseFloat(donazione));
}


function ck_keyclient(obj)
{
	document.getElementById("error_key").style.display='none';
	
	errori = new Array();
	numerr = 0;
	
	var cognome = obj.COGNOME.value;
	var nome = obj.NOME.value;
	var mail = obj.EMAIL.value;
	var sede = obj.SEDE.value;
	var email_reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+[\.]([a-z0-9-]+)*([a-z]{2,3})$/;
	var importo = document.form_key.IMPORTO.value;
	var totale = document.form_key.TOTALE.value;
	
	
	if(cognome=='')
	{
		errori[numerr] = "Cognome non inserito";
		numerr = numerr+1;
	}
	if(nome=='')
	{
		errori[numerr] = "Nome non inserito";
		numerr = numerr+1;
	}
	if(!email_reg.test(mail))
	{
		errori[numerr] = "Email non valida";
		numerr = numerr+1;
	}
	if(sede=='')
	{
		errori[numerr] = "Sede di appartenenza non inserito";
		numerr = numerr+1;
	}
	if(importo<1)
	{
		errori[numerr] = "Importo non valido";
		numerr = numerr+1;
	}
	if(totale<1)
	{
		errori[numerr] = "totale non valido";
		numerr = numerr+1;
	}
	
	numarray = errori.length;
	
	if(numarray>0)
	{
		document.getElementById("error_key").style.display='block';
		i=0;
		
		var stringa="";
		
		for(i=0; i<numarray; i=i+1)
		{
			stringa = stringa + errori[i] + "<br>";
		}
		
		document.getElementById("error_key").innerHTML = stringa;
		return false;	
	}
	else
	{
		return true;
	}
	
}

/////////////////////////////////////////////////////////////////////////////////////////



function ck_mod_dati(obj)
{
	errori = new Array();
	numerr = 0;
	
	var com_nascita = obj.com_nascita.value;
	var reg_res = obj.regione_res.value;
	var prov_res = obj.prov_res.value;
	var comune_res = obj.comune_res.value;
	var indirizzo = obj.indirizzo_anag.value;
	var cap = obj.cap_anag.value;
	var partiva = obj.part_iva.value;
	var mail = obj.mail_pers.value;
	var telefono = obj.tel_anag.value;
	var cellulare = obj.cel_anag.value;
	
	var reg_data = /^[0-9]{2}[//][0-9]{2}[//][0-9]{4}$/;
	var email_reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+\.?[a-z0-9-]+[\.]([a-z0-9-]+)*([a-z]{2,3})$/;
	
	
	if(com_nascita=="")
	{
		errori[numerr] = "Comune di nascita non selezionato";
		numerr = numerr+1;
	}
	if(reg_res=="")
	{
		errori[numerr] = "Regione di residenza non selezionato";
		numerr = numerr+1;
	}
	if(prov_res=="")
	{
		errori[numerr] = "Provincia di residenza non selezionato";
		numerr = numerr+1;
	}
	if(comune_res=="")
	{
		errori[numerr] = "Comune di residenza non selezionato";
		numerr = numerr+1;
	}
	if(indirizzo=="")
	{
		errori[numerr] = "Indirizzo mancante";
		numerr = numerr+1;
	}
	if((isNaN(cap)) || (parseInt(cap)<0) || (cap==""))
	{
		errori[numerr] = "Codice avviamento postale non valido";
		numerr = numerr+1;
	}
	if(mail!="")
	{
		if(!email_reg.test(mail))
		{
			errori[numerr] = "Email principale non valida";
			numerr = numerr+1;
		}
	}
	if(telefono!="")
	{
		if(isNaN(telefono))
		{
			errori[numerr] = "Numero di telefono non valido";
			numerr = numerr+1;
		}
	}
	if(cellulare!="")
	{
		if(isNaN(cellulare))
		{
			errori[numerr] = "Numero di cellulare non valido";
			numerr = numerr+1;
		}
	}
	
	
	numarray = errori.length;
	
	if(numarray>0)
	{
		document.getElementById("error_mod").style.display='block';
		i=0;
		
		var stringa="";
		
		for(i=0; i<numarray; i=i+1)
		{
			stringa = stringa + errori[i] + "<br>";
		}
		
		document.location.href="#";
		document.getElementById("error_mod").innerHTML = stringa;
		
		return false;
	}
	else
	{
		return true;
	}
	
}


function logout()
{
	 if (confirm("Attenzione. Stai per uscire dal sito www.iltributarista.it vuoi memorizzare la password?"))
	{
		document.location.href="logout.php?out=1";
	}
	else
		 {
				document.location.href="logout.php";
		 }
}


function ck_archivio(obj)
{ 
  document.getElementById("error_sc").style.display="none";
  var sezione = obj.sc_sezione.value;

  if(sezione=="")
    {
      document.getElementById("error_sc").style.display="block";
      return false;
    }
    else
      {
        return true;
      }
}













