// 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"){
   		h = document.body.offsetHeight;
   		h_fissa = "20";
   	}
	else if(par=="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);
   	if (document.getElementById("riga_centrale") && h_finale > 0)
   		document.getElementById("riga_centrale").style.height = h_finale +"px";
}

function getApplicazione(){  		
	var startpath= "";
	if (document.location.pathname.substr(0,15) == '/magnoliaAuthor')
		startpath = '/magnoliaAuthor';		
	return startpath;		
}

function apriart7(){  		
	openPopUp(getApplicazione()+'/it/sipra/articolo7.html');
}

function apriNoteLegali(language){
	openPopUp(getApplicazione()+'/' + language + '/sipra/noteLegali.html');
}

function apriPopup(link){
	var startpath=getApplicazione();
	if (link.substr(0,1) != '/' && document.location.protocol != 'file:')
		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;
	}
	finestra=window.open(url,'sipraFinestra','width='+dimx+',height='+dimy+' ,toolbar=no, location=no,status=no,menubar=no,scrollbars='+scrollbars+',resizable='+resizable+', top='+wint+', left='+winl);
	if (window.focus) {finestra.focus()}
}

function apriWindow(link){
	var startpath= getApplicazione();
	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)
{
	finestra=window.open(getApplicazione() + "/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");
	if (window.focus) {finestra.focus()}
}

function popupcdcanalispecializzati(edizione)
{
	finestra=window.open(getApplicazione() + "/docroot/sipra/static/tvtematiche/" + edizione + "/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");
	if (window.focus) {finestra.focus()}
}

function popupListinoInterattivoTV(edizione)
{
	//var stile = "top=0, left=20, width=980, height=720, status=no, menubar=no, scrollbar=no, toolbar=no";
    var stile="width=995,height=720,top=0,left=10,screenX=0,screenY=0,scrollbars=yes,location=no,menubar=no,resizable=no,toolbar=no";
	finestra=window.open(getApplicazione() + "/docroot/sipra/static/tv/cd/" + edizione + "/listino.html", "ListinoInterattivo", stile);
	if (window.focus) {finestra.focus()}
}

function popupPalinsestoInterattivoTV(edizione)
{
	//var stile = "top=0, left=20, width=980, height=720, status=no, menubar=no, scrollbar=no, toolbar=no";
    var stile="width=995,height=720,top=0,left=10,screenX=0,screenY=0,scrollbars=yes,location=no,menubar=no,resizable=no,toolbar=no";
	finestra=window.open(getApplicazione() + "/docroot/sipra/static/tv/cd/" + edizione + "/palinsesto.html", "PalinsestoInterattivo", stile);
	if (window.focus) {finestra.focus()}
}

function palinsestoraiprimavera2009()
{
	finestra=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");
	if (window.focus) {finestra.focus()}
}

//NON USARE: usare popupcdcanalispecializzati(edizione)
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");
}

function goSipra()
{	
	finestra=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");
	if (window.focus) {finestra.focus()}	
}

function goRai()
{	
	finestra=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");
	if (window.focus) {finestra.focus()}
}

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;
	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")
	if (window.focus) {popup.focus()}	
}

// 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, autoclose)
{

	if (document.location.protocol == 'file:')
	{
		alert(title + ': ' +  streamName);
		return
	}
	

	if (autoclose == null) { autoclose = 'off';}
	
	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;
	}
	
	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" name="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&amp;autoClose=' + autoclose +'" /><embed src="' + videoplayer + '" flashvars="&amp;streamName='+ streamName + '&amp;skinName='+ skinName + '&amp;skinColor='+ skinColor + '&amp;autoPlay=on&amp;autoClose=' + autoclose +'" quality="high" bgcolor="000000" width="' + widthVideo + '" height="'+ heightVideo +'" name="videoplayer" id="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.render();
	
	YAHOO.videoNamespace.containerVideo.show();
}

function closeFromPlayer()
{
	YAHOO.videoNamespace.containerVideo.hide();
}

function hidePlayer()
{
	YAHOO.videoNamespace.containerVideo.hide();
	try
	{
		var player = document.getElementById('videoplayer');
		player.RimuoviFilmato('');
	}
	catch(err)
	{
		  //alert('catch:' + err);
	}	
	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.render();
	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;
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ";path=/";
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function setSessionCookie (cookieName, cookieValue) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
}

//----footer----
function setLang(lang, link)
{
	setCookie('lang',lang,10);
	document.location=link;
}

function checkMenuAttivo(hdlpadre)
{
	menuattivo = document.getElementById("menu_attivo");
	if (menuattivo == null)
	{	
		menucorrente = document.getElementById(hdlpadre);
		if (menucorrente != null)
		{
			menucorrente.className = "menu_attivo_class";
		}
	}
}

function setUserTrack()
{
	// gestione utente unico
	if (!getCookie("siprausertrack"))
	{
		ord=Math.random();
		ord=ord*10000000000000000000;
		setCookie("siprausertrack","U"+getCookie("sipraremotehost")+"-"+ord,1);
	}
	deleteCookie("sipraremotehost","/",".sipra.it")
}

