﻿//Funzione che crea il link agli archivi dei minisiti e lo inserisce nella spalla destra
function get_archive(){
	if ($('#archivio').html() != null && $('#consoleMenuBar1').html() == null){
		var archive = $('#archivio').text().toLowerCase();
		archive = $.trim(archive);
		if ($.browser.msie || $.browser.safari){
			archive = archive.substr(0,archive.length-1);	
		}
		$('#archivio-news').html("<a href=\"archivio.aspx?category=" + $.trim(archive) + "\"><img src=\"/Style Library/Images/fattoriedelsole/doc-archivio.gif\" /> Tutte le news &gt;&gt;</a>");
		var archiveCssclass = $.trim(archive);
		archiveCssclass = archiveCssclass.replace(/ /g,'-');
		$('#boxnews').addClass('news-'+archiveCssclass);
		$('#boxnormativa').addClass('normativa-'+archiveCssclass);
		$('#boxdocumenti').addClass('documenti-'+archiveCssclass);
	}
}

function sfFocus() {
	$('INPUT').focus(function() {$(this).addClass('sffocus')});
	$('INPUT').blur(function() {$(this).removeClass('sffocus')});
}

//Funzione che stampa il numero delle pagine. Gli viene passato il div in cui è contenuto il valore
function page_number(div_page){
	document.write(document.getElementById(div_page).innerHTML);
}

/* Funzione che prende il querystring negli indirizzi del sottosito "tecnologie" e lo integra nel pollicino*/
function getTitle(){
	var urlarray = location.href.split("/");
	var site_name = urlarray[3];
	if (site_name == "tecnologie" && location.href.indexOf("category") != -1)
	{
		var queryString = location.href.split("?");
		var qsValues = queryString[1].split("&");
		var categoryArray = qsValues[0].split("=");
		var category = categoryArray[1];
		document.title = document.title.replace("-", "- " + category + " -");
		$('#titolo')[0].innerText = $('#titolo')[0].innerText + category;
	} 
}

//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();
}

//Eseguo gli script 
$(document).ready(function(){
	sfFocus();
	getTitle();
});