﻿/* random images */
function randomImg() {
	if(document.getElementById("imageSplash") == null){
		var UrlStatic = "/SiteCollectionImages/";
		var exst = ".jpg";
		var randomNum = Math.floor(Math.random()*3) + 1;
		var img = UrlStatic + "testata_" + randomNum + exst;
		//document.getElementById("imgRan").style.display = "block";
		document.getElementById("imgRan").src = img ;
		}
}

var searchOn = true;
 
/* auto focus on tabs */
function checkTab(){

	if(document.getElementById("archTab")!=null)
	{
		if(document.getElementById("archTab").value!="0")
			showTab(document.getElementById("archTab").value);
		else
			showTab(comTab);

	}
	else
	{
		if(parent.ifr_comunicati){
		parent.ifr_comunicati.showTab(comTab);
		}
		if(parent.ifr_eventi){
		parent.ifr_eventi.showTab(comTab);
		}
		if(parent.iframe_sx){
		parent.iframe_sx.showTabEv(comTab);
		}
	
		if(document.getElementById("comInvMed") && searchOn) {
			showTab(comTab);
		}
	}
}

function showTab(divId)
{	
	searchOn = false;
	numTabs = 3;
	for ( i=1;i<=numTabs;i++)  {
		if( i == divId) {
			document.getElementById("eventi_" + divId).style.display = "block";
			document.getElementById("tabeventi_" + divId).className = "tabEventi_on";
			
		}
		else {
			document.getElementById("eventi_" + i).style.display = "none";
			document.getElementById("tabeventi_" + i).className = "tabEventi_off";
		}
	}
			
}



function showTabEv(divId)
{	
	numTabs = 4;
	for ( i=1;i<=numTabs;i++)  {
		if( i == divId) {
			document.getElementById("eventi_" + divId).style.display = "block";
			document.getElementById("tabeventi_" + divId).className = "tabEventi_on";
			
		}
		else {
			document.getElementById("eventi_" + i).style.display = "none";
			document.getElementById("tabeventi_" + i).className = "tabEventi_off";
		}
	}
			
}

/* NUOVA FUNZIONE PER LA COMMUTAZIONE PAGINA ITA ENG A LIVELLO DELL 'ITEM */
function getXmllHttpRequest() {
                var obj;
                if (window.XMLHttpRequest) obj= new XMLHttpRequest(); 
                else if (window.ActiveXObject){
                               try{
                                               obj= new ActiveXObject('Msxml2.XMLHTTP');
                               }
                               catch(er){
                                               try{
                                                               obj= new ActiveXObject("Microsoft.XMLHTTP");
                                               }
                                               catch(er){
                                                               obj= false;
                                               }
                               }
                }
                return obj;
          
}


/* NUOVA FUNZIONE PER LA COMMUTAZIONE PAGINA ITA ENG A LIVELLO DELL 'ITEM */
    function pageExists(url) {
        var req = new getXmllHttpRequest(); 
        try {
            req.open("GET", url, false);            
            req.send(null);
            if (req.status != 200) return false;

            if (req.responseText.indexOf("_layouts/error.aspx") == -1)
                return true;
            else
                return false;

        }
        catch (er) {
            return false;
        }
    }

/* NUOVA FUNZIONI PER LA COMMUTAZIONE PAGINA ITA ENG CON REINDIRIZZAMENTO ALLA HOME*/
/*function SetLanguage(lang)
{
var loc;
var curloc;
var oldloc=window.location.href.toLowerCase();
if(lang=="it")
{
loc=oldloc.replace("/int/en","");
}
else
{ 
curloc=oldloc.replace("/int/en","");
var host=curloc.indexOf("/",7);

loc=curloc.substr(0,host)+"/int/"+lang.toLowerCase() +"/"
}

document.location.href=loc;
window.location.replace(loc);
}
*/
/*---------------------------------------------------------------------------------*/

function SetLanguage(lang)
{
	var loc;
	var oldloc=window.location.href.toLowerCase();
	if(lang=="it")
	{
		loc=oldloc.replace("/int/en","");
	}
	else
	{		
		var curloc=oldloc.replace("/int/en","");
		var host=curloc.indexOf("/",7);
		loc=curloc.substr(0,host)+"/int/"+lang.toLowerCase() +"/"+curloc.substr(host+1);
	}
	
	document.location.href=loc;
	window.location.replace(loc);
}

