var esNS, esIE, esDHTML, esNS6, accesoCAPAS;
ndiv=0; 
ndiv1=0;
asig=1;
ocul=1;
suma=0;
var divanterior="";
if (parseInt(navigator.appVersion)>=4)
	{
	esDHTML = true;
	if ((navigator.appName=="Netscape") && (parseInt(navigator.appVersion)<5))
		{esNS = true;esIE = false; esNS6 = false;}
	else
		{
	    if ((navigator.appName=="Netscape") && (parseInt(navigator.appVersion)>=5))
			{esNS = false;esIE = false; esNS6 = true;}
	    else
			{esNS = false;esIE = true; esNS6 = false;}
		}
	}
else
	{
	esDHTML = false;
	if (navigator.appName=="Netscape")
		{esNS = true;esIE = false;}
	else
		{esNS = false;esIE = true;}
	}
/******************RECARGA PARA NETSCAPE COMM*****************************/
	function cambiatexto(valor)
	{
	if ((valor!=null)&&(valor!=''))
		{document.all.textoimg.innerHTML=valor;}
	else
		{document.all.textoimg.innerHTML='selecciona la opción que buscas';}
	}
	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 MM_findObj(n, d) { //v4.0
	  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 && document.getElementById) x=document.getElementById(n); return x;
	}

	function MM_showHideLayers() { //v3.0
	  var i,p,v,obj,args=MM_showHideLayers.arguments;
	  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
	    obj.visibility=v; }
	}

	function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	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 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];}}
	}

/******************FUNCIONES *****************************/

function cambiaalcargar(stname,stimg){
	document.images[stname].src="./img/barrios/Zona"+stimg+".jpg";
	stdiv="DIVZONA"+stimg;
	if (esNS){
		formulario=document.layers[stdiv];
		}
	else{
		formulario=document.getElementById(stdiv).style;
		}
	if (document.images[stname].x){
		stleft=document.images[stname].x;
		stleft=stleft+parseInt(document.images[stname].width);
		}
	else{
		if (parseInt(screen.width)>800){
			stleft=680;}
		else{
			stleft=570;}
		}
	for (i=1;i<9 ;i++){
		stdivfor="DIVZONA"+i;
		if (esNS){
			formulariofor=document.layers[stdivfor];
			}
		else{
			formulariofor=document.getElementById(stdivfor).style;
			}
		formulariofor.visibility="hidden";
	}
	formulario.left=stleft;
	formulario.visibility="visible";
	
}

function cambiaimagen(stname,zona){
	if (esNS){
		formulario=document.formidbarrio;
		}
	else{
		formulario=document.getElementById("formidbarrio");
		}
	formulario.idzona.value=zona;
	formulario.fidbarrio.value='';
	formulario.submit();
}
function aniadirfavoritos()
{
	if (esIE){
		window.external.AddFavorite('http://aspdesarrollo/webcic/ana/','Nueva web de CIC en construccion');}
	else
		{//document.handleEvent(window.event.ctrlKey);
		alert('Hagalo manualmente o pulse sobre el teclado Ctrl-D');}
}
function irdesdeMenu(pag,stidmenu,stidpadre,stfuncion)
{
	formulario='';
	if (esNS){
		formulario=document.formfuncion;}
	else{
		formulario=document.getElementById("formfuncion");}

	formulario.idhijo.value=stidmenu;
	formulario.idpadre.value=stidpadre;
	formulario.funcion.value=stfuncion;
	formulario.action=pag;
	formulario.submit();
}
function iraAmigo(){
	formulario='';
	if (esNS){
		formulario=document.formamigo;}
	else{
		formulario=document.getElementById("formamigo");}
	formulario.submit();
}
function pasaletra(val){
	formulario='';
	if (esNS){
		formulario=document.formbusq;}
	else{
		formulario=document.getElementById("formbusq");}
	formulario.letra.value=val;
	formulario.submit();
}
/**************Comprueba que el string que le pasamos son todo numeros****************/
function soncantidades(val)
{
  var test1=',0123456789';
  var test2=',0123456789';
  var c;
  var decimal=false;
  var numero=true;
  while(val.indexOf(" ")!=-1){
		val=val.substring(1,val.length);
  }
  for(var i=0;i < val.length;i++)
    {
	c=test2.indexOf(val.charAt(i));
	if (c<0){
		numero=false;
		}
	}
  if (numero==false)
    {
	alert("Error. Introduzca un Número.");
    return false;
	}
  return true;
}
function sonnumeros(val)
{
  var test1='0123456789';
  var test2='0123456789';
  var c;
  var decimal=false;
  var numero=true;
  while(val.indexOf(" ")!=-1){
		val=val.substring(1,val.length);
  }
  for(var i=0;i < val.length;i++)
    {
	c=test2.indexOf(val.charAt(i));
	if (c<0){
		numero=false;
		}
	}
  if (numero==false)
    {
	alert("Error. Introduzca un Número.");
    return false;
	}
  return true;
}

