//FUNZIONE PER MENU TENDINA
//parametri: il contenitore del menu
//associa le classi "hafigli" agli elementi di una lista che contengono una sottolista
//associa la classe "active" agli elementi attivati dal mouseover e mostra la lista sottostante
function rollmenu(container) {
    var arr = document.getElementById(container).getElementsByTagName("li");
    var i;
    for (i=0; i<arr.length; i++) {

         if (arr[i].getElementsByTagName("ul")[0]) {
            arr[i].getElementsByTagName("a")[0].className += " hafigli ";        
        }

        arr[i].onmouseover = function() {
            this.getElementsByTagName("a")[0].className += " active ";
            if (this.getElementsByTagName("ul")[0]) this.getElementsByTagName("ul")[0].style.display="block";
        }
        arr[i].onmouseout = function() {
            this.getElementsByTagName("a")[0].className=this.getElementsByTagName("a")[0].className.replace("active","");            
            if (this.getElementsByTagName("ul")[0]) this.getElementsByTagName("ul")[0].style.display="none";
        }
    }
}

//SIMULA LA PSEUDO-CLASSE "FOCUS" - v.1.1 (ora può avere la propria classe, ne viene aggiunta un'altra)
function setFocus(elemento) {
    elemento.className+=" focus";
}

function unsetFocus(elemento) {
    elemento.className=elemento.className.replace('focus', '');
}

//FUNZIONE PER MOSTRARE I LINK ATTIVI
// richiamare la funzione nel tag body con onLoad e passare come parametro l'id del contenitore del menu
// non serve assegnare nessun valore particolare all'html.
// non funziona coi link indicizzabili ma tanto nel menu di navigazione non ci sono le categorie ;)

function currentlink(contenitore) {

    var stringa_get = document.location.href;        
    var menu = new Array();        
    menu = document.getElementById(contenitore).getElementsByTagName("a");
    if (stringa_get.match("php")) { //cioè se sono nel caso www.nomedominio.com/qualcosa.PHP <--
        var i;
        for (i=0; i<menu.length; i++) {            
            if (stringa_get.match(menu[i].href)) menu[i].className = "active";
        }
    } else menu[0].className = "active";
}

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];}}
}


var wiN;

function openWin(nomeFile,nomeFinestra,parametri,larghezza,altezza,barre,ridimensione,centrato) {

    option="toolbar=no,width=" + larghezza + ",height=" + altezza +",resizable=" + ridimensione + ",scrollbars=" + barre
    if (centrato=='yes') {
        LeftPosition = (screen.width) ? (screen.width-larghezza)/2 : 0;
        TopPosition = (screen.height) ? (screen.height-altezza)/2 : 0;
        option=option + ",top="+TopPosition+",left="+LeftPosition
    }
    wiN = window.open(nomeFile + "?titolo=" + nomeFinestra + parametri,nomeFinestra,option);
}

 

 // Spam-proof email by deanq.com
function vmemail(who,subject,domain,body) {
  if (!who) var who = "info";
  if (!domain) var domain = "sito.com";
  if (!subject) var subject = "Richiesta Informazioni";
  if (!body) var body = " ";
  eval("location.href='mailto:" + who + "@" + domain + "?subject=" + subject + "&body=" + body + "'");
}


function cambiaInfoUtente() {

    error = false;
    msgError="";
    nomeCognome = document.new_customer.txtRagSoc.value;
    telefono = document.new_customer.txtTelefono.value;
    
    
    if (nomeCognome == "") {
        error = true;
        msgError = "Compilare il campo 'Nome Cognome'\n"+msgError;
    }
    if (telefono == "") {
        error = true;
        msgError = "Compilare il campo 'Telefono'\n"+msgError;
    }
    if (!error) {
        // nn ci sn errori
        document.new_customer.azione.value = "salva";
        document.new_customer.submit();
    } else {
        alert(msgError);
    }

    return false;
}


