/*
caso diretto

var ajaxObj = new ClassAJAX();
ajaxObj.setExecute(true) ;
ajaxObj.setLoading(false) ; //falso oppure stringa
ajaxObj.setElement(divname) ;
ajaxObj.runAJAX('./ajax/tck.php?&action=visualizzaDettaglio&TCK_ID='+idTestata) ;	
	
	
caso in cui ho bisogno di lavorare l'output ritornato dallo script
var ajaxObj = new ClassAJAX();
//ajaxObj.setMethod("POST") ;
ajaxObj.setExecute(false) ;
ajaxObj.setReturn(true) ;
ajaxObj.runAJAX('./ajax/tck.php?&action=salvaDettaglioEvento&XTCKD08='+idTestata+_url) ;

var html = "" ;
var htmlOld = "" ;

myInterval = window.setInterval(
function() { 
	
	htmlOld = html ;
	html = ajaxObj.getHtml() ;
	
	if (html != false) {
		
		if (htmlOld == html) {
			
			window.clearInterval(myInterval);
			if (html=="ok") {
				alert("tutto a posto") ;
			} else {
				alert("errore") ;
			}
			
		}
	} 
} 
,100) ;
	
*/


function modifica(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="";
		}else{
		document.getElementById(fO).style.display="none";
		}
	}
	
	if(ie4){
		if (document.all[fO].style.display=="none") {
		document.all[fO].style.display="";
		}else{
		document.all[fO].style.display="none";
		}
	}	
}




function aprorisultato(div,risultato,valore){

	
	var elem = document.getElementById(div) ;
	elem.style.display = '' ;
	elem.innerHTML = '' ;
	
	var ajaxObj = new ClassAJAX();
	ajaxObj.setExecute(true) ;
	ajaxObj.setLoading(false) ; //falso oppure stringa
	ajaxObj.setElement(div) ;
	ajaxObj.runAJAX('./ajax/ajax.php?action=filtro&ris='+risultato+'&sez='+valore) ;	
	
	}


function apriPopupCalendario(webpath,campo) {
	
	w = 150;
	h = 180;
	l = (screen.width - w) / 2;
	t = (screen.height - h) / 2;
	
	wnd = window.open(webpath + "popupCalendario.php?campo=" + campo,"wnd","fullscreen=0,channelmode=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no, resizable=no, width="+w+", height="+h+", left="+l+", top="+t);
	wnd.focus();
}

function riporta_data(data,campo,periodo_week,data_end){
	alert(pippo);
	xx = data.split("-");
	aaaa	= xx[2] ;
	mm	= xx[1] ;
	gg	= xx[0] ;
	if(mm.length<2){mm = "0" + mm;}
	if(gg.length<2){gg = "0" + gg;}
	data_ok = gg + "-" + mm + "-" + aaaa ;
	data_post = aaaa + mm + gg ; 
	
	
	var campoDT = campo + "_d_text" ;
	var campoD = campo + "_d" ;
	
	var campoMT = campo + "_m_text" ;
	var campoM = campo + "_m" ;
	
	var campoYT = campo + "_y_text" ;
	var campoY = campo + "_y" ;
	
	try {
		var dadove = eval ("opener.document.form."+campoDT+".name") ;
		var daDoveVengo = "default" ;		
	}catch (e) {
		var daDoveVengo = "ajax" ;
	}
	
	if (daDoveVengo == "default") {	
		eval ("opener.document.form."+campoDT+".value='"+gg+"'") ;
		eval ("opener.document.form."+campoD+".value='"+gg+"'") ;
		
		eval ("opener.document.form."+campoMT+".value='"+mm+"'") ;
		eval ("opener.document.form."+campoM+".value='"+mm+"'") ;
		
		eval ("opener.document.form."+campoYT+".value='"+aaaa+"'") ;
		eval ("opener.document.form."+campoY+".value='"+aaaa+"'") ;
		
		eval ("opener.document.form."+campo+".value='"+data_post+"'") ;
	}else {
		
		eval ("opener.document.formListino."+campoDT+".value='"+gg+"'") ;
		eval ("opener.document.formListino."+campoD+".value='"+gg+"'") ;
		
		eval ("opener.document.formListino."+campoMT+".value='"+mm+"'") ;
		eval ("opener.document.formListino."+campoM+".value='"+mm+"'") ;
		
		eval ("opener.document.formListino."+campoYT+".value='"+aaaa+"'") ;
		eval ("opener.document.formListino."+campoY+".value='"+aaaa+"'") ;
		
		eval ("opener.document.formListino."+campo+".value='"+data_post+"'") ;
	}
	
	self.close() ;

}

