	var formatDateInput = "YYYYMMDD";
	
	function openWin(nomeFile, nomeFinestra, parametri, larghezza, altezza, barre, ridimensione, centrato) {
		
		option="toolbar=no,width=" + larghezza + ",height=" + altezza +",resizable=" + ridimensione + ",scrollbars=" + barre 	
		if (centrato=='yes') {
			LeftPosition = (screen.width) ? (screen.width-larghezza)/2 : 0;
			TopPosition = (screen.height) ? (screen.height-altezza)/2 : 0;
			option=option + ",top="+TopPosition+",left="+LeftPosition
		}
		wiN = window.open(nomeFile + parametri, nomeFinestra, option);
//		return window.open(nomeFile + parametri, nomeFinestra, option);
	}
	
	function openRisparmio() {
		openWin("./includes/ajaxFiles/ajaxCalcolaRisparmio.php", "CalcolaRisparmio", "", 400, 300, 'no', 'no', 'no');
	}
	
	function trim(strIn){
	    while (strIn.substring(0,1) == ' '){
	        strIn = strIn.substring(1, strIn.length);
	    }
	    while (strIn.substring(strIn.length-1, strIn.length) == ' '){
	        strIn = strIn.substring(0,strIn.length-1);
	    }
	    return strIn;
	}
    
    function movePosizione(direzione) {
        var el = document.frmHc.posizione;
        var idx = el.selectedIndex;
        
        if (idx==-1) {
            alert("Devi selezionare un elemento da spostare");
        } else {
            var nxidx = idx+( direzione? -1 : 1)
            if (nxidx<0) nxidx=el.length-1
            if (nxidx>=el.length) nxidx=0
            var oldVal = el[idx].value;
            var oldStyle = el[idx].style.backgroundColor;
            var oldText = el[idx].text;
            el[idx].value = el[nxidx].value;
            el[idx].text = el[nxidx].text;
            el[idx].style.backgroundColor  = el[nxidx].style.backgroundColor;
            el[nxidx].value = oldVal;
            el[nxidx].text = oldText;
            el[nxidx].style.backgroundColor = oldStyle;
            el.selectedIndex = nxidx;
        }
    }
    
	function controlla_codice(campo) {
		
		ret = false;
		if (campo != "") {
			if (campo.match(/^[a-zA-Z]{6}[0-9]{2}[a-zA-Z]{1}[0-9]{2}[a-zA-Z]{1}[0-9]{3}[a-zA-Z]{1}$/)) {
				ret = true;
			}
		} else {
			ret = true;
		}
		
		return ret;
		/*
	
		var caratteri= new Array (	"0","1","2","3","4","5","6","7","8","9",
									"a","b","c","d","e","f","g","h","i","j",
									"k","l","m","n","o","p","q","r","s","t",
									"u","v","w","x","y","z", 
									"A","B","C","D","E","F","G","H","I","J",
									"K","L","M","N","O","P","Q","R","S","T",
									"U","V","W","X","Y","Z");
		var pari= new Array (	0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,
								6,7,8,9,10,11,12,13,14,15,16,17,
								18,19,20,21,22,23,24,25);
		var dispari=new Array (	1,0,5,7,9,13,15,17,19,21,1,0,5,7,
								9,13,15,17,19,21,2,4,18,20,11,3,6,
								8,12,14,16,10,22,25,24,23);

		cod=campo;
		check=true;
		if (cod.length!=16) {
			check=false
		} else {
			lettere=cod.substr(0,6)+cod.substr(8,1)+cod.substr(11,1)+cod.substr(15);
			numeri=cod.substr(6,2)+cod.substr(9,2)+cod.substr(12,3);
			for (i=0;i<10;i++) { 
				if (lettere.charCodeAt(i)<97 || lettere.charCodeAt(i)>122) {
					check=false;
				}
			}
			for (i=0;i<8;i++) {
				if (numeri.charCodeAt(i)<48 || numeri.charCodeAt(i)>57){
					check=false;
				}
			}
		}
		//checksum del codice fiscale
		test=cod.substr(15,1);
		var somma=0
		for (i=0;i<16;i=i+2) { //dispari
			carattere=cod.substr(i,1)
			for (k=0;k<36;k++) {
				if (carattere==caratteri[k]) {
					somma=somma+dispari[k]
					break;
				}
			}
		}

		for (i=1;i<15;i=i+2) { //pari
			carattere=cod.substr(i,1)
			for (k=0;k<36;k++) {
				if (carattere==caratteri[k]) {
					somma=somma+pari[k]
					break
				}
			}
		}
		resto=somma % 26;
		var lettera=String.fromCharCode(97+resto);
		if (test != lettera) {
			check=false;
		}
			
		if (check==false) {
			return false;
		} else {
			return true;
		}
		*/
	}
    
	function controllaIVA(pi) {

//		if (!pi.match(/^[0-9]{11}$/)) return false;
		ret = false;
		if (pi.match(/^([0-9]{11})$/)) {
			ret = true;
		}
		return ret;
/*
		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))) return false;
*/
		return true;
	}

	function IsNumeric(str) {
		var controllo_punti = false;
		var notNumber = 0;
		for ( count=0; count < str.length; count++ ) {
			if ( str.charAt( count ) < '0' || str.charAt( count ) > '9' ) {
				// non e' un numero
				notNumber=1;
				break;
			}
		}
		
		if (notNumber==1 ) {
			return false;
		} else {
			return true;
		}
	}
	    
	function salva() {
		
        /**
        decidiamo noi quali sono obbligatori e quali no
        */
        objFrm = eval(formName);
        error = false;
        msgError = "";
        
		if (!$("#noProfs").attr("checked")) {
        	error = true;
        	msgError += "Sottoscrivere il fatto di non essere un professionista immobiliare.\n";
		}
        
		if (!$("#privacy").attr("checked")) {
        	error = true;
        	msgError += "Accettare l'informativa sulla privacy.\n";
		}
        
        nome = trim(objFrm.elements["nome"].value);
        if (nome == "") {
        	error = true;
        	msgError += "Il campo NOME e' obbligatorio.\n";
		}
		objFrm.elements["nome"].value = nome;
		
        cognome = trim(objFrm.elements["cognome"].value);
        if (cognome == "") {
        	error = true;
        	msgError += "Il campo COGNOME e' obbligatorio.\n";
		}
		objFrm.elements["cognome"].value = cognome;
        
        email = trim(objFrm.elements["email"].value);
        if (email == "") {
        	error = true;
        	msgError += "Il campo EMAIL e' obbligatorio.\n";
		}
		objFrm.elements["email"].value = email;
        
        /**
        * devo controllare la data di nascita
        */
        
		// data di nascita
        giornoNascita = parseFloat($("#daysDP").val());
        if (giornoNascita) {
	        if (giornoNascita < 10) {
        		giornoNascitaStr = "0"+giornoNascita.toString();
			} else {
				giornoNascitaStr = giornoNascita.toString();
			}
		} else {
			error = true;
			msgError += "Inserire correttamente il giorno di nascita.\n";
		}
		
        meseNascita = parseFloat($("#monthsDP").val());
        if (meseNascita) {
	        if (meseNascita < 10) {
        		meseNascitaStr = "0"+meseNascita.toString();
			} else {
				meseNascitaStr = meseNascita.toString();
			}
		} else {
			error = true;
			msgError += "Inserire correttamente il mese di nascita.\n";
		}
		
        annoNascita = parseFloat($("#yearsDP").val());
        if (!annoNascita) {
        	error = true;
			msgError += "Inserire correttamente l'anno di nascita.\n";
		}
		
		if (!error) {
		
	        today = new Date();
	        giornoOggi = today.getDate();
	        if (giornoOggi < 10) {
        		giornoOggiStr = "0"+giornoOggi.toString();
			} else {
				giornoOggiStr = giornoOggi.toString();
			}

	        meseOggi = today.getMonth()+1;
	        if (meseOggi < 10) {
        		meseOggiStr = "0"+meseOggi.toString();
			} else {
				meseOggiStr = meseOggi.toString();
			}

			annoOggiStr = today.getFullYear().toString();
			strOggi = annoOggiStr+meseOggiStr+giornoOggiStr;
			strAnnoNascita = (annoNascita+18).toString()+meseNascitaStr+giornoNascitaStr;
			if (strAnnoNascita > strOggi) {
				error = true;
				msgError += "Per registrarsi occorre essere maggiorenni.\n";
			}
		}
		
//        piva = trim(objFrm.elements["iva"].value);
//        objFrm.elements["iva"].value = piva;
		// pulisco il codice fiscale da cos eindesiderate
		$("#cod_fiscale").val($("#cod_fiscale").val().replace(/([^a-zA-Z0-9]+)/g, ''));
        cf = $("#cod_fiscale").val();
        idNazione = objFrm.elements["nazione_id"][objFrm.elements["nazione_id"].selectedIndex].value;
        // controllo l'italia
        if (idNazione == "78") {
			// sono in italia, per cui devo controllare cf e/o piva
			if (cf != "") {
				// se l'ho inserito allora controllo che sia guisto...
				if (!controlla_codice(cf)) {
					error = true;
        			msgError += "Inserire correttamente il proprio codice fiscale.\n";
				}
			}
		}

        indirizzo = trim(objFrm.elements["indirizzo"].value);
        if (indirizzo == "") {
        	error = true;
        	msgError += "Il campo INDIRIZZO e' obbligatorio.\n";
		}
		objFrm.elements["indirizzo"].value = indirizzo;
        
		nrCivico = trim(objFrm.elements["numero_civico"].value);
//        if (nrCivico == "") {
//        	error = true;
//        	msgError += "Inserire il proprio numero civico.\n";
//		}
		objFrm.elements["numero_civico"].value = nrCivico;
		
		cap = trim(objFrm.elements["cap"].value);
        if (!cap.match(/^([0-9]{5})$/)) {
        	error = true;
        	msgError += "Inserire il CAP.\n";
		}
		objFrm.elements["cap"].value = cap;
		
		citta = trim(objFrm.elements["citta"].value);
        if (citta == "") {
        	error = true;
        	msgError += "Inserire il comune/citt\u00E0 di residenza.\n";
		}
		objFrm.elements["citta"].value = citta;
		
		provincia = trim(objFrm.elements["provincia"].value);
        if (provincia == "") {
        	error = true;
        	msgError += "Inserire la propria provincia.\n";
		}
		objFrm.elements["provincia"].value = provincia;
		
		nazione = objFrm.elements["nazione_id"][objFrm.elements["nazione_id"].selectedIndex].value;
        if (nazione == "") {
        	error = true;
        	msgError += "Selezionare la propria nazione.\n";
		}
		
		// almeno un contatto telefonico
		elMainPrefix = trim(objFrm.elements["prefisso"].value);
		elMainPhone = trim(objFrm.elements["telefonoPrincipale"].value);
		if ((elMainPrefix == "") || (elMainPhone == "")) {
			error = true;
			msgError += "Immettere il proprio contatto telefonico principale.\n";
		}
		objFrm.elements["prefisso"].value = elMainPrefix;
		objFrm.elements["telefonoPrincipale"].value = elMainPhone;
		
		if ($("#prefissoSec").val() != "") {
			// ho messo qualcosa
			if (!parseInt($("#prefissoSec").val(), 10)) {
				error = true;
				msgError += "Inserire un corretto prefisso telefonico secondario.\n";
			}
		}
		if ($("#telefonoSec").val() != "") {
			// ho messo qualcosa
			if (!parseInt($("#telefonoSec").val())) {
				error = true;
				msgError += "Inserire un corretto numero telefonico secondario.\n";
			}
		}
		
		username = trim(objFrm.elements["username"].value);
        if (username.length < 8) {
            error = true;
            msgError += "Lo USERNAME deve essere lungo almeno 8 caratteri.\n";
        }
        objFrm.elements["username"].value = username;
        
		// infine la pwd
		pwd1 = objFrm.elements["password"].value;
		pwd2 = objFrm.elements["conferma_password"].value;
		
		if ((pwd1 == "")) {
			error = true;
			msgError += "Inserire la password.\n";
		} else if ((pwd1 != pwd2)) {
			error = true;
			msgError += "Le password inserite non coincidono.\n";
		}
		
        if (error) {
        	alert(msgError);
		} else {
			if (confirm("Confermi i dati immessi?")) {
	            document.frmHc.azione.value = "SALVA";
	            document.frmHc.submit();
			}
		}

    }

    
    function Candybox() {
		var istance;
		var container; 		//il contenitore di tutta la candybox
		var steps; 			//i blocchi contenenti gli step
		var skips; 			//pulsanti per passare allo step successivo
		var backs; 			//pulsanti per passare allo step precedente
		var skipsTo; 		//pulsanti per passare ad un tab specifico
		var histories;		//elementi dell'history
		
		this.init = function(id) {
			this.container = $(id);
			this.steps     = this.container.find('.step');
			this.skips     = this.container.find('.skipNext');
			this.backs     = this.container.find('.skipPrev');
			this.skipsTo   = this.container.find('.skipTo');
			this.histories = this.container.find('.stepHistory');
			
			/*
			 * jquery quando gestisce gli eventi fa puntare "this" all'elemento che ha lanciato l'evento,
			 * Se devo accedere a attributi e metodi della candybox stessa uso il riferimento "istance"
			 */
			istance = this;
			
			//nascondo tutti tranne il primo...
			this.steps.find('.stepContent').not(':first').hide();
			this.steps.filter(':first').addClass('current');
			this.histories.not(':first').hide();
			this.updateHistory(); //attivo il primo step...
			
			//ora attivo gli eventi...
			this.handleEvents();
		}
		
		this.handleEvents = function() {
			this.skips.click(this.nextStep);
			this.backs.click(this.prevStep);
			this.skipsTo.click(function() {
				var selettore = $(this).attr('href');
				istance.jumpToStep(selettore);
				return false;
			});
		}
		
		//metodo per passare allo step successivo...
		this.nextStep = function() {
			var corrente = istance.findCurrent();
			var prossimo = corrente.next();
			
			if (prossimo.length > 0) {	
				istance.crossFade(corrente, prossimo);
				istance.showHistoryStep(prossimo);
			}
			return false;
		}
		
		//metodo per passare allo step precedente...
		this.prevStep = function() {
			var corrente = istance.findCurrent();
			var precedente = corrente.prev();
			
			if (precedente.length > 0) {	
				istance.crossFade(corrente, precedente);
				istance.showHistoryStep(precedente);
			}
			return false;		
		}
		
		//metodo per saltare ad uno step in base all'id passato come selettore...
		this.jumpToStep = function(selettore) {
			var corrente = istance.findCurrent();
			var prossimo = $(selettore).not(':has(.stepContent:visible)');
			
			if (prossimo.length > 0) {
				istance.crossFade(corrente, prossimo);
				istance.showHistoryStep(prossimo);
			}
			return false;
		}
		
		//aggiunge la classe current all'elemento dell'history corrente...
		this.updateHistory = function() {
			var corrente = istance.findCurrent();
			var id_corrente = corrente.attr('id');
			var history = istance.getHistory(id_corrente);
			istance.histories.removeClass('current');
			history.addClass('current');
		}
		
		//mostra lo step dell'history relativo all'elemento passato come parametro
		this.showHistoryStep = function(elem) {
			var id_elem = elem.attr('id');
			var history = istance.getHistory(id_elem);
			history.show();
		}
		
		//restituisce l'elemento visible corrente
		this.findCurrent = function() {
			return this.steps.filter(':has(.stepContent:visible)');
		}
		
		//metodo per selezionare l'elemento dell'history in base all'id dello step...
		this.getHistory = function(id_step) {
			return $('#'+id_step+'_history');
		}
		
		//qui gestisco la transazione da un div all'altro...
		this.crossFade = function(from, to) {
			from.find('.stepContent').slideUp('fast');
			to.find('.stepContent').slideDown('fast', function() {
				//aggiorno l'history solo dopo aver completato l'animazione...
				istance.updateHistory();
			});
			from.removeClass('current').addClass('visited');
			to.removeClass('visited').addClass('current');
		}
	}
	
	function helpCF() {
	
		openWin('http://www.codicefiscale.com', 'CodiceFiscale', '', 800, 500, 'yes', 'yes', 'yes');
		return false;
		
	}
	
    //cancella un annuncio preferito    
    function cancellaPreferito(cod) {
        if(confirm("Sei sicuro di voler cancellare questo annuncio dai tuoi preferiti?")) {
            document.frmHc.azione.value = "elimina";
            document.frmHc.cod.value = cod;
            document.frmHc.submit();
            return true;
        } else {
            return false;
        }
    }
    
    function salvaBuyer() {
        
        /**
        decidiamo noi quali sono obbligatori e quali no
        */
        objFrm = eval(formName);
        error = false;
        msgError = "";
        
        if (!$("#privacy").attr("checked")) {
            error = true;
            msgError += "Accettare l'informativa sulla privacy.\n";
        }
        
        nome = trim(objFrm.elements["nome"].value);
        if (nome == "") {
            error = true;
            msgError += "Il campo NOME e' obbligatorio.\n";
        }
        objFrm.elements["nome"].value = nome;
        
        cognome = trim(objFrm.elements["cognome"].value);
        if (cognome == "") {
            error = true;
            msgError += "Il campo COGNOME e' obbligatorio.\n";
        }
        objFrm.elements["cognome"].value = cognome;
        
        email = trim(objFrm.elements["email"].value);
        if (email == "") {
            error = true;
            msgError += "Il campo EMAIL e' obbligatorio.\n";
        }
        objFrm.elements["email"].value = email;
        
        // almeno un contatto telefonico
        elMainPrefix = trim(objFrm.elements["prefisso"].value);
        elMainPhone = trim(objFrm.elements["telefonoPrincipale"].value);
        /*
		if ((elMainPrefix == "") || (elMainPhone == "")) {
            error = true;
            msgError += "Immettere il proprio contatto telefonico.\n";
        }
		*/
        objFrm.elements["prefisso"].value = elMainPrefix;
        objFrm.elements["telefonoPrincipale"].value = elMainPhone;
        
        if ((elMainPrefix == "") || (elMainPhone == "")) {
        	/**
        	uno dei due e vuoto...controllo l'altro
        	*/
        	if (elMainPrefix != "") {
        		error = true;
        		msgError += "Inserire anche il numero di telefono se si inserisce il prefisso\n";
			} else if (elMainPhone != "") {
        		error = true;
        		msgError += "Inserire anche il prefisso se si inserisce il numero di telefono\n";
			}
        } else {
            // ok, sn compilati entrambi
            // beh, allora li devi inserire corretti
            if ((!elMainPrefix.match(/^(\+)?[0-9]{2,5}$/)) || (!elMainPhone.match(/^[0-9]{4,}$/))) {
                error = true;
                msgError += "Il numero di telefono, se inserito, deve essere composto da soli numeri.\n";
            }
        }
        
        
        username = trim(objFrm.elements["username"].value);
        if (username.length < 8) {
            error = true;
            msgError += "Il campo USERNAME e' obbligatorio deve essere lungo almeno 8 caratteri.\n";
        }
        objFrm.elements["username"].value = username;
        
        // infine la pwd
        pwd1 = objFrm.elements["password"].value;
        pwd2 = objFrm.elements["conferma_password"].value;
        
        if ((pwd1 == "")) {
            error = true;
            msgError += "Inserire la password.\n";
        } else if ((pwd1 != pwd2)) {
            error = true;
            msgError += "Le password inserite non coincidono.\n";
        }
        
        if (error) {
            alert(msgError);
        } else {
            if (confirm("Confermi i dati immessi?")) {
                document.frmHc.azione.value = "SALVA";
                document.frmHc.submit();
            }
        }

    }
    
    function upgradeBuyer() {
        
        /**
        decidiamo noi quali sono obbligatori e quali no
        */
        objFrm = eval(formName);
        error = false;
        msgError = "";
        
        if (!$("#noProfs").attr("checked")) {
            error = true;
            msgError += "Sottoscrivere il fatto di non essere un professionista immobiliare.\n";
        }
        
        if (!$("#privacy").attr("checked")) {
            error = true;
            msgError += "Accettare l'informativa sulla privacy.\n";
        }
        
        nome = trim(objFrm.elements["nome"].value);
        if (nome == "") {
            error = true;
            msgError += "Il campo NOME e' obbligatorio.\n";
        }
        objFrm.elements["nome"].value = nome;
        
        cognome = trim(objFrm.elements["cognome"].value);
        if (cognome == "") {
            error = true;
            msgError += "Il campo COGNOME e' obbligatorio.\n";
        }
        objFrm.elements["cognome"].value = cognome;
        
        email = trim(objFrm.elements["email"].value);
        if (email == "") {
            error = true;
            msgError += "Il campo EMAIL e' obbligatorio.\n";
        }
        objFrm.elements["email"].value = email;
        
        /**
        * devo controllare la data di nascita
        */
        
        // data di nascita
        giornoNascita = parseFloat($("#daysDP").val());
        if (giornoNascita) {
            if (giornoNascita < 10) {
                giornoNascitaStr = "0"+giornoNascita.toString();
            } else {
                giornoNascitaStr = giornoNascita.toString();
            }
        } else {
            error = true;
            msgError += "Inserire correttamente il giorno di nascita.\n";
        }
        
        meseNascita = parseFloat($("#monthsDP").val());
        if (meseNascita) {
            if (meseNascita < 10) {
                meseNascitaStr = "0"+meseNascita.toString();
            } else {
                meseNascitaStr = meseNascita.toString();
            }
        } else {
            error = true;
            msgError += "Inserire correttamente il mese di nascita.\n";
        }
        
        annoNascita = parseFloat($("#yearsDP").val());
        if (!annoNascita) {
            error = true;
            msgError += "Inserire correttamente l'anno di nascita.\n";
        }
        
        if (!error) {
        
            today = new Date();
            giornoOggi = today.getDate();
            if (giornoOggi < 10) {
                giornoOggiStr = "0"+giornoOggi.toString();
            } else {
                giornoOggiStr = giornoOggi.toString();
            }

            meseOggi = today.getMonth()+1;
            if (meseOggi < 10) {
                meseOggiStr = "0"+meseOggi.toString();
            } else {
                meseOggiStr = meseOggi.toString();
            }

            annoOggiStr = today.getFullYear().toString();
            strOggi = annoOggiStr+meseOggiStr+giornoOggiStr;
            strAnnoNascita = (annoNascita+18).toString()+meseNascitaStr+giornoNascitaStr;
            if (strAnnoNascita > strOggi) {
                error = true;
                msgError += "Per registrarsi occorre essere maggiorenni.\n";
            }
        }
        
//        piva = trim(objFrm.elements["iva"].value);
//        objFrm.elements["iva"].value = piva;
        // pulisco il codice fiscale da cos eindesiderate
        $("#cod_fiscale").val($("#cod_fiscale").val().replace(/([^a-zA-Z0-9]+)/g, ''));
        cf = $("#cod_fiscale").val();
        idNazione = objFrm.elements["nazione_id"][objFrm.elements["nazione_id"].selectedIndex].value;
        // controllo l'italia
        if (idNazione == "78") {
            // sono in italia, per cui devo controllare cf e/o piva
            if (cf != "") {
                // se l'ho inserito allora controllo che sia guisto...
                if (!controlla_codice(cf)) {
                    error = true;
                    msgError += "Inserire correttamente il proprio codice fiscale.\n";
                }
            }
        }

        indirizzo = trim(objFrm.elements["indirizzo"].value);
        if (indirizzo == "") {
            error = true;
            msgError += "Il campo INDIRIZZO e' obbligatorio.\n";
        }
        objFrm.elements["indirizzo"].value = indirizzo;
        
        nrCivico = trim(objFrm.elements["numero_civico"].value);
//        if (nrCivico == "") {
//            error = true;
//            msgError += "Inserire il proprio numero civico.\n";
//        }
        objFrm.elements["numero_civico"].value = nrCivico;
        
        cap = trim(objFrm.elements["cap"].value);
        if (!cap.match(/^([0-9]{5})$/)) {
            error = true;
            msgError += "Inserire il CAP.\n";
        }
        objFrm.elements["cap"].value = cap;
        
        citta = trim(objFrm.elements["citta"].value);
        if (citta == "") {
            error = true;
            msgError += "Inserire il comune/citt\u00E0 di residenza.\n";
        }
        objFrm.elements["citta"].value = citta;
        
        provincia = trim(objFrm.elements["provincia"].value);
        if (provincia == "") {
            error = true;
            msgError += "Inserire la propria provincia.\n";
        }
        objFrm.elements["provincia"].value = provincia;
        
        nazione = objFrm.elements["nazione_id"][objFrm.elements["nazione_id"].selectedIndex].value;
        if (nazione == "") {
            error = true;
            msgError += "Selezionare la propria nazione.\n";
        }
        
        // almeno un contatto telefonico
        elMainPrefix = trim(objFrm.elements["prefisso"].value);
        elMainPhone = trim(objFrm.elements["telefonoPrincipale"].value);
        if ((elMainPrefix == "") || (elMainPhone == "")) {
            error = true;
            msgError += "Immettere il proprio contatto telefonico principale.\n";
        }
        objFrm.elements["prefisso"].value = elMainPrefix;
        objFrm.elements["telefonoPrincipale"].value = elMainPhone;
        
        if ($("#prefissoSec").val() != "") {
            // ho messo qualcosa
            if (!parseInt($("#prefissoSec").val(), 10)) {
                error = true;
                msgError += "Inserire un corretto prefisso telefonico secondario.\n";
            }
        }
        if ($("#telefonoSec").val() != "") {
            // ho messo qualcosa
            if (!parseInt($("#telefonoSec").val())) {
                error = true;
                msgError += "Inserire un corretto numero telefonico secondario.\n";
            }
        }
        
        
        if (error) {
            alert(msgError);
        } else {
            if (confirm("Confermi i dati immessi?")) {
                document.frmHc.azione.value = "UPGRADE";
                document.frmHc.submit();
            }
        }

    }
    
    function paginate(pagina) {
        
        var paginaNumber = 1;
        var paginaSize = 10;
        
        if($("#page").val() != "") {
            paginaNumber = $("#page").val();
        }
        
        if($("#selPageSize").val() != "") {
            paginaSize = $("#selPageSize").val();
        }
        
        if($("#page").val() != "") {
            document.location.href = pagina+"page="+paginaNumber+"&pageSize="+paginaSize;
            //$("#frmPaginate").submit(function() {alert('ok')});
        }
        return true;
    }
    
    function paginateSize(pagina) {
        
        var paginaNumber = 1;
        var paginaSize = 10;
        
        if($("#selPageSize").val() != "") {
            paginaSize = $("#selPageSize").val();
        }
        
        if($("#selPageSize").val() != "") {
            document.location.href = pagina+"page="+paginaNumber+"&pageSize="+paginaSize;
            //$("#frmPaginate").submit(function() {alert('ok')});
        }
        return true;
    }
    
    
    function cambiaStatoAnnuncio(cod) {
        if(confirm("Sei sicuro di voler modificare questo annuncio?")) {
            document.frmHc.azione.value = "stato";
            document.frmHc.codStato.value = cod;
            document.frmHc.submit();
        }
        return false;
    }
    
    function cambiaStatoSeller(cod) {
        if(confirm("Sei sicuro di voler modificare questo seller?")) {
            document.frmHc.azione.value = "stato";
            document.frmHc.codMod.value = cod;
            document.frmHc.submit();
        }
        return false;
    }
    
    function eliminaSeller(cod) {
        if(confirm("Sei sicuro di voler eliminare questo seller?")) {
            document.frmHc.azione.value = "elimina";
            document.frmHc.codMod.value = cod;
            document.frmHc.submit();
        }
        return false;
    }
    
    function cambiaStatoBuyer(cod) {
        if(confirm("Sei sicuro di voler modificare questo buyer?")) {
            document.frmHc.azione.value = "stato";
            document.frmHc.codMod.value = cod;
            document.frmHc.submit();
        }
        return false;
    }
    
    function eliminaBuyer(cod) {
        if(confirm("Sei sicuro di voler eliminare questo buyer?")) {
            document.frmHc.azione.value = "elimina";
            document.frmHc.codMod.value = cod;
            document.frmHc.submit();
        }
        return false;
    }
    
    function ricercaSeller() {
        if($("#txtRicerca").val() == "") {
           alert("Inserire un testo da ricercare");
        } else {
            document.frmHc.azione.value = "";
            document.frmHc.submit();
        }
        return false;
    }
    
    function ricercaAllSeller() {
        $("#txtRicerca").val() = "";
        document.frmHc.azione.value = "";
        document.frmHc.submit();
        return false;
    }
    
    function ricercaBuyer() {
        if($("#txtRicerca").val() == "") {
           alert("Inserire un testo da ricercare");
        } else {
            document.frmHc.azione.value = "";
            document.frmHc.submit();
        }
        return false;
    }
    
    function ricercaAllBuyer() {
        $("#txtRicerca").val("");
        document.frmHc.azione.value = "";
        document.frmHc.submit();
        return false;
    }
    
    function filtraAnnunci() {
        if($('input[name=radStatoAnnuncio]:checked').val() != "") {
            document.frmHc.submit();
        }
    }
    
    function eliminaAnnuncio(cod) {
        if(confirm("Sei sicuro di voler eliminare questo annuncio?")) {
            document.frmHc.azione.value = "elimina";
            document.frmHc.codStato.value = cod;
            document.frmHc.submit();
        }
        return false;
    }
    
    function cambiaSituazioneAnnuncio(annuncio,stato) {
        //if(confirm("Sei sicuro di voler cambiare lo stato del tuo annuncio?")) {
            document.frmHc.codAnnuncio.value = annuncio;
            document.frmHc.codStatoAnnuncio.value = stato;
            document.frmHc.azione.value = "situazione";
            document.frmHc.submit();
        //}
        return false;
    }
    
    function creaAdminSeller(cod) {
        if(confirm("Sei sicuro di voler promuovere questo seller ad admin?")) {
            document.frmHc.azione.value = "promuovi";
            document.frmHc.codMod.value = cod;
            document.frmHc.submit();
        }
        return false;
    }
    
    function ricercaOfferte() {
        /*
        if($("#txtRicerca").val() == "") {
           alert("Inserire un testo da ricercare");
        } else {
        */
            document.frmHc.azione.value = "";
            document.frmHc.submit();
        //}
        return false;
    }
    
    function ricercaAllOfferte() {
        $("#txtRicerca").val("");
        $("#selRicercaTipo").val("-1");
        document.frmHc.azione.value = "";
        document.frmHc.submit();
        return false;
    }
    
    
    function cambiaStatoGruppoPacchetti(cod) {
        if(confirm("Sei sicuro di voler modificare questa offerta?")) {
            document.frmHc.azione.value = "stato";
            document.frmHc.codMod.value = cod;
            document.frmHc.submit();
        }
        return false;
    }
    
    function eliminaGruppoPacchetti(cod) {
        if(confirm("Sei sicuro di voler eliminare questa offerta?")) {
            document.frmHc.azione.value = "elimina";
            document.frmHc.codMod.value = cod;
            document.frmHc.submit();
        }
        return false;
    }
    
    function apriUtentiOfferta(cod) {
        openWin("popupUtentiOfferte.php", "UtentiOfferta", "?cod="+cod, 600, 600, 'no', 'no', 'no');
        return false;
    }
    
    function apriUtentiAcquisti(cod) {
        openWin("popupUtentiAcquisti.php", "UtentiAcquisti", "?cod="+cod, 600, 600, 'no', 'no', 'no');
        return false;
    }