var nav4 = window.Event ? true : false;

function esDigito(sChr)
{
 var sCod = sChr.charCodeAt(0);
 return ((sCod > 47) && (sCod < 58));
}

function valSep(oTxt)
{
 var bOk = false;
 bOk = bOk || ((oTxt.value.charAt(2) == "-") && (oTxt.value.charAt(5) == "-"));
 bOk = bOk || ((oTxt.value.charAt(2) == "/") && (oTxt.value.charAt(5) == "/"));
return bOk;
}

function finMes(nMes)
{
 var nRes = 0;
 switch (nMes)
 {
  case 1: nRes = 31; break;
  case 2: nRes = 29; break;
  case 3: nRes = 31; break;
  case 4: nRes = 30; break;
  case 5: nRes = 31; break;
  case 6: nRes = 30; break;
  case 7: nRes = 31; break;
  case 8: nRes = 31; break;
  case 9: nRes = 30; break;
  case 10: nRes = 31; break;
  case 11: nRes = 30; break;
  case 12: nRes = 31; break;
 }
 return nRes;
}

function valDia(nMes,nDia)
{
 var bOk = false;
 bOk = bOk || ((nDia >= 1) && (nDia <= finMes(nMes)));
 return bOk;
}

function valMes(nMes)
{
 var bOk = false;
 bOk = bOk || ((nMes >= 1) && (nMes <= 12));
 return bOk;
}

function valAno(nAno)
{
 var bOk = true;
 for (var i = 0; i < nAno.length; i++)
 {
  bOk = bOk && esDigito(nAno.charAt(i));
  }
 return bOk;
}

function valFecha(dia,mes,ano)
{
 var bOk = true;
 bOk = bOk && (valAno(ano));
 bOk = bOk && (valMes(mes));
 bOk = bOk && (valDia(mes,dia));
 return bOk;
}

function modalWin(url)
{
 if (window.showModalDialog)
  {
   window.showModalDialog(url,"_blank","dialogWidth:780px;dialogHeight:580px");
  }
 else
 {
  window.open(url,'_blank','height=580,width=780,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no ,modal=yes');
 }
}

