var m_001 = "El Area se grabó con éxito.";
var m_002 = "EL Cargo se grabó con éxito.";
var m_003 = "La Oficina se grabó con éxito.";
var m_004 = "El Usuario se grabó con éxito.";
var m_005 = "El Cliente se grabó con éxito.";
var m_006 = "La Propiedad se grabó con éxito.";
var m_007 = "Está seguro de eliminar los registros seleccionados?";
var m_008 = "Debe seleccionar al menos un registro.";
var m_009 = "Eliminación exitosa.";
var m_010 = "Está seguro de asignar al área las acciones seleccionadas?";
var m_011 = "Está seguro de asignar al área las opciones seleccionadas?";
var m_012 = "Las acciones se asignaron al área con éxito.";
var m_013 = "Las opciones se asignaron al área con éxito.";
var m_014 = "El usuario ingresado ya existe.";
var m_015 = "El jefe inmediato ingresado no existe.";
var m_016 = "Desea subir las imágenes de la propiedad.";
var m_017 = "La Imagen se grabó con éxito.";
var m_018 = "El Video se grabó con éxito.";
var m_019 = "La Baja de la propiedad se grabó con éxito";
var m_020 = "Está seguro de activar los registros seleccionados?";
var m_021 = "Activación exitosa.";
var m_022 = "La Baja del cliente se grabó con éxito";
var m_023 = "El DNI ingresado ya existe.";
var m_024 = "El RUC ingresado ya existe.";
var m_025 = "El PDF se grabó con éxito.";
var m_026 = "El Comentario se grabó con éxito.";
var m_027 = "El formato del archivo ó archivos a subir es incorrecto.";
var m_028 = "El tamaño del archivo ó archivos a subir es muy grande.";
var m_029 = "El correo ha sido enviado.";
var m_030 = "El tamaño del archivo ó archivos a subir es incorrecto.";
var m_031 = "Está seguro de asignar a la(s) propiedad(es) las oficinas seleccionadas?";
var m_032 = "Las oficinas se asignaron a la(s) propiedad(es) con éxito.";
var m_033 = "Está seguro de asignar a el ó los clientes las oficinas seleccionadas?";
var m_034 = "Las oficinas se asignaron a el ó los clientes con éxito.";
var m_035 = "Está seguro de asignar a la(s) propiedad(es) seleccionadas?";
var m_036 = "La(s) propiedad(es) se asignaron con éxito.";
var m_037 = "El Archivo se grabó con éxito.";
var m_038 = "La Noticia se Grabo con Exito.";
var m_039 = "¿Está seguro de agregar las propiedades seleccionadas?";

function loadPage(){
  document.all.wndHide.style.display = 'block';
  document.getElementById("cargando").style.display = 'none';
  
  if(document.getElementById){
    document.getElementById("hidePage").style.visibility = 'hidden';
  }else{
    document.all.hidePage.style.visibility = 'hidden';
  }
}

function objetoAjax(){        
	var xmlhttp=false;        
	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();        }        
	return xmlhttp;
}

function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}

