// JavaScript Document
var popUpWin=0;
var pattern=/^\d*[0-9],{0,1}\d{0,2}$/;
var pattern2=/^\d*[0-9](,{1}\d{1,2})*?$/;

//funzione per il submit del form
function fsubmit(id){
	var f=document.getElementById(id).elements;
	var errore=0;
	
	for(i=0;i<f.length;i++)
	{
		if(f[i].value=="" || f[i].value==null)
		{
			errore=1;
		}
	}
	if(errore>0)
	{
		alert('Attenzione! Compilare tutti i campi del modulo');
		return false;
	}else{
		document.getElementById(id).submit();
	}
}	

function fsubmit2(id){
	var f=document.getElementById(id).elements;
	var errore=0;
	
	for(i=0;i<f.length;i++)
	{
		if(f[i].value=="" || f[i].value==null)
		{
			errore=1;
		}
	}
	if(errore>0)
	{
		alert('Attenzione! Compilare tutti i campi del modulo');
		return false;
	}else{
		return true;
	}
}	

//funzione per sapere se la lunghezza del testo ID è di almeno minLen lunga
function checkLen(id,minLen){
	var lAtt=document.getElementById(id).length;
	if (lAtt<minLen)
	{
		alert("Inserire nel campo " + id + " un testo di almeno "+ minLen + " caratteri");
		return false;
	}else{
		return true;
	}
	}
	
	
	function DomandaEl()
{
	if(confirm('ATTENZIONE! l\'eliminazione è irreversibile. Eliminare definitivamente?'))
	{
		return true;
	}else{
		return false;
	}
}


//funzione per formattare un numero in euro
function format(valore){
var i,nnumero,valore,temp,conta;
nnumero=new String();
temp=valore.indexOf(",");
if(temp>=0){
start=temp-1;
}else{
start=valore.length-1;
}

//alert(valore+" "+start);

conta=1
for(i=start;i>=0;i--){

if(conta==4){
nnumero=valore.substr(i,1)+"."+nnumero;
conta=2;
}else{
nnumero=valore.substr(i,1)+nnumero;
conta++;
}

}

//ricostruisco il numero decimali inclusi
if(start==(temp-1)){

if((valore.length-(temp+1))<2){
nnumero+=","+valore.substr((temp+1),2)+"0";
}else{
nnumero+=","+valore.substr((temp+1),2);
}

}else{
nnumero+=",00";
}

return nnumero;
}


function showHideT(idM)
{
 var cambiain;
 var stato;
 
 stato=document.getElementById(idM).style.display;
 
 if(stato== 'block' || stato==''){
 cambiain='none';
  }else{
  cambiain='block';
  }
  
  document.getElementById(idM).style.display=cambiain;
  
  bottoneT(idM);
}

function showHide(idM)
{
 var cambiain;
 var stato;
 
 stato=document.getElementById(idM).style.display;
 
 if(stato== 'block' || stato==''){
 cambiain='none';
  }else{
  cambiain='block';
  }
  
  document.getElementById(idM).style.display=cambiain;
  

}
//funzione per cambiare il disegno del pulsante del menu
function bottoneT(categoria)
{
	
	
	
	if(document.getElementById(categoria+'1imga').style.display=='block' || document.getElementById(categoria+'1imga').style.display=='')
	{
		document.getElementById(categoria+'1imga').style.display='none';
		document.getElementById(categoria+'2imga').style.display='block';
	}else{
		document.getElementById(categoria+'1imga').style.display='block';
		document.getElementById(categoria+'2imga').style.display='none';
		
		//chiudiMenu(categoria,numero);
	}
	
}


//colore di una cella/riga al passaggio onmouseover/out + filter di trasparenza
function rollColor(id){
//document.getElementById(id).style.background='#01680d';
document.getElementById(id).style.background='#99CCFF';
document.getElementById(id).style.filter='alpha(opacity=50)';
}
function rollOut(id){
document.getElementById(id).style.background='';
document.getElementById(id).style.filter='';
}


//finestra in popup
function popUpWindow(URLStr, left, top, width, height)

{

  if(popUpWin)

  {

    if(!popUpWin.closed) popUpWin.close();

  }

  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

}

//replace di una stringa dentro un'altra stringa
function Replace(StringToReplace, StringToChange, StringChangedIn) { 
return StringToReplace.replace(StringToChange, StringChangedIn); 
} 

//solo numeri che conbaciano con PATTERN
function checkNum(id){

var numero;
numero=document.getElementById(id).value;
if(numero=='' || numero==null){
//document.getElementById(id).value="0,00";
numero="0,00";
}
//alert(numero);
if(!numero.match(pattern)){
alert('Inserire soltanto numeri interi o decimali separati da virgole senza il separatore delle migliaia');
document.getElementById(id).value="0,00";
}
}

//cancellare dalla pagina un elemento tramite id
function delElementById(id) {
var	node,
		result;
	node = 	document.getElementById ? 
		document.getElementById(id) : 
		document.all[id];
	result = (node && node.parentNode);
	
	if(result)
		node.parentNode.removeChild(node);
	return result;
}//fine



function checkPassa()
{
	var npassa=document.getElementById('npassa').value;
	var cnpassa=document.getElementById('cnpassa').value;
	var err=0, err_txt="Errori nella compilazione del form:";
	
	if(npassa.length<6 || cnpassa<6 ){err++;err_txt+="\n- la password deve essere lunga almeno 6 caratteri";}
	if(!npassa.equals(cnpassa)){err++;err_txt+="\n- errore nella conferma della password";}
	
	if(err==0)
	{
		return true;
	}else{
		alert(err_txt);
		return false;
	}
	
}


function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

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 flvFSTI3(v1,v2){//v1.01
var v3;if (v1.filters[0]&&v1.filters[0].status==2){v1.filters[0].Stop();}if (v2==0){v3="blendTrans(Duration="+v1.STI8+")";}else {v3="revealTrans(Duration="+v1.STI8+",Transition="+(v2-1)+")";}v1.style.filter=v3;}


function flvFSTI1(){//v1.01
// Copyright 2003, Marja Ribbers-de Vroed, FlevOOware (www.STI1.nl/dreamweaver/)
var v1=arguments,v2=document,v3;
v2.STI4=new Array();
v2.STI7=(navigator.userAgent.toLowerCase().indexOf("mac")!=-1);
for (var v4=0;v4<v1.length-2;v4+=5){v3=MM_findObj(v1[v4]);
if (v3){v3.STI5=v3.src;v3.STI6=v1[v4+1];v3.STI2=v1[v4+2];v3.STI3=v1[v4+3];v3.STI8=v1[v4+4];v2.STI4[v2.STI4.length]=v3;if (v3.filters&&!v2.STI7){flvFSTI3(v3,v3.STI2);v3.onfilterchange=flvFSTI4;v3.filters[0].Apply();}v3.src=v3.STI6;if (v3.filters&&!v2.STI7){v3.filters[0].Play();}}}}

function flvFSTI2(){//v1.01
var v1,v2=document,v3=v2.STI4,v4;for (v4=0;v3&&v4<v3.length&&(v1=v3[v4])&&v1.STI5;v4++){if (v1.filters&&!v2.STI7){flvFSTI3(v1,v1.STI3);v1.filters[0].Apply();}v1.src=v1.STI5;if (v1.filters&&!v2.STI7){v1.filters[0].Play();}}}

function flvFSTI4(){//v1.01
this.style.filter="";}
