/* Configuraciones */
var toolTipTextDivId 		= "toolTipText"; 	//ID del div que hará de TTT
var floatieId				= "floatie";		//ID del div que hará de Floatie
var countdownId				= "countdowncontainer";		//ID del div que hará de Countdown


/* Codigo de las funciones de Ragnajag, no es necesario modificar */
function ajaxLoad(layerId, url, params)
{
	$(layerId).innerHTML = "Cargando...";
	
	new Ajax.Request
	(
		url,
		{
			method: 'get',
			parameters: params,
			onComplete: function(transport) 
			{
				var response = transport.responseText || "no hay respuesta";
				$(layer_id).innerHTML = response;
			},
			onFailure: function() 
			{ 
				alert('Error: no se ha podido encontrar la pagina `' + url + '´ requerida...') 
			}
		}
	);
}

function ietruebody() 
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


/* Gestion de Cookies*/
function getCookie(name)
{
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

function setCookie(name, value, expires, path, domain, secure) 
{
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

function delCookie (name,path,domain) 
{
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}



/***********************************************
* Link Floatie script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
var fadespeed = 5;
var baseopacity = 0;
function slowhigh(which2)
{
	imgobj = which2;
	browserdetect = which2.filters ? "ie" : typeof which2.style.MozOpacity=="string"? "mozilla" : "";
	instantset(baseopacity);
	highlighting = setInterval("gradualfade(imgobj)", fadespeed);
}

function instantset(degree){
	cleartimer()
	if (browserdetect=="mozilla")
		imgobj.style.MozOpacity=degree/100
	else if (browserdetect=="ie")
		imgobj.filters.alpha.opacity=degree
}

function cleartimer(){
	if (window.highlighting) clearInterval(highlighting)
}

function gradualfade(cur2){
	if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
		cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
	else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
		cur2.filters.alpha.opacity+=10
	else if (window.highlighting)
		clearInterval(highlighting)
}

function paramexists(what){
	return(typeof what!="undefined" && what!="")
}


function showfloatie(thetext, e, optbgColor, optWidth, optHeight){
	var dsocx=(window.pageXOffset)? pageXOffset: ietruebody().scrollLeft;
	var dsocy=(window.pageYOffset)? pageYOffset : ietruebody().scrollTop;
	var floatobj = $(floatieId);
	
	floatobj.style.left = "-900px";
	floatobj.style.display = "block";
	//floatobj.style.backgroundColor=paramexists(optbgColor)? optbgColor : floatiebgcolor
	//floatobj.style.width=paramexists(optWidth)? optWidth+"px" : floatiewidth
	//floatobj.style.height=paramexists(optHeight)? optHeight+"px" : floatieheight!=""? floatieheight : ""
	
	floatobj.innerHTML = thetext;
	
	var floatWidth=floatobj.offsetWidth>0? floatobj.offsetWidth : floatobj.style.width
	var floatHeight=floatobj.offsetHeight>0? floatobj.offsetHeight : floatobj.style.width
	var winWidth=document.all&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
	var winHeight=document.all&&!window.opera? ietruebody().clientHeight : window.innerHeight
	
	e = window.event? window.event : e
	floatobj.style.left=dsocx+winWidth-floatWidth-5+"px"
	
	//if (e.clientX>winWidth-floatWidth && e.clientY+20>winHeight-floatHeight)
		//floatobj.style.top=dsocy+5+"px"
	//else
	floatobj.style.top=dsocy+winHeight-floatHeight-5+"px"
	slowhigh(floatobj)
}

//Adaptación de Floatie para que vaya por AJAX
var gStamp;
function ajaxfloatie(file, param)
{
	var stamp = +new Date();
	gStamp = stamp;
	new Ajax.Request
	(
	    file,
	    {
	            method: 'get',
	            parameters: param,
	            onComplete: function(xmlHttpRequest, responseHeader)
				{
					if (stamp == gStamp)
					{
						showfloatie(xmlHttpRequest.responseText);
					}
				},
				onFailure: function()
				{
					showfloatie("Error: no se ha podido cargar la vista " + file + ".");
				}
	    }
	);
}

function hidefloatie()
{
	gStamp = 0;
	var floatobj = $(floatieId);
	floatobj.style.display="none";
}


/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
var tipobj=document.all? document.all[toolTipTextDivId] : document.getElementById? document.getElementById(toolTipTextDivId) : ""

function ttt(thetext, thecolor, thewidth)
{
	if (ns6||ie){
		tipobj = document.all? document.all[toolTipTextDivId] : document.getElementById? document.getElementById(toolTipTextDivId) : ""
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}

function positiontip(e){
	if (enabletip){
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
		
		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000
		
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
		else if (curX<leftedge)
			tipobj.style.left="5px"
		else
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetxpoint+"px"
		
		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight)
			tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
		else
			tipobj.style.top=curY+offsetypoint+"px"
		
		tipobj.style.visibility="visible"
	}
}

function httt()
{
	if (ns6||ie)
	{
		enabletip=false
		tipobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}

document.onmousemove = positiontip;

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
		setTimeout("is_fadin=false", timer * speed);
		return timer * speed;
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
		setTimeout("is_fadin=false", timer * speed);
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

/***********************************************
* Dynamic Countdown script- © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function cdtime(targetdate)
{
	container = countdownId;
	document.write("<div id='" + container +"'></div>");
	
	if (!document.getElementById || !document.getElementById(container)) return
	this.container=document.getElementById(container)
	this.currentTime=new Date()
	this.targetdate=new Date(targetdate)
	this.timesup=false
	this.updateTime()
}


cdtime.prototype.updateTime=function(){
var thisobj=this
this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

cdtime.prototype.displaycountdown=function(baseunit, functionref){
this.baseunit=baseunit
this.formatresults=functionref
this.showresults()
}

cdtime.prototype.showresults=function(){
var thisobj=this


var timediff=(this.targetdate-this.currentTime)/1000 //difference btw target date and current date, in seconds
if (timediff<0){ //if time is up
this.timesup=true
this.container.innerHTML=this.formatresults()
return
}
var oneMinute=60 //minute unit in seconds
var oneHour=60*60 //hour unit in seconds
var oneDay=60*60*24 //day unit in seconds
var dayfield=Math.floor(timediff/oneDay)
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
hourfield=dayfield*24+hourfield
dayfield="n/a"
}
else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
minutefield=dayfield*24*60+hourfield*60+minutefield
dayfield=hourfield="n/a"
}
else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
var secondfield=timediff
dayfield=hourfield=minutefield="n/a"
}
this.container.innerHTML=this.formatresults(dayfield, hourfield, minutefield, secondfield)
setTimeout(function(){thisobj.showresults()}, 1000) //update results every second
}


function formatresults()
{
	if (this.timesup == false)//if target date/time not yet met
	{	
		var displaystring="<span class='countdown'>Faltan <b>"+arguments[0]+"</b>d, <b>"+arguments[1]+"</b>h, <b>"+arguments[2]+"</b>m y <b>"+arguments[3]+"</b>s para el evento.</span>"
	}
	else //else if target date/time met
	{ 
		var displaystring = "<span class='countdown'>¡Ha llegado el día del evento!</span>" //Don't display any text
	}
	
	return displaystring
}

function formatresults_inscripciones()
{
	if (this.timesup == false)//if target date/time not yet met
	{	
		var displaystring="<span class='countdown'>Las inscripciones se abren en <b>"+arguments[0]+"</b>d, <b>"+arguments[1]+"</b>h, <b>"+arguments[2]+"</b>m y <b>"+arguments[3]+"</b>s.</span>"
	}
	else //else if target date/time met
	{ 
		var displaystring = "<span class='countdown'>¡Inscripciones Abiertas!</span>" //Don't display any text
	}
	
	return displaystring
}