function validateContacto(pIdioma, pNombre_Literal, pApellido1_Literal, pDir_literal, pPob_literal, pCP_Literal, pProv_Literal, pPais_Literal, pTel_Literal, pEmail_Literal, pCom_Literal) {
	//1. Campos obligatorios (Nombre, Apellido1, Pais, Telefono o Email)
	//2. Max length de campo Comentarios
	//3. Email válido
	//4. Teléfono y Fax válidos (sólo números)
	
	var sHtml = "";
	var sValCamposObligatorios = "";
	var sValComentarios = "";
	var sValEmail = "";
	var sValTel = "";
	var sValFax = "";
	
	document.getElementById("validacion").innerHTML = "";
	document.getElementById("validacion").style.display = "none";
	
	//1. Campos obligatorios:
	if (trimAll(document.getElementById("Nombre").value) == "") {
		if (sValCamposObligatorios == "") {
			sValCamposObligatorios = pNombre_Literal;
		}
		else {
			sValCamposObligatorios = sValCamposObligatorios + ", " + pNombre_Literal;
		}
	}
	if (trimAll(document.getElementById("Apellido1").value) == "") {
		if (sValCamposObligatorios == "") {
			sValCamposObligatorios = pApellido1_Literal;
		}
		else {
			sValCamposObligatorios = sValCamposObligatorios + ", " + pApellido1_Literal;
		}
	}
	//if (trimAll(document.getElementById("Direccion").value) == "") {
	//	if (sValCamposObligatorios == "") {
	//		sValCamposObligatorios = pDir_literal;
	//	}
	//	else {
	//		sValCamposObligatorios = sValCamposObligatorios + ", " + pDir_literal;
	//	}
	//}
	//if (trimAll(document.getElementById("Poblacion").value) == "") {
	//	if (sValCamposObligatorios == "") {
	//		sValCamposObligatorios = pPob_literal;
	//	}
	//	else {
	//		sValCamposObligatorios = sValCamposObligatorios + ", " + pPob_literal;
	//	}
	//}
	//if (trimAll(document.getElementById("CodigoPostal").value) == "") {
	//	if (sValCamposObligatorios == "") {
	//		sValCamposObligatorios = pCP_Literal;
	//	}
	//	else {
	//		sValCamposObligatorios = sValCamposObligatorios + ", " + pCP_Literal;
	//	}
	//}
	//if (trimAll(document.getElementById("Provincia").value) == "") {
	//	if (sValCamposObligatorios == "") {
	//		sValCamposObligatorios = pProv_Literal;
	//	}
	//	else {
	//		sValCamposObligatorios = sValCamposObligatorios + ", " + pProv_Literal;
	//	}
	//}
	if (trimAll(document.getElementById("Pais").value) == "") {
		if (sValCamposObligatorios == "") {
			sValCamposObligatorios = pPais_Literal;
		}
		else {
			sValCamposObligatorios = sValCamposObligatorios + ", " + pPais_Literal;
		}
	}
	//if (trimAll(document.getElementById("Telefono").value) == "") {
	//	if (sValCamposObligatorios == "") {
	//		sValCamposObligatorios = pTel_Literal;
	//	}
	//	else {
	//		sValCamposObligatorios = sValCamposObligatorios + ", " + pTel_Literal;
	//	}
	//}
	if (trimAll(document.getElementById("Email").value) == "" && trimAll(document.getElementById("Telefono").value) == "") {
		if (sValCamposObligatorios == "") {
			if (pIdioma == "ING") {
				sValCamposObligatorios = pEmail_Literal + " or " + pTel_Literal;
			}
			else {
				sValCamposObligatorios = pEmail_Literal + " o " + pTel_Literal;
			}
		}
		else {
			if (pIdioma == "ING") {
				sValCamposObligatorios = sValCamposObligatorios + ", " + pEmail_Literal + " or " + pTel_Literal;
			}
			else {
				sValCamposObligatorios = sValCamposObligatorios + ", " + pEmail_Literal + " o " + pTel_Literal;
			}
		}
	}
	//if (trimAll(document.getElementById("Texto").value) == "") {
	//	if (sValCamposObligatorios == "") {
	//		sValCamposObligatorios = pCom_Literal;
	//	}
	//	else {
	//		sValCamposObligatorios = sValCamposObligatorios + ", " + pCom_Literal;
	//	}
	//}
	
	//2. Max length de campo Comentarios:
	if (document.getElementById("Texto").value.length > 1024) {
		if (pIdioma == "ING") {
			sValComentarios = "The maximum length of the Commentary field is of 1024 characters.";
		}
		else {
			sValComentarios = "La longitud màxima del camp de Comentaris és de 1024 carácteres.";
		}
	}
	
	//3. Email válido:
	if (!isValidEmail(document.getElementById("Email").value, false)) {
		if (pIdioma == "ING") {
			sValEmail = "Please enter a valid email address.";
		}
		else {
			sValEmail = "Per favor introdueixi un e-mail vàlid.";
		}
			
	}
	
	//4. Teléfono y Fax válidos (sólo números y "+")
	if (!allValidDigits(document.getElementById("Telefono").value)) {
		if (pIdioma == "ING") {
			sValTel = "Please enter only digits in the phone number field.";
		}
		else {
			sValTel = "Per favor introdueixi només dígits en el camp telèfon.";
		}
	}
	if (!allValidDigits(document.getElementById("Fax").value)) {
		if (pIdioma == "ING") {
			sValFax = "Please enter only digits in the fax number field.";
		}
		else {
			sValFax = "Per favor introdueixi només dígits en el camp fax.";
		}
	}
	if (sValCamposObligatorios != "") {
		if (pIdioma == "ING") {
			sHtml = sHtml + "The following fields are compulsory: " + sValCamposObligatorios + "<br>";
		}
		else {
			sHtml = sHtml + "Els següents camps són obligatoris: " + sValCamposObligatorios + "<br>";
		}
	}
	if (sValEmail != "") {
		sHtml = sHtml + sValEmail + "<br>";
	}
	if (sValTel != "") {
		sHtml = sHtml + sValTel + "<br>";
	}
	if (sValFax != "") {
		sHtml = sHtml + sValFax + "<br>";
	}
	if (sValComentarios != "") {
		sHtml = sHtml + sValComentarios + "<br>";
	}
	if (sHtml != "") {
		document.getElementById("validacion").innerHTML = sHtml;
		document.getElementById("validacion").style.display = "block";
		//document.getElementById("top").focus();
		location.hash="top";
		return false;
	}
	else {
		return true;
	}
}


function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    }
	
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

function allValidDigits(telefono) {
  var parsed = true;
  var validchars = "+0123456789";
  for (var i=0; i < telefono.length; i++) {
    var digit = telefono.charAt(i).toLowerCase();
    if (validchars.indexOf(digit) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}