function FixFeatureButtons()

{

var toolMail;
var toolPrint;
var toolPref;

toolMail=document.getElementById("ico_alert");
if(toolMail!=null)
	toolMail.href="mailto:?subject=Link sito UGF: "+window.document.title+"&body="+window.location.href;

toolPrint=document.getElementById("ico_print");
if(toolPrint!=null)
	toolPrint.href="javascript:window.print();";

toolPref=document.getElementById("ico_pref");

if(toolPref!=null)
{	
	if (window.sidebar) { 
		toolPref.href="javascript:window.sidebar.addPanel('"+window.document.title+"', '"+window.location.href+"','')"; 
	} 
	else {
		toolPref.href="javascript:window.external.addfavorite('"+window.location.href+"','"+window.document.title+"');";
	}
}

}

function FixJob()
{
	var curPath=document.getElementById("curPath");
	if(curPath.innerHTML.indexOf("Lavora con")>0)
	{
		var title=document.getElementById("spanMenuTitle"); //.innerText="Lavora con noi";
		title.innerHTML="Lavora con noi"
	}
}

function expanfFaq(numFaq) {
 var head;
 var elem;
 var img;
 elem = document.getElementById("faqnum_" + numFaq);
 img = document.getElementById("faqimg_" + numFaq);
 row = document.getElementById("real_row_" + numFaq);
 //alert(numFaq + "--" + elem  + "--" + img + "--" + row);
if(elem.style.display == "none" || elem.style.display == "") {
 	elem.style.display = "block";
 	img.src = "/_layouts/images/minus.gif";
 	row.style.marginBottom = "20px";
 }
 else {
 	elem.style.display = "none";
 	img.src = "/_layouts/images/plus.gif";
 	row.style.marginBottom = "0px";

 }
 if(document.getElementById('box_arch'))
 	{ checkIfr('box_arch');}
 if(document.getElementById('form1'))
 	{ checkIfr('form1');}

 }



function checkIfr(label) {
	elem = document.getElementById(label);
	newH = elem.scrollHeight;
	if(label == 'box_arch'){ parent.resizeIfr(newH); }
	if(label == 'form1'){ parent.resizeIfrFaq(newH); }

}


function resizeIfr(setH) {
	ifr = document.getElementById("ifr_archdoc");
	ifr.style.height = setH + "px";
}

function resizeIfrFaq(setH) {
	ifr = document.getElementById("ifr_faq");
	ifr.style.height = setH + 200 + "px";
}

function winPopup(page, left, top, width, height)
{
	var __wpopup = window.open(page, "__wpopup", "left=" + left + ",top=" + top + ",width=" + width + ",height=" + height);
	__wpopup.focus();		
}

/*
function expandDoc(area) {
	alert(area);
}

var start_quot = 0;
function checkSize(ifrid) {

var elem = document.getElementById(ifrid);
elem.style.overflow = "auto";
	if (start_quot !== 0) {
	alert ("scrollH: " +  elem.document.body.scrollHeight);
	//var scrollifr = elem.document.body.scrollHeight;
	//var newH = scrollifr + 200;
	//elem.style.height = newH  + "px";
	}else{//elem.style.height = "250px"; 
	start_quot++; }
}
*/

function GoToQuikLink(){
		var element = document.getElementById("quicklinkselect");
		var linkString = element.value;
			
		if ((linkString != '*') && (linkString.replace(/^ +/,"").length != 0)){
			var n = linkString.indexOf('|');
			
			var iLink = linkString.substring(0,n);
			var iTarget = linkString.substring(n+1);
			
			OpenNewWindow(iLink,iTarget);
			return false;
		}
	}
	
	function OpenNewWindow(url,iTarget){
		
		switch(iTarget){
			case '1':
				var target = "_blank";
				break;    
			case '0':
				var target = "_self";
				break;
			default:
				var target = "_blank";
		}
	
		window.open(url,target);
		//return false;
	}
