function showFiglio (codice,imgName) {
			
	altro_el = document.getElementById(codice).style; 
	//spanName = document.getElementById(imgName).style;
	
	if(altro_el.display == "") {
		altro_el.display = "none" ;
		//spanName.backgroundImage = "url(img/pallino.gif)" ;
		spanName.backgroundRepeat = "no-repeat" ;
	}else {
		altro_el.display = "" ;
		//spanName.backgroundImage = "url(img/pallino.gif)" ;
		spanName.backgroundRepeat = "no-repeat" ;
	}
}

function toggleDisplay(fO){

var ns4 = (document.layers);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);


if(ie5 || ns6){
	if (document.getElementById(fO).style.display=="none") {
	document.getElementById(fO).style.display="inline";
	}else{
	document.getElementById(fO).style.display="none";
	}
}

if(ie4){
	if (document.all[fO].style.display=="none") {
	document.all[fO].style.display="inline";
	}else{
	document.all[fO].style.display="none";
	}
}	
}

function checkLogin () {
var ns4 = (document.layers);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById); 
	
	if (document.form.id_ruolo.selectedIndex == 0 || document.form.id_ruolo.selectedIndex == 1) {
	
		if(ie5 || ns6){	
			document.getElementById('divlogin').style.display="inline";
		}
		if(ie4){
			document.all['divlogin'].style.display="inline";	
		}
		
	} else {
		if(ie5 || ns6){	
			document.getElementById('divlogin').style.display="none";
		}
		if(ie4){
			document.all['divlogin'].style.display="none";	
		}	
		
		}
}

function apriPopupCandidato() {
	var ns4 = (document.layers);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById); 
	
	popup('popupcandidato.php',680,700,'yes') ;
			if(ie5 || ns6){	
			document.getElementById('divlogin').style.display="none";
		}
		if(ie4){
			document.all['divlogin'].style.display="none";	
		}	
}

function riportalocalita(id_regione,id_provincia,id_comune,regione,provincia,comune) {
	
	window.opener.document.form.id_regione.value=id_regione;
	window.opener.document.form.id_provincia.value=id_provincia;
	window.opener.document.form.id_comune.value=id_comune;
	window.opener.document.form.regione.value=regione;
	window.opener.document.form.provincia.value=provincia;
	window.opener.document.form.comune.value=comune;

self.close();
}

function riportacandidato(id_utente,cognome,id_ruolo,ruolo) {
	
	window.opener.document.form.id_utente.value=id_utente;
	window.opener.document.form.nome_utente.value=cognome;
  window.opener.document.form.ruolo.value=ruolo;
	window.opener.document.form.id_ruolo.value=id_ruolo;
	if (id_ruolo == 1 || id_ruolo == 2) {
		window.opener.document.getElementById('divlogin').style.display="inline";
	}
	
self.close();
}

function riportalocalitaNascita(id_regione,id_provincia,id_comune,regione,provincia,comune) {
	
	window.opener.document.form.id_regione_nascita.value=id_regione;
	window.opener.document.form.id_provincia_nascita.value=id_provincia;
	window.opener.document.form.id_comune_nascita.value=id_comune;
	window.opener.document.form.regione_nascita.value=regione;
	window.opener.document.form.provincia_nascita.value=provincia;
	window.opener.document.form.comune_nascita.value=comune;

self.close();
}

function riportalocalitaResidenza(id_regione,id_provincia,id_comune,regione,provincia,comune) {
	
	window.opener.document.form.id_regione_residenza.value=id_regione;
	window.opener.document.form.id_provincia_residenza.value=id_provincia;
	window.opener.document.form.id_comune_residenza.value=id_comune;
	window.opener.document.form.regione_residenza.value=regione;
	window.opener.document.form.provincia_residenza.value=provincia;
	window.opener.document.form.comune_residenza.value=comune;

self.close();
}

