/* ----------------------------- */
/* funzioni prototipo */
String.prototype.trim = function() {
	// skip leading and trailing whitespace
	// and return everything in between
	var x=this;
	x=x.replace(/^\s*(.*)/, "$1");
	x=x.replace(/(.*?)\s*$/, "$1");
	return x;
}// fine funzione

/* ----------------------------- */

function apriFinestra(name, larghezza, altezza){
	var x = (screen.width - larghezza)/2;
	var y = (screen.height - altezza)/2;
	var finestra = window.open(name, 'ingrandimento', 'width=' + larghezza +',height=' + altezza + ', toolbar=no, directories=no, location=no, status=no, menubar=no, copyhistory=no, scrollbars=no, resizable=no');
	finestra.moveTo(x,y);
	finestra.focus();
}// fine funzione

/*-----------------------------------------*/

function apriFinestraParam(name, larghezza, altezza, parametri){
	var x = (screen.width - larghezza)/2;
	var y = (screen.height - altezza)/2;
	var finestra = window.open(name, 'ingrandimento', 'width=' + larghezza +',height=' + altezza + ', ' + parametri);
	finestra.moveTo(x,y);
	finestra.focus();
}// fine funzione

/*-----------------------------------------*/

function login_accedi(){
	with(document.forms['login']){
		//alert(UNAME.value.length);
		if(UNAME.value.length<=2){
			alert('Username non valido!');
			UNAME.focus();
			return;
		}//fine if
		if(PASSWD.value.length<=2){
			alert('Password non valida!');
			PASSWD.focus();
			return;
		}//fine if
		submit();
	}// fine with
}// fine funzione
/*-----------------------------------------*/
function contattaci(lingua){
	// Italiano
	var testi1 = new Array(
	'Devi inserire il nome',
	'Devi inserire il cognome',
	'Devi inserire l\'indirizzo email in maniera corretta\nFormato: nome@dominio.xx',
	'Devi inserire un testo',
	'Non avete dato il consenso alla Legge 196/2003',
	'Specificare una professione'
	);
	// Inglese
	var testi2 = new Array(
	'Insert the name!',
	'Insert the surname',
	'E-mail format not correct\nFormat: name@dom.xx',
	'Insert a text message',
	'Non avete dato il consenso alla Legge 196/2003',
	'Specificare una professione'
	);
	with(document.forms[0]){

		// Nome
		frm_nome.value = frm_nome.value.trim();
		if(frm_nome.value==''){
			alert(eval('testi' + lingua  + '[0]'));
			frm_nome.focus();
			frm_nome.select();
			return;
		}//fine if

		// Cognome
		frm_cognome.value = frm_cognome.value.trim();
		if(frm_cognome.value==''){
			alert(eval('testi' + lingua  + '[1]'));
			frm_cognome.focus();
			frm_cognome.select();
			return;
		}//fine if

		// Mail
		frm_email.value = frm_email.value.trim();
		if (frm_email.value.search(/^\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\.\w+$/) == -1) {
			alert(eval('testi' + lingua  + '[2]'));
			frm_email.focus();
			frm_email.select();
			return;
		}//fine if

		// MESSAGGIO
		frm_mess.value = frm_mess.value.trim();
		if(frm_mess.value==''){
			alert(eval('testi' + lingua  + '[3]'));
			frm_mess.focus();
			frm_mess.select();
			return;
		}//fine if

		// Legge
		if(lingua == 1 ){
			if(!frm_legge.checked){
				alert(eval('testi' + lingua  + '[4]'));
				frm_legge.focus();
				return;
			}// fine if
		}// fine if

		frm_op.value = 'ok';
		submit();
	}// fine with
}// fine funzione


/*-----------------------------------------*/

function recruiting(lingua){
	// Italiano
	var testi1 = new Array(
		'Devi inserire il Nome',
		'Devi inserire il Cognome',
		'Devi inserire l\'indirizzo email in maniera corretta\nFormato: nome@dominio.xx',
		'Non avete dato il consenso alla Legge 196/2003'
	);
	// Inglese
	var testi2 = new Array(
		'You have to insert a name',
		'You have to insert a surname',
		'You must insert address email in correct form: nome@dominio.xx',
		'Non avete dato il consenso alla Legge 196/2003'
	);

	with(document.forms[0]){
		// nome
		if(Nome.value==''){
			alert(eval('testi' + lingua  + '[0]'));
			Nome.focus();
			return;
		}//fine if
		// nome
		if(Cognome.value==''){
			alert(eval('testi' + lingua  + '[1]'));
			Cognome.focus();
			return;
		}//fine if
		// Mail
		if (Email.value.search(/^\w+([\.\-]\w+)*@\w+([\.\-]\w+)*\.\w+$/) == -1) {
			alert(eval('testi' + lingua  + '[2]'));
			Email.focus();
			return;
		}//fine if
		// Legge
		if(lingua == 1){
			if(!check.checked){
				alert(eval('testi' + lingua  + '[3]'));
				check.focus();
				return;
			}// fine if
		}// fine if

		frm_op.value = 'ok';
		submit();
	}// fine with
}// fine if

/*-----------------------------------------*/

/*-------------------------------------------------------*/
function controllo_login(lingua){
	switch(lingua){
		case 2:
			msg_username='Field Username not valid!';
			msg_password='Field Password not valid!';
		break;
		default:
			msg_username='Campo Username non corretto!';
			msg_password='Campo Password non corretto!';
		break;
	}
	with(document.forms['MAIN']){

		if(UNAME.value==''){
			alert(msg_username);
			UNAME.focus();
			return;
		}// fine if

		if(PASSWD.value==''){
			alert(msg_password);
			PASSWD.focus();
			return;
		}// fine if

		submit();
	}// fine with
}// fine funzione


/*-----------------------------------------*/

/* DETTAGLIO PER PHOTOGALLERY */
function apriDettaglio(id){
	var pagina = 'gallery.php?pgSeriale=' + id;
	var larghezza = 580;
	var altezza = 450;
	var x = (screen.width -larghezza)/2;
	var y = (screen.height - altezza)/2;
	var finestra = window.open(pagina, 'ingrandimento', 'width=' + larghezza +',height=' + altezza + ',toolbar=no,directories=no,location=no,status=no,menubar=no,copyhistory=no,scrollbars=yes,resizable=yes');
	finestra.moveTo(x,y);
	finestra.focus();
}// fine funzione