/*
*	Funzioni globali
*/
	// apre il popup della privacy
	function privacy(){
		openWin("/privacy.php", "privacy", "", "800", "600", "yes", "yes", "yes");
		return false;
	}
	
	// apre un popup
	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 + parametri, nomeFinestra, option);
	}
	
/* 
*	funzioni per i controlli
*/
	
	// 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);
	}
	
	//	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;
	}
	
	
