var IE = document.all?true:false;
IE8 = false;
IE7 = false;
IE6 = false;
if(IE){
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	if (ieversion>=8)IE8= true;
	else if (ieversion>=7)IE7 = true;
	else if (ieversion>=6)IE6 = true;
	}
}
var position = window.location.href;
var urlBaseTemplate = position.substring(0,position.indexOf("portal"));
urlBaseTemplate += "portal/template/viewTemplate?templateId=";
var pathUrlIcone = "/lcms/images/"; 
var iconaDelete = "delete.png";
var iconaCheck = "check.png";
var iconaInformation = "information.png";
var iconaError = 'error.png';
var iconaFind = "find.png";
var iconaDataInto = "data_into.png";
var iconaBookBlue = "book_blue.png";
var iconaChecks = "checks.png";
var iconaFindNext = "find_next.png";
var iconaAttivi = "user1.png";
var iconaDisattivi= "user1_delete.png";
var iconaImporta = "user1_into.png";
var iconaEsporta = "user1_back.png";
var iconaAbilitati= "book_blue.png";
var iconaDisabilitati = "book_blue_delete.png";
var iconaStatistiche = "chart.png";
var iconaStatoConcluso = "book_blue_preferences.png";
var iconaStatoAperto = "book_open.png";
var iconaRefesh = "refresh.png";
var iconaUndo = "undo.png";
var iconaLink = "earth.png";
var iconaLiberoKey = 'flag_blue.png';
var iconaAInvitoKey = 'calendar.png';
var iconaFlag = 'flag_blue.png';
var iconaLock = 'lock.png';
var iconaCalendario = 'calbtn.gif';
var iconaMail = 'mail.png';
var iconaUserPreferences = 'user1_preferences.png';
var iconaExpandAll = "expand-all.gif";
var iconaCollapseAll = "collapse-all.gif";
var iconaRuoloAdmin= "businessman.png";
var iconaRuoloGlobalAdmin = "businessman2.png";
var iconaRuoloTutor= "worker.png";
var iconaRuoloStats= "user_headset.png";
var iconaRuoloUser= "user1.png";

var costantRoleAdmin = "CLIENT_ADMINISTRATOR";
var costantRoleGlobalAdmin = "ADMINISTRATOR";
var costantRoleTutor = "TUTOR";
var costantRoleStats = "STATS";
var costantRoleUser = "USER";

var bottoneAnnulla = '<span  style="padding-left: 2em; background: url('+pathUrlIcone+iconaDelete+') 0% 35% no-repeat;">' + strLangAnnulla +'</span>';
var bottoneSi = '<span  style="padding-left: 2em; background: url('+pathUrlIcone+ iconaCheck +') 0% 35% no-repeat;">' + strLangSi + '</span>';
var bottoneNo = '<span  style="padding-left: 2em; background: url('+pathUrlIcone+iconaDelete+') 0% 35% no-repeat;">' + strLangNo + '</span>';


