function toolbarClick(e){
  if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

function habilitar_login_button(fld1,fld2,btn){

	if(document.getElementById(fld1).value && document.getElementById(fld2).value){
		document.getElementById(btn).disabled = false;
	}else{
		document.getElementById(btn).disabled = true;
	}

}


function addShare(className){

	$$("."+className).each(function(obj){

			html = obj.innerHTML.replace('(','').replace(')','');
			cant = parseInt(html);
			if(cant)
				cant++;
			else
				cant = 1;

			obj.innerHTML = '('+cant+')';

		});
}


function toggle_share(id) {
	var shareBox = document.getElementById(id);
	if(shareBox.style.display=='none') {
		shareBox.style.display='';
	} else {
		shareBox.style.display='none'
	}
}
function hide_share(id) {
	var shareBox = document.getElementById(id);
	shareBox.style.display='none'
}




function recomendar(idSocialNetworkKey,idContenido,url,idSocialNetworkShare){

	if(idSocialNetworkKey == 3 || idSocialNetworkKey == 1){

		if(!LOGIN.isValid()){
				LOGIN.modal();
				return;
			}
	}

	if(idSocialNetworkKey == 3){
		url = Base64.encode(location.href);
	}

	query_string = '../_post/ionline/social_content.php?idSocialNetworkKey='+idSocialNetworkKey+'&idContenido='+idContenido+'&url='+url+'&idSocialNetworkShare='+idSocialNetworkShare;
	_post(query_string);

}

function recomendarComentario(idSocialNetworkKey,idContenido,url,idSocialNetworkShare){
  if(!getCookie("recomendar_"+idSocialNetworkKey+"_"+idContenido)){
    if(getCookie("CMSFrontendLogin")){
      document.getElementById('href_recomendar_'+idSocialNetworkKey+'_'+idContenido).innerHTML  = '<strong id="span_href_recomendar_'+idContenido+'" style="font-weight:normal">A processar...</strong>';
      var idContenido = idContenido;
      var funBlink    = null;
      funBlink        = function(){
        var node = document.getElementById('span_href_recomendar_'+idContenido);
        if(node){
          node.style.visibility = (node.style.visibility == "hidden") ? "visible" : "hidden";
          setTimeout(funBlink,500);
        }
      }
      funBlink.call();
      recomendar(idSocialNetworkKey,idContenido,url,idSocialNetworkShare);
    }else{
		  LOGIN.modal();
	  }
  }
}


function vista_video(idAdjunto){

  var idAdjunto = idAdjunto;

  var query_string = "../_post/ionline/enviar_nota.php?idCMSPortal=102&idCMSModulo=11&idAdjunto="+idAdjunto;

  _post(query_string);
 }

function validarIsLoggedIn() {
	var CMSFrontendLogin = getCookie("CMSFrontendLogin");
	if (!CMSFrontendLogin) {
		window.alert("Debe estar logueado para poder realizar la acción solicitada.");
		return false;
	}
	return true;
}

function isLogged() {
	var CMSFrontendLogin = getCookie("CMSFrontendLogin");
	if (!CMSFrontendLogin){ return false;	}
	return true;
}

var request = new Object() ;
var aParams = document.location.search.substr(1).split('&') ;
for ( i = 0 ; i < aParams.length ; i++ )
{
	var aParam = aParams[i].split('=') ;
  var sParamName  = aParam[0] ;
  var sParamValue = aParam[1] ;
	request[ sParamName ] = sParamValue ;
}


function IrAPagina(pagina)
{
	var url  = "?pagina="+pagina;
	for( var i in request ){
		//alert(typeof(request));
		if( i != 'pagina' )	{
			url += "&" + i +"=" + request[i];
		}
	}
	window.location = url;
}


function enviar_contenido(id)
{
    var frm      = document.getElementById(id);
    var strError = false;

    frm.nombre.value = frm.nombre.value.trim();
    if(!strError && frm.nombre.value.length<= 1){
      strError = "Erro, digite seu nome.\n";
      frm.nombre.focus();
    }

    frm.email.value = frm.email.value.trim();
    if(!strError && !frm.email.value.length){
      strError = "Erro, digite um e-mail.";
      frm.email.focus();
    }else if(!strError && !isValidEmail(frm.email.value)){
      strError = "Erro, por favor introduza um email válido.\n";
      frm.email.focus();
    }

    if(strError){
      alert(strError);
    }else{
    	var query_string = "../_post/ionline/enviar_nota.php?";
			for(i = 0 ; i < frm.length ; i++ ){
			  query_string += frm.elements[i].name+"="+frm.elements[i].value+"&";
			}
			_post(query_string);
    }
}

function suscribe(frm)
{
	var frm      = document.getElementById(frm);
	var strError = false;

	frm.email.value = frm.email.value.trim();
	if(!strError && frm.email.value.length<= 3){
		strError = "Erro, digite um e-mail.\n";
		frm.email.focus();
	}

	if(!strError && !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frm.email.value))) {
		strError = "Erro, por favor introduza um email válido.\n";
		frm.email.focus();
	}

	if(strError){
		alert(strError);
	}else{
		var query_string = "../_post/ionline/suscribir_newsletter.php?";
		for(i = 0 ; i < frm.length ; i++ ){
			query_string += frm.elements[i].name+"="+frm.elements[i].value+"&";
		}
		_post(query_string);
	}

	return false;
}

