//***********************CORE DI YEBO CMS - VERSIONE 1.5 BETA ****************



var gallery = new Array (); 

$.post("lib/core.php",{cosa:"js_enable"} ,function(data)
        {
		  if(data=='OK') 
		  {
		
		  } 
		 
		 });

jQuery().ready(function(){


						

						
$("#notifica_login").hide() ;
$("#loader").hide() ;
$("#sp_login").load(login_url);

 
//load_contents(-1,0,'contenuto','Home Page');

$.post("lib/core.php",{cosa:"stato_login"} ,function(data)
        {
		  if(data=='1') 
		  {			
		
			/*document.getElementById('login_form1').style.visibility = 'hidden';
			
			
			document.getElementById('tdlogout').style.width='200px';
			document.getElementById('logout_click').innerHTML = '<a href="javascript:logout_website();">Logout dal sito</a>';
			
*/					
		   
		   }else{
		  
			/*document.getElementById('login_form1').style.visibility = 'visible';
			
			document.getElementById('tdlogout').style.width='0px';
		document.getElementById('logout_click').innerHTML = '';*/
		   
		   }
			   
		   
		 });
	


});	

//******

if (menu_verticale==1){
var menuids=["mn_ver"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
		if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
			ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
		else //else if this is a sub level submenu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
		ultags[t].style.visibility="visible"
		ultags[t].style.display="none"
		}
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus)
}//fine if di controllo

if (menu_orizzontale==1){
var menuids1=["mn_ori"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus_horizontal(){
for (var i=0; i<menuids1.length; i++){
  var ultags=document.getElementById(menuids1[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
		if (ultags[t].parentNode.parentNode.id==menuids1[i]){ //if this is a first level submenu
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
			ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"
		}
		else{ //else if this is a sub level menu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    	ultags[t].parentNode.getElementsByTagName("a")[0].className="subfoldericon"
		}
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.visibility="visible"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.visibility="hidden"
    }
    }
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus_horizontal)
}//fine if di controllo

function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}


function printPartOfPage(elementId)

{

var printContent = document.getElementById(elementId);

var windowUrl = 'about:blank';

var uniqueName = new Date();

var windowName = 'Print' + uniqueName.getTime();

var printWindow = window.open(windowUrl, windowName, 'left=0,top=0,width=1,height=1');

printWindow.document.write(printContent.innerHTML);

printWindow.document.close();

printWindow.focus();

printWindow.print();

printWindow.close();

//alert(printContent.innerHTML)

}



function logout_website(){
	

	


	
	
		$.post("lib/core.php",{cosa:"logout"} ,function(data)
        {
		  if(data=='OK') 
		  {
		

			$("#" + div_login).load(login_url);
			refresh_news();
				   
		   }else{
		   
	
		   
		   
		   }
		   
		   
		   
		 });
	
	
	

	
	
}//fine funzione logout_website

function refresh_news(){
	
	if ( abilita_frame_news == 1 ){
		var f = document.getElementById('newsframe');
f.src = f.src;

		
	}

}

function login_website(){

document.getElementById('loader').style.visibility = 'visible';
nome = document.getElementById('input_username').value ;
pass = document.getElementById('input_password').value ;
	
if ( nome !='' && pass !=''){
	//eseguo il login 
	
	
		$.post("lib/core.php",{nome:"" + nome + "",cosa:"login",pass:"" + pass + ""} ,function(data)
        {
		  if(data=='OK') //if correct login detail
		  {
		
			
			
	
				$("#" + div_login).load(login_url);
			
				refresh_news();
		
		   
		   }else{
		   
		 alert('Attenzione . Login errato !');
		   
		   }
		   
		   
		   
		 });
	
	
	
	
}else{
//dati mancanti
 alert('Attenzione .Dati Mancanti !');
		
	
}

document.getElementById('loader').style.visibility = 'hidden';
	
	
}//fine funzione login_website

function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}


function fbs_click(l,t) {

	
	window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(l) + '&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
	
} 




