Shadowbox.init({
	displayNav : false,
	showOverlay : true,
	overlayColor : "#272727"
});

var ivr = false; //aquesta variable nomes la canviara la pagina de IVR
var sButlletiServiceName = null;//no newsletter selected
function showLogin(divId, frmId, serviceId) {
	// PTF code
	if (nick != null) {
		var lc = '<span id="' + divId + 'Data"></span><input type="button" value="Surt" onclick="prepareForLogout();doLogoutRu(\''
				+ frmId
				+ 'Out\',\''
				+ frmId
				+ 'OutService\')" />'
				+ '<form name="' + frmId + 'Out" id="' + frmId + 'Out" action="' + URL_CAS_SECURE_LOGOUT + '" method="get">'
				+ '<input type="hidden" name="gateway" value="true" />'
				+ '<input type="hidden" id="' + frmId + 'OutService" name="service" value="" /></form>';

		var ctrl = document.getElementById(divId);
		if (ctrl != null) {
			ctrl.innerHTML = lc;
		}
		//afegim control pels documents del programa del Puyal
		var divPuyal = document.getElementById("pdfPuyal");
		if (divPuyal != null) {
			hideElement("iniciSessioPuyal");
			showElement("pdfPuyal");
		}
		//afegim control pels concursos-competicions
		var divConcurs = document.getElementById("envia_item_concurs");
		if (divConcurs != null) {
			hideElement("recordar_contrasenya_concurs");
			showElement("envia_item_concurs");
		}
		
		if (sButlletiServiceName!=null) { 
			doGetUserData(divId+'Data', 'doSubscribeToNewsletter()', null, null, 'IVR'); 
		}else { 
			doGetUserData(divId+'Data', null, null, null, 'IVR');
		}
		if(ivr==true){
			var text = 'Vols entrades per a aquest espectacle? Fes click <a href="javascript:submitViewLogat(\'registreIVR\')">aquí</a>';
			
			var ctrl = document.getElementById("entradesIVR");
			if (ctrl != null) {
				ctrl.innerHTML = text;
			}
			
		}
		
		// catradio code
		doAfterLogin();
	}
}

// ------ START LOGOUT
function doLogoutRu(frmId, serviceId) {
	var frmLogout = document.getElementById(frmId);
	var ctrlService = document.getElementById(serviceId);
	if (ctrlService!=null) {
		ctrlService.value = escape(window.location);
	}
	if (frmLogout!=null) {
		// Refresca página entera
		// frmLogout.action=URL_CAS_SECURE_LOGOUT;
		// frmLogout.submit();
	
		// Refresca solamente divDadesUsuari y  divLogin (via Ajax)
		var ssoIframe = document.getElementById("logoutFrame");
		ssoIframe.src= URL_CAS_SECURE_LOGOUT;
	}
}
// ------ END LOGOUT

// ------ START CLEAN LOGOUT FRAME
function cleanLogoutIFrame() {
	var logoutFrame = document.getElementById("logoutFrame");
	if(logoutFrame.src==URL_CAS_SECURE_LOGOUT) {
		var ifrId = document.getElementById("ifrId");

		doValidate('divLogin','frmLogin','ctrlServiceLogin','frmPostIframe','ifrId');

		rewriteElement("divDadesUsuari","");

		rewriteElement("divLogin",'<a class="pngFix" href="http://www.catradio.cat/su/ru/common_login.jsp?hiRegServiceIdParam=CR_REG" rel="shadowbox[maqueta];width=696;height=551">Inicia sessió</a>');

		showElement("registerLi");
		
		if(ivr==true){
			rewriteElement("entradesIVR","Vols entrades per a aquest espectacle? Has de ser usuari registrat per poder demanar-les. <a rel=\"shadowbox[maqueta];width=696;height=551\" href=\"/su/ru/common_login.jsp?hiRegServiceIdParam=CR_REG\">Identifica't</a>");
		}
		//afegim control pels concursos
		var divPuyal = document.getElementById("pdfPuyal");
		if (divPuyal!=null){
			showElement("iniciSessioPuyal");
			hideElement("pdfPuyal");
		}
		//afegim control pels concursos-competicions
		var divConcurs = document.getElementById("envia_item_concurs");
		if (divConcurs != null) {
			hideElement("envia_item_concurs");
			showElement("recordar_contrasenya_concurs");
		}
		
		logoutFrame.src="";
		
		resetShadowbox();
	}
}
// ------ END CLEAN LOGOUT FRAME

function resetShadowbox() {
	Shadowbox.clearCache(); 
	Shadowbox.setup();
}

function doAfterLogin() {
	hideElement("registerLi");
}

function prepareForLogout() {
	rewriteElement("divDadesUsuari", "Desconnectant ...");
	rewriteElement("divLoginData","");
}
	
function showElement( elementId ) {
	document.getElementById(elementId).style.display="block";
}

function hideElement( elementId ) {
	document.getElementById(elementId).style.display="none";
}

function rewriteElement( elementId, newContent ) {
	document.getElementById(elementId).innerHTML = newContent;
}
