var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function iecompattest(){
   return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ocultarla(){
   parent.document.getElementById("dwindow").style.display="none";
}

function loadwindow(url,width,height){
   if (!ie5&&!ns6)
      window.open(url,"","width=width,height=height,scrollbars=1")
   else {
      document.getElementById("dwindow").style.display=''
      document.getElementById("dwindow").style.width=initialwidth=width+"px"
      document.getElementById("dwindow").style.height=initialheight=height+"px"
      document.getElementById("dwindow").style.left="30px"
      document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px"
      //document.getElementById("cframe").contentWindow.document.body.innerHTML='<img src="'+url+'" border=0 onClick="parent.window.dwindow.style.display=\'none\';" style="cursor:hand;">';
      document.getElementById("cframe").src=url;
   }
}

function resaltarImagen(cur,which){
   strength=(which==1)? 1 : 0.6
   if (cur.style.MozOpacity)
      cur.style.MozOpacity=strength
   else if (cur.filters)
      cur.filters.alpha.opacity=strength*100
}

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;  
} 

function localizaObj(n, d) {
      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=localizaObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function validarForm() {
      var i,p,q,nm,test,num,min,max,errors='',args=validarForm.arguments;
      if (leerCookie('luppa_ln')!='en') 
         var textorequerido='Campos requeridos:';
      else
         var textorequerido='Required fields:';
      
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=localizaObj(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+='- '+nm+' no válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe ser numérico.\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+='- '+nm+' debe ser un nº entre '+min+' y '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+'\n'; }
      } 
      if (errors) {
         if (leerCookie('luppa_ln')=='en') {
            errors = errors.replace("nombre", "name");
            errors = errors.replace("telefono", "phone");
         }
         alert(textorequerido+'\n\n'+errors);
      }
      return (errors == '');
}

function mostrar_tab(TabViewId, CurrentId)
{
  var TabView = document.getElementById(TabViewId);

  // ***** Tabs *****

  var Tabs = TabView.firstChild;
  while (Tabs.className != "Tabs") Tabs = Tabs.nextSibling;
  var Tab  = Tabs.firstChild;
  var textwidth = 0;
  var i    = 0;
  do
  {
    if (Tab.tagName == "A")
    {
      i++;
      Tab.href = "javascript:cambiarvista('"+TabViewId+"', "+i+");";
      textwidth = Tab.innerHTML.length;      
      Tab.className    = (i == CurrentId) ? "TabDefecto" : "";      
      Tab.blur();
    }
  }
  while (Tab = Tab.nextSibling);

  // ***** Pages *****

  var Pages = TabView.firstChild;
  while (Pages.className != 'Pages') Pages = Pages.nextSibling;
  var Page  = Pages  .firstChild;
  var i     = 0;
  var altura=0;

  do
  {
    if (Page.className == 'Page')
    {
      i++;
      Page.style.display  = (i == CurrentId) ? 'block' : 'none';
      if (i == CurrentId) Pages.style.height = Page.clientHeight +"px";  
    }
  }
  while (Page = Page.nextSibling);
}

function cambiarvista(TabViewId, id) { mostrar_tab(TabViewId, id); }
function inicializar_tabs(TabViewId) { mostrar_tab(TabViewId,  1); }

var min=8;
var max=20;
var original=12;
function aumentar() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}

function reducir() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}

function antesdeimprimir(){ 
   if (document.getElementById('filacabecera')) {	 
      document.getElementById('filacabecera').style.visibility = 'hidden';
      document.getElementById('filacabecera').style.position = 'absolute'; 
   }      
   if (document.getElementById('tituloimprimir')) {	 
      document.getElementById('tituloimprimir').style.visibility = 'visible';
      document.getElementById('tituloimprimir').style.position = 'relative'; 
   }      
   if (document.getElementById('lateralizq')) {	 
      document.getElementById('lateralizq').style.visibility = 'hidden';
      document.getElementById('lateralizq').style.position = 'absolute'; 
   }         
   if (document.getElementById('lateraldcha')) {	 
      document.getElementById('lateraldcha').style.visibility = 'hidden';
      document.getElementById('lateraldcha').style.position = 'absolute'; 
   }         
   if (document.getElementById('fondopie')) {
      document.getElementById('fondopie').style.visibility = 'hidden';
      document.getElementById('fondopie').style.position = 'absolute'; 
   }
} 

function despuesdeimprimir(){
   if (document.getElementById('filacabecera')) {	 
      document.getElementById('filacabecera').style.visibility = 'visible';
      document.getElementById('filacabecera').style.position = 'relative'; 
   }      
   if (document.getElementById('tituloimprimir')) {	 
      document.getElementById('tituloimprimir').style.visibility = 'hidden';
      document.getElementById('tituloimprimir').style.position = 'absolute'; 
   }      
   if (document.getElementById('lateralizq')) {	 
      document.getElementById('lateralizq').style.visibility = 'visible';
      document.getElementById('lateralizq').style.position = 'relative'; 
   }         
   if (document.getElementById('lateraldcha')) {	 
      document.getElementById('lateraldcha').style.visibility = 'visible';
      document.getElementById('lateraldcha').style.position = 'relative'; 
   }         
   if (document.getElementById('fondopie')) {
      document.getElementById('fondopie').style.visibility = 'visible';
      document.getElementById('fondopie').style.position = 'relative'; 
   }
}

