﻿/* Funzione che fa scomparire il div con la navigazione per la paginazione se questa non è presente*/
function CheckDivInnerText()
{
	var pag=document.getElementById('WPZonePag')
	if (pag)
	{
		var x=pag.innerText||pag.textContent;
		if (x == "Object reference not set to an instance of an object."){
			//alert(x);
			pag.style.display="none";
		} else {
			pag.style.display="block";
		} 
	}			
}

//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);

}

/* Funzione che resetta il dropdown delle categorie dei sottositi*/
function pulisci()
{	
	var ogg=document.body.getElementsByTagName("SELECT");
	for(var i=0;i<ogg.length;i++)
	{		
		var op=ogg[i];	
		if(op!=null && op.id.indexOf('DropDownChoiceField')>-1)
		{
			op.selectedIndex=-1;
		}
	}	
}


// 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')});
}

function getTitle(){
	var urlarray = location.href.split("/");
	var page_name = urlarray[5];
	if (page_name == "default.aspx")
	{
		site_name = urlarray[3];
		if ($('.archivi > a').length != 0){
			$('.archivi > a')[0].href = $('.archivi > a')[0].href.replace("default.aspx", site_name + '.aspx?Site=' + site_name);
		}
	} 
}

function highlightMenu(){
	if ($('#toolbar > ul > li').length != 0){
		for (i = 0; i < $('#toolbar > ul > li').length; i++){
			categoria = $('#toolbar > ul > li')[i].innerHTML; 
			for (j = 0; j < $('#navsx > ul > li > a').length; j++){
				if (categoria.indexOf($('#navsx > ul > li > a')[j].innerHTML) > -1){
					$('#navsx > ul > li')[j].innerHTML = '<span class="selezionato">'+ $('#navsx > ul > li > a')[j].innerHTML +'</span>';
				}
			}
		}
	}
}

//Eseguo gli script 
$(document).ready(function(){
	sfFocus();
	getTitle();
	highlightMenu();
});