function riportalocalitaRif(id_regione,id_provincia,id_comune,regione,provincia,comune) {
	
	window.opener.document.form.id_regione_rif.value=id_regione;
	window.opener.document.form.id_provincia_rif.value=id_provincia;
	window.opener.document.form.id_comune_rif.value=id_comune;
	window.opener.document.form.regione_rif.value=regione;
	window.opener.document.form.provincia_rif.value=provincia;
	window.opener.document.form.comune_rif.value=comune;

self.close();
}

function riporta_data(data,campo){
 
 var dataincongruente = 0 ;
 
 Arr = data.split("-")
 
 datavisYYYY  = Arr[0] ; 
 datavisMM  = Arr[1] ; 
 datavisGG  = Arr[2] ; 
 
 if(datavisMM.length == 1) datavisMM = "0" + datavisMM ;
 if(datavisGG.length == 1) datavisGG = "0" + datavisGG ;

 datavis = datavisGG + "-" + datavisMM + "-" + datavisYYYY ;
 data = datavisYYYY + datavisMM + datavisGG ;


 if(campo == "stage_al") {
	
	if(window.opener.document.form.stage_dal.value > data ){
	 	alert ('data incongruente') ;
 		dataincongruente = 1 ;
 	} else {
		window.opener.document.form.stage_al.value=data ;
		window.opener.document.form.stage_al_vis.value=datavis ;
	}
}

 if(campo == "stage_dal") {
	window.opener.document.form.stage_dal.value=data ;
	window.opener.document.form.stage_dal_vis.value=datavis ;
}
 
  if(campo == "data_in") {
	window.opener.document.form.data_in.value=data ;
	window.opener.document.form.data_in_vis.value=datavis ;
}
 if(campo == "data_out") {
 	if(window.opener.document.form.data_in.value > data ){
 		alert ('data incongruente') ;
 		dataincongruente = 1 ;
 		} else {
		window.opener.document.form.data_out.value=data ;
		window.opener.document.form.data_out_vis.value=datavis ;
	}
}
if (dataincongruente == 0) { 
	self.close();	
}
}





/*******************************************/
function makeRequestEmail (url) {
		http_request = checkHttpRequest() ;

	  	http_request.onreadystatechange = alertContentsEmail ;
		http_request.open('GET', url, true);
		http_request.send(true);
}

	function alertContentsEmail() {
		
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				
				this.emailEsiste = http_request.responseText ;
				
				this.returnForm = checkFormPreventivo () ;
				
				document.getElementById('checkEmail').innerHTML = "" ; 	
			} else {
				alert('There was a problem with the request.');
			}
		} else {
			loadingEmail () ;	
		}
   }

	function loadingEmail () {
		var text =  "" ;
		text = "<span class=\"text\">Checking ...</span>" ;
		document.getElementById('checkEmail').innerHTML = "cheching ... " ; 	
	}

/*************************************/
function testaForm (){
this.returnForm = "" ;

makeRequestEmail ('../php/checkMail.php?tipoCheck=struttura&email='+document.form.email.value) ;


	if (this.returnForm == ""){
	checkReturnValue ()	;

	}
	 
	if (this.returnForm == 1) {
		return false ;	
		alert(this.returnForm); 	
	}
}

function checkReturnValue () { 
	if (this.returnForm == ""){
		checkReturnValue ();
	}else {
	alert('o');	
	}
}

