//window.onerror=null
msgWindow=""
n_ventanas=0
compat = false;
mouse_x=0;
mouse_y=0;
//    var is_nav     = (parseInt(navigator.appVersion) >= 4) &&((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1)
//		       && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1)
//		       && (agt.indexOf('webtv') == -1));
//var sw_arranque=(is_nav4up ? true : false)
var muestra_clickizq=false
if( parseInt( navigator.appVersion ) >= 3 ) { compat = true; }

//alert("Cargo Fotos");
  if (document.images) {

//    var linea_hor_f2= new Image; linea_hor_f2.src= "linea_hor_f2.gif";
//    var linea_hor_f3= new Image; linea_hor_f2.src= "linea_hor_f3.gif";
//    var linea_hor= new Image; linea_hor.src= "linea_hor.gif";
//    var boceto_web= new Image; boceto_web.src = "boceto_web.gif";
//    var logovfani= new Image; logovfani.src = "logovfani.gif";
//    var globosw= new Image; globosw.src = "globos.gif";
//    var globosw_f2= new Image; globosw_f2.src = "globos_f2.gif";

//    var ultimo_0   = new Image; ultimo_0.src	  = "imgprg/ultimo_0.gif";
//    var ultimo_1 = new Image; ultimo_1.src	= "imgprg/ultimo_1.gif";
//    var anterior_0   = new Image; anterior_0.src    = "imgprg/anterior_0.gif";
//    var anterior_1   = new Image; anterior_1.src    = "imgprg/anterior_1.gif";
//    var siguiente_0	= new Image; siguiente_0.src	= "imgprg/siguiente_0.gif";
//    var siguiente_1	= new Image; siguiente_1.src	= "imgprg/siguiente_1.gif";
//    var primero_0   = new Image; primero_0.src    = "imgprg/primero_0.gif";
//    var primero_1   = new Image; primero_1.src    = "imgprg/primero_1.gif";
  // alert(menuico_r1_c1_f1.src)
  }
if( parseInt( navigator.appVersion ) >= 3 ) { compat = true; }

var count = 0;
var hand = 0;
nav = (document.layers) ? true : false;
ie  = (document.all) ? true : false;
//if (nav)
////  skin = document.topdeck;
//  var skin = document.globos;
//if (ie)
//  var skin = globos.style;
/*if (eval("(nav) ? document.layers['globos']:document.all['globos']")!=null){
   var skin = (nav) ?  document.layers['globos']:document.globos.style;
}*/
document.onmousemove = sustain;
if (nav) document.captureEvents(Event.MOUSEMOVE);
//*****************************************************

compat = false;

if( parseInt( navigator.appVersion ) >= 3 ) { compat = true; }

if (document.images) {
//    var linea_hor_f2= new Image; linea_hor_f2.src= "linea_hor_f2.gif";
//    var linea_hor_f3= new Image; linea_hor_f2.src= "linea_hor_f3.gif";
//    var linea_hor= new Image; linea_hor.src= "linea_hor.gif";
//    var boceto_web= new Image; boceto_web.src = "boceto_web.gif";
//    var logovfani= new Image; logovfani.src = "logovfani.gif";

    var ultimo_0   = new Image; ultimo_0.src	= "imgprg/ultimo_0.gif";
    var ultimo_1 = new Image; ultimo_1.src    = "imgprg/ultimo_1.gif";
    var anterior_0   = new Image; anterior_0.src    = "imgprg/anterior_0.gif";
    var anterior_1   = new Image; anterior_1.src    = "imgprg/anterior_1.gif";
    var siguiente_0   = new Image; siguiente_0.src    = "imgprg/siguiente_0.gif";
    var siguiente_1   = new Image; siguiente_1.src    = "imgprg/siguiente_1.gif";
    var primero_0   = new Image; primero_0.src	  = "imgprg/primero_0.gif";
    var primero_1   = new Image; primero_1.src	  = "imgprg/primero_1.gif";

}

//function cambia(x, y)
//{
 //  if( compat ) { document.images[x].src=eval(y+'.src'); }
//}
//function MM_reloadPage(init) {  //reloads the window if Nav4 resized
//  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
//    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
//  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
//}
//MM_reloadPage(true);
// -->

