/* function_js.js */
/* Creation date: 11/05/2006  */
/* Author: Giuliano Polverari */

/* ---------------------------
 * PARTE 1 
 *  operazioni chiamate sempre 
 * ---------------------------
 */

/* resize della finestra */


/* posizione del mouse */
var mouseX, mouseY;
document.onmousemove=getMouse; //funzione definita sotto

/* ---------------------------
 * PARTE 2 
 *  funzioni
 * ---------------------------
 */

/* versione accorciata del precedente, che chiude solamente*/
function chiudilo(obj) {
	if (document.layers) { // NS 4.x
		d1=document.layers[obj];
		if (d1) d1.visibility="hide";
	} else {
		if (document.getElementById) { // DOM-compliant browsers 
			d1=document.getElementById(obj);
		} else if (document.all) { // IE 4.x
			d1=document.all[obj];
		} else {
 			return
		}
		if (d1) d1.style.display="none";
	}
}

/* versione accorciata del precedente, che apre solamente*/
function aprilo(obj) {
	if (document.layers) { // NS 4.x
		d1=document.layers[obj];
		if (d1) d1.visibility="show";
	} else {
		if (document.getElementById) { // DOM-compliant browsers 
			d1=document.getElementById(obj);
		} else if (document.all) { // IE 4.x
			d1=document.all[obj];
		} else {
 			return
		}
		if (d1) d1.style.display="block";
	}
}

function disappear(obj) {
	if (document.layers) { // NS 4.x
	
		d1=document.layers[obj];
		if (d1) {
			if (d1.visibility=="hide")	{
				d1.visibility="show";
			} else {
				d1.visibility="hide";
			}
		}
	} else {
		if (document.getElementById) { // DOM-compliant browsers 
			d1=document.getElementById(obj);
		} else if (document.all) { // IE 4.x
			d1=document.all[obj];
		} else {
			return
		}
		
		if (d1) {
			if (d1.style.display=="none")	{
				d1.style.display="block";
			} else {
				d1.style.display="none";
			}
		}
	}
}


/* funzione customizzata, fa apparire sotto il mouse */
function apriloSuDiMe (obj, offX, offY, relative) {
	if (!offX) { offX = 0; }
	if (!offY) { offY = 0; }
	
	if (!relative || relative != 'no') {
		//alert((mouseX + offX)+';'+(mouseY + offY));
		offX += mouseX;	
		offY += mouseY;	
	}

	var d1;
	if (document.layers) { // NS 4.x
	
		d1=document.layers[obj];
		if (d1) {
			d1.style.left = offX + 'px';
			d1.style.top  = offY + 'px';
			d1.visibility="show";
		}
	} else {
		if (document.getElementById) { // DOM-compliant browsers 
			d1=document.getElementById(obj);
		} else if (document.all) { // IE 4.x
			d1=document.all[obj];
		} else {
			return;
		}
		
		if (d1) {
			d1.style.left = offX + 'px';
			d1.style.top  = offY + 'px';
			d1.style.display="block";
		}
	}
}


/* funzione customizzata, fa apparire e sparire sotto il mouse */
function disappearSuDiMe (obj, offX, offY, relative) {
	if (!offX) { offX = 0; }
	if (!offY) { offY = 0; }
	
	if (!relative || relative != 'no') {
		//alert((mouseX + offX)+';'+(mouseY + offY));
		offX += mouseX;	
		offY += mouseY;	
	}

	var d1;
	if (document.layers) { // NS 4.x
	
		d1=document.layers[obj];
		if (d1) {
			if (d1.visibility=="hide")	{
				d1.style.left = offX + 'px';
				d1.style.top  = offY + 'px';
				d1.visibility="show";
			} else {
				d1.visibility="hide";
			}
		}
	} else {
		if (document.getElementById) { // DOM-compliant browsers 
			d1=document.getElementById(obj);
		} else if (document.all) { // IE 4.x
			d1=document.all[obj];
		} else {
			return;
		}
		
		if (d1) {
			if (d1.style.display=="none")	{
				d1.style.left = offX + 'px';
				d1.style.top  = offY + 'px';
				d1.style.display="block";
			} else {
				d1.style.display="none";
			}
		}
	}
}