/**************funcion que nos abre una ventanita****************/
// abrir ventana nueva
function abrir_vent(pag,vent,tam_x,tam_y,scroll,resize,menu,tool,status) {
 var pos_x, pos_y;
 scroll = (scroll==null) ? false : scroll;
 scroll = (scroll) ? "yes" : "no";
 resize = (resize==null) ? false : resize;
 resize = (resize) ? "yes" : "no";
 menu = (menu==null) ? false : menu;
 menu = (menu) ? "yes" : "no";
 tool = (tool==null) ? false : tool;
 tool = (tool) ? "yes" : "no";
 status = (status==null) ? false : status;
 status = (status) ? "yes" : "no";
 tam_x = (tam_x==null) ? 550 : tam_x;
 tam_y = (tam_y==null) ? 350 : tam_y;

 if (esNS || esIE || esDHTML || esNS6) {
 	var alto=window.screen.height;
 	var ancho=window.screen.width;
	pos_x = (ancho-tam_x)/2;
	pos_y = (alto-tam_y)/2-20;
 } else {
 	pos_x = 0;
 	pos_y = 0;
 }

window.open(pag, vent, "toolbar="+tool+",directories=no,menubar="+menu+",scrollbars="+scroll+",location=no,status="+status+",resizable="+resize+",width="+tam_x+",height="+tam_y+",left="+pos_x+",top="+pos_y);
}

function abrirventana(sUrl)
{
	window.open(sUrl,"verificar","toolbar=no,height=200px,width=400px,screenX=150px,screenY=125px,scrollbars");
	return;
}

function abrirventDoc(sUrl,stheight,stwidth)
{
if (stDocuw!=''){
	stUrl=stDocuw+sUrl;
	window.open(stUrl,"Docuware","toolbar=no,height="+stheight+"px,width="+stwidth+"px,screenX=150px,screenY=125px,resizable,scrollbars");
	}
	return;
}

/**************INCLUSIÓN DE CAPAS Y ESTILOS****************/
/*if (esIE)
	{
	document.write("<LINK REL='stylesheet' TYPE='text/css' HREF='./inc/estilos.css'>");
	}
else
	{
	if (esNS)
		{
		document.write("<LINK REL='stylesheet' TYPE='text/css' HREF='./inc/estilosns.css'>");
		}
	else
		{
			document.write("<LINK REL='stylesheet' TYPE='text/css' HREF='./inc/estilosns.css'>");
		}
	}
*/
/*********************************************************/

//#################
//### Objeto Hora
//#################
function HoraObj(Hora)
{
  var horas, minutos, segundos, HoraS, indice
 
  this.EsHora = false;
  this.Separadores = new Array();
  HoraS = new String(Hora);

  if (!(HoraS.length < 3 || HoraS.length > 8))
  {
	for (indice=0; indice < HoraS.length; indice++)
	{
		if (HoraS.charAt(indice) < "0" || HoraS.charAt(indice) > "9" )
		{
			if (this.Separadores.length == 0)
			{
				this.Separadores[0] = indice;
			}
			else
			{
				this.Separadores[this.Separadores.length] = indice;
			}
		}
	}
	if (HoraS.length < 8 && this.Separadores.length == 1)
	{
		horas = Number(HoraS.substring(0,this.Separadores[0]));
		minutos = Number(HoraS.substring(this.Separadores[0] + 1,HoraS.Length));
		segundos = 0;

		if (horas >= 0 && horas < 24 && minutos >= 0 && minutos <=59)
		{
			this.EsHora = true;
		}

//		if (horas >= 0 && horas <= 24 && minutos >= 0 && minutos <=59)
//		{
//			if (horas == 24)
//			{
//				if (minutos == 0)
//				{
//					this.EsHora = true;
//				}
//			}
//			else
//			{
//				this.EsHora = true;
//			}
//		}

	}
	if (this.Separadores.length == 2)
	{
		if (HoraS.charAt(this.Separadores[0]) == HoraS.charAt(this.Separadores[1]))
		{
			horas = Number(HoraS.substring(0,this.Separadores[0]));
			minutos = Number(HoraS.substring(this.Separadores[0] + 1,this.Separadores[1]));
			segundos = Number(HoraS.substring(this.Separadores[1] + 1,HoraS.length));

			if (horas >= 0 && horas < 24 && minutos >= 0 && minutos <=59 && segundos >= 0 && segundos <= 59)
			{
				this.EsHora = true;
			}

//			if (horas >= 0 && horas <= 24 && minutos >= 0 && minutos <=59 && segundos >= 0 && segundos <= 59)
//			{
//				if (horas == 24)
//				{
//					if (minutos == 0 && segundos == 0)
//					{
//						this.EsHora = true;
//					}
//				}
//				else
//				{
//					this.EsHora = true;
//				}
//			}
		}
	}
  }

  if (this.EsHora == true)
  {
	this.horas = horas;
	this.minutos = minutos;
	this.segundos = segundos; 	
	this.ComoCadena = String(HoraS);

	if (this.Separadores.length == 1)
	{
		if (this.Separadores[0] == 1) 
		{
			this.Separadores[0] = 2;
			this.Separadores[1] = this.Separadores[1] + 1;
			HoraS = new String("0" + String(HoraS));
			this.ComoCadena = String(HoraS); 
		}
		if (HoraS.length != 5)
		{
			HoraS = String(HoraS.substring(0,3) + "0" + HoraS.substring(3,HoraS.length) + ":00");
			this.ComoCadena = new String(HoraS);
		}
		else
		{
			HoraS = String(this.ComoCadena + ":00");
			this.ComoCadena = new String(HoraS);
		}
	}
	else
	{
		if (this.Separadores[0] == 1) 
		{
			this.Separadores[0] = 2;
			this.Separadores[1] = this.Separadores[1] + 1;
			HoraS = new String("0" + String(HoraS));
			this.ComoCadena = String(HoraS); 
		}
		if (this.Separadores[1] == 4) 
		{
			this.Separadores[1] = 5;
			HoraS = new String(HoraS.substring(0,3) + "0" + HoraS.substring(3,HoraS.length));
			this.ComoCadena = String(HoraS); 
		}
		if (HoraS.length != 8)
		{
			HoraS = String(HoraS.substring(0,6) + "0" + HoraS.substring(6,HoraS.length));
			this.ComoCadena = String(HoraS); 
		}
	}
	HoraS = new String(HoraS.substring(0,2) + ":" + HoraS.substring(3,5) + ":" + HoraS.substring(6,8));
	this.Valor = new String(HoraS.substring(0,2) + HoraS.substring(3,5) + HoraS.substring(6,8));
	this.ComoCadena = String(HoraS);
  }
  else
  {
	this.ComoCadena = "";
	this.Valor = "";
	this.horas = 0;
	this.minutos = 0;
	this.segundos = 0; 
  }
}