function load_contents(tipo,cod_tipo,div_name,lbl,indirizzo,sito){
	if (tipo!=2 && tipo!=0){
	loadjscssfile("lib/facebook.js", "js");
	document.getElementById(div_name).innerHTML  = '<center><img src="img/loading_html.gif"><br> Caricamento pagina in corso ...<center>';
	document.getElementById('pospage').innerHTML  = '<a href="" onclick="printPartOfPage(\'' + div_name +'\');return false;"><img src="img/print.png" height="25" width="25" border="0" alt="Stampa" /></a>' ;
	
	if ( indirizzo == null ) {
		document.getElementById('pospage').innerHTML  = document.getElementById('pospage').innerHTML +'&nbsp;<a onclick="fbs_click(\'' + document.location + '\',\''+  document.location + ' - ' + lbl + '\');return false;" href=""><img src="img/facebook.png" height="25" width="25" border="0" alt="Condividi in Facebook" /></a>' + ' - ' +  lbl ;
		
	}else{
		
		document.getElementById('pospage').innerHTML  = document.getElementById('pospage').innerHTML +'&nbsp;<a onclick="fbs_click(\'' + indirizzo + '\',\''+  sito + ' - ' + lbl + '\');return false;" href=""><img src="img/facebook.png" height="25" width="25" border="0" alt="Condividi in Facebook" /></a>' + ' - ' +  lbl ;
	}
	
	
	


	}
	
	
	switch (tipo){
		
		
		case -2 :
		//Carica Album
		load_album(cod_tipo,div_name);
		
		break ;
		
		case -1 :
		
		load_home_page(div_name);
		
		break ;
		
		case 1 :
		//Pagina html
		
		load_html_page(cod_tipo,div_name);
		
		break ;
		
		
		case 2 :
		//Pagina esterna
		
		load_ext_page (cod_tipo);
		
		break ;
		
		
		case 3 :
		//galleria
		
		load_gallery(cod_tipo,div_name);
		
		break ;
		
		
		case 4 :
		//categoria
		load_category(cod_tipo,div_name);
		
		break ;
		
		
	}//fine switch
	
	
	
}//fine function load contents


function load_news(){
	
	
	
	
}//fine funzione load_news


function load_ext_page(cod){
	//carico contenuto pagina html
	
	
		$.post("lib/core.php",{cod:"" + cod + "",cosa:"2"} ,function(data)
        {
		  if(data!='') //if correct login detail
		  {
		
			
			
		window.open(data,'','');
	
		   
		   }else{
		   
			
		  
		   
		   
		   }
		   
		   
		   
		 });

	
		
	
	
	
}//fine function load_html_page

function form_confirm(id){
	//conferma dati nella form
	
document.getElementById('form_confirm_' + id).disabled=true ;
	
hid = document.getElementById('hid_form_' + id).value;
res = '' ;
var vett = hid.split("|");
mancanti = 0 ;

	for (i=1 ; i<vett.length -1 ;i=i+3){
		
			switch (vett[i]){
				
				case '1' : case '3' :
				if (document.getElementById('FL_' + vett[i+1]).value.replace('|','/') == ''){
					res = res + ' |';
					
				}else{
				res = res + document.getElementById('FL_' + vett[i+1]).value.replace('|','/')  + '|';
				}
				break ;
				
				
				case '2' :
				if ( document.getElementById('FL_' + vett[i+1]).options[document.getElementById('FL_' + vett[i+1]).selectedIndex].text.replace('|','/') ==''){
					
					res = res + ' |';
					
				}else{
				res = res + document.getElementById('FL_' + vett[i+1]).options[document.getElementById('FL_' + vett[i+1]).selectedIndex].text.replace('|','/') + '|' ;
				}
				break ;
				
			}//fine switch
		
		if (vett[i+2] == '1') {
			//verifico compilazione campo
			
			switch (vett[i]){
				
				case '1' : case '3' :
				
					if ( document.getElementById('FL_' + vett[i+1]).value ==''){
						
					mancanti = 1 ;	
					}//fine if
					
					
				
				
				break ;
				
				case '2' :
				
				if ( document.getElementById('FL_' + vett[i+1]).options[document.getElementById('FL_' + vett[i+1]).selectedIndex].text ==''){
						
					mancanti = 1 ;
					
				}//fine if
				
				
				
				break ;
				
			}//fine switch
			
			
		}//fine if
		
	
		
	}//fine for

if ( mancanti == 0 ){

		
		$.post("lib/core.php",{hid:"" + hid + "",cosa:"save_data",res:"" + res + ""} ,function(data)
        {
			
		  if(data.substring(0,6)=='ERRORE') //if correct login detail
		  {
		
				
			alert(data);
		
		   
		   }else{
		     
		   
		   	alert(data);
		   //pulisco i campi
			for (i=1 ; i<vett.length -1 ;i=i+3){
				
			if (vett[i]=='1' || vett[i]=='3' ){
				 document.getElementById('FL_' + vett[i+1]).value ='' ;
					
			}//fine if
				
				
				
			}//fine for
			
			
			
		   
		   }
		   
		   
		   
		 });


	
			
	
	
}else{
	alert('Attenzione . Dati Mancanti !');
	
}//fine ifelse

	document.getElementById('form_confirm_' + id).disabled=false ;
	
	
		

}



function load_html_page(cod,div_name){
	//carico contenuto pagina html
	
	
		$.post("lib/core.php",{cod:"" + cod + "",cosa:"1",lan:"" + lingua_attuale + ""} ,function(data)
        {
		  if(data!='!PROTECT!') //if correct login detail
		  {
		
			
			document.getElementById(div_name).innerHTML = data ;
			
		
	
		   
		   }else{
		   
			document.getElementById(div_name).innerHTML  = '<center><img src="img/html_lock.jpg"><br> Pagina Protetta - Effettuare il login ...<center>';
		  
		   
		   
		   }
		   
		   
		   
		 });

	
		
	
	
	
}//fine function load_html_page


