/*
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,area){
	
	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='+area) ;
	}

function aprorisultatoPaginaInt(div,area,i,padre,i_padre){
	
	var elem = document.getElementById(div) ;
	var elem2 = document.getElementById('overl') ;
	var elem3 = document.getElementById('chiusura') ;
	elem.style.display = '' ;
	elem2.style.display = '' ;
	elem3.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=risultatiContent&cod_pagina='+area+'&arr='+i+'&padre_id='+padre+'&id_padre='+i_padre) ;
	}


function aprorisultatoPagina(div,area,i){
	
	var elem = document.getElementById(div) ;
	var elem2 = document.getElementById('overl') ;
	var elem3 = document.getElementById('chiusura') ;
	elem.style.display = '' ;
	elem2.style.display = '' ;
	elem3.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=risultatiContent&cod_pagina='+area+'&arr='+i) ;
	}


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';
		break ;
	}
	 	
	ajaxObj.runAJAX('./ajax/ajax.php?form='+formName+'&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);
				
					msg = html ;
				    
				    switch (formName) {
					default :;
					displayOutput(idOut,formName, 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 generoFigliSx(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=printMenuSx&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,formName, msg) {
	var elem="";
	var esito="";
	
	elem = document.getElementById(idOut) ;
	elem.style.display="" ;
	elem.innerHTML = msg ;
	try{
	esito=document.getElementById('esito').value;
	campiForm=document.getElementById(formName).value;
	}catch(e){}
	
	
	if(esito=="1"){
		elem.style.color="#cc0000" ;
		elem.style.border="2px solid #cc0000" ;
		elem.style.width="180px;" ;
		elem.style.height="30px;" ;
		setTimeout(function(){
			elem.style.display="none" ;
			eval("document."+formName+".reset();");
		}, 3000);
		
	}else{
		elem.style.color="#000000" ;
		elem.style.border="2px solid #cc0000" ;
		elem.style.width="180px;" ;
		elem.style.height="50px;" ;
	}
	
}

function displayOutputMenu(idOut) {

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



function displayOutputAndReload(idOut, msg) {

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

	var elem = document.getElementById(id) ;
	var elem2 = document.getElementById('overl') ;
	var elem3 = document.getElementById('chiusura') ;
	elem.style.display="none" ;
	elem2.style.display="none" ;
	elem3.style.display="none" ;
	elem.innerHTML = msg ;
	
	setTimeout(function(){
		elem.style.display="none" ;
		elem2.style.display="none" ;
		elem3.style.display="none" ;
	}, 1000);
	
}

function RegistrazioneBackendB2C_togglePrivatoAzienda(tipo) {
	
	switch (tipo) {
		
		case "privato" :
			jQuery("#case_azienda").hide('fast') ;
			jQuery("#case_azienda * input").each(function (i) {
				jQuery(this).val('') ;
			}) ;
		break ;
		
		case "azienda" :
			jQuery("#case_azienda").show('fast') ;
			
		break ;
	}
}


