//** Funciones privadas
//** --- NO UTILIZAR DIRECTAMENTE --
function limitar_adjuntos(objTxt,mensaje,arreglo_permitidos,setfoco){
	var nombre_archivo = objTxt.value;
	if (!nombre_archivo) return false;
	while (nombre_archivo.indexOf("\\") != -1)
	nombre_archivo = nombre_archivo.slice(nombre_archivo.indexOf("\\") + 1);
	ext = nombre_archivo.slice(nombre_archivo.lastIndexOf(".")).toLowerCase();

	for (var i = 0; i < arreglo_permitidos.length; i++){
		if (arreglo_permitidos[i] == ext){
			return false;
		}
	}
	if(mensaje != "") alert(mensaje + "\narchivos permitidos: " + (arreglo_permitidos.join("  ")) + "\nPor favor, seleccione un nuevo archivo");
	if(setfoco) { objTxt.select(); objTxt.focus(); }
	return true;
}

function Trim(s) {
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	s = s.substring(1,s.length);
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	s = s.substring(0,s.length-1);
	return s;
}

function Del(Word) {
	var a = Word.indexOf("<");
	var b = Word.indexOf(">");
	var len = Word.length;
	var c = Word.substring(0, a);
	if(b == -1)	b = a;
	var d = Word.substring((b + 1), len);
	Word = c + d;
	var tagCheck = Word.indexOf("<");
	if(tagCheck != -1)	Word = Del(Word);
	return Word;
}

/*
function  validateNumeric(strValue) {
	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	return objRegExp.test(strValue);
}*/

function validateEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) return (true);
	return (false);
}

//esta
function no_es_entero(objTxt,solopositivos,mensaje,setfoco) {
	var valor = objTxt.value;
	var es_entero;
	if(valor != "") {
		if(solopositivos) {
			if(isNaN(valor) || isNaN(parseInt(valor,10)) || valor.indexOf('.') > -1 || valor.indexOf('-') > -1) {
				es_entero=false;
			}else { es_entero=true; }
		}
		else {
			if(isNaN(valor) || isNaN(parseInt(valor,10)) || valor.indexOf('.') > -1) {
				es_entero=false;
			}else { es_entero=true; }
		}
		if(!es_entero) {
			if(mensaje != "") alert(mensaje);
			if(setfoco) { objTxt.select(); objTxt.focus(); }
			return true;
		}
		return false;
	} else return false;
}

//esta
function no_es_numero(objTxt,solopositivos,mensaje,setfoco) {
	var valor = objTxt.value;
	var es_numero;
	if(solopositivos) {
		if(isNaN(valor) || Trim(valor) == "" || valor.indexOf('-') > -1) {
			es_numero=false;
		}else { es_numero=true; }
	}
	else {
		if(isNaN(valor) || Trim(valor) == "") {
			es_numero=false;
		}else { es_numero=true; }
	}
	if(!es_numero) {
		if(mensaje != "") alert(mensaje);
		if(setfoco) { objTxt.select(); objTxt.focus(); }
		return true;
	}
	return false;
}

//esta
function no_en_rango(objTxt,limiteinf,limitesup,mensaje,setfoco) {
	var valor = parseFloat(objTxt.value);
	if(no_es_numero(objTxt,false,"Para verificar un rango, el valor debe ser un número",setfoco)) return true;
	if( (valor < limiteinf)	|| (limitesup < valor) )	{
		if(mensaje != "") alert(mensaje);
		if(setfoco) { objTxt.select(); objTxt.focus(); }
		return true;
	}
	return false;
}

//esta
function cadena_vacia(objTxt,hacertrim,mensaje,setfoco) {
var valor = objTxt.value;
	if(Trim(valor) == "") {
		if(mensaje != "") alert(mensaje);
		if(setfoco) { objTxt.select(); objTxt.focus(); }
		return true;
	}
	return false;
}

function editor_vacio(objEditor,hacertrim,mensaje,setfoco) {
	var valor = objEditor.GetXHTML();
	valor = Del(valor);
	valor = valor.replace(/&nbsp;/g,"");
	valor = Trim(valor);
	if(valor=="") {
		if(mensaje != "") alert(mensaje);
		if(setfoco) { objEditor.Focus(); }
		return true;
	}
	return false;
}

/*
function no_casillas_seleccionadas(objChk,numselecciones,mensaje) {
	var chequeados = 0;
	var i;
	if(typeof(objChk.length)=="number") {
		for(i=0; i<objChk.length; i++) {
			if (objChk[i].checked)	chequeados++;
		}
	}
	else {
		if (objChk.checked)	chequeados++;
	}
	if(chequeados < numselecciones) {
		if(mensaje != "") alert(mensaje);
		return true;
	}
	return false;
}
*/

function no_casillas_seleccionadas(objChk,numselecciones,mensaje) {
	var chequeados = 0;
	var i;
	if(typeof(objChk.length)=="number") {
		for(i=0; i<objChk.length; i++) {
//			if (objChk[i].disabled==true){
//				alert(objChk[i].value);
				if (objChk[i].checked) chequeados++;
//			}
		}
	}
	else {
		if (objChk.checked)	chequeados++;
	}
	if(chequeados < numselecciones) {
		if(mensaje != "") alert(mensaje);
		return true;
	}
	return false;
}


