//defaults value
var DEF_RURL = document.location;
var DEF_ERRURL = document.location;
var DEF_SITECODE = 'CO';
var DEF_SUBSCRIBE_SCRIPT = 'https://duprovisioning.dev.24orepro.in.ilsole24ore.it/DU/iniziaRegistrazione.aspx';
var DEF_LOGIN_SCRIPT = 'https://duprovisioning.dev.24orepro.in.ilsole24ore.it/DU/authfiles/logincentrale.aspx';
var DEF_LOGOFF_SCRIPT = 'https://duprovisioning.dev.24orepro.in.ilsole24ore.it/du/authfiles/logoff.aspx';
var DEF_USERPROFILE_SCRIPT = 'https://duprovisioning.dev.24orepro.in.ilsole24ore.it/DU/Areautente/profiloutente.aspx';
var isAuthenticated = false;
var friendlyName = null;
var isPremium = -1;
var PopupAuthenticationTimeout=60000; //milliseconds
var DataOra;
var DEF_SEARCH_URL = "http://www.ricerca24.ilsole24ore.com";
var IMG_URL = "http://www.ilsole24ore.com/st/testata/sole24/images/head24ore/"; 
// var IMG_URL_CANALI = "http://www.services.ilsole24ore.com/testata/img_canali/"; 


// Modified from Bill Dortch's Cookie Functions (hidaho.com) 
// (found in JavaScript Bible)
function setCookie(name,value,days,path,domain,secure) {
	  var expires, date;
	  if (typeof days == "number") {
	    date = new Date();
	    date.setTime( date.getTime() + (days*24*60*60*1000) );
			expires = date.toGMTString();
	  }
	  document.cookie = name + "=" + escape(value) +
	    ((expires) ? "; expires=" + expires : "") +
	    ((path) ? "; path=" + path : "") +
	    ((domain) ? "; domain=" + domain : "") +
	    ((secure) ? "; secure" : "");
}

// Modified from Jesse Chisholm or Scott Andrew Lepera ?
// (found at both www.dansteinman.com/dynapi/ and www.scottandrew.com/junkyard/js/)
function getCookie(name) {
	  var nameq = name + "=";
	  var c_ar = document.cookie.split(';');
	  for (var i=0; i<c_ar.length; i++) {
	    var c = c_ar[i];
	    while (c.charAt(0)==' ') c = c.substring(1,c.length);
	    if (c.indexOf(nameq) == 0) return unescape( c.substring(nameq.length, c.length) );
	  }
	  return null;
}
 
 
 // from Bill Dortch's Cookie Functions (hidaho.com) 
function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function setCookieRitorno() {
	if (getCookie("URLRIT") == null) {
		setCookie("URLRIT",document.location,180,"/");
	}
	return true;
}

function deleteCookieRitorno() {
	if (getCookie("URLRIT") != null) {
		deleteCookie("URLRIT");
	}
	return true;
}

/*
Recupera le informazioni dell'utente stabilendo se si tratta di una connessione anonima o no
*/
function GetUserStatus(){
	var allCookies = document.cookie;	//all cookies
	var soleAuthStart = allCookies.indexOf("SoleAuth");
	
	if (soleAuthStart>=0){
		var soleAuth = allCookies.substring(soleAuthStart,allCookies.indexOf(";", soleAuthStart));
		if (soleAuth!="SoleAuth=") {
			isAuthenticated = true;
			SetFriendlyName();	
		}
	}
}


//Controllo periodico se autenticato
function CheckPopupAuthentication(){
	var allCookies = document.cookie;	//all cookies
	var soleAuthStart = allCookies.indexOf("SoleAuth="); //Start of SoleAuth
	
	if (soleAuthStart>0){	//SoleAuth present
		var soleAuth = allCookies.substring(soleAuthStart,allCookies.indexOf(";",soleAuthStart));
		
		var aSoleAuth = soleAuth.split('=')
		if (aSoleAuth[1].length>0){	//SoleAuth valid
			document.location.reload();
			return;
		}
	}
	
	// riattivo il check		
	setTimeout(CheckPopupAuthentication,PopupAuthenticationTimeout);	
}

function SetFriendlyName(){
	var allCookies = document.cookie;	//all cookies
	var soleUserStart = allCookies.indexOf("SoleUser="); //Start of SoleUser
	var ispremiumIdx;
	
	if (soleUserStart>0){	//SoleUser present
		var soleUser;	
		if (allCookies.indexOf(";", soleUserStart)>=0)
			soleUser = allCookies.substring(soleUserStart,allCookies.indexOf(";",soleUserStart)); //SoleUser content
		else
			soleUser = allCookies.substring(soleUserStart);
		
		var aSoleUser = soleUser.substring(soleUser.indexOf("=")+1).split(','); 
		
		for (i=0; i<aSoleUser.length; i++)
		{
			if (aSoleUser[i].toLowerCase().indexOf('friendlyname=')>=0){
				isAuthenticated = true;
				ispremiumIdx = aSoleUser[i].toLowerCase().indexOf('&ispremium=');
		    if (ispremiumIdx == -1)
		        ispremiumIdx = aSoleUser[i].length;
		    else 
		    	isPremium = aSoleUser[i].substring(ispremiumIdx+11);    
				friendlyName = aSoleUser[i].substring(aSoleUser[i].indexOf('=')+1,ispremiumIdx);
				break;
			}
		}
	}	
	else{
		isAuthenticated = false;
		friendlyName = null;
		isPremium = -1;
	}
		
}



function DrawLogo() {
	DataOra = doClock("W0","%20","D1","%20","M0","%20","Y0","%20ore%20","H0","%3A","N0");
	var content = '';
	var header = document.getElementById("head24riga2sx2");
	
	if (header == null)	return false;

	content += '<a href="http://www.ilsole24ore.com"><img src="' + IMG_URL + 'head24ore-logosole.gif" alt="Il Sole 24 ORE.com" border="0" height="59" width="256"></a>';
	content += '<div id="data_ora"><a href="http://www.ilsole24ore.com/feedrss"><img src="' + IMG_URL + 'ico_rss.gif" alt="RSS" border="0" height="12" width="21"></a>';
	content += '<b>' + DataOra + '</b></div>';
	
	header.innerHTML = content;
		
	return true;
}