function submitForm(formName, idOut, msg) {
	
	var the_form = document.getElementById(formName);
	var action = null;
	var ajaxObj = new ClassAJAX();
	ajaxObj.setMethod("POST") ;	
	ajaxObj.setExecute(false) ;
	ajaxObj.setReturn(true) ;
	
	switch (formName) {
		case 'formLogin': action = 'submitLogin'; break;
		
		
		default: action = 'submitForm';
	}
	 	
	 	
	ajaxObj.runAJAX('./ajax/ajax.php?action='+action+'&'+ajaxObj.getUrlParams(the_form)) ;
	
	var html = "" ;
	var htmlOld = "" ;
		
	myInterval = window.setInterval(
	function() { 
		
		htmlOld = html ;
		html = ajaxObj.getHtml() ;
		
		if (html != false) {
			
			if (htmlOld == html) {
				
				window.clearInterval(myInterval);
				if (html != "ok") {
					msg = html ;
				}
				
				eval("document."+formName+".reset();") ;
				
				switch (formName) {
					default :
					displayOutput(idOut, msg) ;
					break ; 
					
					case "formLogin": 
					displayOutputAndReload(idOut, msg) ;
					break;
				}			
			}
			
		} 
	} 
	,1);
	
	
}

function generoFigli(id, idOut) {
	
	var result = document.getElementById(idOut);
	var action = null;
	var ajaxObj = new ClassAJAX();
	ajaxObj.setMethod("GET") ;	
	ajaxObj.setExecute(false) ;
	ajaxObj.setReturn(true) ;
		 	
	ajaxObj.runAJAX('./ajax/ajax.php?action=printMenu&padre='+id+'') ;
	
	var html = "" ;
	var htmlOld = "" ;	
	
	
	myInterval = window.setInterval(
	function() { 
		
		htmlOld = html ;
		html = ajaxObj.getHtml() ;
		
		if (html != false) {
			
			if (htmlOld == html) {
				
				window.clearInterval(myInterval);
				
				result.style.display="" ;
				result.innerHTML = html ;
						
			}
			
		} 
	} 
	,1);
	
	
}






function forceLogout(idOut, msg) {
	
	var action = null;
	var ajaxObj = new ClassAJAX();
	
	ajaxObj.setMethod("POST") ;	
	ajaxObj.setExecute(false) ;
	ajaxObj.setReturn(true) ;
	 	
	ajaxObj.runAJAX('./ajax/ajax.php?action=submitLogout') ;
	
	var html = "" ;
	var htmlOld = "" ;
		
	myInterval = window.setInterval(
	function() { 
		
		htmlOld = html ;
		html = ajaxObj.getHtml() ;
		
		if (html != false) {
			
			if (htmlOld == html) {
				
				window.clearInterval(myInterval);
				if (html != "ok") {
					msg = html ;
				}
				
				displayOutputAndReload(idOut, msg) ;
						
			}
			
		} 
	} 
	,1);
}




function displayOutput(idOut, msg) {

	var elem = document.getElementById(idOut) ;
	elem.style.display="" ;
	elem.innerHTML = msg ;
	
	setTimeout(function(){
		elem.style.display="none" ;
	}, 1000);
	
}

function displayOutputMenu(idOut) {

	var elem = document.getElementById(idOut) ;
	elem.style.display="" ;
	elem.innerHTML = msg ;
	
	setTimeout(function(){
		elem.style.display="none" ;
	}, 1000);
	
}



function displayOutputAndReload(idOut, msg) {

	var elem = document.getElementById(idOut) ;
	elem.style.display="" ;
	elem.innerHTML = msg ;
	
	setTimeout(function(){
		elem.style.display="none" ;
		location.reload();
	}, 1000);
	
}


