var logoffFromEssig;

/*
* mamato: controlla il riposizionamento della pagina
* dopo un refresh all'ultimo campo che aveva il focus
*/
var enablePageReposition = false;


function alertNotImplemented() {	
	msgbox('Funzione non attivabile', 'vbOK or vbInformation', 'Work In Progress');
}

/**
 * @author bolofel
 * @since 02/10/2007
 */
function jf4uIsDefined(obj) {
	return typeof obj!="undefined";
}

function replaceAll(testo, a,b){
	return testo.replace(new RegExp(a,"g"),b);
}

//-------------------------------------------------
// mamato
//-------------------------------------------------
function getParameter(queryString, parameterName) {
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 ) {
		// Find the beginning of the string
		begin = queryString.indexOf ( parameterName );
		// If the parameter name is not found, skip it, otherwise return the value
		if ( begin != -1 ) {
			// Add the length (integer) to the beginning
			begin += parameterName.length;
			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) {
				end = queryString.length
			}
			// Return the string
			return unescape ( queryString.substring ( begin, end ) );
		}
		// Return "null" if no parameter has been found
		return "null";
	}
} 

/**
 * body onLoad Event Handler
 * @author bolofel
 * @since 31/01/2008
 */
function jf4uBodyOnLoad(document, form) {
	//alert("on load");
	//25/09/2008-UGF05565
	if (typeof disableContextMenu!="undefined"){
		disableContextMenu(document);
	}
	
	if(skipTabOfReadonlyElement){
		skipTabOfReadonlyElement(document, form);  
	}
	
	if (selectFirstActiveDocumentFieldElement){
		selectFirstActiveDocumentFieldElement(document, form);
	}
	
	//mamato: resetto il flag di blocco del doppio submit
	setDoubleSubmitCheckToken(false);
		
	//mamato
	if(enablePageReposition){
		var nextFocusField = getParameter(window.top.location.search.substring(1), "f");
		if(nextFocusField > ""){
			//alert("Focus su " + nextFocusField);
			try{
				document.all(nextFocusField).scrollIntoView(true);
			} catch (e){
			}
		}
	}
}

/**
 * body onBeforeUnload Event Handler
 * @author 
 * @since 
 */
function jf4uBodyOnBeforeUnload(e, document) {
	var evt = getEvent(e);
	//logoffFromEssig ritorna true se mi trovo sulla x di chiusura del browser
	logoffFromEssig = (((document.body.offsetWidth - evt.clientX )<25) && (evt.clientY <0) && !(evt.clientX > document.body.offsetWidth));
	
	//questo funziona solo su IE * 2010-05-11 Giusti, la riga sembra non andare mai..
	//logoffFromEssig = (window.event.clientY < 0 && (window.event.clientX > (document.documentElement.clientWidth - 5) || window.event.clientX < 15));
	
	//alert(logoffFromEssig);
}



/**
 * body onUnload Event Handler
 * @author bolofel
 * @since 15/02/2008
 *
 */
function jf4uBodyOnUnload(e, document, url) {
	
	var evt = getEvent(e);
    var version = navigator.appVersion.match(/MSIE (.\..)/)[1];
    
    //var logoffIE6 = evt.clientY < 0 && evt.clientX > 600;
    //if(((document.body.offsetWidth - evt.clientX )<25) && (evt.clientY <0)){
   	if(isAltF4KeyDown || logoffFromEssig){
   	//TODO check Firefox
    //alert("["+evt.clientY + "," + evt.clientX + "] - X close button intercepted"+ " screen.width :"+screen.availWidth );
    //per risoluzione 1024 e in modalita non a scermo intero
   	// if(((screen.availWidth == 1024) && (evt.clientY > -120 && evt.clientY < -100) && (evt.clientX > 1000 && evt.clientX < 1024)) ||
	//per risoluzione 1024 e in modalita a scermo intero
	//	((screen.availWidth == 1024) && (evt.clientY > 0 && evt.clientY < 26) && (evt.clientX > 997 && evt.clientX < 1024))||
		 // per risoluzione 1280 e modalità non a schermo intero 
	//    ((screen.availWidth == 1280) && (evt.clientY > -120 && evt.clientY < -100) && (evt.clientX > 1256 && evt.clientX < 1280)) ||
		 //per risoluzione 1280 e in modalita a scermo intero
	//    ((screen.availWidth == 1280) && (evt.clientY > 0 && evt.clientY < 25) && (evt.clientX > 1255 && evt.clientX < 1280))){
				
		//mamato: prova per disattivare il logoff in caso di chiusura browser
		//voglio verificare se è questo che fa scoppiare selenium.
		//nel caso remmare la riga che segue
		window.location.href = url;
		

		//21/02/2008-BOLOFEL
		//eraseCookie("LtpaToken");
		//eraseCookie("LtpaToken2");		
		//eraseCookie("JSESSIONID");		

	}
	return true;
}