function checkFormPreventivo() { 	
		var swKO = 0 ;
		var msg = "" ;
 
  
 		 
 		/*
 		if (this.emailEsiste == "undefined") {
 		msg += 'Indirizzo email gia presente.\n';
		swKO = 1 ;	
 		} 
 		*/
 
		// sezione valida email
		var x = document.form.email.value;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)) {
		//alert('YES! Correct email address');
		} else {
		msg += 'Indirizzo email inesatto.\n';
		swKO = 1 ;	
		} 

		// sezione campi obbligatori
		if (document.form.struttura.value == "" ) {
		msg += 'Manca il nome della struttura.\n';
		swKO = 1 ;
		}
		if (document.form.id_comune.value == "" && document.form.comune_estero.value == "") {
			msg += 'Manca la citta\'.\n';
			swKO = 1 ;
		}		 
		
		if (document.form.id_comune.value != "" && document.form.comune_estero.value != "") {
			msg += 'Hai immesso sia una citta\' italiana sia una estera.\n';
			swKO = 1 ;			
		}		
		
		if (document.form.email.value == "" ) {
		msg += 'Manca l\' email.\n';
		swKO = 1 ;
		} 
		if (document.form.via.value == "" ) {
		msg += 'Manca la via.\n';
		swKO = 1 ;
		}
		if (document.form.civico.value == "" ) {
		msg += 'Manca il civico.\n';
		swKO = 1 ;
		}
		if (document.form.cap.value == "" ) {
		msg += 'Manca il cap.\n';
		swKO = 1 ;
		}
		if (document.form.tel.value == "" ) {
		msg += 'Manca il telefono.\n';
		swKO = 1 ;
		}	
	
				 			
		if (swKO == 1) {
			this.returnForm = false ;
			alert(msg) ;
			return false ;	
		} else { 
			this.returnForm = true ;	
		} 
}


function checkFormRegistrati() { 	
		
		var swKO = 0 ;
		var msg = "" ;
 
		// sezione valida email
		var x = document.form.email.value;
		this.emailForm = x ;
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(x)) {
		//alert('YES! Correct email address');
		} else {
		msg += 'Indirizzo email inesatto.\n';
		swKO = 1 ;	
		} 

		// sezione campi obbligatori
		if (document.form.nome.value == "" ) {
		msg += 'Manca il nome.\n';
		swKO = 1 ;
		}
		if (document.form.cognome.value == "" ) {
		msg += 'Manca il cognome.\n';
		swKO = 1 ;
		}	
		if (document.form.email.value == "" ) {
		msg += 'Manca l\' email.\n';
		swKO = 1 ;
		} 
		if (document.form.tel.value == "" ) {
		msg += 'Manca il telefono.\n';
		swKO = 1 ;
		} 
		if (document.form.cell.value == "" ) {
		msg += 'Manca il cellullare.\n';
		swKO = 1 ;
		} 
		if (document.form.candidato_1.value == "" ) {
		msg += 'Manca il curriculum.\n';
		swKO = 1 ;
		}  
		if (document.form.candidato_2.value == "" ) {
		msg += 'Manca la foto tessera.\n';
		swKO = 1 ;
		} 
		if (document.form.candidato_3.value == "" ) {
		msg += 'Manca la foto intera.\n';
		swKO = 1 ;
		} 
		if (document.form.eta.value == "" ) {
		msg += 'Manca l\' eta.\n';
		swKO = 1 ;
		} 
		if (document.form.id_comune_nascita.value == "" && document.form.comune_nascita_estero.value == "") {
			msg += 'Manca la citta di nascita.\n';
			swKO = 1 ;
		}		 
		
		if (document.form.id_comune_nascita.value != "" && document.form.comune_nascita_estero.value != "") {
			msg += 'Hai immesso sia una citta\' di nascita italiana sia una estera.\n';
			swKO = 1 ;			
		}
		
		if (document.form.cittadinanza.value == "" ) {
		msg += 'Manca la cittadinanza.\n';
		swKO = 1 ;
		}				




		// morchia disponibilita
		var the_box1 = document.form.anim_tipo_anno_ultima_stagione[0].checked;
		var the_box2 = document.form.anim_tipo_anno_ultima_stagione[1].checked;
		var the_box3 = document.form.anim_tipo_anno_ultima_stagione[2].checked;
		var the_box4 = document.form.anim_tipo_anno_ultima_stagione[3].checked;
	
		var the_box5 = document.forms['form'].anim_ultima_stagione.options[0].selected ;
		var the_box6 = document.forms['form'].id_anim_ruolo.options[0].selected ;
		var the_box7 = document.forms['form'].anim_num_stagioni.options[0].selected ;

		if (the_box1 == false && the_box2 == false && the_box3 == false && the_box4 == false) {
			//alert('o');
		} 
		if (the_box5 == true && the_box6 == true && the_box7 == true ) {
			//alert('oo');
		}		
		
		if (the_box4 == false ) {

			if(the_box5 == true) {
				msg += 'Devi specificare anno ultima stagione.\n';
				swKO = 1 ;	
			}
			if(the_box6 == true) {
				msg += 'Devi specificare il ruolo dell\'ultima stagione.\n';
				swKO = 1 ;	
			}	
			if(document.form.anim_agenzia_citta.value == "") {
				msg += 'Devi specificare dove hai lavorato nell\'ultima stagione.\n';
				swKO = 1 ;
			}
			
			if(document.form.anim_agenzia.value == ""){
				msg += 'Devi specificare l\'agenzia dell\'ultima stagione.\n';
				swKO = 1 ;				
			}
			
		} 
		
		
		 
		//if(document.form.anim_agenzia_citta.value != "" &&  document.form.anim_tipo_anno_ultima_stagione.value != "" &&  document.form.anim_agenzia.value != "" && document.form.anim_sw_tutto_anno.value != "" && document.form.anim_al.value != "" && document.form.anim_dal.value != ""  ) {	
		/*if(document.form.anim_agenzia_citta.value == "" ||  document.form.anim_tipo_anno_ultima_stagione.value == "") {	
		msg += 'Seleziona almeno una disponibilita\'.\n';
		//alert('ooo');
		swKO = 1 ;
		}*/
		
				
		if (document.form.id_ruolo_proponi.selectedIndex  == 0 ) {
		msg += 'Manca ruolo con cui ti proponi.\n';
		swKO = 1 ;
		}	
		
	
		if (swKO == 1) {
			alert(msg) ;
			return false ;	
		}  else {
			//return true ;	
		}
		

		
}

