// ********************* Funciones Para los menus que siempre te salgan en pantalla con el nombre tabla_desplazar
function findScrollTop() {
	if (window.pageYOffset != null)
		return window.pageYOffset;
	if (document.body.scrollWidth != null)
		return document.body.scrollTop;
	return null;
}
var offsetTablaInicial = null;

function miOnScroll() {
	var top;
	//alert("scroll");
	if ( offsetTablaInicial==null) {
		offsetTablaInicial = document.all["tabla_desplazar"].offsetTop;
	} else {
		top = findScrollTop();
		if (top!=null) {
			if (top>offsetTablaInicial) {
				document.all["tabla_desplazar"].style.top = top;				
			} else {
				document.all["tabla_desplazar"].style.top = offsetTablaInicial;
			}
		}				
	}
}

function eliminarEntradaAsiento(numero) {
	if (confirm("¿Seguro que desea eliminar esta linea?")) {
		eval("document.formulario.importe_"+numero+".value='';");
		eval("document.formulario.cuenta_"+numero+".value='';");
	}
	return;
}

function changeDisplay(id) {
	//Permite ocultar o ver un elemento:
	var nodo=document.all[id];
	if (nodo.style.display=="none") {
		nodo.style.display="block";
	} else {
		nodo.style.display="none";
	}
}

function openWindow(url, ancho, alto) {
	strancho=ancho;
	stralto=alto;
	if (ancho==null) strancho = 600;
	if (alto==null) stralto = 360;
	window.open(url,"","resizable=yes,status=1,scrollbars=1,width="+strancho+",height="+stralto,false);
}

function esVacio(cadena) {
	if (trim(cadena)=="") return true;
	else return false;
}

function openLogin() {
	var url="popup_login.php";
	window.open(url,"","resizable=0,status=0,scrollbars=0,width=200,height=140",false);
	//window.open(url,"","",false);
}

function openBigWindow(url) {
	window.open(url,"","resizable=yes,status=1,scrollbars=1,width=540,height=480",false);
}



function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function resaltarGuardar() {
	var element = document.getElementById("boton_guardar");
	if (element!=null) {
		element.innerHTML ="* Guardar *";
	}
}

function abrirMail() {
	if (event.ctrlKey) {
		event.returnValue=false;
		window.open('http://www.varaderoweb.com/cgi-bin/sqwebmail');
		return false;
	}
}

function getElement( id ) {
	var element;
	if (document.getElementById==null) {
		element = document.all[id];
	} else {
		element =document.getElementById(id);
	}
	return element;
}

function getElementDoc( ndoc, id) {
	var doc;
	doc = ndoc;
	if (doc==null) doc = document;
	var element;
	if (doc.getElementById==null) {
		element = doc.all[id];
	} else {
		element =doc.getElementById(id);
	}
	return element;
}


function toggleOcultacion(partner) {
	var table = getElement(partner);
	if (table!=null) {
		if (table.style.display=="none") table.style.display="block";
		else table.style.display="none";
	}
}

function mostrarOcultacion(partner) {
	var table = getElement(partner);
	table.style.display="block";	
}

function ocultarOcultacion(partner) {
	var table = getElement(partner);
	table.style.display="none";	
}


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
			for (var i=0; i<changeImages.arguments.length; i+=2) {
				document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
			}
	}
}


function onchange_data() {
	var estado="";

	var f = document.formulario;
	var idtipo_recurso=f.idtipo_recurso.value;
	var seleccionar=f.seleccionar.value;
	var tipo=f.tipo.value;
	if (f["estado"]!=null) {
		estado=f["estado"].value;
	}
	var q=f.q.value;
	window.location.href="gestion_de_recursos.asp?seleccionar="+seleccionar+"&idtipo_recurso="+idtipo_recurso+"&q="+q+"&estado="+estado+"&tipo="+tipo;
}

function onchange_data_taxonomias() {
	var f = document.formulario;
	var idtipo_recurso=f.idtipo_recurso.value;
	var seleccionar=f.seleccionar.value;
	var q=f.q.value;
	window.location.href="gestion_de_taxonomias.asp?idtipo_recurso="+idtipo_recurso+"&q="+q;
}

function onchange_data_filtros() {
	var f = document.formulario;
	var tipo=f.tipo.value;
	window.location.href="cm_popup_filtros.asp?tipo="+tipo;
}


function onchange_data_categorias() {
	var f = document.formulario;
	var idportal=f.idportal.value;
	var seleccionar=f.seleccionar.value;
	var tipo=f.tipo.value;
	window.location.href="gestion_de_categorias.asp?seleccionar="+seleccionar+"&idportal="+idportal+"&tipo="+tipo;
}


function getElement( id ) {
	var element;
	if (document.getElementById==null) {
		element = document.all[id];
	} else {
		element =document.getElementById(id);
	}
	return element;
}

function toggleOcultacion(partner) {
	var table = getElement(partner);
	if (table!=null) {
		if (table.style.display=="none") table.style.display="block";
		else table.style.display="none";
	}
}

