var myimages=new Array()
function preloadimages(){
	for (i=0;i<preloadimages.arguments.length;i++){
		myimages[i]=new Image()
		myimages[i].src=preloadimages.arguments[i]
	}
}

//Enter path of images to be preloaded inside parenthesis. Extend list as desired.
preloadimages('/images/puls_acc.jpg', '/images/puls_spe.jpg');


function agg_footer() {
	a="<img src='/images/oriz2.gif' />";
	liv=document.getElementById('mission').innerHTML=a;
}

function acc_puls(id) {
	document.getElementById(id).style.backgroundImage="url('/images/puls_acc.jpg')";
}

function spe_puls(id) {
	document.getElementById(id).style.backgroundImage="url('/images/puls_spe.jpg')";
}

function spe_puls_ara(id) {
	document.getElementById(id).style.backgroundImage="url('/images/puls_accedi.jpg')";
}

function aggiorna_pagina(cosa, valore, ricerca) {
	if(ricerca=="rapida" || ricerca=="avanzata") {	
		if(cosa=="marca") {
			campo="modello";
			modificatore="/ajax/marca.php";		
			invio_par="marca="+valore;	
		}
		
		if(cosa=="regione") {
			campo="provincia";
			modificatore="/ajax/regione.php";		
			invio_par="regione="+valore;	
		}
	}
	
	if(ricerca=="inserimento") {
		if(cosa=="marca") {
			campo="nuovo_modello";
			modificatore="/ajax/tutti_modelli.php";
			invio_par="marca="+valore;
		}
		
		if(cosa=="regione") {
			campo="provincia";
			modificatore="/ajax/tutte_province.php";
			invio_par="regione="+valore;
		}
	}
	
	var request=new Ajax.Updater(campo, modificatore, { 
		method: "get",
		parameters: invio_par,
		onComplete: $(campo).selectedIndex=0
		});
	
}

function ordina(ricerca) {
	var mio_link = document.location.pathname;
	var valore = document.form_ordina.ordinamento.value;
	mio_link = mio_link + "?ordinamento=" + valore + "&ricerca=" + ricerca;
	document.location.replace(mio_link);
} 

function visibilita(livello) {
	if(livello == "reg_rivenditori") {
		 document.getElementById('reg_privati').style.visibility = "hidden";
		 document.getElementById('reg_rivenditori').style.display = "block";
	}
	if(livello == "reg_privati") {
		 document.getElementById('reg_rivenditori').style.visibility = "hidden";
		 document.getElementById('reg_rivenditori').style.display = "none";
	}
	document.getElementById(livello).style.visibility = "visible"; 
}

function allunga() {
	document.getElementById('content').style.height = 1100 + 'px';
	
}

// Funzione per la convalida delle form per la registrazione

