﻿
var CRTL_SessionID = '';
var CRTL_LoggedName = '';

function CRTL_FadeIn(oDiv)
{
	oDiv.style.display = 'block';
}

function CRTL_FadeOut(oDiv)
{
	oDiv.style.display = 'none';
}

function CRTL_OnMouseLeave(obj, evt)
{
	oParent = window.event?evt.toElement:evt.relatedTarget;
	while(oParent != null)
	{
		if(oParent == obj) return false;
		oParent = oParent.parentNode;
	}
	
	return true;
}

function CRTL_SetCookie(sName, sValue, bPersistant)
{
	var today = new Date();
	var expiry = new Date(today.getTime() + (bPersistant ? (30*24*3600*1000) : (24*60*60*1000)));
	if(sValue == null) sValue = '';
	if(sValue.length == 0) expiry = new Date(today.getTime() - 1000);

	//document.cookie = sName + '=' + sValue + ';path=/;expires=' + expiry.toGMTString();
	
	//document.cookie = sName + '=' + sValue + ';path=/;domain=rtltvi.be;expires=' + expiry.toGMTString();
	//document.cookie = sName + '=' + sValue + ';path=/;domain=clubrtl.be;expires=' + expiry.toGMTString();
	//document.cookie = sName + '=' + sValue + ';path=/;domain=plugrtl.be;expires=' + expiry.toGMTString();
	document.cookie = sName + '=' + sValue + ';path=/;domain=rtl.be;expires=' + expiry.toGMTString();
	//document.cookie = sName + '=' + sValue + ';path=/;domain=belrtl.be;expires=' + expiry.toGMTString();
	document.cookie = sName + '=' + sValue + ';path=/;domain=radiocontact.be;expires=' + expiry.toGMTString();
	document.cookie = sName + '=' + sValue + ';path=/;domain=rtlalinfini.be;expires=' + expiry.toGMTString();

	CRTL_SetCookieForDomain(sName, sValue, bPersistant, 'connect.rtl.be');
	//CRTL_SetCookieForDomain(sName, sValue, bPersistant, 'www.rtltvi.be');
	//CRTL_SetCookieForDomain(sName, sValue, bPersistant, 'www.clubrtl.be');
	//CRTL_SetCookieForDomain(sName, sValue, bPersistant, 'www.plugrtl.be');
	//CRTL_SetCookieForDomain(sName, sValue, bPersistant, 'www.belrtl.be');
	CRTL_SetCookieForDomain(sName, sValue, bPersistant, 'www.radiocontact.be');
	CRTL_SetCookieForDomain(sName, sValue, bPersistant, 'www.rtlalinfini.be');
}

function CRTL_SetCookieForDomain(sName, sValue, bPersistant, sDomain)
{
	script = document.createElement('script');
    script.type = 'text/javascript';
    script.src  = 'http://' + sDomain + '/RTLIDOAuth.aspx?action=setcookie&name=' + sName + '&value=' + sValue + '&persist=' + (bPersistant ? 1 : 0);
    document.getElementsByTagName('head')[0].appendChild(script);	
}

function CRTL_GetCookie(sName)
{
	sCookies = '' + document.cookie + ';';
	s = 0;
	while( -1 != (e = sCookies.indexOf(';', s)) )
	{
		sCookie = sCookies.substr(s, e-s);
		if(sCookie.indexOf('=') != -1)
		{
			sCookieName = sCookie.substr(0, sCookie.indexOf('=')).replace(' ', '');
			if(sCookieName == sName) return sCookie.substr(sCookie.indexOf('=') + 1);
		}
		
		s = e + 1;
	}
	
	return '';
}

function CRTL_GetTagValue(oXml, sName)
{
	if (oXml.getElementsByTagName(sName).length > 0)
	{
		if (oXml.getElementsByTagName(sName)[0].childNodes.length > 0) return oXml.getElementsByTagName(sName)[0].childNodes[0].nodeValue;
	}

	return '';
}

function CRTL_HttpRequest(sURL, sTarget)
{
	script = document.createElement('script');
    	script.type = 'text/javascript';
    	script.src  = sURL + '?bNoLog=1&js=document.getElementById(\'' + sTarget + '\').innerHTML=\'{0}\';CRTL_CheckSession();';
    	document.getElementsByTagName('head')[0].appendChild(script);
}