/**
 * body onBeforeUnload Event Handler
 * @author 
 * @since 
 */
function jf4uBodyOnKeyDown(e, document) {
	cancelUnsafeHotkeyOnKeyDownEvent();
}

function jf4uBodyPrint() {

	if(isIE()){
	    document.execCommand("print", "false", "false");
	}
}
/*
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
*/

/**
* questa funzione imposta il focus sul primo elemento input text o select abilitato nel form
* che ha minimo tab-index;
* input: form è il form html ove opera la funzione
* 28/07/2008-UGF05565
* @deprecated
*/
function focusOnLoad(form) {
	var countElements = form.elements.length;
	var minimumTab = 1000;
	var minimumElement = -1;
	for(i=0;i<countElements;i++) {
		if((form.elements[i].type=='text' || form.elements[i].type=='textarea' || form.elements[i].type=='select-one' ) 
			&&  form.elements[i].readOnly==false && form.elements[i].disabled==false && form.elements[i].hidden==false)
			  {
			var currentTabIndex = form.elements[i].tabIndex;
			if(currentTabIndex<minimumTab) {
				minimumTab = currentTabIndex;
				minimumElement = i;
			}
		}		 	      	   
	}
 	      	
	if(minimumElement!=-1) {		 	      		
		form.elements[minimumElement].focus();
		form.elements[minimumElement].select();	      		 
	}
}		 	      

function cleanUpFields(name0, name1, name2, name3, name4, name5, name6, name7, name8, name9) {

	for (var i = 0; i < 10; i++) {
//		alert("param="+eval("name"+i));
		if(eval("document.getElementById(name" + i + ")") != undefined){	
		 	eval("document.getElementById(name" + i + ").value = ''");
		}else
			break;
	}
}

/**
* cancella un campo se non è già vuoto
*/
function makeFieldClean(form, fieldName) {	
	text = form.elements[fieldName];
	if (text.value != '') {
		text.value = '';
	}
}	

/**
* cancella 2 campi se non sono già vuoti
*/
function make2FieldClean(form, 
	fieldName1, fieldName2) {	
	
	text = form.elements[fieldName1];
	if (text.value != '') {
		text.value = '';
	}
	text = form.elements[fieldName2];
	if (text.value != '') {
		text.value = '';
	}
}	
		
/**
* cancella 4 campi se non sono già vuoti
*/
function make4FieldClean(form, 
	fieldName1, fieldName2, fieldName3, fieldName4) {	
	
	text = form.elements[fieldName1];
	if (text.value != '') {
		text.value = '';
	}
	text = form.elements[fieldName2];
	if (text.value != '') {
		text.value = '';
	}
	text = form.elements[fieldName3];
	if (text.value != '') {
		text.value = '';
	}
	text = form.elements[fieldName4];
	if (text.value != '') {
		text.value = '';
	}
}	
function isFieldEmpty(field){
	var isEmpty = false;
	if(field.value == ''){
		isEmpty=true;
	}
	return isEmpty;
}		
function myfunc(button , idfunz){
	var form = button.form;
	var oldAction = form.action;
	form.action = idfunz;
	//15/02/2008-bolofel-amatmax
	var result = executeFormSubmit();
	if (!result){
	    //alert("no submit from myfunc");
		return;
	}
	form.submit();
	//ripristino la action originale nel caso la pagina non venisse ricaricata...
	form.action = oldAction;
}

