function disableSubmit()
{
	document.getElementById("div5").className = 'mainDivOff';
}

function enableSubmit()
{
	document.getElementById("div5").className = 'mainDivOn';
}

function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 1);
    }
}

function enableBusqueda()
{
	document.getElementById("busqueda").className = 'mainDivOn';
	document.getElementById("busquedaSimple").className = 'mainDivOff';
	document.getElementById("busquedaAvanzada").className = 'mainDivOn';
}

function disableBusqueda()
{
	document.getElementById("busqueda").className = 'mainDivOff';
	document.getElementById("busquedaSimple").className = 'mainDivOn';
	document.getElementById("busquedaAvanzada").className = 'mainDivOff';
}


function popupwindow(url,ancho,alto)
{
        var winl = (screen.width - 750) / 2;
        var wint = ((screen.height - 540) / 2) - 30;

        mywindow = window.open(url, 'Tracker', 'status=no,toolbar=no,location=no,menubar=no,scrollbars=no,resizable=no,width='+ancho+',height='+alto+',top='+wint+',left='+winl);
        mywindow.location = url;
}


function enableButton(field)
{
	document.getElementById("okButton" + field).style.visibility="visible";
}


function clickOk(field) 
{
	try
    {
    	var mierror = document.getElementById('error').value;
        return false;
    }
    catch (mierr)
    {
    }

    try
    {
    	next = field + 1;
        try
        {
        	var i;
            for (i=1;i<6;i++)
            {
            	document.getElementById("paso" + i).className = 'mainDivOff';
            }
            if (next<5)
            {
            	document.getElementById("div" + next).className = 'mainDivOn';
                document.getElementById("paso" + next).className = 'mainDivOn';
                document.getElementById("input" + next).focus();
            }
            else
            {
            	document.getElementById("paso" + next).className = 'mainDivOn';
                enableSubmit();
            }
            
            return true;
        }
        catch (err)
        {
        	return false;
        }
   }
   catch (mierr)
   {
   	return false;
   }
}


function handleKeyPress(event, field)
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	
	if (keyCode == 13) 
	{
		 ValidaCampo(field);
	}
	else
	{
		return true;
	}
}

function textCounter(field, countfield, minlimit,maxlimit,nombre) 
{
	countfield.value = field.value.length;
	
	if (((countfield.value) < minlimit) || ((countfield.value) > maxlimit))
	{
		document.getElementById(nombre+"Error").style.visibility = 'visible';
	}
	else
	{
		document.getElementById(nombre+"Error").style.visibility = 'hidden';
	}
}

function activaEditaCampo(campo)
{
   	var i;
    for (i=1;i<12;i++)
    {
    	try
    	{
	   		document.getElementById("divA" + i).className = 'noactivo';
	   	}
	   	catch (mierror){}
    }
	document.getElementById("divA" + campo).className = 'activo';
	document.getElementById("divA" + campo).blur();
}

function activaJuego(juego)
{
	document.getElementById("jugar").innerHTML = '<embed src='+juego+' width=800 height=600>';
}


function enableAddImagen(nombre)
{
	document.getElementById("rutaImagen").value = nombre;
}

function enableSubmitAddImagen()
{
	document.getElementById("divSubmitAddImagen").className = 'mainDivOn';
	document.getElementById("submitButton").focus();
}


function anadeComentario(id)
{
	document.editJuegoForm.inputNota.value += "\n" + id + ": ";
}


function muestraMapa(latitud,longitud,zoom)
{
	var map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(latitud,longitud), zoom);
	map.addControl(new GSmallZoomControl());
	var punto = new GLatLng(latitud,longitud);
	var marker = new GMarker(punto,{draggable: false});
	map.addOverlay(marker);
}


function dibujaMapa(latitud,longitud,zoom)
{
	var map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(latitud,longitud), zoom);
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	var punto = new GLatLng(latitud,longitud);
	var marker = new GMarker(punto,{draggable: true});
	map.addOverlay(marker);
}