function CRTL_CheckSessionCallback(sResponse)
{
	if(CRTL_HandleResponse(sResponse))
	{
		document.getElementById('CRTL_LoggedName').innerHTML = 'Bonjour ' + CRTL_LoggedName;
		document.getElementById('CRTL_Logged').style.display='block';

		CRTL_SetCookie('CRTL_Session', CRTL_GetCookie('CRTL_Session'), false);
	}
	else
	{
		document.getElementById('CRTL_Login').style.display='block';

		CRTL_SetCookie('CRTL_Session', '', false);
	}
}

function CRTL_CheckSession()
{
	document.forms['CRTL_LoginForm'].sEMAIL.value = CRTL_GetCookie('CRTL_Email');
	document.forms['CRTL_LoginForm'].sPASSWORD.value = CRTL_GetCookie('CRTL_Password');
	if(document.forms['CRTL_LoginForm'].sEMAIL.value.length > 0)
	{
		document.forms['CRTL_LoginForm'].bREMEMBERME.checked = true;
	}

	script = document.createElement('script');
    	script.type = 'text/javascript';
    	script.src  = 'http://www.rtl.be/moncompte/RID_Id.asmx?action=checksession&js=CRTL_CheckSessionCallback(\'{0}\');&sSESSION=' + encodeURIComponent(CRTL_GetCookie('CRTL_Session'));
    	document.getElementsByTagName('head')[0].appendChild(script);
}

function CRTL_ConnectCallback(sResponse, sFormName, sTarget)
{
	if(CRTL_HandleResponse(sResponse, sTarget))
	{
		CRTL_SetCookie('CRTL_Session', CRTL_SessionID, false);
		
		if(document.forms[sFormName].bREMEMBERME.checked)
		{
			CRTL_SetCookie('CRTL_Email', document.forms[sFormName].sEMAIL.value, true);
			CRTL_SetCookie('CRTL_Password', document.forms[sFormName].sPASSWORD.value, true);
		}
		else
		{
			CRTL_SetCookie('CRTL_Email', '', true);
			CRTL_SetCookie('CRTL_Password', '', true);
		}

		window.location = window.location;
	}
}

function CRTL_Connect(oForm, sTarget)
{
	script = document.createElement('script');
    	script.type = 'text/javascript';
    	script.src  = 'http://www.rtl.be/moncompte/RID_Id.asmx?action=login&js=CRTL_ConnectCallback(\'{0}\',\'' + oForm.name + '\', \'' + sTarget + '\');&sEMAIL=' + encodeURIComponent(oForm['sEMAIL'].value) + '&sPASSWORD=' + encodeURIComponent(oForm['sPASSWORD'].value);
    	document.getElementsByTagName('head')[0].appendChild(script);
}

function CRTL_DisconnectCallback(sResponse)
{
	if(CRTL_HandleResponse(sResponse))
	{
		CRTL_SetCookie('CRTL_Session', '', false);
		
		window.location = window.location;
	}
}

function CRTL_Disconnect()
{
	script = document.createElement('script');
    	script.type = 'text/javascript';
    	script.src  = 'http://www.rtl.be/moncompte/RID_Id.asmx?action=logout&js=CRTL_DisconnectCallback(\'{0}\');&sSESSION=' + CRTL_SessionID;
    	document.getElementsByTagName('head')[0].appendChild(script);
}

function CRTL_HandleResponse(sResponse, sTarget)
{
	var nError = -1;
	var oXml = null;

	try
	{
		oXml = new ActiveXObject("Msxml2.DOMDocument.3.0");
		oXml.loadXML(sResponse);
	}
	catch (e)
	{
		try
		{
			parser = new DOMParser();
			oXml = parser.parseFromString(sResponse, "text/xml");
		}
		catch (e)
		{
			alert(e);
		}
	}

	if(oXml)
	{
		sMessage = CRTL_GetTagValue(oXml, 'MESSAGE');
		nError = parseInt(CRTL_GetTagValue(oXml, 'STATUS'));

		sSessionId = CRTL_GetTagValue(oXml, 'SESSIONID');
		if(sSessionId.length > 0) CRTL_SessionID = sSessionId;

		sLoggedName = CRTL_GetTagValue(oXml, 'FIRSTNAME');
		if(sLoggedName.length > 0) CRTL_LoggedName = sLoggedName;
		
		if(sMessage.length > 0) CRTL_Alert(sMessage, sTarget);
	}

	return (nError == 0);
}

function CRTL_ResetPasswordCallback(sResponse)
{
	CRTL_HandleResponse(sResponse);
}