function checkMail () {
	makeRequestIdSpan('php/checkMail.php?email='+this.emailForm,'boxDettaglio') ;
		
		alert (this.rispostaHtml ) ;
}

function popup(url_pagina,w,h,sw_scroll) {

	
	  /*w = 500;
	  h = 400;*/
	  l = (screen.width - w) / 2;
	  t = (screen.height - h) / 2;
	
	  wnd = window.open(url_pagina,"","fullscreen=0,channelmode=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+sw_scroll+", resizable=no, width="+w+", height="+h+", left="+l+", top="+t);
	  wnd.focus();		

}

function loginSubmit(){
	makeRequest('php/dologin.php?ajax=1&login='+document.form.login.value+'&passwd='+document.form.passwd.value) ;	
	
}
/*
	------------------------------------------------------------------
	HTTP_REQUEST
*/	



function makeRequest (url) {
		http_request = checkHttpRequest() ;

	  http_request.onreadystatechange = alertContents ;
		http_request.open('GET', url, true);
		http_request.send(true);
}

	function alertContents() {
		
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				changeHtml () ;
			} else {
				alert('There was a problem with the request.');
			}
		} else {
			loading () ;	
		}
   }

	function makeRequestIdSpan(url,idSpan) {
		
		this.idSpan = idSpan ;
		http_request = checkHttpRequest() ;

	  http_request.onreadystatechange = alertContentsProdLista ;
		http_request.open('GET', url, true);
		http_request.send(true);
			
	}	
	
	function alertContentsProdLista() {
		
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				changeHtml () ;
			} else {
				alert('There was a problem with the request.');
			}
		} else {
			loading () ;	
		}
   }
    
	function loading () {
		var text =  "" ;
		text = "<span class=\"text\">Loading ...</span>" ;
		eval('document.getElementById(\''+this.idSpan+'\').innerHTML = text ;') ; 	
	}

	
	function changeHtml() {
		this.rispostaHtml = http_request.responseText ;
		eval('document.getElementById(\''+this.idSpan+'\').innerHTML = http_request.responseText;') ;

	}
    	
    	
    function checkHttpRequest() {
		http_request = false;
		
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
			
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/xml');
				
			}
		} else if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		
		if (!http_request) {
		alert('Browser obsoleto.\n\nScarica un nuovo browser');
		return false;
		}
		
		return http_request ;
	}

