function lightPopup(id){
	if((lp=$('js_Popup_'+id))!=null){
		try{						
			lp.show().select('a.link_Close')[0].observe('click',function(event){event.element().up().hide();});			
		}catch(exception){}
	}
	return false;
}

/*

Davide Evangelisti
Accenture 09/06/2011

I popup, prima del mio intervento, venivano unicamente visulizzati nella località del bottone che li rendeva visibili. Questo risultato si ottiene posizionando consecutivamente al bottone il div del popup. Il bottone però, si trova in una struttura artificiale TabbedPane e questo porta a far sì che il popup possa non essere al di sopra di ogni elemento. A questo punto potevo smontare il layout oppure scegliere di mettere il popup esternamente ( subito dopo il body a questo punto ) e poi di posizionalo al centro della pagina; questo deve essere fatto via JavaScript perché il css con percentuali e numeri fissi, non consente di adattarsi a browser con la finestra ridotta, etc.

Chicca da notare, è che per evitare improprie modifiche di template per mettere il mio popup sotto il body, ho inserito la stringa "document.body.appendChild( $('js_Popup_'+id) );"

*/

function lightPopupCentered(id){
	if((lp=$('js_Popup_'+id))!=null){
		try{
			
			/* porto il popup da dove si trova a sotto il body evitando tutti i conflitti di layout. */
			document.body.appendChild( $('js_Popup_'+id) );
			
			var element = $('deepmarker_'+id);
			var coords = { x: 0, y: 0};
			
			while (element) {
				coords.x += element.offsetLeft;
				coords.y += element.offsetTop;
				element = element.offsetParent;
			}

			$('js_Popup_'+id).style.top = coords.y - $('js_Popup_content_'+id).style.height.replace("px","")+ "px";	
						
			lp.show().select('a.link_Close')[0].observe('click',function(event){event.element().up().hide();});
			
		}catch(exception){}
	}
	return false;
}

function MSHUpcase(myfield) {
	    if (myfield.inchange) return;
	    myfield.inchange = true;
	    myfield.value = myfield.value.toUpperCase();
	    myfield.inchange = false;
	}

function MSHLowcase(myfield) {
    if (myfield.inchange) return;
    myfield.inchange = true;
    myfield.value = myfield.value.toLowerCase();
    myfield.inchange = false;
}

function MSHlimitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	}
}

/*
	"FACT-Finder Integration" operation:
	Select or deselect all elements of specified form with specified name (or part of the name)
	according to specified "checking status" (i.e. true/false)
	N.B. Taken from "selectAll()" JavaScript function in "inc/GlobalJavaScript" template of "sld_enterprise_app" cartridge
	@author Triboo
*/
function selectAll(formID, partOfFormElementName, checkingStatus) {
	var selectedForm = document.getElementById(formID);

	if (selectedForm != null)
	{
		var formElements = selectedForm.elements;

		for (var i = 0; i < formElements.length; i++)
		{
			if (	( -1 != formElements[i].name.indexOf(partOfFormElementName) ) &&
					( formElements[i].disabled == false ) &&
					( ( formElements[i].type == "checkbox" ) || ( formElements[i].type == "radio" ) )
				)
			{
				formElements[i].checked = checkingStatus;
			}
		}
	}
}

/*
	"FACT-Finder Integration" operation:
	Submit specified form or redirect to alternative URL if it does not exist
	@author Triboo
*/
function submitForm(formID, submitTypeName, submitTypeValue, alternativeURL)
{
	// get specified form
	var selectedForm = document.getElementById(formID);

	if (selectedForm != null)
	{
		if (submitTypeName != "")
		{
			// generate hidden input field with required code for dispatch node
			var input = document.createElement("input");
			input.setAttribute("type", "hidden");
			input.setAttribute("name", submitTypeName);
			input.setAttribute("value", submitTypeValue);
			selectedForm.appendChild(input);
		}

		// submit specified form
		selectedForm.submit();
	}
	else
	{
		// redirect to alternative URL
		window.location.href = alternativeURL;
	}
}