function recomendar_comentario(idCMSModulo,idContenido){

	var frm = document.getElementById('frmRanquearNota');
	var query_string = '../_post/ionline/recomendar.php?';
	var strError = false;

	query_string += 'idCMSModulo='+idCMSModulo+'&';
	query_string += 'idContenido='+idContenido+'&';

	if(consultarGalleta('recomendar_'+idCMSModulo+'_'+idContenido) || consultarGalleta('recomendar_'+idCMSModulo+'_'+idContenido+'_sum')){
		PopUpAlert("Você já recomendou este comentário.");
		strError = true;
	}

	if(!strError)	_post(query_string);
}


function calificar_nota(idCMSModulo,idContenido,votos,set){

	var frm 			= document.getElementById('frmRanquearNota');
	var query_string 	= '../_post/ionline/calificar.php?';
	var strError 		= false;
	var cantVotosTop	= document.getElementById('cantidadVotosViewTop');
	var cantVotosBottom	= document.getElementById('cantidadVotosViewBottom');
	var cantVotos 		= document.getElementById('cantidadVotosHidden');

	frm.idCMSModulo.value 	= idCMSModulo;
	frm.idContenido.value 	= idContenido;
	frm.votos.value 		= votos;

	if(consultarGalleta('votar_'+idCMSModulo+'_'+idContenido) || consultarGalleta('votar_'+idCMSModulo+'_'+idContenido+'_sum')){
		PopUpAlert("Você já avaliou esta nota.");
		strError = true;
	}

	if(!strError){
		if(cantVotosTop){
			cantVotosTop.innerHTML 		= (parseInt(cantVotos.value)+1);
		}

		if(cantVotosBottom){
			cantVotosBottom.innerHTML 	= (parseInt(cantVotos.value)+1);
		}

		for(i = 0 ; i < frm.length ; i++ ){
		  	query_string += frm.elements[i].name+"="+frm.elements[i].value+"&";
		}

		swapImage(idCMSModulo,idContenido,votos,set);

		for(i=1;i<=5;i++){
			obj = document.getElementById(set+'_'+idCMSModulo+'_'+idContenido+'_'+i);
			obj.style.cursor = 'default';
			obj.onclick = null;
			obj.onmouseover  = null;
			obj.onmouseout = null;

		}

		_post(query_string);

	}

}
function swapImage(idModulo,idContenido,obj,set) {

	var img = "../../_modulos/notas/_imgs/ionline/star",
		estado = new Array("2", "3"),
		ext = ".gif";

    for (var i = 1; i <= obj; ++i)
		document.getElementById(set+"_" + idModulo +'_'+ idContenido + '_' + i).src = img + estado[1] + ext;
}

function swapImageDark(idModulo,idContenido,obj,set) {

	var img = "../../_modulos/notas/_imgs/ionline/star",
		estado = new Array("2", "3"),
		ext = ".gif";

    for (var i = 1; i <= obj; ++i)
		document.getElementById(set+"_" + idModulo +'_'+ idContenido + '_' + i).src = img + estado[1] +"-d"+  ext;
}

function starVotar(puntaje) {
	var frm = document.getElementById("frmPrincipal");
	frm.votar.value = puntaje;
	frm.submit();
}

