function showHide(idform) {
	//alert('formdiv'+idform);
	//alert(document.getElementById('formdiv'+idform).style.display);
	if (document.getElementById('formdiv'+idform).style.display=="block"){
		document.getElementById('formdiv'+idform).style.display="none";
	}else{
		document.getElementById('formdiv'+idform).style.display="block";
	}
}

function caricaPosizione(){
    if (document.getElementById("rif") != undefined)
	{
		document.fForm.offerta.value = document.getElementById("rif").innerHTML;
	}
	else
	{
		document.fForm.offerta.value = document.getElementById("posizione").firstChild.nodeValue;
	}
}

function sendCv() {
//xmlhttpPost('fForm', '/skyIt/CandidaturaUploadServlet', 'lavora_spalladx');
        nome=document.fForm.nome.value;
        cognome=document.fForm.cognome.value;
        mail=document.fForm.email.value;
        cv=document.fForm.file.value;
        radio=get_radio_value();
        if(nome==null || trim(nome)==""){
        	document.getElementById("labelNome").style.color="red";
                alert("Il campo Nome e' obbligatorio");
				document.fForm.nome.focus();
                return;
        }
        else
                document.getElementById("labelNome").style.color="black";

        if(cognome==null || trim(cognome)==""){
        	document.getElementById("labelCognome").style.color="red";
                alert("Il campo Cognome e' obbligatorio");
				document.fForm.cognome.focus();
                return;
        }
        else
                document.getElementById("labelCognome").style.color="black";

        if(mail==null || trim(mail)==""){
        	document.getElementById("labelMail").style.color="red";
                alert("Il campo Email e' obbligatorio");
				document.fForm.email.focus();
                return;
        }
        else if(!isEmail(mail)){
                document.getElementById("labelMail").style.color="red";
                alert("Inserire email corretta");
				document.fForm.email.focus();
                return;
        }
        else
                document.getElementById("labelMail").style.color="black";
       
        if(cv==null || cv==""){
                alert("Allegare il proprio curriculum");
				document.fForm.file.focus();
                return;
        }else if(cv.lastIndexOf(".pdf")==-1 && cv.lastIndexOf(".doc")==-1){
               alert("Il formato del curriculum deve essere doc o pdf");
			   document.fForm.file.focus();
                return;
        }

        if(radio!='accetto'){
            alert('Autorizzare il trattamento dei dati sensibili');
            return;
        }
        document.fForm.submit(); 
}


function trim(stringa)
{
	while (stringa.substring(0,1) == ' ')
	{
		stringa = stringa.substring(1, stringa.length);
	}
	while (stringa.substring(stringa.length-1, stringa.length) == ' ')
	{
		stringa = stringa.substring(0,stringa.length-1);
	}
	return stringa;
}

function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
		return 1;
	else
		return 0;
}



function get_radio_value()
{
for (var i=0; i < document.fForm.privacy.length; i++)
   {
   if (document.fForm.privacy[i].checked)
      {
      var rad_val = document.fForm.privacy[i].value;
      return rad_val;
      }
   }
}

