// FUNZIONE PER SISTEMARE IL FOOTER IN BASSO IN CASO DI POCHI CONTENUTI IN PAGINA
function setAltezzaAreaCentrale(par){
		var h = "";
		var h_fissa = "0";
		if(par=="offset"){
			//alert("offset")
      		h = document.body.offsetHeight;
      		h_fissa = "20";
      	}
   		else if(par=="client"){
   			//alert("client")
      		h = document.documentElement.clientHeight;         		   		
      	}
      	else
      		alert("indicare il parametro!")
      	
      	var h_footer = document.getElementById("footer").offsetHeight;
      	var h_testata = document.getElementById("testata").offsetHeight;      	
      	var h_finale = (h-h_testata-h_footer-h_fissa);
      	//alert("altezza documento:"+h + "\n" + "altezza testata:"+h_testata  + "\n" + "altezza footer:"+h_footer  + "\n" + "altezza fissa:"+h_fissa);
      	//alert("altezza finale:"+h_finale);
      	if (document.getElementById("riga_centrale") && h_finale > 0)
      	{
      		document.getElementById("riga_centrale").style.height = h_finale +"px";
      	}
}


function apriart7(){  		
	var startpath= "";
	if (document.location.pathname.substr(0,15) == '/magnoliaAuthor')
		startpath = '/magnoliaAuthor';
		
	//apriFinestra(startpath+'/docroot/sipra/static/articolo7.html', 650, 450, 'no', 'yes');
	openPopUp(startpath+'/it/sipra/articolo7.html');
	
}

function getApplicazione(){  		
	var startpath= "";
	if (document.location.pathname.substr(0,15) == '/magnoliaAuthor')
		startpath = '/magnoliaAuthor';
		
	return startpath;		
}

function apriNoteLegali(language){
	var startpath= "";
	if (document.location.pathname.substr(0,15) == '/magnoliaAuthor')
		startpath = '/magnoliaAuthor';	
	
	//apriFinestra(startpath+'/docroot/sipra/static/' + lang + '/noteLegali.html', 650, 340, 'no', 'yes', true);
	openPopUp(startpath+'/' + language + '/sipra/noteLegali.html');
}

function apriPopup(link){
	var startpath= "";
	if (document.location.pathname.substr(0,15) == '/magnoliaAuthor')
		startpath = '/magnoliaAuthor';	

	if (link.substr(0,1) != '/')
		startpath = startpath + '/';	
	
	openPopUp(startpath + link);
}

function apriFinestra(url, dimx, dimy, scrollbars, resizable, centrata){
	var winl = 200;
	var wint = 150;
	
	if(centrata){		
		winl = (screen.width-dimx)/2;
		wint = (screen.height-dimy)/2;
	}
	window.open(url,'miaFinestra','width='+dimx+',height='+dimy+' ,toolbar=no, location=no,status=no,menubar=no,scrollbars='+scrollbars+',resizable='+resizable+', top='+wint+', left='+winl);
}

function apriWindow(link){
	var startpath= "";
	if (document.location.pathname.substr(0,15) == '/magnoliaAuthor')
		startpath = '/magnoliaAuthor';	

	if (link.substr(0,1) != '/')
		startpath = startpath + '/';	

	window.open(startpath + link);		
}

function controllacheck(){
    if(document.getElementById('confermo').checked){
		    document.location.href = "mailto:dperorg@sipra.it";
	}else{
			alert("E' necessario confermare di aver letto l'informativa");
	}
}

function popupcdradio(edizione)
{
	
	var startpath= "";
	if (document.location.pathname.substr(0,15) == '/magnoliaAuthor')
		startpath = '/magnoliaAuthor';	

	window.open(startpath + "/docroot/sipra/static/radio/cd/" + edizione + "/home.html","CdMultimedialePalinsestoRadio","width=1024,height=768,top=0,left=0,screenX=0,screenY=0,scrollbars=yes,location=no,menubar=no,resizable=no,toolbar=no");
}

function palinsestoraiprimavera2009()
{
	
window.open("/docroot/sipra/static/manifestazioni/raipalinsestoprimavera2009/index.html","PresentazionePalinsestoRaiPrimavera2009","width=840,height=650,top=50,left=50,screenX=50,screenY=50,scrollbars=no,location=no,menubar=no,resizable=no,toolbar=no");

}