function myfuncWithoutForm(idfunz){
	try{
		var form = document.getElementById('myActionForm');
		if(undefined == form || null == form){
			form = window.document.forms[0];
		}
		var oldAction = form.action;
		form.action = idfunz;
		var result = executeFormSubmit();
		if (!result){
			return;
		}
		form.submit();
		form.action = oldAction;
	} catch (ex) {}		

}
function myfuncWithForm(idfunz, idForm){
	try{
		var form = window.document.forms[idForm];
		var oldAction = form.action;
		form.action = idfunz;
		var result = executeFormSubmit();
		if (!result){
			return;
		}
		form.submit();
		form.action = oldAction;
	} catch (ex) {}		
}
function postTheForm(idfunz, idForm){
	var form = window.document.forms[idForm];
	form.action = idfunz;
	form.submit();
}

/*
	mamato: rispetto alla standard doClick questa valorizza i campi della finestra "opener" e 
	non del suo top. E' necessario in INDI dove devo valorizzare i campi dell'iFrame che ha
	aperto il popup.
*/
function doClickSameOpener(nomeCampoCodice,codice,nomeCampoDescrizione,descrizione) {
	//mamato: aggiunto .top
	//Enrico: aggiunto controllo sul form (in alcune app. ho piu form)
	form = window.opener.parent.document.forms["myActionForm"];
	if(undefined == form){
		form = window.opener.parent.document.forms[0];
	}
	campoDescrizione = form.elements[nomeCampoDescrizione];
	if(undefined != campoDescrizione){
		campoDescrizione.value = descrizione.replace(/^\s+|\s+$/g,"");
	}
	campoCodice = form.elements[nomeCampoCodice];
	if(undefined != campoCodice){
		campoCodice.value = codice.replace(/^\s+|\s+$/g,"");
	}
	/*
	* Se esiste una funzione nella finestra chiamante con nome = postPopup_xxx
	* dove xxx è il nome del puntatore associato al poup, la eseguo.
	*/
	try{
		var pos = nomeCampoCodice.indexOf(".value")
		if(pos != -1)
			nomeCampoCodice = nomeCampoCodice.substring(0, pos);
			
		eval("var dummy=window.opener.postPopup_" + nomeCampoCodice + "();");
	} catch (e){
	}
	
	window.close();
	return false;
}

function doClick3ParamSameOpener(nomeCampoCodice,codice,nomeCampoDescrizione,descrizione,nomeCampoDescrizione2,descrizione2) {
	//mamato: aggiunto .top
	//Enrico: aggiunto controllo sul form (in alcune app. ho piu form)
	form = window.opener.parent.document.forms["myActionForm"];
	if(undefined == form){
		form = window.opener.parent.document.forms[0];
	}

	campoDescrizione2 = form.elements[nomeCampoDescrizione2];
	if(undefined != campoDescrizione2){
		campoDescrizione2.value = descrizione2.replace(/^\s+|\s+$/g,"");
	}
	campoDescrizione = form.elements[nomeCampoDescrizione];
	if(undefined != campoDescrizione){
		campoDescrizione.value = descrizione.replace(/^\s+|\s+$/g,"");
	}
	campoCodice = form.elements[nomeCampoCodice];
	if(undefined != campoCodice){
		campoCodice.value = codice.replace(/^\s+|\s+$/g,"");
	}
	/*
	* Se esiste una funzione nella finestra chiamante con nome = postPopup_xxx
	* dove xxx è il nome del puntatore associato al poup, la eseguo.
	*/
	try{
		var pos = nomeCampoCodice.indexOf(".value")
		if(pos != -1)
			nomeCampoCodice = nomeCampoCodice.substring(0, pos);
			
		eval("var dummy=window.opener.postPopup_" + nomeCampoCodice + "();");
	} catch (e){
	}
	
	window.close();
	return false;
}

function doClick(nomeCampoCodice,codice,nomeCampoDescrizione,descrizione) {
	//mamato: aggiunto .top
	//Enrico: aggiunto controllo sul form (in alcune app. ho piu form)
	form = window.opener.top.document.forms["myActionForm"];
	if(undefined == form){
		form = window.opener.top.document.forms[0];
	}
	campoCodice = form.elements[nomeCampoCodice];
	if(undefined != campoCodice){
		campoCodice.value = codice.replace(/^\s+|\s+$/g,"");
	}
	campoDescrizione = form.elements[nomeCampoDescrizione];
	if(undefined != campoDescrizione){
		campoDescrizione.value = descrizione.replace(/^\s+|\s+$/g,"");
	}
	/*
	* Se esiste una funzione nella finestra chiamante con nome = postPopup_xxx
	* dove xxx è il nome del puntatore associato al poup, la eseguo.
	*/
	try{
		var pos = nomeCampoCodice.indexOf(".value")
		if(pos != -1)
			nomeCampoCodice = nomeCampoCodice.substring(0, pos);
			
		eval("var dummy=window.opener.top.postPopup_" + nomeCampoCodice + "();");
	} catch (e){
	}
	
	window.close();
	return false;
}

