function isNotEmpty(elem) {
    var str = elem.value;
    var re = /.+/;
    if(!str.match(re)) {
        alert("Por favor, llene los campos requeridos.");
        return false;
    } else {
        return true;
    }
}
function isEmailAddr(elem) {
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Verifique su direccion de email.");
		elem.value = "";
		return false;
    } else {
        return true;
    }
}
function isCedula(elem)
{
	var str = elem.value;
    var re = /\b[0-9]{1,2}-[0-9]{1,4}-[0-9]{1,5}\b/;
    if (!str.match(re)) {
        alert("Verifique su formato de cedula.");
        return false;
    } else {
        return true;
    }
}
//Funcion para eliminar los espacios
function Trim( str ) {
	var resultStr = "";
	
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	
	return resultStr;
}
//Funcion para eliminar los espacios a la derecha
function TrimRight( str ) {
	var resultStr = "";
	var i = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";
	
	if (str.length == 0) 
		resultStr = "";
	else {
  		// Loop through string starting at the end as long as there
  		// are spaces.
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
 			
 		// When the loop is done, we're sitting at the last non-space char,
 		// so return that char plus all previous chars of the string.
  		resultStr = str.substring(0, i + 1);
  	}
  	
  	return resultStr;  	
}
//Funcion para eliminar los espacios a la derecha
function TrimLeft( str ) {
	var resultStr = "";
	var i = len = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";

	if (str.length == 0) 
		resultStr = "";
	else {	
  		// Loop through string starting at the beginning as long as there
  		// are spaces.
//	  	len = str.length - 1;
		len = str.length;
		
  		while ((i <= len) && (str.charAt(i) == " "))
			i++;

   	// When the loop is done, we're sitting at the first non-space char,
 		// so return that char plus the remaining chars of the string.
  		resultStr = str.substring(i, len);
  	}

  	return resultStr;
}
//Funcion para validar numeros en un textbox
function isNumber(evt)
{
	evt = (evt) ? evt:event;
	charCode = (evt.CharCode) ? evt.charCode : ((evt.keyCode)  ? evt.keyCode: ((evt.which) ? evt.which : 0));
	if (charCode > 31 && (charCode < 48 || charCode > 57)){
		alert("Introduzca solo números por favor");
		return false;
	}
	return true;
}
//Funcion para validar que en el textbox introduzcan solo letras
function soloLetras(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	if (charCode > 31 && (charCode < 65 || charCode > 90)  &&  (charCode < 97 || charCode > 122)) {
		alert("Introduzca solo letras por favor");
        return false;
    }
    return true;
}
//Funcion para validar solo la letra y o la letra n
// Se utiliza colocando el maxlenght del textbox en 1
function soloYN(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :  ((evt.which) ? evt.which : 0));
    if (charCode > 31 && charCode != 78 && charCode != 89 && charCode != 110 && charCode != 121) {
        alert("Enter \"Y\" or \"N\" only.");
        return false;
    }
    return true;
}
function vHttp(elem) {
    	
	var str = elem.value;
    var re = "^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$";
    if (!str.match(re)) {
        alert("Ingresar una direccion valida.");
		elem.value = "http://";
		return false;
    } else {
        return true;
    }
} 
function isChosen(select) {
    if (select.selectedIndex == 0) {
        alert("Debes seleccionar una categoria.");
        return false;
    } else {
        return true;
    }
}
function isChosen_one(select) {
    if (select.options[select.selectedIndex].value == -1) {
		alert('Debes seleccionar un Campo');
        return false;
    } else {
        return true;
    }
}
function maxCaract(elem,maximo){
	
	var str = elem.value;
	var cant = 	str.length;
	if (cant > maximo){
		alert("El campo descripción solo acepta " + maximo + " caracteres y tiene " + cant);
		return false;
	} else {
        return true;
	}
	
}


function isDate(elem) {
	var str = elem.value;
	
    if(str == 'dd/mm/yy') {
        alert("Por favor, ingrese una fecha correcta.");
        return false;
    } else {
        return true;
    }
}

function isExtencion(elem, ext){
	var str = elem.value;
	
    var re = '/.' + ext + '$/';
	var re = /.pdf$/;
    if(!str.match(re)) {
        alert("El formato del archivo no es el correcto.");
        return false;
    } else {
        return true;
    }
}