function swapOut(idModulo,idContenido,set) {

	var img = "../../_modulos/notas/_imgs/ionline/star",
		estado = new Array("2", "3"),
		ext = ".gif";

	for (var i = 1; i <= 5; ++i)
		document.getElementById(set+"_" + idModulo +'_'+ idContenido + '_' + i).src = img + estado[0] + ext;
}

function swapOutDark(idModulo,idContenido,set) {

	var img = "../../_modulos/notas/_imgs/ionline/star",
		estado = new Array("2", "3"),
		ext = ".gif";

	for (var i = 1; i <= 5; ++i)
		document.getElementById(set+"_" + idModulo +'_'+ idContenido + '_' + i).src = img + estado[0] +"-d"+ ext;
}

function checkCaracteres( inputElement, cantidad, span_id ) {

	if( inputElement.value.length > cantidad ) {
		inputElement.value = inputElement.value.substr(0, cantidad);
	}

	document.getElementById(span_id).innerHTML = 1200 - inputElement.value.length;
}

function switchLogin(){

	// header-obj-col3 : caja con buscador y link a login
	// login-header-obj-col3 : caja de login
	// loged-header-obj-col3 : caja de logueado
	// CMSLoginBoxUser	: nombre del usuario
  if(typeof(socialTopBar) != "undefined" && $("linkShowSocialTopBar") ){
    $("linkShowSocialTopBar").style.display        = socialTopBar.visibleTopBar ? "none" : "inline";
    $("linkShowSocialTopBarNoLogin").style.display = socialTopBar.visibleTopBar ? "none" : "block";
  }
	var CMSLoginBox = document.getElementById("header-obj-col3"),
		CMSLoginBoxUser = document.getElementById("CMSLoginBoxUser"),
		CMSLogoutBox = document.getElementById("loged-header-obj-col3")

	if (CMSLoginBox && CMSLoginBoxUser && CMSLogoutBox) {

		var CMSFrontendLogin = getCookie("CMSFrontendLogin");

		if (CMSFrontendLogin) {
			var userData = CMSFrontendLogin.split("|");
			CMSLoginBoxUser.innerHTML = userData[0];

			// seteo el avatar
			var CMSFrontendLoginAvatar = getCookie("CMSFrontendLoginAvatar");
			if(CMSFrontendLoginAvatar){

				if(document.getElementById('CMSFrontendLoginAvatar')){

					document.getElementById('CMSFrontendLoginAvatar').src = CMSFrontendLoginAvatar;

				}

			}

			CMSLoginBox.style.display = "none";
			CMSLogoutBox.style.display = "";


		}
		else {
			CMSLoginBoxUser.innerHTML = "";
			CMSLoginBox.style.display = "";
			CMSLogoutBox.style.display = "none";
		}
	}
}

function getCookieData(intKey) {

	var CMSFrontendLogin = getCookie("CMSFrontendLogin");
	if (CMSFrontendLogin) {
		var userData = CMSFrontendLogin.split("|");
		return userData[intKey];
	}
	return "";
}

function getCookie(nombre)
{
	var buscamos = nombre + "=";
	try{
		if (document.cookie.length > 0) {
			var i = document.cookie.indexOf(buscamos);
			if (i != -1)
			{
				i += buscamos.length;
				var j = document.cookie.indexOf(";", i);
				if (j == -1){
				  j = document.cookie.length;
				}
  	  return unescape(document.cookie.substring(i,j));
  	  }
  	}
	}catch(e){};
}
function goLinkIfLogged (link) {
	var CMSFrontendLogin = getCookie("CMSFrontendLogin");

	if(CMSFrontendLogin) {
		window.location = link;
	} else {
		window.location = '../'+window.SEO_PAGINAS+'/login.html?redirect=../'+link;
	}
	return "";

}
function clear_this(obj,val){
	if(obj.value == val) obj.value = '';
	return;
}

function fill_this(obj,val){
	if(obj.value == '') obj.value = val;
	return;
}

function popup(p){

	switch(p){
		case 'contacto':
			PopUpLogin('../'+window.SEO_PAGINAS+'/contacto.html',p);
			break;
	}
}