function pop(orientation,msg) {
if (pon_globos!=true){
  return
}
 content=  '  <table border="0" cellpadding="0" cellspacing="0" width="1" height="1">																				'
+'  <tr>																											      '
+'    <td rowspan="2" colspan="2" >																								      '
+'	 <img src="shim.gif" width="1" height="1" border="0">																					      '
+'    </td>																											      '
+'    <td align="left"> 																									      '
+'	<div align="left"><img src="shim.gif" width="1" height="18" border="0"></div>																		      '
+'    </td>																											      '
+'    <td width="1">																										      '
+'	<div align="left" width="1"><img src="globos/globo_pico.gif" align="left" width="12" height="18" border="0"></div>													      '
+'    </td>																											      '
+'    <td>																											      '
+'	<div align="left"><img	src="shim.gif" width="1" height="18" border="0"></div>																		      '
+'    </td>																											      '
+'    <td rowspan="2" colspan="2">																								      '
+'	 <img src="shim.gif" width="1" height="1" border="0">																					      '
+'    </td>																											      '
+'  </tr>																											      '
+'  <tr>																											      '
+'    <td bgcolor="#000000" width="1">																								      '
+'	<div align="left"><img src="shim.gif" width="1" height="1" border="0"></div>																		      '
+'    </td>																											      '
+'    <td bgcolor="#000000" width="1">																								      '
+'	<div align="left"><img src="globos/globo_blancen.gif" align="left" width="12" height="1" border="0"></div>														      '
+'    </td>																											      '
+'    <td bgcolor="#000000" width="100%">																							      '
+'	<div align="left"><img src="shim.gif" width="1" height="1" border="0"></div>																		      '
+'    </td>																											      '
+'  </tr>																											      '
+'  <tr>																											      '
+'    <td colspan="2" valign="top" height="7" width="11"><img src="globos/globo_supiz.gif" width="11" height="7" border="0"></td>												      '
+'    <td colspan="3" bgcolor="#FFFFFF" height="1"><img src="shim.gif" width="1" height="1" border="0"></td>															      '
+'    <td colspan="2" valign="top" height="7"><img  src="globos/globo_supder.gif" width="11" height="7" border="0"></td>													      '
+'  </tr>																											      '
+'  <tr>																											      '
+'    <td width="1" bgcolor="#000000"><img src="shim.gif" width="1" height="1" border="0"></td> 																      '
+'    <td bgcolor="#FFFFFF" width="11"><img src="shim.gif" width="1" height="1" border="0"></td>																      '
+'    <td colspan="3" bgcolor="#FFFFFF" height="2">																					       '
+'	<center"><font size="-3" face="Geneva, Arial, Helvetica, san-serif" size=-1>																	     '
+''+msg
+'	</font></center>																										   '
+'	</td>																											      '
+'    <td bgcolor="#FFFFFF"><img src="shim.gif" width="11" height="1" border="0"></td>																		      '
+'    <td width="1" bgcolor="#000000"><img src="shim.gif" width="1" height="1" border="0"></td> 																      '
+'  </tr>																											      '
+'  <tr>																											      '
+'    <td width="11" height="8" rowspan="2" colspan="2" valign="bottom"><img src="globos/globo_infizq.gif" width="11" height="8" border="0"></td>										      '
+'    <td colspan="3" bgcolor="#FFFFFF" height="100%"><img src="shim.gif" width="1" height="7" border="0"></td> 														      '
+'    <td rowspan="2" colspan="2" valign="bottom"><img src="globos/globo_infder.gif" width="11" height="8" border="0"></td>													      '
+'  </tr>																											      '
+'  <tr>																											      '
+'    <td height="1" bgcolor="#000000" width="1"><img src="shim.gif" width="1" height="1" border="0"></td>															      '
+'    <td height="1" bgcolor="#000000" width="1"><img src="shim.gif" width="1" height="1" border="0"></td>															      '
+'    <td height="1" bgcolor="#000000" width="1"><img src="shim.gif" width="1" height="1" border="0"></td>															      '
+'  </tr>																											      '
+'</table>																											      '
  if (nav) {
    var canvas = document.globos.document;
    canvas.write(content);
    canvas.close();
   // skin.visibility = "show";
   //	show_capa('globos',true)
  }
  else if (ie) {
    document.all("globos").innerHTML = content;

  //  skin.visibility = "visible";
  }
    show_capa('globos',true)
    hand = orientation;
}

function sustain(e) {
// kill();
return;
if (eval("(nav) ? document.layers['globos']:document.all['globos']")!=null){
   var skin = (nav) ?  document.layers['globos']:document.all['globos'].style;
}else{
  return
}
var x = (is_nav4up )? e.pageX : event.x+document.body.scrollLeft
var y = (is_nav4up )? e.pageY : event.y+document.body.scrollTop
//  var x = (nav) ? e.pageX : event.x;
//  var y = (nav) ? e.pageY : event.y;
//  alert(hand)
  switch(hand) {
  case 0 :
   kill();
    break;
  case 1 :
    skin.left = x+10,  skin.top = y+10;
   // window.status = "Demostración del panel de control";
    break;
  case 2 :
    skin.left = x-60,  skin.top = y+20;
    break;
  case 3 :
    skin.left = x-135, skin.top = y+10;
    window.status = "Right Popup";
    break;
  default:
    skin.left = x+10,  skin.top = y+10;
    break;
  }
  skin.left = x-5,  skin.top = y+10;
       //  status = "x1---:"+	x+" y1:"+y  +" h:"+ hand


}
 function Dia_del_anyo()  {
//   var fecha = new Date();
//alert(document.lastModified)
fecha = new Date(document.lastModified) // get string of last modified date
//alert(fecha);
//fecha = Date.parse(lastmod)
    var dia,dia_sem,mes,anyo;

    dia = fecha.getDate();
    dia_sem = fecha.getDay();
    mes = fecha.getMonth();
    anyo = fecha.getYear();
    if(anyo<2000) anyo += 2000;

    switch(dia_sem)  {
      case 0: dia_sem = 'Domingo'; break;
      case 1: dia_sem = 'Lunes'; break;
      case 2: dia_sem = 'Martes'; break;
      case 3: dia_sem = 'Miércoles'; break;
      case 4: dia_sem = 'Jueves'; break;
      case 5: dia_sem = 'Viernes'; break;
      case 6: dia_sem = 'Sábado'; break;
      }

    switch(mes)  {
      case 0: mes = 'Enero'; break;
      case 1: mes = 'Febrero'; break;
      case 2: mes = 'Marzo'; break;
      case 3: mes = 'Abril'; break;
      case 4: mes = 'Mayo'; break;
      case 5: mes = 'Junio'; break;
      case 6: mes = 'Julio'; break;
      case 7: mes = 'Agosto'; break;
      case 8: mes = 'Septiembre'; break;
      case 9: mes = 'Octubre'; break;
      case 10: mes = 'Noviembre'; break;
      case 11: mes = 'Diciembre'; break;
      }

    return dia + " de " + mes + " de " + anyo;
    }