function CRTL_ResetPassword(oForm)
{
	//oForm = document.forms['CRTL_LoginForm'];

	oForm.sPASSWORD.value = '';
	CRTL_SetCookie('CRTL_Password', '', true);

	script = document.createElement('script');
    	script.type = 'text/javascript';
    	script.src  = 'http://www.rtl.be/moncompte/RID_Id.asmx?action=resetpassword&js=CRTL_ResetPasswordCallback(\'{0}\');&sLOGIN=' + encodeURIComponent(oForm['sEMAIL'].value);
    	document.getElementsByTagName('head')[0].appendChild(script);
}

function CRTL_CheckEmailDisponibilityCallback(sResponse, sFormName, sTarget)
{
	if(CRTL_HandleResponse(sResponse, sTarget))
	{
		document.forms[sFormName].submit();
	}
}

function CRTL_CheckEmailDisponibility(sEmail, oForm, sTarget)
{
	script = document.createElement('script');
    	script.type = 'text/javascript';
    	script.src  = 'http://www.rtl.be/moncompte/RID_Id.asmx?action=checkemaildisponibility&js=CRTL_CheckEmailDisponibilityCallback(\'{0}\', \'' + oForm.name + '\', \'' + sTarget + '\');&sEMAIL=' + encodeURIComponent(oForm['sEMAIL'].value);
    	document.getElementsByTagName('head')[0].appendChild(script);
}

function CRTL_Alert(sMessage, sTarget)
{
	if(sTarget != null && sTarget.length > 0)
	{
		oTarget = document.getElementById(sTarget);
		if(oTarget != null)
		{
			oMessageBox = oTarget.previousSibling
			if(oMessageBox == null || oMessageBox.className != 'MsgBoxHolder')
			{
				oMessageBoxHolder = document.createElement('SPAN');
				oMessageBoxHolder.className = 'MsgBoxHolder';
				oTarget.parentNode.insertBefore(oMessageBoxHolder, oTarget);

				oMessageBoxHolder.innerHTML = '<span id="' + sTarget + 'MsgBox" class="MsgBox" onclick="this.style.display=\'none\';"><span class="MsgBoxText"></span></span>';

				oMessageBox = document.getElementById(sTarget + 'MsgBox');
				oMessageBoxText = oMessageBox.firstChild;

				oMessageBoxText.innerHTML = sMessage;
				oMessageBox.style.display = 'block';
				oDummy = document.createElement('span');
				oDummy.className = 'MsgBoxBottom';
				oDummy.style.clear = 'both';
				oMessageBox.appendChild(oDummy);
				oMessageBox.style.top = -(oDummy.offsetTop + 24) + 'px';

				oTarget.setAttribute('onclick', 'this.previousSibling.style.display=\'none\';this.focus();');
			}
			else
			{
				oMessageBox = oMessageBox.firstChild;
				oMessageBoxText = oMessageBox.firstChild;

				oMessageBoxText.innerHTML = sMessage;
				oMessageBox.style.display = 'block';
			}
		}
	}
	else
	{
		oMessageBox = document.getElementById('CRTL_ErrorMessage');
		oMessageBoxText = document.getElementById('CRTL_ErrorMessageText');

		oMessageBoxText.innerHTML = sMessage;
		oMessageBox.style.display = 'block';
	}
}

function CRTL_TogglePopmenuItem(oLink)
{
	oInfos = null;
	oItem = oLink.parentNode;
	oDivs = oItem.getElementsByTagName('DIV');

	for(i=0;i<oDivs.length;i++)
	{
		if(oDivs[i].className == 'MetanavPopupItemInfo') oInfos = oDivs[i];
	}


	if(oLink.className == 'Expand')
	{
		oLink.className = 'Reduce';
		if(oInfos) oInfos.style.display = 'block';
	}
	else
	{
		oLink.className = 'Expand';
		if(oInfos) oInfos.style.display = 'none';
	}
}