function DrawLogoBasso() {
	DataOra = doClock("W0","%20","D1","%20","M0","%20","Y0","%20ore%20","H0","%3A","N0");
	var content = '';
	var header = document.getElementById("head24riga2sx4");
	
	if (header == null)	return false;

	content += '<a href="http://www.ilsole24ore.com"><img src="' + IMG_URL + 'head24ore-logosole_small.gif" alt="Il Sole 24 ORE.com" border="0" height="38" hspace="4" width="165"></a>';
	content += '<b>' + DataOra + '</b>';

	header.innerHTML = content;
		
	return true;
}


function DrawLogoServizio() {
	DataOra = doClock("W0","%20","D1","%20","M0","%20","Y0","%20ore%20","H0","%3A","N0");
	var content = '';
	var header = document.getElementById("head24riga3");
	
	if (header == null)	return false;


	content += '<div id="head24riga3dx"><b>' + DataOra + '</b></div>';
	content += '<div id="head24riga3sx"><a href="http://www.ilsole24ore.com"><img src="' + IMG_URL + 'head24ore-logosole_small.gif" alt="Il Sole 24 ORE.com" border="0" height="38" hspace="4" width="165"></a></div>';

	header.innerHTML = content;
		
	return true;
}



function DrawEdizioneOdierna(){
	var content = '';
	var header = document.getElementById("head24riga2sx3");
	
	if (header == null) return false;

	content += '<div id="edizione_odierna">';
	content += '<div id="p12">';
	content += '<div id="p2">';
	content += '<div><img src="' + IMG_URL + 'edizione_odierna_giornale.gif" alt="24ore.com" height="34" width="100"></div>';
	content += '<div><img src="' + IMG_URL + 'edizione_odierna_bull1.gif" alt="-" align="absmiddle" height="11" width="11"><a href="http://www.abbonamenti.ilsole24ore.com/fc?cmd=sez&chId=45&sezId=10209">Come abbonarsi</a></div>';
	content += '<div><img src="' + IMG_URL + 'edizione_odierna_bull1.gif" alt="-" align="absmiddle" height="11" width="11"><a href="http://utilities.ilsole24ore.com/abb/quot_index.jsp">Area abbonati</a></div>';
	content += '</div>';
	content += '<div id="p1">';
	content += '<div><img src="' + IMG_URL + 'edizione_odierna_bull2.gif" alt="-" align="absmiddle" height="11" width="11"><a href="http://paginegialle.ilsole24ore.com">Pagine Gialle</a></div>';
	content += '<div><img src="' + IMG_URL + 'edizione_odierna_bull3.gif" alt="-" align="absmiddle" height="11" width="11"><a href="http://paginebianche.ilsole24ore.com">Pagine Bianche</a></div>';
	content += '<div><img src="' + IMG_URL + 'edizione_odierna_bull4.gif" alt="-" align="absmiddle" height="11" width="11"><a href="http://tuttocitta.ilsole24ore.com/tcolnew/index_ilsole24ore.html">Tutto Citt&#224;</a></div>';
	content += '</div>';
	content += '</div>';
	content += '</div>';
	
	header.innerHTML = content;
		
	return true;
}



function DrawNavigatoreAlto(channelDescription) {
	
	var class_1_borsa = 'menucanali01';
	var class_2_job = 'menucanali00';
	var class_3_casa = 'menucanali00';
	var class_4_viaggi = 'menucanali00';
	var class_5_radio = 'menucanali00';
	var class_6_pa = 'menucanali00';
	var class_7_shop = 'menucanali00';
	var class_8_esperto = 'menucanali00';
	var class_9_banche = 'menucanali00';
	var class_10_mobile = 'menucanali00';
	var class_11_formazione = 'menucanali00';
	var class_12_periodici = 'menucanali00';
	var class_13_minuti = 'menucanali00';
	
	var content = '';
	var cell = document.getElementById("menucanali");
	
	if (cell==null) return false;
	
	if(channelDescription == "BO")
		class_1_borsa = 'menucanaliattivo01';
	if(channelDescription == "JO")
		class_2_job = 'menucanaliattivo02';
	if(channelDescription == "CA")
		class_3_casa = 'menucanaliattivo03';
	if(channelDescription == "VI")
		class_4_viaggi = 'menucanaliattivo04';
	if(channelDescription == "RA")
		class_5_radio = 'menucanaliattivo05';
	if(channelDescription == "PA")
		class_6_pa = 'menucanaliattivo06';
	if(channelDescription == "SH")
		class_7_shop = 'menucanaliattivo07';
	if(channelDescription == "ES")
		class_8_esperto = 'menucanaliattivo08';
	if(channelDescription == "BA")
		class_9_banche = 'menucanaliattivo09'
	if(channelDescription == "MO")
		class_10_mobile = 'menucanaliattivo10';
	if(channelDescription == "FO")
		class_11_formazione = 'menucanaliattivo11'; 
	if(channelDescription == "PE")
		class_12_periodici = 'menucanaliattivo12'; 
		
	content += '<h4>Canali</h4><ul>';
	content += '<li><a href="http://www.24oreborsaonline.ilsole24ore.com/" title="Borsa Online" class="' + class_1_borsa + '">Borsa Online</a></li>';	
	content += '<li><a href="http://job24.ilsole24ore.com/" title="Job24" class="' + class_2_job + '">Job24</a></li>';		
	content += '<li><a href="http://www.casa24.ilsole24ore.com/" title="Casa24" class="' + class_3_casa + '">Casa24</a></li>';		
	content += '<li><a href="http://www.viaggi24.ilsole24ore.com/" title="Viaggi24" class="' + class_4_viaggi + '">Viaggi24</a></li>';		
	content += '<li><a href="http://www.radio24.ilsole24ore.com/" title="Radio24" class="' + class_5_radio + '">Radio24</a></li>';		
	content += '<li><a href="http://www.professionisti24.ilsole24ore.com/" title="Professionisti e P.A." class="' + class_6_pa + '">Professionisti e P.A.</a></li>';		
	content += '<li><a href="http://www.shopping24.ilsole24ore.com/" title="Shopping24" class="' + class_7_shop + '">Shopping24</a></li>';		
	content += '<li><a href="http://www.24minuti.ilsole24ore.com/" title="24minuti" class="' + class_13_minuti + '">24minuti</a></li>';	
	content += '<li><a href="http://www.espertorisponde.ilsole24ore.com/" title="Esperto Risponde" class="' + class_8_esperto + '">Esperto Risponde</a></li>';		
	content += '<li><a href="http://www.banchedati.ilsole24ore.com/" title="Banche Dati" class="' + class_9_banche + '">Banche Dati</a></li>';		
	content += '<li><a href="http://www.mobile.ilsole24ore.com/" title="Mobile" class="' + class_10_mobile + '">Mobile</a></li>';		
	content += '<li><a href="http://www.formazione.ilsole24ore.com/" title="Formazione" class="' + class_11_formazione + '">Formazione</a></li>';		
	content += '<li><a href="http://www.ilsole24ore.com/fc?cmd=sez&amp;sezId=10461" title="Periodici" class="' + class_12_periodici + '">Periodici</a></li></ul>';		
	
				
	cell.innerHTML = content;
	
	 return true;
}


