
	//
	// funzioni generiche Flex
	//

	// imposta in un controllo data la data corrente
	
function SetTodayDate(elName) {

	var now = new Date();

	var el;	
	el = document.getElementById(elName + '_D')
	if (el)
		el.value = now.getDate();

	el = document.getElementById(elName + '_M')
	if (el)
		el.value = now.getMonth() + 1;	// Jan = 0

	el = document.getElementById(elName + '_Y')
	if (el)
		el.value = now.getYear();

}

function DumpElement(el) {

	var t = '';
	for (i in el)
		t += i + " - " + el[i] + "\n";

	alert(t);
}

	//
	// hides elements in the page based on CSS class
	//

function HideShowJSElements(tags) {

	for (j = 0; j < tags.length; j++) {

		var els = document.getElementsByTagName(tags[ j ]);

		for (i=0; i < els.length; i++) {

			if (HasClassName(els[i], 'jsHide'))
				els[i].style.display = 'none';

			if (HasClassName(els[i], 'jsShow'))
				els[i].style.display = 'inline';

			if (HasClassName(els[i], 'jsShowB'))
				els[i].style.display = 'block';
		}
	}
}

	//

function OpenWinScroll(winURL, winName, w, h, top, left) {

	var winOptions = 'scrollbars=yes,resizable=yes,width=' + w + ',height=' + h + ',top=' + top + ',left=' + left + ',status=no,location=no,toolbar=no,titlebar=no';
	var wnd = window.open('', winName, winOptions);
	if (wnd != null) {

		wnd = window.open(
			winURL,
			winName,
			winOptions
		);
	}

	wnd.window.focus();
	//      setTimeout('wnd.window.focus();', 1000);

	return false;
}

	//
	// siccome se chiamato a mano in explorer il submit del form non invoca l'onsubmit()
	// bisogna farlo a mano
	//

function SubmitForm(idForm) {

	var f = document.getElementById(idForm);
	if (f) {

			// invoca l'handler solamente se definito

		if (f.onsubmit)
			f.onsubmit();

		f.submit();
	}
}

	//
	// Toggle DIV visibility
	//
	
function TV(id, controller) {

	el = document.getElementById(id);
	if (el) {

			// al primo giro verifica se l'oggetto ha il salvataggio della label
			// TBD: 'Mostra' è hardcodeed
			
		if (controller && ! controller.flexLabel)
			controller.flexLabel = controller.alt.replace('Mostra', '');

		shouldShow = (el.style.display == 'none');
		el.style.display = shouldShow ? 'block' : 'none';

		label = (shouldShow ? 'Nascondi' : 'Mostra');
		
		if (controller)
			controller.alt = label + ' ' + controller.flexLabel;
	}

	return false;
}

	// jump del focus sui div editabili
	
function FlipFocus(id1, id2) {

	if (HasFocus(id1)) {
//alert('flip');	


window.status = 'Taking focus from ' + id1 + ' - Giving focus to ' + id2;
alert('Taking focus from ' + id1 + ' - Giving focus to ' + id2);

		ResetFocus(id1);
		GiveFocus(id2);
	

	} else {
//alert('flop');


window.status = 'Taking focus from ' + id2 + ' - Giving focus to ' + id1;
alert('Taking focus from ' + id2 + ' - Giving focus to ' + id1);

		ResetFocus(id2);
		GiveFocus(id1);
	}
}

function GiveFocus(id) {

	var el = document.getElementById(id);
	if (el) {

//alert(HasFocus(id) ? 'Has focus' : 'not have focus');
		el.focus();
		
		el.flexFocus = true;
	} else
		alert("GiveFocus: Element " + id + " non trovato");
}

function ResetFocus(id) {

	var el = document.getElementById(id);
	if (el) {
	
		el.flexFocus = null;
	} else
		alert("ResetFocus: Element " + id + " non trovato");
}

function HasFocus(id) {

	var el = document.getElementById(id);
	if (el) {

		return (el.flexFocus == true);

	} else
		alert("HasFocus: Element " + id + " non trovato");
	
	return false;
}

	//
	// Gestione dell'evidenziazione dei campi
	// TBD: spostare in un file esterno per conto loro

function OnFocusHandler() {

	var tags = Array('input', 'textarea', 'select', 'div#editorLite');

	for (j = 0; j < tags.length; j++) {

		var t = tags[ j ].split('#')[0];
		var c = tags[ j ].split('#')[1];

		var els = document.getElementsByTagName(t);
		for (i=0; i < els.length; i++) {

			if (! c || HasClassName(els[i], c)) {

				FHSaveProperties(els[ i ]);

					// aggiunge solo se non esiste già un gestore dell'onfocus

				if (! els[ i ].onfocus) {
					
					els[ i ].onfocus = function () { FHHighlightProperties(this); };
					els[ i ].onblur  = function () { FHRestoreProperties(this); };
				}
			}
		}
	}
}

function FHSaveProperties(el) {

	if (! el.flexSaved) {

		el.flexBG = el.style.backgroundColor;
		el.flexBorderColor = el.style.borderColor;
		el.flexColor = el.style.color;
		
		el.flexSaved = true;
	}
}

function FHRestoreProperties(el) {

	el.style.backgroundColor = el.flexBG;
	el.style.borderColor = el.flexBorderColor;
	el.style.color = el.flexColor;
	
	el.flexSaved = null;
}

function FHHighlightProperties(el) {

	FHSaveProperties(el);

	el.style.backgroundColor = '#ffc';
	el.style.borderColor = '#000';
	el.style.color = '#000';
}