function convalida(la_form) {
	
  	errori = 0;
	sbagli = new Array();
	
	if(la_form == "privato") {
    mio_form = document.reg_privati;
	
    // Password
	
	password = mio_form.password.value;
	if(password != "") {
		lun_pass = password.length;
		if(lun_pass < 6) {
			alert("Attenzione: la password deve contenere almeno 6 caratteri !");
			errori++;
		}
	}
	else {
		alert("Attenzione il campo 'Password' è obbligatorio");
		errori++;
	}
	
	password_rip = mio_form.password2.value;
	if(password_rip != "") {
		if(password_rip != password) {
			alert("Attenzione: la 'Password ripetuta' non corrisponde alla 'password'");
			errori++;
		}
	}
	else {
		alert("Attenzione: il campo 'Password ripetuta è obbligatorio !")
		errori++;
	}

	
	//nome
	
	nome = mio_form.nome.value;
	if(nome != "") {
	lun_nome = mio_form.nome.value.length;
	count = 0;
	for(i=0; i<lun_nome; i++) {
		lettera = nome.charAt(i);
		if(!isNaN(lettera)) { if(lettera != " ") { count++; } }
	}
	if(count > 0) {
		
	sbagli[1] = "Nome";
	errori++; }
	}
	else { alert("Attenzione: il campo nome è obbligatorio !");
	errori++;
	
	}
	
	//cognome
	
		cognome = mio_form.cognome.value;
		if(cognome != "") {
	lun_cognome = mio_form.cognome.value.length;
	count = 0;
	for(i=0; i<lun_cognome; i++) {
		lettera = cognome.charAt(i);
		if(!isNaN(lettera)) { if(lettera != " ") { count++; } }
	}
		if(count > 0) {
			
	sbagli[2] = "Cognome";
	errori++;
	}
}
else { alert("Attenzione: il campo cognome è obbligatorio !");
        errori++;
		
		}

    //via
	
	
	//cap
	
	cap = mio_form.cap.value;
	if(cap != "") {
	lun_cap = mio_form.cap.value.length;
	count = 0;
	for(i=0; i<lun_cap; i++) {
		lettera = cap.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
	if(count > 0 || lun_cap != 5) {
		errori = errori + 1;
		
		sbagli[3] = "Cap";
	
	}
	}
	
	
	//città
	
		citta = mio_form.citta.value;
		if(citta != "") {
	lun_citta = mio_form.citta.value.length;
	count = 0;
	for(i=0; i<lun_citta; i++) {
		lettera = citta.charAt(i);
		if(!isNaN(lettera) && lettera != " ") { count++; }
	}
		if(count > 0) {
	
	sbagli[4] = "Città";
	errori = errori + 1;  }
	
	}
	else { alert("Attenzione: il campo città è obbligatorio !");
	errori = errori + 1;
	
	}
	
	
	//prefisso Telefono
	
	telefono = mio_form.prefisso_fisso.value;
	if(telefono != "") {
	lun_telefono = mio_form.prefisso_fisso.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if((count > 0)||(lun_telefono > 5)) {
				
	sbagli[5] = "Prefisso telefonico";
	errori = errori + 1;   }
	}
	
	
	//telefono
	
			telefono = mio_form.numero_fisso.value;
			if(telefono != "") {
	lun_telefono = mio_form.numero_fisso.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if(count > 0) {
	
	sbagli[6] = "Numero telefonico";
	errori = errori + 1;   }
	}
	
		//prefisso Telefono2
	
	telefono = mio_form.prefisso_fisso2.value;
	if(telefono != "") {
	lun_telefono = mio_form.prefisso_fisso2.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if((count > 0)||(lun_telefono > 5)) {
				
	sbagli[9] = "Prefisso telefonico 2";
	errori = errori + 1;   }
	}
	
	
	//telefono2
	
			telefono = mio_form.numero_fisso2.value;
			if(telefono != "") {
	lun_telefono = mio_form.numero_fisso2.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if(count > 0) {
	
	sbagli[10] = "Numero telefonico 2";
	errori = errori + 1;   }
	}
	
		//prefisso Fax
	
	telefono = mio_form.prefisso_fax.value;
	if(telefono != "") {
	var lun_telefono = mio_form.prefisso_fax.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if((count > 0)||(lun_telefono > 5)) {
				
	sbagli[11] = "Prefisso telefonico";
	errori = errori + 1;   }
	}
	
	
	// Fax
	
			telefono = mio_form.numero_fax.value;
			if(telefono != "") {
	lun_telefono = mio_form.numero_fax.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if(count > 0) {
	
	sbagli[12] = "Numero telefonico";
	errori = errori + 1;   }
	}
	
	//prefisso Cellulare
	
	telefono = mio_form.prefisso_cell.value;
	if(telefono != "") {
	lun_telefono = mio_form.prefisso_cell.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if((count > 0)||(lun_telefono > 5)) {
				
	sbagli[5] = "Prefisso cellulare";
	errori = errori + 1;   }
	}
	
	//cellulare	
	
				mobile = mio_form.numero_cell.value;
				if(mobile != "") {
	lun_mobile = mio_form.numero_cell.value.length;
	count = 0;
	for(i=0; i<lun_mobile; i++) {
		lettera = mobile.charAt(i);
		if(isNaN(lettera)) { count++;}
	}
				if(count > 0) {
					
	sbagli[7] = "Numero cellulare";
	errori = errori + 1;   }
	}
	//mail
	
				mail = mio_form.email.value;
				if(mail != "") {
	lun_mail = mio_form.email.value.length;
	chiocciole = 0;
	punti = 0;
		for(i=0; i<lun_mail; i++) {
		lettera = mail.charAt(i);
		if(lettera == "@") { chiocciole = chiocciole + 1; }
		if(lettera == ".") { punti = punti + 1;  }
		}
		
		if(punti < 1 || chiocciole != 1) { errori = errori + 1; 
		
		sbagli[8] = "Email"; }
		
	}
	else { errori++;   alert("Attenzione, il campo mail è obbligatorio !");
	
	}

	//password
	
	
	
	if(mio_form.assenso.checked == false) { alert("Prestare consenso al trattamento dei dati personali !");  errori++; }
	
	if(errori > 0) {
		if(sbagli.length != null && sbagli.length != 0) {
		stringa = "Ci sono errori nei seguenti campi: ";
		
		numero_sbagli = sbagli.length;
		 
		for(i=1; i<13;i++) {
			if(sbagli[i]) {
				if(i != (numero_sbagli-1)) {
		    stringa = stringa + sbagli[i] + ", "; }
			else { stringa = stringa + sbagli[i] + "."; }
			}
		
		}
		alert(stringa);
	}
	}
	else { 
		
		new Ajax.Request('/ajax/cerca_email.php', {
						 method: 'get',
						 parameters: {email: mio_form.email.value },
						 onComplete: function(transport){
							 resp = transport.responseText || "no response text";
							 if(resp==1) {
								alert("Esiste già un utente registrato con questa casella email. \n\r Non è possibile effettuare un'altra registrazione con la stessa email"); 
							 } 
							 if(resp==0) {
								invia_reg('privati'); 
							 }
							 
						 }
					});
		
	
	}
}	
	
	// Registrazione rivenditori _____________________________________________________________
	
	if(la_form == "rivenditore") {
	mio_form = document.reg_rivenditori;
		//nome
	
		rag_sociale = mio_form.ragione_sociale.value;
	if(rag_sociale == "") {
	alert("Attenzione: il campo 'Ragione Sociale' è obbligatorio!");
	errori++;
	}	
	
		password = mio_form.password.value;
	if(password != "") {
		lun_pass = password.length;
		if(lun_pass < 6) {
			alert("Attenzione: la password deve contenere almeno 6 caratteri !");
			errori++;
		}
	}
	else {
		alert("Attenzione il campo 'Password' è obbligatorio");
		errori++;
	}
	
	password_rip = mio_form.password2.value;
	if(password_rip != "") {
		if(password_rip != password) {
			alert("Attenzione: la 'Password ripetuta' non corrisponde alla 'password'");
			errori++;
		}
	}
	else {
		alert("Attenzione: il campo 'Password ripetuta è obbligatorio !")
		errori++;
	}
	
	
	
	
	nome = mio_form.nome.value;
	if(nome != "") {
	lun_nome = mio_form.nome.value.length;
	count = 0;
	for(i=0; i<lun_nome; i++) {
		lettera = nome.charAt(i);
		if(!isNaN(lettera)) { if(lettera != " ") { count++; }}
	}
	if(count > 0) {
		
	sbagli[1] = "Nome";
	errori++; }
	}

	
	//cognome
	
		cognome = mio_form.cognome.value;
		if(cognome != "") {
	lun_cognome = mio_form.cognome.value.length;
	count = 0;
	for(i=0; i<lun_cognome; i++) {
		lettera = cognome.charAt(i);
		if(!isNaN(lettera)) { if(lettera != " ") { count++; }}
	}
		if(count > 0) {
			
	sbagli[2] = "Cognome";
	errori++;
	}
}


    //via
	
	
	//cap
	
		cap = mio_form.cap.value;
	if(cap != "") {
	lun_cap = mio_form.cap.value.length;
	count = 0;
	for(i=0; i<lun_cap; i++) {
		lettera = cap.charAt(i);
		if(isNaN(lettera)) {  count++; }
	}
	if(count > 0 || lun_cap != 5) {
		errori = errori + 1;
		
		sbagli[3] = "Cap";
		
	}
	}

	
	//città
	
			citta = mio_form.citta.value;
			if(citta != "") {
	lun_citta = mio_form.citta.value.length;
	count = 0;
	for(i=0; i<lun_citta; i++) {
		lettera = citta.charAt(i);
		if(!isNaN(lettera) && lettera != " ") { count++; }
	}
		if(count > 0) {
			
	sbagli[4] = "Città";
	errori = errori + 1;  }
	
	}
	else { alert("Attenzione: il campo città è obbligatorio !");
	errori = errori + 1;
	
	}
	
	
	//prefisso Telefono
	
	telefono = mio_form.prefisso_fisso.value;
	if(telefono != "") {
	lun_telefono = mio_form.prefisso_fisso.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if((count > 0)||(lun_telefono > 5)) {
				
	sbagli[5] = "Prefisso telefonico";
	errori = errori + 1;   }
	}
	
	
	//telefono
	
			telefono = mio_form.numero_fisso.value;
			if(telefono != "") {
	lun_telefono = mio_form.numero_fisso.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if(count > 0) {
				
	sbagli[6] = "Numero telefonico";
	errori = errori + 1;   }
	}
	
			//prefisso Telefono2
	
	telefono = mio_form.prefisso_fisso2.value;
	if(telefono != "") {
	var lun_telefono = mio_form.prefisso_fisso2.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if((count > 0)||(lun_telefono > 5)) {
				
	sbagli[9] = "Prefisso telefonico 2";
	errori = errori + 1;   }
	}
	
	
	//telefono2
	
			telefono = mio_form.numero_fisso2.value;
			if(telefono != "") {
	lun_telefono = mio_form.numero_fisso2.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if(count > 0) {
	
	sbagli[10] = "Numero telefonico 2";
	errori = errori + 1;   }
	}
	
		//prefisso Fax
	
	telefono = mio_form.prefisso_fax.value;
	if(telefono != "") {
	lun_telefono = mio_form.prefisso_fax.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if((count > 0)||(lun_telefono > 5)) {
				
	sbagli[11] = "Prefisso telefonico";
	errori = errori + 1;   }
	}
	
	
	// Fax
	
			telefono = mio_form.numero_fax.value;
			if(telefono != "") {
	lun_telefono = mio_form.numero_fax.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if(count > 0) {
	
	sbagli[12] = "Numero telefonico";
	errori = errori + 1;   }
	}
	
		//prefisso Cellulare
	
	telefono = mio_form.prefisso_cell.value;
	if(telefono != "") {
	lun_telefono = mio_form.prefisso_cell.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if((count > 0)||(lun_telefono > 5)) {
				
	sbagli[5] = "Prefisso cellulare";
	errori = errori + 1;   }
	}
	
	//cellulare	
	
				mobile = mio_form.numero_cell.value;
				if(mobile != "") {
	lun_mobile = mio_form.numero_cell.value.length;
	count = 0;
	for(i=0; i<lun_mobile; i++) {
		lettera = mobile.charAt(i);
		if(isNaN(lettera)) { count++;}
	}
				if(count > 0) {
					
	sbagli[7] = "Numero cellulare";
	errori = errori + 1;   }
	}
	//mail
	
				mail = mio_form.email.value;
				if(mail != "") {
	lun_mail = mio_form.email.value.length;
	chiocciole = 0;
	punti = 0;
		for(i=0; i<lun_mail; i++) {
		lettera = mail.charAt(i);
		if(lettera == "@") { chiocciole = chiocciole + 1; }
		if(lettera == ".") { punti = punti + 1; }
		}
		if(punti < 1 || chiocciole != 1) { 
		errori = errori + 1;
		sbagli[8] = "Email"; }
		
		
	}
	else { errori++;   alert("Attenzione, il campo mail è obbligatorio !");
	
	}

	//password
	
	
	
	if(mio_form.assenso.checked == false) { alert("Prestare consenso al trattamento dei dati personali !"); errori++; }
	
	if(errori > 0) {
		if(sbagli.length != null && sbagli.length != 0) {
		stringa = "Ci sono errori nei seguenti campi: ";
		
		numero_sbagli = sbagli.length;
		 
		for(i=1; i<13;i++) {
			if(sbagli[i]) {
				if(i != (numero_sbagli-1)) {
		    stringa = stringa + sbagli[i] + ", "; }
			else { stringa = stringa + sbagli[i] + "."; }
			}
		
		}
		alert(stringa);
	}
	}
	
	else { 
	new Ajax.Request('/ajax/cerca_email.php', {
						 method: 'get',
						 parameters: {email: mio_form.email.value },
						 onComplete: function(transport){
							 resp = transport.responseText || "no response text";
							 if(resp==1) {
								alert("Esiste già un utente registrato con questa casella email. \n\r Non è possibile effettuare un'altra registrazione con la stessa email"); 
							 } 
							 if(resp==0) {
								invia_reg('rivenditori'); 
							 }
							 
						 }
					});
	
	}
}
	
if(la_form == "ins_annuncio") {
   mio_form = document.ins_annuncio;
   vuoti = 0;
   errori = 0;
   sbagli = 0;
   if(mio_form.marca.value == "") {
	   vuoti++;
	   errori++;
   }
   if(mio_form.modello.value == "") {
	   vuoti++;
	   errori++;
   }
	if(mio_form.provincia.value == "") {
		vuoti++;
		errori++;
	}
   var telefono = mio_form.cilindrata.value;
			if(telefono != "") {
	lun_telefono = mio_form.cilindrata.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if(count > 0) {
				
	sbagli++;
	errori = errori + 1;   }
	}
	   telefono = mio_form.kw.value;
			if(telefono != "") {
	lun_telefono = mio_form.kw.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if(count > 0) {
				
	sbagli++;
	errori = errori + 1;   }
	}
	
telefono = mio_form.cv.value;
			if(telefono != "") {
	lun_telefono = mio_form.cv.value.length;
	count = 0;
	for(i=0; i<lun_telefono; i++) {
		lettera = telefono.charAt(i);
		if(isNaN(lettera)) { count++; }
	}
			if(count > 0) {
				
	sbagli++;
	errori = errori + 1;   }
	}
	if(errori > 0) {
	    if(vuoti > 0 && sbagli == 0) { var msg1 = "Ci sono uno o più campi obbligatori rimasti vuoti."; }
		if(vuoti == 0 && sbagli > 0) { var msg1 = "Ci sono errori in campi che richiedono solo valori numerici."; }
		if(vuoti > 0 && sbagli >0 ) { var msg1 = "Cisono alcuni errori e campi obbligatori rimasti vuoti."; }
		alert(msg1);
	}
	else { mio_form.submit(); }
}
	
}

function invia_reg(tipo) {
	if(tipo=="privati") {
		document.reg_privati.submit();
	} else {
		document.reg_rivenditori.submit();
	}
}

function sel_eventi() {
	aa=document.cerca_eventi;
	bb=aa.getElementsByTagName('select');
	campi=0;
	for(i=0; i<bb.length; i++) {
		if(bb.item(i).value=="") {
			campi++;	
		}
	}
	if(campi>0) {
		alert("Alcuni campi sono rimasti vuoti");	
	} else {
		aa.submit();	
	}
}

function full_optional(valore) {
  
	if(valore == "full" && document.ins_annuncio.nuovo_full.checked == true) {
		document.ins_annuncio.nuovo_clima.checked = true;
		document.ins_annuncio.nuovo_abs.checked = true;
		document.ins_annuncio.nuovo_antifurto.checked = true;
		document.ins_annuncio.nuovo_sterzo.checked = true;
		document.ins_annuncio.nuovo_airbag.checked = true;
		
		document.ins_annuncio.nuovo_intpelle.checked = true;
		document.ins_annuncio.nuovo_tetto_ap.checked = true;
		
		document.ins_annuncio.nuovo_fendinebbia.checked = true;
		document.ins_annuncio.nuovo_radio.checked = true;
	
	}
	
	if(valore == "nofull" && document.ins_annuncio.nuovo_full.checked == true) {
		document.ins_annuncio.nuovo_full.checked = false;
	}

}

function colora(colore) {
	document.ins_annuncio.nuovo_colore.value= colore;
}

function controlla_annuncio() {
	
	mio_form = document.ins_annuncio;
	vuoti = 0;
	errori = 0;
	numero = 0;

	if(mio_form.usura.value == "") {
		vuoti++;
		errori++;
	}
	
	if(mio_form.nuova_categoria.value == "") {
		vuoti++;
		errori++;
	}
	if(mio_form.nuova_marca.value == "") {
		vuoti++;
		errori++;
	}
	if(mio_form.nuovo_modello.value == "") {
		vuoti++;
		errori++;
	}
	
	if(mio_form.nuovo_prezzo.value == "") {
		vuoti++;
		errori++;	
	}
	
	if(mio_form.nuova_cilindrata.value != "" && isNaN(mio_form.nuova_cilindrata.value) == true) {
		numero++;
		errori++;
	}
	if(mio_form.cavalli.value != "" && isNaN(mio_form.cavalli.value) == true) {
		numero++;
		errori++;
	}
	if(mio_form.kw.value != "" && isNaN(mio_form.kw.value) == true) {
		numero++;
		errori++;
	}
	if(mio_form.nuove_porte.value != "" && isNaN(mio_form.nuove_porte.value) == true) {
		numero++;
		errori++;
	}
	if(mio_form.nuovi_km.value != "" && isNaN(mio_form.nuovi_km.value) == true) {
		numero++;
		errori++;
	}
	/*
	if(mio_form.nuovo_prezzo.value != "" && isNaN(mio_form.nuovo_prezzo.value) == true) {
		numero++;
		errori++;
	} */
	if(mio_form.nuovo_prezzo.value!="") {
		myreg=new RegExp("^[0-9]+$");
		res=myreg.test(mio_form.nuovo_prezzo.value);
		if(!res) {
			numero++;
			errori++;
		}
	} else {
		errori++;
		vuoti++;
	}
	if(errori>0) {
		if(vuoti>0 && numero == 0) {
			alert("Attenzione! Alcuni campi obbligatori sono rimasti vuoti.");
		}
		if(vuoti == 0 && numero>0) {
			alert("Ci sono degli errori su alcuni campi che ammettono solo valori numerici.");
		}
		if(vuoti>0 && numero>0) {
			alert("Sono presenti alcuni errori, verificare i campi obbligatori e quelli solo numerici.");
		}
	} else {
		mio_form.submit();
	}
}

function cancella_utente(utente) {
	if(confirm("Confermando l'utente selezionato e tutti i suoi annunci \n\rsaranno definitivamente eliminati")) {
		pag=document.location.pathname;
		pag=pag+"?elimina_utente="+utente;
	}
	document.location.href=pag;
}

function verifica_mail(obg, laform, campo) {
	if(obg=="") {
		alert("Riempire il campo relativo al "+campo);	
	} else {
		laform.submit();	
	}
}

function vedi_dati(div) {
	document.getElementById(div).style.visibility='visible';	
}

function nascondi_dati(div) {
	document.getElementById(div).style.visibility='hidden';
}

function contatta(auto) {
pagina="contatta_inserzionista.php?vettura="+auto;

window.open(pagina, 'fin_contact', 'width=430, height=350, top=260, left=350, resizable=no, menubar=no, toolbar=no, location=no, scrollbars=no, status=no');
	
}

function richiedi_banner() {
	a=document.prenota;
	if(a.posizione.value=="" || a.banner.value=="") {
		alert("Si prega di riempire entrambi i campi");	
	} else {
		a.submit();	
	}
}

function ctl_cliente() {
	a=document.prenota_banner;
	errori=0;
	obblighi=0;
	
	if(a.cognome.value=="") {
		errori++;
		obblighi++;
	} else {
		myreg=new RegExp("^[a-zA-Z ']+$");
		res=myreg.test(a.cognome.value);
		if(!res) {
			alert("Il campo COGNOME e' errato");
			errori++;
		}
	}
	
	if(a.nome.value=="") {
		errori++;
		obblighi++;
	} else {
		myreg=new RegExp("^[a-zA-Z ']+$");
		res=myreg.test(a.nome.value);
		if(!res) {
			alert("Il campo NOME e' errato");
			errori++;
		}
	}
	if(a.via.value=="") {
		errori++;
		obblighi++;
	}
	if(a.cap.value=="") {
		errori++;
		obblighi++;
	} else {
		myreg=new RegExp("^[0-9]+$");
		res=myreg.test(a.cap.value);
		if(!res || a.cap.value.length!=5) {
			errori++;
			alert("Il campo CAP e' errato");
		}
	}
	if(a.provincia.value=="") {
		errori++;
		obblighi++;
	}
	if(a.citta.value=="") {
		errori++;
		obblighi++;
	} else {
		myreg=new RegExp("^[a-zA-Z ']+$");
		res=myreg.test(a.citta.value);
		if(!res) {
			errori++;
			alert("Il campo CITTA' e' errato");
		}
	}
	
	if(a.cf.value!="") {
		myreg=new RegExp("^([a-zA-Z'])+([a-zA-Z'])+([a-zA-Z'])+([a-zA-Z'])+([a-zA-Z'])+([a-zA-Z'])+([0-9])+([0-9])+([a-zA-Z'])+([0-9])+([0-9])+([a-zA-Z'])+([0-9])+([0-9])+([0-9])+([a-zA-Z'])+$");
		res=myreg.test(a.cf.value);
		if(!res) {
			errori++;
			alert("Il campo CODICE FISCALE e' errato");
		}
	}
	
	if(a.pi.value!="") {
		myreg=new RegExp("^[0-9]+$");
		res=myreg.test(a.pi.value);
		if (!res || a.pi.value.length!=11) {
			errori++;
			alert("Il campo PARTITA IVA e' errato");
		}
	}
	
	if(a.email.value=="") {
		errori++;
		obblighi++;
	} else {
		myreg=new RegExp("^([a-zA-Z0-9\._-])+@([a-zA-Z0-9])+\.([a-zA-Z0-9])+$");
		res=myreg.test(a.email.value);
		if(!res) {
			errori++;
			alert("Il campo EMAIL e' errato");
		}
	}
	
	if(errori>0) {
		if(obblighi>0) {
			alert("Uno o piu' campi obbligatori sono rimasti vuoti");
			
		}
	} else {
		a.submit();	
	}
	
}

/**
 * SWFObject v1.4.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, xiRedirectUrl, redirectUrl, detectKey){
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', useExpressInstall);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "PlugIn"); }
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "ActiveX"); }
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else{
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // throws if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	if (window.opera || !document.all) return;
	var objects = document.getElementsByTagName("OBJECT");
	for (var i=0; i < objects.length; i++) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// fixes bug in fp9 see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
deconcept.SWFObjectUtil.prepUnload = function() {
	__flash_unloadHandler = function(){};
	__flash_savedUnloadHandler = function(){};
	if (typeof window.onunload == 'function') {
		var oldUnload = window.onunload;
		window.onunload = function() {
			deconcept.SWFObjectUtil.cleanupSWFs();
			oldUnload();
		}
	} else {
		window.onunload = deconcept.SWFObjectUtil.cleanupSWFs;
	}
}
if (typeof window.onbeforeunload == 'function') {
	var oldBeforeUnload = window.onbeforeunload;
	window.onbeforeunload = function() {
		deconcept.SWFObjectUtil.prepUnload();
		oldBeforeUnload();
	}
} else {
	window.onbeforeunload = deconcept.SWFObjectUtil.prepUnload;
}
/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;
