function campoVacio(campo,nombreCampo)
{
	if (campo.value=="") {
		alert("El campo "+nombreCampo+" no puede estar vacío");
		campo.focus();
		return true;
	}
	return false;
}

function campoVacioDefecto(campo,nombreCampo,valorDefecto)
{
	if (campo.value=="" || campo.value==valorDefecto) {
		alert("El campo "+nombreCampo+" no puede estar vacío");
		campo.focus();
		return true;
	}
	return false;
}

function selectVacio(campo,nombreCampo)
{
	if (campo.options[campo.selectedIndex].value=="") {
		alert("El campo "+nombreCampo+" no puede estar vacío");
		campo.focus();
		return true;
	}
	return false;
}

function opcionVacia(campo, totalOpciones, mensaje)
{
	var seleccionado=false;
	
	if (totalOpciones>1) {
		for (var i=0; i<totalOpciones && !seleccionado; i++)
		{
			if (campo[i].checked) {
				seleccionado=true;
			}
		}
	} else if (campo.checked) {
		seleccionado=true;
	}

	if (!seleccionado) {
		alert(mensaje);
		if (totalOpciones>1) {campo[0].focus(); } else {campo.focus(); }
		return true;
	}
	return false;
}

function isNumeric(n)
{
	var number = '0';
	var longi = n.length;
	for (var i = 0; i < longi; i++)
	{
		number = n.charAt(i);
		if (number >= '0' && number <= '9')
			continue;
		else 
			return false;
	}
	return true;
}

function isFloat (n)
{
	var number = '0';
	var nPoint = 0;
	for (var i = 0; i < n.length; i++)
	{
		number = n.charAt(i);
		if (number >= '0' && number <= '9')
			continue;
		else if (number == '-' && i==0)
			continue;
		else if (number == '.' && nPoint==0) {
			nPoint=1;
			continue;
		}
		else 
			return false;
	}
	return true;
}

function longExcesiva(campo,nombreCampo,longMax)
{
	if (campo.value.length > longMax) {
		alert("No puedes introducir más de "+longMax+" caracteres en el campo "+nombreCampo);
		campo.focus();
		return true;
	}
	return false;
}

function isEmail(email)
{
	var posArroba = email.indexOf('@',0);
	
	if (posArroba <= 0)
		return false;

	var posPunto = email.indexOf('.',posArroba);
		
	if (posPunto == -1)
		return false;
		
	if (posPunto+1 == email.length)
		return false;

	return true;
}

function isAlfanumerico(valor)
{
	var longi = valor.length;
	var c;
	valor = valor.toLowerCase();
	
	if (longi>0) {
		c = valor.charAt(0);
		if (!(c >= 'a' && c <= 'z')) {
			return false;
		}
	}
	
	for (var i = 1; i < longi; i++)
	{
		c = valor.charAt(i);
		if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || c=='_' || c=='.')
			continue;
		else 
			return false;
	}
	return true;
}

function contieneCaracteresPermitidos(valor, caracteresValidos)
{
	var longi = valor.length;
	var c;
	valor = valor.toLowerCase();
	
	for (var i = 0; i < longi; i++)
	{
		c = valor.charAt(i);
		if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z')) {
			continue;
		} else {
			for (var j=0; j<caracteresValidos.length; j++) {
				if (caracteresValidos.indexOf(c)==-1) {
					return false;
				}
			}
		}
	}
	return true;
}

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;
}	


	function isMail(_email) {
		var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
	return emailReg.test(_email);
}