/////*********** REGEXP *********////
var integerTest = /^\d+$/; // controlla se la stringa è formata solo da numeri
//controlla la data che il formato sia d/m/yyyy o dd/mm/yyyy e controlla pure se dd è corretto in corrispondenza del mese ( pure se febbraio in quell'anno ha 28 o 29 giorni)
var dateTest = /^((((0?[1-9]|[12]\d|3[01])[\/](0?[13578]|1[02])[\/]((1[6-9]|[2-9]\d)?\d{4}))|((0?[1-9]|[12]\d|30)[\/](0?[13456789]|1[012])[\/]((1[6-9]|[2-9]\d)?\d{4}))|((0?[1-9]|1\d|2[0-8])[\/]0?2[\/]((1[6-9]|[2-9]\d)?\d{4}))|(29[\/]0?2[\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{4}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{4}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{4}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
//controlla se il formato è h:mm o hh:mm
var timeTest = /^([0-1]?[0-9]|[2][0-3])(:([0-5][0-9])){1,2}$/;
//controlla le mail
var emailTest = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
//serve per vedere se c'è nella stringa (datasource) un template
//utilizzato nell'esporta per aggiungere al template l'url completo
var templateTest = /[']+[a-zA-Z0-9]+[_layout_]+[a-zA-Z0-9]+[.]psml[']/;
///////////////////////////////////////

divHeaderConferma =  '<div class=\"hd\"><span  style="padding-left: 1.8em; background: url('+pathUrlIcone+iconaInformation+') 0% 35% no-repeat;">' + strLangConfirm + '</span></div>';
divHeaderError =  '<div class=\"hd\"><span  style="padding-left: 1.8em; background: url('+pathUrlIcone+iconaError+') 0% 35% no-repeat;">' + strLangError + '</span></div>';


var bottoneCerca = '<span  style="padding-left: 2em; background: url('+pathUrlIcone+iconaFind+') 0% 35% no-repeat;">' + strLangCerca + '</span>';
var bottoneEsporta = '<span  style="padding-left: 2em; background: url('+pathUrlIcone+iconaDataInto+') 0% 35% no-repeat;">' + strLangEsporta + '</span>';
var bottoneCercaEsporta = '<span  style="padding-left: 2em; background: url('+pathUrlIcone+iconaDataInto+') 0% 35% no-repeat;">' + strLangCercaEsporta + '</span>';
var bottoneNewCliente = '<span>' + strLangNewClient + '</span>';
var bottoneNewUtente = '<span>' + strLangNewUtente + '</span>';
var bottoneNewGruppo = '<span>' + strLangNewGruppo + '</span>';
var bottoneModifca = '<span>' + strLangModifica + '</span>';
var bottoneModifica = '<span>' + strLangModifica + '</span>';
var bottoneElimina = '<span>' + strLangElimina + '</span>';
var bottoneDettaglio = '<span>' + strLangDettaglio + '</span>';
var bottoneApri = '<span>' + strLangApri + '</span>';
var bottoneSalva = '<span>' + strLangSalva + '</span>';
var bottoneSfoglia = '<span>' + strLangSfoglia + '</span>';
var bottoneAnnulla2 = '<span>' + strLangAnnullaCaps + '</span>';
var bottoneChiudi = '<span>' + strLangChiudi + '</span>';
var bottoneAggiungi = '<span>' + strLangAggiungi + '</span>';
var bottoneRimuovi = '<span>' + strLangRimuovi + '</span>';
var bottoneStatisticheCorso = '<span>' + strStatisticheCorso + '</span>';
var bottoneNuovo = '<span>' + strLangNuovo + '</span>';
var bottoneImporta = '<span>' + strLangImporta + '</span>';
var bottonePulisci = '<span>' + strLangPulisci + '</span>';
var bottoneAbilita = '<span>' + strLangAbilita + '</span>';
var bottoneDisabilita = '<span>' + strLangDisabilita + '</span>';
var bottoneOK = '<span>' + strLangOK + '</span>';
var bottoneAssocia = '<span>' + strLangAssociaCliente + '</span>';
var bottoneStatistiche = '<span>' + strStatistiche + '</span>';
var bottoneMandaInvito = '<span>' + strMandaInvito + '</span>';
var bottoneModificaInvito = '<span>' + strLangModificaInvito + '</span>';
var bottoneIndietro = '<span>' + strLangIndietro + '</span>';
var bottoneProcedi = '<span>' + strLangProcedi + '</span>';
var bottoneAggiungiClasse = '<span>' + strLangAggiungiClasse + '</span>';
var bottoneRimuoviClasse = '<span>' + strLangRimuoviClasse + '</span>';
var bottoneInvia = '<span>'+strLangInvia+'</span>';
var bottoneAssociaTutor = '<span>'+strLangAssociaTutor+'</span>';
var bottoneConferma = '<span>'+strLangConferma+'</span>';
var bottoneRispondiInvito = '<span>'+strLangRispondiInvito+'</span>';
var bottoneCalendario = '<span><img src='+ pathUrlIcone + iconaCalendario+'></img></span>';
var bottoneCarrieraDidattica =  '<span  style="padding-left: 2em; background: url('+pathUrlIcone+iconaBookBlue+') 0% 35% no-repeat;">' + strLangCarrieraDidattica + '</span>';
var bottoneVaiAlCorso =  '<span>' + strLangVaiAlCorso + '</span>';
var bottoneRipristina =  '<span>' + strLangRipristina + '</span>';
var bottoneImportaCorsoScorm =  '<span>' + strBottoneImportaCorsoScorm + '</span>';
var bottoneSottopacchetti =  '<span>' + strLangSottopacchetti + '</span>';
var bottoneDipendenze =  '<span>' + strLangDipendenze + '</span>';
var bottoneRuoli =  '<span>' + strLangRuoli + '</span>';
var bottoneSalvaOrdine =  '<span>' + strLangSaveOrder + '</span>';

//funzion eper fare chiamata al server non c'è bisogno di farla OOP
function sendToServer(datiDaInviare,callback,url){
	YAHOO.util.Connect.asyncRequest("POST" , url , callback , datiDaInviare);
}

/**
* 
*Initialize cells format
*formatta il contenuto delle celle, utilizzato LCMS 
*/
function initFormatter(){
	/*
	*modify yahoo default format for the single cell
	*/

	YAHOO.widget.DataTable.formatDefault = function(elCell, oRecord, oColumn, oData) {
		var text = oData;
		elCell.innerHTML = "<span>" + text + "</span>";
		elCell.parentNode.style.textAlign = "center";
	};
	myCustomFormatter = function(elCell, oRecord, oColumn, oData) {
		if(oColumn.getKey() == recordDBCorso) { // recordDBCorso: column name comming from the server for course name
			if(oRecord.getData(recordDBTipoCorso) == "1" ) {
				elCell.innerHTML = "<span  style=\"padding-left: 2em; background: url("+ pathUrlIcone + iconaLock+") 0% 0% no-repeat;\">"+oRecord.getData(recordDBCorso)+"</span>";
				elCell.parentNode.style.textAlign = "left";
			}else if(oRecord.getData(recordDBTipoCorso) == "0" ) {
				elCell.innerHTML = "<span  style=\"padding-left: 2em; background: url("+ pathUrlIcone + iconaFlag+") 0% 0% no-repeat;\">"+oRecord.getData(recordDBCorso)+"</span>";
				elCell.parentNode.style.textAlign = "left";
			}else if(oRecord.getData(recordDBTipoCorso) == "FREE" ) {
				elCell.innerHTML = "<span  style=\"padding-left: 2em; background: url("+ pathUrlIcone + iconaFlag+") 0% 0% no-repeat;\">"+oRecord.getData(recordDBCorso)+"</span>";
				elCell.parentNode.style.textAlign = "left";
			}else if(oRecord.getData(recordDBTipoCorso) == "REPLIED" ) {
				elCell.innerHTML = "<span  style=\"padding-left: 2em; background: url("+ pathUrlIcone + iconaLock+") 0% 0% no-repeat;\">"+oRecord.getData(recordDBCorso)+"</span>";
				elCell.parentNode.style.textAlign = "left";
			}else if(oRecord.getData(recordDBTipoCorso) == "INVITED" ) {
				elCell.innerHTML = "<span  style=\"padding-left: 2em; background: url("+ pathUrlIcone + iconaMail+") 0% 0% no-repeat;\">"+oRecord.getData(recordDBCorso)+"</span>";
				elCell.parentNode.style.textAlign = "left";
			}else{
				elCell.innerHTML = "<span>"+oRecord.getData(recordDBCorso)+"</span>";
				elCell.parentNode.style.textAlign = "left";
			}
		}else if(oColumn.getKey() == recordDBUserId) { 
			if(oRecord.getData(recordDBRole) == costantRoleAdmin ) {
				elCell.innerHTML = "<span title='"+strLANGRolePanelAdmin+"' style=\"padding-left: 2em; background: url("+ pathUrlIcone + iconaRuoloAdmin+") 0% 0% no-repeat;\">"+oRecord.getData(recordDBUserId)+"</span>";
				elCell.parentNode.style.textAlign = "left";
			}else if(oRecord.getData(recordDBRole) == costantRoleGlobalAdmin ) {
				elCell.innerHTML = "<span title='"+strLANGRolePanelGloablAdmin+"'  style=\"padding-left: 2em; background: url("+ pathUrlIcone + iconaRuoloGlobalAdmin+") 0% 0% no-repeat;\">"+oRecord.getData(recordDBUserId)+"</span>";
				elCell.parentNode.style.textAlign = "left";
			}else if(oRecord.getData(recordDBRole) == costantRoleTutor ) {
				elCell.innerHTML = "<span title='"+strLANGRolePanelTutor+"' style=\"padding-left: 2em; background: url("+ pathUrlIcone + iconaRuoloTutor+") 0% 0% no-repeat;\">"+oRecord.getData(recordDBUserId)+"</span>";
				elCell.parentNode.style.textAlign = "left";
			}else if(oRecord.getData(recordDBRole) == costantRoleStats ) {
				elCell.innerHTML = "<span title='"+strLANGRolePanelStats+"' style=\"padding-left: 2em; background: url("+ pathUrlIcone + iconaRuoloStats+") 0% 0% no-repeat;\">"+oRecord.getData(recordDBUserId)+"</span>";
				elCell.parentNode.style.textAlign = "left";
			}else if(oRecord.getData(recordDBRole) == costantRoleUser ) {
				elCell.innerHTML = "<span title='"+strLANGRolePanelUser+"' style=\"padding-left: 2em; background: url("+ pathUrlIcone + iconaRuoloUser+") 0% 0% no-repeat;\">"+oRecord.getData(recordDBUserId)+"</span>";
				elCell.parentNode.style.textAlign = "left";
			}else{
				elCell.innerHTML = "<span>"+oRecord.getData(recordDBUserId)+"</span>";
				elCell.parentNode.style.textAlign = "left";
			}
		}else if(oColumn.getKey() == recordDBTipologia) { // recordDBTipologia :  cell corriponde to "Tipologia corso"
			if(oRecord.getData(recordDBTipologia) == "1" ) {
				elCell.innerHTML = "<img alt='"+strLangAInvito+"' title='"+strLangAInvito+"' src="+ pathUrlIcone + iconaLock+"></img>";
				elCell.parentNode.style.textAlign = "center";
			}else if(oRecord.getData(recordDBTipologia) == "0" ) {
				elCell.innerHTML = "<img alt='"+strLangLibero+"' title='"+strLangLibero+"' src="+ pathUrlIcone + iconaFlag+"></img>";
				elCell.parentNode.style.textAlign = "center";
			}else {
				elCell.innerHTML = "<span>"+oRecord.getData(recordDBTipologia)+"</span>";
				elCell.parentNode.style.textAlign = "center";
			}
		}else if(oColumn.getKey() == recordDBRisposta) { 
			if(oRecord.getData(recordDBRisposta) == "1") {
				elCell.innerHTML = "<img alt='"+oRecord.getData(recordDBRisposta)+"' title='"+oRecord.getData(recordDBRisposta)+"' src="+ pathUrlIcone + iconaCheck+"></img>";
				elCell.parentNode.style.textAlign = "center";
			}else if(oRecord.getData(recordDBRisposta) == "0") {
				elCell.innerHTML = "<img alt='"+oRecord.getData(recordDBRisposta)+"' title='"+oRecord.getData(recordDBRisposta)+"' src="+ pathUrlIcone + iconaDelete+"></img>";
				elCell.parentNode.style.textAlign = "center";
			}else{
				elCell.innerHTML = "<span>"+oRecord.getData(recordDBRisposta)+"</span>";
				elCell.parentNode.style.textAlign = "center";
			}
		}else if(oColumn.getKey() == recordDBStatoCorso) {
			if(oRecord.getData(recordDBStatoCorso) == "completed") {
				elCell.innerHTML = "<img alt='"+strLangCompleted+"' title='"+strLangCompleted+"' src="+ pathUrlIcone + iconaStatoConcluso+"></img>";
				elCell.parentNode.style.textAlign = "center";
			}else{
				elCell.innerHTML = "<img alt='"+strLangAperto+"' title='"+strLangAperto+"' src="+ pathUrlIcone + iconaStatoAperto+"></img>";
				elCell.parentNode.style.textAlign = "center";
			}
		}else if(oColumn.getKey() == recordDBTemplate ) {
			my_text = oRecord.getData(recordDBTemplate);
			if(my_text != undefined && my_text.substr(0,7)!="http://" && my_text != "N. D."){
				my_text = urlBaseTemplate + my_text;
			}
			if(my_text != "N. D."){
				elCell.innerHTML = "<a style='text-decoration:none;' target='_blank' href='"+my_text+"'><img title='"+my_text+"'  alt='"+my_text+"' style='border:none' src="+ pathUrlIcone + iconaLink+"></img></a>";
			}else{
				elCell.innerHTML = "<span>"+my_text+"</span>";
			}
			elCell.parentNode.style.textAlign = "center";
		}else if(oColumn.getKey() == recordDBLink) {
			my_text = oRecord.getData(recordDBLink);
			if(my_text.indexOf("http://") == -1 && my_text.indexOf("_layout_")!= -1)my_text = urlBaseTemplate + my_text;
			if(my_text.indexOf("http://") == -1 && my_text.indexOf("_layout_")== -1)my_text = "http://" + my_text;	
			if(my_text != "N. D."){
				elCell.innerHTML = "<a style='text-decoration:none;' target='_blank' href='"+my_text+"'><img title='"+my_text+"'  alt='"+my_text+"' style='border:none' src="+ pathUrlIcone + iconaLink+"></img></a>";
			}else{
				elCell.innerHTML = "<span>"+my_text+"</span>";
			}
			elCell.parentNode.style.textAlign = "center";
		}else if(oColumn.getKey() == tipologiaKey) { // no more used
			if(oRecord.getData(tipologiaKey) == tipologiaLiberoKey){
				icona = iconaLiberoKey;
			}else{
				icona = iconaAInvitoKey;
			}
		elCell.innerHTML = "<img title='" +oRecord.getData(tipologiaKey)+"' alt='" +oRecord.getData(tipologiaKey)+"' style='border:none' src="+ pathUrlIcone + icona+"    title='" +oRecord.getData(tipologiaKey)+"'></img>";
		elCell.parentNode.style.textAlign = "center";
		}
		else if(oRecord.getData(recordDBStato) == "CONFIRMED") {
			elCell.innerHTML = "<img alt='"+strLangIconaConfirmed+"' title='"+strLangIconaConfirmed+"' src="+ pathUrlIcone + iconaUserPreferences+"></img>";
			elCell.parentNode.style.textAlign = "center";
		}
		else if(oRecord.getData(recordDBStato) == "DISABLED") {
			elCell.innerHTML = "<img alt='"+strLangIconaDisabled+"' title='"+strLangIconaDisabled+"' src="+ pathUrlIcone + iconaDisattivi+"></img>";
			elCell.parentNode.style.textAlign = "center";
		}	else  {
			elCell.innerHTML = "<span>" + oRecord.getData(recordDBStato) + "</span>";
			elCell.parentNode.style.textAlign = "center";
		}
		//elCell.parentNode.style.textAlign = "center";
	};
	YAHOO.widget.DataTable.Formatter.myCustom = myCustomFormatter; 

	myCustomDate = function(elCell, oRecord, oColumn, oData) { // no more used
		data = oRecord.getData(oColumn.key)
		/*dataArr = data.split("-");
		dataOut = dataArr[2] + "/" + dataArr[1] + "/" + dataArr[0]; */
		//dataOut = data.replace(/-/g,"/");
		elCell.innerHTML = data;
	elCell.parentNode.style.textAlign = "center";

	};
	YAHOO.widget.DataTable.Formatter.myCustomDate = myCustomDate; 

}
//crea dato source e memorizza  parametri (key) (RICREATO IN ALTRO FILE OOP)
function createDataSource(strDataSource,bool){
	if(bool == true){
		saveDataSource(strDataSource);
	}
	param = [];
	try {
		strDataSource = strDataSource.replace(/§ç/g , ":");
		strDataSource = strDataSource.replace(/§§/g , ",");
	} catch (e) {
		// TODO: handle exception
	}
	try {
		data_source ="";
		data_source = eval(strDataSource);
	} catch (e) {
		// TODO: handle exception
	}
	try {

		var a = strDataSource.split("{");
		var b = a[1].split("}");
		b = b[0].split(",");
		for(i=0; i < b.length ; i++){
			var c = b[i];
			c = c.split(":");
			c[0] = c[0].split(" ").join("");
			param.push(c[0].split("'").join(""));
		}
	} catch (e) {
		// TODO: handle exception
	}

	return data_source;
}
// controlla una stringa se è vuot ainserisce "N. D."(ora il  controllo viene effettuato lato server)
function controlEmptyString(str){
	var a = str;
	if(str == "null" || str == "" || str == null || str == undefined){
		str = "N. D.";
	}
	return str;
}
// crea delle label specifiche alle colonne per LCMS 
function getLabelForColumnDef(columnDef){
	text = "";
	for( i = 0; i < columnDef.length; i++){
		if(columnDef[i]== recordDBCliente){
			text = strLangCliente;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaNewEditClient+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}else if(columnDef[i]== recordDBCorsiInvito){
			text = strLangCorsiInvito;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaLock+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}
		else if(columnDef[i]== recordDBCorsiLiberi){
			text = strLangCorsiLiberi;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaFlag+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
			//paramLabel[i]= '<span>' + text.toUpperCase() + '</span>';
		}
		else if(columnDef[i]== recordDBGruppi || columnDef[i]== recordDBUserId || columnDef[i]== recordDBGroupName){
			if(columnDef[i]== recordDBGruppi)text=strLangGruppi;
			else if(columnDef[i]== recordDBGroupName)text=strLangGruppi;
			else text=strLangUserId;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaNewEditGruppo+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}
		else if(columnDef[i]== recordDBAbilitati){
			text=strLangAbilitati;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaAbilitati+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}
		else if(columnDef[i]== recordDBDisabilitati){
			text = strLangDisabilitati;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaDisabilitati+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}
		else if(columnDef[i]== recordDBCorso || columnDef[i]== recordDBCConclusi || columnDef[i]== recordDBObjName){
			if(columnDef[i]== recordDBCorso || columnDef[i]== recordDBObjName)text=strLangCorso;
			else text=strLangCConclusi;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaBookBlue+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}
		else if(columnDef[i]== recordDBDisattivi){
			text = strLangDisattivi;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaDisattivi+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}
		else if(columnDef[i]== recordDBAttivi){
			text=strLangAttivi;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaUserPreferences+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}
		else if( columnDef[i]== recordDBFullname){
			text=strLangNome;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaAttivi+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}
		else if(columnDef[i]== recordDBCAperti){
			text = strLangCAperti;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaStatoAperto+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}else if(columnDef[i]== recordDBNome){
			text = strLangNome;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaAttivi+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}else if(columnDef[i]== recordDBCognome){
			text = strLangCognome;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaAttivi+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}else if(columnDef[i]== recordDBTipologia || columnDef[i]== recordDBStato || columnDef[i]== recordDBStatoCorso){
			if(columnDef[i]== recordDBTipologia)text=strLangTipologia;
			else if(columnDef[i]== recordDBStato)text=strLangStato;
			else text=strLangStato;
			paramLabel[i]= '<span  style=\'background: url('+pathUrlIcone+iconaChecks+') 0% 35% no-repeat; width:20px;\'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ' + text.toUpperCase() + '</span>';
		}else{
			if(columnDef[i]== recordDBClienti)text=strLangClienti;
			else if(columnDef[i]== recordDBLink)text=strLangLink;
			else if(columnDef[i]== recordDBUtenti)text=strLangUtenti;
			else if(columnDef[i]== recordDBValidita)text=strLangValidita;
			else if(columnDef[i]== recordDBDataInizio)text=strLangDataInizio;
			else if(columnDef[i]== recordDBDataFine)text=strLangDataFine;
			else if(columnDef[i]== recordDBTest)text=strLangTest;
			else if(columnDef[i]== recordDBNomeCorso)text=strLangNome;
			else if(columnDef[i]== recordDBEndDate)text=strLangDataFine;
			else if(columnDef[i]== recordDBStartDate)text=strLangDataInizio;
			else if(columnDef[i]== recordDBTemplate)text=strLangAttestato;
			else if(columnDef[i]== recordDBNome)text=strLangNome;
			else if(columnDef[i]== recordDBCognome)text=strLangCognome;
			else if(columnDef[i]== recordDBEMail)text=strLangEMail;
			else if(columnDef[i]== recordDBDal)text=strLangDal;
			else if(columnDef[i]== recordDBAl)text=strLangAl;
			else if(columnDef[i]== recordDBInviti)text=strLangInviti;
			else if(columnDef[i]== recordDBRisposte)text=strLangRisposte;
			else if(columnDef[i]== recordDBRisposteG)text=strLangRisposteG;
			else if(columnDef[i]== recordDBDataRisposta)text=strLangDataRisposta;
			else if(columnDef[i]== recordDBFirstLesson)text=strLangFirstLesson;
			else if(columnDef[i]== recordDBRisposta)text=strLangRisposta;
			else if(columnDef[i]== recordDBGruppoId)text=strLangGruppoId;
			else if(columnDef[i]== recordDBClienteId)text=strLangIDCliente;
			else if(columnDef[i]== recordDBCorsoId)text=strLangID;
			else if(columnDef[i]== recordDBSlaveName)text=strLangNome;
			else text=columnDef[i];
			paramLabel[i]= '<span>' + text.toUpperCase() + '</span>';
		}
	}


}
//NON OOP DA ELIMINARE
function tabellaTestInit(divID,pagination,resizable,sortable,datasource,columDef,columnWidth,tableHeader,divPagination,tableHeaderId){
	if(divPagination == null || divPagination == undefined)divPagination = tablePaginationID;
	if(resizable == null)resizable = true;
	if(sortable == null)sortable = true;
	if(datasource == null)datasource = data_source;
	if(columDef != null)param = columDef;  // param is the array of db coloumns name  
	if(columnWidth != null)arrWidth = columnWidth;
	if(tableHeaderId == null)tableHeaderId = tableHeaderID;
	myDivTabella = document.getElementById(divID);
	tableStyle = myDivTabella.style;
	if(tableFirstHeigth){tableOriginalHeight = tableStyle.height; tableFirstHeigth = false;}
	if(tableFirstWidth){tableOriginalWidth = tableStyle.width; tableFirstWidth = false;}
	if(tableHeader != undefined & tableHeader != ""){
		tableStyle.height = parseInt(tableOriginalHeight) - 20 + "px";
		tableHeight = parseInt(tableStyle.height) - 30 + "px";
		document.getElementById(tableHeaderId).innerHTML = tableHeader;
	}else{
		tableStyle.height = parseInt(tableOriginalHeight)+ "px";
		document.getElementById(tableHeaderId).innerHTML = tableHeader;
		tableHeight = parseInt(tableStyle.height) - 30 + "px";
	}
	if(pagination == true){
		tableStyle.height = parseInt(tableStyle.height) - 24 + "px";
		tableHeight = parseInt(tableHeight) - 30 + "px";
	}
	// set the global var paramLabel which is an array of column label   
	getLabelForColumnDef(param);
	tableWidth = parseInt(tableOriginalWidth) - 100 + "px";

//	strColumnDef = '[   {key:"nome",formatter:YAHOO.widget.DataTable.formatDefault, sortable:true, resizeable:true},     {key:"data", formatter:"myCustomDate",sortable:true/*,formatter:"date"*/ ,resizeable:true},     {key:"corso",formatter:YAHOO.widget.DataTable.formatDefault, sortable:true, resizeable:true},     {key:"stato", formatter:"myCustom", sortable:true, resizeable:true},     {key:"tipo",formatter:YAHOO.widget.DataTable.formatDefault, sortable:true, resizeable:true}     ]';    
	var strColumnDef ='[';
	k = 0;
	// definition for all column
	for( i = 0; i < param.length; i++){
		if(param[i]!= idKey){
			myWidth = arrWidth[k]*parseInt(tableWidth,10);
			k += 1;
			strColumnDef += '{key:"'+param[i] +'",label:"'+paramLabel[i] +'",sortable:'+ sortable + ', resizeable: '+ resizable +',width:'+myWidth;
			if(param[i] == recordDBStato){
				strColumnDef += ',formatter:"myCustom"},';
			}else if(param[i] == dataKey){
				strColumnDef += ',formatter:"myCustomDate"},';
			}else if(param[i] == recordDBDataInizio){
				strColumnDef += ',formatter:"myCustomDate"},';
			}else if(param[i] == recordDBDataFine){
				strColumnDef += ',formatter:"myCustomDate"},';
			}else if(param[i] == recordDBLink){
				strColumnDef += ',formatter:"myCustom"},';
			}else if(param[i] == recordDBTemplate){
				strColumnDef += ',formatter:"myCustom"},';
			}else if(param[i] == tipologiaKey){
				strColumnDef += ',formatter:"myCustom"},';
			}else if(param[i] == recordDBStatoCorso){
				strColumnDef += ',formatter:"myCustom"},';
			}else if(param[i] == recordDBTipologia){
				strColumnDef += ',formatter:"myCustom"},';
			}else if(param[i] == recordDBCorso){
				strColumnDef += ',formatter:"myCustom"},';
			}else if(param[i] == recordDBRisposta){
				strColumnDef += ',formatter:"myCustom"},';
			}else if(param[i] == recordDBUserId){
				strColumnDef += ',formatter:"myCustom"},';
			}else{
				strColumnDef += ',formatter:YAHOO.widget.DataTable.formatDefault},';
			}

		}
	}
	strColumnDef = strColumnDef.substr(0,strColumnDef.length-1);
	strColumnDef +=']';


	var myColumnDefs = eval(strColumnDef);

	var strResp ='{fields: [';
	for( i = 0; i < param.length; i++){
		strResp += 	'{key:"'+ param[i] +'"},';
	}
	strResp = strResp.substr(0,strResp.length-1);
	strResp +=']}';

	var selectFirstRecordInCurrentPage = function(){
		try {
			firstRow = testTabella.getFirstTrEl();  
			testTabella.unselectAllRows();
			testTabella.selectRow(firstRow);
		} catch (e) {
		}
	};

	testDataSource = new YAHOO.util.DataSource(datasource);
	testDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
	testDataSource.responseSchema = eval(strResp);
	// calculate how many records the table can contain in a single page
	paginationRow = 0;
	if(pagination == true){
		paginationRow = parseInt(parseInt(tableStyle.height,10)/23-2,10);
		myPaginator = new YAHOO.widget.Paginator({containers:[divPagination],rowsPerPage:paginationRow})
		var oConfig = {selectionMode:"single",
			/*maxHeight:tableHeight,
			width:tableWidth, 
			scrollable:true,*/
			paginator: myPaginator
		/* dateOptions:{format:"%d/%m/%Y"}*/};
		//myPaginator.subscribe("changeRequest", selectFirstRecordInCurrentPage);

	}else{
		var oConfig = {selectionMode:"single",
				height:tableHeight,
				/*width:tableWidth, */
				scrollable:true				
		/* dateOptions:{format:"%d/%m/%Y"}*/};	

		document.getElementById(tablePaginationID).innerHTML = "<!-- DIV -->";
	}
	testTabella = new YAHOO.widget.DataTable(divID,
			myColumnDefs, testDataSource ,oConfig);
	//yahoo.util.recordset
	records = testTabella.getRecordSet();
	testTabella.subscribe("rowMouseoverEvent", testTabella.onEventHighlightRow);
	testTabella.subscribe("rowMouseoutEvent", testTabella.onEventUnhighlightRow);
	testTabella.subscribe("rowClickEvent",testTabella.onEventSelectRow);
	testTabella.subscribe("rowDblclickEvent",function(){nextTable();});
	if(pagination == true)testTabella.subscribe("postRenderEvent", selectFirstRecordInCurrentPage);
	// PER SELEZIONARE SUBITO LA PRIMA RIGA
	try {
		firstRow = testTabella.getFirstTrEl();  
		testTabella.selectRow(firstRow);
	} catch (e) {
	}

	testTabella.render();

}
//NON OOP DA ELIMINARE
function removeSelectedRow(row){
	return	testTabella.deleteRow(row);  
}
//NON OOP DA ELIMINARE
function getSelectedRow(){
	return	testTabella.getSelectedRows();  
}
//NON OOP DA ELIMINARE
function getRowRecord(row){
	return testTabella.getRecord(row);
}
//NON OOP DA ELIMINARE
function getRowRecordData(rec){
	return rec.getData();
}
//NON OOP DA ELIMINARE
function stringifyJSON(data){
	return YAHOO.lang.JSON.stringify(data);
}
//NON OOP DA ELIMINARE
function getTableRecordString(){
	myTableRecordSet = testTabella.getRecordSet();
	myRecordArr = myTableRecordSet.getRecords(0);
	var recordString = "";
	for ( var i = 0; i < myRecordArr.length; i++) {
		tmpRecordData = getRowRecordData(myRecordArr[i]);
		recordString += stringifyJSON(tmpRecordData);
	}
	return recordString;
}
// controlla se in un record è presente uno specifico valore  NON E' OOP
function matchRecord(recSet,key, valueKeyRef){
	var	aRecord = recSet.getRecords(0);
	aRecordDouble = [];
	for ( var i = 0; i < aRecord.length; i++) {
		var tmpRecordData = getSpecificRecordData(aRecord[i],key);
		if(tmpRecordData != null && tmpRecordData == valueKeyRef)aRecordDouble.push(aRecord[i]);
	}
	return aRecordDouble;
}
//NON OOP DA ELIMINARE
function getSpecificRecordData(rec,key){
	return rec.getData(key);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//NON OOP DA ELIMINARE
function crateYahooButton(divId, buttonId,clickEventHandler,paramentro,value){
	oNewNode = document.createElement("Button");
	oNewNode.id = buttonId
	document.getElementById(divId).appendChild(oNewNode);
	newYahooButton = new YAHOO.widget.Button(buttonId, {type:"push", id:buttonId,label:value, onclick:{fn:clickEventHandler,obj:paramentro}});
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
//crea un div e lo inserisce nel body
function fnAppendDiv(id,classe){
	var oNewNode = document.createElement("DIV");
	oNewNode.id=id;
	oNewNode.className=classe;
	document.body.appendChild(oNewNode);
}
//crea un error panel non è OOP ma va bene comunque non sarà mai multiplo ed è già specifico
function createErrorPanel(textPanel){
	errorPanelMask = document.getElementById('errorPanel_mask');
	if(errorPanelMask != null)errorPanelMask.parentNode.removeChild(errorPanelMask);

	fnAppendDiv("errorPanel","");
	divInnerPanel = divHeaderError;
	divInnerPanel += "<div class=\"bd\"></div>";
	divInnerPanel += "<div class=\"fd\"></div>";
	document.getElementById('errorPanel').innerHTML  = divInnerPanel;
	if(divClass != "")document.getElementById('errorPanel').className  =  divClass + document.getElementById('errorPanel').className;

	panelError = new YAHOO.widget.SimpleDialog("errorPanel", 
			{ width: "400px",
		fixedcenter: true,
		visible: true,
		draggable: true,
		close: true,
		zIndex: 100,
		modal: true,
		text: textPanel,
		constraintoviewport: true
			});
	panelError.hideEvent.unsubscribe();
	panelError.hideEvent.subscribe(function() {panelConfirm.destroy();} );
	panelError.bringToTop();
	panelError.render();
	document.getElementById('errorPanel_c').style.zIndex = document.getElementById('errorPanel_mask').style.zIndex +2;
}
//non OOP DA ELIMINARE
function createConfirmPanel(textPanel,handler){  		
	var handleConfirmYes = function() {
		panelConfirm.destroy();
		return true;
	};
	var handleConfirmNo = function() {
		panelConfirm.destroy();
		return false;
	};
	var handleConfirmAnnulla = function() {
		panelConfirm.destroy();
		this.hide();  
	};

	fnAppendDiv("confirmPanel","");
	divInnerPanel = divHeaderConferma;
	divInnerPanel += "<div class=\"bd\"></div>";
	divInnerPanel += "<div class=\"fd\"></div>";
	document.getElementById('confirmPanel').innerHTML  = divInnerPanel;
	if(divClass != "")document.getElementById('confirmPanel').className  =  divClass + document.getElementById('confirmPanel').className;

	panelConfirm = new YAHOO.widget.SimpleDialog("confirmPanel", 
			{ width: "300px",
		fixedcenter: true,
		visible: true,
		draggable: true,
		close: true,
		zIndex: 1000,
		modal: true,
		text: textPanel,
		constraintoviewport: true,
		buttons: [ { text:bottoneSi, handler:handler},
		           { text:bottoneNo, handler:handleConfirmNo }/*,
		{ text:bottoneAnnulla, handler:handleConfirmAnnulla }*/ ]
			} );
	panelConfirm.hideEvent.unsubscribe();
	panelConfirm.hideEvent.subscribe(function() {panelConfirm.destroy();} );
	panelConfirm.render();
}

//non OOP DA ELIMINARE
function createPanel(panelTitle,icona,widthCustom){
	if(widthCustom == null || widthCustom == undefined || widthCustom == "")widthCustom = "420px";
	fnAppendDiv("yahooPanel",""); 
	divInnerPanel2 = '<div class=\"hd\"><span  style="padding-left: 1.8em; background: url('+pathUrlIcone + icona +') 0% 50% no-repeat;">' + panelTitle + '</span></div>';
	divInnerPanel2 += "<div class=\"bd\" id=\"bdyahooPanel\" ></div>";
	divInnerPanel2 += "<div class=\"ft\" id=\"ftyahooPanel\"></div>";
	document.getElementById('yahooPanel').innerHTML  = divInnerPanel2;
	if(divClass != "")document.getElementById('yahooPanel').className  =  divClass + document.getElementById('yahooPanel').className;
	var handler = function() {
	};

	panelYahoo = new YAHOO.widget.Dialog("yahooPanel", 
			{ width : widthCustom,
		fixedcenter : true,
		visible : true, 
		cancel:true,
		modal:true,
		zIndex:10,
		constraintoviewport : true,
		draggable:true/*,
		buttons : [ { text: bottoneOK, handler:null},
		            { text:bottoneAnnulla, handler:null} ]*/
			} );

	panelYahoo.hideEvent.unsubscribe();
	panelYahoo.hideEvent.subscribe(function() {panelYahoo.destroy();} );
	panelYahoo.render();
}
//non OOP DA ELIMINARE
function createPanel2(panelTitle,icona,widthCustom){
	if(widthCustom == null || widthCustom == undefined || widthCustom == "")widthCustom = "420px";
	fnAppendDiv("yahooPanel2",""); 
	divInnerPanel2 = '<div class=\"hd\"><span  style="padding-left: 1.8em; background: url('+pathUrlIcone + icona +') 0% 50% no-repeat;">' + panelTitle + '</span></div>';
	divInnerPanel2 += "<div class=\"bd\" id=\"bodyyahooPanel2\" ></div>";
	divInnerPanel2 += "<div class=\"ft\" id=\"ftyahooPanel2\"></div>";
	document.getElementById('yahooPanel2').innerHTML  = divInnerPanel2;
	if(divClass != "")document.getElementById('yahooPanel2').className  =  divClass + document.getElementById('yahooPanel2').className;
	var handler = function() {

	};

	panelYahoo2 = new YAHOO.widget.Dialog("yahooPanel2", 
			{ width : widthCustom,
		fixedcenter : true,
		visible : true, 
		cancel:true,
		modal:true,
		constraintoviewport : true,
		draggable:true/*,
		buttons : [ { text: bottoneOK, handler:null},
		            { text:bottoneAnnulla, handler:null} ]*/
			} );

	panelYahoo2.hideEvent.unsubscribe();
	panelYahoo2.hideEvent.subscribe(function() {panelYahoo2.destroy();} );
	panelYahoo2.render();
	//yahooManager.register(propImagePanel);
}
//non OOP DA ELIMINARE
var destroyYahooPanel = function(){
	panelYahoo.destroy();
}
//non OOP DA ELIMINARE
var destroyYahooPanel2 = function(){
	panelYahoo2.destroy();
}


function createTableHTML(myId,myComp,myValue,cssclass,strLang){
	var text1 = " ";
	var text2 = " ";

	var metabody = document.getElementById(myId);
	metabody.innerHTML = "";
	metatable  = document.createElement("table");
	metatable.setAttribute("id", "myTableHTML");
	metatable.setAttribute("class", cssclass);
	metatablebody = document.createElement("tbody");
	mycurrent_row = document.createElement("tr");

	for(i=0; i< myComp.length; i++){
		text1 = myComp[i];
		text2 = myValue[i];
		//if(text2 == "")text2 = " ";
		mycurrent_row = document.createElement("tr");
		mycurrent_cell = document.createElement("td");
		//mycurrent_cell.onclick = function (evt) { editCell(this);};
		currenttext = document.createTextNode("");
		mycurrent_cell.appendChild(currenttext);
		mycurrent_cell.innerHTML= text1;
		mycurrent_row.appendChild(mycurrent_cell);
		mycurrent_cell = document.createElement("td");
		//	mycurrent_cell.setAttribute("id", myId + text1);
		if(text1 == strPanUtente_Password || text1 == strPanUtente_ConPassword){
			type = "password";
		}else{
			type = "text";
		}

		input = document.createElement('INPUT');
		input.setAttribute('value', text2);
		//	input.setAttribute('style', 'width:98%; border:none;');
		input.style.width = "98%";
		input.style.border = "none";
		input.setAttribute('type', type);
		input.setAttribute("id", myId + i);


		if(strLang == strLangModifica){
			if(i == 2 || i == 6){
				//	mycurrent_cell.style.color = "#A9A9A9";
				input.setAttribute('readonly', "readonly");
				input.style.color = "#A9A9A9";
				input.style.border = "1px solid white";
				input.style.bgColor = "#FFFFFF";
				input.setAttribute('style', 'width:98%; border:1px solid white; background-color:white');
			}else if(text2 == "..."){
				YAHOO.util.Event.addListener(input,'click',function (evt) { gestioneGruppiRequest(strLang);});
			}else{
				//	mycurrent_cell.onclick = function (evt) { editCell(this,"text");};
			}
		}else if(strLang == strLangNewUtente){
			if(i == 6){
				//		mycurrent_cell.style.color = "#A9A9A9";
				input.setAttribute('readonly', "readonly");
				input.style.color = "#A9A9A9";
				input.style.border = "1px solid white";
				input.style.bgColor = "#FFFFFF";
				input.setAttribute('style', 'width:98%; border:1px solid white; background-color:white');
			}else if(text2 == "..."){
				YAHOO.util.Event.addListener(input,'click',function (evt) { gestioneGruppiTable(strLang);});
			}else{
				//	mycurrent_cell.onclick = function (evt) { editCell(this,"text");};
			}
		}else if(strLang == strLangDettaglioUtente){
			if(text2 == "...") {
				YAHOO.util.Event.addListener(input,'click',function (evt) { gestioneGruppiRequest(strLang);});
			}else{
				input.setAttribute('readonly', "readonly");
			}
			input.style.border = "1px solid white";
			input.style.bgColor = "#FFFFFF";
			input.setAttribute('style', 'color:black; width:98%; border:1px solid white; background-color:white');
		}else if(strLang == strLangDettaglioCarriera){	
			if(text2 == "..."){
				YAHOO.util.Event.addListener(input,'click',function (evt) { gestioneGruppiRequest(strLang);});
			}else{
				input.setAttribute('readonly', "readonly");
			}
			input.style.border = "1px solid white";
			input.style.bgColor = "#FFFFFF";
			input.style.Color = "black";
			input.setAttribute('style', 'color:black; width:98%; border:1px solid white; background-color:white');
		}else if(strLang == strMandaInvito){	
			input.style.border = "1px solid white";
			input.style.bgColor = "#FFFFFF";
			input.style.Color = "black";
			input.setAttribute('style', 'color:black; width:98%; border:1px solid white; background-color:white');
			if(i == 0){
				input.setAttribute('readonly', "readonly");
				input.style.Color = "#A9A9A9";
			}
		}else if(strLang == strIlMioProfilo){	
			if(i == 2 || i == 6){
				input.setAttribute('readonly', "readonly");
				input.style.Color = "#A9A9A9";
			}else if(i == 7){
				// pannello il mio profilo riepilogo Clienti
				YAHOO.util.Event.addListener(input,'click',handleClientiIlMioProfilo);
			}else if(i == 8){
				// pannello il mio profilo riepilogo gruppi
				YAHOO.util.Event.addListener(input,'click',function (evt) {alert("riepilogo gruppi"); });
			}
			input.style.border = "1px solid white";
			input.style.bgColor = "#FFFFFF";
			input.style.Color = "black";
			input.setAttribute('style', 'color:black; width:98%; border:1px solid white; background-color:white');
		}else{
			//	mycurrent_cell.onclick = function (evt) { editCell(this,"text");};
		}
		//	if(text2 == "...") mycurrent_cell.onclick = function (evt) { gestioneGruppiTable(strLang);};
		mycurrent_cell.appendChild(input);
		currenttext = document.createTextNode("");
		mycurrent_cell.appendChild(currenttext);
		mycurrent_row.appendChild(mycurrent_cell);
		metatablebody.appendChild(mycurrent_row);
		metatable.appendChild(metatablebody);
		metabody.appendChild(metatable);
		if(strLang == strLangModificaCorso ){
			if(text1 == strPanCarriera_Tipologia) {
				input = document.createElement('select');
				input.setAttribute("id", myId + i);
				input.style.width = "98%";
				var a = document.getElementById(myId + i).parentNode;
				a.innerHTML = "";
				a.appendChild(input);
				addOptionToSelect(myId + i,strLangLibero,0);
				addOptionToSelect(myId +i,strLangAInvito,1);
				document.getElementById(myId + i).selectedIndex=text2;
			}
		}
	}
	dynTable = metatable;
}

function setCell (cell, value) {
	if (document.all){
		if(value == "")value = " ";
		cell.innerText = value;}
	else if (document.getElementById)
		try{ if(value == "")value = " ";
		cell.replaceChild(document.createTextNode(value), cell.firstChild);}catch(ex){;}
}

function editCell (cell, type) {
	if (document.all) {
		cell.innerHTML =
			'<INPUT ' +
			'type= ' + type+
			' ID="editCell"' +
			' ONCLICK="event.cancelBubble = true;"' + 
			' ONCHANGE="setCell(this.parentElement, this.value)" ' +
			' ONBLUR="setCell(this.parentElement, this.value)" ' +
			' VALUE="' + cell.innerText + '"' +
			' STYLE= "width:96%"' +
			'>';
		document.all.editCell.focus();
		document.all.editCell.select();
		selectedRow = cell.parentNode.rowIndex;
	}
	else if (document.getElementById) {
		cell.normalize();
		selectedRow = cell.parentNode.rowIndex ;
		var input = document.createElement('INPUT');
		input.setAttribute('value', cell.firstChild.nodeValue);
		input.setAttribute('style', 'width:98%');
		input.setAttribute('type', type);
		input.onchange = function (evt) { setCell(this.parentNode, 
				this.value); };
				input.onblur = function (evt) { setCell(this.parentNode, 
						this.value); };
						input.onclick = function (evt) { 
							evt.cancelBubble = true;
							if (evt.stopPropagation)
								evt.stopPropagation();
						};
						cell.replaceChild(input, cell.firstChild);
						input.focus();
						input.select();
	}

}
//delete row
function deleteSelectedRow(table, row)
{
	table.deleteRow(selectedRow);
}
//delete last row.
function deleteRow(table){
	if(table.rows.length >=2){
		noOfRows = table.rows.length;
		table.deleteRow(noOfRows-1);
	}
}

function insRowLast(table)
{
	//	noOfRpws in table.
	noOfRows = table.rows.length;
//	no of columns of last row.
	noOfCols = table.rows[noOfRows-1].cells.length;

//	insert row at last.
	var x=table.insertRow(noOfRows);
//	insert cells in row.
	for (var j = 0; j < noOfCols; j++) {
		newCell = x.insertCell(j);
//		make cell editable feature.
		newCell.onclick = function (evt) { editCell(this);};
		newCell.innerHTML= "&nbsp;";
	}
}
//aggiunge un option ad una select(dropdownlist)
function addOptionToSelect(selectId, text,value){
	var elOptNew = document.createElement('option');
	elOptNew.text = text;
	elOptNew.value = value;
	var elSel = document.getElementById(selectId);

	try {
		elSel.add(elOptNew, null);
	}
	catch(ex) {
		elSel.add(elOptNew); // IE only
	}
}
//rimuove tutte le options da una select(dropdown list) partendo da un id
function removeAllSelectOption(theSelId){
	var theSel = document.getElementById(theSelId);
	for(i=theSel.length-1; i>=0; i--)
	{
		theSel.options[i] = null;
	}

}

/**
* @param panelTitle <string>
* @param icona <string>
* @param panelText <string>
* @param handler <object>
* @return
*/
function yConfirmPanel(panelTitle,icona,panelText,handler){
	//crea subtito un id univoco 
	this.id = YAHOO.util.Dom.generateId("","myYahooPanel");
	//crea il div con l'id appena creato
	fnAppendDiv(this.id,""); 
	// crea il contenuto del pannello header, body e footer
	divInnerPanel2 = '<div class=\"hd\"><span  style="padding-left: 1.8em; background: url('+pathUrlIcone + icona +') 0% 50% no-repeat;">' + panelTitle + '</span></div>';
	divInnerPanel2 += "<div class=\"bd\" id=\"bd"+ this.id +"\" ></div>";
	divInnerPanel2 += "<div class=\"ft\" id=\"ft"+ this.id +"\"></div>";
	document.getElementById(this.id).innerHTML  = divInnerPanel2;
	// assegna la classe al pannello se presente nell ambiente
	try{if(divClass != "")document.getElementById(this.id).className  =  divClass + document.getElementById(this.id).className;
	}catch(ex){}
	// handler per le risposte
	var handleConfirmYes = function() {
		this.hide();
		return true;
	};
	var handleConfirmNo = function() {
		this.hide();
		return false;
	};
	// crea un confirm panel di yahoo, l'handler sul si è quello passato alla funzione
	this.confimrPanel = 	new YAHOO.widget.SimpleDialog(this.id, 
			{fixedcenter: true,
		visible: true,
		draggable: true,
		close: true,
		zIndex: 1000,
		modal: true,
		text: panelText,
		constraintoviewport: true,
		buttons: [ { text:bottoneSi, handler:handler},
		           { text:bottoneNo, handler:handleConfirmNo }
		]
			} );
	// per attivare o disattivare la proprietà modal (lo schermo nero dietro il pannello)
	this.setModal = function (bool){
		this.confimrPanel.cfg.setProperty("modal",bool,false); 
	}
	// setta fixedcenter (a ogni movimento della pagina riposiziona il pannello al centro del viewport
			this.setFixedcenter = function (bool){
		this.confimrPanel.cfg.setProperty("fixedcenter",bool,false); 
	}
	// setta lo z index
	this.setZIndex = function (num){
		this.confimrPanel.cfg.setProperty("zIndex",num,false); 
	}
	// setta il constrainviewport, serve per non fare uscire il pannelli dal viewport
	this.setConstraintoviewport = function (bool){
		this.confimrPanel.cfg.setProperty("constraintoviewport",bool,false); 
	}
	// setta se il pannello è draggabile o meno
	this.setDraggable = function (bool){
		this.confimrPanel.cfg.setProperty("draggable",bool,false); 
	}
	// setta l'altezza del pannello
	this.setHeight = function (num){
		this.confimrPanel.cfg.setProperty("height",num+"px",false); 
	}
	// setta la larghezza del pannello
	this.setWidth = function (num){
		this.confimrPanel.cfg.setProperty("width",num+"px",false); 
	}
	// setta la posizione partendo da sinistra del pannello
	this.setX = function (num){
		this.confimrPanel.cfg.setProperty("x",num,false); 
	}
	// setta la posizione partendo dall'alto del pannello
	this.setY = function (num){
		this.confimrPanel.cfg.setProperty("y",num,false); 
	}
	// chiama il reder del pannello
	this.render = function (){
		this.confimrPanel.render();
	}
	// setta il contenuto del body
	this.setContentBody = function(str){
		this.confimrPanelBoody.innerHTML = str;
	}
	// setta il footer del body
	this.setContentFooter = function(str){
		this.confimrPanelFooter.innerHTML = str;
	}
	// nasconde il pannello
	this.hide = function(){
		this.confimrPanel.hide();
	}


	this.render();
}

/**
* Panel of yahoo personalized by eterbit
* @panelTitle <string>
* @icona <string>
*/
function yPanel(panelTitle,icona){
	this.panel = null;
	// crea id univoco per il pannello
	this.id = YAHOO.util.Dom.generateId("","myYahooPanel");
	// crea il div e gli aggiunge il contenuto
	fnAppendDiv(this.id,""); 
	divInnerPanel2 = '<div class=\"hd\"><span  style="padding-left: 1.8em; background: url('+pathUrlIcone + icona +') 0 50% no-repeat;">' + panelTitle + '</span></div>';
	divInnerPanel2 += "<div class=\"bd\" id=\"bd"+ this.id +"\" ></div>";
	divInnerPanel2 += "<div class=\"ft\" id=\"ft"+ this.id +"\"></div>";
	document.getElementById(this.id).innerHTML  = divInnerPanel2;
	//setta una classe se è presente
	try{if(divClass != "")document.getElementById(this.id).className  =  divClass + document.getElementById(this.id).className;
	}catch(ex){}
	// crea il pannello yahoo
	this.panel = new YAHOO.widget.Dialog(this.id, 
			{fixedcenter : true,
		visible : true, 
		cancel:true,
		modal:true,
		zIndex:10,
		constraintoviewport : true,
		draggable:true
			} );
	// per accedere velocemete al body e al footer del pannello
	this.panelFooter  = document.getElementById("ft"+this.id);
	this.panelBody = document.getElementById("bd"+this.id);
	// setta la proprietà modal ( schermo nero dietro al pannello)
	this.setModal = function (bool){
		this.panel.cfg.setProperty("modal",bool,false); 
	}
	// setta se il pannello deve rimanere al centro forzatamente
	this.setFixedcenter = function (bool){
		this.panel.cfg.setProperty("fixedcenter",bool,false); 
	}
	// setta lo z index del pannello
	this.setZIndex = function (num){
		this.panel.cfg.setProperty("zIndex",num,false); 
	}
	// setta se il pannello può uscire o meno dal viewport
	this.setConstraintoviewport = function (bool){
		this.panel.cfg.setProperty("constraintoviewport",bool,false); 
	}
	//setta se è draggabile o meno
	this.setDraggable = function (bool){
		this.panel.cfg.setProperty("draggable",bool,false); 
	}
	// setta l'altezza del pannello
	this.setHeight = function (num){
		this.panel.cfg.setProperty("height",num+"px",false); 
	}
	// setta la larghezza del pannello
	this.setWidth = function (num){
		this.panel.cfg.setProperty("width",num+"px",false); 
	}
	// setta la posizione partendo da sinistra
	this.setX = function (num){
		this.panel.cfg.setProperty("x",num,false); 
	}
	// setta la poszione partendo dall'alto
	this.setY = function (num){
		this.panel.cfg.setProperty("y",num,false); 
	}
	// chiama il render del pannello
	this.render = function (){
		this.panel.render();
	}
	// setta il contenuto del body
	this.setContentBody = function(str){
		this.panelBody.innerHTML = str;
	}
	// setta il contenuto del footer
	this.setContentFooter = function(str){
		this.panelFooter.innerHTML = str;
	}
	// nasconde il pannello
	this.hide = function(){
		this.panel.hide();
	}

	this.panel.render();
	// aumenta il font nell'header altrimenti si vede più piccolo e non ci starebbe manco l'icona
	document.getElementById(this.id+"_h").style.fontSize  = "105%";
}
/**
* @param divId <string>
* @param multiSelect <bool>
* @return
* example: 
	*var calen = new yCalendar('calendario',true);
*calen.changeStyleForWeekDay(2,calen.calendar.renderBodyCellRestricted);
*calen.changeStyleForInterval('4/01/2009','4/30/2009',calen.calendar. renderCellStyleHighlight1 )
*calen.render();
*/
function yCalendar(divId,multiSelect){

	this.calendar 					= null;
	this.calendarSelectedInterval 	= new Array();
	//navigatore
	var navConfig = {
			strings: {
		month:strLangCalendarNavMonth,
		year:strLangCalendarNavYear,
		submit: strLangCalendarNavSubmit,
		cancel: strLangCalendarNavCancel,
		invalidYear: strLangCalendarNavInvalidYear
	},
	initialFocus: "month"
	}



	//crea il calendario multiselect o singleselect
	if(multiSelect){
		this.calendar = new YAHOO.widget.Calendar(divId,{ MULTI_SELECT:true,mindate:"",maxdate:"",navigator:navConfig});
	}else{
		this.calendar = new YAHOO.widget.Calendar(divId, {navigator:navConfig});
	} 
	// cambio lo stile di un intervallo di date
	this.changeStyleForInterval = function (startDate,endDate,style){
		this.calendar.addRenderer(startDate + "-" + endDate, style); 
	}
	// cambia lo stile di un giorno della settimana scelto ( giorno <number> 1-7
			this.changeStyleForWeekDay = function (giorno,style){
		this.calendar.addWeekdayRenderer(giorno,style);
	}
	//setta il giorno massimo selezionabile
	this.configMaxDate = function (giorno){
		this.calendar.cfg.setProperty("maxdate",giorno,false); 
	}
	// setta il giorno minimo selezionabile
	this.configMinDate = function (giorno){
		this.calendar.cfg.setProperty("mindate",giorno,false); 
	}
	// chiama il render del calendario
	this.render = function (){
		this.calendar.render();
	}
	// restituisce un array di date selezionate
	this.getSelectedDates = function (){
		return this.calendar.getSelectedDates();
	}
	// seleziona un intervallo di date
	this.selectInterval = function (startDate,endDate){
		this.calendarSelectedInterval   = this.calendar.select(startDate + "-" + endDate); 
	}
	/*
	Metodo getLCMSSelectableDates che mi restituisce una lista
	di date selezionate, potendo decidere di escludere i sabati e/o le
	domeniche, e alcune date che sono state deselezionate.
	parameters:
		chkSat, chkSun : boolean		
		*/		
		this.getLCMSSelectableDates = function (chkSat,chkSun){
		this.datesList = this.calendar.getSelectedDates();

		for (var i=0; i<this.datesList.length; i++) {
			tmpVal  = this.datesList[i].toString();
			tmpVal  = tmpVal.substr(0,3);

			if(tmpVal == "Sat") {
				if (chkSat) {
					this.datesList.splice(i,1);
					i -= 1; 
				}
			}
			if(tmpVal == "Sun") {
				if (chkSun) {
					this.datesList.splice(i,1);
					i -= 1; 
				}
			}
		}
		return this.datesList;
	}
	// proprietà indicano delimitatore e posizione del giorno, mese anno quando viene passata una data al calendario
	this.calendar.cfg.setProperty("DATE_FIELD_DELIMITER", "/"); 
	this.calendar.cfg.setProperty("MD_DAY_POSITION", 1); 
	this.calendar.cfg.setProperty("MD_MONTH_POSITION", 2); 	
	this.calendar.cfg.setProperty("MDY_DAY_POSITION", 1); 
	this.calendar.cfg.setProperty("MDY_MONTH_POSITION", 2); 	
	this.calendar.cfg.setProperty("MDY_YEAR_POSITION", 3); 
	//	proprietà per renderlo multilingua
	this.calendar.cfg.setProperty("WEEKDAYS_SHORT",[strLangCalendarDo, strLangCalendarLu, strLangCalendarMe, strLangCalendarMe, strLangCalendarGi, strLangCalendarVe, strLangCalendarSa]); 
	this.calendar.cfg.setProperty("MONTHS_LONG",   [strLangCalendarGennaio, strLangCalendarFebbraio, strLangCalendarMarzo, strLangCalendarAprile, strLangCalendarMaggio, strLangCalendarGiugno, strLangCalendarLuglio, strLangCalendarAgosto, strLangCalendarSettembre, strLangCalendarOttobre, strLangCalendarNovembre, strLangCalendarDicembre]); 
}	
/**
 * 
 * @param imgId <String>
 * @param multiSelect <bool>
 * @param handleSelect <object>
 * @param handleOk <object>
 * @return
 */
function yCalendarPopUp(imgId,multiSelect,handleSelect,handleOk){
	//crea l'id univoco al calendario e div
	this.id = YAHOO.util.Dom.generateId("","myYahooCalendar");
	fnAppendDiv(this.id,""); 
	// setta il contenuto al calendario
	//	divInnerPanel2 = '<div class="bd" id='+"calendarContainer"+this.id +'></div>';
	divInnerPanel2 = "<div class='bd' id=bd"+this.id+" ><div id="+"calendarContainer"+this.id +"></div></div>";
	document.getElementById(this.id).innerHTML  = divInnerPanel2;
	try{if(divClass != "")document.getElementById(this.id).className  =  divClass + document.getElementById(this.id).className;
	}catch(ex){}
	//setta aspetto grafico fix utilizzato anche da team di yahoo
	document.getElementById("calendarContainer"+this.id).style.border ="medium none";
	document.getElementById("calendarContainer"+this.id).style.padding= "1em";

	this.container 					= null;
	this.calendar 					= null;
	this.calendarSelectedInterval 	= new Array();
	//per IE se bisogna settare un'altezza specifica
	myHeight = IE ? "285px" : "";
	//controlla se sono stati passati dei valori senno lascia quelli di default(da aggiugere quelli di default)
	if(multiSelect != null && handleOk != null)	okHandler = handleOk;
	// crea il pannello per il caledario
	this.container 	=  new YAHOO.widget.Dialog(this.id, {
		visible:false,
		height:myHeight,
		draggable:true,
		close:true,
		modal:true,
		buttons:[ {text:strLangOK, handler:okHandler, isDefault:true}, 
		          {text:strLangAnnulla, handler:function(){this.hide();}}]
	});
	//navigatore
	var navConfig = {
			strings: {
		month:strLangCalendarNavMonth,
		year:strLangCalendarNavYear,
		submit: strLangCalendarNavSubmit,
		cancel: strLangCalendarNavCancel,
		invalidYear: strLangCalendarNavInvalidYear
	},
	initialFocus: "month"
	}
	// creal il calendario
	this.calendar = new YAHOO.widget.Calendar("calendarContainer"+this.id ,{
		MULTI_SELECT:multiSelect,navigator:navConfig});

	// cambia lo stile ad un intervallo di date
	this.changeStyleForInterval = function (startDate,endDate,style){
		this.calendar.addRenderer(startDate + "-" + endDate, style); 
	}
	// cambia lo stile ad un giorno specifico (giorno <number> 1-7)
	this.changeStyleForWeekDay = function (giorno,style){
		this.calendar.addWeekdayRenderer(giorno,style);
	}
	// configura la data massima selezionabile
	this.configMaxDate = function (giorno){
		this.calendar.cfg.setProperty("maxdate",giorno,false); 
	}
	// configura la data minima selezionabile 
	this.configMinDate = function (giorno){
		this.calendar.cfg.setProperty("mindate",giorno,false); 
	}
	//chiama il render del panello e calendario 
	this.render = function (){
		this.calendar.render();
		this.container.render();
	}
	// restituisce un array di date selezionate
	this.getSelectedDates = function (){
		return this.calendar.getSelectedDates();
	}
	// seleziona un intervallo di date
	this.selectInterval = function (startDate,endDate){
		this.calendarSelectedInterval   = this.calendar.select(startDate + "-" + endDate); 
	}
	//setta l'altezza del pannello
	this.setHeight = function (num){
		this.container.cfg.setProperty("height",num+"px",false); 
	}
	//setta la larghezza del pannello
	this.setWidth = function (num){
		this.container.cfg.setProperty("width",num+"px",false); 
	}
	//setta la posizione da sinistra del pannello
	this.setX = function (num){
		this.container.cfg.setProperty("x",num,false); 
	}
	//setta la posizione partendo dall'alto del pannello
	this.setY = function (num){
		this.container.cfg.setProperty("y",num,false); 
	}
	//mostra il pannello/caledario
	this.show = function (){
		this.container.show();
	}
	//proprietà indicano delimitatore e posizione del giorno, mese anno quando viene passata una data al calendario
	this.calendar.cfg.setProperty("DATE_FIELD_DELIMITER", "/"); 
	this.calendar.cfg.setProperty("MD_DAY_POSITION", 1); 
	this.calendar.cfg.setProperty("MD_MONTH_POSITION", 2); 	
	this.calendar.cfg.setProperty("MDY_DAY_POSITION", 1); 
	this.calendar.cfg.setProperty("MDY_MONTH_POSITION", 2); 	
	this.calendar.cfg.setProperty("MDY_YEAR_POSITION", 3); 
	//proprietà per renderlo multilingua
	this.calendar.cfg.setProperty("WEEKDAYS_SHORT",[strLangCalendarDo, strLangCalendarLu, strLangCalendarMe, strLangCalendarMe, strLangCalendarGi, strLangCalendarVe, strLangCalendarSa]); 
	this.calendar.cfg.setProperty("MONTHS_LONG",   [strLangCalendarGennaio, strLangCalendarFebbraio, strLangCalendarMarzo, strLangCalendarAprile, strLangCalendarMaggio, strLangCalendarGiugno, strLangCalendarLuglio, strLangCalendarAgosto, strLangCalendarSettembre, strLangCalendarOttobre, strLangCalendarNovembre, strLangCalendarDicembre]); 
}	
//crea un caledario popup non OOP DA ELIMINARE
function createCalendarPopUp(conId, calId,imgId, handleSelect, multiSelect,handleOk){
	fnAppendDiv(conId,divClass);
	divInnerPanel = '<div class=\"hd\">&nbsp;</div>';
	divInnerPanel += "<div id='bd' style='height:100%'><div id='"+calId+"'></div></div>";
	divInnerPanel += "<div class=\"fd\" style='padding-top:10px'></div>";
	document.getElementById(conId).innerHTML  = divInnerPanel;

	popUpCalendarDialog = new YAHOO.widget.Dialog(conId, {
		visible:false,
		draggable:true,
		close:true,
		modal:true,
		buttons:[ {text:strLangOK, handler: handleOk, isDefault:true}, 
		          {text:strLangAnnulla, handler: closeHandler}]
	});
	function closeHandler() { 
		dialog.hide(); 
	} 

	if(handleOk == undefined || handleOk == null || handleOk == ""){
		handleOk = closeHandler;
	}
	yahooPopUpCalendar = new YAHOO.widget.Calendar(calId,{
		MULTI_SELECT:multiSelect});
	yahooPopUpCalendar.cfg.setProperty("DATE_FIELD_DELIMITER", "/"); 
	yahooPopUpCalendar.cfg.setProperty("MD_DAY_POSITION", 1); 
	yahooPopUpCalendar.cfg.setProperty("MD_MONTH_POSITION", 2); 	
	yahooPopUpCalendar.cfg.setProperty("MDY_DAY_POSITION", 1); 
	yahooPopUpCalendar.cfg.setProperty("MDY_MONTH_POSITION", 2); 	
	yahooPopUpCalendar.cfg.setProperty("MDY_YEAR_POSITION", 3); 

	yahooPopUpCalendar.cfg.setProperty("WEEKDAYS_SHORT",[strLangCalendarDo, strLangCalendarLu, strLangCalendarMe, strLangCalendarMe, strLangCalendarGi, strLangCalendarVe, strLangCalendarSa]); 
	yahooPopUpCalendar.cfg.setProperty("MONTHS_LONG",   [strLangCalendarGennaio, strLangCalendarFebbraio, strLangCalendarMarzo, strLangCalendarAprile, strLangCalendarMaggio, strLangCalendarGiugno, strLangCalendarLuglio, strLangCalendarAgosto, strLangCalendarSettembre, strLangCalendarOttobre, strLangCalendarNovembre, strLangCalendarDicembre]); 


	YAHOO.util.Event.addListener(imgId, "click",function(e){mousePos = setXYMousePosition(e);
	popUpCalendarDialog.show();
	popUpCalendarDialog.cfg.setProperty("xy", mousePos);
	popUpCalendarDialog.render();
	}, 
	popUpCalendarDialog, true); 
	document.getElementById(conId+"_c").style.zIndex= "200";
	yahooPopUpCalendar.render();
	popUpCalendarDialog.render();
}
// restituisce un array [x,y] della posizione del mouse, utile con on clik per far comparire qualcosa sotto il puntatore
function setXYMousePosition(e){
	if (IE) { // grab the x-y pos.s if browser is IE

		mouseXposition = e.clientX + document.documentElement.scrollLeft; //document.body.scrollLeft;
	mouseYposition = e.clientY + document.documentElement.scrollTop; //document.body.scrollTop;

	} else {  // grab the x-y pos.s if browser is NS
		mouseXposition = e.pageX;
	mouseYposition = e.pageY;
	}
	return [mouseXposition,mouseYposition];
}
// formatta una data in dd/mm/yyyy, controlla solo il numero di cifre siano giuste in caso aggiunge uno 0
function formatDates(dates){
	for (var i=0; i<dates.length; i++) {
		try {
			tmpDate = new Date(dates[i]);
			tmpDay = tmpDate.getDate();
			tmpDay = LPad(tmpDay.toString(),2,"0");
			tmpMonth = tmpDate.getMonth()+1;
			tmpMonth = LPad(tmpMonth.toString(),2,"0");
			tmpYear = tmpDate.getFullYear();
			dates[i] = tmpDay +"/" +tmpMonth +"/"+ tmpYear;
		} catch (e) {
			// TODO: handle exception
		}
	}
	return dates;
}
//sottrae un array ad un altro arr1 - arr2 e ritorna il primo array senza i valori doppi
function subtractArray(arr1, arr2) {
	A = arr1;
	B = arr2;
	for (var i=0; i<B.length; i++) {
		for (var j = 0; j < A.length; j++) {
			if (A[j] == B[i].toString())
				A.splice(j,1); 
		}
	}
	return A;
}
// Lpad di una stringa conta il nuemro di caratteri se sono meno di quelli richiesti aggiunge un carattere indicato
function LPad(ContentToSize,PadLength,PadChar){
	var PaddedString=ContentToSize.toString();
	ContentToSize = ContentToSize.toString();
	for(i=ContentToSize.length+1;i<=PadLength;i++)
	{
		PaddedString=PadChar+PaddedString;
	}
	return PaddedString;
}
// controlla se una data è compresa tra due date
function dateBetweenDates(dateToControl, minDate,maxDate){
	dateToControl = dateToControl.split("/");
	minDate = minDate.split("/");
	maxDate = maxDate.split("/");
	d1 = new Date();
	d2 = new Date();
	d3 = new Date();
	d1.setFullYear(dateToControl[2],dateToControl[1]-1,dateToControl[0]);
	d2.setFullYear(minDate[2],minDate[1]-1,minDate[0]);
	d3.setFullYear(maxDate[2],maxDate[1]-1,maxDate[0]);
	d1=d1.getTime();
	d2=d2.getTime();
	d3=d3.getTime();
	if(d1<d2 ||d1>d3)return false;
	else return true;

}
// controlla se una data non sia progressiva ad un'altra. va bene anche se sono uguali
function dateProgressiveControl(startDate,endDate){
	try{
		startDate = startDate.split("/");
		endDate = endDate.split("/");
		d1 = new Date();
		d2 = new Date();
		d1.setFullYear(startDate[2],startDate[1]-1,startDate[0]);
		d2.setFullYear(endDate[2],endDate[1]-1,endDate[0]);
		d1=d1.getTime();
		d2=d2.getTime();
		if(d1<=d2)return true;
		else return false;
	}catch(ex){return false}
}
// crea una select(dropdown list) per le ore
function eSelectHours(){
	var selectHour = document.createElement("select");
	var hourCount = 0
	do{
		tmpNum = LPad(hourCount,2,"0")
		elOptNew = document.createElement('option');
		elOptNew.text = tmpNum;
		elOptNew.value = tmpNum;
		try {
			selectHour.add(elOptNew, null);
		}
		catch(ex) {
			selectHour.add(elOptNew); // IE only
		}
		hourCount+=1
	}while(hourCount < 24);

	return selectHour;
}
// crea una select(dropdown list) per i minuti con un intervallo id 5 minuti
function eSelectMinutes(){
	var selectMinute = document.createElement("select");
	var minuteCount = 0
	do{
		tmpNum = LPad(minuteCount,2,"0")
		elOptNew = document.createElement('option');
		elOptNew.text = tmpNum;
		elOptNew.value = tmpNum;
		try {
			selectMinute.add(elOptNew, null);
		}
		catch(ex) {
			selectMinute.add(elOptNew); // IE only
		}
		minuteCount+=5
	}while(minuteCount < 60);
	return selectMinute;
}

function Trim(StrToTrim)
{
	if (typeof StrToTrim != "string")
	{
		return StrToTrim;
	}

	var StrBlank = StrToTrim.substring(0, 1);

	while (StrBlank == " ")
	{
		StrToTrim = StrToTrim.substring(1, StrToTrim.length);
		StrBlank = StrToTrim.substring(0, 1);
	}

	StrBlank = StrToTrim.substring(StrToTrim.length - 1, StrToTrim.length);

	while (StrBlank == " ")
	{
		StrToTrim = StrToTrim.substring(0, StrToTrim.length-1);
		StrBlank = StrToTrim.substring(StrToTrim.length-1, StrToTrim.length);
	}
	return StrToTrim;
}