function LTrim(s){
	// Devuelve una cadena sin los espacios del principio
	var i=0;
	var j=0;

	// Busca el primer caracter <> de un espacio
	for(i=0; i<=s.length-1; i++)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(j, s.length);
}

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/geral/is-date [v1.0]

isDate = function(y, m, d){ //v1.0
        if(typeof y == "string" && m instanceof RegExp && d){
            if(!m.test(y)) return 1;
            y = RegExp["$" + d.y], m = RegExp["$" + d.m], d = RegExp["$" + d.d];
        }
        d = Math.abs(d) || 0, m = Math.abs(m) || 0, y = Math.abs(y) || 0;
        return arguments.length != 3 ? 1 : d < 1 || d > 31 ? 2 : m < 1 || m > 12 ? 3 : /4|6|9|11/.test(m) && d == 31 ? 4
        : m == 2 && (d > ((y = !(y % 4) && (y % 1e2) || !(y % 4e2)) ? 29 : 28)) ? 5 + !!y : 0;
};

function isValidDate(fecha)
{
  return isDate(fecha,/^([0-9]{1,2})[\/]([0-9]{1,2})[\/]([0-9]{1,4})$/, {d: 2, m: 1, y: 3}) == 0;
}

function RTrim(s){
	// Quita los espacios en blanco del final de la cadena
	var j=0;

	// Busca el último caracter <> de un espacio
	for(var i=s.length-1; i>-1; i--)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}

	if(s.substring(0, j+1)!=' ')
		return s.substring(0, j+1);
	else
		return s.substring(0, j);
}
function Trim(s){
	// Quita los espacios del principio y del final
	return LTrim(RTrim(s));
}
function LargoPermitido(cadena,largo){

	if(cadena.length>largo)
		return false;
	else
		return true;

}
function CheckboxChecker(form,checkbox){

	checkbox_choices = 0;

	for (counter = 0; counter < form.checkbox.length; counter++){
		if (form.checkbox[counter].checked){
			checkbox_choices = checkbox_choices + 1;
		}
	}
	return checkbox_choices;
}
function isDigit (c){
	return ((c >= "0") && (c <= "9"))
}
function EsEntero(s){
	var i;
    
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
			if (!isDigit(c)){
				return false;
			}
   	}
	return true;
}
function isInteger(valor){
    //intento convertir a entero.
    //si era un entero no le afecta, si no lo era lo intenta convertir
    valor = parseInt(valor);

    //Compruebo si es un valor numérico
    if (isNaN(valor)) {
       //entonces (no es numero) devuelvo el valor cadena vacia
       return false;
    }else{
       //En caso contrario (Si era un número) devuelvo el valor
       return true;
    }
}
function EsEmail(w_email) {
    if(w_email == '')
        return true;
	//si le pones comillas a test se caga
    var test = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var emailReg = new RegExp(test);

	return emailReg.test(w_email);
}

function LargoMinimo(cadena,largo){

	if(cadena.length>0 && cadena.length<largo)
		return false;
	else
		return true;


}
function LargoPermitido(cadena,largo){

	if(cadena.length>largo)
		return false;
	else
		return true;


}
function NoVacio(cadena){

	if(Trim(cadena)=="" || Trim(cadena)=="<br>" || cadena.length==0)
		return false;
	else
		return true;

}
function SonIguales(campo1,campo2){
	if(campo1!=campo2)
		return false;
	else
		return true;
}
function SonGrupo(campo1,campo2,campo3){
	if((campo1 != '' || campo2 != '') && (campo1 == '' || campo2 == '') && (campo3 == ''))
		return 'Picture and Thumbnail must be completed';
	if((campo1 != '') && (campo3 != ''))
		return 'Pictures and Press files are mutually exclusive';
	return '';
}

function asignaClase(objeto,clase) {
    document.getElementById(objeto).className = clase;
}


function existeUsuario(usuario) {

    var http = getHTTPObject();

    http.open("GET", 'archivo.php?usuario=' + escape(usuario), false);
    http.send(null);

    if (http.readyState == 4 && http.status == 200) {
        result = http.responseText;
        if(result=='1'){
        	return false;
        }else{
        	return true;
        }
    }else{
        return false;
    }

}
function existeEmail(email) {

    var http = getHTTPObject();

    http.open("GET", 'archivo.php?email=' + escape(email), false);
    http.send(null);

    if (http.readyState == 4 && http.status == 200) {
        result = http.responseText;
        if(result=='1'){
            return false;
        }else{
            return true;
        }
    }else{
        return false;
    }

}
function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
    try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
    xmlhttp = false;
    }
    }
    @else
    xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}
function isdefined(variable){
    return (typeof(window[variable]) == "undefined")?  false: true;
}
function mifuncion(valor){
	if(valor>0)
		return true;
	else
		return false;

}
function EsUrl(s) {
    var v = new RegExp();
    v.compile("^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=\+\?]+$");
	return v.test(s);
}

function EsIP(s) {
    var v = new RegExp();
    v.compile("^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$");
	return v.test(s);
}

function EsUrlbk(s) {
	var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}
function SonExc(campo1,campo2){
	if(((campo1 == '' || campo1 == '<p />') && (campo2 == '' || campo2 == '<p />')) || ((campo1 != '' && campo1 == '<p />') && (campo2 == '' && campo2 == '<p />'))){
		return false;
	} else {
		return true;
	}
}

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Robert Nyman | http://robertnyman.com/ */
function removeHTMLTags(strInputCode){
 		/* 
  			This line is optional, it replaces escaped brackets with real ones, 
  			i.e. < is replaced with < and > is replaced with >
 		*/	
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
 		return strTagStrippedText;
}

/*Devuelve true si, por mas tags html que haya, en realidad no dice nada*/
function isHTMLEmpty(controlId) {
  var strText = this[controlId+'_rEdit'].document.body.innerHTML;
  strText = removeHTMLTags(strText);
  strText = strText.replace(/(\s|\&nbsp;)*/g,"");
  return strText.length == 0;
}
