function popupBlog(blogId, userId, address)
{
  var src = 'votar-' + blogId + '-' + userId + '.html?adresse=' + address + '&popup=1';
  window.open(src,'vote_pop','toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,width=1014,height=90');
}

function popupLogo()
{
  window.open('logopop.php','_blank','toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=1,copyhistory=0,menuBar=0,width=400,height=400');
}

function ppp(total_pages, num_page, url)
{
  if (num_page != '' && num_page >= 1 && num_page <= total_pages)
  {
    document.location.href = url.replace("{N_PAGE}", num_page);
	return true;
  }
  else
  {
	alert('¡No es un número de página correcto!\r\nÉste debe ser un número entre 1 y ' + total_pages + '.');
	return false;
  }
}

function doYourPub(text,domain)
{
  str = '';
  text.shuffle();
  if (text.length > 0)
  {
	for (i = 0; i < text.length; i++)
	{
	  if (i != 0) { str += ' | '; }
      str += '<a href="perfil-' + text[i][2] + '.html" class="global_link-' + ((text[i][4] == '2') ? 'w' : 'm') + '"'+(self!=top?' target="_blank"':'')+'>' + text[i][0] + '</a> : <a href="http://' + text[i][1] + '.' + domain + '/"  target="_blank">' + text[i][3] + '</a>';
	}
  }
  if (str.length > 0) { str += ' | '; }
  str += '<a href="cuenta-publicitaria.html">¡Pon tu mensaje de publicidad haciendo un clic aquí!</a>';
  return '<marquee scrolldelay="30" scrollamount="3" truespeed="1" onmouseover="this.stop();" onmouseout="this.start();">' + str + '</marquee>';
}

Array.prototype.shuffle = function() {
   var i=this.length, j, t; while(i--) {
     j = Math.floor( ( i + 1 ) * Math.random() );
     t = this[i];
     this[i] = this[j];
     this[j] = t;
   }
};

function setActiveStyle(title, type)
{
	for(var i=0; lnk = document.getElementsByTagName("link")[i]; i++)
	{
		if(lnk.getAttribute("rel").indexOf("style") != -1 && lnk.getAttribute("title"))
		{
			if (type == "screen")
			{
				if (lnk.getAttribute("title") == "large")
				{
					if (lnk.getAttribute("title") != title)
					{
						lnk.disabled = true;
					}
					else
					{
						/* Fix IE */
						lnk.disabled = true;
						lnk.disabled = false;
					}
				}
			}
			else if (type == "menu")
			{
				if (lnk.getAttribute("title") == "right")
				{
					if (lnk.getAttribute("title") != title)
					{
						lnk.disabled = true;
					}
					else
					{
						/* Fix IE */
						lnk.disabled = true;
						lnk.disabled = false;
					}
				}
			}
		}
	}
}

function getActiveStyle(type)
{
	for(var i=0; lnk = document.getElementsByTagName("link")[i]; i++)
	{
		if(lnk.getAttribute("rel").indexOf("style") != -1 && !lnk.disabled && lnk.getAttribute("title"))
		{
			if (type == "screen")
			{
				if (lnk.getAttribute("title") != "right")
				{
					return lnk.getAttribute("title");
					break;
				}
			}
			else if (type == "menu")
			{
				if (lnk.getAttribute("title") != "large")
				{
					return lnk.getAttribute("title");
					break;
				}
			}
		}
	}
	return null;
}

function toggleLayout()
{
	var style = "";
	var srcLiquid = "images/large.gif";
	var srcFixed = "images/fixed.gif";
	if(getActiveStyle("screen") == "large")
	{
		var globalBody = document.getElementById("global_body");
		if(globalBody)
		{
			globalBody.style.paddingLeft="0px";
			globalBody.style.paddingRight="0px";
		}
		document.switcher.src = srcLiquid;
		document.switcher.title = imgScreen.liquidTitle;
	}
	else
	{
		style = "large";
		document.switcher.src = srcFixed;
		document.switcher.title = imgScreen.fixedTitle;
	}
	setActiveStyle(style, "screen");
}

function toggleMenu()
{
	var style = "";
	var srcRight = "images/right.gif";
	var srcLeft = "images/left.gif";
	if(getActiveStyle("menu") == "right")
	{
		document.positionMenu.src = srcRight;
		document.positionMenu.title = imgMenu.rightTitle;
	}
	else
	{
		style = "right";
		document.positionMenu.src = srcLeft;
		document.positionMenu.title = imgMenu.leftTitle;
	}
	setActiveStyle(style, "menu");
	if (getActiveStyle("screen") == "large")
	{
		setBodyPadding();
	}
}

