function clearFormRegistrazione() {
	$('doaction').value = "clear";
	
	$('frmreg').submit();		
}

function checkFormRegistrazioneENG() {	
	var marca, modello, paese_immatr, dtimm_yy, targa, kw, cc, nome, cognome, dtnascita_gg, dtnascita_mm, dtnascita_yy, nazionalita, 
		indirizzo, cap, citta, prov, nazione, tel_fisso, tel_mobile, fax, email, note;
		
	marca = ($('marca')) ? $F('marca') : "";
	modello = ($('modello')) ? $F('modello') : "";
	paese_immatr = ($('paese_immatr')) ? $F('paese_immatr') : "";
	dtimm_yy = ($('dtimm_yy')) ? $F('dtimm_yy') : "";
	targa = ($('targa')) ? $F('targa') : "";
	kw = ($('kw')) ? $F('kw') : "";
	cc = ($('cc')) ? $F('cc') : "";
	nome = ($('nome')) ? $F('nome') : "";
	cognome = ($('cognome')) ? $F('cognome') : "";
	dtnascita_gg = ($('dtnascita_gg')) ? $F('dtnascita_gg') : "0";
	dtnascita_mm = ($('dtnascita_mm')) ? $F('dtnascita_mm') : "0";
	dtnascita_yy = ($('dtnascita_yy')) ? $F('dtnascita_yy') : "0";
	dtnascita = dtnascita_gg + "/" + dtnascita_mm + "/" + dtnascita_yy;
	nazionalita = ($('nazionalita')) ? $F('nazionalita') : "";
	indirizzo = ($('indirizzo')) ? $F('indirizzo') : "";
	cap = ($('cap')) ? $F('cap') : "";
	citta = ($('citta')) ? $F('citta') : "";
	prov = ($('ds_provincia')) ? $F('ds_provincia') : "";
	nazione = ($('nazione')) ? $F('nazione') : "";
	tel_fisso = ($('tel_fisso')) ? $F('tel_fisso') : "";
	tel_mobile = ($('tel_mobile')) ? $F('tel_mobile') : "";
	fax = ($('fax')) ? $F('fax') : "";
	email = ($('email')) ? $F('email') : "";
	note = ($('note')) ? $F('note') : "";
	
	var errore = false;
	var message = "Error. Application can not be sent:\r\n\r\n";
	
	if(marca == "") {
		errore = true;
		message += "- Please, fill in the Automaker field.\r\n";
	}
	if(modello == "") {
		errore = true;
		message += "- Please,fill in the model field.\r\n";
	}
	if(paese_immatr == "") {
		errore = true;
		message += "- Please,select the country of registration.\r\n";
	}
	if(dtimm_yy == "") {
		errore = true;
		message += "- Please select the year of construction.\r\n";
	}
	if(targa == "") {
		errore = true;
		message += "- Please, fill in the number plate field.\r\n";
	}
	if(kw == "") {
		errore = true;
		message += "- Please,fill in the power field.\r\n";
	}
	if(cc == "") {
		errore = true;
		message += "- Please,fill in the displacement field.\r\n";
	}
	if(nome == "") {
		errore = true;
		message += "- Please, fill in the name field.\r\n";
	}
	if(cognome == "") {
		errore = true;
		message += "- Please, fill in the surname field.\r\n";
	}
	if(!controllo_data(dtnascita)) {
		errore = true;
		message += "- Please insert a valid birth date.\r\n";
	}
	if(nazionalita == "") {
		errore = true;
		message += "- Please, fill in the nationality field.\r\n";
	}
	if(indirizzo == "") {
		errore = true;
		message += "- Please, fill in the address field.\r\n";
	}
	if(indirizzo == "") {
		errore = true;
		message += "- Please, fill in the zip code field.\r\n";
	}
	if(citta == "") {
		errore = true;
		message += "- Please, fill in the City field.\r\n";
	}
	if(prov == "") {
		errore = true;
		message += "- Please, fill in the Province field.\r\n";
	}
	if(nazione == "") {
		errore = true;
		message += "- Please, fill in the Nation field.\r\n";
	}
	if(tel_fisso == "") {
		errore = true;
		message += "- Please, fill in the fixed phone field.\r\n";
	}
	if(tel_mobile == "") {
		errore = true;
		message += "- Please, fill in the mobile phone field.\r\n";
	}
	if (email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
		errore = true;
		message += "- Please, insert a valid e-mail.\r\n";
	}
	
	if(errore) {
		alert(message);
		return false;
	}
		
	$('frmreg').submit();
}