function PopUpAlert(text)
{
	if(document.getElementById('popup_iframe')) { return false; }
	if(!isBackend())
	{
		block();

		var src = '../interior/index.php?p=popup_custom';

		src += '&text='+text;

		var strFrame = (isMSIE()) ? "<iframe id='popup_iframe' name='alert_iframe' frameborder='0' allowtransparency='true' scrolling='no'>" : "iframe";
		var objPopup = null;

		objPopup = document.createElement(strFrame);
		objPopup.setAttribute("id"		,	"popup_iframe");
		objPopup.setAttribute("name"	,	"alert_iframe");
		objPopup.setAttribute("frameborder", "0");
		objPopup.setAttribute("scrolling", "no");

		objPopup.name 	= "alert_iframe";
		objPopup.src	= src;
		objPopup.style.position	= 'absolute';

		var width		= f_clientWidth();
		var height		= f_clientHeight() + f_scrollTop();

		var top 		= '0';
		var left 		= '0';

		objPopup.style.width	= width+'px';
		objPopup.style.height	= height+'px';
		objPopup.style.top 		= top+'px';
		objPopup.style.left 	= left+'px';

		document.documentElement.style.overflow = 'hidden';
		document.body.appendChild(objPopup);
	}
	else
	{
		window.location = src;
	}
}

function PopUp(src,iframe_name)
{

	if(!isBackend())
	{
		block();

		var strFrame = (isMSIE()) ? "<iframe id='popup_iframe' name='"+iframe_name+"' frameborder='0' allowtransparency='true' scrolling='no'>" : "iframe";

		var objPopup = null;

		objPopup = document.createElement(strFrame);
		objPopup.setAttribute("id"	,	"popup_iframe");
		objPopup.setAttribute("name"	,	iframe_name);
		objPopup.setAttribute("frameborder", "0");
		objPopup.setAttribute("scrolling", "yes");

		objPopup.name = iframe_name;
		objPopup.src	= src;
		objPopup.style.position	= 'absolute';

		var width	= f_clientWidth();
		var height	= f_clientHeight() + f_scrollTop();

		var top 		= '0';
		var left 		= '0';

		objPopup.style.width	= width+'px';
		objPopup.style.height	= height+'px';
		objPopup.style.top 		= top+'px';
		objPopup.style.left 	= left+'px';

		document.documentElement.style.overflow = 'hidden';
		document.body.appendChild(objPopup);
	}
	else
	{
		window.location = src;
	}
}


function block()
{
	window.onmousewheel = document.onmousewheel = wheel;
	document.documentElement.style.overflow = 'hidden';

	var objBlock = null;
	if( objBlock == null )
	{

		var width		= f_clientWidth();
		var height		= f_clientHeight() + f_scrollTop();
		var top 		= 0;
		var left 		= 0;

		var strFrame = (isMSIE()) ? "<iframe id='block_iframe' name='block_iframe' frameborder='0' allowtransparency='true' scrolling='no'>" : "iframe";

		objBlock = document.createElement(strFrame);

		objBlock.src				= '../interior/block.html';
		objBlock.style.position 	= 'absolute';

		objBlock.setAttribute("id"	,	"block_iframe");
		objBlock.setAttribute("name"	,	"block_iframe");
		objBlock.setAttribute("frameborder"	,	"0");
		objBlock.setAttribute("scrolling"		,	"no");
		objBlock.name = 'block_iframe';
		objBlock.style.width	= width+'px';
		objBlock.style.height	= height+'px';
		objBlock.style.top 	= top+'px';
		objBlock.style.left = left+'px';

		if(isMSIE()){
			objBlock.style.filter = 'alpha(opacity=80)';
		}else{
			objBlock.style.opacity = 0.8;
		}

		document.body.appendChild(objBlock);

	}
}




function soyPopup(obj){

	if(isBackend()) return false;

	obj.body.style.height = '100%';

	var div_height 		= 0;
	var div_width 		= 0;
	var div_offsetY 	= f_scrollTopParent();
	var clientHeight 	= f_clientHeight() - div_offsetY;
	var clientWidth  	= f_clientWidth();

	// Busco la altura del div exterior
	for(i=0;i<obj.body.childNodes.length;i++)
	{
		if(obj.body.childNodes[i].tagName == 'DIV' && obj.body.childNodes[i].id != 'FB_HiddenContainer'){
			div = obj.body.childNodes[i];

			div_height = div.offsetHeight;
			div_width = div.offsetWidth;
			break;
		}
	}


	if(div_height > clientHeight){

		div_height = clientHeight - 100;

		div.style.height = div_height+'px';
		div.style.width	 = parseInt(div.offsetWidth + 20)+'px';
		div.style.overflow = 'auto';
	}

	if( window.frameElement )
	{
		var top 	 = div_offsetY + ((clientHeight - div_height - 40)/2);
		var left 	 = (clientWidth - div_width)/2;
		var height = clientHeight; // - vtop;

		div.style.position = 'absolute';
		div.style.top  = top+'px';
		div.style.left  = left+'px';
		//div.style.top  = vtop+'px';
	}





}