function doClickTextArea(nomeCampoCodice,codice,nomeCampoDescrizione,descrizione) {
	//mamato: aggiunto .top
	//Enrico: aggiunto controllo sul form (in alcune app. ho piu form)
	form = window.opener.top.document.forms["myActionForm"];
	if(undefined == form){
		form = window.opener.top.document.forms[0];
	}
	
	campoCodice = form.elements[nomeCampoCodice];
	campoCodice.value = codice;
	campoDescrizione = form.elements[nomeCampoDescrizione];
	campoDescrizione.value = replaceAll(descrizione,'<br>','\n');

	/*
	* Se esiste una funzione nella finestra chiamante con nome = postPopup_xxx
	* dove xxx è il nome del puntatore associato al poup, la eseguo.
	*/
	try{
		var pos = nomeCampoCodice.indexOf(".value")
		if(pos != -1)
			nomeCampoCodice = nomeCampoCodice.substring(0, pos);
			
		eval("var dummy=window.opener.top.postPopup_" + nomeCampoCodice + "();");
	} catch (e){
	}
	
	window.close();
	return false;
}
function doClick1Param(nomeCampoCodice,codice) {
	form = window.opener.top.document.forms[0];
	campoCodice = form.elements[nomeCampoCodice];
	campoCodice.value = codice;
	window.close();
	return false;
}
function doClick3Param(nomeCampoCodice,codice,nomeCampoDescrizione,descrizione,nomeCampoProv,provincia) {
	form = window.opener.top.document.forms[0];
	campoCodice = form.elements[nomeCampoCodice];
	campoCodice.value = codice;
	campoDescrizione = form.elements[nomeCampoDescrizione];
	campoDescrizione.value = descrizione;
	field = form.elements[nomeCampoProv];
	field.value = provincia;
	window.close();
	return false;
}

function doClick5Param(nome1,valore1,nome2,valore2,nome3,valore3,nome4,valore4,nome5,valore5) {
	form = window.opener.top.document.forms[0];
	var campo1 = form.elements[nome1];
	campo1.value = valore1;

	var campo2 = form.elements[nome2];
	campo2.value = valore2;

	var campo3 = form.elements[nome3];
	campo3.value = valore3;

	var campo4 = form.elements[nome4];
	campo4.value = valore4;

	var campo5 = form.elements[nome5];
	campo5.value = valore5;

	window.close();
	return false;
}

function doClick6Param(nome1,valore1,nome2,valore2,nome3,valore3,nome4,valore4,nome5,valore5,nome6,valore6) {
	form = window.opener.top.document.forms[0];
	var campo1 = form.elements[nome1];
	if(undefined != campo1){
		campo1.value = valore1;
	}
	var campo2 = form.elements[nome2];
	if(undefined != campo2){
		campo2.value = valore2;
	}
	var campo3 = form.elements[nome3];
	if(undefined != campo3){
		campo3.value = valore3;
	}
	var campo4 = form.elements[nome4];
	if(undefined != campo4){
		campo4.value = valore4;
	}
	var campo5 = form.elements[nome5];
	if(undefined != campo5){
		campo5.value = valore5;
	}
	var campo6 = form.elements[nome6];
	if(undefined != campo6){
		campo6.value = valore6;
	}

	window.close();
	return false;
}

function doClick7Param(nome1,valore1,nome2,valore2,nome3,valore3,nome4,valore4,nome5,valore5,nome6,valore6,nome7,valore7) {
	form = window.opener.top.document.forms[0];
	var campo1 = form.elements[nome1];
	if(undefined != campo1){
		campo1.value = valore1;
	}
	var campo2 = form.elements[nome2];
	if(undefined != campo2){
		campo2.value = valore2;
	}
	var campo3 = form.elements[nome3];
	if(undefined != campo3){
		campo3.value = valore3;
	}
	var campo4 = form.elements[nome4];
	if(undefined != campo4){
		campo4.value = valore4;
	}
	var campo5 = form.elements[nome5];
	if(undefined != campo5){
		campo5.value = valore5;
	}
	var campo6 = form.elements[nome6];
	if(undefined != campo6){
		campo6.value = valore6;
	}
	var campo7 = form.elements[nome7];
	if(undefined != campo7){
		campo7.value = valore7;
	}

	window.close();
	return false;
}