/* catturo la posizione del mouse (attivata sempre) */
function getMouse(e) {
	if(!e) { e=window.event; }

	var vDoc=(document.documentElement && document.documentElement.scrollTop)?document.documentElement:document.body;

	mouseX=(e.pageX)?e.pageX:e.clientX+vDoc.scrollLeft;
	mouseY=(e.pageY)?e.pageY:e.clientY+vDoc.scrollTop;
}


/* funzione di popup */
function Popup(apri) {
	var top  = (screen.width  - 400) /2;
	var left = (screen.height - 550) /2;
	if (top > 2*left) { top = top*2; }
	var stile = "top="+top+", left="+left+", width=400, height=550, status=no, menubar=no, toolbar=no scrollbar=yes";
	window.open(apri, "", stile);
}


/* funzione di logout */	
function esci(){
	if (confirm("Uscire dal programma?")) { 
		//self.close(); 
		location.href = "index.php?exit";
	}
}
	

/* funzione di logout (2 - utilizzata per chiudere la pagina) */	
function close() {
	document.write('self.close();');
}
	
	
/* funzione di salto */
function jump(targ,selObj) {
	eval("parent.location='"+targ+selObj.options[selObj.selectedIndex].value+"'");
//	document.location.href = targ + selObj.options[selObj.selectedIndex].value;
}


/* funzione per recuperare un parametro get */
function getget(name) {
  var q = document.location.search;
  var i = q.indexOf(name + '=');

  if (i == -1) { return false; }

  var r = q.substr(i + name.length + 1, q.length - i - name.length - 1);

  i = r.indexOf('&');

  if (i != -1) { r = r.substr(0, i); }

  return r.replace(/\+/g, ' ');
}



/* funzione per cercare elementi in un array */
Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};



/* attiva le maniglie per il menù principale*/
function menuStrech1(verso) {
	if (verso == 'su') {
		chiudilo('mdown');		aprilo('mup');	
	} else {
		aprilo('mdown');			chiudilo('mup');	
	}
	ajax_menuStrech(1);		
}

/* attiva le maniglie per il menù laterale*/
function menuStrech2() {
	disappear('smdown');
	disappear('smup');	
	ajax_menuStrech(2);		
}


/* attiva azioni cliccando il tasto destro 
 * ex. utilizzo: onmouseover=\"abilitadestro('disappear(\'rub".$row['IDRUB']."\')')\" 
 */
function abilitadestro(azione) {
	function clickIE() {
		if (document.all)	{ }
	}
	function clickNS(e) {
		if	(document.layers||(document.getElementById&&!document.all))	{
			if (e.which==2||e.which==3) { }
		}
	}
	if (document.layers)	{
		document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;
	} else {
		document.onmouseup=clickNS;document.oncontextmenu=clickIE;
	}
	document.oncontextmenu=new Function(azione+';return false');
}

/* disattiva attiva azioni cliccando il tasto destro */
function disabilitadestro() {
	if (document.layers)	{
		document.captureEvents(Event.MOUSEDOWN);document.onmousedown='';
	} else {
		document.onmouseup='';document.oncontextmenu='';
	}
}


/* aggiorna il testo di un div */
function aggiorna_testo (id_elemento, testo) {
	document.getElementById(id_elemento).innerHTML = testo;
}


/* formattazione euro */
function formatta_euro (elemento) {
	var numero = elemento.value.toString().replace(".","");
   dp=numero.indexOf(",")!=-1?numero.substring(0,numero.indexOf(",")).length:numero.length;
   for (i=dp-3;i>0;i-=3)
      numero=numero.substring(0,i)+"."+numero.substr(i);
  	numero = numero.toString();
   numero.indexOf(",")==-1?numero+=",00":numero.substr(numero.indexOf(",")).length==2?numero+="0":null;
	if (numero.toString() == ",00"){ numero = ""; }
	elemento.value = numero;
	return;
}

