// Removes leading whitespaces
function LTrim( value ) {	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");	
}

// Removes ending whitespaces
function RTrim( value ) {	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");	
}

// Removes leading and ending whitespaces
function trim( value ) {	
	return LTrim(RTrim(value));	
}


function detectar_elemento(ele){
	if(ele.tagName == "INPUT"){		
		var td = ele.parentNode;
		tr = td.parentNode;			
	}
	else if(ele.tagName == "TD"){
		tr = ele.parentNode;			
	}
	else{
		tr = null;
	}
	return tr;
}


function validatePass(campo) {
    var RegExPattern = /(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$/;
    if ((campo.value.match(RegExPattern)) && (campo.value!='')) {
        return true;
    } else {
        campo.focus();
		return false;
    } 
}

function emailCheck (email) {
	//var campo = document.getElementById(email);
	//var emailStr = campo.value;
	var emailStr = email;
	if(emailStr.length>=1){
		/* Verificar si el email tiene el formato user@dominio. */
		var emailPat=/^(.+)@(.+)$/
		
		/* Verificar la existencia de caracteres. ( ) < > @ , ; : \ " . [ ] */
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		
		/* Verifica los caracteres que son válidos en una dirección de email */
		var validChars="\[^\\s" + specialChars + "\]"
		
		var quotedUser="(\"[^\"]*\")"
		
		/* Verifica si la dirección de email está representada con una dirección IP Válida */
		
		
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		
		/* Verificar caracteres inválidos */
		
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		/*domain, as opposed to ipDomainPat, shown above. */
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
		
		
		var matchArray=emailStr.match(emailPat)
		if (matchArray==null) {
		alert("La dirección de email es incorecta")
		return false;
		}
		var user=matchArray[1]
		var domain=matchArray[2]
		
		// Si el user "user" es valido 
		if (user.match(userPat)==null) {
		// Si no
		alert("El nombre de usuario de el correo no es válido.");
		return false;
		}
		
		/* Si la dirección IP es válida */
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
		alert("IP de destino inválida");
		return false;
		}
		}
		return true;
		}
		
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
		alert("El dominio parece no ser válido.")
		return false;
		}
		
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length;
		if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
		
		alert("La dicrección debe tener 3 letras si es .\"com\" o 2 si es de algún pais.");
		return false;
		}
		
		if (len<2) {
		var errStr="La dirección es erronea";
		alert(errStr);
		return false;
		}
		
		// La dirección de email ingresada es Válida
		return true;
	}
}

function getWindowData(){
    var widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal;
    if (typeof window.innerWidth != 'undefined'){
        widthViewport= window.innerWidth-17;
        heightViewport= window.innerHeight-17;
    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){
        widthViewport=document.documentElement.clientWidth;
        heightViewport=document.documentElement.clientHeight;
    }else{
        widthViewport= document.getElementsByTagName('body')[0].clientWidth;
        heightViewport=document.getElementsByTagName('body')[0].clientHeight;
    }
    xScroll=self.pageXOffset || (document.documentElement.scrollLeft+document.body.scrollLeft);
    yScroll=self.pageYOffset || (document.documentElement.scrollTop+document.body.scrollTop);
    widthTotal=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth,widthViewport);
    heightTotal=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,heightViewport);
    return [widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal];
}


/*
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
	function test() {
		var str = "             a             ";
		alert("Original string: '" + str + "'");
		str = str.trim();
		alert("Incompletely stripped string: '" + str + "'");
	}
	test(); 
*/
//String.prototype.trim = function() { return this.replace(/^s+|s+$/g, ""); };