function preloadImages() {
     if (document.images) {
          for (var i = 0; i < preloadImages.arguments.length; i++) {
               (new Image()).src = preloadImages.arguments[i];
          }
     }
}
   
function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=3) {
		        var control = changeImages.arguments[i];
		        var fuente = changeImages.arguments[i+1];
			document.all[control].src = fuente;		        
		}
	}
}

function create_form(d,txt,lang,gn,tgt){
   fx_2g=d.createElement('form');
   d.body.appendChild(fx_2g);
   fx_2g.target=tgt;
   fx_2g.method='POST';
   fx_2g.action='http://vozme.com/text2voice.php';
   // --------------------------------------------
   // Texto
   // --------------------------------------------
   t=d.createElement('input');
   t.name='text';
   t.type='hidden';
   t.value=txt;
   fx_2g.appendChild(t);
   // --------------------------------------------
   // Idioma
   // --------------------------------------------
   l=d.createElement('input');
   l.name='lang';
   l.type='hidden';
   l.value=lang;
   fx_2g.appendChild(l);
   // --------------------------------------------
   // Voz Masculina / Femenina
   // --------------------------------------------
   g=d.createElement('input');
   g.name='gn';
   g.type='hidden';
   g.value=gn;
   fx_2g.appendChild(g);
   // --------------------------------------------
   // Interface
   // --------------------------------------------
   i=d.createElement('input');
   i.name='interface';
   i.type='hidden';
   i.value='full';
   fx_2g.appendChild(i);
   // --------------------------------------------
   // Reproducimos
   // --------------------------------------------
   fx_2g.submit();
   delete fx_2g;
   return false;
}

function reproducir(id){
   if (Get_Cookie('audio')==1) {
      var lang = arguments[1] || '';
      var gn = arguments[2] || '';
      var tgt='voice_43694';
      var d=window.document;   
      var txt='';
      txt=d.getElementById(id).innerHTML;
      create_form(d,txt,lang,gn,tgt);
   }
   return false;
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
   var today = new Date();
   today.setTime( today.getTime() );
   if ( expires ) {
      expires = expires * 1000 * 60 * 60 * 24;
   }
   var expires_date = new Date( today.getTime() + (expires) );
   document.cookie = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +  ( ( path ) ? ";path=" + path : "" ) +  ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
   var a_all_cookies = document.cookie.split( ';' );
   var a_temp_cookie = '';
   var cookie_name = '';
   var cookie_value = '';
   var b_cookie_found = false;
	
   for ( i = 0; i < a_all_cookies.length; i++ )	{
	a_temp_cookie = a_all_cookies[i].split( '=' );
	cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	if ( cookie_name == check_name ) {
	   b_cookie_found = true;
	   if ( a_temp_cookie.length > 1 ) {
	      cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
	   }
	   return cookie_value;
	   break;
	}
	a_temp_cookie = null;
	cookie_name = '';
   }
   if ( !b_cookie_found ) {
	return null;
   }
}

function Delete_Cookie( name, path, domain ) {
   if ( Get_Cookie( name ) ) document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function sonido(control) {
   var valor = Math.abs( Get_Cookie('audio') - 1);
   if (valor==0) {
      document.getElementById(control).src='html/img/audio_off.gif';
      document.getElementById(control).alt='Escuchar';
   } else {
      document.getElementById(control).src='html/img/audio_on.gif';
      document.getElementById(control).alt='Silenciar';
   }
   Set_Cookie('audio', valor , 30, '/', '', '');
   if (valor==1) {
      reproducir('contenidotxt','es','fm')   
   }
}

function iniciarsonido(){
   //Delete_Cookie('audio','/','');	
   if (Get_Cookie('audio')==null)
      Set_Cookie('audio', '0' , 30, '/', '', '');
}

function opening(m,mW,mH) {
	var me=window.open("","","width="+(mW+40)+",height="+(mH+70)+",location=0,scrollbars=auto,document=0,status=0,resizable=yes");
	me+=me.document.write('<center>  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+mW+'" height="'+mH+'"><param name=movie value="'+m+'"><param name=quality value=high><embed src="'+m+'" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+mW+'" height="'+mH+'"></embed></object><br><br><a href="javascript:self.close()"><img src="(IMG_ROOT)juegos/closewindow.gif" border="0"></a> </center>');
}

var anterior=null;
function eltiempo(control,dia) {
   if (anterior==null)
      anterior=document.getElementById('enlacedia0');

   anterior.style.textDecoration='underline';
   control.style.textDecoration='none';
   anterior=control;
   document.getElementById('imgtiempo').src='http://www.tutiempo.net/i/Mapas/Mapa-del-tiempo-en-Leon-'+dia+'.jpg';
}

function dos_digitos(numero) {
	if (numero<10)
		return "0"+numero;
	else
		return numero;
}

function reloj() {
	var fecha = new Date();
	var diasemana = ["Domingo", "Lunes","Martes","Miércoles","Jueves","Viernes","Sábado"];
	var meses = ["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"];
	var hoy = diasemana[fecha.getDay()]+", "+fecha.getDate()+" de "+meses[fecha.getMonth()]+" de "+fecha.getFullYear();   
	var hora = dos_digitos(fecha.getHours())+":"+dos_digitos(fecha.getMinutes())+":"+dos_digitos(fecha.getSeconds());
	document.getElementById('fechahora').value= " " + hoy + " " + hora + " ";
	setTimeout("reloj()",1000);
}