//#################
//### Objeto Fecha
//#################


function Invertida()
{
var FechaAlReves
var FechaS

FechaS = new String(this.ComoCadena);
FechaAlReves = FechaS.substring(6,10) + FechaS.substring(3,5) + FechaS.substring(0,2);
return FechaAlReves;
}
function FechaObj(Fecha)
{
  var ano, mes, dia, FechaS, indice
 
  this.EsFecha = false;
  this.Separadores = new Array();
  FechaS = new String(Fecha);
 
  if (!(FechaS.length < 8 || FechaS.length > 10))
  {
     for (indice=0; indice<FechaS.length; indice++)
     {
       if (FechaS.charAt(indice) < "0" || FechaS.charAt(indice) > "9" )
       {
         if (this.Separadores.length == 0)
         {
           this.Separadores[0] = indice;
         }
         else
           this.Separadores[this.Separadores.length] = indice;
       }
     }
     if (this.Separadores.length == 2)
     {
       if (FechaS.charAt(this.Separadores[0]) == FechaS.charAt(this.Separadores[1]))
       {
         dia = Number(FechaS.substring(0,this.Separadores[0]));
         mes = Number(FechaS.substring(this.Separadores[0] + 1,this.Separadores[1]));
         ano = Number(FechaS.substring(this.Separadores[1] + 1,FechaS.length));
         if (ano > 1899 && mes > 0 && mes < 13 && dia < 32 && dia > 0) 
         {
           if (mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes ==8 || mes == 10 || mes == 12)  
             {this.EsFecha = true;}
           else
             {
               if (mes == 2)
               {
                 if (dia < 29)
                   {this.EsFecha =true;}
                 else
                   if (dia == 29 && ano % 4 == 0)
                   {this.EsFecha = true;}
               }
               else
                 if (dia < 31)
                   {this.EsFecha = true;}  
             }
         }
       }
     }
  }
  if (this.EsFecha == true)
  {
    this.ano = ano;
    this.mes = mes;
    this.dia = dia; 
    this.ComoCadena = String(FechaS); 
    if (this.Separadores[0] == 1) 
    {
      this.Separadores[0] = 2;
      this.Separadores[1] = this.Separadores[1] + 1;
      FechaS = new String("0" + String(FechaS));
      this.ComoCadena = String(FechaS); 
    } 
    if (this.Separadores[1] == 4) 
    {
      this.Separadores[1] = this.Separadores[1] + 1;
      FechaS = new String(FechaS.substring(0,3) + "0" + FechaS.substring(3,FechaS.length));
      this.ComoCadena = String(FechaS); 
    }
	FechaS = new String(FechaS.substring(0,2) + "/" + FechaS.substring(3,5) + "/" + FechaS.substring(6,10));
	this.ComoCadena = String(FechaS);
  }
  else
  {
    this.ComoCadena = "";
    this.ano = 0;
    this.mes = 0;
    this.dia = 0; 
  }
  this.Invertida = Invertida;
}
///////////////////////////////////////////////////////////