function confirmaEliminaComentario(comentario)
{
	document.getElementById("borrarA"+comentario).className = 'mainDivOff';
	document.getElementById("borrarB"+comentario).className = 'mainDivOn';
}

function cancelaEliminaComentario(comentario)
{
	document.getElementById("borrarB"+comentario).className = 'mainDivOff';
	document.getElementById("borrarA"+comentario).className = 'mainDivOn';

}

function disableText(id)
{
	document.getElementById("textoB"+id).innerHTML = '';
	document.getElementById("textoC"+id).className = 'mainDivOn';
}

function jumpToGame() {
   window.location = String(window.location).replace(/\#.*$/, "") + "#play";
}


function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function preloadJuego() 
{
	var flashMovie=getFlashMovieObject("juegoYupis");
	if (flashMovie.PercentLoaded() == 100)
	{
		window.clearInterval(miPreload);
		document.getElementById("yupisGame").style.visibility = 'visible';
		document.getElementById("preloadJuego").style.display = 'none';
	}
	else
	{
		progBar(3*flashMovie.PercentLoaded());
	}
}

function progBar(i)
{
   if (i<=(300))
   {
	  if (i>40)
	  {
	  	document.getElementById("porcentaje").innerHTML=parseInt(i/3)+"%";
	  }
      document.getElementById("barra").style.width=i+"px";
   }
}


function popupwindow(url,ancho,alto)
{
        var winl = (screen.width - 750) / 2;
        var wint = ((screen.height - 540) / 2) - 30;

        mywindow = window.open(url, 'Tracker', 'status=no,toolbar=no,location=no,menubar=no,scrollbars=no,resizable=yes,width='+ancho+',height='+alto+',top='+wint+',left='+winl);
        mywindow.location = url;
}

function ProbarJuego(url)
{
		if (document.getElementById('inputAlto').value>600)
		{
			if (confirm("El juego tiene un ALTO mayor de 600px, estas seguro ?"))
			{
				popupwindow(url,document.getElementById('inputAncho').value,document.getElementById('inputAlto').value);
			}
		}
		else
		{
				popupwindow(url,document.getElementById('inputAncho').value,document.getElementById('inputAlto').value);
		}
}

function ucfirst( str ) {
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1, str.length-1);
}
function remplazaAlternativo(id,texto)
{
	var mitext = texto.replace(/@@@/,document.getElementById('inputTag'+id).value);
	document.getElementById('inputAlternativo'+id).value=ucfirst(mitext);
}


/*********
* Javascript for file upload demo
* Copyright (C) Tomas Larsson 2006
* http://tomas.epineer.se/

* Licence:
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
* 
* Software distributed under this License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*/
function PeriodicalAjax(url, parameters, frequency, decay, onSuccess, onFailure) {
	function createRequestObject() {
		var xhr;
		try {
			xhr = new XMLHttpRequest();
		}
		catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		return xhr;
	}
	
	function send() {
		if(!stopped) {
			xhr.open('post', url, true);
			xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			xhr.onreadystatechange = function() { self.onComplete(); };
			xhr.send(parameters);
		}
	}
	
	this.stop = function() {
		stopped = true;
		clearTimeout(this.timer);
	}
	
	this.start = function() {
		stopped = false;
		this.onTimerEvent();
	}
	
	this.onComplete = function() {
		if(this.stopped) return false;
		if ( xhr.readyState == 4) {
			if(xhr.status == 200) {
				if(xhr.responseText == lastResponse) {
					decay = decay * originalDecay;
				} else {
					decay = 1;
				}
				lastResponse = xhr.responseText;
				if(onSuccess instanceof Function) {
					onSuccess(xhr);
				}
				this.timer = setTimeout(function() { self.onTimerEvent(); }, decay * frequency * 1000);
			} else {
				if(onFailure instanceof Function) {
					onFailure(xhr);
				}
			}
		}
	}
	
	this.getResponse = function() {
		if(xhr.responseText) {
			return xhr.responseText;
		}
	}
	
	this.onTimerEvent = function() {
		send();
	}

	var self = this;
	var stopped = false;
	var originalDecay = decay || 1.2;
	decay = originalDecay;
	var xhr = createRequestObject();
	var lastResponse = "";
	this.start();
}