function kill() {

  if (count >= 1 )
    var always=true;
  if (always == true) {
    hand = 0;
      show_capa('globos',false)
   }
  else
    count++;
}

function pon_globo(texto,pon){
  if (pon){
   pop(2,texto)
  }else{
     kill()
  }

}

function pon_globo1(texto,pon){
if (pon_globos==true){
  if (eval("(is_nav4up) ? document.layers['globos']:document.all['globos']")!=null){
	var x = mouse_x
     //(is_nav4up)? e.pageX : event.x+document.body.scrollLeft
	var y =  mouse_y
     //(is_nav4up)? e.pageY : event.y+document.body.scrollTop
     //   alert(x+"/"+y)
//   algo=((is_nav4up) ? document.layers['globos'] : document.all['globos'].style);
//	algo=((is_nav4up) ? document.layers['globos'].myform.textoglobo: document.all['globos'].myform.textoglobo);
      algo=((is_nav4up) ? document.layers['globos'].document.links: document.all['globos'].document.links[1]);
   //	 alert(show_props(algo,"formcapa"))
   algo.value=texto
   if (!is_nav4up){
     algo.innerHTML=texto
    // alert(show_props(algo,'capa1'))
     //alert(algo.innertext)
   }else{
  // algo.text=texto
   //  document.layers['globos'].myform.globotxt.value=texto
    document.layers['globos'].document.myform.textoglobo.value=texto.replace("<BR>", " ")
     //: document.all['globos'].myform.textoglobo);
  //   alert(algo.value)
   //alert(show_props(algo,'capa1'))
   }
   move_div('globos',x-50,y+15)
   //color_capa('globos','blue')
   show_capa('globos',pon)

   //document.write(A)
   //alert("KKKKKKKKKKKKKKKKKK")
  }else{
   alert('No definida capa de globos')
  }
 }
}
function init_mouse() {
//	  document.onmousedown = mouseDown
//	  document.onmousemove = sustain
//	  document.onmouseup = mouseUp
//	  if (is_nav4up ) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP )
}

function mouseDown(e) {
    que_boton=((is_nav4up)?e.which:event.button)
    if (que_boton!=1 && !muestra_clickizq) {
     //    alert("© Asociación de Ferias Españolas")
      if (is_nav4up){
   //	      return false
      }else{
   //	  return void(0)
	 //event.button=1
      }
    }
	if ((is_nav4up	&& e.which!=1) || (!is_nav4up && event.button!=1)) return true
	var x = (is_nav4up )? e.pageX : event.x+document.body.scrollLeft
	var y = (is_nav4up )? e.pageY : event.y+document.body.scrollTop
     //   status = "pico x:"+x+" y:"+y
	mouse_x= x;
	mouse_y= y;
	return true
}


function mouseMove(e) {
	var x = (is_nav4up )? e.pageX : event.x+document.body.scrollLeft
	var y = (is_nav4up )? e.pageY : event.y+document.body.scrollTop
    //	  status = "x:"+x+" y:"+y
	mouse_x= x;
	mouse_y= y;
	return true
}

function mouseUp(e) {
	var x = (is_nav4up )? e.pageX : event.x+document.body.scrollLeft
	var y = (is_nav4up )? e.pageY : event.y+document.body.scrollTop
	mouse_x= x;
	mouse_y= y;
	return true
}
function usuar(){
//alert(this.parent.frames.quien.usuario_ht);
    if (eval("this.parent.frames.quien")==null){
	usr_ht=""
    }else{
	usr_ht='|'+this.parent.frames.quien.usuario_ht;
    }
return usr_ht
}

function lleva_funphp(fun,para){
  alert(fun+"('"+para+"')|ZmVy")
      window.open(fun+"('"+para+"')","_self")  ;
  // window.open("index.php?|consultadb('estadisticas')|ZmVy","_self")  ;
//http://fer-movil/afe/newweb/afe_bd.php3?|consultadb('estadisticas')|ZmVy
//http://fer-movil/afe/newweb/afephp.php3?|pon_idkey_est('537|BILBAO031|BILBAO031')|ZmVy
}
function at(fullS,cadena_busca){
	// alert("esto es at : "+fullS+"/"+cadena_busca)
    for (var i=0; i<fullS.length; i++) {
      //alert(i+"("+fullS.substring(i,1)+")")
      cade_corta=fullS.substring(i,i+1)
	 //   alert(i+"("+cade_corta+"/"+fullS.substring(i,i+1))
      if ( cade_corta==cadena_busca) {

	return fullS.substring(0,i)
       // fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length)
      }
    }
   return ""
}
function replaceString(oldS,newS,fullS) {
  // Replaces oldS with newS in the string fullS
  for (var i=0; i<fullS.length; i++) {
    if (fullS.substring(i,i+oldS.length) == oldS) {
      fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length)
    }
   }
   return fullS
}

