/* codice x box di login */

//defaults value
var DEF_RURL = document.location;
var DEF_ERRURL = 'http://www.ilsole24ore.com/errore.shtml';
var DEF_SITECODE = 'CO';
var DEF_SUBSCRIBE_SCRIPT = 'http://du.ilsole24ore.com/DU/iniziaRegistrazione.aspx';
var DEF_LOGIN_SCRIPT = 'http://du.ilsole24ore.com/du/authfiles/logincentrale.aspx';
var DEF_LOGOFF_SCRIPT = 'http://du.ilsole24ore.com/du/authfiles/logoff.aspx';
var DEF_USERPROFILE_SCRIPT = 'http://du.ilsole24ore.com/DU/Areautente/profiloutente.aspx';
var isAuthenticated = false;
var friendlyName = null;
var isPremium = -1;
var isPlus = -1;
var PopupAuthenticationTimeout=60000; //milliseconds
var DataOra;
var DEF_SEARCH_URL = "http://www.ricerca24.ilsole24ore.com";
var IMG_URL = "http://www.ilsole24ore.com/img2009/header/"; 

// 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");
		setCookie("URLRIT",'',-1,"/");
	}
	return true;
}

function getParameter(paramName) {
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	var result = null;
	var pos;
	var key;
	for (var i=0; i<parms.length; i++) {
		pos = parms[i].indexOf('=');
		if (pos > 0) {
			key = parms[i].substring(0,pos);
			if (key == paramName)
			{
				result = unescape(parms[i].substring(pos+1));
			}
		}
	}
	return result;
}

