/*evita il warning*/
function validform(pform){
//news
     if (pform.titolo.value == "")
  {
    alert("Si prega di specificare il titolo !");
    pform.titolo.focus();
    return false;
  }
updateRTEs();
return true;
}
 
/**Per IE, evita il warning*/
var xajax;
/**SESSION VARS*/

//sessvars.$.debug();

sessvars.pageCount=sessvars.pageCount||0;
sessvars.pageCount++;
//sessvars.$.clearMem();

function setHistory(livelli){
	//alert('setHistory '+livelli);
	//var level =new Array(livello,value);
	//var sessvars.history;
	sessvars.history=sessvars.history||'';
	
	if(sessvars.history != 'undefined' && sessvars.history !='')
		sessvars.history+="-";

	sessvars.history +=livelli;
	
	//alert('setHistory '+sessvars.history);
};
/**procedura indietro*/
function indietro(){
	//alert("indietro()");
	
	var livello1=null;
	var livello2=null;
	var livello3=null;
	
	var livelli = getPreviousHistory();
	if(livelli!=null){
		var level_array=livelli.split(",");
		if(level_array[0]!=null && level_array[0]!="undefined")
			livello1=level_array[0];
		if(level_array[1]!=null && level_array[1]!="undefined")
			livello2=level_array[1];
		if(level_array[2]!=null && level_array[2]!="undefined")
			livello3=level_array[2];
		
		//alert("view.js indietro() set preview("+livello1+","+livello2+","+livello3+")");
		removeLastHistory();
		xajax_setXPreview(livello1,livello2,livello3);
	}
};

function showHistory(){
	//alert('showHistory '+sessvars.history);
	var text="";
	var storia=sessvars.history;
	if(storia){
		var livelli = storia.split("-");
		//alert('showHistory livelli '+livelli[0]);
		var i=0;
		 while(i < livelli.length) {
			var level = livelli[i];
			text +="livelli: "+level+"\n";
			i++;
		}	
	}
	//alert('showHistory\n '+text);
	//sessvars.$.clearMem();
};
/**Rimuove l'ultima selezione ricavata dall'history*/
function removeLastHistory(){
	var storia=sessvars.history;
	//alert('prima removeLastHistory\n '+sessvars.history);
	var newstoria="";
	if(storia){
			var stop=storia.lastIndexOf("-");
			//var stop=storia.length;
			newstoria=storia.substring(0,stop);
			sessvars.history=newstoria;
		}	
	//alert('dopo removeLastHistory\n '+sessvars.history);
};
/**Restituisce la penultima selezione ricavata dall'history*/
function getPreviousHistory(){
	//alert('showHistory '+sessvars.history);
	var last =null;
	var storia=sessvars.history;
	if(storia){
		var livelli = storia.split("-");
		var previous=livelli.length-2;
		if(previous < 0)
			previous=0;
		var last=livelli[(previous)];
	}
	//alert('getPreviousHistory\n '+last);
	return last;
};

/**Impostazione iniziale del il sito secondo i livelli forniti come parametro
 * 
 * 
 * @see GestoreXajaxMenu->setPreview();
 * 
 * */
function init(livello1,livello2,livello3){
	//sessvars.$.clearMem();

	//alert("tabPanels.js init(): "+livello1+" - "+livello2+" - "+livello3);
    Righello("tabella1");
    //showHistory();
    //PER PLUGIN
    xajax_setNextIdContenuto();
    
    xajax_setXPreview(livello1,livello2,livello3);
    //setPreview(livello1,livello2,livello3);
}
/**Impostazione runtime del il sito secondo i livelli forniti come parametro*/
function setPreview(livello1,livello2,livello3){
	alert("view,js setPreview: "+livello1+" - "+livello2+" - "+livello3);
	if(livello1!=null)
		xajax_selectedLivello1(livello1);
	if(livello1!=null && livello2!=null)
		xajax_selectedLivello2(livello1,livello2,'2');
	if(livello3 !=null){	
		if(livello2!=null)
			xajax_selectedLivello3(livello2,livello3,'3');
		else
			xajax_selectedLivello3(livello1,livello3,'3');
	}
}
/***/
function startPreview(){
	//alert("PREVIEW");
	window.open('index.php?geofor_modo=preview','','scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,location=no,status=no');
	}
/**Imposta il reload nella pagina con le variabili correnti
 * 
 * Viene chiamato al cambio di comune selezionato nel popup
 * @see GestoreComponenti->setComune()
 * 
 * @param modalita
 * @return void
 */
function startReload(modalita){
	//alert("RELOAD");
	var url="index.php"
	if(modalita)
		url +="?geofor_modo="+modalita;
	window.location.replace(url);
}

/**Cambia il background di un div chimato dai vari select livello
 * 
 * @see GestoreXajaxMenu->selectedLivello1(selected)
 * */
