function popup_partenze(id, lang)
{
    pagina= "popup_partenze.php?id=" + id + "&lang=" + lang;
    var w = 660;
    var h = 200;
    var l = Math.floor((screen.width-w)/2);
    var t = Math.floor((screen.height-h)/2);
    window.open(pagina,"dati","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",scrollbars=yes");
}

function check_user_login()
{
	if (document.getElementById('user').value == "")
	{
		alert('Inserire la username');
		document.getElementById('user').focus();
		return;
	}
	if (document.getElementById('psw').value == "")
	{
		alert('Inserire la password');
		document.getElementById('psw').focus();
		return;
	}
    document.getElementById('login').submit();
}

function upload_popup()
{
    pagina = 'user_upload_foto.php?open';
    var w = 820;
    var h = 680;
    var l = Math.floor((screen.width-w)/2);
    var t = Math.floor((screen.height-h)/2);
    window.open(pagina,"MacedoniaAdventures","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",scrollbars=yes");
}

function submit_registrazione(modifica)
{
	if (document.getElementById('cognome').value == "")
	{
		alert('Indicare il proprio cognome');
		document.getElementById('cognome').focus();
		return;
	}

	if (document.getElementById('nome').value == "")
	{
		alert('Indicare il proprio nome');
		document.getElementById('nome').focus();
		return;
	}

	if (document.getElementById('data').value == "")
	{
		alert('Indicare la propria data di nascita');
		document.getElementById('data').focus();
		return;
	}

	if (document.getElementById('nato_a').value == "")
	{
		alert('Indicare il proprio luogo di nascita');
		document.getElementById('nato_a').focus();
		return;
	}

	if (document.getElementById('email').value == "")
	{
		alert('Indicare il proprio indirizzo email');
		document.getElementById('email').focus();
		return;
	}

    if (!check_email(document.getElementById('email').value))
	{
		alert('Indirizzo email non valido');
		document.getElementById('email').focus();
		return;
	}

	if (document.getElementById('telefono').value == "")
	{
		alert('Indicare un recapito telefonico.');
		document.getElementById('telefono').focus();
		return;
	}

    if (!check_intero(document.getElementById('telefono').value))
	{
		alert('Recapito telefonico non valido. Non inserire separatori tra prefisso e numero\n(Ad esempio: 3331234567 o 0612345678)');
		document.getElementById('telefono').focus();
		return;
	}

    if (!modifica)
    {
    	if (document.getElementById('username').value == "")
    	{
    		alert('Specificare una username');
    		document.getElementById('username').focus();
    		return;
    	}

        string = document.getElementById('username').value;

        a = string.split(" ");
        if (a.length > 1)
    	{
    		alert('La username non puņ contenere spazi');
    		document.getElementById('username').focus();
    		return;
    	}

    	if (string.length < 5)
    	{
    		alert('La username deve contenere almeno 5 caratteri');
    		document.getElementById('username').focus();
    		return;
    	}
    }

    if (modifica)
    {
        if ((document.getElementById('vecchia_password').value != "") ||
            (document.getElementById('password').value != "") ||
            (document.getElementById('ripeti_password').value != ""))
        {
            if (document.getElementById('vecchia_password').value == "")
        	{
        		alert('Per modificare la password devi inserire la password attuale');
        		document.getElementById('vecchia_password').focus();
        		return;
        	}

            if (document.getElementById('password').value == "")
        	{
        		alert('Devi inserire la nuova password');
        		document.getElementById('password').focus();
        		return;
        	}

            string = document.getElementById('password').value;
        	if (string.length < 6)
        	{
        		alert('La nuova password deve contenere almeno 6 caratteri');
        		document.getElementById('password').focus();
        		return;
        	}

        	if (document.getElementById('ripeti_password').value != document.getElementById('password').value)
        	{
        		alert('Il campo "Ripeti password" non coincide con il campo "Nuova Password".');
        		document.getElementById('ripeti_password').focus();
        		return;
        	}
        }
    }
    else
    {
        if (document.getElementById('password').value == "")
    	{
    		alert('Specificare una password');
    		document.getElementById('password').focus();
    		return;
    	}

        string = document.getElementById('password').value;
    	if (string.length < 6)
    	{
    		alert('La password deve contenere almeno 6 caratteri');
    		document.getElementById('password').focus();
    		return;
    	}

    	if (document.getElementById('ripeti_password').value != document.getElementById('password').value)
    	{
    		alert('Devi ripetere la stessa password.');
    		document.getElementById('ripeti_password').focus();
    		return;
    	}

    	if (document.getElementById('privacy_no').checked)
    	{
    		alert('Devi accettare l\'informativa sul trattamento dei dati');
    		return;
    	}
    }

    document.getElementById('form_registrazione').submit();
}

function submit_recupero_pwd()
{
	if (document.getElementById('username').value == "")
	{
		alert('Indicare la propria username');
		document.getElementById('username').focus();
		return;
	}

	if (document.getElementById('email').value == "")
	{
		alert('Indicare la propria casella email');
		document.getElementById('email').focus();
		return;
	}

    document.getElementById('form_recupero_pwd').submit();
}

function submit_invio_preventivo()
{
	if (document.getElementById('email').value == "")
	{
		alert('Indicare la propria casella email');
		document.getElementById('email').focus();
		return;
	}

    if (!check_email(document.getElementById('email').value))
	{
		alert('Indirizzo email non valido');
		document.getElementById('email').focus();
		return;
	}

    document.getElementById('step').value = 2;
    document.form_prenota_2.submit();
}

function submit_prenotazione(modifica)
{
	if (document.getElementById('cognome').value == "")
	{
		alert('Indicare il proprio cognome');
		document.getElementById('cognome').focus();
		return;
	}

	if (document.getElementById('nome').value == "")
	{
		alert('Indicare il proprio nome');
		document.getElementById('nome').focus();
		return;
	}

	if (document.getElementById('data').value == "")
	{
		alert('Indicare la propria data di nascita');
		document.getElementById('data').focus();
		return;
	}

	if (document.getElementById('nato_a').value == "")
	{
		alert('Indicare il proprio luogo di nascita');
		document.getElementById('nato_a').focus();
		return;
	}

	if (document.getElementById('email').value == "")
	{
		alert('Indicare il proprio indirizzo email');
		document.getElementById('email').focus();
		return;
	}

    if (!check_email(document.getElementById('email').value))
	{
		alert('Indirizzo email non valido');
		document.getElementById('email').focus();
		return;
	}

	if (document.getElementById('telefono').value == "")
	{
		alert('Indicare un recapito telefonico.');
		document.getElementById('telefono').focus();
		return;
	}

    if (!check_intero(document.getElementById('telefono').value))
	{
		alert('Recapito telefonico non valido. Non inserire separatori tra prefisso e numero\n(Ad esempio: 3331234567 o 0612345678)');
		document.getElementById('telefono').focus();
		return;
	}

	if (document.getElementById('cod_fiscale').value == "")
	{
		alert('Devi compilare il campo CODICE FISCALE');
		document.getElementById('cod_fiscale').focus();
		return;
	}
	else
	{
		str= document.getElementById('cod_fiscale').value;
		if (str.length != 16)
		{
			alert('CODICE FISCALE non valido');
			document.getElementById('cod_fiscale').focus();
			return;
		}
	}

	if (!document.getElementById('pagamento_acconto').checked && !document.getElementById('pagamento_saldo').checked)
	{
		alert('Indicare il tipo di pagamento.');
    	document.getElementById('pagamento_acconto').focus();
		return;
	}

	if (!document.getElementById('mezzo').checked)
	{
		alert('Indicare il mezzo di pagamento.');
    	document.getElementById('mezzo').focus();
		return;
	}

	if (!(document.getElementById('accetto_1_si').checked) ||
        !(document.getElementById('accetto_2_si').checked) ||
        !(document.getElementById('accetto_3_si').checked))
	{
		alert('Devi accettare tutte le opzioni per prenotare.');
    	document.getElementById('accetto_1_si').focus();
		return;
	}

    document.getElementById('form_prenotazione').submit();
}

function submit_link()
{
    if (document.form_link.titolo_ita.value == "")
    {
        alert('ATTENZIONE: Inserire il titolo del link.');
        document.form_link.titolo_ita.focus();
        return;
    }

    if (document.getElementById('id_categoria').value == 0)
    {
        alert('ATTENZIONE: Selezionare la categoria.');
        document.getElementById('id_categoria').focus();
        return;
    }

    if (document.form_link.link.value == "")
    {
        alert('ATTENZIONE: Inserire il link.');
        document.form_link.link.focus();
        return;
    }
    // controllo che il link contenga http://
    str = document.form_link.link.value;
    if ((trim(str) != '') && (str.search("http://") != 0))
    {
        alert('ATTENZIONE: Errore nella composizione del link.\nIl link deve iniziare con "http://"');
        return;
    }

    document.form_link.submit();
}