function checkFormRegistrazione() {	
    var marca, modello, paese_immatr, dtimm_yy, targa, kw, cc, nome, cognome, dtnascita_gg, dtnascita_mm, dtnascita_yy, nazionalita, 
		indirizzo, cap, citta, prov, nazione, tel_fisso, tel_mobile, fax, email, note;
		
	marca = ($('marca')) ? $F('marca') : "";
	modello = ($('modello')) ? $F('modello') : "";
	paese_immatr = ($('paese_immatr')) ? $F('paese_immatr') : "";
	dtimm_yy = ($('dtimm_yy')) ? $F('dtimm_yy') : "";
	targa = ($('targa')) ? $F('targa') : "";
	kw = ($('kw')) ? $F('kw') : "";
	cc = ($('cc')) ? $F('cc') : "";
	nome = ($('nome')) ? $F('nome') : "";
	cognome = ($('cognome')) ? $F('cognome') : "";
	dtnascita_gg = ($('dtnascita_gg')) ? $F('dtnascita_gg') : "0";
	dtnascita_mm = ($('dtnascita_mm')) ? $F('dtnascita_mm') : "0";
	dtnascita_yy = ($('dtnascita_yy')) ? $F('dtnascita_yy') : "0";
	dtnascita = dtnascita_gg + "/" + dtnascita_mm + "/" + dtnascita_yy;
	nazionalita = ($('nazionalita')) ? $F('nazionalita') : "";
	indirizzo = ($('indirizzo')) ? $F('indirizzo') : "";
	cap = ($('cap')) ? $F('cap') : "";
	citta = ($('citta')) ? $F('citta') : "";
	prov = ($('prov')) ? $F('prov') : "";
	nazione = ($('nazione')) ? $F('nazione') : "";
	tel_fisso = ($('tel_fisso')) ? $F('tel_fisso') : "";
	tel_mobile = ($('tel_mobile')) ? $F('tel_mobile') : "";
	fax = ($('fax')) ? $F('fax') : "";
	email = ($('email')) ? $F('email') : "";
	note = ($('note')) ? $F('note') : "";
	
	var errore = false;
	var message = "Attenzione, per poter inviare la richiesta di associazione č necessario:\r\n\r\n";
	
	if(marca == "") {
		errore = true;
		message += "- Inserire la marca dell'autovettura.\r\n";
	}
	if(modello == "") {
		errore = true;
		message += "- Inserire il modello dell'autovettura.\r\n";
	}
	if(paese_immatr == "") {
		errore = true;
		message += "- Selezionare il paese in cui l'autovettura č stata immatricolata.\r\n";
	}
	if(dtimm_yy == "") {
		errore = true;
		message += "- Selezionare l'anno in cui l'autovettura č stata costruita.\r\n";
	}
	if(targa == "") {
		errore = true;
		message += "- Inserire la targa dell'autovettura.\r\n";
	}
	if(kw == "") {
		errore = true;
		message += "- Inserire la potenza dell'autovettura.\r\n";
	}
	if(cc == "") {
		errore = true;
		message += "- Inserire la cilindrata dell'autovettura.\r\n";
	}
	if(nome == "") {
		errore = true;
		message += "- Inserire il tuo nome.\r\n";
	}
	if(cognome == "") {
		errore = true;
		message += "- Inserire il tuo cognome.\r\n";
	}
	if(!controllo_data(dtnascita)) {
		errore = true;
		message += "- Inserire una data di nascita valida.\r\n";
	}
	if(nazionalita == "") {
		errore = true;
		message += "- Selezionare la nazionalitā.\r\n";
	}
	if(indirizzo == "") {
		errore = true;
		message += "- Inserire l'indirizzo.\r\n";
	}
	if(indirizzo == "") {
		errore = true;
		message += "- Inserire il cap.\r\n";
	}
	if(citta == "") {
		errore = true;
		message += "- Inserire la cittā.\r\n";
	}
	if(prov == "") {
		errore = true;
		message += "- Inserire la provincia.\r\n";
	}
	if(nazione == "") {
		errore = true;
		message += "- Selezionare la nazione di residenza.\r\n";
	}
	if(tel_fisso == "") {
		errore = true;
		message += "- Inserire il numero di telefono fisso.\r\n";
	}
	if(tel_mobile == "") {
		errore = true;
		message += "- Inserire il numero di telefono mobile.\r\n";
	}
	if (email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
		errore = true;
		message += "- Inserire un indirizzo email valido.\r\n";
	}
	
	if(errore) {
		alert(message);
		return false;
	}
		
	$('frmreg').submit();
}

function checkFormPassword() {
	var email = $('email') ? $F('email') : "";
	var lang = ($('lang')) ? $F('lang') : "it"; 
	
	if(email == "") {
		if(lang == "it") {
			alert("Inserisca nel campo sottostante l'indirizzo e-mail fornito in fase di registrazione. Riceverā un e-mail con la Sua password.");
		} else {
			alert("Please, fill in the field below with the registered e-mail address. You will receive an e-mail with your password.");
		}
		return;
	}
	
	if (email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
		if(lang == "it") {
			alert("Per poter ricevere la password č necessario inserire un indirizzo e-mail valido.");
		} else {
			alert("To get your password you must insert a valid e-mail address.");
		}
		return;
	}
	
	$('frmpswd').submit();
}

function controllo_data(stringa) {
	var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	if (!espressione.test(stringa)) {
		return false;
	}else {
		anno = parseInt(stringa.substr(6),10);
		mese = parseInt(stringa.substr(3, 2),10);
		giorno = parseInt(stringa.substr(0, 2),10);
		
		var data=new Date(anno, mese-1, giorno);
		if(data.getFullYear()==anno && data.getMonth()+1==mese && data.getDate()==giorno) {
			return true;
		} else {
			return false;
		}
	}
}

function login() {
	var user = ($('user')) ? $F('user') : "";
	var pswd = ($('pswd')) ? $F('pswd') : "";
	
	var message = "Per accedere all'area riservata č necessario inserire i propri dati di accesso";
	
	if(user == "" || pswd == "") {
		alert(message);
		return;
	}
	
	$('frmlogin').submit();
}

function loginENG() {
	var user = ($('user')) ? $F('user') : "";
	var pswd = ($('pswd')) ? $F('pswd') : "";
	
	var message = "To have access to the reserved area please insert your login data.";
	
	if(user == "" || pswd == "") {
		alert(message);
		return;
	}
	
	$('frmlogin').submit();
}