
// Function to increase the font size of the page
var min=8;
var max=18;


$jq(document).ready(function(){

});

//Controlla la validità formale di un indirizzo mail
function eMailCheck(str) {
		
	if (jQuery.trim(str) == '')
		return false;
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false;
	 }

	 return true;					
}


//Valida la password
function validatePassword (pw, options) {
	
	//La commerce richiede password con le seugenti caratteristiche:
	// almento 6 caratteri con almeno 1 carattere alfabetico e uno numerico 
	// senza che abbia caratteri consecutivi uguali e senza caratteri/alfebitici consecutivi
	//
	var o = {
			lower:    0,
			upper:    1,
			alpha:    1, /* lower + upper */
			numeric:  1,
			special:  0,
			length:   [6, Infinity],
			custom:   [ /* regexes and/or functions */ ],
			badWords: [],
			badSequenceLength: 4,
			noQwertySequences: false,
			noSequential:      false
	};

	for (var property in options)
		o[property] = options[property];

	var	re = {
			lower:   /[a-z]/g,
			upper:   /[A-Z]/g,
			alpha:   /[A-Z]/gi,
			numeric: /[0-9]/g,
			special: /[\W_]/g
		},
		rule, i;

	// enforce min/max length
	if (pw.length < o.length[0] || pw.length > o.length[1])
		return false;

	// enforce lower/upper/alpha/numeric/special rules
	for (rule in re) {
		if ((pw.match(re[rule]) || []).length < o[rule])
			return false;
	}

	// enforce word ban (case insensitive)
	for (i = 0; i < o.badWords.length; i++) {
		if (pw.toLowerCase().indexOf(o.badWords[i].toLowerCase()) > -1)
			return false;
	}

	// enforce the no sequential, identical characters rule
	if (o.noSequential && /([\S\s])\1/.test(pw))
		return false;

	// enforce alphanumeric/qwerty sequence ban rules
	if (o.badSequenceLength) {
		var	lower   = "abcdefghijklmnopqrstuvwxyz",
			upper   = lower.toUpperCase(),
			numbers = "0123456789",
			qwerty  = "qwertyuiopasdfghjklzxcvbnm",
			start   = o.badSequenceLength - 1,
			seq     = "_" + pw.slice(0, start);
		for (i = start; i < pw.length; i++) {
			seq = seq.slice(1) + pw.charAt(i);
			if (
				lower.indexOf(seq)   > -1 ||
				upper.indexOf(seq)   > -1 ||
				numbers.indexOf(seq) > -1 ||
				(o.noQwertySequences && qwerty.indexOf(seq) > -1)
			) {
				return false;
			}
		}
	}

	// enforce custom regex/function rules
	for (i = 0; i < o.custom.length; i++) {
		rule = o.custom[i];
		if (rule instanceof RegExp) {
			if (!rule.test(pw))
				return false;
		} else if (rule instanceof Function) {
			if (!rule(pw))
				return false;
		}
	}

	// Check if first letter is uppercase
	
	var firstPassLetter = pw.substring(0,1);
	var firstPassLetterUpper = firstPassLetter.toUpperCase();
	
	if (firstPassLetter != firstPassLetterUpper)
		return false;
	
	// great success!
	return true;
}

// Valida i numeri di telefono per l'olanda
// 10 o 11 cifre con l'eventuale barretta dopo il prefisso
function validateTelNumb(tel){
	if ((/^\d{2}(|-)?\d{8,9}$/.test(tel)) || 
		(/^\d{3}(|-)?\d{7,8}$/.test(tel)) ||
		(/^\d{4}(|-)?\d{6,7}$/.test(tel))
		){
		return true;
	} else {
		return false;
	} 
}

function stampa(obj){
	$jq("#"+obj).jqprint({importCSS:true, printContainer:false, debug:true });
}


// Funzione per calcolare il numero degli elementi in un array associativo
function associativeArrayLength(associativeArray) {
	
    var i = 0;
    
    for (key in associativeArray) {
        i++;
    }
    
    return i;
}



// ----- Funzioni utilizzate nell'onload del body delle pagine ----- 
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_findObj(n, d) { //v4.01
	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 && d.getElementById) x=d.getElementById(n); return x;
}
	 
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// ------------------------------------------------------------------

function MM_openBrWindow(theURL,winName,features){ 
	window.open(theURL,winName,features);
}