function ProgressTracker(sid, options) {

	this.onSuccess = function(xhr) {
		if(parseInt(xhr.responseText) >= 100) {
			periodicalAjax.stop();
			if(options.onComplete instanceof Function) {
				options.onComplete();
			}
		} else if(xhr.responseText && xhr.responseText != lastResponse) {
			if(options.onProgressChange instanceof Function) {
				options.onProgressChange(xhr.responseText);
			}
			if(options.progressBar && options.progressBar.style) {
				options.progressBar.style.width = parseInt(xhr.responseText) + "%";
				options.progressBar2.innerHTML = parseInt(xhr.responseText) + "%";
			}
		}
	}
	
	this.onFailure = function(xhr) {
		if(options.onFailure instanceof Function) {
			options.onFailure(xhr.responseText);
		} else {
			alert(xhr.responseText);
		}
		periodicalAjax.stop();
	}

	var self = this;
	var lastResponse = -1;
	options = options || {};
	var url = options.url || '/fileprogress.php';
	var frequency = options.frequency || 0.5;
	var decay = options.decay || 2;
	var periodicalAjax = new PeriodicalAjax(url, 'sid=' + sid, frequency, decay, function(request){self.onSuccess(request);},function(request){self.onFailure(request);});
}


function setDimensions(movie,url,divName) {
   var movieObj = getFlashMovieObject(movie);
   var width = movieObj.TGetProperty("/", 8);
   var height= movieObj.TGetProperty("/", 9);

   if (parseFloat(width)>800)
   {
   		height=parseInt(parseFloat(height)/(parseFloat(width)/800));
   		width=800;
   }
   else if (parseFloat(width)<400)
   {
   		height=parseInt(parseFloat(height)/(parseFloat(width)/400));
   		width=400;
   }
   var respuesta = "";
   respuesta = '<embed name="'+movie+'2" width="'+width+'" height="'+height+'" src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>';
   document.getElementById(divName).innerHTML = respuesta;
}
    
function preloadJuegoDimensions(movie,url,divName) 
{
	var flashMovie=getFlashMovieObject(movie);
	if (flashMovie.PercentLoaded() == 100)
	{
		window.clearInterval(relojDimensiones);
		setDimensions(movie,url,divName);
	}
}

function resizeIframe(divName,newWidth, newHeight)
{
	document.getElementById(divName).width = newWidth;
	document.getElementById(divName).height = newHeight;
}

function resizeJuego(divName){
	var winWidth, winHeight, d=document;
	if (typeof window.innerWidth!='undefined') {
	winWidth = window.innerWidth;
	winHeight = window.innerHeight;
	} else if ( d.documentElement
	&& typeof d.documentElement.clientWidth!='undefined'
	&& d.documentElement.clientWidth!=0 ) {
	winWidth = d.documentElement.clientWidth;
	winHeight = d.documentElement.clientHeight;
	} else if ( d.body
	&& typeof d.body.clientWidth!='undefined') {
	winWidth = d.body.clientWidth;
	winHeight = d.body.clientHeight;
	}
	document.getElementById(divName).style.width = (winWidth-210) + "px";
	document.getElementById(divName).style.height = (winHeight-70) + "px";
}

function popUp(URL) 
{
id = 'YupisGame';
if (navigator.appName == "Microsoft Internet Explorer")
{
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,fullscreen=yes');");
}
else
{
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,height="+(screen.height-30)+",width="+(screen.width-5)+"');");
}
location.reload();
}

