// JavaScript Document

function vText(v, lg){
	if(v.value != ""){ return 1; }else{ 
	alert(alertCampoObligatorio);
	v.style.border="1px solid #F66";
	v.focus();
	return 0; }
}

function vCaracteresMin(v,n, lg){
	if(v.value.length >= n){ return 1; }else{ 
	/*switch(lg){
	case "en":
		alert("Character’s number insufficient.\nyou must fill at least "+n+" characters.");
		break;
	case "fr":
		alert("Nombre de caractères insuffisants. \nLe champ doit contenir au moins "+n+" caractères.");
		break;
	default:
		alert("Número de caracteres insuficiente.\nEl campo debe contener al menos "+n+" caracteres.");
		break;
	}*/
	alert(alertCaracteresInsuficientes+" "+n+" "+alertCaracteres);
	v.style.border="1px solid #F66";
	v.focus();
	return 0; }
}

function vEmail(v, lg){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(v.value)){ return 1; } else { 
	/*switch(lg){
	case "en":
		alert("Invalid email");
		break;
	case "fr":
		alert("L’email n’est pas valide");
		break;
	default:
		alert("El e-mail no es correcto");
		break;
	}*/
	alert(alertEmailNoValido);
	v.style.border="1px solid #F66";
	v.focus();
	return 0; }
}

function vEquidad(v1,v2, lg){
	if (v1.value==v2.value){ return 1; } else { 
	/*switch(lg){
	case "en":
		alert("The value does not match");
		break;
	case "fr":
		alert("La valeur des champs de coïncide pas");
		break;
	default:
		alert("El valor de los dos campos no coincide");
		break;
	}*/
	alert(alertValoresNoCoinciden);
	v2.style.border="1px solid #F66";
	v2.focus();
	return 0; }
}

/*function quitarTodosEspacios(cadena) {
	for(i=0; i<cadena.length; i++) {
		if(cadena.charAt(i)==" ") {
			cadena=cadena.substring(i+1, cadena.length);
		}
	}

	for(i=cadena.length-1; i>=0; i--)	{
		if(cadena.charAt(i)==" ") {
			cadena=cadena.substring(0,i);
		}
		
	}
	
	return cadena;
}*/
function vNum(v, lg) {
	// Return immediately if an invalid value was passed in
	if (v.value+"" == "undefined" || v.value+"" == "null" || v.value+"" == "") {
		/*switch(lg){
		case "en":
			alert("Required field.");
			break;
		case "fr":
			alert("Champ obligatoire.");
			break;
		default:
			alert("Campo obligatorio.");
			break;
		}*/
		alert(alertCampoObligatorio);
		v.style.border="1px solid #F66";
		v.focus();
		return 0;
	}
	var isValid = 1;
	
	// convert to a string for performing string comparisons.
	v.value += ""; 
	// Loop through length of string and test for any alpha numeric 
	// characters
	for (i = 0; i < v.value.length; i++) {
		// Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z"
		if (!((v.value.charAt(i) >= "0") && (v.value.charAt(i) <= "9")))
		{
			isValid = 0;
			/*switch(lg){
			case "en":
				alert("You must introduce a value number");
				break;
			case "fr":
				alert("Vous devez entrer une valeur numérique dans ce champ");
				break;
			default:
				alert("Debe introducir un valor numérico para este campo");
				break;
			}*/
			alert(alertNumeroObligatorio);
			v.style.border="1px solid #F66";
			v.focus();
			break;
		} 
	} // END for 
	return isValid;
} // end vNum

function vAlfaNum(v, lg) {
	// Return immediately if an invalid value was passed in
	if (v.value+"" == "undefined" || v.value+"" == "null" || v.value+"" == "") {
		/*switch(lg){
		case "en":
			alert("Required field.");
			break;
		case "fr":
			alert("Champ obligatoire.");
			break;
		default:
			alert("Campo obligatorio.");
			break;
		}*/
		alert(alertCampoObligatorio);
		v.style.border="1px solid #F66";
		v.focus();
		return 0;
	}
	var isValid = 1;
	
	// convert to a string for performing string comparisons.
	v.value += ""; 
	// Loop through length of string and test for any alpha numeric 
	// characters
	for (i = 0; i < v.value.length; i++) {
		// Alphanumeric must be between "0"-"9", "A"-"Z", or "a"-"z"
		if (!(((v.value.charAt(i) >= "0") && (v.value.charAt(i) <= "9")) || 
		((v.value.charAt(i) >= "a") && (v.value.charAt(i) <= "z")) ||
		((v.value.charAt(i) >= "A") && (v.value.charAt(i) <= "Z"))))
		{
			isValid = 0;
			/*switch(lg){
			case "en":
				alert("The field only can be filled by alphanumeric characters, with no spaces.");
				break;
			case "fr":
				alert("Ce champ n’autorise que des valeurs alphanumériques anglo-saxons et sans espaces");
				break;
			default:
				alert("El campo solo puede contener caracteres alfanuméricos anglosajones\ny no debe contener espacios.");
				break;
			}*/
			alert(alertSoloAlfanumericos);
			v.style.border="1px solid #F66";
			v.focus();
			break;
		} 
	} // END for 
	return isValid;
} // end vAlfaNum

function validarBusquedaBaby(f,lg){
	salida = vCaracteresMin(f.q,3,lg);
	if(salida==1){
		return true;
	}else{
		return false;
	}
}