function DrawNavigatoreBasso(channelDescription) {
	
	var class_1_borsa = 'nobull';
	var class_2_job = '';
	var class_3_casa = '';
	var class_4_viaggi = '';
	var class_5_radio = '';
	var class_6_pa = '';
	var class_7_shop = '';
	var class_8_esperto = '';
	var class_9_banche = '';
	var class_10_mobile = '';
	var class_11_formazione = '';
	var class_12_periodici = '';
	var class_13_minuti = '';
		
	var content = '';
	var cell = document.getElementById("menucanali-basso-cont");
	
	if (cell==null) return false;
	
	if(channelDescription == "BO")
		class_1_borsa = 'menucanaliattivo';
	if(channelDescription == "JO")
		class_2_job = 'menucanaliattivo';
	if(channelDescription == "CA")
		class_3_casa = 'menucanaliattivo';
	if(channelDescription == "VI")
		class_4_viaggi = 'menucanaliattivo';
	if(channelDescription == "RA")
		class_5_radio = 'menucanaliattivo';
	if(channelDescription == "PA")
		class_6_pa = 'menucanaliattivo';
	if(channelDescription == "SH")
		class_7_shop = 'menucanaliattivo';
	if(channelDescription == "ES")
		class_8_esperto = 'menucanaliattivo';
	if(channelDescription == "BA")
		class_9_banche = 'menucanaliattivo'
	if(channelDescription == "MO")
		class_10_mobile = 'menucanaliattivo';
	if(channelDescription == "FO")
		class_11_formazione = 'menucanaliattivo'; 
	if(channelDescription == "PE")
		class_12_periodici = 'menucanaliattivo'; 
	
	content += '<div id="menucanali-basso">';
	content += '<h4>Canali</h4><ul>';
	content += '<li><a href="http://www.24oreborsaonline.ilsole24ore.com/" title="Borsa Online" class="' + class_1_borsa + '">Borsa Online</a></li>';	
	content += '<li><a href="http://job24.ilsole24ore.com/" title="Job24" class="' + class_2_job + '">Job24</a></li>';		
	content += '<li><a href="http://www.casa24.ilsole24ore.com/" title="Casa24" class="' + class_3_casa + '">Casa24</a></li>';		
	content += '<li><a href="http://www.viaggi24.ilsole24ore.com/" title="Viaggi24" class="' + class_4_viaggi + '">Viaggi24</a></li>';		
	content += '<li><a href="http://www.radio24.ilsole24ore.com/" title="Radio24" class="' + class_5_radio + '">Radio24</a></li>';		
	content += '<li><a href="http://www.professionisti24.ilsole24ore.com/" title="Professionisti e P.A." class="' + class_6_pa + '">Professionisti e P.A.</a></li>';		
	content += '<li><a href="http://www.shopping24.ilsole24ore.com/" title="Shopping24" class="' + class_7_shop + '">Shopping24</a></li>';	
	content += '<li><a href="http://www.24minuti.ilsole24ore.com/" title="24minuti" class="' + class_13_minuti + '">24minuti</a></li>';	
	content += '<li><a href="http://www.espertorisponde.ilsole24ore.com/" title="Esperto Risponde" class="' + class_8_esperto + '">Esperto Risponde</a></li>';		
	content += '<li><a href="http://www.banchedati.ilsole24ore.com/" title="Banche Dati" class="' + class_9_banche + '">Banche Dati</a></li>';		
	content += '<li><a href="http://www.mobile.ilsole24ore.com/" title="Mobile" class="' + class_10_mobile + '">Mobile</a></li>';		
	content += '<li><a href="http://www.formazione.ilsole24ore.com/" title="Formazione" class="' + class_11_formazione + '">Formazione</a></li>';		
	content += '<li><a href="http://www.ilsole24ore.com/fc?cmd=sez&amp;sezId=10461" title="Periodici" class="' + class_12_periodici + '">Periodici</a></li></ul>';		
	content += '</div>';
	
				
	cell.innerHTML = content;
	
	 return true;
}