//***********************************************************************
//***********************************************************************
//Semicrol, S.L.........................................................*
//Fecha Creacion:02/05/2002 Fecha Modificación:02/05/2002...............*
//Librería JavaScript:campo.js..........................................*
//Funcion:Crea objetos campo y valida el contendio de los mismos........* 
//Valida datos de tipo entero,decimal,texto,password y checkbox.........*
//A los campos de tipo checkbox se les da a la propiedad value el valor.*
//FALSE o TRUE..........................................................*
//***********************************************************************
//***********************************************************************
function LocalizarTag()
{
	var MiFormulario;
	var MiCampo;
	var elemento;

	MiFormulario = document.forms[this.Formulario].elements;
	for (elemento = 0; elemento < MiFormulario.length; elemento ++)
	{
		MiCampo = MiFormulario[elemento];
		if ((MiCampo.type=='text')||(MiCampo.type=='textarea')||(MiCampo.type=='checkbox')||(MiCampo.type=='password')||(MiCampo.type=='radio')||(MiCampo.type=='file'))
		{
			if (MiCampo.name==this.Nombre)
			{     
				this.ObjetoHtml = MiCampo;
				return true;
			}
		}
	}
	window.alert("El campo " + this.Nombre  + " no se ha encontrado en el formulario " + this.Formulario + ".")
	return false;
}
//***********************************************************************
//***********************************************************************
function ValidarEntero()
{
	var entero;
	var CadenaNumero;
	var correcto = false;
	entero = Number(this.ObjetoHtml.value.replace(/ /g,""));
	CadenaNumero = entero.toString();//obtener la representancion en forma de cadena del objeto number.
	
	if (isNaN(entero))
	{
		correcto = false;
	}
	else
	{		
		if (CadenaNumero.indexOf('.',0)==-1) //si es numerico y no tiene decimales
		{
			if (this.ObjetoHtml.value.replace(/ /g,""))
			{
				this.ObjetoHtml.value = entero.valueOf();
			}
			else
			{
				this.ObjetoHtml.value = this.ObjetoHtml.value.replace(/ /g,"");//se quitan los espacios en blanco
			}
			return true;
		}
	}
	window.alert("El campo " + this.Descripcion + " solo admite valores numéricos enteros positivos o negativos.");
	return false;
	
}
//***********************************************************************
//***********************************************************************
function ValidarDecimal()
{
	var decimal;
	var CadenaNumero;
	CadenaNumero = this.ObjetoHtml.value;
	CadenaNumero = CadenaNumero.replace(/,/,".");
	decimal = Number(CadenaNumero);
	if (isNaN(decimal))
	{
		window.alert("El campo " + this.Descripcion + " solo admite valores numéricos decimales positivos o negativos.");
		return false;
	}
	else
	{
		if (CadenaNumero.replace(/ /g,"")) //si existe algo en el campo
		{
			this.ObjetoHtml.value = decimal.valueOf();
		}
		else 
		{
			this.ObjetoHtml.value = CadenaNumero.replace(/ /g,""); //si tiene espacios en blanco se quitan
		}
		return true;
	}
}
//***********************************************************************
//***********************************************************************
function ValidarFecha()
{
	var MiFecha;
	var cadena;
	if (this.ObjetoHtml.value != '')
	{
		MiFecha = new FechaObj(this.ObjetoHtml.value);
		if (MiFecha.EsFecha==false)
		{
			window.alert("El formato del campo " + this.Descripcion + " no es correcto. Utilice el formato dd-mm-aaaa.");
			return false;
		}
		else
		{
			this.ObjetoHtml.value = MiFecha.ComoCadena;
			return true;
		}
	}
}
//***********************************************************************
//***********************************************************************
function ValidarHora()
{
	var MiHora;
	var cadena;
	if (this.ObjetoHtml.value != '')
	{
		MiHora = new HoraObj(this.ObjetoHtml.value);
		if (MiHora.EsHora==false)
		{
			window.alert("El formato del campo " + this.Descripcion + " no es correcto. Utilice el formato hh:mm:ss.");
			return false;
		}
		else
		{
			this.ObjetoHtml.value = MiHora.ComoCadena;
			return true;
		}
	}
}
//***********************************************************************
//***********************************************************************
function EstablecerValor()
{
	if (this.ObjetoHtml.checked)
	{
		this.ObjetoHtml.value = 'TRUE'; 
	}
	else
	{
		this.ObjetoHtml.value = 'FALSE'; 
	}
}
//***********************************************************************
//***********************************************************************
function Validar()
{
	var ValorCampo = "";

	if (this.ObjetoHtml==null)
	{
		if (this.LocalizarTag()==false)//localizar el elemento por la propiedad type
		{
			return false;
		}
	}

	if (this.Requerido==true)
	{
		ValorCampo = this.ObjetoHtml.value;
		ValorCampo = ValorCampo.replace(/ /g,"");//remplazar los espacios en blanco por nada
		if (ValorCampo.length==0) //si la longitud es cero
		{
			window.alert("El campo " + this.Descripcion + " es de introducción obligatoria.");
			return false;
		}
		
	}
	if (isNaN(this.TamanoMaximo)==false)
	{
		ValorCampo = this.ObjetoHtml.value;
		ValorCampo = ValorCampo.replace(/ /g,"");//remplazar los espacios en blanco por nada
		if (ValorCampo.length > this.TamanoMaximo)
		{
			window.alert("El campo " + this.Descripcion + " tiene " + ValorCampo.length + " caracteres. Debe tener como máximo " + this.TamanoMaximo + " caracteres.");
			return false;
		}
	}

	switch (this.TipoDato)
	{
		case 'I': //valores enteros
			if (this.ValidarEntero()==false) return false;
			break;
		case 'F': //valores decimales
			if (this.ValidarDecimal()==false) return false;
			break;
		case 'D': //valores tipo fecha
			if (this.ValidarFecha()==false) return false;
			break;
		case 'T': //valores tipo hora
			if (this.ValidarHora()==false) return false;
			break;
		case 'B': //valores tipo Booleano
			this.EstablecerValor();
			return false;
			break;
		case 'S': //valores de cadena
			break;
		
	}
}
//***********************************************************************
//***********************************************************************
function Campo(Nombre,Requerido,Descripcion,TipoDato,Formulario,TamanoMaximo)
{
	this.Nombre      = Nombre;
	this.Requerido   = Requerido;
	this.Descripcion = Descripcion;
	this.TipoDato    = TipoDato;
	this.Formulario  = Formulario;
	this.TamanoMaximo = TamanoMaximo;
	this.CadenaValores = null;
	this.ObjetoHtml = null;
	this.LocalizarTag   = LocalizarTag;
	this.ValidarEntero  = ValidarEntero;
	this.ValidarDecimal = ValidarDecimal;
	this.ValidarFecha   = ValidarFecha;
	this.ValidarHora   = ValidarHora;
	this.EstablecerValor = EstablecerValor;
	this.Validar        = Validar;
}
//***********************************************************************
//***********************************************************************
function AnadirCampo(Nombre,Requerido,Descripcion,TipoDato,TamanoMaximo)
{
	var elemento ;
	var MiCampo;
      	elemento = this.Campos.length;
	MiCampo = new Campo(Nombre,Requerido,Descripcion,TipoDato,this.Nombre,TamanoMaximo);
	this.Campos[elemento] = MiCampo;

}
//***********************************************************************
//***********************************************************************
function Validaciones()
{
	var elemento;
	var MiCampo;
	var MiFormulario;

	for (elemento=0; elemento < this.Campos.length; elemento ++)
	{
		MiCampo = this.Campos[elemento];
		if (MiCampo.Validar()==false)
		{
			MiFormulario = document.forms[MiCampo.Formulario];
			if (MiCampo.ObjetoHtml!=null)
			{
				//MiFormulario.elements[MiCampo.Nombre].focus();
				MiCampo.ObjetoHtml.focus();
			}
			return false;
		}
	}
	return true;
}
//***********************************************************************
//***********************************************************************
function MostrarRadios()
{
	var formulario = document.forms[this.Nombre];
	var ColeccionRadios = formulario.Radio;
	var Indice;

	if (ColeccionRadios != null)
	{
		if (ColeccionRadios.length > 0)
		{
			for (Indice=0; Indice<ColeccionRadios.length; Indice++)
			{
				ColeccionRadios[Indice].style.visibility = "visible";
			}
		}
		else
		{
			ColeccionRadios.style.visibility = "visible";
		}
		return true;
	}
	else
	{
		return false;
	}
}
//***********************************************************************
//***********************************************************************
function MostrarChecks()
{
	var formulario = document.forms[this.Nombre];
	var ColeccionChecks = formulario.Check;
	var Indice;

	if (ColeccionChecks != null)
	{
		if (ColeccionChecks.length > 0)
		{
			for (Indice=0; Indice<ColeccionChecks.length; Indice++)
			{
				ColeccionChecks[Indice].style.visibility = "visible";
				ColeccionChecks[Indice].checked = false;
			}
		}
		else
		{
			ColeccionChecks.style.visibility = "visible";	
			ColeccionChecks.checked = false;
		}
		return true;
	}
	else
	{
		return false;
	}
}
//***********************************************************************
//***********************************************************************
function MostrarCampo(NombreCampo)
{
	var formulario = document.forms[this.Nombre];
	var ColeccionCampos = formulario.all.tags("input");
	var Indice;

	if (ColeccionCampos != null)
	{
		if (ColeccionCampos.length > 0)
		{
			for (Indice=0; Indice<ColeccionCampos.length; Indice++)
			{
				if (ColeccionCampos[Indice].name == NombreCampo)
				{
					ColeccionCampos[Indice].style.visibility = "visible";
				}
			}
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}
//***********************************************************************
//***********************************************************************
function OcultarRadios()
{
	var formulario = document.forms[this.Nombre];
	var ColeccionRadios = formulario.Radio;
	var Indice;

	if (ColeccionRadios != null)
	{
		if (ColeccionRadios.length > 0)
		{
			for (Indice=0; Indice<ColeccionRadios.length; Indice++)
			{
				ColeccionRadios[Indice].style.visibility = "hidden";
			}
		}
		else
		{
			ColeccionRadios.style.visibility = "hidden";
		}
		return true;
	}
	else
	{
		return false;
	}
}
//***********************************************************************
//***********************************************************************
function OcultarChecks()
{
	var formulario = document.forms[this.Nombre];
	var ColeccionChecks = formulario.Check;
	var Indice;

	if (ColeccionChecks != null)
	{
		if (ColeccionChecks.length > 0)
		{
			for (Indice=0; Indice<ColeccionChecks.length; Indice++)
			{
				ColeccionChecks[Indice].style.visibility = "hidden";
			}
		}
		else
		{
			ColeccionChecks.style.visibility = "hidden";
		}
		return true;
	}
	else
	{
		return false;
	}
}
//***********************************************************************
//***********************************************************************
function OcultarCampo(NombreCampo)
{
	var formulario = document.forms[this.Nombre];
	var ColeccionCampos = formulario.all.tags("input");
	var Indice;

	if (ColeccionCampos != null)
	{
		if (ColeccionCampos.length > 0)
		{
			for (Indice=0; Indice<ColeccionCampos.length; Indice++)
			{
				if (ColeccionCampos[Indice].name == NombreCampo)
				{
					ColeccionCampos[Indice].style.visibility = "hidden";		
				}
			}
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}
//***********************************************************************
//***********************************************************************
function AlgunCheckSeleccionado()
{
	var formulario = document.forms[this.Nombre];
	var ColeccionChecks = formulario.Check;
	var Indice;
	var Seleccionado = false;

	this.CadenaValores = "";

	if (ColeccionChecks != null)
	{
		if (ColeccionChecks.length > 0)
		{
			for (Indice=0; Indice<ColeccionChecks.length; Indice++)
			{
				if (ColeccionChecks[Indice].checked)
				{
					this.CadenaValores = this.CadenaValores + ColeccionChecks[Indice].value + "|";
					Seleccionado = true;
				}
			}
			if (Seleccionado)
			{
				return true;			
			}
		}
		else
		{
			if (ColeccionChecks.checked)
			{
				this.CadenaValores = ColeccionChecks.value + "|"
				return true;
			}
		}
	}
	return false;
}
//***********************************************************************
//***********************************************************************
function RadioActivo()
{
	var formulario = document.forms[this.Nombre];
	var ColeccionRadios = formulario.Radio;
	var Indice;

	if (ColeccionRadios != null)
	{
		if (ColeccionRadios.length > 0)
		{
			for (Indice=0; Indice<ColeccionRadios.length; Indice++)
			{
				if (ColeccionRadios[Indice].checked)
				{
					return ColeccionRadios[Indice].value;
				}
			}
		}
		else
		{
			return ColeccionRadios.value;
		}
	}
	else
	{
		return 0;
	}
}
//***********************************************************************
//***********************************************************************
function NumeroRadioActivo()
{
	var formulario = document.forms[this.Nombre];
	var ColeccionRadios = formulario.Radio;
	var Indice;

	if (ColeccionRadios != null)
	{
		if (ColeccionRadios.length > 0)
		{
			for (Indice=0; Indice<ColeccionRadios.length; Indice++)
			{
				if (ColeccionRadios[Indice].checked)
				{
					Indice = Indice + 1;
					return Indice;
				}
			}
		}
		else
		{
			return 1;
		}
	}
	else
	{
		return 0;
	}
}
//***********************************************************************
//***********************************************************************
function formulario(Nombre)
{
	this.Nombre = Nombre;
	this.AnadirCampo = AnadirCampo;
	this.Validaciones = Validaciones;
	this.MostrarChecks = MostrarChecks;
	this.MostrarRadios = MostrarRadios;
	this.OcultarChecks = OcultarChecks;
	this.OcultarRadios = OcultarRadios;
	this.RadioActivo = RadioActivo;
	this.NumeroRadioActivo = NumeroRadioActivo;
	this.AlgunCheckSeleccionado = AlgunCheckSeleccionado;
	this.MostrarCampo = MostrarCampo;
	this.OcultarCampo = OcultarCampo;
	this.Campos = new Array();
}
//***********************************************************************
//***********************************************************************
function MostrarAlert(Entidad,CodigoError)
{
	switch(CodigoError)
	{
		case 'I1':
			alert("Se han producido un error en la Inserción.");
			break;
		case 'I2':
			alert("Ya existe un registro con ese Código / Nombre.");
			break;
		case 'D1':
			alert("Se han producido errores en el Borrado.");
			break;
		case 'D2':
			alert("No se han podido borrar algunos registros.");
			break;
		case 'U1':
			alert("Se han producido errores en la modificación.");
			break;
		case 'U2':
			alert("Ya existe un registro con ese Código / Nombre.");
			break;
	}
}
//***********************************************************************
//***********************************************************************
function FechasCorrectas()
	{
		var ObjFechaDesde
		var ObjFechaHasta

		ObjFechaDesde = new FechaObj(document.formulario.FechaPublicacionDesde.value);
		ObjFechaHasta = new FechaObj(document.formulario.FechaPublicacionHasta.value);
							
		if (ObjFechaDesde.Invertida() > ObjFechaHasta.Invertida())
		{
			window.alert('La Fecha de Publicación Desde debe ser anterior a la Fecha de Publicación hasta.');
			document.formulario.FechaPublicacionDesde.focus();
			return false;
		}
		return true;	
	}

	function CambiarTipoBusqueda(Tipo)
	{
		switch (Tipo)
		{
			case 'T' : document.formulario.Titulo.checked = true;
					   document.formulario.Texto.checked = false;
					   break;
			case 'X' : document.formulario.Titulo.checked = false;
					   document.formulario.Texto.checked = true;
					   break;
		}
		document.formulario.TipoBusqueda.value = Tipo;
	}

	function Redireccionar(Operacion)
	{
		if (MiFormulario.Validaciones() == true)
		{
			if (FechasCorrectas() == true)
			{
				switch (Operacion)
				{
					case 'Buscar' : document.formulario.NumeroConsulta.value = 0;
									document.formulario.Movimiento.value = "Buscar";
									document.formulario.submit();		
									break;

					case 'Siguiente' :	if (document.formulario.NumeroConsulta.value != 0)
										{
											if (document.formulario.PaginaActual.value < document.formulario.TotalPaginas.value)
											{
												document.formulario.Movimiento.value = "Siguiente";
												document.formulario.submit();
											}
											else
											{
												window.alert("No hay más páginas.");
											}
										}
										break;

					case 'Anterior' :	if (document.formulario.NumeroConsulta.value != 0)
										{
											if (document.formulario.PaginaActual.value > 1)
											{
												document.formulario.Movimiento.value = "Anterior";
												document.formulario.submit();
											}
											else
											{
												window.alert("No hay más páginas.");
											}
										}
										break;

					case 'IrAPagina' :	if (document.formulario.NumeroConsulta.value != 0)
										{
											if (document.formulario.IrAPagina.value == '' || document.formulario.IrAPagina.value == '0')
											{
												window.alert("Debe indicar el Nº de Página.");
											}
											else
											{
												if (document.formulario.IrAPagina.value > document.formulario.TotalPaginas.value)
												{
													window.alert("Nº de Página inexistente.");
												}
												else
												{
													document.formulario.Movimiento.value = "IrAPagina";
													document.formulario.submit();
												}
											}
										}
										break;
				}
			}
		}
	}

function desplazarse(cint,stname,stdivname){
	//obtenemos el left de las divisiones
	if (document.images[stname].x){
		stleft=document.images[stname].x;
		stleft=parseInt(stleft)+parseInt(document.images[stname].width)-50;
	}
	else{
		if (parseInt(screen.width)>800){
			stleft=680;}
		else{
			stleft=570;}
	}
	
	//ponemos todas las divisiones a ocultas
	posinicio=-1;
	posfin=-1;
	terminar='';
	for (i=0;i<arrayespacios.length;i++){
		stdiv='DIVESPACIO'+arrayespacios[i];
		//arrayespacios contiene todas las divisiones de los espacios de todas las plantas
		if (esNS){
			formulario=document.layers[stdiv];
			}
		else{
			formulario=document.getElementById(stdiv).style;
			}
		formulario.visibility='hidden';
		if (terminar!='S'){
			if ((stdivname!='') && (stdivname==arrayespacios[i])){
				//entra por aquí cuando se hace click en el mapa de una planta
				indicediv=i;
				terminar='S';
				} 
			else{
				//entra por aquí cuando se hace click en el mapa de la planta, cuando se hace click en las flechas
				//cuando se hace click en la descripcion de una planta y te quieres cambiar de planta, y tn cuando se carga la página por primera vez
				if ((posinicio<0) && (varplanta==arrayespacios[i].substr(0,1) )) {posinicio=i;if (cint==0) indicediv=i;}
				if ((posfin<0) && (posinicio>=0) && (varplanta!=arrayespacios[i].substr(0,1)) ){posfin=i-1;}
				}
		}
	}
	if ((posfin<0) && (stdivname=='')) { posfin=arrayespacios.length-1;}
	//buscamos en el array la division que nos toca
	if ((varplanta!='') && (cint!=0)) {
		//indicediv=(indicediv+cint)%(arrayespacios.length);
		indicediv=(indicediv+cint)
		if ((indicediv<0) || (indicediv<posinicio)){indicediv=posfin;}
		if (indicediv>posfin){indicediv=posinicio;}
	}
	else{
		indicediv=(indicediv+cint)%(arrayespacios.length);
		if (indicediv<0){indicediv=arrayespacios.length-1;}
	}
	//mostramos la division que nos toca
	stdiv='DIVESPACIO'+arrayespacios[indicediv];
	if (esNS){
		formulario=document.layers[stdiv];
		}
	else{
		formulario=document.getElementById(stdiv).style;
		}
	if (esNS6){stleft=stleft+35;}
	formulario.left=stleft;
	formulario.visibility='visible';
}
function cambiadivplanta(stplantas,stnombre)
{
	for (i=0;i<arrayplantas.length;i++){
		stdiv='DIVPLANTA'+arrayplantas[i];
		if (arrayplantas[i]!=''){
			if (esNS){
				formulario=document.layers[stdiv];
				}
			else{
				formulario=document.getElementById(stdiv).style;
				}
			//ponemos todas las divisiones ocultas
			formulario.visibility='hidden';
		}
	}
	stdivplanta="DIVPLANTA"+stplantas;
	if (esNS){
		formulario2=document.layers[stdivplanta];
		}
	else{
		formulario2=document.getElementById(stdivplanta).style;
		}
	if (document.images[stnombre].x){
		stleft=document.images[stnombre].x;
		stleft=parseInt(stleft)+parseInt(document.images[stnombre].width)-509;
		}
	else{
		if (parseInt(screen.width)>800){
			stleft=183;}
		else{
			stleft=72;}
		}
	if (esNS6){stleft=stleft+35;}
	varplanta=stplantas;
	formulario2.left=stleft;
	desplazarse(0,stnombre,'');
	formulario2.visibility='visible';
}

function cambiadivision_old(stname,stimg)
{
	//entra cuando seleccionas un espacio dentro de la búsqueda avanzada.
	stdiv="DIVESPACIO"+stimg;
	if (esNS){
		formulario=document.layers[stdiv];
		if (divanterior!="") formulario2=document.layers[divanterior];
		}
	else{
		formulario=document.getElementById(stdiv).style;
		if (divanterior!="") formulario2=document.getElementById(divanterior).style;
		}
	if (document.images[stname].x){
		stleft=document.images[stname].x;
		stleft=parseInt(stleft)+parseInt(document.images[stname].width)-50;
		}
	else{
		if (parseInt(screen.width)>800){
			stleft=680;}
		else{
			stleft=570;}
		}
	if (divanterior!=""){
		formulario2.left=stleft;
		formulario2.visibility="hidden";
		}
	divanterior=stdiv;
	formulario.left=stleft;
	formulario.visibility="visible";
}

function cargadatosinicio(stvisible,stDiv){
	if (esNS){
		formulario=document.layers[stDiv];
		}
	else{
		formulario=document.getElementById(stDiv).style;
		}
	if (document.all){
		stWid=parseInt(document.body.clientWidth);
		stWid=parseInt(stWid-650);
		stleft=parseInt(stWid/2);
		}
	else if (document.layers){
		stWid=parseInt(window.innerWidth);
		stWid=parseInt(stWid-650);
		stleft=parseInt(stWid/2);
		}
	else{
		if (parseInt(screen.width)>800){
			stleft=100;}
		else{
			stleft=25;}
	}
	if (parseInt(screen.width)>800){
		sttop=150;}
	else{
		sttop=100;}
	formulario.left=stleft;
	formulario.top=sttop;
	formulario.visibility=stvisible;
}

function pasoIdFuncion(val,stidmenu,stidpadre,stfuncion,stdestino)
	{
		if (esNS){
			formulario=document.formfuncion;
			}
		else{
			formulario=document.getElementById("formfuncion");
			}
		formulario.idhijo.value=stidmenu;
		formulario.idpadre.value=stidpadre;
		formulario.funcion.value=stfuncion;
		formulario.idbuscar.value=val;
		if (stdestino!=''){
			formulario.action=stdestino;
			}
		else{
			formulario.action=stfuncion;
			}
		formulario.submit();
	}

function Redirecgreservas(Codigo,Imagen)
	{	
		if (esNS){
			formulario=document.formgreservas;
			}
		else{
			formulario=document.getElementById("formgreservas");
			}
		formulario.TipoActividad.value = Codigo;
		formulario.Imagen.value = Imagen;
		formulario.submit();
	}
/***************************COMPROBAR LAS FECHAS**********************/	
function compruebafecha(f) {
if (f.length == 10){
	var test="0123456789";
	var i;
	for (i=0;i<2;i++)
		{
		if (test.indexOf(f.charAt(i))<0){
			alert(f.substring(0,2)+" dia no valido");
			return false;}
		}
	for (i=3;i<5;i++)
		{
		if (test.indexOf(f.charAt(i))<0){
			alert(f.substring(3,5)+" mes no valido");
			return false;}
		}
	for (i=6;i<10;i++)
		{
		if (test.indexOf(f.charAt(i))<0){
			alert(f.substring(6,10)+" año no valido");
			return false;}
		}
 if  (isBetween(parseInt(f.substring(0,2),10),1,31)==false) {
	alert(f.substring(0,3)+" dia no valido");
    return false;
 }
 if (isBetween(parseInt(f.substring(3,5),10),1,12)==false) {
	alert(f.substring(3,5)+" mes no valido");
    return false;
 }
 if ( parseInt(f.substring(6,10),10)==false ) {
	alert(f.substring(6,10)+" año no valido");
    return false;
 }
 if ( (parseInt(f.substring(0,3),10)==31) && ((parseInt(f.substring(3,5),10)==11)||(parseInt(f.substring(3,5),10)==4)||(parseInt(f.substring(3,5),10)==6)||(parseInt(f.substring(3,5),10)==9))) {
	alert(f+" fecha incorrecta");
    return false;
 }
 if ( parseInt(f.substring(3,5),10)==2 && (parseInt(f.substring(0,3),10)>29)) {
	alert(f+" fecha incorrecta");
    return false;
 }
//bisiestos
 if (( parseInt(f.substring(3,5),10)==2) && (parseInt(f.substring(0,3),10)==29)) {
	if ((parseInt(f.substring(8,10))==0) && (parseInt(f.substring(6,8)) % 4!=0))	{
   	  alert("No es bisiesto");
      return false;
	}
	if ((parseInt(f.substring(8,10),10)!=0) && (parseInt(f.substring(8,10),10) % 4 != 0))	{
   	  alert("No es bisiesto");
      return false;
	}
 }
}
else
{
	if (f.length > 0)
	{
		alert(f+" fecha incorrecta. El formato debe ser dd/mm/aaaa");
		return false;
	}
}
return true;
}


function isBetween(val,limit1,limit2) {
var max=(limit1 > limit2) ? limit1 : limit2 ;
var min=(limit1 < limit2) ? limit1 : limit2 ;
if (val == max || val == min)
  {return true;}
if (val > min && val < max)
  {return true;}
return false;
}

function isEmailAddress(theElement)
{
var s = theElement;
var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
if (s.length == 0 ) return true;
   if (filter.test(s))
      return true;
   else
     alert("Introduzca una direccion de correo valida");
//theElement.focus();
return false;
}
////////versiones para imprimir
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function imprimepag() {
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("No soportado por este navegador");
}
