function Credits(){
	var w = 500;
	var h = 300;
	var l = Math.floor((screen.width-w)/2);
	var t = Math.floor((screen.height-h)/2);
	window.open("credits.php","","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ", status=no, menubar=no, toolbar=no scrollbar=no");
	return false;
}

function ArtByEmail(IDArticolo){
	var w = 450;
	var h = 450;
	var l = Math.floor((screen.width-w)/2);
	var t = Math.floor((screen.height-h)/2);
	window.open("art_by_email.php?IDArticolo=" + IDArticolo,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ", resizable=no, location=no, menubar=no, scrollbars=no, status=no");
	return false;
}

function isNumberKey(evt){ // CONTROLLA INSERIMENTO SOLO NUMERI
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;
	return true;
}

function echeck(str) { // CONTROLLA VALIDITA EMAIL
	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					
}

function ControllaPIVA(pi) {
	if( pi.length != 11 ){
		alert ("La lunghezza della partita IVA non è\n" +
			"corretta: la partita IVA dovrebbe essere lunga\n" +
			"esattamente 11 caratteri.\n");
		return false;
		}
	validi = "0123456789";
	for( i = 0; i < 11; i++ ){
		if( validi.indexOf( pi.charAt(i) ) == -1 ){
			alert("La partita IVA contiene un carattere non valido `" +
				pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n");
			return false;
		}
	}
	s = 0;
	for( i = 0; i <= 9; i += 2 )
		s += pi.charCodeAt(i) - '0'.charCodeAt(0);
	for( i = 1; i <= 9; i += 2 ){
		c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
		if( c > 9 )  c = c - 9;
		s += c;
	}
	if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) ){
		alert ("La partita IVA non è valida:\n" +
			"il codice di controllo non corrisponde.\n");
		return false;
		}
	return true;
}

function ControllaCF(cf) {
	var validi, i, s, set1, set2, setpari, setdisp, bolTemp;
	cf = cf.toUpperCase();
	
	if( cf.length != 16 ){
		alert ("La lunghezza del codice fiscale non è\n"
		+"corretta: il codice fiscale dovrebbe essere lungo\n"
		+"esattamente 16 caratteri.\n");
		return false;
	}
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 ){
			alert("Il codice fiscale contiene un carattere non valido `" +
				cf.charAt(i) +
				"'.\nI caratteri validi sono le lettere e le cifre.\n");
			return false;
		}
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) ){
		alert ("Il codice fiscale non è corretto:\n"+
			"il codice di controllo non corrisponde.\n");
		return false;
	}
	return true;
}

function SVota(theForm){
	var timestamp = new Date();
	var bolControllo=true;
	if(bolControllo){
		new Ajax.Updater('sondaggio_results', 'applets/_sondaggio.php?' + timestamp.getTime(), 
			{
			parameters : $(theForm).serialize(),
			onLoading  : function(rq){$('sondaggio_results').hide();$('sondaggio_wait').show();},
			onComplete : function(rq){$('sondaggio_wait').hide();$('sondaggio_results').show();},
			onFailure  : function(rq){alert('Errore ' + rq.status + ' -- ' + rq.statusText);}
			}
		);
	}
}