function load_category(cod,div_name){
	//carico contenuto pagina html
	
	
	
		$.post("lib/core.php",{cod:"" + cod + "",cosa:"4",div:""  + div_name + "",lan:"" + lingua_attuale + ""} ,function(data)
        {
			
		  if(data!='!ERR!') //if correct login detail
		  {
		
			
			document.getElementById(div_name).innerHTML = data ;
			
		
	
		   
		   }else{
		   
			//document.getElementById(div_name).innerHTML  = '<center><img src="img/html_lock.jpg"><br> Galleria Protetta - Effettuare il login ...<center>';
		  
		   
		   
		   }
		   
		   
		   
		 });

	
}


function load_gallery(cod,div_name){
	//carico contenuto pagina html
	
	
		$.post("lib/core.php",{cod:"" + cod + "",cosa:"3",div:""  + div_name + "",lan:"" + lingua_attuale + ""} ,function(data)
        {
		  if(data!='!PROTECT!') //if correct login detail
		  {
		
			
			document.getElementById(div_name).innerHTML = data ;
			
		
	
		   
		   }else{
		   
			document.getElementById(div_name).innerHTML  = '<center><img src="img/html_lock.jpg"><br> Galleria Protetta - Effettuare il login ...<center>';
		  
		   
		   
		   }
		   
		   
		   
		 });

	
		
	
	
	
}//fine function load_html_page


function load_album(cod,div_name){
	//carico contenuto pagina html
	
	
		$.post("lib/album.php",{cod:"" + cod + "",div:""  + div_name + "",lan:"" + lingua_attuale + ""} ,function(data)
        {
		  if(data!='!PROTECT!') //if correct login detail
		  {
		
			
			document.getElementById(div_name).innerHTML = data ;
			
		
	
		   
		   }else{
		   
			//document.getElementById(div_name).innerHTML  = '<center><img src="img/html_lock.jpg"><br> Galleria Protetta - Effettuare il login ...<center>';
		  
		   
		   
		   }
		   
		   
		   
		 });

	
		
	
	
	
}//fine function load_html_page



function read_all_news(div_name){
	document.getElementById(div_name).innerHTML  = '<center><img src="img/loading_html.gif"><br> Caricamento pagina in corso ...<center>';
	document.getElementById('pospage').innerHTML  = 'Tutte le news';
	
	$.post("lib/core.php",{cosa:"read_all_news",lan:"" + lingua_attuale + ""} ,function(data)
        {
		  if(data!='') //if correct login detail
		  {
		
			
			document.getElementById(div_name).innerHTML = data ;
			
		
	
		   
		   }else{
		  
		  
		   
		   
		   }
		   
		   
		   
		 });

	
	
	
	
}//fine funzione read_all_news


function read_one_news(cod,lbl,div_name){
	document.getElementById(div_name).innerHTML  = '<center><img src="img/loading_html.gif"><br> Caricamento pagina in corso ...<center>';
	document.getElementById('pospage').innerHTML  = 'NEWS : ' + lbl;
	
	$.post("lib/core.php",{cosa:"read_one_news",cod:"" + cod + "",lan:"" + lingua_attuale + ""} ,function(data)
        {
		  if(data!='') //if correct login detail
		  {
		
			
			document.getElementById(div_name).innerHTML = data ;
			
		
	
		   
		   }else{
		  
		  
		   
		   
		   }
		   
		   
		   
		 });

	
	
	
	
}//fine funzione read_all_news


function imghtm(cod,lbl){
//$("#loader_album").show() ;
	document.getElementById('loader_album').style.visibility = 'visible';
	
	
		$.post("lib/core.php",{cosa:"imghtm",cod:"" + cod + "",lan:"" + lingua_attuale + ""} ,function(data)
        {
		  if(data!='erro!!') //if correct login detail
		  {
		
			
		
			document.getElementById('imgtitdiv').innerHTML = lbl ;
			
			if (data==''){
			document.getElementById('imghtmdiv').innerHTML ='Nessuna descrizione per questa immagine';
			
				
			}else{
			document.getElementById('imghtmdiv').innerHTML = data ;
			}
			
			document.getElementById('loader_album').style.visibility = 'hidden';
			//$("#loader_album").hide() ;
	
	
		   
		   }else{
		  
		  
		   
		   
		   }
		   
		   
		   
		 });
	
	





	
	
}//fine visimg


function visimg(cod,tipo,lbl){


	
	GB_showImage(lbl,img_album_path + cod + '.' + tipo);


	
}//fine visimg



function load_home_page(div_name){
	//carico contenuto pagina html
	
	
		$.post("lib/core.php",{cosa:"load_home",lan:"" + lingua_attuale + ""} ,function(data)
        {
		  if(data!='') //if correct login detail
		  {
		
			
			document.getElementById(div_name).innerHTML = data ;
			
		
	
		   
		   }else{
		  
		  
		   
		   
		   }
		   
		   
		   
		 });

	
		
	
	
	
}//fine function load_home_page