function getCookie(name)
{
	name += "=";
	var cookies = document.cookie.split(";");
	for(var i=0; i<cookies.length; i++)
	{
		var start = (cookies[i].charAt(0) == " ")? 1:0;
		var c = cookies[i].substr(start);
		if(!c.indexOf(name))
		{
			return unescape(c.substr(name.length));
			break;
		}
	}
	return null;
}

function setCookie(name, value, days)
{
	if(!days) days = 365;
	var oToday = new Date();
	oToday.setTime(oToday.getTime() + (days * 24 * 60 * 60 * 1000));
	document.cookie = name + "=" + escape(value) + "; expires=" + oToday.toGMTString() + "; path=/";
}


window.onunload = function()
{
	if (window.top == window.self)
	{
		setCookie("cookie_screen", getActiveStyle("screen"));
		setCookie("cookie_menu", getActiveStyle("menu"));
	}
}

setActiveStyle(getCookie("cookie_screen"), "screen");
setActiveStyle(getCookie("cookie_menu"), "menu");

getViewportScrollY = function()
{
	var scrollY = 0;
	var bodyheight=0;
	if(document.documentElement && document.documentElement.scrollTop)
	{
		scrollY = document.documentElement.scrollTop;
		bodyheight=document.documentElement.scrollHeight;
	}
	else if(document.body && document.body.scrollTop)
	{
		scrollY = document.body.scrollTop;
		bodyheight=document.body.scrollHeight;
	}
	else if(window.pageYOffset)
	{
		scrollY = window.pageYOffset;
	}
	else if(window.scrollY) {
		scrollY = window.scrollY;
	}
	if(bodyheight>0 && scrollY>bodyheight-620){
		scrollY = bodyheight-620;
	}
	else if(scrollY>10000){
		scrollY=10000;
	}
	return scrollY;
};

getViewportWidth = function()
{
	var width = 0;
	if(document.documentElement && document.documentElement.clientWidth)
	{
		width = document.documentElement.clientWidth;
	}
	else if(document.body && document.body.clientWidth)
	{
		width = document.body.clientWidth;
	}
	else if(window.innerWidth)
	{
		width = window.innerWidth - 18;
	}
	return width;
};

function skyIsActive(right_margin)
{
	var activeStyle = getActiveStyle("screen");
	if (activeStyle == "large" || (document.body  && document.body.clientWidth-right_margin < 995))
	{
		return false;
	}
	return true;
}

function setBodyPadding()
{
	var globalBody = document.getElementById("global_body");
	if(document.body && globalBody)
	{
		if (document.body.clientWidth < 800)
		{
			globalBody.style.paddingLeft="0px";
			globalBody.style.paddingRight="0px";
		}
		else
		{
			var activeMenu = getActiveStyle("menu");
			if(activeMenu=="right")
			{
				globalBody.style.paddingLeft=parseInt((document.body.clientWidth - 810)/12)+"px";
				globalBody.style.paddingRight="0px";
			}
			else
			{
				globalBody.style.paddingLeft="0px";
				globalBody.style.paddingRight=parseInt((document.body.clientWidth - 810)/12)+"px";
			}
		}
	}
}

function pubOrganized()
{
	var scraper = document.getElementById("global_sky");
	if(scraper){
		var leaderBoard = document.getElementById("global_leaderBoard");
		var scraperTopPosition = 1;
		var scraperLeftOffset = 380;
		var activeStyle = getActiveStyle("screen");
		var skyActive = skyIsActive(0);
		if (activeStyle == "large" && document.body)
		{
			if (document.body.clientWidth < 800)
			{
				setCookie("style", "fixed");
				toggleLayout();
			}
			setBodyPadding();
		}
		if (skyActive == false)
		{
			scraper.style.display = "none";
			scraper.style.visibility = "hidden";
			scraper.style.left = "1px";
			if (typeof(noPub) != "undefined")
			{
				leaderBoard.style.display = "none";
				leaderBoard.style.visibility = "hidden";
			}else{
				leaderBoard.style.display = "";
				leaderBoard.style.visibility = "visible";
			}
		}
		else
		{
			scraperPositionRight = (getViewportWidth() > 850) ? getViewportWidth() / 2 + scraperLeftOffset : 800;
			scraper.style.left = scraperPositionRight + "px";
			scraper.style.display = "";
			scraper.style.visibility = "visible";
		}
    }
	setTimeout('pubOrganized()',250);
}