//02/03/2009 - cd canali specializzati prima edizione 2009
function popupcdcanalispecializzati2009()
{
	
window.open("/docroot/sipra/static/tvtematiche/cdprimaedizione2009/canali.html","CdMultimedialeCanaliSpecializzati","width=1024,height=768,top=0,left=0,screenX=0,screenY=0,scrollbars=yes,location=no,menubar=no,resizable=no,toolbar=no");

}

//-----------------------------------------------------------------------------------
//funzioni inglobate da codice.js in modo che siano disponibili in tutte le pagine
//(prima codice.js era incluso solo nelle pagine statiche del palinsesto TV)
//-----------------------------------------------------------------------------------

function goSipra()
{	
	window.open("http://www.sipra.it/","newsipra","width="+screen.availWidth+",height="+screen.availHeight+",screenX=0,screenY=0,top=0,left=0,scrollbars=yes,resizable=yes,toolbar=yes,status=yes,menubar=yes,location=yes");
	//self.close();
}


function goRai()
{	
	window.open("http://www.rai.it/","newrai","width="+screen.availWidth+",height="+screen.availHeight+",screenX=0,screenY=0,top=0,left=0,scrollbars=yes,resizable=yes,toolbar=yes,status=yes,menubar=yes,location=yes");
	//self.close();
}


function getBrowser(){
	var browserName=navigator.appName; 
	if (browserName=="Netscape"){ 
	 	return "no_ie";
	}
	else 
	{ 
		if (browserName=="Microsoft Internet Explorer")	 
	 		return "ie";
	 	else
	    	return "no_ie";	   
	}	
}

function reSizzatiScheda(tagName){	
		self.moveTo(10,10);		
		var alt = getAltezza(tagName)+55;
		var lar = getLarghezza(tagName)+50;		
	
		max_alt = screen.availHeight-50;
		if(alt>max_alt){
			alt = max_alt;
		}
		
		self.resizeTo(lar,alt);	
}

function reSizzati(tagName, centrata)
{		
		if (!centrata)
		{
			self.moveTo(0,0);
		}
		
		var spreadX;
		var spreadY;
		
		if(getBrowser()=="ie"){
			//alert("IE")
			spreadX = 60;
			spreadY = 50;	//80
		}
		else{		// altri browser
			//alert("altro browser")
			spreadX = 35;
			spreadY = 130;
		}
		
		var alt = getAltezza(tagName)+spreadY;
		var lar = getLarghezza(tagName)+spreadX;
		
		//alert("altezza:"+alt)
		//alert("larghezza:"+lar)
		
		max_alt = screen.availHeight;
		
		if(alt>max_alt){
			//alert("altezza maggiore del disponibile")
			alt = max_alt;
		}
		
		self.resizeTo(lar,alt);
		
		if (centrata)
		{
			//centro il popup sullo schermo dopo che la finestra si è ridimensionata
			var winl = (screen.width-lar)/2;
			var wint = (screen.height-alt)/2;
			self.moveTo(wint,winl);
		}
}

function getAltezza(tagName){
	var altabella = document.getElementById("tabrutta").offsetHeight;

	return altabella;
}

function getLarghezza(tagName){
	var valore = document.getElementById("tabrutta").offsetWidth;
	//alert(valore)

	return valore;
}

function openPopUp(strLink)		// FUNZIONE PER APRIRE UN POPUP SPECIFICANDO IL NOME DEL FILE
{      
	popup=window.open(strLink,"siprapopup","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,height=100,resizable=no,width=100,directories=0")
	
}


// intercetta il browser
function qualeBrowser()
{
	var br = "ff";	
	if (document.all)
		br = "ie"			

	return br;
}

function showVideo4_3a_small(title, streamName)
{
	showPlayer(title, streamName, 'player4-3-384x324.swf', '', '')
}

function showVideo4_3_small(title, streamName)
{
	showPlayer(title, streamName, 'player4-3.swf', '', '')
}

function showVideo16_9_small(title, streamName)
{
	showPlayer(title, streamName, 'player16-9.swf', '', '')
}

function showVideo4_3a_large(title, streamName)
{
	var widthVideo = 545;
	var heightVideo = 460;
	showPlayer(title, streamName, 'player4-3-384x324.swf', widthVideo, heightVideo)
}

function showVideo4_3_large(title, streamName)
{
	var widthVideo = 511;
	var heightVideo = 460;
	showPlayer(title, streamName, 'player4-3.swf', widthVideo, heightVideo)
}

function showVideo16_9_large(title, streamName)
{
	var widthVideo = 729;
	var heightVideo = 460;
	showPlayer(title, streamName, 'player16-9.swf', widthVideo, heightVideo)
}


