var g_debug=0;

///////////////////////////////////////////////////////////////////////////
//// objetos
function d_obj(id){
	var o;
	if (document.all) o = document.all(id);
	else if (document.getElementById) o = document.getElementById(id);
	else if (document.layers) o = document.layers[id];
	if (o) return(o);
	return(null);
}

///////////////////////////////////////////////////////////////////////////
//// mensajes
function msj(s){ window.status=s; return true; }
///////////////////////////////////////////////////////////////////////////

function mOvr(src,clrOver) {
	if (!src.contains(event.fromElement)) {
		src.bgColor = clrOver;
	}
}

function mOut(src,clrIn) {
	if (!src.contains(event.toElement)) {
		src.bgColor = clrIn;
	}
}

function muestra(faq_){
	if(document.getElementById(faq_).style.visibility=="visible"){
		SetCookie(faq_,'0');
		document.getElementById(faq_).style.visibility="hidden";
		document.getElementById(faq_).style.display="none";
	}else{
		SetCookie(faq_,'1');
		document.getElementById(faq_).style.display="block";
		document.getElementById(faq_).style.visibility="visible";
	}
}

function esconde(num_){
var n, tmp
for (n=1;n<=parseInt(num_);n++) {
	tmp="fi"+n
		document.getElementById(tmp).style.visibility="hidden";
		document.getElementById(tmp).style.display="none";
	if (n==num_){
   break;}
	}
}

//funciones para cambiar el tamaño de los marcos de forma dinámica.
function Baja(filas_) {
  	top.contenidos.rows = filas_;
}
function Sube(filas_) {
  	top.contenidos.rows = filas_;
}
function ver_filtro(campo_){
	window.open('/cpo/adm/inc/filtro.asp?c='+campo_,'filtro','width=500, height=320, scrollbars=yes,status=yes');
}

function ver_calendario(tipo, formulario_, nm_campo_) {
	var fecha = eval(formulario_+"."+nm_campo_+".value");
	var nombre = eval(formulario_+".name");
	ventanaXY(425,250,175,128,'/cpo/adm/inc/calendario_v.3.1.asp?tipo='+tipo+'&dt='+fecha+"&formulario="+nombre+'&nm_campo='+nm_campo_,'');
}

///////////////////////////////////////////////////////////////////////////
//// ventanas
//g_debug=0;
var g_o_comun='toolbar=no,location=no,directories=no,status=1,menubar=no,scrollbar=yes,scrollbars=1,resizable=1,copyhistory=no';
if(g_debug)
	g_o_popup1='width='+580+',height='+490+'toolbar=1,location=no,directories=no,status=1,menubar=1,scrollbar=yes,scrollbars=1,resizable=1,copyhistory=yes';
else
	g_o_popup1='width='+580+',height='+490+g_o_comun;
var g_o_popup2='width='+700+',height='+600+g_o_comun;
var g_o_popup3=g_o_comun;
var g_o_popup4='width='+720+',height='+600+g_o_comun;
var g_o_popup5='width='+580+',height='+300+g_o_comun;
var g_o_popup6='width='+670+',height='+600+g_o_comun;
function popup(u,v,o){
	w=window.open(u,v,o);
	w.focus();
}
function popup_superusuario(idu){
	var wsu=window.open('/web/inicio.asp?idUsuario='+idu,'web_superusuario');
	wsu.focus();
}
//g_debug=0;

function ventanaXY(X,Y,ancho,alto,URL,propiedades,titulo_ventana) {
	var windowprops,s,w,t;
  	windowprops = 'status=1,statusbar=1,left=' + X + ',top=' + Y + ',width=' + ancho + ',height=' + alto;
  	if(propiedades>''){
		s=windowprops+','+propiedades;
  	} else {
		s=windowprops;
	}
	if(titulo_ventana) t=titulo_ventana;
	else t='MenuPopup';
  	w=window.open(URL,t,s);
  	w.focus();
}