function unblock()
{
	objBlock = window.parent.objBlock;

	if( objBlock != null ){
		window.parent.document.documentElement.style.overflow = 'auto';
		objBlock.parentNode.removeChild(objBlock);
		delete(objBlock);
		objBlock = null;
	}
}

function closePopUp() {

	if(!isBackend()) {

		parent.document.documentElement.style.overflow = 'auto';

		var objBlock = parent.document.getElementById('block_iframe');
		var objPopup = parent.document.getElementById('popup_iframe');

		objBlock.parentNode.removeChild(objBlock);
		objPopup.parentNode.removeChild(objPopup);

	}
	else
	{
		history.back();
	}

}

function close(){
	parent.window.closePopUp();
}

function isMSIE(){
	return (navigator.appName == "Microsoft Internet Explorer");
}

function f_clientWidth() {

	return document.documentElement.clientWidth;

}
function f_clientHeight() {

	return document.documentElement.clientHeight;

}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_scrollTopParent() {
	return f_filterResults (
		window.parent.window.pageYOffset ? window.parent.window.pageYOffset : 0,
		window.parent.document.documentElement ? window.parent.document.documentElement.scrollTop : 0,
		window.parent.document.body ? window.parent.document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function wheel(event){
	//if (event.preventDefault) event.preventDefault();
	//event.returnValue = false;
	return true;
	}


tamanio0=14; 	// cuerpo
tamanio1=16;	// copete

tamanioL0=20;
tamanioL1=20;

function setTamFuente(nodo,tamanio,tamanioL)
{
	// nodo actual
	if(nodo && nodo.style)
	{ nodo.style.fontSize = tamanio+'px'; nodo.style.lineHeight = tamanioL+'px'; }

	// tiene hijos?
	if(nodo.childNodes.length)
	{
		nodo = nodo.firstChild;

		// primer hijo
		if(nodo.style) { nodo.style.fontSize = tamanio+'px'; nodo.style.lineHeight = tamanioL+'px'; }
		setTamFuente(nodo,tamanio,tamanioL);

		// resto de los hijos
		while(nodo = nodo.nextSibling)
		{
			if(nodo.style) { nodo.style.fontSize = tamanio+'px'; nodo.style.lineHeight = tamanioL+'px'; }
			setTamFuente(nodo,tamanio,tamanioL);
		}
	}
}

function tamFuente(operacion)
{

  if (operacion == 0)
  {
    if (tamanio0 > 8) { tamanio0--; tamanioL0--; }
    if (tamanio1 > 8) { tamanio1--; tamanioL1--; }

  }
  else if(operacion == 1)
  {
    if (tamanio0 < 30) { tamanio0++; tamanioL0++; }
    if (tamanio1 < 30) { tamanio1++; tamanioL1++; }
  }
  else if(operacion == 2)
  {
  		tamanio0=14;
		tamanio1=16;

		tamanioL0=20;
		tamanioL1=20;
  }

	setTamFuente(document.getElementById('news-detail-obj-copete'),tamanio1,tamanioL1);
	setTamFuente(document.getElementById('news-detail-obj-cuerpo'),tamanio0,tamanioL0);

}

function isBackend(){

	if(typeof(window.parent.document.body) != 'undefined' && window.parent.document.body.id == 'mainBody'){
		//alert('back');
		return true;
	}
	else
	{
		//alert('front');
		return false;
	}

}


function isValidEmail(mail){
  if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail))){
  	return false;
  } else {
    return true;
  }
}

function trim(valor) {
	var re = /^\s+|\s+$/;
	var str = (valor? valor: this);
	return str.replace(re, "");
}
String.prototype.trim = trim;

function _post(url)
{
	var _objPost = document.createElement("iframe");
			_objPost.style.display 	= "none";
			_objPost.style.width   	= "100%";
			_objPost.style.height  	= "200";
			_objPost.src 						= url;
	document.body.appendChild(_objPost);
}

