// controllo form

var whitespace = " \t\n\r";
function isEmail (s){
	if (isEmpty(s))
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@")){
		i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != ".")){
		i++
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
function isEmpty(s){
	return ((s == null) || (s.length == 0))
}
function isWhitespace (s){
	var i;
	if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}




//mostra nascondi campi
function show_hide_tipologia(passa_campo){

	if((passa_campo == "A building/real estate company") || (passa_campo == "A retailer")){
		document.getElementById("campo_azienda").style.display = "block";
		document.getElementById("campo_p_iva_cf").style.display = "block";
	}else{
		document.getElementById("campo_azienda").style.display = "none";
		document.getElementById("campo_p_iva_cf").style.display = "none";
	}

}




//mostra nascondi campi
function show_hide_tipologia_2(passa_campo){

	if(passa_campo == "Company"){
		document.getElementById("campo_azienda").style.display = "block";
		document.getElementById("campo_p_iva_cf").style.display = "block";
	}else{
		document.getElementById("campo_azienda").style.display = "none";
		document.getElementById("campo_p_iva_cf").style.display = "none";
	}

}




//definisce se il form contatti puo o meno partire
function send_contatti(link_pagina){
	
	c=document.getElementById("richiesta");
	if(c.value=="Select..."){
		alert("Select: type of request");
		c.focus();
		return;
	}
	
	c=document.getElementById("tipologia");
	if(c.value=="Select..."){
		alert("Select: I am...'");
		c.focus();
		return;
	}
	
	if(document.getElementById("campo_azienda").style.display=="block"){
		c=document.getElementById("azienda");
		if(c.value==""){
			alert("Company please");
			c.focus();
			return;
		}
	}
	
	if(document.getElementById("campo_p_iva_cf").style.display=="block"){
		c=document.getElementById("p_iva_cf");
		if(c.value==""){
			alert("Vat number please");
			c.focus();
			return;
		}
	}

	c=document.getElementById("nome");
	if(c.value==""){
		alert("Name please");
		c.focus();
		return;
	}

	c=document.getElementById("cognome");
	if(c.value==""){
		alert("Surname please");
		c.focus();
		return;
	}
	
	c=document.getElementById("indirizzo");
	if(c.value==""){
		alert("Address please");
		c.focus();
		return;
	}
	
	c=document.getElementById("cap");
	if(c.value==""){
		alert("Zip code please");
		c.focus();
		return;
	}
	
	c=document.getElementById("comune");
	if(c.value==""){
		alert("Town please");
		c.focus();
		return;
	}

	c=document.getElementById("provincia");
	if(c.value==""){
		alert("District please");
		c.focus();
		return;
	}
	
	c=document.getElementById("nazione");
	if(c.value==""){
		alert("Country please");
		c.focus();
		return;
	}
	
	c=document.getElementById("telefono");
	if(c.value==""){
		alert("Phone please");
		c.focus();
		return;
	}
	
	c=document.getElementById("email");
	if(c.value==""){
		alert("Email please");
		c.focus();
		return;
	}

	if (!isEmail(c.value)){
		alert("Email please");
		c.focus();
		return;
	}
	
	c=document.getElementById("messaggio");
	if(c.value==""){
		alert("Message please");
		c.focus();
		return;
	}
	
	c=document.getElementById("frm_agree");
	if (!c.checked){
		alert("Please read the privacy policy and check the box - I allow personal data processing -");
		c.focus();
		return;
	}
	
	c=document.getElementById("formDati");
	c.azione.value='send';
	c.action=link_pagina;
	c.submit();
}




//definisce se il form registrazione puo o meno partire
function send_registrazione(link_pagina){

	c=document.getElementById("nome");
	if(c.value==""){
		alert("Name please");
		c.focus();
		return;
	}

	c=document.getElementById("cognome");
	if(c.value==""){
		alert("Surname please");
		c.focus();
		return;
	}
	
	c=document.getElementById("indirizzo");
	if(c.value==""){
		alert("Address please");
		c.focus();
		return;
	}
	
	c=document.getElementById("cap");
	if(c.value==""){
		alert("Zip code please");
		c.focus();
		return;
	}
	
	c=document.getElementById("comune");
	if(c.value==""){
		alert("Town please");
		c.focus();
		return;
	}

	c=document.getElementById("provincia");
	if(c.value==""){
		alert("District please");
		c.focus();
		return;
	}

	c=document.getElementById("nazione");
	if(c.value==""){
		alert("Country please");
		c.focus();
		return;
	}
	
	c=document.getElementById("telefono");
	if(c.value==""){
		alert("Phone please");
		c.focus();
		return;
	}
	
	c=document.getElementById("email");
	if(c.value==""){
		alert("Email please");
		c.focus();
		return;
	}

	if (!isEmail(c.value)){
		alert("Email please");
		c.focus();
		return;
	}
	
	c=document.getElementById("frm_agree");
	if (!c.checked){
		alert("Please read the privacy policy and check the box - I allow personal data processing -");
		c.focus();
		return;
	}
	
	c=document.getElementById("formDati");
	c.azione.value='send';
	c.action=link_pagina;
	c.submit();
}






//definisce se il form cerca agente puo o meno partire
function send_cerca_agente(link_pagina){

	c=document.getElementById("nome");
	if(c.value==""){
		alert("Name please");
		c.focus();
		return;
	}

	c=document.getElementById("cognome");
	if(c.value==""){
		alert("Surname please");
		c.focus();
		return;
	}
	
	c=document.getElementById("telefono");
	if(c.value==""){
		alert("Phone please");
		c.focus();
		return;
	}
	
	c=document.getElementById("email");
	if(c.value==""){
		alert("Email please");
		c.focus();
		return;
	}

	if (!isEmail(c.value)){
		alert("Email please");
		c.focus();
		return;
	}
	
	c=document.getElementById("regione");
	if(c.value=="Select..."){
		alert("Selezionare una regione");
		c.focus();
		return;
	}
	
	c=document.getElementById("provincia");
	if(c.value=="Select..."){
		alert("Selezionare una provincia");
		c.focus();
		return;
	}
	
	c=document.getElementById("comune");
	if(c.value=="Select..."){
		alert("Selezionare un comune");
		c.focus();
		return;
	}
	
	c=document.getElementById("frm_agree");
	if (!c.checked){
		alert("Please read the privacy policy and check the box - I allow personal data processing -");
		c.focus();
		return;
	}
	
	c=document.getElementById("formDati");
	c.azione.value='send';
	c.action=link_pagina;
	c.submit();
}






//definisce se il form prenota agente puo o meno partire
function send_prenota_agente(link_pagina){

	c=document.getElementById("giorni");
	if(c.value==""){
		alert("Giorni preferiti please");
		c.focus();
		return;
	}

	c=document.getElementById("orario");
	if(c.value==""){
		alert("Orario preferito please");
		c.focus();
		return;
	}
	
	c=document.getElementById("messaggio");
	if(c.value==""){
		alert("Motivo del contatto please");
		c.focus();
		return;
	}
	
	c=document.getElementById("frm_agree");
	if (!c.checked){
		alert("Please read the privacy policy and check the box - I allow personal data processing -");
		c.focus();
		return;
	}
	
	c=document.getElementById("formDati");
	c.azione.value='send';
	c.action=link_pagina;
	c.submit();
}







//definisce se il form invia curriculum puo o meno partire
function send_curriculum_autocandidatura(link_pagina){

	c=document.getElementById("nome");
	if(c.value==""){
		alert("Name please");
		c.focus();
		return;
	}

	c=document.getElementById("cognome");
	if(c.value==""){
		alert("Surname please");
		c.focus();
		return;
	}
	
	c=document.getElementById("data_nascita");
	if(c.value==""){
		alert("Date of Birth please");
		c.focus();
		return;
	}
	
	c=document.getElementById("indirizzo");
	if(c.value==""){
		alert("Address please");
		c.focus();
		return;
	}
	
	c=document.getElementById("cap");
	if(c.value==""){
		alert("Zip code please");
		c.focus();
		return;
	}
	
	c=document.getElementById("comune");
	if(c.value==""){
		alert("Town please");
		c.focus();
		return;
	}

	c=document.getElementById("provincia");
	if(c.value==""){
		alert("District please");
		c.focus();
		return;
	}

	c=document.getElementById("nazione");
	if(c.value==""){
		alert("Country please");
		c.focus();
		return;
	}
	
	c=document.getElementById("telefono");
	if(c.value==""){
		alert("Phone please");
		c.focus();
		return;
	}
	
	c=document.getElementById("email");
	if(c.value==""){
		alert("Email please");
		c.focus();
		return;
	}

	if (!isEmail(c.value)){
		alert("Email please");
		c.focus();
		return;
	}
	
	c=document.getElementById("titolo_studio");
	if(c.value==""){
		alert("Study please");
		c.focus();
		return;
	}
	
	c=document.getElementById("ultima_occupazione");
	if(c.value==""){
		alert("Last employment please");
		c.focus();
		return;
	}
	
	c=document.getElementById("azienda_lavoro");
	if(c.value==""){
		alert("Company please");
		c.focus();
		return;
	}
	
	c=document.getElementById("mansione");
	if(c.value==""){
		alert("Tasks please");
		c.focus();
		return;
	}
	
	c=document.getElementById("motivo_interruzione");
	if(c.value==""){
		alert("Reason of leaving your last employment please");
		c.focus();
		return;
	}
	
	c=document.getElementById("allegato");
	if(c.value==""){
		alert("Attached please");
		c.focus();
		return;
	}
	
	c=document.getElementById("frm_agree");
	if (!c.checked){
		alert("Please read the privacy policy and check the box - I allow personal data processing -");
		c.focus();
		return;
	}
	
	c=document.getElementById("formDati");
	c.azione.value='send';
	c.action=link_pagina;
	c.submit();
}






//definisce se il form invia curriculum puo o meno partire
function send_curriculum_agenti(link_pagina){

	c=document.getElementById("nome");
	if(c.value==""){
		alert("Name please");
		c.focus();
		return;
	}

	c=document.getElementById("cognome");
	if(c.value==""){
		alert("Surname please");
		c.focus();
		return;
	}
	
	c=document.getElementById("data_nascita");
	if(c.value==""){
		alert("Date of Birth please");
		c.focus();
		return;
	}
	
	c=document.getElementById("indirizzo");
	if(c.value==""){
		alert("Address please");
		c.focus();
		return;
	}
	
	c=document.getElementById("cap");
	if(c.value==""){
		alert("Zip code please");
		c.focus();
		return;
	}
	
	c=document.getElementById("comune");
	if(c.value==""){
		alert("Town please");
		c.focus();
		return;
	}

	c=document.getElementById("provincia");
	if(c.value==""){
		alert("District please");
		c.focus();
		return;
	}

	c=document.getElementById("nazione");
	if(c.value==""){
		alert("Country please");
		c.focus();
		return;
	}
	
	c=document.getElementById("telefono");
	if(c.value==""){
		alert("Phone please");
		c.focus();
		return;
	}
	
	c=document.getElementById("email");
	if(c.value==""){
		alert("Email please");
		c.focus();
		return;
	}

	if (!isEmail(c.value)){
		alert("Email please");
		c.focus();
		return;
	}
	
	c=document.getElementById("zona_operativa");
	if(c.value==""){
		alert("Work area please");
		c.focus();
		return;
	}
	
	c=document.getElementById("prodotti_trattati_attualmente");
	if(c.value==""){
		alert("Products presently sold please");
		c.focus();
		return;
	}
	
	c=document.getElementById("numero_mandati_dichiarati");
	if(c.value==""){
		alert("No. of companies represented please");
		c.focus();
		return;
	}
	
	c=document.getElementById("aziende_mandatarie");
	if(c.value==""){
		alert("Name of companies represented please");
		c.focus();
		return;
	}
	
	c=document.getElementById("allegato");
	if(c.value==""){
		alert("Attached please");
		c.focus();
		return;
	}
	
	c=document.getElementById("frm_agree");
	if (!c.checked){
		alert("Please read the privacy policy and check the box - I allow personal data processing -");
		c.focus();
		return;
	}
	
	c=document.getElementById("formDati");
	c.azione.value='send';
	c.action=link_pagina;
	c.submit();
}