function authenticated_user_premium(){
	
	var content = '';
	var cell = document.getElementById("head24riga2sx1");
	
	if (cell==null) return false;
		
		
		
		content +=  '<table id="UTENTE_PREMIUM" border="0" cellpadding="0" cellspacing="0" height="72" width="190">';
		content +=  '<tbody><tr>';
		content +=  '<td rowspan="4" bgcolor="#ea2c1c" width="9"><img src="' + IMG_URL + 'pix.gif" alt="" height="63" width="9"></td>';
		content +=  '<td rowspan="4" width="2"><img src="' + IMG_URL + 'pix.gif" alt="" height="63" width="2"></td>';
		content +=  '<td colspan="4" align="left"><a id="lnkLogoff" href="" border="0"><img src="' + IMG_URL + 'box_testata_prem_03.gif" alt="" border="0" height="17" width="163"></a></td>';
		content +=  '</tr>';
		
		content +=  '<tr>';
		content +=  '<td rowspan="2" width="6"><img src="' + IMG_URL + 'pix.gif" alt="" height="20" width="6"></td>';
		content +=  '<td colspan="3" class="head24-nero" align="left"><span class="head24-rosso">Benvenuto</span><br>';
		content +=  '<span id="spnFriendlyName"></span></td>';
		content +=  '</tr>';
		
		content +=  '<tr>';
		content +=  '<td class="head24-nero" align="left" valign="middle" width="69">';
		content +=  '<span class="head24-rosso">Profilo:</span><br>Premium</td>';
		content +=  '<td align="center" background="' + IMG_URL + 'box_testata_prem_09.gif" valign="top" width="1"><img src="' + IMG_URL + 'pix.gif" alt="" height="27" width="1"></td>';
		content +=  '<td align="left" valign="middle" width="100"><img src="' + IMG_URL + 'frecciatestata.gif" align="absmiddle" height="10" width="22">';
		content +=  '<a id="lnkUserProfile" href="" class="head24-linknero">Il tuo profilo</a><br>';
		content +=  '<img src="' + IMG_URL + 'frecciatestata.gif" align="absmiddle" height="10" width="22"><a href="http://serviziattivi.ilsole24ore.com" class="head24-linknero">Servizi Attivi</a></td>';
		content +=  '</tr>';
		content +=  '</tbody></table>';
          
    cell.innerHTML = content;
	
	deleteCookieRitorno();
	return true;
          
}

function authenticated_user_premium_bassa() {

	var content = '';
	var cell = document.getElementById("head24riga2sx5");
	
	if (cell==null) return false;
		
		content += '<div id="head24-registrazione-bassa">';
		content +=  '<table id="UTENTE_PREMIUM" border="0" cellpadding="0" cellspacing="0" height="60" width="250">';
		content +=  '<tbody><tr>';
		content +=  '<td rowspan="4" bgcolor="#e42022" width="9"><img src="' + IMG_URL + 'pix.gif" alt="" height="63" width="9"></td>';
		content +=  '<td rowspan="4" width="2"><img src="' + IMG_URL + 'pix.gif" alt="" height="63" width="2"></td>';
		content +=  '<td colspan="4" align="left" bgcolor="#e42022" height="19"><a id="lnkLogoff" href="#" border="0"><img src="' + IMG_URL + 'box_testata_prem_11.gif" alt="Esci" border="0" height="19" width="226"></a></td>';
		content +=  '</tr>';
		
		content +=  '<tr>';
		content +=  '<td rowspan="2" width="6"><img src="' + IMG_URL + 'pix.gif" alt="" height="20" width="6"></td>';
		content +=  '<td colspan="3" class="head24-nero" align="left"><img src="' + IMG_URL + 'pix.gif" alt="" height="3" width="6"></td>';
		content +=  '</tr>';
		
		content +=  '<tr>';
		content +=  '<td class="head24-nero head24-interlin2" align="left" valign="middle" width="226">';
		content +=  '<span class="head24-rosso">Benvenuto </span>';
		content +=  '<span id="spnFriendlyName"></span>';
		content +=  '<br><span class="head24-rosso">Profilo: </span>Premium</td>';
		content +=  '<td align="center" background="' + IMG_URL + 'box_testata_prem_09.gif" valign="top" width="1"><img src="' + IMG_URL + 'pix.gif" alt="" height="40" width="1"></td>';
		content +=  '<td align="left" valign="middle" width="130"><img src="' + IMG_URL + 'frecciatestata.gif" align="absmiddle" height="10" width="22"><a id="lnkUserProfile" href="" class="head24-linknero">Il tuo profilo</a><br>';
		content +=  ' <img src="' + IMG_URL + 'frecciatestata.gif" align="absmiddle" height="10" width="22"><a href="http://serviziattivi.ilsole24ore.com" class="head24-linknero">Servizi Attivi</a></td>';
		content +=  '</tr>';
		content +=  '</tbody></table>';
		content += '</div>';
	
	cell.innerHTML = content;
	
	deleteCookieRitorno();
	return true;
}



function authenticated_user()
{
	var content = '';
	var cell = document.getElementById("head24riga2sx1");
	
	if (cell==null) return false;
		
		content +=  '<table id="UTENTE_PREMIUM" border="0" cellpadding="0" cellspacing="0" height="72" width="190">';
		content +=  '<tbody><tr>';
		content +=  '<td rowspan="4" bgcolor="#0298d3" width="9"><img src="' + IMG_URL + 'pix.gif" alt="" height="63" width="9"></td>';
		content +=  '<td rowspan="4" width="2"><img src="' + IMG_URL + 'pix.gif" alt="" height="63" width="2"></td>';
		content +=  '<td colspan="4" align="left"><a id="lnkLogoff" href="" border="0"><img src="' + IMG_URL + 'box_testata_prem_05.gif" alt="" border="0" height="17" width="163"></a></td>';
		content +=  '</tr>';
		
		content +=  '<tr>';
		content +=  '<td rowspan="2" width="6"><img src="' + IMG_URL + 'pix.gif" alt="" height="20" width="6"></td>';
		content +=  '<td colspan="3" class="head24-nero" align="left"><span class="head24-blu">Benvenuto</span><br>';
		content +=  '<span id="spnFriendlyName"></span></td>';
		content +=  '</tr>';
		
		content +=  '<tr>';
		content +=  '<td class="head24-nero" align="left" valign="middle" width="69">';
		content +=  '<span class="head24-blu">Profilo:</span><br>Registrato</td>';
		content +=  '<td align="center" background="' + IMG_URL + 'box_testata_prem_09.gif" valign="top" width="1"><img src="' + IMG_URL + 'pix.gif" alt="" height="27" width="1"></td>';
		content +=  '<td align="left" valign="middle" width="100"><img src="' + IMG_URL + 'frecciatestata2.gif" align="absmiddle" height="10" width="22">';
		content +=  '<a id="lnkUserProfile" href="" class="head24-linknero">Il tuo profilo</a><br>';
		content +=  '<img src="' + IMG_URL + 'frecciatestata2.gif" align="absmiddle" height="10" width="22"><a href="http://serviziattivi.ilsole24ore.com" class="head24-linknero">Servizi Attivi</a></td>';
		content +=  '</tr>';
		content +=  '</tbody></table>';
	
	cell.innerHTML = content;
	
	deleteCookieRitorno();
	return true;
}