function modalWinVerFotos(url)
{
 w = 430;
 h = 400;

 if (window.showModalDialog)
  {
   window.showModalDialog(url,"_blank","dialogWidth:"+ w +"px;dialogHeight:" + h + "px;resizable:yes;scroll:yes");
  }
 else
 {
  window.open(url,'_blank','height=' + h+ ',width=' + h + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes ,modal=yes');
 }
}

function modalWinNuevoAnexo(url)
{
 w = 580;
 h = 150;

 if (window.showModalDialog)
  {
   window.showModalDialog(url,"_blank","dialogWidth:"+ w +"px;dialogHeight:" + h + "px;resizable:yes;scroll:yes");
  }
 else
 {
  window.open(url,'_blank','height=' + h+ ',width=' + h + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes ,modal=yes');
 }
}

function modalWinNuevaFoto(url)
{
 w = 580;
 h = 200;

 if (window.showModalDialog)
  {
   window.showModalDialog(url,"_blank","dialogWidth:"+ w +"px;dialogHeight:" + h + "px;resizable:yes;scroll:yes");
  }
 else
 {
  window.open(url,'_blank','height=' + h+ ',width=' + h + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes ,modal=yes');
 }
}

function modalWinFotos(url)
{
 w = 580;
 h = 350;

 if (window.showModalDialog)
  {
   window.showModalDialog(url,"_blank","dialogWidth:"+ w +"px;dialogHeight:" + h + "px;resizable:yes;scroll:yes");
  }
 else
 {
  window.open(url,'_blank','height=' + h+ ',width=' + h + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes ,modal=yes');
 }
}



function mensajeXML(num)
{
 num = parseInt(num);
 var  s = 'No se pudo completar la Operación (' + num + ')';
 switch(num)
 {
  case 1  : s = 'No se pudo completar la Operación (001)'; break;
  case 2  : s = 'No se pudo completar la Operación (002)'; break;
  case 3  : s = 'No se pudo completar la Operación (003)'; break;
  case 4  : s = 'El Nombre de Usuario y/o Palabra Clave no son válidos'; break;
  case 5  : s = 'No tiene permiso para realizar esta Acción'; break;
  case 6  : s = 'Su identificador no es válido, debe volver a ingresar al Sistema (006)'; break;
  case 7  : s = 'Su identificador no es válido, debe volver a ingresar al Sistema (007)'; break;
  case 8  : s = 'El formato de los datos enviados no es Válido (008)'; break;
  case 9  : s = 'El formato de los datos enviados no es Válido (009)'; break;
  case 10 : s = 'El registro solicitado no existe'; break;
  case 11 : s = 'Trato de incorporar un registro duplicado'; break;
  case 12 : s = 'No se pudo borrar, por que hay registros relacionados'; break;
  case 13 : s = 'No se pudo guardar, el padre seleccionado también es hijo de otra estación'; break;
  case 14 : s = 'La estación padre no existe'; break;
  case 15 : s = 'La estación padre e hijo son la misma'; break;
 }
 alert(s);
}

function get_xmlhttp()
{
var xmlhttp = null;	
try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
if (!xmlhttp && typeof XMLHttpRequest!='undefined')
{
  xmlhttp = new XMLHttpRequest();
}
if(xmlhttp == null)
{
 alert("Debe actualizar su Explorador Web");	
}

return xmlhttp
}

function enviar(xmlhttp,metodo,url,async,callback, parametros)
{
 xmlhttp.open(metodo, url,async);
 xmlhttp.onreadystatechange=function()
  {
  switch(xmlhttp.readyState)
  {
   case 0:
     //window.title = "Enviando Solicitud...";
     break;

   case 1:
     //window.title = "Esperando Respuesta...";
      break;

   case 2:
     // window.title = "Cargando Respuesta...";
       break;

    case 3:
      // window.title = "Respuesta Lista...";
       break;

    case 4:
     callback(xmlhttp)
     break;
  }
 }
 if(metodo == 'POST')
 {
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlhttp.setRequestHeader("Content-length", parametros.length);
  xmlhttp.setRequestHeader("Connection", "close");
 }
 xmlhttp.send(parametros)
}


function validar_entero_viejo(valor)
{
 valor = parseInt(valor);
 if(isNaN(valor)){ valor = 0; }
 return valor;
}

function validar_entero(valor)
{
 if (valor == null) return 0;

 valor = Trim(valor);
 if(valor == '') return 0;
 
 valor1  = valor;
 valor   = '';
 primero = true;
 
 for(ij = 0; ij < valor1.length; ij++)
 {
  caracter = valor1.charAt(ij);
  
  ok = false;
  switch(caracter)
  {
   case '0' : ok = primero ? false : true; break;
   case '1' : primero = false; ok = true; break;
   case '2' : primero = false; ok = true; break;
   case '3' : primero = false; ok = true; break;
   case '4' : primero = false; ok = true; break;
   case '5' : primero = false; ok = true; break;
   case '6' : primero = false; ok = true; break;
   case '7' : primero = false; ok = true; break;
   case '8' : primero = false; ok = true; break;
   case '9' : primero = false; ok = true; break;
  }
  if(!ok) continue;

  valor += caracter;
 }

 valor = parseInt(valor);
 if(isNaN(valor)) valor = 0;
 return valor;

}


function validar_float(valor)
{
 valor = parseFloat(valor);
 if(isNaN(valor)){ valor = 0; }
 return valor;
}

function acceptText(evt, campo, longitud)
 {
  var key = nav4 ? evt.which : evt.keyCode;
  if(campo.value.length < longitud)
    { return true; }
   else
    {return false;}
 }

function acceptNumDec(evt,campo,decimales)
 {
  var key = nav4 ? evt.which : evt.keyCode;
  var punto =  campo.value.indexOf('.',0);
  var dec   = campo.value.length - punto;
  if(punto==-1) {dec = 0;}
  if(key!=46)
     return ((((key <= 13)||((key>=48)&&(key <= 57))))&&(dec<=decimales));
   else
    {return ((key == 46)&&(punto<=0));}
 }

function acceptNum(evt)
 {
  var key = nav4 ? evt.which : evt.keyCode;
  return (key <= 13 || (key >= 48 && key <= 57));
 }

function Trim( str ) {
	var resultStr = "";

	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
 
        if (resultStr == null) resultStr = '';


	return resultStr;
}

function TrimRight( str ) {
	var resultStr = "";
	var i = 0;

	if (str+"" == "undefined" || str == null)
		return null;

	str += "";

	if (str.length == 0)
		resultStr = "";
	else {
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;

  		resultStr = str.substring(0, i + 1);
  	}

  	return resultStr;
}

function TrimLeft( str ) 
{
	var resultStr = "";
	var i = len = 0;


	if (str+"" == "undefined" || str == null)
		return null;

	str += "";

	if (str.length == 0)
		resultStr = "";
	else {
		len = str.length;

  		while ((i <= len) && (str.charAt(i) == " "))
			i++;

  		resultStr = str.substring(i, len);
  	}

  	return resultStr;
}

 function obtener_tipo_personal(i)
 {
  var tipo = '';
  switch(i)
  {
   case 0 : tipo = 'Administrador'; break;
   case 1 : tipo = 'Supervisor'; break;
   case 2 : tipo = 'Técnico'; break;
   case 3 : tipo = 'Cliente'; break;
  }
  return tipo;
 }

 function obetener_permisos_personal(permisos)
 {
  return (permisos == 1) ? 'Activo' : 'Inactivo'  ;
 }

function cambiar_estado_panel(item)
 {
   obj=document.getElementById(item);

   visible=(obj.style.display!="none")
   if (visible)
    {
     obj.style.display="none";
    }
   else
    {
     obj.style.display="";
    }
}

//AE Function Replace Prompt

var ae_cb = null;
 
// this is a simple function-shortcut
// to avoid using lengthy document.getElementById
function ae$(a) { return document.getElementById(a); }
 
// This is a main ae_prompt function
// it saves function callback 
// and sets up dialog
function ae_prompt(cb, q, a) {
	ae_cb = cb;
	ae$('aep_t').innerHTML = document.domain + ' question:';
	ae$('aep_prompt').innerHTML = q;
	ae$('aep_text').value = a;
	ae$('aep_ovrl').style.display = ae$('aep_ww').style.display = '';
	ae$('aep_text').focus();
	ae$('aep_text').select();
}
 
// This function is called when user presses OK(m=0) or Cancel(m=1) button
// in the dialog. You should not call this function directly.
function ae_clk(m) {
	// hide dialog layers 
	ae$('aep_ovrl').style.display = ae$('aep_ww').style.display = 'none';
	if (!m)  
		ae_cb(null);  // user pressed cancel, call callback with null
	else
		ae_cb(ae$('aep_text').value); // user pressed OK 
}