function _formPost(frm,url)
{

	var _objPost = document.createElement("iframe");
			_objPost.style.display 	= "none";
			_objPost.name 			= "targetIframe";
			_objPost.style.width   	= "100%";
			_objPost.style.height  	= "300";
			_objPost.src 			= "";
	document.body.appendChild(_objPost);

	if(frm){

		frm.target = "targetIframe";
		frm.method = "POST";
		frm.action = url;
		frm.submit();

		}
}

function consultarGalleta(nombre){

	var buscamos = nombre + "=";
	if (document.cookie.length > 0){
		i = document.cookie.indexOf(buscamos);
		if (i != -1) {
			i += buscamos.length;
			j = document.cookie.indexOf(";", i);
			if (j == -1)
				j = document.cookie.length;
			return unescape(document.cookie.substring(i,j));
		}
	}
}

function $()
{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++)
	{
		var element = arguments[i];
	  if (typeof element == 'string') element = document.getElementById(element);
	  if (arguments.length == 1) return element;
	  elements.push(element);
	}
	return elements;
}

function show(id){ if($(id)) $(id).style.display = 'block'; }
function hide(id){ if($(id)) $(id).style.display = 'none'; }

function toggle(id){

  if($(id).style.display == 'none')
		$(id).style.display = 'block';
	else
		$(id).style.display = 'none';
}

function submit(id){
	alert('hola: '+id);
	$(id).submit();
}
function setValue(id,val){ $(id).value = val; }

function getCookie(name)
{
  var dc 			= document.cookie;
  var prefix 	= name + "=";
  var begin 	= dc.indexOf("; " + prefix);
  var end = -1;

  if (begin == -1)
  {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
    end = dc.indexOf(';');
  }
  else
  {
  	begin += 2;
  	var end = document.cookie.indexOf(";", begin);
  	if (end == -1)
  	{
    	end = dc.length;
    }
  }
  return unescape(dc.substring(begin + prefix.length, end));
}

function runSWF(archivo, ancho, alto, version, bgcolor, idIe, idMz, menu, FlashVars, quality, allowScriptAccess, writeScript, wmode) {
	var version_data = (version? version: "6,0,0,0");
	var menu_data    = (menu?    menu:    false);
	var bgcolor_data = (bgcolor? bgcolor: "#FFFFFF");
	var idIe_data    = (idIe?    idIe:    "flashMovIe");
	var idMz_data    = (idMz?    idMz:    "flashMovMz");
	var quality_data = (quality? quality: "high");
	var allowScriptAccess_data = (allowScriptAccess? allowScriptAccess: "always");
	var agt                    = navigator.userAgent.toLowerCase();
	var is_safari              = ((agt.indexOf('safari')!=-1))?true:false;

	if (typeof(writeScript) == "undefined" || writeScript == "") {
		writeScript = "1";
	}
	if (typeof(wmode) == "undefined") {
		wmode = "transparent";
	}

	quality_data = "high"; // Calidad de visualización del Flash

	var html = "";
	var agt=navigator.userAgent.toLowerCase();
	if((navigator.appName == "Microsoft Internet Explorer") ||
	((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1)))
	{
	html += '<object id="'+idIe_data+'" width="'+ancho+'" height="'+alto+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version_data+'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">\n';
	html += '<param name="movie" value="'+archivo+'">\n';
	html += '<param name="quality" value="'+quality_data+'">\n';
	html += '<param name="FlashVars" value="'+FlashVars+'">\n';
	html += '<param name="bgcolor" value="'+bgcolor_data+'">\n';
	html += '<param name="menu" value="'+menu_data+'">\n';
	html += '<param name="wmode" value="'+wmode+'">\n';
	html += '<param name="allowScriptAccess" value="'+allowScriptAccess_data+'">\n';
	html += '<param name="allowFullScreen" value="true">\n';
	html += '</object>\n';
	} else {
	html += '<embed src="'+archivo+'" id="'+idMz_data+'" name="'+idMz_data+'" width="'+ancho+'" height="'+alto+'" quality="'+quality_data+'" wmode="'+wmode+'" bgcolor="'+bgcolor_data+'" FlashVars="'+FlashVars+'" menu="'+menu_data+'" allowScriptAccess="'+allowScriptAccess_data+'" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swLiveConnect="true"></embed>';
	}
	if (typeof(document.readyState) == "undefined" || document.readyState == "interactive" || is_safari) {
		if (writeScript == "1") {
			document.write(html);
		}
		else {
			return html;
		}
	}
}