function showPlayer4_3a(title, streamName, widthVideo, heightVideo)
{
	showPlayer(title, streamName, 'player4-3-384x324.swf', widthVideo, heightVideo)
}

function showPlayer4_3(title, streamName, widthVideo, heightVideo)
{
	showPlayer(title, streamName, 'player4-3.swf', widthVideo, heightVideo)
}

function showPlayer16_9(title, streamName, widthVideo, heightVideo)
{
	showPlayer(title, streamName, 'player16-9.swf', widthVideo, heightVideo)
}

function showPlayer(title, streamName, videoplayer, widthVideo, heightVideo)
{
	var contextPath = "";
	if (document.location.pathname.substr(0,15) == '/magnoliaAuthor')
		contextPath = '/magnoliaAuthor';

	if (YAHOO.videoNamespace == null)
	{
		var newdiv = document.createElement('div');
		newdiv.setAttribute('id', 'myDiv');
		newdiv.setAttribute('name', 'myDiv');
		newdiv.className  = 'yui-containerVideo';
		newdiv.innerHTML = '<div id="containerVideo" name="containerVideo"><div id="containerVideoTitle" name="containerVideoTitle" class="hd">&nbsp;</div><div id="containerVideoObj" name="containerVideoObj" class="bd">&nbsp;</div></div>';
		document.body.appendChild(newdiv);
		YAHOO.namespace("videoNamespace");
		YAHOO.videoNamespace.containerVideo = new YAHOO.widget.Panel("containerVideo", {visible:false, constraintoviewport:false, fixedcenter:true, underlay:"shadow", close:true} );
		YAHOO.videoNamespace.containerVideo.hideEvent.subscribe(hidePlayer); 			
		YAHOO.videoNamespace.containerVideo.render();
	}
	
	if ((heightVideo == '' || heightVideo == null) || (widthVideo == '' || widthVideo == null))
	{
		/* 
		//usando lo script per generare l'object non compare il bordo su IE7
		*/
		
		if (videoplayer == 'player4-3-384x324.swf')
		{
			widthVideo = 384;
			heightVideo = 324;
			//videoplayer = 'player4-3';
		}
		
		if (videoplayer == 'player4-3.swf')
		{
			widthVideo = 360;
			heightVideo = 324;
			//videoplayer = 'player4-3';
		}
		if (videoplayer == 'player16-9.swf')
		{
			widthVideo = 536;
			heightVideo = 338;
			//videoplayer = 'player16-9';
		}
		if (videoplayer == 'videoplayerSpallaHP.swf')
		{
			widthVideo = 320;
			heightVideo = 270;
			//videoplayer = 'videoplayerSpallaHP';
		}
	}
	
	var skinColor = "#00457E";
	var skinName = contextPath + "/docroot/sipra/flash/SkinUnderAll.swf";
	
	/*
	//imposto le dimensioni del panel: non imposto le dimensioni del pannello perche altrimenti crea problemi con il
	//bordo 'matte', tanto l'object fa in modo di espandere il pannello
	//YAHOO.videoNamespace.containerVideo.cfg.setProperty("height",heightVideo) ; 
	//YAHOO.videoNamespace.containerVideo.cfg.setProperty("width",widthVideo); 
	*/

	videoplayer = contextPath + "/docroot/sipra/flash/" + videoplayer;

	if ((document.location.pathname.substr(0,15) == '/magnoliaAuthor') && (streamName.substr(0,15) != '/magnoliaAuthor'))
	{
		streamName = contextPath + streamName;
	}
	
	/* 
	//usando lo script si fa in modo che su IE7 non ci sia il bordo attorno ai flash, ma risulta
	//molto lento...
	var objHtml = AC_FL_GetContent(
			'codebase', 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
			'width', widthVideo,
			'height', heightVideo,
			'src',  videoplayer,
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'transparent',
			'devicefont', 'false',
			'id', 'MULTIMEDIA',
			'bgcolor', '000000',
			'name', 'MULTIMEDIA',
			'menu', 'true',
			'allowFullScreen', 'true',
			'allowScriptAccess','sameDomain',
			'FlashVars','&amp;streamName=' + streamName + '&amp;skinName=' + skinName + '&amp;skinColor=' + skinColor + '&amp;autoPlay=on',
			'movie',  videoplayer,
			'salign', ''
		);
	*/

	var objHtml = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + widthVideo + '" height="'+ heightVideo +'" id="videoplayer"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="true" /><param name="movie" value="' + videoplayer + '" /><param name="quality" value="high" /><param name="bgcolor" value="000000" /><param name="FlashVars" value="&amp;streamName=' + streamName + '&amp;skinName=' + skinName + '&amp;skinColor=' + skinColor + '&amp;autoPlay=on" /><embed src="' + videoplayer + '" flashvars="&amp;streamName='+ streamName + '&amp;skinName='+ skinName + '&amp;skinColor='+ skinColor + '&amp;autoPlay=on" quality="high" bgcolor="000000" width="' + widthVideo + '" height="'+ heightVideo +'" name="videoplayer" autoPlay="on" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	YAHOO.videoNamespace.containerVideo.setBody(objHtml);
	
	/* 
	//N.B.: su IE6 il padding sulla header genera errori; per questo motivo aggiungo un div interno con padding e poi setto la larghezza per fare in modo che vada a capo
	*/			
	YAHOO.videoNamespace.containerVideo.setHeader('<div class="containerVideoTitleDiv" id="containerVideoTitleDiv" name="containerVideoTitleDiv" style="width:' + (widthVideo - 30) + 'px">' + title + '</div>');
	if (isBrowserIE6())
	{
		YAHOO.videoNamespace.containerVideo.cfg.setProperty("width",widthVideo); 
		document.getElementById('containerVideoTitle').style.width=document.getElementById('containerVideo').clientWidth;
	}
	
	YAHOO.videoNamespace.containerVideo.show();
}