function setTabellaPrincipale(contenuto,r1,r2,rx,islogin,modalita){
	//alert("setTabellaPrincipale "+contenuto);
	var color;
	color=document.getElementById('tabella_centrale').style.backgroundColor;
	//alert("setTabellaPrincipale "+contenuto+" bg: "+color);
	var trs;
	var tds;
	if(contenuto ==1){
		//if(document.getElementById('tabella_centrale').style.backgroundColor !=''){//evito setting inutili
			document.getElementById('tabella_centrale').style.backgroundColor = '#FFFFFF';
			trs=document.getElementById('tabella_centrale').tBodies[0].rows;
			//PRIMA RIGA
			tds=trs[r1].cells;
			tds[0].style.background = '';
			tds[0].style.backgroundColor = '#FFFFFF';
			tds[0].innerHTML="";
			tds[0].style.height = '0 px';
			

			//COLONNA DX
			tds=null;
			tds=trs[rx].cells;
			tds[1].style.width = '0 px';
			//tds[1].innerHTML="&nbsp;";
			//tds[1].innerHTML="&nbsp;";
			if(islogin==1 && modalita=="preview"){
				//alert("devo togliere la 2a riga");
				tds[0].style.height = '0 px';
			}
						
			//ULTIMA RIGA
			tds=null;
			tds=trs[r2].cells;
			tds[0].style.background = '';
			tds[0].innerHTML="";
			tds[0].style.backgroundColor = '#FFFFFF';
			tds[0].style.height = '0 px';			
		//}
		
	}else if(contenuto !=1){//'
		//if(document.getElementById('tabella_centrale').style.backgroundColor ==''){//evito setting inutili
			document.getElementById('tabella_centrale').style.backgroundColor = '#EFF8FF';
			trs=document.getElementById('tabella_centrale').tBodies[0].rows;
			//PRIMA RIGA
			//trs[r1].title="riga "+r1;
			//trs[rx].title="riga "+rx;
			
			tds=trs[r1].cells;
			tds[0].style.background = 'url("css/geofor/stondogrande_t.gif") no-repeat top left';
			tds[0].innerHTML="&nbsp;";
			tds[0].style.height = '11 px';
			
			//COLONNA DX
			tds=null;
			tds=trs[rx].cells;
			tds[1].style.width = '200 px';
			//tds[1].innerHTML="&nbsp;";
			
			//ULTIMA RIGA
			tds=null;
			//trs[r2].title="riga "+r2;
			tds=trs[r2].cells;
			tds[0].style.background = 'url("css/geofor/stondogrande_b.gif") no-repeat bottom left';
			tds[0].innerHTML="&nbsp;";
			tds[0].style.height = '11 px';
		//}
	}
}

/**Apre l e finestre per i contenuti*/
function mostraFinestra(padre,contenuto,generazione,create){
	//alert("tabPanels.js : mostraFinestra(padre "+padre+" cont "+contenuto+" gen "+generazione+" create "+create);
	features='menubar=no,height=600,width=800,scrollbar=yes,resizable=yes,toolbar=no,location=no,status=no';
	
	var URL="/finestra.php?padre="+padre+"&contenuto="+contenuto+"&generazione="+generazione+"&create="+create;
	MM_openBrWindow(URL, 'Finestra', features);
}

/**Cambia il background di un div chimato dai vari select livello*/
function changeDivBackgroundimage(div,url){
	//alert("tabPanels.js changeDivBackgroundimage: changeDivBackgroundimage "+document.getElementById(div).id+" div "+div+" url "+url);
	document.getElementById(div).style.backgroundImage = 'url('+url+')';
	document.getElementById(div).style.backgroundRepeat='no-repeat';
	document.getElementById(div).style.width='605px';
	document.getElementById(div).style.height='210px';
}


var padreEditor=null;
var nomeContenutoEditor=null;
var contenutoEditor=null;
var nextContenutoEditor=null;
var contenutoEditorVisibile='0';
var generazioneContenutoEditor='0';
var ivelloNuovoContenutoEditor='0';

function setNumeroContenutoEditor(contenuto){
	//alert("view.js setNumeroContenutoEditor( contenuto="+contenuto+")");
	contenutoEditor=contenuto;
}

function setNextIndexContenutoEditor(nextContenuto){
	//alert("view.js setIndexContenutoEditor( contenuto="+nextContenuto+")");
	nextContenutoEditor=nextContenuto;
}
function getNextIndexContenutoEditor(){
	//alert("view.js getNextIndexContenutoEditor( contenuto="+nextContenutoEditor+")");
	return nextContenutoEditor;
}


function setContestoEditor(padre,contenuto,generazione,visibile,livello){
	padreEditor=padre;
	contenutoEditor=contenuto;
	generazioneContenutoEditor=generazione;
	contenutoEditorVisibile=visibile;
	livelloNuovoContenutoEditor=livello;
	
	//alert("view.js setContenutoEditor( contenuto="+contenutoEditor+",padreContenuto="+padreEditor+",generazione="+generazioneContenutoEditor+",visibile="+contenutoEditorVisibile+",livello="+livelloNuovoContenutoEditor+")");
}