function authenticated_user_bassa() {
	
	var content = '';
	var cell = document.getElementById("head24riga2sx5");
	
	if (cell==null) return false;
		
		content += '<div id="head24-registrazione-bassa">';
		content +=  '<table id="UTENTE_PREMIUM" border="0" cellpadding="0" cellspacing="0" height="60" width="250">';
		content +=  '<tbody><tr>';
	content +=  '<td rowspan="4" bgcolor="#0298d3" width="9"><img src="' + IMG_URL + 'pix.gif" alt="" height="63" width="9"></td>';
		content +=  '<td rowspan="4" width="2"><img src="' + IMG_URL + 'pix.gif" alt="" height="63" width="2"></td>';
		content +=  '<td colspan="4" align="left" bgcolor="#0298d3" height="19"><a id="lnkLogoff" href="" border="0"><img src="' + IMG_URL + 'box_testata_prem_13.gif" alt="Esci" border="0" height="19" width="226"></a></td>';
		content +=  '</tr>';
			
		content +=  '<tr>';
		content +=  '<td rowspan="2" width="6"><img src="' + IMG_URL + 'pix.gif" alt="" height="20" width="6"></td>';
		content +=  '<td colspan="3" class="head24-nero" align="left"><img src="' + IMG_URL + 'pix.gif" alt="" height="3" width="6"></td>';
		content +=  '</tr>';
		
		content +=  '<tr>';
		content +=  '<td width="226" align="left" valign="middle" class="head24-nero head24-interlin2">';
		content +=  '<span class="head24-blu">Benvenuto </span>';
		content +=  '<span id="spnFriendlyName"></span>';
		content +=  '<br><span class="head24-blu">Profilo: </span>Registrato</td>';
		
		content +=  '<td align="center" background="' + IMG_URL + 'box_testata_prem_09.gif" valign="top" width="1"><img src="' + IMG_URL + 'pix.gif" alt="" height="40" width="1"></td>';
		content +=  '<td align="left" valign="middle" width="130"><img src="' + IMG_URL + 'frecciatestata2.gif" align="absmiddle" height="10" width="22"><a id="lnkUserProfile" href="" class="head24-linknero">Il tuo profilo</a><br>';	
		content +=  '<img src="' + IMG_URL + 'frecciatestata2.gif" align="absmiddle" height="10" width="22"><a href="http://serviziattivi.ilsole24ore.com" class="head24-linknero">Servizi Attivi </a></td>';
		content +=  '</tr>';
		content +=  '</tbody></table>';
		content += '</div>';
	
	cell.innerHTML = content;
	
	deleteCookieRitorno();
	return true;
}

//disegna la form di log-in
function auth_form() {
	
	var content  = '';
	var cell = document.getElementById("head24riga2sx1");
	if (cell==null)
		return false;
		
		
	content  = '<!-- login -->';
	content += '<div id="head24-registrazione">';
	content += '<FORM action="" method="post" name="authUser" onsubmit="setCookieRitorno()">';
	content += '<INPUT value="" name="URL" type="hidden"/>';
	content += '<INPUT value="BYPOST" name="realSubmit" type="hidden"/>';
	content += '<INPUT type="hidden" name="RURL" value=""/>';
	content += '<INPUT type="hidden" name="ERRURL" value=""/>';
	content += '<INPUT type="hidden" name="SC" value=""/>';
	content += '<div>&nbsp;Username</div>';
	content += '<input name="txtUsername" value="" type="text">';
	content += '<div>&nbsp;Password</div>';
	content += '<input name="txtPassword" value="" type="password">';
	content += '<input src="' + IMG_URL + 'head24ore-login-arr.gif" alt="" id="head24-reg-input" align="absmiddle" border="0" height="21" type="image" width="21"></form>';
	content += '</div>';
	
	content += '<div id="head24-login">';
	content += '<a id="lnkSubscribe" href=""><img src="' + IMG_URL + 'head24ore-login-reg.gif" alt="" align="middle" border="0" height="21" width="61"></a>';
	content += '<a href="http://redir.ilsole24ore.com/redir.asp?id=11"><img src="' + IMG_URL + 'head24ore-login-vag.gif" alt="" align="middle" border="0" height="21" width="61"></a>';
	content += '</div>';
	content += '<!-- fine login -->';

	cell.innerHTML = content;
	
	return true;
	
}

//disegna la form di log-in
function auth_form_bassa()
{
	var content  = '';
	var cell = document.getElementById("head24riga2sx5");
	if (cell==null)
		return false;
		
		
	content  = '<!-- login -->';
	content += '<div id="head24-registrazione-bassa">';
	content += '<FORM action="" method="post" name="authUser" onsubmit="setCookieRitorno()">';
	content += '<INPUT value="" name="URL" type="hidden"/>';
	content += '<INPUT value="BYPOST" name="realSubmit" type="hidden"/>';
	content += '<INPUT type="hidden" name="RURL" value=""/>';
	content += '<INPUT type="hidden" name="ERRURL" value=""/>';
	content += '<INPUT type="hidden" name="SC" value=""/>';
	content += 'Username&nbsp;';
	content += '<input name="txtUsername" value="" type="text">';
	content += '<img src="' + IMG_URL + 'pix.gif" alt="" align="middle" border="0" height="21" width="22">';
	content += '<a id="lnkSubscribe" href=""><img src="' + IMG_URL + 'head24ore-login-reg.gif" alt="" align="absmiddle" border="0" height="21" width="61"></a>';
	content += '<br>Password&nbsp;';
	content += '<input name="txtPassword" value="" type="password">';
	content += '<input src="' + IMG_URL + 'head24ore-login-arr.gif" alt="" id="head24-reg-input" align="absmiddle" border="0" height="21" type="image" width="21">';
	content += '<a href="http://redir.ilsole24ore.com/redir.asp?id=11"><img src="' + IMG_URL + 'head24ore-login-vag.gif" alt="" align="absmiddle" border="0" height="21" width="61"></a></form>';
	content += '</div>';
	content += '<!-- fine login -->';

	cell.innerHTML = content;
	
	return true;
	
}