function hidePlayer()
{
	YAHOO.videoNamespace.containerVideo.hide();
	YAHOO.videoNamespace.containerVideo.setBody('');
}

function showPanel(title, url, widthPanel, heightPanel)
{
	var contextPath = "";
	if (document.location.pathname.substr(0,15) == '/magnoliaAuthor')
	{
		contextPath = '/magnoliaAuthor';
	}
	if (YAHOO.panelNamespace == null)
	{
		var newdiv = document.createElement('div');
		newdiv.setAttribute('id', 'myDivPanel');
		newdiv.setAttribute('name', 'myDivPanel');
		newdiv.className  = 'yui-containerPanel';
		newdiv.innerHTML = '<div id="containerPanel" name="containerPanel"><div id="containerPanelTitle" name="containerPanelTitle" class="hd">&nbsp;</div><div id="containerPanelObj" name="containerPanelObj" class="bd">&nbsp;</div></div>';
		document.body.appendChild(newdiv);
		YAHOO.namespace("panelNamespace");
		YAHOO.panelNamespace.containerPanel = new YAHOO.widget.Panel("containerPanel", {visible:false, constraintoviewport:false, fixedcenter:true, underlay:"shadow", close:true, modal:false} );
		YAHOO.panelNamespace.containerPanel.hideEvent.subscribe(hidePanel); 			
		YAHOO.panelNamespace.containerPanel.render();
	}
	
	if ((document.location.pathname.substr(0,15) == '/magnoliaAuthor') && (url.substr(0,15) != '/magnoliaAuthor'))
	{
		url = contextPath + url;
	}
	
	var objHtml = '<iframe name="ifSchedaTV" id="ifSchedaTV" style="height: ' + heightPanel + 'px; width: ' + widthPanel + 'px;" frameborder="0" allowtransparency="no" src="' + url + '"></iframe>';
	
	YAHOO.panelNamespace.containerPanel.setBody(objHtml);
	
	/* 
	//N.B.: su IE6 il padding sulla header genera errori; per questo motivo aggiungo un div interno con padding e poi setto la larghezza per fare in modo che vada a capo
	*/			
	YAHOO.panelNamespace.containerPanel.setHeader('<div class="containerPanelTitleDiv" id="containerPanelTitleDiv" name="containerPanelTitleDiv" style="width:' + (widthPanel - 30) + 'px">' + title + '</div>');
	if (isBrowserIE6())
	{
		YAHOO.panelNamespace.containerPanel.cfg.setProperty("width",widthPanel); 
		document.getElementById('containerPanelTitle').style.width=document.getElementById('containerPanel').clientWidth;
	}
	YAHOO.panelNamespace.containerPanel.show();
}

function hidePanel()
{
	YAHOO.panelNamespace.containerPanel.hide();
	YAHOO.panelNamespace.containerPanel.setBody('');
}

function isBrowserIE6()
{
	var browserName=navigator.appName; 
	var rc = false;
	if (browserName=="Microsoft Internet Explorer")	 
	{
		var appVersion=navigator.appVersion.toLowerCase();
		if (appVersion.indexOf('msie 6') != -1)
		{
				rc = true;
		}
	}
	return rc;
}