function no_seleccionado_en_multiple(objSel,numselecciones,mensaje,setfoco) {
	var chequeados = 0;
	var i;
	if(typeof(objSel.length)=="number") {
		for(i=0; i<objSel.length; i++) {
			if (objSel[i].selected)	chequeados++;
		}
	}
	else {
		if (objSel.selected)	chequeados++;
	}
	if(chequeados < numselecciones) {
		if(mensaje != "") alert(mensaje);
		if(setfoco) { objSel.focus(); }
		return true;
	}
	return false;
}

//esta
function longitud_mayor(objTxt,limite,hacertrim,mensaje,setfoco) {
	var cad = "";
	var valor = objTxt.value;
	cad = valor;
	if(hacertrim) cad = Trim(valor);
	if(cadena_vacia(objTxt,hacertrim,"",false) || cad.length > limite) {	
		if(mensaje != "") alert(mensaje);
		if(setfoco) { objTxt.select(); objTxt.focus(); }
		return true;
	}
	return false;
}

//esta
function longitud_menor(objTxt,limite,hacertrim,mensaje,setfoco) {
	var esmenor = !longitud_mayor(objTxt,limite,hacertrim,"",false);
	if(esmenor) {
		if(mensaje != "") alert(mensaje);
		if(setfoco) { objTxt.select(); objTxt.focus(); }
		return true;
	}
	return false;
}

//esta
function es_valor_diferente(objTxt,valorcompara,hacertrim,mensaje,setfoco) {
	var cad = "";
	var valor = objTxt.value;
	cad = valor;
	var valcompara = "";
	valcompara = valorcompara.value;
	if(hacertrim) { cad = Trim(valor); valcompara=Trim(valcompara); }
	if(cad != valcompara) {
		if(mensaje != "") alert(mensaje);
		if(setfoco) { objTxt.select(); objTxt.focus(); }
		return true;
	}
	return false;
}

function primero_seleccionado_de_lista(objSelect,mensaje,setfoco) {
	if (objSelect.selectedIndex==0){
    	if(mensaje != "") alert(mensaje);
    	if(setfoco) { objSelect.focus(); }
		return true;
    }
    return false;
}

function casilla_no_seleccionada(objChk,mensaje,setfoco) {
	if (!objChk.checked){
    	if(mensaje != "") alert(mensaje);
    	if(setfoco) { objChk.focus(); }
		return true;
    }
    return false;
}

//esta
function no_es_correo(objTxt,mensaje,setfoco) {
	var cadena_correos = objTxt.value;
	var arreglo_correos = cadena_correos.split(',');
	var cantidad_correos = arreglo_correos.length;
	for (i=0;i<cantidad_correos;i++){
		if(!validateEmail(arreglo_correos[i])) {
			if(mensaje != "") alert(mensaje);
			if(setfoco) { objTxt.select(); objTxt.focus(); }
			return true;
		}
	}
	return false;
}

function es_valor_igual(objTxt,valorcompara,hacertrim,mensaje,setfoco) {
	var cad = "";
	var valor = objTxt.value;
	cad = valor;
	if(hacertrim) { cad = Trim(valor); valorcompara=Trim(valorcompara); }
	if(cad == valorcompara) {
		if(mensaje != "") alert(mensaje);
		if(setfoco) { objTxt.select(); objTxt.focus(); }
		return true;
	}
	return false;
}

function comparar_fechas(fecha_inial,fecha_final,mensaje,setfoco){
	var fecha  	= fecha_inial.value.split("/");
	var fecha2 	= fecha_final.value.split("/");
	var retorno	= false;

	ano1=fecha[2];
	mes1=fecha[1];
	dia1=fecha[0];

	ano2=fecha2[2];
	mes2=fecha2[1];
	dia2=fecha2[0];

	if (ano2 < ano1) {
    	retorno = true;
    }
	if((ano1 == ano2) && (mes2 < mes1))  {
    	retorno = true;
    }
	if((ano1 == ano2) && (mes1 == mes2) && (dia2 < dia1))  {
    	retorno = true;
    }

	if (retorno){
		if(mensaje != "") alert(mensaje);
		return true;
	}else{
		return false;
	}
}

function no_son_letras(objTxt,mensaje,setfoco){
	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
	var checkStr = objTxt.value;
	var allValid = true;
	for (i = 0; i < checkStr.length; i++){
		ch = checkStr.charAt(i);
		for (j = 0; j <= checkOK.length; j++){
			if (ch == checkOK.charAt(j)) break;
			if (j == checkOK.length) {
				allValid = false;
				break;
			}
		}
	}
	if (!allValid){
		alert(mensaje);
		if (setfoco) objTxt.focus();
		return true;
	}else return false;
}

//****************************************LUXA => NOV-27-2007*************
function numero_mayor(objTxt,limite,hacertrim,mensaje,setfoco) {	
	var valor = objTxt.value;	
	if(cadena_vacia(objTxt,hacertrim,"",false) || valor > limite) {	
		if(mensaje != "") alert(mensaje);
		if(setfoco) { objTxt.select(); objTxt.focus(); }
		return true;
	}
	return false;
}