function DrawPremiumBanner() {
	
	var content = '';
	var header = document.getElementById("head24rigadx");
	if (header == null)
		return false;
	
	
    if (isPremium == "1"){
    content += '<div id="head24premreg">';
    content += '<img src="'+ IMG_URL + 'head24ore-prembox1.gif" width="248" height="17" alt="" border="0" />';
    content += '<ul class="head24-interlin2"><li><a href="http://www.ilsole24ore.com/fc?cmd=art&codid=22.0.1272368697" title="Articoli redazionali - Speciali e Dossier">Articoli redazionali - Speciali e Dossier</a></li>';
    content += '<li><a href="http://www.banchedati.ilsole24ore.com/enter.do?product=BIG" title="Archivio quesiti Esperto Risponde">Archivio storico del Sole 24 Ore</a></li>';
    content += '<li><a href="http://www.espertorisponde.ilsole24ore.com/fc?cmd=art&codid=20.0.792552346&chId=33&letter=A" title="Ricerca annunci">Archivio quesiti Esperto Risponde</a></li>';
    content += '<li><a href="http://www.24oreborsaonline.ilsole24ore.com/" title="Borsa e News in tempo reale" >Borsa e News in tempo reale</a></li>';
    content += '<li><a href="http://premium.ilsole24ore.com/fc?cmd=sez&chId=49&sezId=10680" title="Offerte speciali Club 24" class="rosso">Offerte speciali Club 24</a></li></ul>';
    content += '</div>';
      } else {
    //content += '<img src="'+ IMG_URL + 'head24ore-premium.gif" usemap="#Map" border="0" height="90" width="250">';
    //content += '<map name="Map" id="Map">';
    //content += '<area shape="rect" coords="134,37,248,61" href="http://premium.ilsole24ore.com/fc?cmd=sez&amp;chId=49&amp;sezId=10610" alt="Prova Gratuita">';
    //content += '<area shape="rect" coords="134,61,248,83" href="http://www.shopping24.ilsole24ore.com/sh3/catalog/ProductI.jsp?PRODID=PREM02" alt="Abbonati">';
    //content += '<area shape="rect" coords="125,1,248,22" href="http://premium.ilsole24ore.com/" alt="Premium24">';
    //content += '</map>';  	
	  /*content += '<img src="'+ IMG_URL + 'head24ore-premium1_wbf.gif" usemap="#Map" border="0" height="90" width="250">';
    content += '<map name="Map" id="Map">';
    content += '<area shape="rect" coords="6,37,104,61" href="http://premium.ilsole24ore.com/fc?cmd=sez&amp;chId=49&amp;sezId=10610" alt="Prova Gratuita" />';
    content += '<area shape="rect" coords="32,61,104,83" href="http://www.shopping24.ilsole24ore.com/sh3/catalog/ProductI.jsp?PRODID=PREM02" alt="Abbonati" />';
    content += '<area shape="rect" coords="1,2,127,24" href="http://premium.ilsole24ore.com/" alt="Premium24" />';
    content += '<area shape="rect" coords="107,42,249,89" href="http://premium.ilsole24ore.com/" alt="Vinci - World Business Forum"/>';
    content += '</map>';*/
    
		content += '<table width="250" height="90" border="0" cellpadding="0" cellspacing="0" bgcolor="#ee3928" id="BOX_TESTATA_BASSA">';
		content += '<tr><td colspan="4"><a href="http://premium.ilsole24ore.com/"><img src="'+ IMG_URL + 'box_testata_bassa_01.gif" width="250" height="21" alt="emium24 Il sole 24 ORE" /></a></td></tr>';
		content += '<tr><td bgcolor=""><img src="'+ IMG_URL + 'pix.gif" width="2" height="66" alt="" /></td><td align="left" width="115" bgcolor="#FFFFFF">';
	
	  content += '<table id="INTERNA" width="109" height="45" border="0" cellpadding="0" cellspacing="0">';
		content += '<tr><td><img src="'+ IMG_URL + 'box_testata_bassa_int_01.gif" width="109" height="1" alt="" /></td></tr>';
    content += '<tr><td height="21" align="right" nowrap="nowrap" class="boxtestatap_rosso12"><a href="http://www.shopping24.ilsole24ore.com/sh3/catalog/ProductI.jsp?PRODID=PREM02" class="boxtestatap_rosso12">Abbonati subito</a><img src="'+ IMG_URL + 'box_testata_bassa_freccia.gif" alt="-" width="18" height="9" align="absmiddle" /></td></tr>';
    content += '<tr><td><img src="'+ IMG_URL + 'box_testata_bassa_int_01.gif" width="109" height="1" alt="" /></td></tr>';
    content += '<tr><td height="21" align="right" nowrap="nowrap" class="boxtestatap_rosso12"><a href="http://premium.ilsole24ore.com/fc?cmd=sez&chId=49&sezId=10670" class="boxtestatap_rosso12">Scopri il servizio</a><img src="'+ IMG_URL + 'box_testata_bassa_freccia.gif" alt="-" width="18" height="9" align="absmiddle" /></td></tr>';

		content += '<tr><td><img src="'+ IMG_URL + 'box_testata_bassa_int_01.gif" width="109" height="1" alt="" /></td></tr></table>';
		content += '</td><td><a href="http://premium.ilsole24ore.com/fc?cmd=sez&chId=49&sezId=11653"><img src="'+ IMG_URL + 'box_testata_bassa_04.gif" alt="Novit&agrave;! Ora anche in versione Finanza" width="131" height="66" border="0" /></a></td>';
		content += '<td><img src="'+ IMG_URL + 'box_testata_bassa_05.gif" width="3" height="66" alt="" /></td>';
		content += '</tr><tr><td colspan="4"><img src="'+ IMG_URL + 'box_testata_bassa_06.gif" width="250" height="3" alt="" /></td></tr></table>';

  	}
	

	header.innerHTML = content;
		
	 		return true;
	
}