function CRTL_InitSitesbar()
{
	document.write('<link rel="stylesheet" type="text/css" href="http://common.rtl.be/css/Sitesbar/sitebar.css" media="all" />');

	var CRTL_oDiv = document.createElement('DIV');
	CRTL_oDiv.setAttribute('id', 'CRTL_Sitebar');

	var CRTL_oBody = document.getElementsByTagName('body')[0];
	CRTL_oBody.insertBefore(CRTL_oDiv, CRTL_oBody.firstChild);

	sInnerHTML = '';
	
	sInnerHTML += '<div id="Sitesbar"> \
<div id="SitesbarInner"> \
<div id="CRTL_Logged"><a title="Me d&eacute;connecter" onclick="CRTL_Disconnect(); return false;" href=""><input class="DeconnexionBut" onclick="parentNode.click();" value=" " type="button"></a><a title="Mon profil" href="http://www.rtl.be/moncompte"><input class="MoncompteBut" onclick="parentNode.click();" value=" " type="button"></a>  \
<div id="CRTL_LoggedName"></div></div> \
<div id="CRTL_Login"><a id="ShowPopup" onclick="document.getElementById(\'CRTL_LoginPopup\').style.display=\'block\'; return false;" href="javascript:">S\'identifier</a> <a id="Subscribe" href="http://www.rtl.be/moncompte/page/inscription-etape-1/5.aspx">Cr&eacute;er un compte</a>  \
<div id="CRTL_LoginPopup"><a id="HidePopup" onclick="document.getElementById(\'CRTL_LoginPopup\').style.display=\'none\'; return false;" href="javascript:">S\'identifier</a>  \
<form name="CRTL_LoginForm">Adresse e-mail<br /><input class="LoginText" name="sEMAIL" maxLength="199" required="1" minlength="1"><br />Mot de passe&nbsp;<img alt="" align="absMiddle" src="http://common.rtl.be/CWS/Img/Void.gif" width="32" height="16" /> <a href="http://www.rtl.be/moncompte/page/mot-de-passe-oublie/13.aspx">Mot de passe oubli&eacute;<br /></a> \
<div id="ErrorTarget0"></div><input class="LoginText" name="sPASSWORD" maxLength="199" type="password" required="1" minlength="1"><br /><input class="ConnexionBut" onclick="CRTL_Connect(this.form, \'ErrorTarget0\'); return false;" name="Connexion" value=" " type="button"><img alt="" align="bottom" src="http://common.rtl.be/CWS/Img/Void.gif" width="8" height="16" /><input class="LoginCheckbox" name="bREMEMBERME" value="1" type="checkbox"><img alt="" align="top" src="http://common.rtl.be/CWS/Img/Void.gif" width="4" height="16" /><label for="bREMEMBERME">Se souvenir de moi</label></form></div></div> \
<ul class="Sites"> \
<li class="separator"> \
<li class="Be"><a class="SiteBe" href="http://www.rtl.be/">RTL.be</a>  \
<li class="separator"> \
<li id="tinfo" class="Info" onmouseover="try{if(CRTL_FadeOut != null){document.getElementById(\'MN_info\').style.display=\'block\';}}catch(e){}" onmouseout="try{if(CRTL_OnMouseLeave(this, event)){CRTL_FadeOut(document.getElementById(\'MN_info\'));}}catch(e){}"><a class="Site" href="http://www.rtl.be/info">INFO</a>  \
<li class="separator"> \
<li id="tsport" class="Sport" onmouseover="try{if(CRTL_FadeOut != null){document.getElementById(\'MN_sport\').style.display=\'block\';}}catch(e){}" onmouseout="try{if(CRTL_OnMouseLeave(this, event)){CRTL_FadeOut(document.getElementById(\'MN_sport\'));}}catch(e){}"><a class="Site" href="http://www.rtl.be/sport">SPORT</a>  \
<li class="separator"> \
<li id="tpeople" class="People" onmouseover="try{if(CRTL_FadeOut != null){document.getElementById(\'MN_people\').style.display=\'block\';}}catch(e){}" onmouseout="try{if(CRTL_OnMouseLeave(this, event)){CRTL_FadeOut(document.getElementById(\'MN_people\'));}}catch(e){}"><a class="Site" href="http://www.rtl.be/people">PEOPLE</a>  \
<li class="separator"> \
<li id="tloisirs" class="Loisirs" onmouseover="try{if(CRTL_FadeOut != null){document.getElementById(\'MN_loisirs\').style.display=\'block\';}}catch(e){}" onmouseout="try{if(CRTL_OnMouseLeave(this, event)){CRTL_FadeOut(document.getElementById(\'MN_loisirs\'));}}catch(e){}"><a class="Site" href="http://www.rtl.be/loisirs">LOISIRS</a>  \
<li class="separator"> \
<li id="tservices" class="Services" onmouseover="try{if(CRTL_FadeOut != null){document.getElementById(\'MN_services\').style.display=\'block\';}}catch(e){}" onmouseout="try{if(CRTL_OnMouseLeave(this, event)){CRTL_FadeOut(document.getElementById(\'MN_services\'));}}catch(e){}"><a class="Site" onclick="return false;" href="http://www.rtl.be/services">SERVICES</a>  \
<div id="MN_services" class="MetanavPopup"> \
<div class="MetanavPopupInner"> \
<div class="MetanavPopupItem"><a href="http://www.rtl.be/meteo"><img alt="La m&eacute;t&eacute;o" src="http://c';
sInnerHTML += 'ommon.rtl.be/moncompte/GED/00000000/2800/2848.jpg" width="160" height="90" alt="La m&eacute;t&eacute;o" title="La m&eacute;t&eacute;o" /></a></div> \
<div class="MetanavPopupItem"><a href="http://www.rtl.be/agenda"><img alt="Agenda" src="http://common.rtl.be/moncompte/GED/00000000/2800/2844.jpg" width="160" height="90" alt="Agenda" title="Agenda" /></a></div> \
<div class="MetanavPopupItem"><a class="MetanavPopupItem" title="Horoscope" href="http://www.rtl.be/horoscope"><img  src="http://common.rtl.be/moncompte/GED/00000000/2800/2846.jpg" width="160" height="90" alt="horoscope_160x90" title="horoscope_160x90" /></a></div> \
<div class="MetanavPopupItem"><a class="MetanavPopupItem" title="RTL Jeux" href="http://www.rtl.be/jeux"><img  src="http://common.rtl.be/GED/00030000/31200/31202.jpg" alt="RTL_Jeux_160x90" title="RTL_Jeux_160x90" /></a></div> \
<div class="MetanavPopupItem"><a class="MetanavPopupItem" title="Ma Commune" href="http://www.rtl.be/macommune"><img  src="http://common.rtl.be/GED/00030000/31000/31065.jpg" alt="macommune_160x90" title="macommune_160x90" /></a></div></div></div> \
<li class="separator"> \
<li class="Vitrines" onmouseover="try{if(CRTL_FadeOut != null){document.getElementById(\'MN_tvradio\').style.display=\'block\';}}catch(e){}" onmouseout="try{if(CRTL_OnMouseLeave(this, event)){CRTL_FadeOut(document.getElementById(\'MN_tvradio\'));}}catch(e){}"><a class="Site" onclick="return false;" href="javascript:">TV &amp; RADIO</a>  \
<div id="MN_tvradio" class="MetanavPopup"> \
<div class="MetanavPopupInner"> \
<div class="MetanavPopupItem"><a href="http://www.rtl.be/rtltvi/"><img alt="RTL TVI" src="http://common.rtl.be/moncompte/GED/00000000/2800/2843.jpg" alt="RTL TVI" title="RTL TVI" /></a></div> \
<div class="MetanavPopupItem"><a href="http://www.rtl.be/clubrtl/"><img alt="Club RTL" src="http://common.rtl.be/moncompte/GED/00000000/2800/2840.jpg" alt="Club RTL" title="Club RTL" /></a></div> \
<div class="MetanavPopupItem"><a href="http://www.rtl.be/plugrtl/"><img alt="Plug RTL" src="http://common.rtl.be/moncompte/GED/00000000/2800/2841.jpg" alt="Plug RTL" title="Plug RTL" /></a></div> \
<div class="MetanavPopupItem"><a href="http://www.rtl.be/belrtl/"><img alt="Bel RTL" src="http://common.rtl.be/moncompte/GED/00000000/2800/2839.jpg" alt="Bel RTL" title="Bel RTL" /></a></div> \
<div class="MetanavPopupItem"><a href="http://www.radiocontact.be/"><img alt="Radio Contact" src="http://common.rtl.be/moncompte/GED/00000000/2800/2842.jpg" width="160" height="90" alt="Radio Contact" title="Radio Contact" /></a></div></div></div> \
<li class="separator"></li></ul></div></div>';

	CRTL_oDiv.innerHTML = sInnerHTML;

	CRTL_CheckSession();

	sLoc = '' + document.location;
	if(sLoc.indexOf('www.rtl.be/info') != -1) document.getElementById('tinfo').className = 'InfoSelected';
	if(sLoc.indexOf('www.rtl.be/sport') != -1) document.getElementById('tsport').className = 'SportSelected';
	if(sLoc.indexOf('www.rtl.be/people') != -1) document.getElementById('tpeople').className = 'PeopleSelected';
	if(sLoc.indexOf('www.rtl.be/loisirs') != -1) document.getElementById('tloisirs').className = 'LoisirsSelected';
	if(sLoc.indexOf('www.rtl.be/services') != -1) document.getElementById('tservices').className = 'ServicesSelected';
	if(sLoc.indexOf('www.rtl.be/meteo') != -1) document.getElementById('tservices').className = 'ServicesSelected';
	if(sLoc.indexOf('www.rtl.be/macommune') != -1) document.getElementById('tservices').className = 'ServicesSelected';
}

CRTL_InitSitesbar();