function centraVentana(ancho,alto) {
	if (window.screen) {
		var aw = screen.availWidth;var ah = screen.availHeight;window.resizeTo(ancho,alto);window.moveTo((aw-ancho)/2,(ah-alto)/2);
	}
}
function algunCheck(form){
	for(i=0 ; i<form.elements.length; i++){
		if(form.elements[i].type == "checkbox"){if(form.elements[i].checked){return true;}}
	}
	return false;
}
function esTeclaNumero(e) {
	var valid = "0123456789";
	var key = String.fromCharCode(event.keyCode);
		if (valid.indexOf("" + key) == "-1") return false;
}
function validarHora(strHora){
	if (longitudcorrecta(strHora, 5)) {
		strHora += ":00";
	}
	return !(!(/[0-2][0-9]:[0-5][0-9]:[0-5][0-9]/.test(strHora)) || (strHora.substring(0,2)<0 || strHora.substring(0,2)>23));
}
function formateafecha(valor){
  var l = StringTokenizer(valor, "/");
  return rellena(l[0], "0", 2) + "/" + rellena(l[1], "0", 2) + "/" + l[2];
}
function estelefono(valor){
  var pattern = "/\\b(^(\\d+)(\\-\\d+)$)\\b/gi";
	return valor.match(eval(pattern));
}
function esEntero(numero){
  tokens = StringTokenizer(numero, '.');
  return ( (tokens.length<=1)&&(esnumero(numero)) );
}
function validaDecimal(numero, dec){
  tokens = StringTokenizer(numero, '.');
  return (( tokens.length>1 )? (tokens[tokens.length-1].length > 0 && tokens[tokens.length-1].length <= dec) : true)&&(esdecimal(numero));
}
function esdecimal(valor){
  var pattern = "/\\b(^(\\d+)(\\.\\d+)$)\\b/gi";
	return valor.match(eval(pattern));
}
function validacorreo(myString) {
	return myString.match(/\b(^(\S+@).+((\.gob)|(\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.biz)|(\.org)|(\..{2,2}))$)\b/gi)
}
/* fn & ext Rt T F */
function validanombrearchivo(nombre, ext){
  var pattern = "/\\b(^(((\\S)|(\\s))+)(\\."+ext+")$)\\b/gi";
	return nombre.match(eval(pattern));
}
/* Rt Arr */
function StringTokenizer(cad, delim){
  var cads = new Array();
  var n = cad.length;
  var j = 0;
  var ic = 0;
  for (i=0;i<n;i++){
    if ( cad.charAt(i)==delim ){ cads[j] = cad.substring(ic, i); ic = i+1; j++; }
  }
  cads[j] = cad.substring(ic, n);
  return cads;
}
/*Rt m ltr: mes # / 1-12, may 1 o 0 M o m, cap 1 o 0 M 1ra lt*/
function mesenletras(mes, may, cap){
  if ( !esnumero(mes) ) return "-";
  var imes = parseInt(mes, 10);
  var tmes = "";
  if ( imes == 1 ) tmes = "enero";
  else if ( imes == 2 ) tmes = "febrero";
  else if ( imes == 3 ) tmes = "marzo";
  else if ( imes == 4 ) tmes = "abril";
  else if ( imes == 5 ) tmes = "mayo";
  else if ( imes == 6 ) tmes = "junio";
  else if ( imes == 7 ) tmes = "julio";
  else if ( imes == 8 ) tmes = "agosto";
  else if ( imes == 9 ) tmes = "setiembre";
  else if ( imes == 10 ) tmes = "octubre";
  else if ( imes == 11 ) tmes = "noviembre";
  else if ( imes == 12 ) tmes = "diciembre";
  if ( may == 1) tmes = tmes.toUpperCase(); 
  if ( cap == 1) tmes = tmes.substring(0,1).toUpperCase() + tmes.substring(1, tmes.length);
  return tmes;
}
/* -1: err, 1: f1>f2, 2: f1<f2, 0: f1=f2 */
function comparafecha(fecha1, fecha2){
  if ( !checkdate(fecha1) || !checkdate(fecha2) ) return -1;
  dia = fecha1.substring(0,2)
  mes = fecha1.substring(3,5)
  anho = fecha1.substring(6,10)
  fecha1x = anho + mes + dia
  dia = fecha2.substring(0,2)
  mes = fecha2.substring(3,5)
  anho = fecha2.substring(6,10)
  fecha2x = anho + mes + dia
  return (fecha1x>fecha2x?1:(fecha1x<fecha2x?2:0));
}
function nada(){}
function corta(campo, longitud, cars) {
  if (campo.value.length>longitud) campo.value=campo.value.substring(0,longitud);
  cuenta(campo, cars);
}
function cuenta(campo, cars) { cars.value=campo.value.length; }
function rellena(dato, caracter, tamanho){
  dato_trim = trim(dato);
  len = dato_trim.length;
  dato_fill = "";
  for (var i=0;i<tamanho-len;i++){ dato_fill+=caracter; }
  dato_fill+=dato_trim;
  return dato_fill;
}
function checkdate(fecha){
  var err=0
  if ( fecha.length != 10) err=1
  dia = fecha.substring(0,2)
  slash1 = fecha.substring(2,3)
  mes = fecha.substring(3,5)
  slash2 = fecha.substring(5,6)
  anho = fecha.substring(6,10)
  if ( dia<1 || dia>31) err = 1
  if ( slash1 != '/' ) err = 1
  if ( mes<1 || mes>12) err = 1
  if ( slash1 == '/' && slash2 != '/' ) err = 1
  if ( anho < 0 || anho > 2200 ) err = 1
  if ( mes == 4 || mes == 6 || mes == 9 || mes == 11 ){
    if (dia==31) err=1
  }
  if (mes == 2){
    var g = parseInt(anho/4)
    if (isNaN(g)){
      err = 1
    }
    if (dia >29) err =1
    if (dia ==29 && ((anho/4)!=parseInt(anho/4))) err=1
  }
  return (!(err==1));
}
function esnulo(campo){ return (campo == null||campo=="");}
function esnulooguion(campo){
  return esnulo(campo) || ( trim( campo ) == "-" );
}
function esnumero(campo){ return (!(isNaN( campo )));}
function longitudcorrecta( campo, len ){
  if ( campo != null ) return ( campo.length == len );
  else return false;
}
function mayuscula(campo){return campo.toUpperCase();}
function minuscula(campo){return campo.toLowerCase();}
function eslongrucok(ruc){return ( ruc.length == 11 );}
function eslongcontrasenhaok(contrasenha){
  return (contrasenha.length >= longcontrasenhaok());
}
function longcontrasenhaok(){ return 6;}
function esnegativo(valor){ return (valor < 0);}
function esrucok(ruc){
  return (!( esnulo(ruc) || !esnumero(ruc) || !eslongrucok(ruc) || !valruc(ruc) ));
}
function valruc(valor){
  valor = trim(valor)
  if ( esnumero( valor ) ) {
    if ( valor.length == 8 ){
      suma = 0
      for (i=0; i<valor.length-1;i++){
        digito = valor.charAt(i) - '0';
        if ( i==0 ) suma += (digito*2)
        else suma += (digito*(valor.length-i))
      }
      resto = suma % 11;
      if ( resto == 1) resto = 11;
      if ( resto + ( valor.charAt( valor.length-1 ) - '0' ) == 11 ){
        return true
      }
    } else if ( valor.length == 11 ){
      suma = 0
      x = 6
      for (i=0; i<valor.length-1;i++){
        if ( i == 4 ) x = 8
        digito = valor.charAt(i) - '0';
        x--
        if ( i==0 ) suma += (digito*x)
        else suma += (digito*x)
      }
      resto = suma % 11;
      resto = 11 - resto
      
      if ( resto >= 10) resto = resto - 10;
      if ( resto == valor.charAt( valor.length-1 ) - '0' ){
        return true
      }      
    }
  }
  return false
}
function longitudmayor( campo, len ){
  return ( campo != null )? (campo.length > len) : false;
}
function estaentre(campo, inicio, fin){
  if ( campo != null ) return ( campo.length >= inicio && campo.length <= fin );
  else return false;
}
var sorry="Derechos Reservados© 2010";
function click(e){
   if (document.all) if (event.button == 2){alert(sorry);return false;} 
   if (document.layers) if (e.which == 3){alert(sorry);return false;}
}
if (document.layers){ document.captureEvents(Event.MOUSEDOWN);}
document.onmousedown=click;
function abreventana(i, j) {
  window.open(i, j, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=no,copyhistory=0,width=600,height=450")
}
function abreventana1(i, j) {
  window.open(i, j, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=no,copyhistory=0,width=880,height=510")
}
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 
function printPage(frame, arg) {
  if (frame == window){printThis();}
  else {link = arg; printFrame(frame); }
  return false;
}
function printThis() {
  if (pr) { // NS4, IE5
    window.print();
  } else if (da && !mac) { // IE4 (Windows)
    vbPrintPage();
  } else { // other browsers
    alert("Disculpe, su browser no soporta esta aplicacion.");
  }
}
function trim(cadena){
  cadena2 = "";
  len = cadena.length;
  for ( var i=0; i <= len ; i++ ) if ( cadena.charAt(i) != " " ){cadena2+=cadena.charAt(i);	}
  return cadena2;
}
function printFrame(frame) {
  if (pr && da) { // IE5
    frame.focus();
    window.print();
    link.focus();
  } else if (pr) { // NS4
    frame.print();
  } else if (da && !mac) { // IE4 (Windows)
    frame.focus();
    setTimeout("vbPrintPage(); link.focus();", 100);
  } else { // other browsers
    alert("Disculpe, su browser no soporta esta aplicacion.");
  }
}
if (da && !pr && !mac) with (document) {
  writeln('<'+'OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<'+'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<'+'/SCRIPT>');
}

 function comprueba_extension(formulario, archivo, extensiones_permitidas) {
	if(extensiones_permitidas == ""){
		extensiones_permitidas = ".txt";
	}
	var mensaje = "";
	if (!archivo) {
		//Si no tengo archivo, es que no se ha seleccionado un archivo en el formulario
		mensaje = "No se ha seleccionado ningún archivo TXT";
	}else{
		//Recupera la extensión de este nombre de archivo
		var extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase();
		//Comprueba si la extensión está entre las permitidas
		var permitida = false;
		if (extensiones_permitidas == extension) { 
			permitida = true;

		}
		if (!permitida) {
			mensaje = "Comprueba la extensión de los archivos a subir. \nSólo se pueden subir archivos con extensiones: " + extensiones_permitidas;
		}else{
			//Envia Submit
			formulario.submit();
			return 1;
		}
	}
	//No envio Submit
	alert (mensaje);
	return 0;
}
function teclaNumero(e) {
	tecla = (document.all) ? e.keyCode : e.which;
	if (tecla==8) return true;
	patron =/[0-9]/;
	te = String.fromCharCode(tecla);
	return patron.test(te);
}

function teclaFecha(e) {
	tecla = (document.all) ? e.keyCode : e.which;
	if (tecla==8) return true;
	patron =/[0123456789\/]/;
	te = String.fromCharCode(tecla);
	return patron.test(te);
}

function validaTecla(e) {
	tecla = (document.all) ? e.keyCode : e.which;
	if (tecla==8) return true;
	patron =/[^\"\'\,\¨\´\;\u002F\u005C]/;
	te = String.fromCharCode(tecla);
	return patron.test(te);
}

function completaFecha(form,txt_lugar, dato){	
	var tam = dato.length;
	var fecha_final = "";
	if (tam==8) {	
		if (esnumero(dato)){
			fecha_final = dato.substring(0,2) + "/" + dato.substring(2,4) + "/" + dato.substring(4,8) 
			if (checkdate(fecha_final)) {
				txt_lugar.value = fecha_final;
			}
		}	
	}	
}

function adjuntaArchivo(form, objeto) {	
	if (esnulo(objeto.value)) {
		alert('Escoja el archivo que desea adjuntar.');
		objeto.focus();	
		return;	
	} else {
		form.accion.value = "adjuntaArchivo";
		comprueba_extension(form,objeto.value,".pdf");	
	}
}

function verificaDatosEliminar(form, tipo, nombre) {
	var cantidad = 0;
	var escogidos = 0;
	for (i = 0; i < form.elements.length; i++) {
		if (form.elements[i].type==tipo && form.elements[i].name==nombre) {
			cantidad++;
			if (form.elements[i].checked) {
			escogidos++;
			}
		}
	}
	if (cantidad == 0) {alert('No ha adjuntado ningun archivo.');return;}
	if (escogidos == 0) {alert('Escoja el archivo que desea eliminar.');return;}
	return true;
}

function eliminaArchivo(form, tipo, nombre) {
	var checos = document.getElementsByName(nombre);	
	var num = checos.length;
	var indices = '';	 
	if (verificaDatosEliminar(form, tipo, nombre)) {
		if (confirm("¿Está seguro de eliminar los archivos seleccionados?")) {
			for ( var i = 0; i < num; i++ ) {
				if ( checos[i].checked ) {
					if (indices == '') {
						indices = checos[i].value;
					} else {
						indices = indices + ',' + checos[i].value;
					}
				}
			}
			form.indices.value = indices;	     	
			form.accion.value = "eliminaArchivo";
			form.submit();
		}
	}
}

function limpiaFile(nombre){  
	obj = document.getElementById(nombre);  
	var newobj = document.createElement('input');  
	newobj.type='file';  
	newobj.size='45';  
	newobj.id=obj.id;  
	newobj.name=obj.name;  
	obj.parentNode.replaceChild(newobj, obj);  	 
}

function bloqueaTecla(){
	var tecla=window.event.keyCode;
	if (tecla==116) {alert(sorry); event.keyCode=0;
	event.returnValue=false;}
}

function validaURLs(url) { 
	var re=/^(ht|f)tps?:\/\/\w+([\.\-\w]+)?\.([a-z]{2,3}|info|mobi|aero|asia|name)(:\d{2,5})?(\/)?((\/).+)?$/i;
	return re.test(url); 
} 