function DrawBottoni() {
	
	var content = '';
	var header = document.getElementById("head24-bottoni");
	
	if (header == null) return false;
	
    content += '<div id="head24-bottoni2">';
    content += '<a href="http://www.ilsole24ore.com/gr24" alt=""><img src="'+ IMG_URL + 'head24ore-bott-gr24.gif" alt="Gr 24 - Radio24" border="0" height="25" width="30"></a>';
    content += '<a href="http://www.ilsole24ore.com/vialibera" alt=""><img src="'+ IMG_URL + 'head24ore-bott-tr.gif" alt="Che strada fa - Radio24" border="0" height="25" width="30"></a>';
    content += '<a href="http://www.ilsole24ore.com/1minuto" alt=""><img src="'+ IMG_URL + 'head24ore-bott-graf.gif" alt="Borsa in un minuto" border="0" height="25" width="30"></a>';
    content += '<a href="http://www.ilsole24ore.com/meteo" alt=""><img src="'+ IMG_URL + 'head24ore-bott-meteo.gif" alt="Meteo" border="0" height="25" width="30"></a>';
    content += '<a href="http://www.ilsole24ore.com/giochi24" alt=""><img src="'+ IMG_URL + 'head24ore-bott-sudoku.gif" alt="Giochi24 - Sudoku" border="0" height="25" width="30"></a>';
    content += '<a href="http://www.ilsole24ore.com/fc?cmd=art&amp;codid=20.0.1809318792&amp;chId=30&amp;artType=Articolo&amp;DocRulesView=Libero" alt=""><img src="'+ IMG_URL + 'head24ore-bott-video.gif" alt="Video" border="0" height="25" width="30"></a>';

    content += '</div>';
    
    content += '<div id="r24_banner">';
    content += '<a href="http://www.radio24.ilsole24ore.com/"><img src="'+ IMG_URL + 'head24ore-bott-r24.gif" alt="" border="0" height="35" width="55"></a>';
    content += '</div>';
	
		header.innerHTML = content;
		
	 	return true;
	
}



function DrawSearchForm(actionURL) {
	
	var content = '';
	var cell = document.getElementById("head24-cerca");
	
	if (cell==null) return false;

    if (actionURL != null)
    {
        content += '<form name="ricerca" action="' + actionURL + '" method="get">';

        content += '<span id="testoSearchBox">Cerca</span>';
        content += '<input name="keyWords" maxlength="50" size="70" class="testoSearchBox" type="text">';
        content += '<span id="testoSearchBox">in</span>';

        content += '<select class="testoSearchBox" name="channelsId">';
        content += '<option value="informazione|borsa|47|33|30|32|43|40|35">Tutte le fonti</option>';
        content += '<option value="informazione" selected>Informazione online</option>';
        content += '<option value="borsa">Borsa online</option>';
        content += '<option value="47">Casa 24</option>';
        content += '<option value="40">Radio 24</option>';
        content += "<option value='33'>L'Esperto risponde</option>";
        content += "<option value='30|32|43|35'>Contenuti d'archivio</option>";
        content += '</select>';

        content += '<input name="vai2" alt="" class="head24-cerca-input" src="'+ IMG_URL + 'head24ore-login-arr.gif" align="middle" border="0" height="21" type="image" width="21">';
        //content += '</div>';
        content += '<input type="hidden" name="cmd" value="static">';
        content += '<input type="hidden" name="chId" value="30">';
        content += '<input type="hidden" name="path" value="/search/search_engine.jsp">';
        content += '</form>';
	}
	else
	{
	    content += '';
	}

	cell.innerHTML = content;
	 
	return true;

}





