<!--



	/************************************************/	
	/* 			FUNZIONI PER EDITOR TESTO BREVE		*/
	/************************************************/	
	
function arrayIndexOf(needle, haystack) {
	var lunghezza = haystack.length;
	for (var i=0; i < lunghezza; i++) {
		if (haystack[i]==needle) {
			return i;
		}
	}
	return -1;
}
	
	function PulisciTesto(testo) {
			/* Questa funzione viene utilizzata per pulire il testo da caratteri che risulterebbero nocivi per il funzionamento AJAX */

			var testo1 = "";
            var allowedChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            //var CodChar = new Array(160,38,224,236,232,233,242,176,249,8217,194);
            //var CharValue = new Array("&nbsp;","&amp;","&agrave;","&igrave;","&egrave;","&eacute;","&ograve;","&deg;","&ugrave;","&rsquo;","&Acirc;");

            var CodChar = new Array(160,38);
            var CharValue = new Array("&nbsp;","&amp;");	
			for (i=0; i < CharValue.length; i++){
				var t = new RegExp(CharValue[i],"g");
				testo = testo.replace(t,String.fromCharCode(CodChar[i]));
			}			
			
			for (i=0; i < testo.length; i++){
				CurrChar = testo.substring(i,i+1);

				if (allowedChars.indexOf(CurrChar)>=0)
				{
					testo1 += (CurrChar);
				}
				else if (arrayIndexOf(CurrChar.charCodeAt(0),CodChar)>=0)
				{
					testo1 += CharValue[arrayIndexOf(CurrChar.charCodeAt(0),CodChar)];
				}
				else
				{
					testo1 += CurrChar
					//testo1 += encodeURIComponent(CurrChar);
				}
			}
			testo = encodeURIComponent(testo1);
			//testo = testo1;

			return testo;
		}

	
	function EditorTestoBreve(parametro){	
		var arr_parametro = new Array();
		arr_parametro = parametro.split("{{{");
		nomediv = arr_parametro[2] + arr_parametro[3];
		var campo = arr_parametro[1];
		var url = '/main/Editor/Editor.asp';
		var pars = 'parametro=' + parametro + '&Edit=1';
		var myAjax = new Ajax.Updater(
					{success: nomediv}, 
					url, 
					{
					    contentType: 'application/x-www-form-urlencoded',
						method: 'post', 
						encoding: 'UTF-8',
						parameters: pars, 
						onFailure: reportError
					});
	}


	function reportError(request)
	{
		alert(request);
	}
	
	
	function EditorTestoBreveSalva(parametro)
	{
		var arr_parametro = new Array();
		arr_parametro = parametro.split("{{{");
		nomediv = arr_parametro[2] + arr_parametro[3];
		var campo = arr_parametro[2];
		
		var url = '/main/Editor/Editor.asp';
		var valoreCampoModifica = 'txt' + campo+arr_parametro[3];
		var pars = 'parametro=' + parametro + '&' + 'txt' + campo + arr_parametro[3] + '=' + PulisciTesto($(valoreCampoModifica).value) + '&Edit=2';		
		var myAjax = new Ajax.Updater(
					{success: nomediv}, 
					url, 
					{
					    contentType: 'application/x-www-form-urlencoded',
						method: 'post', 
						encoding: 'UTF-8',
						parameters: pars, 
						onFailure: reportError
					});

	}
	
	
	
	/************************************************/	
	/* 			FUNZIONI PER EDITOR COMBO BOX	*/
	/************************************************/	
	//var nameSelectCombo;
	//var optionSelected;
	function EditorComboBox(parametro){	
		var arr_parametro = new Array();
		arr_parametro = parametro.split("{{{");
		nomediv = arr_parametro[2] + arr_parametro[3];
		nameSelectCombo = "txt" + arr_parametro[1] + arr_parametro[3];
		textCombo = "textCombo";
		optionSelected = arr_parametro[7]
		var campo = arr_parametro[1];
		var url = '/main/Editor/Editor.asp';
		var pars = 'parametro=' + parametro + '&Edit=6';
		var myAjax = new Ajax.Updater(
					{success: nomediv}, 
					url, 
					{
					    contentType: 'application/x-www-form-urlencoded',
						method: 'post', 
						encoding: 'UTF-8',
						parameters: pars, 
						onFailure: reportError,
						onComplete: function(){ initCombo(nameSelectCombo, textCombo, optionSelected)}
					});
	}
	
	function EditorComboBoxSalva(parametro)
	{
		var arr_parametro = new Array();
		arr_parametro = parametro.split("{{{");
		nameSelectCombo = "txt" + arr_parametro[1] + arr_parametro[3];
		parametro = parametro + "{{{" + $(nameSelectCombo).options[$(nameSelectCombo).selectedIndex].text;
		nomediv = arr_parametro[2] + arr_parametro[3];
		var campo = arr_parametro[1];
		
		var url = '/main/Editor/Editor.asp';
		var valoreCampoModifica = 'txt' + campo+arr_parametro[3];
		var pars = 'parametro=' + parametro + '&' + 'txt' + campo + arr_parametro[3] + '=' + PulisciTesto($(valoreCampoModifica).value) + '&Edit=7';		
		var myAjax = new Ajax.Updater(
					{success: nomediv}, 
					url, 
					{
					    contentType: 'application/x-www-form-urlencoded',
						method: 'post', 
						encoding: 'UTF-8',
						parameters: pars, 
						onFailure: reportError
					});

	}
	
	
	


	function Ridimensiona(nameSelectCombo, textCombo){
		var dimensionsSelect = $(nameSelectCombo).getDimensions(); 
		$(textCombo).style.width = (dimensionsSelect.width - 20) + "px";
		if (($(nameSelectCombo).options[$(nameSelectCombo).selectedIndex].value == "") ){
			$(textCombo).value = "";
			$(nameSelectCombo).options[$(nameSelectCombo).selectedIndex].value = 0;
		} else {
			$(textCombo).value = $(nameSelectCombo).options[$(nameSelectCombo).selectedIndex].text;
		}		
	}

	function initCombo(nameSelectCombo, textCombo, optionSelected) {
		Ridimensiona(nameSelectCombo, textCombo);
		for(i=0; i<$(nameSelectCombo).options.length; i++) {
			if ($(nameSelectCombo).options[i].value == optionSelected) {
					$(nameSelectCombo).options[i].selected = true
					$(textCombo).value = $(nameSelectCombo).options[i].text;
			}
		}
	}
	
	function TextChange(nameSelectCombo, textCombo){
		$(textCombo).value = $(nameSelectCombo).options[$(nameSelectCombo).selectedIndex].text;
		Ridimensiona(nameSelectCombo, textCombo);
	}
	
	function SelectChange(nameSelectCombo, textCombo){
		 $(nameSelectCombo).options[$(nameSelectCombo).selectedIndex].text = $(textCombo).value;
		 Ridimensiona(nameSelectCombo, textCombo);
	}
	



	/************************************************/	
	/* 			FUNZIONI PER EDITOR TESTO EDITOR		*/
	/************************************************/	
		var nomeTextAreaEditor;
		var nomeTextArea;
	
		function EditorTestoOpzioni(parametro)	{	
			var arr_parametro = new Array();
			arr_parametro = parametro.split("{{{");
			nomediv = "LoginContainer"; /*arr_parametro[2] + arr_parametro[3];*/
			nomeTextAreaEditor = 'txt' + arr_parametro[4] + arr_parametro[3];
			//var campo = arr_parametro[1];
			var url = '/main/Editor/Editor.asp';
			var pars = 'parametro=' + parametro + '&Edit=3';	
			var myAjax = new Ajax.Updater(
						{success: nomediv}, 
						url, 
						{
							contentType: 'application/x-www-form-urlencoded',
							method: 'post', 
							encoding: 'UTF-8',
							parameters: pars, 
							asynchronous: true,
							onFailure: reportError,
							onComplete: Inizio
						});
			
		}	
	
		function Inizio() {
			/* Subito dopo ilcaricamento se ci sono delle tabelle le celle verranno indicate con dei punti 		*/
			var win = document.getElementById('edit').contentWindow;
			var doc = win.document;			
			
			listaNodiTD =doc.body.getElementsByTagName("TD")
			for(i=0; i < listaNodiTD.length; i++){
				listaNodiTD(i).style.border = 'dotted 1px #000000';
			}

		}
		
	function Caricamento(){
	}
	function Completo(){
	}
	
	function accenti() {
		
	}
		
		function EditorTestoOpzioniSalva(parametro)	{
	
			var arr_parametro = new Array();
			arr_parametro = parametro.split("{{{");
			nomediv = arr_parametro[2] + arr_parametro[3];
			//var campo = arr_parametro[0];
			
			var url = '/main/Editor/Editor.asp';
			var valoreCampoModifica = 'txt' + nomediv;
			nomeTextArea = 'txt' +arr_parametro[1] + arr_parametro[3];

			var pars = 'parametro=' + parametro + '&' + nomeTextAreaEditor + '=' + PulisciTesto($(nomeTextAreaEditor).value) + '&' + nomeTextArea + '=' + PulisciTesto($(nomeTextArea).value) + '&Edit=4';
			var myAjax = new Ajax.Updater(
						{success: nomediv}, 
						url, 
						{
							contentType: 'application/x-www-form-urlencoded',
							method: 'post', 
							encoding: 'UTF-8',
							parameters: pars, 
							onFailure: reportError
						});
			}	
			
			Ajax.Responders.register({
			 onCreate : Caricamento,
			 onComplete : Completo
			}); 				
			
		
	
	
	
	
		function save (txt,txtEditor,parametro,openerTxt,openerTxtEditor, heightObject, widthObject){			
			//togliStyleTD();
			
			if (heightObject!='' && widthObject!='' ){
					arrElements = document.getElementById("edit").contentWindow.document.getElementsByTagName('EMBED')
					for(i=0; i < arrElements.length; i++){
							$(arrElements[i]).setStyle({width: widthObject + 'px', height: heightObject + 'px' });
							if (arrElements[i].getAttribute("wmode") == 'Window' ){
									$(arrElements[i]).setAttribute("trillalerotrillala_id", "trillalerotrillala_value");
							}
					}
			}
			var editorDoc = document.getElementById("edit").contentWindow.document;
			var code =editorDoc.body.innerHTML;
			code = code.replace("trillalerotrillala_id","wmode").replace("trillalerotrillala_value","transparent")						
			document.getElementById(txtEditor).value = code;

			txtSource = editorDoc.body.innerHTML;
			//tutti i tag vengono trasformati in minuscolo
			txtSource = txtSource.replace(/<\w+/gi,function(x){return x.toLowerCase()});
			txtSource = txtSource.replace(/<\/\w+>/gi,function(x){return x.toLowerCase()});
			//trasformo il tag <'br>
			var varRegExp = new RegExp("<" + "br>","gi");
			txtSource = txtSource.replace(varRegExp,"<" + "br/>");			
			
			//Togli i tag vuoti con niente nel mezzo
			var varRegExp = new RegExp("<" + "p[^<" + ">]*><" + "\/p>","gi");
			txtSource = txtSource.replace(varRegExp, '');
			
			var varRegExp = new RegExp("<" + "em><" + "\/em>","gi");
			txtSource = txtSource.replace(varRegExp, '');
			
			var varRegExp = new RegExp("<" + "strong><" + "\/strong>","gi");
			txtSource = txtSource.replace(varRegExp, '');
			
			//txtSource = AggiungiIMGChiuso(txtSource);
			//txtSource = togliIMGChiuso(txtSource);
			
			editorDoc.body.innerHTML = txtSource;

			//Sostituisco ad ogni align=attributo l'appropriata classe
			//txtSource = txtSource.replace(/\salign=right\s?/gi, ' class="interna_dx"');
			//txtSource = txtSource.replace(/\salign=left\s?/gi, ' class="interna_sx"');
			//txtSource = txtSource.replace(/\salign=center\s?/gi, ' class="interna_center"');
			
			//Metto gli apici doppi nella classe interna_blank
			//txtSource = txtSource.replace(/class=interna_blank/gi, ' class="interna_blank"');
			//txtSource = txtSource.replace(/class=interna/gi, ' class="interna"');
			
			//Setto la classe nella tabella
			//txtSource = txtSource.replace(/border=0/gi, ' class="interna_border_0"');
			//txtSource = txtSource.replace(/border=[1-9]/gi, ' class="interna_border_1"');
			//txtSource = txtSource.replace(/http:\/\/<%=session("URLSito")%>/gi, '');
			
			//tolgo <'p>&nbsp;<'/p> se c è solo questo
			stringa = "<" + "p>&nbsp;<" + "/p>"
			if (txtSource == stringa)
				txtSource = ""
				
			if (parametro == ''){
				opener.document.getElementById(openerTxt).value = txtSource;
				opener.document.getElementById(openerTxtEditor).value = code;
				window.close();
			} else {
				document.getElementById(txt).value = txtSource;
				EditorTestoOpzioniSalva(parametro);
			}

			
		    //document.getElementById("pippo").value = xmlFile
		} 	
		
		function Codice(idTextArea) {
			var CodiceHTML = $('edit').contentWindow.document.body.innerHTML;
			larghezza = $('edit').getWidth();
			altezza = $('edit').getHeight();
			if ($('chkCodice').checked){
				$(idTextArea).setStyle({visibility:'visible', display:'block', width:(larghezza-6) + 'px' , height:(altezza + 18) + 'px', top:'0px', left:'0px'});
				$(idTextArea).value = CodiceHTML;			
			} else {
					$('edit').contentWindow.document.body.innerHTML = $(idTextArea).value;
					$(idTextArea).setStyle({visibility:'hidden', display:'none'});
			}
		}
		
		
		
		//***********Inserimento Immagine dentro l editor estseso
		function CreateImage(Controllo, immagineEdit,immagineName){
			if(document.selection) { //nel caso di explorer
				var range = document.getElementById(Controllo).contentWindow.document.selection.createRange();	
				var doc =  document.getElementById(Controllo).contentWindow.document;
				image = '<' + 'IMG src="' + immagineEdit + '"' + ' alt=" ' + immagineName + ' " Border =" interna_image " ><' + '/IMG>';
				range.pasteHTML(image);
				//nodi1("IMG");
			} else  {
				var range = document.getElementById("edit").contentWindow.getSelection();
				var doc =  document.getElementById(Controllo).contentWindow.document;
				image = '<' + 'IMG src="' + immagineEdit + '"' + ' alt=" ' + immagineName + ' " Border =" interna_image " ><' + '/IMG>';
				document.getElementById("edit").contentWindow.document.execCommand('insertHTML',false,image); 
				//nodi1("IMG");
			}
		}
		
		function nodi1(parametroTag){
			var tag = new Array()
			tag[0] = 'EM';
			tag[1] = 'STRONG';
			tag[2] = 'P';
			listaNodiTable =document.getElementById("edit").contentWindow.document.body.getElementsByTagName(parametroTag)
			//document.getElementById().
			for(i=0; i < listaNodiTable.length; i++){
				k=0
				while (k<3) {
						elemento = tag[k];
						k++;
						elementoTABLE = listaNodiTable(i)
						elementoP = listaNodiTable(i).parentElement
		
						if (elementoP.tagName == elemento) {
							oCloneTABLE = listaNodiTable(i).cloneNode(true) //clonata tabella
							cloneTagP1 = listaNodiTable(i).parentElement.cloneNode(false) //clonato tag P
							
							cloneTagP2 = cloneTagP1.cloneNode(false)
							
							elementoSpan=document.getElementById("edit").contentWindow.document.createElement('SPAN')
							listaNodiTable(i).replaceNode(elementoSpan)
							htmlOriginale = elementoP.innerHTML;
							
							htmlModificato = htmlOriginale;
							
							var ricercaSpan = new RegExp("<" + "SPAN><" + "\/SPAN>","gi");
							htmlModificato = htmlModificato.replace(ricercaSpan,"funcia")
							
							
							var arr = htmlModificato.split("funcia")
							
							
							cloneTagP1.innerHTML = arr[0]
							
							cloneTagP2.innerHTML = arr[1]
							
							divPippo = '<' + 'div id="pippo">';
							newDiv = document.getElementById("edit").contentWindow.document.createElement(divPippo)
							newDiv.appendChild(cloneTagP1)
							if (parametroTag == "IMG"){
								image = '<' + 'IMG ALT="" src="' + oCloneTABLE.src + '" class=" interna_image "><' + '/IMG>';
								newDiv.innerHTML = newDiv.innerHTML + image;
							} else {
								newDiv.appendChild(oCloneTABLE)
							}
							newDiv.appendChild(cloneTagP2)
							
							elementoP.replaceNode(newDiv)
							newDiv.removeNode(false)
							k = 0;
							//oCloneTABLE = cloneTagP2.parentElement.insertBefore(oCloneTABLE,cloneTagP2)
						} //fine IF
						listaNodiTable =document.getElementById("edit").contentWindow.document.body.getElementsByTagName(parametroTag)
				} //Fine While
				
			}// Fine FOR
		}		
		
		//*********** FINE Inserimento Immagine dentro l editor estseso
		
		
		
		function Exec (name, Path, CartellaMin){
			var isIE = (navigator.userAgent.indexOf("MSIE") != -1) ;
			var editor = document.getElementById("edit").contentWindow.document;
			editor.body.focus();
			if (name=='createLink') {
				winCreateLink = window.open("/main/Editor/createlink.asp",'winCreateLink', 'width=400,height=350,scrollbars=yes');
				winCreateLink.window.focus();
			}
			else if (name=='createTable') {
				window.open("/main/Editor/Editor.asp?Edit=5",'winCreateTable', 'width=400,height=300,scrollbars=yes');
			} 	
			else if (name=='createImage') {
					Elenco_Immagini_popup('edit','contenuti' + CartellaMin, Path, '', '3')				
			} 						
			else if (name=='pulisciTesto') {
				Pulisci();
			} 
			
			else {	
					
					editor.execCommand(name,false,null);
			}
			if(!isIE) return ;
			editorChange();
		}

		var queryCommands = ['bold','italic','justifyleft','justifycenter','justifyright'];
		
		function editorChange (){
			// Ogni volta che clicco sun un pulsante lo richiama la classe idonea per il pulsanti bold italic, etc
			var editorDoc = document.getElementById("edit").contentWindow.document;
			for(var i=0; i < queryCommands.length; i++){
				var queryCommand=queryCommands[i];
				var b = editorDoc.queryCommandValue(queryCommand);	
				var cmdButton = document.getElementById("btn" + queryCommand);	
				if(!b)  cmdButton.className="toolbarButton";
				else cmdButton.className="toolbarButtonOn";	
			}
		}		
		
		function Pulisci(){
			var tag = ['p','br/','br']

			txtSource = document.getElementById("edit").contentWindow.document.body.innerHTML;
			//Elimino tutti i tag di apertura non presenti nella mia lista 
			var m;
			m = "<(?!("
			for(i=0; i < tag.length-1; i++){
				m = m + tag[i] + "\\s*>|" + tag[i] + "\\s+[a-z][^<>]*|"
			}
			m =  m + tag[tag.length-1] + "\\s*>|" + tag[tag.length-1] + "\\s+[a-z][^<>]*))[a-z|?][^<>]*>"
			var myregexp = new RegExp(m,"gi")
			txtSource = txtSource.replace(myregexp, "");
			
			//Elimino tutti i tag di chiusura non presenti nella mia lista 
			m = "</(?!("
			for(i=0; i < tag.length-1; i++){
				m = m + tag[i] + "\\s*>|" + tag[i] + "\\s+[a-z][^<>]*|"
			}
			m =  m + tag[tag.length-1] + "\\s*>|" + tag[tag.length-1] + "\\s+[a-z][^<>]*))[a-z|?][^<>]*>"
			var myregexp = new RegExp(m,"gi")
			txtSource = txtSource.replace(myregexp, "");

			//Elimino tutti gli attributi dei tag presenti nella mia lista 
			/*for(i=0; i < tag.length; i++){
				m = "<" + tag[i] + "\\s+[a-z][^<>]*>"
				var myregexp = new RegExp(m,"gi")
				r = "<" + tag[i] + ">"
				txtSource = txtSource.replace(myregexp, r);
			}*/
			document.getElementById("edit").contentWindow.document.body.innerHTML = txtSource
		}	
		
		function togliStyleTD(){
			//Toglie lo stile inserito inizialmente nel TD per poterlo visualizzare con dei puntini
			listaNodiTD =document.getElementById("edit").contentWindow.document.getElementsByTagName("TD")
			alert(listaNodiTD.length)
    		for(i=0; i < listaNodiTD.length; i++){
				listaNodiTD(i).removeAttribute("style");
			}

		}
		
		function AggiungiIMGChiuso(testo) {
			//gestisce i tag img mettedo il tag di chiusura </img>
			t = testo
			var ris = new Array();
			var varRegExp = new RegExp("<" + "img[^>]*>(?!<" + "\/img>)","gi")
			ris = t.match(varRegExp);	
			try {
			for (i = 0;i < ris.length; i++){
				var p = new RegExp(ris[i]);
				testo = testo.replace(p, ris[i] + "<" + "/img>");
			}
			}
			catch(e){
			}
			return testo;
			
		}
		
		function togliIMGChiuso(testo) {
			var risultato = new Array()
			var varRegExp = new RegExp("<" + "img[^>]*><" + "\/img>","gi")
			risultatoMatch = testo.match(varRegExp);	
			risultatoSplit = testo.split(varRegExp);	
			uguali = false;
			try
			{
				if (risultatoSplit.length == risultatoMatch.length) uguali = true;
			}
			catch(e)
			{
				uguali = false;
			}
			
			for(i=0; i < risultatoSplit.length; i++) {
				risultatoSplit[i] = risultatoSplit[i].replace(/<\/img>/gi,'')
			}
			var t=""
			for(i=0; i < risultatoSplit.length; i++) {
				if (!uguali) {
					t = t + risultatoSplit[i]
					if (i < risultatoSplit.length-1)	t = t + risultatoMatch[i]
				} else {
					t = t + risultatoMatch[i];
					t = t + risultatoSplit[i];				
				}
			}
			return t;
			
		}		
		
		function nodi1(parametroTag){
			var tag = new Array()
			tag[0] = 'EM';
			tag[1] = 'STRONG';
			tag[2] = 'P';
			listaNodiTable =document.getElementById("edit").contentWindow.document.body.getElementsByTagName(parametroTag)
			//document.getElementById().
			for(i=0; i < listaNodiTable.length; i++){
				k=0
				while (k<3) {
						elemento = tag[k];
						k++;
						elementoTABLE = listaNodiTable(i)
						elementoP = listaNodiTable(i).parentElement
		
						if (elementoP.tagName == elemento) {
							oCloneTABLE = listaNodiTable(i).cloneNode(true) //clonata tabella
							cloneTagP1 = listaNodiTable(i).parentElement.cloneNode(false) //clonato tag P
							
							cloneTagP2 = cloneTagP1.cloneNode(false)
							
							elementoSpan=document.getElementById("edit").contentWindow.document.createElement('SPAN')
							listaNodiTable(i).replaceNode(elementoSpan)
							htmlOriginale = elementoP.innerHTML;
							
							htmlModificato = htmlOriginale;
							
							var ricercaSpan = new RegExp("<" + "SPAN><" + "\/SPAN>","gi");
							htmlModificato = htmlModificato.replace(ricercaSpan,"funcia")
							
							
							var arr = htmlModificato.split("funcia")
							
							
							cloneTagP1.innerHTML = arr[0]
							
							cloneTagP2.innerHTML = arr[1]
							
							divPippo = '<' + 'div id="pippo">';
							newDiv = document.getElementById("edit").contentWindow.document.createElement(divPippo)
							newDiv.appendChild(cloneTagP1)
							if (parametroTag == "IMG"){
								image = '<' + 'IMG ALT="" src="' + oCloneTABLE.src + '" class=" interna_image "><' + '/IMG>';
								newDiv.innerHTML = newDiv.innerHTML + image;
							} else {
								newDiv.appendChild(oCloneTABLE)
							}
							newDiv.appendChild(cloneTagP2)
							
							elementoP.replaceNode(newDiv)
							newDiv.removeNode(false)
							k = 0;
							//oCloneTABLE = cloneTagP2.parentElement.insertBefore(oCloneTABLE,cloneTagP2)
						} //fine IF
						listaNodiTable =document.getElementById("edit").contentWindow.document.body.getElementsByTagName(parametroTag)
				} //Fine While
				
			}// Fine FOR
}
	
	
-->	

