// JavaScript Document 
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- El campo '+nm.slice(2)+' debe ser una dirección de e-mail correcta.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- El campo '+nm.slice(2)+' debe ser un número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- El campo '+nm.slice(2)+' debe ser un número entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- El campo '+nm.slice(2)+' no ha sido completado.\n'; }
  } if (errors) alert('El formulario presenta algunos errores:\n'+errors+'\nPor favor corrígelos y vuelve a enviarlo. Gracias.');
  document.MM_returnValue = (errors == '');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

 function isNull(a) 
 {
      return typeof a == 'object' && !a;
 }

function cambiaClase(id, newClass) {
	identity=document.getElementById(id);
	if (!isNull(identity)) {
		identity.className=newClass;
	}
}

function abreLopd(theURL, theTarget) {
	window.open(theURL,theTarget,'resizable=yes,scrollbars=yes,width=500,height=230');
}

//Muestra u oculta un texto cambiando también el texto del link (se usa un texto distinto para el link)
function muestraLeer(idTexto, idLink) {
	var texto = document.getElementById(idTexto);
	var link = document.getElementById(idLink);
	var mostrar = "Ver detalles";
	var ocultar = "Ocultar detalles";
	var txtMando;
	if (texto.style.display == 'block') {
		texto.style.display = 'none';
		txtMando = mostrar;
	} else {
		texto.style.display = 'block';
		txtMando = ocultar;
	}
	if(document.all) { link.innerText = txtMando; }
	else { link.textContent = txtMando; }
}

//Selecciona una opción concreta en un select
function selOpcion(idSelect, txtValue) {
	var elSelect = document.getElementById(idSelect);
	var nOptions = elSelect.length;
	var selIndex = 0;
	var selValue = elSelect.options[selIndex].value;
	
	while (selIndex<nOptions && selValue!=txtValue) {
		selIndex++;
		selValue = elSelect.options[selIndex].value;
	}
	elSelect.selectedIndex = selIndex;
}

function cambiaTextoC2C(nuevoTitulo, nuevaExplicacion) {
	var titulo = document.getElementById("titulo");
	var explicacion = document.getElementById("explicacion");
	if(document.all) {
		titulo.innerText = nuevoTitulo;
		explicacion.innerText = nuevaExplicacion;
	} else {
		titulo.textContent = nuevoTitulo;
		explicacion.textContent = nuevaExplicacion;
	}
	
}
//Funcion para leer una cookie determinada
function leerCookie(nombre) {
   a = document.cookie.substring(document.cookie.indexOf(nombre + '=') + nombre.length + 1,document.cookie.length);
   if(a.indexOf(';') != -1)a = a.substring(0,a.indexOf(';'))
   return a; 
} 
//Funcion para los errores en el webcam
function preguntarSeguir(){
       document.img1.src = "pres/images/error.gif";
	   //document.fondo.src = "pres/images/error.gif";
}
//Funcion para obtener el dominio
function obtenerDominio(valor){
	valor.href = valor.href+"?TB_iframe=true&height=600&width=900";	
}

//Muestra u oculta un texto (se usa el mismo link para mostrar y ocutar)
function muestraLink(idTexto) {
	var texto = document.getElementById(idTexto);
	if (texto.style.display == '') texto.style.display = 'none'
	else texto.style.display = '';
}

//Muestra u oculta un texto cambiando la imagen del link (se usa una imagen distinta para el link)
function muestraImg(idTexto, idImg) {
	var texto = document.getElementById(idTexto);
	var img = document.getElementById(idImg);
	var imgMas = "mas.gif";
	var imgMenos = "menos.gif";
	if (texto.style.display == '') {
		texto.style.display = 'none';
		img.outerHTML = replaceCharacters(img.outerHTML, imgMenos, imgMas);
	} else {
		texto.style.display = '';
		img.outerHTML = replaceCharacters(img.outerHTML, imgMas, imgMenos);
	}
}

//Funcion para sustituir el nombre de la imagen en el HTML dinamico
function replaceCharacters(conversionString,inChar,outChar)
{
  var convertedString = conversionString.split(inChar);
  convertedString = convertedString.join(outChar);
  return convertedString;
}

//Funcion para abrir pop-ups que funcionen con javascript desactivado
function abre(theURL, theTarget) {
	window.open(theURL,theTarget,'resizable=yes,scrollbars=yes,width=680,height=517');
}

$(document).ready(function(){
	$("#previous a").attr("href","#");
	$("#previous a").click(function(){//Efecto generado para el evento onclick en el popup del menu principal
		//$("#popup").css({left:625,top:68});
		$("#popup").toggle("slow");		
	});
	
	//Efecto generado para el evento onmouseover, onmouseout
	$("#popup").hover( 
	function() {
		//No se hace nada si el raton esta en evento onmouseover
	},
	function() {
		//$("#popup").css({left:625,top:68});
		$("#popup").fadeOut("slow");
	});
/*
$('#previous a').tooltip({ 
    delay: 0, 
    showURL: false, 
    bodyHandler: function() { 
        return $("<img src='http://jquery.bassistance.de/tooltip/demo/image.png'>"); 
    } 
});*/
});


function abreVentana(theURL, theTarget, theWidth, theHeight) {
	var opciones = 'resizable=yes,scrollbars=yes,width=' + theWidth + ',height=' + theHeight;
	window.open(theURL,theTarget,opciones);
}