function cambia(w,x, y,z,a,b,r,s){
//alert(x)
//alert(eval(x+'.src'));
//alert(w +" / " + x +" / " + y+" / " +z);
//alert(r +" / " + s );
//alert(r == null );
//alert(eval(w+'.src')+"/"+document.images[z].src)
   if( compat ) { document.images[w].src=eval(x+'.src');
		if (!(y == null)) {document.images[y].src=eval(z+'.src');}
		if (!(a == null)) {document.images[a].src=eval(b+'.src'); }
		if (!(r == null)) {document.images[r].src=eval(s+'.src')} }
}
 //*************************
function cambia_fotocapa(foto_src,foto_trae,capa,tipo_graf)
{
//  foto_ant=foto_sw;
//alert(foto_src+"/"+foto_trae+"/"+capa+"/"+tipo_graf);
//alert(capa.substring( 1,2));
// Mira si es menu para guardar la imagen activa
if (capa.substring(0,2)=="mn"){
afoto_sw[capa.substring(2)]=foto_trae.substring(0,foto_trae.length-3)
//  alert(afoto_sw[capa.substring(2)])
}
//alert(eval("document."+foto_trae+".src"))
  if (tipo_graf==null){
     tipo_graf=".gif"
  }
//
     algo=(is_nav4up ? "document."+capa+".document." : "document.")+foto_src
  //alert(algo)
     obj=eval(algo);
 //alert(show_props(algo, "obj"))
    obj.src=foto_trae+tipo_graf;
}

function move_div1(capa,x,y,ancho)
{
//alert(capa)
d=(is_nav4up) ? document.layers[capa] : document.all[capa].style;
//alert(show_props(d,'capa'))
//algo=(show_props(d,'capa'))
//document.write(algo)
//alert(d)
 d.left=x;
 d.top=y;
 if ((is_ie4) && ancho!=null) {
 // alert(ancho)
//    alert("************* "+ancho)
   d.pixelWidth=ancho;
 }
}

function show_props(obj, obj_name) {
//alert(obj_name)
	  var result = obj_name+"\n\n"
	  for (var i in obj)
		    result += obj_name + "." + i + " = " + obj[i] + "\n"
	  return result
}
function color_capa1(capa,color){
//ver1=((!ver)?"hidden":((is_nav4up)?"show":"visible"));
//alert(capa+"/"+color);
     if (is_nav4up) {
	//document[capa].visibility = ver1;
    //alert(capa+"/"+color);
	document[capa].bgColor = color;
//alert( show_props(document[capa],"capA"));
     } else {
//	  alert(capa+"/"+color);
    color=(color==null)?"":color;
//alert( show_props(document.all[capa].style,"capA"));
	document.all[capa].style.backgroundColor = color;
     }
}
function show_capa1(capa,ver){
ver1=((!ver)?"hidden":((is_nav4up)?"show":"visible"));
//alert(capa+"/"+ver1);

     if (is_nav4up) {	 
	document.layers[capa].visibility = ver1;
// document[capa].bgColor = "#FFFFFF";
//   alert( show_props(document[capa],"capA"));
//    alert(document[capa].visibility);
     } else {
	document.all[capa].style.visibility =  ver1;
     }
}
function foto_abierta()
{
//alert(eval(msgWindow.closed))
//var a=eval(msgWindow.closed)
//alert("->"+a+"<-")
//alert(a==null)
//if (eval(msgWindow.closed)==false){msgWindow.close()};
	if (eval(msgWindow.closed)==null){
	}
	else
	{
	if (eval(msgWindow.closed)==false){msgWindow.close()};
	}
}