function doClickScopMinFr(nome1,valore1,nome2,valore2,nome3,valore3) {
	form = window.opener.top.document.forms[0];
	var campo1 = form.elements[nome1];
	if(undefined != campo1){
		campo1.value = valore1;
	}
	var campo2 = form.elements[nome2];
	if(undefined != campo2){
		campo2.value = valore2;
	}
	var campo3 = form.elements[nome3];
	if(undefined != campo3){
		campo3.value = valore3;
	}
	
	/*
	* Se esiste una funzione nella finestra chiamante con nome = postPopup_xxx
	* dove xxx è il nome del puntatore associato al poup, la eseguo.
	*/
	try{
		var pos = nome1.indexOf(".value")
		if(pos != -1)
			nome1 = nome1.substring(0, pos);

		eval("var dummy=window.opener.top.postPopup_" + nome1 + "();");
	} catch (e){
	}
	
	window.close();
	return false;
}
function popupWindow(anchor,fieldName,url) {
	var popup = new PopupWindow();
	var nomeCampo = document.forms[0].elements[fieldName];
	popup.setSize(700, 350);
	popup.offsetX = -150;
	popup.autoHide();					      					
	popup.setUrl(url+nomeCampo.value);
	popup.showPopup(anchor);
	return false;
}

function popupWindowParam(anchor,url,width,heigth) {

		windowProperties = "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable,alwaysRaised,dependent,titlebar=no";
		var popup = new PopupWindow();
		popup.setSize(width,heigth);
		popup.setWindowProperties(windowProperties);
		popup.autoHide();
		popup.setUrl(url);					
		popup.showPopup(anchor);
		return false;					
	
	}


/* Controlla la lunghezza massima di un textarea */	
function textLimit(field, maxlen) {
	/* sostituisco le accentate con le lettere apostrofate per risolvere il problema in fase di stampa*/
	var testo =field.value;
	var a = replaceAll(testo,"à","a'");
	var b = replaceAll(a,"è","e'");
	var c = replaceAll(b,"é","e'");
	var d = replaceAll(c,"ì","i'");	
	var e = replaceAll(d,"ò","o'");
	var f = replaceAll(e,"ù","u'");
	var g = replaceAll(f,"À","A'");
	var h = replaceAll(g,"È","E'");
	var i = replaceAll(h,"É","E'");
	var l = replaceAll(i,"Ì","I'");
	var m = replaceAll(l,"Ò","O'");
	var n = replaceAll(m,"Ù","U'");

	if(testo !=n){

		field.value = n;
	}
	if (field.value.length > maxlen){
		field.value = field.value.substring(0, maxlen);
	}	
	
}

/* funzioni per la gestione dello style dei bottoni disabled */
document.getElementsByClassName = function(clsName){
   var retVal = new Array();
   var elements = document.getElementsByTagName("*");
   for(var i = 0;i < elements.length;i++){
       if(elements[i].className.indexOf(" ") >= 0){
           var classes = elements[i].className.split(" ");
           for(var j = 0;j < classes.length;j++){
               if(classes[j] == clsName)
                   retVal.push(elements[i]);
           }
       }else if(elements[i].className == clsName)
           retVal.push(elements[i]);
   }
   return retVal;
}

function spegniBottone(){
	
	var getClass = document.getElementsByClassName("bottone");	
    
    for (var i=0; i < getClass.length; i++){ 
		var laTable =  (getClass[i].parentNode.parentNode.parentNode.parentNode.nodeName == "TABLE");
     	
     	if(laTable){	
	     	///alert(getClass[i].value+" ----- DISABLED");
	     	getClass[i].parentNode.parentNode.parentNode.parentNode.className = "";
	     			
	    }if(laTable && getClass[i].disabled){
		    ///alert(getClass[i].value+" ----- ENABLED");
			getClass[i].parentNode.parentNode.parentNode.parentNode.className = "bottoneSpento";
  			
   	 }
   }
   
}