function mostrarOcultacion(partner) {
	var table = getElement(partner);
	table.style.display="block";	
}

function ocultarOcultacion(partner) {
	var table = getElement(partner);
	table.style.display="none";	
}

function sinImagen(imagen) {
	var nodo;
	nodo = getElement("ubicacion_"+imagen);
	if (nodo!=null) nodo.innerHTML="-- Sin imágen --";
	nodo = getElement("imagen_"+imagen);
	if (nodo!=null) nodo.src="img/punto_claro.gif";
	nodo = getElement(imagen+"_bancoimagenes");
	if (nodo!=null) nodo.value="-1";
		
}

function sinDocumento(doc) {
	var nodo;
	nodo = getElement("ubicacion_"+doc);
	if (nodo!=null) {
		nodo.innerHTML="-- Sin documento --";
		nodo.href="#"
	}
	nodo = getElement(doc+"_eliminar");
	if (nodo!=null) nodo.value="S";		
}


function categorias_cambio_tipo_contenidos() {
	var f = document.formulario;
	var tipo=f.tipo_contenidos.value;
	var nodo;
	if (tipo=="-3") {
		nodo = getElement("mostrar_banco_filtros");
		if (nodo!=null) nodo.style.display = "block";
		nodo = getElement("mostrar_nombre_filtro")
		if (nodo!=null) nodo.style.display = "block";
	} else {
		nodo = getElement("mostrar_banco_filtros");
		if (nodo!=null) nodo.style.display = "none";
		nodo = getElement("mostrar_nombre_filtro")
		if (nodo!=null) nodo.style.display = "none";
	}
}


function edicionDestacado( obj, tipo, idcat) {
	if (obj.previousSibling.value=="") {
		alert("Debe guardar la categoria para poder editar este recurso.");
	} else {
		openWindow("cm_popup_destacados.asp?tipo="+tipo+"&idcat="+idcat+"&numero="+obj.previousSibling.value,670,480);
	}
}

function construyeQuery( url, nombre, valor) {
	//var re = new RegExp('(?|&)'+nombre+'=[^&]*','g');
	var v1 = url.split('?');
	var res="";
	var v2 = v1[1].split('&');
	var i;
	inicio = false;
	for (i=0;i<v2.length;i++) {
		var v3 = v2[i].split("=");
		if (res!="") {
		} else {
			res = v1[0]+"?";
			inicio = true;
		}
		if ( (v3[0]!=nombre) &&(v3[0]!="") ) {
			if (!inicio) {
				res +="&";
			} else {
				inicio = false;
			}
			res += v3[0]+"="+v3[1];
		} else {
		}
	}
	res += "&" + nombre + "=" + valor;
	return res;
}

function eliminarOrganizador(strid) {
	var nodo = getElement("mostrar_idorganizadores_"+strid);
	nodo.outerHTML="";


	var valorPrevio = document.formulario.idorganizadores.value;
	var v = valorPrevio.split(",");
	var res="";
	var i;
	for (i=0;i<v.length;i++) {
		if (v[i]!="") {
			if (v[i]!=strid) {
				res = res +","+v[i];
			}
		}
	}
	if (res!="") res=res.substring(1);
	document.formulario.idorganizadores.value = res;
}

function eliminarEvento(strid) {
	var nodo = getElement("mostrar_ideventociclo_"+strid);
	nodo.outerHTML="";


	var valorPrevio = document.formulario.ideventociclo.value;
	var v = valorPrevio.split(",");
	var res="";
	var i;
	for (i=0;i<v.length;i++) {
		if (v[i]!="") {
			if (v[i]!=strid) {
				res = res +","+v[i];
			}
		}
	}
	if (res!="") res=res.substring(1);
	document.formulario.ideventociclo.value = res;
}

function eliminarProyecto(strid) {
	var nodo = getElement("mostrar_otros_proyectos_"+strid);
	nodo.outerHTML="";

	var valorPrevio = document.formulario.otros_proyectos.value;
	var v = valorPrevio.split(",");
	var res="";
	var i;
	for (i=0;i<v.length;i++) {
		if (v[i]!="") {
			if (v[i]!=strid) {
				res = res +","+v[i];
			}
		}
	}
	if (res!="") res=res.substring(1);
	document.formulario.otros_proyectos.value = res;
}

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function


function abrirEnlaceCamino(url, idcamino) {
	var str_buffer=getElement( idcamino ).innerHTML;
	var text = getElement( idcamino ).innerText;
	if (text!="") {
		openWindow(url);
		var vWinCal = window.open("", "Camino", "width=200,height=210,status=no,resizable=yes,top=200,left=200");
		vWinCal.opener = self;
		var calc_doc = vWinCal.document;
		calc_doc.write (str_buffer);
		calc_doc.close();
	} else {
		openWindow(url);
	}
	return false;
}