function MM_preloadImages() { //v3.0
//alert("Aqui");
  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 arranca2(){
a=this.location.href
var_litestoy=""
//alert(show_props(a))

//  alert(a.substring(0,a.length-1))
// alert(a)
  if (!todo_bien){
  //alert('Voy');
    if (a.substring(a.length-1)=="#"){
      a=a.substring(0,a.length-1)
      // alert(show_props(this.location))

    }
   this.location.href=a
  }
  sw_arranque=false
  //alert('Vuelvo')
 // this.location=this.location+"#"
}
function carga_foto_ventana(foto,comentario,ancho_trae,alto_trae,directorio)
{
//alert("aqui");
foto_abierta()
//alert(document.images.length)
//alert(comentario==null)
n_ventanas=document.images.length+1;
imagen_nueva=new Image;
//alert(foto)
imagen_nueva.src=foto;
if (directorio==null){
  directorio="";
}else{
  directorio=directorio+"/";
}

imagen_nueva.src=directorio+foto;
//alert("Voy a Preload Aqui");
MM_preloadImages(imagen_nueva.src);
MM_preloadImages(imagen_nueva.src);
//alert(foto+'; nombre=' + document.images[document.images.length].name+
//alert(foto+'; nombre=' + document.images[n_ventanas].name+
//	'; height=' + ancho+
//    '; width=' + alto +
//	'; hspace=' + imagen_nueva.hspace +
//	'; vspace=' + imagen_nueva.vspace);
// analiza_foto()


document.images[n_ventanas]=imagen_nueva.src;
document.images[n_ventanas]=imagen_nueva.src;
//alert(document.images[n_ventanas])
if (ancho_trae==null){
ancho=imagen_nueva.height;
alto=imagen_nueva.width;
//alert(ancho+" <--- SIN Paremetros ---> "+alto)
}
else{
ancho=ancho_trae;
alto=alto_trae;
//alert(ancho+" <--- CON Paremetros ---> "+alto)
}

n_ventanas++;
//if (alto==0){
if (false){
	//alert(imagen_nueva.hspace)
	//carga_foto_ventana(foto,comentario)
}
else{
	if (!(comentario == null)) {
		ancho=ancho+10
	}
	msgWindow=window.open('','window'+n_ventanas,'resizable=1,width='+(alto+15)+',height='+(ancho+70));
//	msgWindow=window.open('','descripcion1');
	msgWindow.document.write('<TITLE>'+foto+'</title>',"\n");
	msgWindow.document.write('<BODY TEXT="#FFFFFF" BGCOLOR="#4888A4" LINK="#000000" VLINK="#808080" ALINK="#990000">',"\n");
	msgWindow.document.write('<img src="'+imagen_nueva.src+'" HEIGHT='+ancho+' WIDTH='+alto+ ' >',"\n");
	msgWindow.document.write('<IMG SRC="logoafe_pq.gif" BORDER=0  ALIGN=LEFT>');
	if (!(comentario == null)) {
		msgWindow.document.write('<CENTER><FONT FACE="Arial,Helvetica"><FONT SIZE=1>'+comentario+'</FONT></FONT></CENTER>',"\n");
	}
	msgWindow.document.write('<FORM NAME="form2"><INPUT TYPE="button" VALUE="Cerrar Foto" onClick=self.close()> </FORM>');
//alert("KKKK")

// PRINT MsgWindow.document.write('</FORM><FORM NAME="form3"><INPUT TYPE="button" VALUE="Imprimir Foto" onClick=document.images[n_ventanas].print()> </FORM>',"\n");
	msgWindow.document.write('</BODY>',"\n");
	msgWindow.focus()
}
}
/* ------------------- */
/* Funciones generales */
/* ------------------- */

function Trim(cad)
{
  var aux="";
  var i,lg = cad.length;
  for (;lg>0 && cad.charAt(lg-1)<=' ';lg--);
  for (i=0;i<lg && cad.charAt(i)<=' ';i++);
  for (;i<lg;i++) aux = aux + cad.charAt(i);
  return aux;
}


function IsAlpha(car)
{
  car = car.toUpperCase();
  esp = " -áéíóúäëïöüÄËÏÖÜÁÉÍÓÚñÑ";
  return  (car>='A' && car<='Z') || esp.indexOf(car)!=-1;
}


// ARGUMENTOS FUNCION Abrir_Ventana
// theURL: Dirección
// winName: Nombre que queremos darle a la ventana
// Features:
	// scrollbars: Si tiene barras de desplazamiento
	// resizable: Si puede cambiarse tamaño
	// width y height: Dan tamaño a la ventana
	// top y left: Posiciona la ventana

function Abrir_Ventana(theURL, winName, features)
{
  window.open(theURL, winName, features);
}


/* --------------------------------- */
/* Funciones de validacion de fechas */
/* --------------------------------- */

// Función que comprueba que el formato de fecha es correcto

function comprobarFecha1(dia, mes, anio)
{
  var caracter;
  var cadena = dia + "/" + mes + "/20" + anio;
  var caracteresValidos = "/0123456789";

  if(cadena.length!=10 || cadena.charAt(2)!="/" || cadena.charAt(5)!="/")
  {
    return false;
  }
  for(var i=0;i<cadena.length;i++)
  {
    caracter = cadena.charAt(i);
    if(caracteresValidos.indexOf(caracter)<0)
    {
      return false;
    }
  }
  dia = parseInt(cadena.substr(0,2),10);
  mes = parseInt(cadena.substr(3,2),10);
  anio = parseInt(cadena.substr(6,4),10);
  if(anio<=0)
  {
    return false;
  }
  switch(mes)
  {
    case 1:case 3:case 5:case 7:case 8:case 10:case 12:
    {
      if(dia<=0 || dia>31) return false;
      break;
    }
    case 4:case 6:case 9:case 11:
    {
      if(dia<=0 || dia>30) return false;
      break;
    }
    case 2:
    {
      if(anio%4)
      {
	if(dia<=0 || dia>28) return false;
      }
      else if(dia<=0 || dia>29) return false;
      break;
    }
    default:
    {
      return false;
    }
  }
  return true;
}


// Función que comprueba que la fecha de regreso sea mayor o igual que la de salida

function CompruebaRangos(di, mi, ai, df, mf, af)
{
  if (ai<100)
  {
    ai = "20" + ai;
  }
  if (af<100)
  {
    af = "20" + af;
  }
  di = parseInt(di,10);
  mi = parseInt(mi,10);
  ai = parseInt(ai,10);
  df = parseInt(df,10);
  mf = parseInt(mf,10);
  af = parseInt(af,10);
  if (af<ai)
  {
    return false;
  }
  if (af>ai) return true;
  if (mf<mi) return false;
  if (mf>mi) return true;
  if (df<di) return false;

  return true;
}


// Función que comprueba que una fecha sea posterior a la fecha actual

function CompruebaRango(df, mf, af, navegador)
{
  if (af<100)
  {
    af="20" + af;
  }

  df = parseInt(df,10);
  mf = parseInt(mf,10);
  af = parseInt(af,10);

  fa = new Date();
  da = fa.getDate();
  ma = fa.getMonth()+1;

  if (navegador=="ie")
  {
    aa = fa.getYear();
  }
  else
  {
    aa = 1900+fa.getYear();
  }

  if (af<aa) return false;
  if (af>aa) return true;
  if (mf<ma) return false;
  if (mf>ma) return true;
  if (df<da) return false;
  return true;
}


// Función que comprueba que la hora de regreso sea posterior a la hora de salida

function CompruebaHoras(di, mi, ai, df, mf, af, hs, hr)
{
  if((af==ai) && (mf==mi) && (df==di))
  {
    if (hr<=hs)
    {
      return false;
    }
  }
  return true;
}


// Función que comprueba que una hora sea posterior a la hora actual

function CompruebaHora(di, mi, ai, hs, navegador)
{
  mi = parseInt(mi,10);
  di = parseInt(di,10);
  hs = parseInt(hs,10);
  if (ai<100)
  {
    ai = "20" + ai;
  }
  ai = parseInt(ai,10);
  fa = new Date();

  if (navegador=="ie")
  {
    aa = fa.getYear();
  }
  else
  {
    aa = 1900+fa.getYear();
  }

  ma = fa.getMonth()+1;
  da = fa.getDate();
  ha = fa.getHours();

  if((aa==ai) && (ma==mi) && (da==di))
  {
    if (hs<=ha)
    {
      return false;
    }
  }
  return true;
}


/* --------------- */
/* Otras funciones */
/* --------------- */

// Función que comprueba que el número de vuelo sea correcto

function redimensionar() {
	//Redimensionar en NS causa problemas
	//window.onResize = redimensionar
	if (anchoVentana != window.innerWidth || altoVentana != window.innerHeight)
	document.location.href = document.location.href
}

function longitudMes(mes,agno) {
	if(mes==3||mes==5||mes==8||mes==10) return 30;
	else if (mes==1 && bisiesto(agno)) return 29;
	else if (mes==1) return 28;
	else return 31;
}

function introducir_fecha()
{
	mesmarcado=mesmarcado+1;
	agnomarcado_aux=agnomarcado.toString()
	if(diamarcado<10)
	{
		 dia = "0" + diamarcado;
	}
	else
	{
		dia = diamarcado;
	}
	if(mesmarcado<10)
	{
		mes = "0" + mesmarcado;
	}
	else
	{
		mes = mesmarcado;
	}
	if(window.opener.document.formulario.origen_destino.value=='origen')
	{
		window.opener.document.formulario.D_Day.value = dia
		window.opener.document.formulario.D_Month.value = mes
		window.opener.document.formulario.D_Anio.value = agnomarcado_aux.substring(2,4)
		aux=dia + "/" + mes + "/" + agnomarcado_aux.substring(2,4)
		window.opener.document.formulario.D_Fecha_usr.value = aux
	}
	else
	{
		window.opener.document.formulario.R_Day.value = dia
		window.opener.document.formulario.R_Month.value = mes
		window.opener.document.formulario.R_Anio.value = agnomarcado_aux.substring(2,4)
		aux=dia + "/" + mes + "/" + agnomarcado_aux.substring(2,4)
		window.opener.document.formulario.R_Fecha_usr.value = aux
	}
	window.close()
}

function bisiesto(agno) {
	if (((agno%4==0) && (agno%100!=0)) || (agno%400==0)) return true;
	else return false;
}

function escribir(texto,bloque) {
	//alert(bloque)
	if (ns4)
		{
		aux = eval(bloque)
		aux.open()
		aux.write(texto)
		aux.close()
		}
	else
		document.all[bloque].innerHTML=texto
}

function borrar() {
	for(i=1;i<43;i++) {
		if (ns4) casilla="document.Calendario.document.CalendarioCelda"+i+".document"
		else casilla="CalendarioCelda"+i
		contenido=''
		escribir(contenido,casilla)
	}

}


   function cargar_calendario_origen()
  {
    alert()
	document.myform.origen_destino.value='origen'
	window.open('calendario.html','Vernatura','scrollbars=no,resizable=no,width=210,height=210,top=200,left=400')
  }

  function cargar_calendario_destino()
  {
	document.myform.origen_destino.value='destino'
	window.open('calendario.jsp','Vernatura','scrollbars=no,resizable=no,width=210,height=210,top=200,left=400')
  }

    function cargar_calendario(nom_campo,aplicacion)
  {
	 document.myform.origen_destino.value=nom_campo
	 document.myform.aplicacion.value=aplicacion
       //  alert(aplicacion)
	window.open('calendario.html','Vernatura','scrollbars=no,resizable=no,width=210,height=210,top=200,left=400')
  }


 //function phpcal(id,usr,nomcapa){
 function phpcal(id,nomcapa){
 // alert(id+" / "+usr)

    if (document.getElementById(nomcapa) == undefined){
	//peque_pag("index.php?p=actualiza&arg='consul','certamenes','id="+id+"','',false,true&blanca=true&logo=true",550,400)  ;
	document.location.href="index.php?p=actualiza&arg='consul','certamenes','id="+id+"','',false,true" ;
    }else{
      loadPage('caja_datos',null,"index.php?p=actualiza&arg='consul','certamenes','id="+id+"','',false,true,true&nada=true");
    }
}
 function panasoc(id,nomcapa){
 // alert(id+" / "+usr)
    if (document.getElementById(nomcapa) == undefined){
	peque_pag("index.php?p=actualiza&arg='consul','asociados','id_asoc=\""+id+"\"','',false,true&blanca=true&logo=true",550,400)  ;
    }else{
      loadPage('caja_datos',null,"index.php?p=actualiza&arg='consul','asociados','id_asoc=\""+id+"\"','',false,true,true&nada=true");
    }
}
//**********************************************************
function valores_buscar_cert(url_ve,corto,nom_form){
//alert(corto);
//alert(show_props(document.forms.myform.tipo_evento));
evento_ferias="";
evento_otros="";
mes_trae="";
dia_trae="";
ano_trae=	"";
algo="d=document.forms."+nom_form+";";
eval(algo);
//alert(d);
//alert(nom_form)
if (corto){
//alert("Es cotrto");
	lst_Asociado="";
	  tipo_ufi=d.ufi;
	  tipo_qafe=d.qafe;
	  tipo_icex=d.ICEX;
	  evento_ferias="S"
}else{
	//alert("no Es cotrto");
	lst_Asociado=d.Asociado_sele.options[document.forms.myform.Asociado_sele.selectedIndex].value;
	  tipo_ufi="";
	  tipo_qafe="";
	  tipo_icex="";
	//evento_ferias=(document.forms.myform.ferias.checked)?"&eventos_f=S":"";
	//evento_otros=(document.forms.myform.otros_eventos.checked)?"&eventos_o=S":"";

}

mes_trae=d.mes_trae.options[d.mes_trae.selectedIndex].value;
ano_trae=d.ano_trae.options[d.ano_trae.selectedIndex].value;
dia_trae=d.dia_trae.options[d.dia_trae.selectedIndex].value;
  tipo_evento=d.tipo_evento.value;
 //alert(tipo_evento+"...."+typeof tipo_evento);
  tipo_evento=(typeof tipo_evento!="undefined")?"&tipo_evento="+tipo_evento+"":"";
if (dia_trae!="" && mes_trae!="" && ano_trae!="") {
	if (comprobarFecha(dia_trae, mes_trae,ano_trae)==false) {
		alert ("Fecha Introducida ("+dia_trae+"/"+mes_trae+"/"+ano_trae+") Erronea");
		return void(0);
	}
}

//alert(mes_trae+"/"+dia_trae+"/"+ano_trae+"/"+evento_ferias+"/"+ tipo_evento+"/");
  lst_Grupo=d.Grupo_sele.options[d.Grupo_sele.selectedIndex].value;
  lst_Ciudad=d.Ciudad_sele.options[d.Ciudad_sele.selectedIndex].value;

  //lst_Grupo=document.forms.myform.Grupo_sele.options[document.forms.myform.Grupo_sele.selectedIndex].value;
 // lst_Ambito=document.forms.myform.Ambito.options[document.forms.myform.Ambito.selectedIndex].value;
  //lst_dirigido=document.forms.myform.dirigido.options[document.forms.myform.dirigido.selectedIndex].value;
  //tipo_Ciudad=document.forms.myform.Ciudad_sele.value;
  //tipo_grupo=document.forms.myform.Grupo_sele.value;
//alert(tipo_Ciudad+"/"+tipo_grupo)
 // alert(document.forms.myform.ufi.value)
  tipo_Nombre_del_Certamen=d.Nombre_del_Certamen.value;
  //tipo_claves=document.forms.myform.claves.value;
  url_ve+=(lst_Asociado!="")?"&Asociado="+ lst_Asociado+"":"";
  url_ve+=(tipo_Nombre_del_Certamen!="")?"&Nombre_del_Certamen="+tipo_Nombre_del_Certamen+"":"";
  //url_ve+=(tipo_claves!="")?"&claves="+tipo_claves+"":"";
  url_ve+=(lst_Grupo!="")?"&Grupo="+lst_Grupo+"":"";
  url_ve+=(lst_Ciudad!="")?"&Ciudad="+lst_Ciudad+"":"";
  //alert(tipo_ufi.checked);
  //url_ve+=(lst_Ambito!="")?"&Ambito="+lst_Ambito+"":"";
  //url_ve+=(lst_dirigido!="")?"&dirigido="+lst_dirigido+"":"";
  url_ve+=(tipo_ufi.checked)?"&ufi=S":"";
  url_ve+=(tipo_qafe.checked)?"&qafe=S":"";
  url_ve+=(tipo_icex.checked)?"&ICEX=S":"";
 // url_ve+=(tipo_qafe!="")?"&qafe="+tipo_qafe+"":"";
  //url_ve+=(tipo_icex!="")?"&icex="+tipo_icex+"":"";
  url_ve+=(dia_trae!="")?"&dia_trae="+dia_trae+"":"";
  url_ve+=(mes_trae!="")?"&mes_trae="+mes_trae+"":"";
  url_ve+=(ano_trae!="")?"&ano_trae="+ano_trae+"":"";
  //url_ve+=(evento_ferias!="")?evento_ferias+"":"";
  //url_ve+=(evento_otros!="")?evento_otros+"":"";
  url_ve+=(tipo_evento!="" && tipo_evento!="undefined")?tipo_evento:"";

  
//url_ve="index.php?p=cal_fechas&arg="+tipo_listado+",'"+lst_tipo+"',"+lst_mes+","+lst_ano+",1,1,null,null, certamenes.nombre_del_certamen"+"&nada=true"+((tipo_evento=="")?"":"&tevento="+tipo_evento);
//ok  url_ve="javascript:void(0)"
   //url_ve="index.php?p=calendario&arg='"+tipo_listado+":"+lst_tipo+":"+lst_mes+":"+lst_ano+"'&nada=true";
//alert(url_ve);
  //document.write(url_ve);
//alert("--->"+url_ve);
if (true || corto){
	url_ve1=url_ve.replace("&nada=true","")
//alert(url_ve);

	document.location.href=url_ve1;
}else{
	//loadPage("lista_certa",null,url_ve);
}
}
function valores_buscar(){
  lst_mes=document.forms.datos.mes.options[document.forms.datos.mes.selectedIndex].value;
  lst_ano=document.forms.datos.ano.options[document.forms.datos.ano.selectedIndex].value;
  tipo_listado=document.forms.datos.tipo.options[document.forms.datos.tipo.selectedIndex].value;
 //OK Tipo Eventos tipo_evento=document.forms.datos.tipoeventos.options[document.forms.datos.tipoeventos.selectedIndex].value; 
 tipo_evento="";
 // alert(tipo_evento);

    if (tipo_listado=="blanco"){
       alert("Selecione Tipo de Listado")
       return
    }else{
		if (lst_mes=="" && lst_ano==""){
			alert("Introduzca Mes,Año o ambos")
	    return
		}
	}
//    alert(show_props(document.forms,"df"));

  // alert(tipo_listado);
    nom_lst=tipo_listado+"lst";
    nom_frm=tipo_listado+"_frm";
 //   if (is_nav4up) {
 //	  // alert(nom_frm);
 //	  dcf=document.layers[tipo_listado].document.forms
 //	  //alert(show_props(eval("dcf."+nom_frm+"."+nom_lst),"dcf1"));
 //	  dcf_lst=eval("dcf."+nom_frm+"."+nom_lst);
 // } else {
 //	  //dcf=document.layers[tipo_listado].document.forms
 //	  dcf_lst=eval("document.forms."+nom_frm+"."+nom_lst);
 //	  //lst_tipo=document.forms.datos.tipo.options[document.forms.datos.tipo.selectedIndex].value;
 //
 // }
//  lst_tipo=dcf_lst.options[dcf_lst.selectedIndex].value;
lst_tipo=document.forms.datos.menu2.options[document.forms.datos.menu2.selectedIndex].value;
//  alert(lst_tipo)

  if (lst_tipo=="" || lst_tipo==null){
     lst_tipo="TODOS"
  }else{
     lst_tipo=replaceString(" ", "%20",lst_tipo)
  }
  if (lst_mes==null || lst_mes==""){
  lst_mes="null";
  }
  if (lst_ano==null || lst_ano==""){
  lst_ano="null";
  }
//alert(lst_mes+"/"+lst_ano);
  //  lst_tipo=lst_tipo.replace(" ", "%20")
  //  lst_tipo=lst_tipo.replace(" ", "%20")
  //alert(lst_tipo)
//  alert("Tipo Listado "+tipo_listado+" Buscar "+lst_tipo+" y Mes/Año : "+lst_mes+"/"+lst_ano);

  //document.location="afe_bd.php3?|calendario('"+tipo_listado+":"+lst_tipo+":"+lst_mes+":"+lst_ano+"')"+usuar();
   //document.location="index.php?p=calendario&arg='"+tipo_listado+":"+lst_tipo+":"+lst_mes+":"+lst_ano+"'";
   //calendario("ciudad:TODOS:".$intMonth.":".$intYear.":fechas.ffi ASC,certamenes.nombre_del_certamen ASC",false,false)
   /*
 $tipo_listado -> ciudad
 $buscar_listado_orig -> ,TODOS
 $mes_listado ->12
 $ano_listado -> ,2005
 $camp_buscar -> ,1
 $buscar_listado -> ,1,
 $cad_buscar -> select * from certamenes where 1 like '%1%' and f_inicial like '%2005-12%',
$orden_trae -> fechas.ffi ASC
$titu_listado -> certamenes.nombre_del_certamen
   , ASC,Ciudad=TODOS Mes/Mounth : Diciembre/December Año/Year : 2005,NULL,
   cal_fechas(,,,,,,,,,NULL,$pinta_form);*/
 url_ve="index.php?p=cal_fechas&arg="+tipo_listado+",'"+lst_tipo+"',"+lst_mes+","+lst_ano+",1,1,null,null, certamenes.nombre_del_certamen"+"&nada=true"+((tipo_evento=="")?"":"&tevento="+tipo_evento);
//ok  url_ve="javascript:void(0)"
   //url_ve="index.php?p=calendario&arg='"+tipo_listado+":"+lst_tipo+":"+lst_mes+":"+lst_ano+"'&nada=true";
//alert(url_ve);
  //document.write(url_ve);
  //alert(url_ve);
   loadPage("lst_eventos",null,url_ve)
   //document.location="index.php?p=calendario&arg='"+tipo_listado+":"+lst_tipo+":"+lst_mes+":"+lst_ano+"'";
//  document.location=(\'../frame_cas.htm\')
  //muesta_consulta("certamenes","select * from certamenes where id_key like '%SILLEDA001%'","","",0,true)
}

