﻿//Redirige alla pagina di autenticazione per gli utenti anonimi
function authenticateUser()
{
	var currentLocation = window.top.location.toString();
	var trimLocation = currentLocation.indexOf('/',9)
	var trimmedSource = currentLocation.substring(trimLocation);
	window.top.location.replace("/_layouts/authenticate.aspx?source=" + trimmedSource);
}

// THIS OVERRIDES THE OOTB SHAREPOINT FUNCTION WHICH CAUSES ACTIVEX INSTALL ISSUES
//
// Essentially it overrides the ootb sharepoint function which calls the activex object
// See http://support.microsoft.com/default.aspx/kb/931509 for info on the issue
//
function ProcessDefaultOnLoad(onLoadFunctionNames)
{
	//** Uncomment this to see when this runs
	//alert('Fixing the Issue');
	ProcessPNGImages();
	UpdateAccessibilityUI();
	
	//** We comment out the offending ootb function
	//** and leave the rest of the functions as they were
	//ProcessImn();
	for (var i=0; i < onLoadFunctionNames.length; i++)
	{
		var expr="if(typeof("+onLoadFunctionNames[i]+")=='function'){"+onLoadFunctionNames[i]+"();}";
		eval(expr);
	}
	if (typeof(_spUseDefaultFocus)!="undefined")
		DefaultFocus();
}
	
function sfFocus() {
	$('INPUT').focus(function() {$(this).addClass('sffocus')});
	$('INPUT').blur(function() {$(this).removeClass('sffocus')});
}

/* Funzioni riguardanti il menù a tendina */
var timeout         = 150;
var closetimer		= 0;
var ddmenuitem      = 0;

function menu_open()
{	menu_canceltimer();
	menu_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function menu_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function menu_timer()
{	closetimer = window.setTimeout(menu_close, timeout);}

function menu_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}
		
/* Funzione che mostra il contenuto della tendina servizi/sezione se sono in modalità editing */
function mostraDrop(){
	if($('#servizi-drop').contents().children().length >= 2){
		$('#servizi-drop').css({display: "block"});		
	}
	if($('#sezione-drop').contents().children().length >= 2){
		$('#sezione-drop').css({display: "block"});		
	}
}

/* Questa funzione prende il contenuto della tendina servizi e lo usa per creare le classi css*/
function makeStyle(){
	if($('#servizi-drop').length != 0){
		var pagina = ($.trim($('#servizi-drop')[0].innerText)).toLowerCase();
		if (pagina != ""){
			$('#pagina-')[0].id = 'pagina-'+pagina;
			for (var i = 0; i<$('#servizi > p > a').length; i++){
				$('#servizi > p > a')[i].href = ($('#servizi > p > a')[i].href).replace("xxx", pagina);
			}
		} else {
			$('#pagina-')[0].id = 'pagina-servizi';
		}
	}
	if($('#sezione-drop').length != 0){
		var pagina = ($.trim($('#sezione-drop')[0].innerText)).toLowerCase().replace(" ","-");
		if (pagina != ""){
			$('#pagina-')[0].id = 'pagina-'+pagina;
		} else {
			$('#pagina-')[0].id = 'pagina-sezione';
		}
	}

}

function getTitle(){
	var urlarray = location.href.split("/");
	var page_name = urlarray[5];
	if (page_name == "default.aspx")
	{
		if ($('.titolo-interno-').length != 0){
			var classTitolo = $('.titolo-interno-')[0];
			classTitolo.className = 'titolo-interno-regioni';
			classTitolo.innerText = 'Regioni';
		}
	} 
	else 
	{
		if (page_name != null){
			if ($('.titolo-interno-').length != 0){
				var classTitolo = $('.titolo-interno-')[0];
				classTitolo.className = 'titolo-interno-province';
				classTitolo.innerText = 'Province';
			}
		}
	}
}


//Eseguo gli script 
$(document).ready(function(){
	sfFocus();
	mostraDrop();
	makeStyle();
	getTitle();
	/* Gli script vengono eseguito solo per IE6 */
	if ($.browser.msie && $.browser.version == 6.0){
		/* Funzioni di apertura e chiusura del menu */
		$('#menuList > li').bind('mouseover', menu_open);
		$('#menuList > li').bind('mouseout',  menu_timer);
		
		/* Hover del menù orizzontale */
		$("#menuList > li").hover(function () {
	      $(this).css({ backgroundColor:"#9BCD66"});
	    }, 
	    function () {
		  $(this).css({ backgroundColor:"#EFFFC0"}); 
	    }); 

		/* Hover dei li del menù dropdown */
		$("#Aree > li").hover(function () {
	      $(this).css({ backgroundColor:"#9BCD66"});
	    }, 
	    function () {
		  $(this).css({ backgroundColor:"#578F3A"}); 
	    }); 
			
		document.onclick = menu_close;
	}
});