// disegna la testata in base al tipo
function disegna_testata(){
	
	
	var browserName=navigator.appName;
	var OSName;
        
 	if (this.Tipo == "Alta") { 
 		
 		 // caricamento css per testata alta
		
		 if (browserName=="Microsoft Internet Explorer")
		 {
		     document.write("<link href=http://www.ilsole24ore.com/st/testata/sole24/css/alta/testata_ie.css rel=stylesheet type=text/css media=all />");
		     //document.write("<link href=/css/testata_ie.css rel=stylesheet type=text/css media=all />");	  
	         }
	     	 else
		 {
		     document.write("<link href=http://www.ilsole24ore.com/st/testata/sole24/css/alta/testata_ne.css rel=stylesheet type=text/css media=all />"); 	
		     //document.write("<link href=/css/testata_ne.css rel=stylesheet type=text/css media=all />");
		 }	
	
	//disegna la testata alta in base ai seguenti controlli:
		   
	   if (this.ShowPremiumBanner)
	   		DrawPremiumBanner(); 
	   
	   if (this.ShowSearchForm)
				DrawSearchForm(this.SearchURL);
	    	
	   if (this.ShowBottoni) 	
		 		DrawBottoni();
		 		
		 if (this.ShowEdizioneOdierna) 
		 		DrawEdizioneOdierna();
		 
		 if (this.ShowLogo)
		 		DrawLogo();
		 		
		 if (this.ShowNavigatore)
		 		DrawNavigatoreAlto(this.Canale);
	}	
	   
	   

else if (this.Tipo == "Bassa") { 
	
	 // caricamento css per testata bassa e testata servizio
	 
	 if (browserName=="Microsoft Internet Explorer")
	 {
	     document.write("<link href=http://www.ilsole24ore.com/st/testata/sole24/css/bassa_servizio/testata_ie.css rel=stylesheet type=text/css media=all />");	  
	     //document.write("<link href=/css/testata_ie.css rel=stylesheet type=text/css media=all />");
         }
     	 else
	 {
	     document.write("<link href=http://www.ilsole24ore.com/st/testata/sole24/css/bassa_servizio/testata_ne.css rel=stylesheet type=text/css media=all />"); 
	     //document.write("<link href=/css/testata_ie.css rel=stylesheet type=text/css media=all />");	
	 }	
	
	
	if (this.ShowPremiumBanner)
	   		DrawPremiumBanner(); 
	   
	   if (this.ShowSearchForm)
				DrawSearchForm(this.SearchURL);
	    	
	   if (this.ShowBottoni) 	
		 		DrawBottoni();
		 		
		 if (this.ShowLogo)
		 		DrawLogoBasso();
		 		
		 if (this.ShowNavigatore)
		 		DrawNavigatoreBasso(this.Canale); 
		 		
} 

else if (this.Tipo == "Servizio") {

// caricamento css per testata bassa e testata servizio
	 
	 if (browserName=="Microsoft Internet Explorer")
	 {
	     document.write("<link href=http://www.ilsole24ore.com/st/testata/sole24/css/bassa_servizio/testata_ie.css rel=stylesheet type=text/css media=all />");	  
         }
     	 else
	 {
	     document.write("<link href=http://www.ilsole24ore.com/st/testata/sole24/css/bassa_servizio/testata_ne.css rel=stylesheet type=text/css media=all />"); 	
	 }	
	 
	 if (this.ShowNavigatore)
		 		DrawNavigatoreBasso(this.Canale); 
		 		
	 if (this.ShowLogo)
		 		DrawLogoServizio(); 		

}	   
	   
	   
	   
	if (isPremium == "1"){
		
		if (isAuthenticated && this.ShowWellcomeMessage){
			if (this.Tipo == "Bassa") { authenticated_user_premium_bassa(); } else { authenticated_user_premium(); }
			{
				document.getElementById("spnFriendlyName").innerHTML = friendlyName.length<=20?friendlyName:friendlyName.substring(0,17) + "...";
				document.getElementById("lnkLogoff").href = this.LogoutUrl + "?RURL=" + escape(this.LoginRURL);
				document.getElementById("lnkUserProfile").href = this.UserProfileUrl + "?SiteCode=" + this.SiteCode + "&RURL=" + escape(this.LoginRURL);
			}
		}
	}else{
	
		if (isAuthenticated && this.ShowWellcomeMessage){
			if (this.Tipo == "Bassa") { authenticated_user_bassa(); } else { authenticated_user(); }
			{
				document.getElementById("spnFriendlyName").innerHTML = friendlyName.length<=20?friendlyName:friendlyName.substring(0,17) + "...";
				document.getElementById("lnkLogoff").href = this.LogoutUrl + "?RURL=" + escape(this.LoginRURL);
				document.getElementById("lnkUserProfile").href = this.UserProfileUrl + "?SiteCode=" + this.SiteCode + "&RURL=" + escape(this.LoginRURL);
			}
		}
	}
	
	if (!isAuthenticated && this.ShowLoginForm){
		
		if (this.Tipo == "Bassa") { auth_form_bassa(); } else { auth_form(); }
		
		{	
			var f = document.forms["authUser"];
			if (getCookie("URLRIT") != null) {	
			        if (document.location.href.indexOf("index") < 0) 
			        	f.elements["RURL"].value = getCookie("URLRIT");
			        else
			        	f.elements["RURL"].value = this.LoginRURL;       	
			}else
				f.elements["RURL"].value = this.LoginRURL;       
				
				f.elements["ERRURL"].value = this.ERRURL;
				f.elements["SC"].value = this.SiteCode;
				f.action = this.LoginUrl;
			
			document.getElementById("lnkSubscribe").href = this.SubscribeUrl + "?SiteCode=" + this.SiteCode + "&RURL=" + escape(this.SubscribeRURL) + "&ERRURL=" + escape(this.ERRURL);
			
			if (this.CheckIfAuthenticated && f!='undefined')
				setTimeout(CheckPopupAuthentication,PopupAuthenticationTimeout);
				
		} 
	}
	
}



// disegna il footer
function disegna_piede(){
	
	drawFooter();
	
}

function drawFooter(){
	var content = '';
	var footer = document.getElementById("footer");
	if (footer == null)
		return false;
	content += '<div id="piede"><div style="width:60%; text-align:left;float:left;">';
  content += '<a href="http://www.gruppo.ilsole24ore.com/Public/IT/001_Header/010_Chi_Siamo/010_Chi_Siamo_1_1_0_0_0.htm">Chi siamo</a> | ';
  content += '<a href="http://newsletters.ilsole24ore.com/">Newsletter</a> | ';
  content += '<a href="http://www.gruppo.ilsole24ore.com/Public/IT/002_Footer/005_Contatti/005_Contatti_1_1_0_0_0.htm">Contattaci</a> | ';
  content += '<a href="http://www.ilsole24ore.com/tuttiservizi/index.shtml">Tutti i servizi</a> | ';
  content += '<a href="http://www.ilsole24ore.com/redazione/news24.shtml">Redazione Online</a> | ';
  content += '<a href="http://annunci.ilsole24ore.com/">Annunci economici</a> | ';
  content += '<a href="http://www.ricerca24.ilsole24ore.com/indiceTop/100aa/100aa-index.html">Parole pi&#249; cercate</a> | ';
  content += '<a href="http://www.ricerca24.ilsole24ore.com/indiceAlfab/a/a-index.html">A-Z</a>';
  content += '</div>';
  content += '<div style="width:40%; text-align:right;float:left;">';
  content += 'P.I. 00777910159 - &#169; Copyright Il Sole 24 Ore - Tutti i diritti sono riservati';
  content += '</div>';
  content += '</div>';
  content += '<div id="under_footer">';
	content += '<a href="#" onClick="setHomePage(location.href)">Fai di questa pagina la tua homepage</a></div>';
		
	
	footer.innerHTML = content;
	
	return true;

}


//Object __PageFooter  definition
function __PageFooter(){
		
	this.DrawFooter= disegna_piede;
	
}


function __PageHeader() {
	
	this.ShowLoginForm = false;
	this.ShowSearchForm = false;
	this.LoginRURL = DEF_RURL;										//pagina di ritorno dal login
	this.ERRURL = DEF_ERRURL;											//ERRURL per form di login e registrazione
	this.SiteCode = DEF_SITECODE;									//SiteCode
	this.LoginUrl = DEF_LOGIN_SCRIPT;							//action del form di login
	this.SubscribeUrl = DEF_SUBSCRIBE_SCRIPT;			//url di avvio registrazione
	this.SubscribeRURL = DEF_RURL;								//url di ritorno dalla registrazione (es. secondo livello)
	this.LogoutUrl = DEF_LOGOFF_SCRIPT;						//url di ritorno dal logout
	this.UserProfileUrl = DEF_USERPROFILE_SCRIPT;	//url del link il mio profilo
	this.CheckIfAuthenticated = false;						//flag per l'avvio del timer per il controllo se autenticato
	this.SearchURL = DEF_SEARCH_URL;    					//action url del box di ricerca
	
	this.TestataHome = true;
	this.DrawHeader = disegna_testata; 
	
	GetUserStatus();
	
}