function popup_foto(i,t){
	var w=window.open('','foto','height=200,width=200,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,scrollbars=1,resizable=1,copyhistory=no');
	w.focus();
	var d=w.document.open();
	d.write('<html>');
	d.write('<head>');
	d.write('<title>');
	d.write(t);
	d.write('</title>');
	d.write('<script>function redimensionar(){');
	d.write('resizeTo(document.images.foto.width+12,document.images.foto.height+32);');
	d.write('}</script>');
	d.write('</head>');
	d.write('<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0" onLoad="redimensionar()" scroll="no" style="overflow:auto;">');
	d.write('<table width="100%" height="100%" cellpadding=0 cellspacing=0 border=0><tr><td width="100%" height="100%" align=center valign=center><img name=foto src="'+i+'" hspace=0 vspace=0 border=0></td></tr></table>');
	d.write('</body>');
	d.write('</html>');
	d.close();
	w.location.reload();
}

//////////////////////////////////////////////////////////////////////////////
// Cookies
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg){
			return getCookieVal (j);
			}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
//////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
//// FECHAS

function anyoBisiesto(anyo){
 var fin;
  if (anyo < 100) fin = anyo + 1900;
  else fin = anyo ;
  if (fin % 4 != 0) return false;
  else {
     if (fin % 100 == 0) {
         if (fin % 400 == 0) return true;
         else return false;
     }
     else return true;
  }
}

function es_fecha(a){
  var mes, dia, anyo, febrero,fecha;
 if (a.indexOf("/")==-1) {
     alert('Formato de fecha inválido');
	 return false;
  }
  dia = parseInt(a.split("/")[0],10);
  mes = parseInt(a.split("/")[1],10);
  anyo = parseInt(a.split("/")[2],10);
  if(anyoBisiesto(anyo)) febrero=29;
  else febrero=28;
  if (isNaN(mes) || (mes<1) || (mes>12)) {
     alert('Mes inválido');
     return false;
  }
  if ((isNaN(mes) || (mes==2)) && (isNaN(dia) || (dia<1) || (dia>febrero))) {
     alert('Fecha inválida');
     return false;
  }
  if ((isNaN(mes) || (mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) || (mes==10) || (mes==12)) && (isNaN(dia) || (dia<1) || (dia>31))) {
     alert('Fecha inválida');
     return false;
  }
  if ((isNaN(mes) || (mes==4) || (mes==6) || (mes==9) || (mes==11)) && (isNaN(dia) || (dia<1) || (dia>30))) {
     alert('Fecha inválida');
     return false;
  }
  if (isNaN(anyo) || anyo<0 ) {
     alert('Año inválido');
     return false;
  }
  if(anyo<99){
	  	anyo+=2000;
  }
  if ( anyo<1900  || anyo>3000 ) {
     alert('Año inválido');
     return false;
  }
  dia='0'+dia+'/';
  dia=dia.substr(dia.length-3, 3);
  mes='0'+mes+'/';
  mes=mes.substr(mes.length-3, 3);
  fecha=dia+mes+anyo;
  //alert(fecha);
  return fecha;
}

function validar_fecha_valida(nm_campo_, formulario_) {
  var a = eval(formulario_+"."+nm_campo_+".value");
  return es_fecha(a);
}