/* l'argomento è l'id dell'immagine */
function image_trans (img) {
	var arVersion = navigator.appVersion.split("MSIE")
	//alert('versione'+navigator.appVersion);
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5) && (version < 7)) {
      var img = document.getElementById(img);
      var imgName = img.src.toUpperCase();
      if (imgName.substring(imgName.length-4, imgName.length) == ".PNG") {
         //alert (imgName);
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}

function image_swap (id_img, img) {
	//document.getElementById(\''.$row['ICONS'].'\').src=\'themes/evo/images/'.$row['ICONS'].'.png\'
	document.getElementById(id_img).src=img;
	//image_trans(id_img);
}



//aggiunge una frase; se frase è vuota, aggiunge una riga vuota
function add_frase (frase, contesto, padre) {
	
	count = 1;
	nuovoInner = "";
	while (document.getElementById(contesto+count)) { 
		fraseAct = document.getElementById(contesto+count);
		if (frase != undefined && fraseAct.value == '') { 
			//resetto il contatore ed esco
			count = 0; break; 
		}
		nuovoInner += '<div><input id="'+contesto+count+'" name="'+contesto+count+'" \
      		type="text" size="60" class="form" value="'+fraseAct.value+'">';
		//alla prima riga aggiungo il pulsante +
		if (count == 1) {
			nuovoInner += ' <a href="javascript:add_frase(\'\', \''+contesto+'\', \''+padre+'\');" onclick="">+</a>';
		}
		nuovoInner += '</div>';
		count++; 
	}

	//se ho trovato un posto libero, ci scrivo ed esco
	if (count == 0) {
		fraseAct.value = frase;
		return;
	}
	
	//altrimenti creo un nuovo posto e lo riempio
	nuovoInner += '<div><input id="'+contesto+count+'" name="'+contesto+count+'"  \
   		type="text" size="60" class="form" value="';
	if (frase != '' && frase != undefined) { nuovoInner += frase; }
	nuovoInner += '"></div>';
	
	document.getElementById(padre).innerHTML = nuovoInner;
	return;
}


function get_key_down(e) {
	var keynum;
	var keychar;
	
	if(window.event) { // IE
		keynum = e.keyCode;
	} else if(e.which) { // Netscape/Firefox/Opera
		keynum = e.which;
	}
	return keynum;
}



/* ---------------------------
 * PARTE 3 
 * libreria funzioni condivise ajax (lato javascript)
 * ---------------------------
 */

/* Creation date: 11/05/2006  */
/* Author: Giuliano Polverari */

function findPosX(obj)	{
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent)	{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}


function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function scrivi(val, e) {
	var responseSuccess = function(o) { 
	//	alert(o.responseText);
		setZIndex(val);
	}
	var responseFailure = function(o) { alert('ERRORE'+o.responseText); }
	
	var callback = { success:responseSuccess, failure:responseFailure }
	var cObj = YAHOO.util.Connect.asyncRequest('POST','XDajaxComm.php?act=dd2&&id='+e,callback,null);
}


function scriviAppear(val, e) {
	var responseSuccess = function(o) { 
		//alert(o.responseText);
		setZIndex(val);
		//codice di compatibilità perché js 'dimentica' la larghezza del div
		if (e == 'SI') {
		 	theId = document.getElementById(val);
			theId.style.width = o.responseText + 'px';
		}
	}
	var responseFailure = function(o) { alert('ERRORE'+o.responseText); }
	
	var callback = { success:responseSuccess, failure:responseFailure }
	var cObj = YAHOO.util.Connect.asyncRequest('POST','XDajaxComm.php?act=appear&&id='+val+'--'+e,callback,null);
}

/* versione customizzata per salvare il risultato su db */
function floatAppear(obj) {
	// DOM-compliant browsers 
	if (document.getElementById) { d1=document.getElementById(obj);	}	
	// IE 4.x
	else if (document.all) 		{	d1=document.all[obj];		}
	else					{				return;		}
	if (d1.style.display=="none")	{	
		d1.style.display="block";	
		scriviAppear(obj, 'SI'); 
	}	else	{
		d1.style.display="none";	
		scriviAppear(obj, 'NO'); 
	}
}	


function provaNull(id) {
	//una serie di azioni nulle, per far girare il motore javascript
 	theId = document.getElementById(id);

	//ATTENZIONE non cambiare MAI questo codice
	// la proprietà offsetWidth è di sola lettura
	// la proprietà style.width può essere letta solo se è stata già scritta
	theId.style.width = theId.offsetWidth + 'px';
	theId.style.width = theId.offsetWidth -4 + 'px';
}

function postRequest(id, act, e) {
	var responseSuccess = function(o) { 
		//alert(o.responseText);
	 	theId = document.getElementById(id+'Text');
		theId.innerHTML = o.responseText;
		//alert(theId.innerHTML);
		provaNull(id);
	}
	var responseFailure = function(o) { alert('ERRORE'+o.responseText); }

	var callback = { success:responseSuccess, failure:responseFailure }
	var cObj = YAHOO.util.Connect.asyncRequest('POST','XDajaxComm.php?act='+id+'--'+act+'&&id='+e,callback,null);
}

function postRequestScroll(id) {
	var responseSuccess = function(o) { 
		//alert(o.responseText);
	 	theId = document.getElementById(id+'Scroll');
		theId.innerHTML = "<a href=\"javascript:provaScroll('"+id+"', 'su');\"	"+
			"	onmouseover=\"javascript:provaScroll('"+id+"', 'scrollsu');\"		"+
			"	onmouseout=\"clearTimeout(timeOff)\">										"+
			"<img src=\"image/frecciasu.gif\"></a>	<br />									"+
			"<a href=\"javascript:provaScroll('"+id+"', 'giu');\" 						"+
			"	onmouseover=\"javascript:provaScroll('"+id+"', 'scrollgiu');\"		"+
			"	onmouseout=\"clearTimeout(timeOff)\">										"+
			"<img src=\"image/frecciagiu.gif\"></a>	<br />								"+
			o.responseText;
		//alert(theId.innerHTML);
		provaNull(id);
	}
	var responseFailure = function(o) { alert('ERRORE'+o.responseText); }

	var callback = { success:responseSuccess, failure:responseFailure }
	var cObj = YAHOO.util.Connect.asyncRequest('POST','XDajaxComm.php?act='+id+'--scroll&&id=0',callback,null);
}


//'e' è l'elemento da portare avanti
function setZIndex(e) {
	
	var responseSuccess = function(o) { 
		//alert(o.responseText);
		var arr = new Array();
		arr = (o.responseText).split('--');
		var i = 1;
		for (key in arr) {
		 	//check di esistenza elemento (a scanso di equivoci)
			 if (document.getElementById(arr[key])) {
				theId = document.getElementById(arr[key]);
				theId.style.zIndex = i;
				//alert(key+' '+i);
				i++;
			}
		} 
	}
	var responseFailure = function(o) { alert('ERRORE'+o.responseText); }

	var callback = { success:responseSuccess, failure:responseFailure }
	var cObj = YAHOO.util.Connect.asyncRequest('POST','XDajaxComm.php?act=zIndex&&id='+e,callback,null);
}



function provaGrande(id) {
 	theId = document.getElementById(id);
	//alert(theId.style.width+'u'+theId.style.height);
	theId.style.width = (window.screen.availWidth - 60) +'px';	
	theId.style.height= (window.screen.availHeight - 350) +'px';
	//alert(theId.style.width+'u'+theId.style.height);
	theId.style.top = '80px';
	theId.style.left = '20px';
	theId.style.right = '20px';
	setZIndex(id);
}


//'e' è l'elemento da portare avanti
function ajax_menuStrech(e) {
	var responseSuccess = function(o) { }
	var responseFailure = function(o) { alert('ERRORE'+o.responseText); }
	var callback = { success:responseSuccess, failure:responseFailure }
	var cObj = YAHOO.util.Connect.asyncRequest('POST','ajax_pra.php?pag=menu_stretch&&id_menu='+e,callback,null);
}


/* setta il div messaggi a loading */
function ajax_set_effettuato() {
	elem = document.getElementById('msg');
	elem.innerHTML = '<div class="tranqui_box">Aggiornamento effettuato</div>';
	elem.style.opacity = 0.9;
	elem.style.filter = 'alpha(opacity=90)';

	YAHOO.example.init = function() {   
   	var anim = new YAHOO.util.Anim('msg', { opacity: { to: 0 } }, 4, YAHOO.util.Easing.easeOut);
   	anim.animate();
	};
	YAHOO.util.Event.onAvailable('msg', YAHOO.example.init);
}

/* setta il div messaggi a loading */
function ajax_set_errore() {
	elem = document.getElementById('msg');
	elem.innerHTML = '<div class="avviso_box">Errore</div>';
	elem.style.opacity = 0.9;
	elem.style.filter = 'alpha(opacity=90)';

	YAHOO.example.init = function() {   
   	var anim = new YAHOO.util.Anim('msg', { opacity: { to: 0 } }, 4, YAHOO.util.Easing.easeOut);
   	anim.animate();
	};
	YAHOO.util.Event.onAvailable('msg', YAHOO.example.init);
}

/* setta il div messaggi a loading */
function ajax_set_loading() {
	elem = document.getElementById('msg');
	if (!elem) { return; }
	elem.innerHTML = '<div class="avviso_box" style="display:inline">Loading...</div>';
	elem.style.opacity = 0.9;
	elem.style.filter = 'alpha(opacity=90)';
}

/* resetta il div messaggi (trasparente, senza testo) */
function ajax_reset_loading() {
	elem = document.getElementById('msg');
	if (!elem) { return; }
	elem.innerHTML = '';
	elem.style.opacity = 1;
	elem.style.filter = 'alpha(opacity=100)';
}


/*	esegue un'azione e scrive il risultato nel div_indicato dall'id oggetto
*/
function ajax_request (link_azione, id_div_oggetto, post_data) {
	
	var responseSuccess = function(o) { 
		ajax_reset_loading();
		elem = document.getElementById(id_div_oggetto);
		if (elem && o.responseText != '')
			elem.innerHTML = o.responseText;
	}
	var responseFailure = function(o) { alert('ERRORE '+o.responseText); }
	var callback = { success:responseSuccess, failure:responseFailure }
	var cObj = YAHOO.util.Connect.asyncRequest('POST',link_azione,callback,post_data);
	ajax_set_loading();
}


/*	esegue un'azione e scrive il risultato nel div_oggetto
*/
function ajax_request_div (link_azione, div_oggetto, post_data) {
	
	var responseSuccess = function(o) { 
		ajax_reset_loading();
		if (o.responseText != '')
			div_oggetto.innerHTML = o.responseText;
	}
	var responseFailure = function(o) { alert('ERRORE '+o.responseText); }
	var callback = { success:responseSuccess, upload:responseSuccess, abort:responseFailure, failure:responseFailure }
	var cObj = YAHOO.util.Connect.asyncRequest('POST',link_azione,callback, post_data);
	ajax_set_loading();
}



/*	esegue un'azione, scrive il risultato nel "popup ajax yui"_oggetto e lo apre
*/
function ajax_request_popup (link_azione, div_oggetto, post_data) {
	
	var responseSuccess = function(o) { 
		ajax_reset_loading();
		if (o.responseText != '') {
			div_oggetto.setBody(o.responseText);
			div_oggetto.show();
		}
	}
	var responseFailure = function(o) { alert('ERRORE '+o.responseText); }
	var callback = { success:responseSuccess, failure:responseFailure, upload:responseSuccess, abort:responseFailure }
	if (post_data==false) {
		var cObj = YAHOO.util.Connect.asyncRequest('POST',link_azione,callback);
	} else {
		var cObj = YAHOO.util.Connect.asyncRequest('POST',link_azione,callback, post_data);
	}
	ajax_set_loading();
}



/*	esegue un'azione e passa il risultato alla funzione_oggetto
*/
function ajax_request_eval(link_azione, funzione_oggetto, post_data) {
	
	var responseSuccess = function(o) { 
		ajax_reset_loading();
		if (o.responseText != '')
			eval(funzione_oggetto+'(\''+o.responseText+'\')');
	}
	var responseFailure = function(o) { alert('ERRORE'+o.responseText); }

	var callback = { success:responseSuccess, failure:responseFailure }
	var cObj = YAHOO.util.Connect.asyncRequest('POST',link_azione,callback,post_data);
	ajax_set_loading();
}



/*	esegue un'azione e carica la pagina link con parametro = risultato azione
*/
function ajax_request_link(azione, link, post_data) {
	var responseSuccess = function(o) { 
		ajax_reset_loading();
		if (o.responseText != '') {
			if (link.indexOf('?') == -1) {
				location.href = link+'?msg='+o.responseText;
			} else {
				location.href = link+'&&msg='+o.responseText;
			}
		}
	}
	var responseFailure = function(o) { alert('ERRORE '+o.responseText); }
	var callback = { success:responseSuccess, failure:responseFailure }
	var cObj = YAHOO.util.Connect.asyncRequest('POST',azione,callback,post_data);
	ajax_set_loading();
}



/*	esegue un'azione e carica la pagina restituita
*/
function ajax_loading(link_azione, post_data) {
	
	var responseSuccess = function(o) { 
		if (o.responseText != '') {
			location.href = o.responseText;
		} else {
			elem.innerHTML = '';
		}
	}
	var responseFailure = function(o) { alert('ERRORE'+o.responseText); }

	var callback = { success:responseSuccess, failure:responseFailure }
	var cObj = YAHOO.util.Connect.asyncRequest('POST',link_azione,callback,post_data);
	ajax_set_loading();
}



function ajax_loading_confirm(link_azione, post_data, testo_conferma) {
	if (!confirm(testo_conferma)) return;
	ajax_loading(link_azione, post_data);
}


/* genera il campo post con tutti i dati del form */
function ajax_post_da_form (modulo) {
	var campo_post = '';
	
	for (x=0;x<eval('document.'+modulo+'.length');x++){
		var el=eval('document.'+modulo).elements[x];		
		if (el) {
			var type=el.type;
			if (el.type=='text' || el.type=='select-one' || (el.type=='checkbox' && el.checked)
			|| (el.type=='radio' && el.checked) || el.type=='textarea') {
				//alert(el.name+' - '+eval('document.'+modulo+"."+el.name).value);
				if (eval('document.'+modulo+"."+el.name).value) {
					if (campo_post != '') { campo_post += '&&'; }
					// modifico i caratteri "+" in "%2b", "&" in "%26" e "'" in "%27" (tramite espressione regolare)
					// ATTENZIONE!! il replace va fatto obbligatoriamente inline (sulla stessa riga), 
					// 	altrimenti perde il riferimento all'oggetto e non funziona!
					mio_valore = (eval('document.'+modulo+"."+el.name).value).replace(/\+/g, "%2b").replace(/&/g, "%26").replace(/'/g, "%27");
					campo_post += el.name+'='+mio_valore;
					chiudilo('modulo_'+el.name);
				}
			}
		}
	}
	return campo_post;
}



/* submit del form con esecuzione query e ritorno ad una pagina ulteriore */
function ajax_request_form (modulo, azione, ritorno) {	
	var campo_post = ajax_post_da_form(modulo);

	var codici = new Array(	
		'Campo obbligatorio',
		'Campo non valido',
		'Campo numerico',
		'Campo non nullo',
		'Data non corretta (gg-mm-aaaa)',
		'Data ed ora non corrette (gg-mm-aaaa hh:mm)',
		'Campo già esistente',
		'Lunghezza minima di almeno 8 caratteri'
	);
	var responseSuccess = function(o) { 
		ajax_reset_loading();
		if (o.responseText != '') {
			if (o.responseText.indexOf('-') != -1) {
				//condizione di errore rilevata: mostra e colora gli errori
				var split1 = o.responseText.split('-');
				for (i in split1) {
					if (split1[i] != '') {
						var riga = split1[i].toString();
						var id = modulo+'_'+riga.substr(0, riga.indexOf(':'));
						var codice = riga.substr(riga.indexOf(':')+1);
						//alert(id+' '+codice);
						if (document.getElementById(id)) {
							aprilo(id);
							document.getElementById(id).innerHTML = '<span style="color:red; font-size:0.80em;">* '+codici[codice]+'</span>';
						}
					}
				}
			} else if (parseInt(o.responseText).toString() == o.responseText) {	
				//ritorna un intero, è il codice di messaggio corretto da restituire
				if (ritorno == '') {
					if (o.responseText == 1 || o.responseText == 2 
					 || o.responseText == 3 || o.responseText == 4) { ajax_set_effettuato(); }
					else { ajax_set_errore(); }
				} else if (ritorno.indexOf('?') == -1) {
					location.href = ritorno+'?msg='+o.responseText;
				} else {
					location.href = ritorno+'&&msg='+o.responseText;
				}
			} else {
				//non ritorna un intero: errore di altro tipo, lo segnalo
				alert('Errore: '+o.responseText);
			}
		}
	}
	var responseFailure = function(o) { alert('ERRORE'+o.responseText); }
	
	var callback = { success:responseSuccess, failure:responseFailure }
	var cObj = YAHOO.util.Connect.asyncRequest('POST',azione,callback,campo_post);
	ajax_set_loading();
}




/**
 * @extends YAHOO.util.DragDrop
 * @constructor
 * @param {String} handle the id of the element that will cause the resize
 * @param {String} panel id of the element to resize
 */
YAHOO.XpenResize = function(panelElId, handleElId, step) {
    if (panelElId) {
    		this.panelElId = panelElId;
        this.init(panelElId);
        this.handleElId = handleElId;
        this.setHandleElId(handleElId);
        this.logger = this.logger || YAHOO;
			this.step = step;
			this.newHeight = 0;
    }
};

YAHOO.extend(YAHOO.XpenResize, YAHOO.util.DragDrop);

YAHOO.XpenResize.prototype.startDrag = function(e) {
	var theId = document.getElementById(this.panelElId);
	theId.className='square_on';
}

YAHOO.XpenResize.prototype.onMouseDown = function(e) {
    var panel = this.getEl();
    //this.startWidth = panel.offsetWidth;
    this.startHeight = panel.offsetHeight;

    this.startPos = [YAHOO.util.Event.getPageX(e),
                     YAHOO.util.Event.getPageY(e)];
};

YAHOO.XpenResize.prototype.onDrag = function(e) {
	var newPos = [YAHOO.util.Event.getPageX(e),
	            YAHOO.util.Event.getPageY(e)];
	
	//var offsetX = newPos[0] - this.startPos[0];
	var offsetY = newPos[1] - this.startPos[1];
	
	this.newHeight = Math.max(this.startHeight + offsetY, this.step);
	this.newHeight -= (this.newHeight % this.step);
	var panel = this.getEl();
	panel.style.height = this.newHeight + "px";
};