/*
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
			    {
			    	ispremiumPlusIdx = aSoleUser[i].toLowerCase().indexOf('&premiumlevel=');
			    	if (ispremiumPlusIdx == -1) ispremiumPlusIdx = aSoleUser[i].length;
			    	else isPlus = aSoleUser[i].substring(ispremiumPlusIdx+14);
			    	isPremium = aSoleUser[i].substring(ispremiumIdx+11,ispremiumPlusIdx);
			    }

				friendlyName = aSoleUser[i].substring(aSoleUser[i].indexOf('=')+1,ispremiumIdx);
				break;
			}
		}
	}	
	else{
		isAuthenticated = false;
		friendlyName = null;
		isPremium = -1;
		isPlus = -1;
	}
}

function authenticated_user_plus(){
	if (typeof autopromo == 'undefined')
	{
		var content = '<div class="loggato"><table cellpadding="0" cellspacing="0" width="247"><tr valign="top"><td colspan="2" height="4"></td></tr>';
		content += '<tr><td width="150">Benvenuto<br /><strong class="rosso"><span id="spnFriendlyName"></span></strong> <img src="' + IMG_URL + 'ico_premium.gif" alt="!" /></td>';
		content += '<td align="right" valign="top"><a href="" id="lnkLogoff" class="small">ESCI</a></td>';
		content += '<tr><td colspan="2" height="6"></td></tr><tr><td colspan="2" height="1" style="background: #878787"></td></tr></table>';
		content += '<table cellpadding="0" cellspacing="0" width="247"><tr><td colspan="2" height="5"></td></tr><tr valign="top"><td width="130">';
		content += '<div class="logriga"><a id="lnkUserProfile" href="">Il tuo profilo &raquo;</a></div>';
		content += '<a href="http://serviziattivi.ilsole24ore.com">Servizi Attivi &raquo;</a></td>';
		content += '<td><div class="logriga"><br /></div><a href="http://premium.ilsole24ore.com/" class="rosso">Contenuti Premium24 &raquo;</a></td></tr>';
		content += '<tr><td colspan="2" height="5"></td></tr> <tr><td colspan="2" height="1" style="background: #878787"></td></tr></table></div>';
	}
	else if (autopromo == 1)
	{
		var content = '<link href="/css2007/testate_slim09.css" media="all" rel="stylesheet" type="text/css" />';
		content += '<div class="testata09_bannerlogin testata09_bannerlogin_bassa"><div class="loggato">';
		content += '<table width="100%" cellpadding="0" cellspacing="0"><tr valign="middle">';
		content += '<td><table cellpadding="0" cellspacing="0"><tr>';
		content += '<td>Benvenuto  <strong class="rosso"><span id="spnFriendlyName"></span></strong> <img src="' + IMG_URL + 'ico_premium.gif" alt="!" /></td>';
		content += '<td class="t09sepvert_rosso"></td><td class="t09sepvert"></td>';
		content += '<td><a id="lnkUserProfile" href="" class="small">il tuo profilo &raquo;</a></td>';
		content += '<td class="t09sepvert_vuoto"></td><td class="t09sepvert"></td>';
		content += '<td ><a href="http://serviziattivi.ilsole24ore.com" class="small">servizi attivi &raquo;</a></td>';
		content += '<td class="t09sepvert_rosso"></td><td class="t09sepvert"></td>';
		content += '<td> <a href="http://premium.ilsole24ore.com/" class="rosso">Contenuti Premium24 &raquo;</a></td>';
		content += '<td class="t09sepvert_rosso"></td><td class="t09sepvert"></td>';
		content += '<td><a href="" id="lnkLogoff">ESCI</a></td></tr></table></td>';
		content += '<td align="right"></td><td width="10"></td></tr></table></div></div>';
	}
	
	deleteCookieRitorno();
	document.write(content);
}

function authenticated_user_premium(){
	if (typeof autopromo == 'undefined')
	{
		var content = '<div class="loggato"><table cellpadding="0" cellspacing="0" width="247"><tr valign="top"><td colspan="2" height="4"></td></tr>';
		content += '<tr><td width="150">Benvenuto<br /><strong class="rosso"><span id="spnFriendlyName"></span></strong> <img src="' + IMG_URL + 'ico_premium.gif" alt="!" /></td>';
		content += '<td align="right" valign="top"><a href="" id="lnkLogoff" class="small">ESCI</a></td>';
		content += '<tr><td colspan="2" height="6"></td></tr><tr><td colspan="2" height="1" style="background: #878787"></td></tr></table>';
		content += '<table cellpadding="0" cellspacing="0" width="247"><tr><td colspan="2" height="5"></td></tr><tr valign="top"><td width="130">';
		content += '<div class="logriga"><a id="lnkUserProfile" href="">Il tuo profilo &raquo;</a></div>';
		content += '<a href="http://serviziattivi.ilsole24ore.com">Servizi Attivi &raquo;</a></td>';
		content += '<td><div class="logriga"><br /></div><a href="http://premium.ilsole24ore.com/" class="rosso">Contenuti Premium24 &raquo;</a></td></tr>';
		content += '<tr><td colspan="2" height="5"></td></tr> <tr><td colspan="2" height="1" style="background: #878787"></td></tr></table></div>';
	}
	else if (autopromo == 1)
	{
		var content = '<link href="/css2007/testate_slim09.css" media="all" rel="stylesheet" type="text/css" />';
		content += '<div class="testata09_bannerlogin testata09_bannerlogin_bassa"><div class="loggato">';
		content += '<table width="100%" cellpadding="0" cellspacing="0"><tr valign="middle">';
		content += '<td><table cellpadding="0" cellspacing="0"><tr>';
		content += '<td>Benvenuto  <strong class="rosso"><span id="spnFriendlyName"></span></strong> <img src="' + IMG_URL + 'ico_premium.gif" alt="!" /></td>';
		content += '<td class="t09sepvert_rosso"></td><td class="t09sepvert"></td>';
		content += '<td><a id="lnkUserProfile" href="" class="small">il tuo profilo &raquo;</a></td>';
		content += '<td class="t09sepvert_vuoto"></td><td class="t09sepvert"></td>';
		content += '<td ><a href="http://serviziattivi.ilsole24ore.com" class="small">servizi attivi &raquo;</a></td>';
		content += '<td class="t09sepvert_rosso"></td><td class="t09sepvert"></td>';
		content += '<td> <a href="http://premium.ilsole24ore.com/" class="rosso">Contenuti Premium24 &raquo;</a></td>';
		content += '<td class="t09sepvert_rosso"></td><td class="t09sepvert"></td>';
		content += '<td><a href="" id="lnkLogoff">ESCI</a></td></tr></table></td>';
		content += '<td align="right"></td><td width="10"></td></tr></table></div></div>';
	}
	
	deleteCookieRitorno();
	document.write(content);
}

function authenticated_user()
{
	if (typeof autopromo == 'undefined')
	{
		var content = '<div class="loggato"><table cellpadding="0" cellspacing="0" width="247"><tr valign="top"><td colspan="2" height="4"></td></tr>';
		content += '<tr><td width="150">Benvenuto<br /><strong class="blu"><span id="spnFriendlyName"></span></strong></td>';
		content += '<td align="right" valign="top"><a href="" id="lnkLogoff" class="small">ESCI</a></td>';
		content += '<tr><td colspan="2" height="6"></td></tr><tr><td colspan="2" height="1" style="background: #878787"></td></tr></table>';
		content += '<table cellpadding="0" cellspacing="0" width="247"><tr><td colspan="2" height="5"></td></tr><tr valign="top"><td width="130">';
		content += '<div class="logriga"><a id="lnkUserProfile" href="">Il tuo profilo &raquo;</a></div>';
		content += '<a href="http://serviziattivi.ilsole24ore.com">Servizi Attivi &raquo;</a></td><td><div class="logriga">Diventa un utente</div>';
		content += '<a href="http://www.shopping24.ilsole24ore.com/sh3/catalog/ProductI.jsp?PRODID=PREM02" class="rosso"><strong>Premium24</strong><img src="' + IMG_URL + 'ico_premium.gif" alt="!" /></a></td></tr>';
		content += '<tr><td colspan="2" height="5"></td></tr> <tr><td colspan="2" height="1" style="background: #878787"></td></tr></table></div>';
	}
	else if (autopromo == 1)
	{
		var content = '<link href="/css2007/testate_slim09.css" media="all" rel="stylesheet" type="text/css" />';
		content += '<div class="testata09_bannerlogin testata09_bannerlogin_bassa">';
		content += '<div class="loggato"><table width="100%" cellpadding="0" cellspacing="0">';
		content += '<tr valign="middle"><td><table cellpadding="0" cellspacing="0"><tr>';
		content += '<td>Benvenuto <strong class="blu"><span id="spnFriendlyName"></span></strong></td>';
		content += '<td class="t09sepvert_blu"></td><td class="t09sepvert"></td>';
		content += '<td><a id="lnkUserProfile" href="" class="small">il tuo profilo &raquo;</a></td>';
		content += '<td class="t09sepvert_vuoto"></td><td class="t09sepvert"></td>';
		content += '<td ><a href="http://serviziattivi.ilsole24ore.com" class="small">servizi attivi &raquo;</a></td>';
		content += '<td class="t09sepvert_blu"></td><td class="t09sepvert"></td>';
		content += '<td ><a href="" id="lnkLogoff">ESCI</a></td></tr></table></td>';
		content += '<td align="right"><a href="http://www.shopping24.ilsole24ore.com/sh3/catalog/ProductI.jsp?PRODID=PREM02">DIVENTA UN UTENTE <strong class="rosso">PREMIUM24</strong> <img src="' + IMG_URL + 'ico_premium.gif" alt="!" /></a> </td>';
		content += '<td width="10"></td></tr></table></div></div>';
	}
	
	deleteCookieRitorno();
	document.write(content);
}

//disegna la form di log-in
function auth_form() {
	if (typeof autopromo == 'undefined')
	{
		var content = '<div class="login"><h3 class="titoGuida"><strong>Login</strong></h3><form action="" method="post" name="authUser" onsubmit="setCookieRitorno()">';
		content += '<INPUT value="" name="URL" type="hidden"/><INPUT value="BYPOST" name="realSubmit" type="hidden"/>';
		content += '<INPUT type="hidden" name="RURL" value=""/><INPUT type="hidden" name="ERRURL" value=""/>';
		content += '<INPUT type="hidden" name="SC" value=""/>';
		content += '<table cellpadding="0" cellspacing="0" width="222"><tr><td colspan="2" height="4"></td></tr><tr>';
	    content += '<td width="130"><input name="txtUsername" type="text" size="15" class="in_testata" /></td><td>';
		content += '<a id="lnkSubscribe" href="">Registrati &raquo;</a></a></td></tr>';
		content += '<tr><td colspan="2" height="4"></td></tr><tr><td><input size="15" class="in_testata2 absmiddle" name="txtPassword" value="" type="password" />';
		content += '<input src="'+IMG_URL+'vai.gif" type="image" alt="Vai" class="absmiddle" /></td><td><a href="http://newsletters.ilsole24ore.com/">Newsletter &raquo;</a></td></tr>';
		content += '<tr><td colspan="2" height="10"></td></tr><tr><td colspan="2" height="1" style="background: #878787"></td></tr></table>';
		content += '<table cellpadding="0" cellspacing="0" width="222"><tr><td colspan="2" height="6"></td></tr>';
		content += '<tr><td width="130"><a href="http://www.ilsole24ore.com/st/abbonamenti/abbonamenti.html"><strong>Abbonamenti &raquo;</strong></a></td>';
		content += '<td><a href="http://premium.ilsole24ore.com/"><strong>Premium24 &raquo;</strong></a></td></tr></table></form></div>';
	}
	else if (autopromo == 1)
	{
		var content = '<link href="/css2007/testate_slim09.css" media="all" rel="stylesheet" type="text/css" />';
		content += '<div class="testata09_bannerlogin testata09_bannerlogin_bassa"><div class="login">';
		content += '<form action="" method="post" name="authUser" onsubmit="setCookieRitorno()">';
		content += '<INPUT value="" name="URL" type="hidden"/><INPUT value="BYPOST" name="realSubmit" type="hidden"/>';
		content += '<INPUT type="hidden" name="RURL" value=""/><INPUT type="hidden" name="ERRURL" value=""/>';
		content += '<INPUT type="hidden" name="SC" value=""/>';
		content += '<table width="980" cellpadding="0" cellspacing="0"><tr valign="middle">';
		content += '<td width="150"><input name="txtUsername" type="text" class="in_testata" value="" size="15" /></td>';
		content += '<td width="160"><input name="txtPassword" type="password" class="in_testata2 absmiddle" value="" size="15" /><input type="image" src="'+IMG_URL+'vai.gif" alt="Vai" class="absmiddle" /></td>';
		content += '<td width="75"><a id="lnkSubscribe" href="">Registrati &raquo;</a></td>';
		content += '<td width="85"><a href="http://newsletters.ilsole24ore.com/">Newsletter &raquo;</a></td>';
		content += '<td width="95"><a href="http://www.ilsole24ore.com/st/abbonamenti/abbonamenti.html">Abbonamenti &raquo;</a></td>';
		content += '<td width="413"><a href="http://premium.ilsole24ore.com/">Premium24 &raquo;</a></td>';
		content += '</tr></table></form></div></div>';
	}

	document.write(content);
}

//disegna la form di log-in per la preview degli articoli a pagamento
function auth_formprv() {
	var content  = '';
	var cell = document.getElementById("auth_container");
	if (cell==null)
		return false;
		
	content += '<form name="authUser" method="post" action="" onsubmit="setCookieRitorno()">';
	content += '<table border="0" cellspacing="0" cellpadding="0"><input type="hidden" name="URL" value="">';
	content += '<input type="hidden" name="realSubmit" value="BYPOST"><input type="hidden" name="RURL" value="">';
	content += '<input type="hidden" name="ERRURL" value=""><input type="hidden" name="SC" value="">';
	content += '<tr><td colspan="5"><img src="' + IMG_URL + 'pix.gif" width="633" height="35" /></td></tr>';
	content += '<tr><td><img src="' + IMG_URL + 'pix.gif" width="118" height="1" /></td>';
	content += '<td colspan="3" width="397" class="blubo13">Per leggere questo contenuto ad accesso riservato nella versione integrale, devi ';
	content += 'inserire qui la username e la password da te scelte per fruire del servizio:</td>';
	content += '<td><img src="' + IMG_URL + 'pix.gif" width="118" height="1" /></td></tr>';
	content += '<tr><td colspan="5"><img src="' + IMG_URL + 'pix.gif" width="633" height="75" /></td></tr>';
	content += '<tr><td></td><td class="nebo12" width="65">Username:</td><td width="160"><input type="text" name="txtUsername" size="20" maxlength="50" id="username"></td>';
	content += '<td cospan="2"></td></tr><tr><td></td><td class="nebo12">Password:</td>';
	content += '<td><input type="password" name="txtPassword" size="20" maxlength="50" id="password"></td>';
	content += '<td><input type="image" src="' + IMG_URL + 'bottone_entra.gif" name="vai" alt="ENTRA" width="84" height="19" vspace="8" border="0" /></td>';
	content += '<td></td></tr><tr><td colspan="2"></td><td align="left" nowrap>';
	content += '<a href="http://du.ilsole24ore.com/DU/passwordReminder.aspx?RURL=' + escape(this.LoginRURL) + '" class="linkbluno11">Hai dimenticato la password?</a>';
	content += '</td><td colspan="2"></td></tr>';
	content += '<tr><td colspan="5"><img src="' + IMG_URL + 'pix.gif" width="633" height="40" /></td></tr></table></form>';

	cell.innerHTML = content;

	return true;
}

function setDUUrls() {
    var hostname = document.location.hostname.toLowerCase();

    if (hostname.indexOf('.dlv.') != -1) { // stage
        login.LoginUrl  = "http://duprovisioning.dlv.24orepro.in.ilsole24ore.it/DU/authfiles/logincentrale.aspx";
        login.LogoutUrl = "http://duprovisioning.dlv.24orepro.in.ilsole24ore.it/DU/authfiles/logoff.aspx";
        login.UserProfileUrl = "http://duprovisioning.dlv.24orepro.in.ilsole24ore.it/DU/areautente/profiloutente.aspx";
        login.SubscribeUrl = "http://duprovisioning.dlv.24orepro.in.ilsole24ore.it/DU/iniziaregistrazione.aspx";
    }
    else if (hostname.indexOf('.dev.') != -1)   // sviluppo
    {
        login.LoginUrl  = "http://duprovisioning.dev.24orepro.in.ilsole24ore.it/DU/authfiles/logincentrale.aspx";
        login.LogoutUrl = "http://duprovisioning.dev.24orepro.in.ilsole24ore.it/DU/authfiles/logoff.aspx";
        login.UserProfileUrl = "http://duprovisioning.dev.24orepro.in.ilsole24ore.it/DU/areautente/profiloutente.aspx";
        login.SubscribeUrl = "http://duprovisioning.dev.24orepro.in.ilsole24ore.it/DU/iniziaregistrazione.aspx";
    }
}

function disegna_auth(){
	setDUUrls();
	
	if (isPremium == "1"){
		
		if (isPlus == "2")
		{
			if (isAuthenticated && this.ShowWellcomeMessage){
				authenticated_user_plus(); 
				{
					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){
			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){
			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){
		
		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);
		}
	}
}

function disegna_authprv(){	
	setDUUrls();
	
	auth_formprv(); 
	
	var f = document.forms["authUser"];

	f.elements["RURL"].value = this.LoginRURL;       
	f.elements["ERRURL"].value = this.ERRURL;
	f.elements["SC"].value = this.SiteCode;
	f.action = this.LoginUrl;
}

function disegna_prverror(){	
	var errmsg1 = "Questo &egrave; un contenuto ad accesso riservato.";
	var errmsg2 = '<td class="colore_grigioscuro"><strong>Per accedere introdurre USERNAME e PASSWORD.</strong></td>';
	
	var errcode = getCookie('SoleError');
	deleteCookie('SoleError');
	
	if (isAuthenticated)
	{
		var errmapping = new Array();
		errmapping[1002] = 'La chiave di accesso (username) utilizzata non risulta abilitata ad alcun servizio.';
		errmapping[1005] = 'La chiave di accesso (username) utilizzata non &#232; abilitata a consultare il servizio';
		errmapping[1006] = 'L\'accesso al servizio non &#232; consentito poich&#232; il contratto &#232; scaduto.';
		errmapping[1008] = 'Gentile utente, l\'accesso non &#232; consentito poich&#232; l\'indirizzo IP non risulta abilitato alla consultazione del servizio.';
		errmapping[1009] = 'L\'accesso al servizio non &#232; consentito poich&#232; l\'utente non &#232; abilitato a fruirne in questa fascia oraria.';
		errmapping[1010] = 'La chiave di accesso (username) utilizzata non &#232; abilitata a consultare il servizio';
		errmapping[1015] = 'Spiacenti. L\'utente ha raggiunto la quota massima di consumo.';
		errmapping[1016] = 'Spiacenti. Il costo dell\'operazione non &#232; coperto dal credito disponibile';
	
		errmsg1 = "Gentile UTENTE "+friendlyName+", il suo profilo non le consente l'accesso a questo contenuto.";
		errmsg2 = '<td class="colore_grigioscuroPicco">';
		errmsg2 += '<strong>Se &egrave; gi&agrave; in possesso di un differente profilo che le permette l\'accesso a questo contenuto la invitiamo a effettuare<br />nuovamente il login.  </strong>';
		errmsg2 += '<strong>Altrimenti la invitiamo a considerare le modalit&agrave; di accesso al contenuto presentate in questa pagina. </strong> </td>';
		
		if (errmapping[errcode] != undefined)
			errmsg1 = errmapping[errcode];
	}
	else
	{
		var duError = getParameter('ErrMsg');
		if (duError == "Utente+non+registrato")
		{
			errmsg1 = 'Utente non registrato. USERNAME e PASSWORD non validi';
		}
		else
		{
			if (duError == "Password+errata")
			{
				errmsg1 = "Password errata";
			}
			else
				if (duError != null)
				{
					errmsg1 = duError;
				}
		}
	}
	
	draw_prverror(errmsg1,errmsg2);
}

function draw_prverror(errmsg1,errmsg2) {
	var cell = document.getElementById("prv_error");
	if (cell==null)
		return false;
	
	var content = '';
	
	content += '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
	content += '<tr><td class="colore_grigioscuro"><img src="' + IMG_URL + 'pix.gif" width="19" height="1" /></td>';
	content += '<td class="colore_grigioscuro"><img src="' + IMG_URL + 'pix.gif" width="972" height="14" /></td></tr>';
	content += '<tr><td rowspan="2" class="colore_grigioscuro"></td><td class="colore_grigioscuroGiallo">'+errmsg1+'</td></tr>';
	content += '<tr>' + errmsg2 + '</tr>';
	content += '<tr><td colspan="2" class="colore_grigioscuro"><img src="' + IMG_URL + 'pix.gif" width="991" height="7" /></td></tr>';
	content += '<tr><td colspan="2"><img src="' + IMG_URL + 'gradiente_giallo.gif" width="991" height="16" /></td></tr></table>';

	cell.innerHTML = content;

	return true;
}

function __Login() {
	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.DrawLogin = disegna_auth;
	this.DrawLoginPrv = disegna_authprv;
	this.DrawLoginError = disegna_prverror;
	
	GetUserStatus();
}

var login = new __Login();
login.ShowLoginForm = true;
login.ShowWellcomeMessage = true;
login.DrawLogin();
/* find codice x box di login */

function cp_show(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	
	if (document.all) {
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	} else{
		posx = e.pageX;
		posy = e.pageY;
	}  
	
	// posx and posy contain the mouse position relative to the document
	document.getElementById("cp_box").style.display = "block";
	document.getElementById("cp_box").style.top = posy + "px";
	document.getElementById("cp_box").style.left = (posx-122) + "px";
	
}

function quotidianoOnlinePopUp(){
	var url = "http://edicola.ilsole24ore.com/homeVal.jsp?paper=SO,sole";
	var winame = "SIPOL";
	var settings = "status=no,toolbar=no,menubar=no,location=yes,scrollbars=yes,maximize=yes,resizable=yes";

	var newWin = window.open(url, winame, settings);

	newWin.moveTo(0,0);

	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
	{
		newWin.resizeTo(screen.availWidth,screen.availHeight);
	}
	else
	{
		newWin.outerHeight = screen.availHeight; newWin.outerWidth = screen.availWidth;
	}
	
}