function abrirDescripcion(idtexto) {
	var str_buffer=getElement( idtexto ).innerHTML;
	var text = getElement( idtexto ).innerText;
	if (text!="") {
		var vWinCal = window.open("", "Descripcion", "width=400,height=210,status=no,resizable=yes,scrollbars=1,top=200,left=200");
		vWinCal.opener = self;
		var calc_doc = vWinCal.document;
		calc_doc.write (str_buffer);
		calc_doc.close();
	} 
	return false;
}


function timeout2() {
	var nodo, i;
	if (cicloTrans==null) return false;
	for(i=0;i<cicloTrans.length;i++) {
		toggleTransition( cicloTrans[i] );
	}
	alarma1=setTimeout("timeout2()",tiempoTrans);
}

function toggleTransition(informacion) {
	var nodo = getElement(informacion);
	var cuentamax=1;
	var cuentaactual=1;
	var cuenta = 1;
	var strcuenta = numDigitos(cuenta,2);
	var nodo2 = getElement(informacion+strcuenta);
	while (nodo2!=null) {
		if (nodo2.style.visibility!='hidden') {
			cuentaactual=cuenta;
		}
		cuenta ++;
		strcuenta = numDigitos(cuenta,2);
		nodo2 = getElement(informacion + strcuenta);
		cuentamax = cuenta;
	}
	cuentamax--;

	if (cuentamax<=1) return;

	try {
	    nodo.filters[0].Apply();
	} catch (e) { }
	//alert(informacion + " - cuentamax="+cuentamax);
	for (i=1;i<=cuentamax ;i++ ) {
		strcuenta = numDigitos(i,2);
		nodo2 = getElement(informacion + strcuenta);
		if (i<=cuentaactual) {
			nodo2.style.visibility="hidden";
		} else if (i==cuentaactual+1) {
			nodo2.style.visibility="visible";			
		} else {
			nodo2.style.visibility="hidden";
		}
		if ((cuentamax==cuentaactual) && (i==1)) {
			nodo2.style.visibility="visible";
		}
	}

	try
	{
	   	nodo.filters[0].Play();
	}
	catch (e) { }
	/*
	var nodo1 = getElement(informacion+"01");
	var nodo2 = getElement(informacion+"02");
	var nodo3 = getElement(informacion+"03");
	var nodo4 = getElement(informacion+"04");

	alert("nodo:"+nodo);
	alert("nodo1:"+nodo1);

	try
	{
	    nodo.filters[0].Apply();
	}
	catch (e) { }

    if (nodo1.style.visibility!='hidden') { 
		if (nodo1!=null) nodo1.style.visibility="hidden";
		else nodo1.style.visibility="visible";
        if (nodo2!=null) nodo2.style.visibility="visible"; 
		else nodo1.style.visibility="visible";
		if (nodo3!=null) nodo3.style.visibility="hidden";
		else nodo1.style.visibility="visible";
		if (nodo4!=null) nodo4.style.visibility="hidden";
		else nodo1.style.visibility="visible";
    } else if (nodo2.style.visibility!='hidden') { 
		if (nodo1!=null) nodo1.style.visibility="hidden";
        if (nodo2!=null) nodo2.style.visibility="hidden"; 
		else nodo1.style.visibility="visible";
		if (nodo3!=null) nodo3.style.visibility="visible";
		else nodo1.style.visibility="visible";
		if (nodo4!=null) nodo4.style.visibility="hidden";
		else nodo1.style.visibility="visible";
    } else if (nodo3.style.visibility!='hidden') { 
		if (nodo1!=null) nodo1.style.visibility="hidden";
        if (nodo2!=null) nodo2.style.visibility="hidden"; 
		else nodo1.style.visibility="visible";
		if (nodo3!=null) nodo3.style.visibility="hidden";
		else nodo1.style.visibility="visible";
		if (nodo4!=null) nodo4.style.visibility="visible";
		else nodo1.style.visibility="visible";
    } else if (nodo4.style.visibility!='hidden') { 
		if (nodo1!=null) nodo1.style.visibility="visible";
        if (nodo2!=null) nodo2.style.visibility="hidden"; 
		else nodo1.style.visibility="visible";
		if (nodo3!=null) nodo3.style.visibility="hidden";
		else nodo1.style.visibility="visible";
		if (nodo4!=null) nodo4.style.visibility="hidden";
		else nodo1.style.visibility="visible";

	} else {  
		//nodo1.style.visibility="visible";
        //nodo2.style.visibility="hidden"; 
	}
	try
	{
	   	nodo.filters[0].Play();
	}
	catch (e) { }*/
}

	function numDigitos( valor, ancho) {
		var res, i;
		res = valor +"";
		for (i=(res+"").length; i<ancho; i++) {
			res ="0"+ res;
		}
		return res;
	}

	function protegeFlash(contenido) {
		return replaceSubstring(contenido, "<PARAM NAME=\"Play\" " , "<PARAM NAME=\"tempplay\" ");
	}