function _attachEvent( element, name, observer)
{
	if( element.addEventListener )
	{
		name = name.replace("on","");
		element.addEventListener( name, observer, true );
  }
  else if ( element.attachEvent )
	{
  	element.attachEvent( name, observer );
  }
}

function clearOnSocialLogin(){
  window.onSocialLogin = null;
}

function closeExternalLogin(win){
  if( typeof(window.onSocialLogin) == "function" ){
    window.onSocialLogin.call();
    clearOnSocialLogin();
  }else{
    window.location.reload();
  }
  win.close();
}

var socialTopBar = {
  visibleTopBar   : 0 ,
  contentExpanded : 0 ,
  netExpanded     : 0 ,
  net             : 'user',
  factivate       : null,
  firstLoad       : 0,

  load : function(){
    var CMSFrontendLogin        = getCookie("CMSFrontendLogin");
    var hideSocialTopBar        = getCookie("hideSocialTopBar");
    var socialTopBarLastStatus  = getCookie("socialTopBarLastStatus");
    if(!parseInt(hideSocialTopBar)){
      if(CMSFrontendLogin || (socialTopBarLastStatus == 'nologued' && CMSFrontendLogin)){
        var socialTopBarNet  = getCookie("socialTopBarNet");
        if(socialTopBarNet && socialTopBarNet != this.net ){
          switch(socialTopBarNet){
            case "user" : this.setUserNet(false); break;
            case "site" : this.setIonlineNet(false); break;
          }
        }
        _attachEvent( window, "onload" , socialTopBar.getContentLoad);
      }else{
        this.setIonlineNet(false);
        _attachEvent( window, "onload" , socialTopBar.getContentLoad);
      }
      this.showTopBar();
    }else{
      $("contentSocialTopBarHeight").style.height  = "0px";
      this.setIonlineNet(false);
      _attachEvent( window, "onload" , socialTopBar.getContentLoad);
    }
    document.cookie = "socialTopBarLastStatus="+(CMSFrontendLogin ? 'logued': 'nologued')+";path=/";
  },

  hideTopBar : function(){
    this.visibleTopBar = 0;
    $("contentSocialTopBarBg").style.display     = "none";
    $("socialTopBarSep").style.display           = "none";
    $("socialTopBarSepLine").style.display       = "none";
    $("contentSocialTopBarHeight").style.height  = "10px";
    if($("linkShowSocialTopBar")){
      $("linkShowSocialTopBar").style.display = "inline";
    }
    if($("linkShowSocialTopBarNoLogin")){
      $("linkShowSocialTopBarNoLogin").style.display = "block";
    }

    document.cookie = "hideSocialTopBar=1;path=/";
  },

  showTopBar : function(){
    this.visibleTopBar = 1;
    var CMSFrontendLogin   = getCookie("CMSFrontendLogin");
    var statusSocialTopBar = getCookie("statusSocialTopBar");
    statusSocialTopBar     = statusSocialTopBar || "looked";
    statusSocialTopBar = "unlooked";
    $("contentSocialTopBarHeight").style.height       = "44px";
    $("contentSocialTopBarBg").style.display          = "block";
    $("socialTopBarSep").style.display                = "block";
    $("socialTopBarSepLine").style.display            = "block";

    if(!CMSFrontendLogin || statusSocialTopBar == "unlooked"){
      $("contentSocialTopBar").style.position      = "absolute";
      //$("socialTopBarLookIco").src                 = "../css/images/pin_off.gif";
    }else{
      $("contentSocialTopBar").style.position      = "fixed";
     // $("socialTopBarLookIco").src                 = "../css/images/pin_on.gif";
    }

    if(CMSFrontendLogin){
      $("topbarIcon").style.display                 = "block";
      //$("socialTopBarLookIco").style.visibility     = "visible";
    }else{
      $("topbarIcon").style.display                 = "none";
      //$("socialTopBarLookIco").style.visibility     = "hidden";
    }

    if($("linkShowSocialTopBar")){
      $("linkShowSocialTopBar").style.display = "none";
    }
    if($("linkShowSocialTopBarNoLogin")){
      $("linkShowSocialTopBarNoLogin").style.display = "none";
    }
    document.cookie = "hideSocialTopBar=0;path=/";
  },

  lookTopBar : function(){
    var statusSocialTopBar = getCookie("statusSocialTopBar");
    statusSocialTopBar     = statusSocialTopBar || "looked";
    if(statusSocialTopBar == "looked"){
      //$("socialTopBarLookIco").src = "../css/images/pin_off.gif";
      document.cookie = "statusSocialTopBar=unlooked;path=/";
    }else{
      //$("socialTopBarLookIco").src = "../css/images/pin_on.gif";
      document.cookie = "statusSocialTopBar=looked;path=/";
    }
    this.showTopBar();
  },

  getContentLoad : function(){
    if(!socialTopBar.firstLoad){
      socialTopBar.getContent();
    }
  },

  getContent : function(){
      socialTopBar.firstLoad = 1;
      var myRequest = new Request({
                                   url       : "../_post/ionline/getSocialTopBar.php?template=topbar&net="+this.net,
                                   method    : "POST",
                                   data      : null,
                                   onSuccess : function(responseText, responseXML) {
                                                 if(responseText=='Nok') {
                                                     alert('The operation failed, please try again in a few minutes');
                                                 } else {
                                                  $("socialTopBarPostContent").innerHTML = responseText;
                                                  var scriptstxt = [];
																					  		  var regexp = /<!--script[^>]*>([\s\S]*?)<\/script-->/gi;

																					  		  while (script = regexp.exec(responseText)){

																						  		  eval(script[1]);

																						      }
                                                 }
                                               }
                                  });
      myRequest.send();
  },

  setIonlineNet : function(refreshData){
    var refreshData = typeof(refreshData) != "undefined" ? refreshData : true;
    $("socialTopBarNetDescription").innerHTML = "Actividade em ionline";
    this.net = 'site';

    if(refreshData){
      this.showNets();
      this.setCookieNet();
      this.getContent();
    }
  },

  setUserNet : function(refreshData){
    var refreshData = typeof(refreshData) != "undefined" ? refreshData : true;
    $("socialTopBarNetDescription").innerHTML = "Actividade na minha rede";
    this.net = 'user';

    if(refreshData){
      this.showNets();
      this.setCookieNet();
      this.getContent();
    }
  },

  setCookieNet : function(net){
    document.cookie = "socialTopBarNet="+this.net+";path=/";
  },

  showNets : function(){
    var CMSFrontendLogin = getCookie("CMSFrontendLogin");
    if(CMSFrontendLogin){
      if(this.netExpanded){
        this.netExpanded = 0;
        $("socialTopBarNets").style.display     = "none";
        $("topbarIcon").src                     = "../css/images/topbarIcon.gif";
      }else{
        this.netExpanded = 1;
        $("socialTopBarNets").style.display     = "block";
        $("topbarIcon").src                     = "../css/images/topbarIconUp.gif";
      }
    }
  },

  showPost : function(){
    if(this.contentExpanded){
      this.contentExpanded = 0;
      $("socialTopBarPostContent").style.overflow     = "hidden";
      $("socialTopBarPostContent").style.height       = "34px";
      $("socialTopBarPostContent").style.borderBottom = "0px";
      $("topBarBulletGray").src                       = "../css/images/topBarBulletGray.gif";
    }else{
      this.contentExpanded = 1;
      $("socialTopBarPostContent").style.overflow     = "visible";
      $("socialTopBarPostContent").style.height       = "auto";
      $("socialTopBarPostContent").style.borderBottom = "1px solid #EBEBEB";
      $("topBarBulletGray").src                       = "../css/images/topBarBulletGrayUp.gif";
    }
  },

  activate : function(factivate){
    var CMSFrontendLogin = getCookie("CMSFrontendLogin");
    if(CMSFrontendLogin){
      this.factivate = factivate;
      $("socialTopBarRecomendarBlock").style.display = "none";
      $("socialTopBarRecomendarA").style.color       = "#666666";
    }
  },

  recomendar : function(){
    if(this.factivate != null){
      $("socialTopBarRecomendarA").innerHTML = "Obrigado!";
      this.factivate.call();
      this.factivate = null;
    }
  }

}



var Base64 = {

	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Base64._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		}

		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = Base64._utf8_decode(output);

		return output;

	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}
}

function loadUsersFacebookRelated(){
  _post("../php5/cronjobs/onUserLogin.php");
}

if( getCookie("updateUsersFacebookRelated") ){
 _attachEvent( window, "onload" , loadUsersFacebookRelated);
}