//------------------------------------------------------------------------------
// ajusta días a partir de las fechas de entrada y salida
// los parámetros son los objetos input
function ajustar_fechas_y_dias(ofe,ofs,ond) {
	var fecha_entrada,fecha_salida;
	fecha_entrada=ofe.value;
	fecha_salida=ofs.value;
	if(fecha_entrada=='') return;
	fecha_entrada=es_fecha(fecha_entrada);
	if(!fecha_entrada) return;
	ofe.value=fecha_entrada;
	if(fecha_salida=='') return;
	fecha_salida=es_fecha(fecha_salida);
	if(!fecha_salida) return;
	ofs.value=fecha_salida;

	var Ano1 = fecha_entrada.substring(6,10);
	var Mes1 = fecha_entrada.substring(3,5);
	var Dia1 = fecha_entrada.substring(0,2);

	var Ano2 = fecha_salida.substring(6,10);
	var Mes2 = fecha_salida.substring(3,5);
	var Dia2 = fecha_salida.substring(0,2);

	var dte_entrada = Ano1+'/'+Mes1+'/'+Dia1
	var dte_salida = Ano2+'/'+Mes2+'/'+Dia2

	var today = new Date(dte_entrada);
	var year = today.getYear();

	if ((navigator.appName == "Microsoft Internet Explorer") && (year < 2000))
		year="19" + year;
	if (navigator.appName == "Netscape")
		year=1900 + year;

	var date = new Date(dte_salida);
	var diff = date.getTime() - today.getTime();
	var days = Math.floor(diff / (1000 * 60 * 60 * 24));

	if(days<1) {
		ond.value=0;
		ofs.focus();
		ofs.select();
		alert(s_[13]);
		ofs.focus();
		ofs.select();
		ofs.focus();
		ofs.select();
		return;
	}
	ond.value=days;
}


//////////////////////////////////////////////////////////////////////////////
//// mensajes JavaScript
var s_ = new Array(); // mensajes JavaScript
s_[1]='Por favor, revise el valor de la casilla siguiente, pues es obligatorio: ';
s_[2]='Por favor, revise el valor de la casilla siguiente, pues debe ser numérico: ';
s_[3]='Por favor, revise el valor de la casilla siguiente, pues no contiene un formato válido de correo electrónico: ';
s_[4]='Por favor, revise el valor de la casilla, pues la hora indicada no tiene el formato correcto hh:mm o hh:mm:ss';
s_[5]='La parte horaria de la hora es incorrecta.\nLas parte horaria debe ir de 0 a 23.';
s_[6]='Los minutos de la hora son incorrectos.';
s_[7]='La segundos de la hora son incorrectos.';
s_[8]='La fecha indicada no tiene el formato correcto: dd/mm/aaaa';
s_[9]='El mes introducido no es válido. Por favor, introduzca un mes correcto.';
s_[10]='El día introducido no es válido. Por favor, introduzca un día correcto.';
s_[11]='El año introducido no es válido.';
s_[12]='Por favor, seleccione una localidad (no una zona)';
s_[13]='La fecha de salida no es válida. Por favor, introduzca otra fecha.';


function limit_long(o,n) {
	if (o.value.length > n){ // if too long...trim it!
		o.value=o.value.substring(0,n);
		alert('Se ha truncado el texto de esta casilla, pues ha superado los '+n+' caracteres.');
	}
}

function validar_campos_formulario(formulario) {
     for (i=0;i<formulario.length;i++) {
         var tempobj=formulario.elements[i];
         var valor = tempobj.value;
         var tipo = tempobj.id.substring(0,3);
         var nombre_campo = tempobj.id.substring(4,30).toUpperCase();
         if (tempobj.id.length > 0) {
            if (((tempobj.type=="text")||(tempobj.type=="textarea")||(tempobj.type=="password")||(tempobj.type=="file"))&&(valor.length==0)&&(nombre_campo.length >0)){
               alert(s_[1]+nombre_campo);
	           //tempobj.style.background = "#CCCCCC";  //permitir cambiar el color de fondo del campo
               tempobj.focus();
			   return false;
            }
			if ((tipo.length > 0)&&(valor.length > 0)) {
 		       switch (tipo){
		          case "num":
		               if (isNaN(valor)) {
				          alert(s_[2]+nombre_campo);
                          tempobj.select();
			              return false;
				       }
                       break;
		          case "dts":
			           if (!validar_fecha_valida(tempobj.name, formulario)) {
                          tempobj.select();
			              return false;
				       }
                       break;
			      case "@@@":
			           var inicio = valor.indexOf("@");
					   var fin = valor.lastIndexOf("@");
                       if ((inicio != fin) || ((inicio == -1) && (fin == -1)) || ((inicio == 0) && (fin == 0))|| ((inicio == valor.length-1) && (fin == valor.length-1))){
					      alert(s_[3]+nombre_campo);
                          tempobj.select();
			              return false;
                       }
			           break;
				  case "hhh":
                       var horas=valor.split(":")[0];
                       var minutos=valor.split(":")[1];
                       var segundos=valor.split(":")[2];
                       if (valor.indexOf("/")==-1) {
                          alert(s_[4]);
                          tempobj.select();
                     	  return false;
                       }
					   if ((horas > "23")||(horas < "0")) {
					      alert(s_[5]);
                          tempobj.select();
                          return false;
					   }
					   if ((minutos > "59")||(minutos < "0")) {
					      alert(s_[6]);
                          tempobj.select();
                          return false;
					   }
					   if ((segundos > "59")||(segundos < "0")) {
					      alert(s_[7]);
                          tempobj.select();
                          return false;
					   }
				       break;
		          case "txt": break;
		          case "bit": break;
		          case "ids": break;
		       }
            }
         }
	 }
  return true;
}