function controllaPermessi() {
    if ((window.opener!==null) && (window.opener!==undefined) ) {
    } else {
        window.location.href = "http://www.blicomm.net";
    }
}

function paginateSize(pagina) {
        
    var paginaNumber = 1;
    var paginaSize = 10;
    
    if($("#selPageSize").val() != "") {
        paginaSize = $("#selPageSize").val();
    }
    
    if($("#selPageSize").val() != "") {
        document.location.href = pagina+"page="+paginaNumber+"&pageSize="+paginaSize;
        //$("#frmPaginate").submit(function() {alert('ok')});
    }
    return true;
}

function paginate(pagina) {
        
        var paginaNumber = 1;
        var paginaSize = 10;
        
        if($("#page").val() != "") {
            paginaNumber = $("#page").val();
        }
        
        if($("#selPageSize").val() != "") {
            paginaSize = $("#selPageSize").val();
        }
        
        if($("#page").val() != "") {
            document.location.href = pagina+"page="+paginaNumber+"&pageSize="+paginaSize;
            //$("#frmPaginate").submit(function() {alert('ok')});
        }
        return true;
    }
    
/**
	*	Controllo che la stringa passata sia numerica e più
	*	precisamente che contenga solo i caratteri validi passati in strvalidChars
	*/
	function IsValidChar(strString,strValidChars){
	   var strChar;
	   var blnResult = true;

	   if (strString.length == 0) return false;
	   for (i = 0; i < strString.length && blnResult == true; i++)
	      {
	      strChar = strString.charAt(i);
	      if (strValidChars.indexOf(strChar) == -1)
	         {
	         blnResult = false;
	         }
	      }
	   return blnResult;
	}

	/**
	*	Controllo il campo telefono se è corretto
	*/
	function isTelephoneNumber(telefono) {
		var ret = false;
		if ($.trim(telefono).length > 0) {
			ret = true;
		}
		return true;
	}

	/**
	*	Controllo il codice fiscale
	*	retituisce true se è corretto
	*/
	function isFiscalCode(campo) {
		ret = false;
		if (campo != "") {
			if (campo.match(/^[a-zA-Z]{6}[0-9]{2}[a-zA-Z]{1}[0-9]{2}[a-zA-Z]{1}[0-9]{3}[a-zA-Z]{1}$/)) {
				ret = true;
			}
		} else {
			ret = true;
		}
		
		return ret;
	}
	/**
	*	Controllo della partita iva
	*/
	function isIVA(pi) {
		ret = false;
		if (pi.match(/^([0-9]{11})$/)) {
			ret = true;
		}
		return ret;
	}
	
	function controllaIVAItaliana(pi) {
		ret = false;
		if (pi.match(/^([0-9]{11})$/)) {
			ret = true;
		}
		return ret;
	}

	/**
	*	Controllo il codice fiscale aziendale italiano
	*	retituisce true se è corretto
	*	che è fatto come la piva oppure come un CF normale
	*/
	function controllaCfAzItaliano(campo) {
		
		ret = false;
		if (controllaIVAItaliana(campo)) {
			// ok, è una piva
			ret = true;
		} else {
			// no, niente piva
			if (campo.match(/^[a-zA-Z]{6}[0-9]{2}[a-zA-Z]{1}[0-9]{2}[a-zA-Z]{1}[0-9]{3}[a-zA-Z]{1}$/)) {
				// ok, è un cf
				ret = true;
			}
		}
		return ret;
	}
	
	// Controllo della email
	function IsEmailValid(eml){
	    var test = eml;
	    var lAt = test.indexOf("@")
	    var lDot = test.lastIndexOf(".")
	    //Checks over 5: x@x.x
	    if ( test.length <5 || lAt <= 0 || lAt >= lDot - 1 || lDot >= test.length) {                
	        return false;
	    }else{
    		if(filter(test)){
    			return true;
	        }else{
        		return false;
	        }
	    }
	}

	function filter(address){
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,5})+$/;
		return filter.test(address);
	}
