﻿/* Script per cambiare colore al campo ricerca quando selezionato */
function sfFocus() {
	$('INPUT').focus(function() {$(this).addClass('sffocus')});
	$('INPUT').blur(function() {$(this).removeClass('sffocus')});
}

/* Script per nascondere i tasti di navigazione del forum */
function nascondiBack() {
	var url=document.location.href.toLowerCase();
	$.currurl = document.location.href.toLowerCase();

	if(url.indexOf("allitems.aspx")==-1 && url.indexOf("/lists/")>-1)
	{	
		$('#torna-forum').removeClass('torna-forum-nascosto');
		$('#torna-forum').addClass('torna-forum');
	}
	if(url.indexOf("default.aspx")==-1 )
	{
		$('#title-community').removeClass('title-community-nascosto');
		$('#title-community').addClass('title-community');
	}
}


// 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();
}	

//Estrae dalla pagina il LogonName -- METODO DA RISCRIVERE SERVER SIDE
function getUserName() 
{ 
	var username = 'Anonimo'; 
	var sSearch = 'Opzioni per'; 
	// Cerco in testata-editing
	if (document.getElementById('testata-editing'))
	{
		var HTMLActionsMenu = document.getElementById('testata-editing').innerHTML; 
		var iOpzioni = HTMLActionsMenu.indexOf('Opzioni per'); 
		// Se esiste il logonname in pagina 
		if (iOpzioni > -1) 
		{ 
			var iEndOpzioni = HTMLActionsMenu.indexOf('<' , iOpzioni); 
			username = HTMLActionsMenu.substring(iOpzioni + sSearch.length , iEndOpzioni); 
		} 
	}
	return username; 
}

function getUserNameOK() 
{ 
	var username = 'Anonimo'; 
	var sSearch = 'Opzioni per'; 
	var divaccount=document.getElementById('account');
	// Cerco in testata-editing
	if (divaccount)
	{
		username = divaccount.innerText; 
	}
	return username; 
}

//elimina la voce 'tutti i siti' dalla combo di ricerca del forum
function impostaScope() {
	var ogg=$("SELECT");
	if(ogg.length>0)
	{
		var oggs=ogg[0];
		if(oggs.id.indexOf('SBScopesDDL')>-1 && (oggs.className=='ms-sbscopes'))
		{
			var i= oggs.selectedIndex;
			oggs.options.remove(i);
			var oOption = document.createElement("OPTION");
			var n=oggs.options.length;
			oggs.options.add(oOption,n);
			oOption.innerText = "Tutte le aree";
			oOption.selected=true;
		}
	}
}

//nasconde lo stato e bottone ok dalle form del buy e del contact center
function nascondiStato()
{
	var ogg=document.body.getElementsByTagName("A");
	var i=0;
	var adm=false;
	var inform=false;
	var newform=false;
	var visform=false;

	var loc=document.location.href;
	if(loc.indexOf('EditForm.aspx')>-1)
	{
		inform=true;
	}
	if(loc.indexOf('NewForm.aspx')>-1)
	{
		newform=true;
	}
	if(loc.indexOf('DispForm.aspx')>-1)
	{
		visform=true;
	}

	while(i<ogg.length)
	{
		var oggs=ogg[i];
		
		if(oggs.id.indexOf('DeleteItem')>-1 && (oggs.className=='ms-toolbar'))
		{
			adm=true;
			i=ogg.length + 1;
		}
		i++;
	}

	if(!adm)
	{
		//new
		if(newform)
		{
			//disabilito stato
			ogg=document.body.getElementsByTagName("SELECT");
			i=0;
			while(i<ogg.length)
			{
				var oggs=ogg[i];
				if(oggs.id.indexOf('Lookup')>-1 && (oggs.title=='Stato'))
				{
					oggs.disabled=true;
					i=ogg.length + 1;
				}
				i++;
			}
			
			//disabilito risposta
			ogg=document.body.getElementsByTagName("TEXTAREA");
			i=0;
			while(i<ogg.length)
			{
				var oggs=ogg[i];
				if(oggs.id.indexOf('TextField')>-1 && (oggs.title=='Risposta'))
				{
					oggs.disabled=true;
					i=ogg.length + 1;
				}
				i++;
			}
		}
		
		//visualizza
		if(visform)
		{
		ogg=document.body.getElementsByTagName("TABLE");
			i=0;
			while(i<ogg.length)
			{
				var oggs=ogg[i];
				
				if((oggs.className=='ms-toolbar'))
				{
					//oggs.href="#";
					//oggs.onclick="";
					//oggs.disabled=true;
					oggs.className='nascosto';
					i=ogg.length + 1;
				}
				i++;
			}
		}
		
		//modifica
		if(inform)
		{
			ogg=document.body.getElementsByTagName("INPUT");
			i=0;

			while(i<ogg.length)
			{
				var oggs=ogg[i];
		
				if(oggs.type=='button' && oggs.value=='OK')
				{
					oggs.disabled=true;
				}
				if(oggs.type=='text' && oggs.id.indexOf('InputKeywords')==-1)
				{
					oggs.disabled=true;
				}
				i++;
			}
			
			ogg=document.body.getElementsByTagName("TEXTAREA");
			i=0;
			while(i<ogg.length)
			{
				var oggs=ogg[i];
				oggs.disabled=true;
				i++;
			}
			
			ogg=document.body.getElementsByTagName("SELECT");
			i=0;
			while(i<ogg.length)
			{
				var oggs=ogg[i];
				oggs.disabled=true;
				i++;
			}

			ogg=document.body.getElementsByTagName("A");
			i=0;
			while(i<ogg.length)
			{
				var oggs=ogg[i];
				if(oggs.href.indexOf('javascript:RemoveAttachmentFromServer')>-1 )
				{
					oggs.href="#";
					oggs.disabled=true;
					//i=ogg.length + 1;
				}
				if(oggs.id.indexOf('Attach_LinkText')>-1 && (oggs.className=='ms-toolbar'))
				{
					oggs.href="#";
					oggs.onclick="";
					oggs.disabled=true;
				}
				i++;
			}
		}//inform
	}//not adm
}

//Eseguo gli script 
$(document).ready(function(){
	sfFocus();
	nascondiBack();
	impostaScope();
	//Apre il popup di stampa
	$('.stampa > a').click(function(){window.open("/print.aspx","_blank","height=500,width=700,resizable=no,status=no,toolbar=no,menubar=yes,location=no,scrollbars=yes");return false;});
});