function validar_formulario_estadisticas(){
	var f,o,v;
	f=document.filtrado;
	o=f.dt_desde; v=o.value;
	if(o>''){
		if(!validar_fecha_valida('dt_desde',f)){
			alert('Fecha "desde" inválida');
			o.focus();
			return false;
		}
	}
	o=f.dt_hasta; v=o.value;
	if(o>''){
		if(!validar_fecha_valida('dt_hasta',f)){
			alert('Fecha "hasta" inválida');
			o.focus();
			return false;
		}
	}
	return true;
}

function validaHora(obj)
{
	a=obj.value;
	if(a=="") return true;

	if (isNaN(a.substring (0,2)) || isNaN(a.substring (3,5)) || a.substring(2,3)!=":")
	{
		return false;
	}
	if(a.substring (0,2)>23)
	{
		return false;
	}
	if(a.substring (3,5)>59)
	{
		return false;
	}
	return true;
}

function esNumerico(a)
{
        for (i=0; i< a.length; i++)
        {
 		if (a.charAt(i)!='0' && a.charAt(i)!='1' && a.charAt(i)!='2' && a.charAt(i)!='3'
 			 && a.charAt(i)!='4' && a.charAt(i)!='5' && a.charAt(i)!='6' && a.charAt(i)!='7'
 			  && a.charAt(i)!='8' && a.charAt(i)!='9')   // numeros
 		{
 			return false;
 		}
	}
	return true;
}

function esNumericoDecimal(a)
{
	numcomas=0;
	numpuntos=0;
        for (i=0; i< a.length; i++)
        {
 		if (a.charAt(i)!='0' && a.charAt(i)!='1' && a.charAt(i)!='2' && a.charAt(i)!='3'
 			 && a.charAt(i)!='4' && a.charAt(i)!='5' && a.charAt(i)!='6' && a.charAt(i)!='7'
 			  && a.charAt(i)!='8' && a.charAt(i)!='9' && a.charAt(i)!=',' && a.charAt(i)!='.')   // numeros
 		{
 			return false;
 		}

 		if(a.charAt(i)==',') numcomas=numcomas+1;
 		if(a.charAt(i)=='.') numpuntos=numpuntos+1;
	}

	if(numcomas>1) return false;
	if(numpuntos>1) return false;

	return true;
}
//////////////////////////////////////////////////////////////////////////////
function inicializar_pagina(){ return true; }
//////////////////////////////////////////////////////////////////////////////

//<!--
//Disable right click script III- By Renigade (renigade@mediaone.net)
//For full source code, visit http://www.dynamicdrive.com

var message="";
///////////////////////////////////
function clickIE() {
	if (document.all) {
		(message);return false;
	}
}
function clickNS(e) {
	if (document.layers||(document.getElementById&&!document.all)) {
		if (e.which==2||e.which==3) {
			(message);return false;
		}
	}
}

if(document.layers) {
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS;
} else{
	document.onmouseup=clickNS;
	document.oncontextmenu=clickIE;
}
// -->