/* funzioni per la gestione del loading...*/

function startLoading(){
	try{
		document.getElementById("loading").style.display = "";
	}catch (e){}
}
function endLoading(){
	try{
		document.getElementById("loading").style.display = "none";
	}catch (e){}
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function openHelp(url){
	window.open(url,'Help','scrollbars=auto,resizable=no,width=980,height=580,status=no,location=no,toolbar=no');
	/*
	var popup = new PopupWindow();

	popup.setSize(980, 580);
	//popup.offsetX = -150;
	popup.autoHide();					      					
	
	popup.setUrl(url);
	popup.showPopup();
	*/
}

function apriHelp(context, numeroPagina){
	//alert('Help per la pagina ' + numeroPagina + ' ' + context);

	//window.open(context + "/help/help.jsp?pagina=" + numeroPagina, '', '');

	var popup = new PopupWindow();

	popup.setSize(800, 350);
	//popup.offsetX = -150;
	popup.autoHide();					      					
	popup.setUrl(context + "?pagina=" + numeroPagina);
	popup.showPopup("helpAnchor");
}

/*ELEMENTI MENU - visualizzazione commenti*/
function showTip(obj) 
{   if  (document.layers) 
    {   if  (document.layers[obj] != null) document.layers[obj].visibility = 'visible';
    }
    else 
    if  (document.all) document.all[obj].style.visibility = 'visible';
}
function hideTip(obj) 
{   if  (document.layers) 
    {   if (document.layers[obj] != null) document.layers[obj].visibility = 'hidden';
    }
    else 
    if  (document.all)
        document.all[obj].style.visibility = 'hidden';
}
/*fine - ELEMENTI MENU - visualizzazione commenti*/

function hideMenuButton(){
	
	if(window.name && window.name.indexOf("window_") != -1 && document.getElementById("tastoMenu")){
		// tastoMenu è uno span che si trova nella pagina exception.jsp
		document.getElementById("tastoMenu").style.display = "none";
	}		
}

/* funzioni di trim */
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

/* giusti per popup help */

/*-----------------------------------------------------------
   Toggles element's display value
   Input: any number of element id's
   Output: none 
   ---------------------------------------------------------*/
function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = $(arguments[i]);
        if (d.style.display == 'none')
            d.style.display = 'block';
        else
            d.style.display = 'none';
    }
}
/*-----------------------------------------------------------
    Toggles tabs - Closes any open tabs, and then opens current tab
    Input:     1.The number of the current tab
                    2.The number of tabs
                    3.(optional)The number of the tab to leave open
                    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
    Output: none 
    ---------------------------------------------------------*/
function toggleTab(num,numelems,opennum,animate) {
    if ($('tabContent'+num).style.display == 'none'){
        for (var i=1;i<=numelems;i++){
            if ((opennum == null) || (opennum != i)){
                var temph = 'tabHeader'+i;
                var h = $(temph);
                if (!h){
                    var h = $('tabHeaderActive');
                    h.id = temph;
                }
                var tempc = 'tabContent'+i;
                var c = $(tempc);
                if(c.style.display != 'none'){
                    if (animate || typeof animate == 'undefined')
                        Effect.toggle(tempc,'blind',{duration:0.5, queue:{scope:'menus', limit: 3}});
                    else
                        toggleDisp(tempc);
                }
            }
        }
        var h = $('tabHeader'+num);
        if (h)
            h.id = 'tabHeaderActive';
        h.blur();
        var c = $('tabContent'+num);
        c.style.marginTop = '2px';
        if (animate || typeof animate == 'undefined'){
            Effect.toggle('tabContent'+num,'blind',{duration:0.5, queue:{scope:'menus', position:'end', limit: 3}});
        }else{
            toggleDisp('tabContent'+num);
        }
    }
}

  var stile = "top=10, left=10, width=600, height=450, status=no, menubar=no, toolbar=no scrollbar=no";
     function Popup(apri) {
        window.open(apri.toLowerCase(), "", stile);
     }

	function Right(str, n){
	    if (n <= 0)
	       return "";
	    else if (n > String(str).length)
	       return str;
	    else {
	       var iLen = String(str).length;
	       return String(str).substring(iLen, iLen - n);
	    }
	}
