function ValidateEmail()
  	{
	var email;

	email= document.getElementById("txtEmail").value;
    if (! allValidChars_email(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;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
  }
  
function allValidChars_email(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 validar_formulario(formulario,idioma)
{	  			
	if (idioma=="es") 
	{
		strMensajeNombre = "Por favor introduzca su nombre";
		strMensajeApellido = "Por favor introduzca su apellido";
		strMensajeEmail = "Por favor introduzca su email";
		strMensajeEmailCorrecto = "Por favor introduzca un email válido";
		strMensajeComentario = "Por favor introduzca si mensaje";
		url_destino =  "http://www.calaceiteresidencial.com/residencial/gracias.asp" 
	}
	
	if (idioma=="en") 
	{
		strMensajeNombre = "Please fill in your First Name";
		strMensajeApellido = "Please fill in your Last Name";
		strMensajeEmail = "Please fill in your Email to contact you";
		strMensajeEmailCorrecto = "Please fill in a valid Email address";
		strMensajeComentario = "Please write a message";
		url_destino = "http://www.calaceiteresidencial.com/residential/thanks.asp" 
	}
	
	if (idioma=="de") 
	{
		strMensajeNombre = "Bitte überprüfen Sie ihren Name";
		strMensajeApellido = "Bitte überprüfen Sie ihren Nachnamen";
		strMensajeEmail = "Bitte überprüfen Sie ihren E-Mail";
		strMensajeEmailCorrecto = "Bitte überprüfen Sie ihren E-Mail";
		strMensajeComentario = "Bitte überprüfen Sie ihren Nachricht";
		url_destino = "http://www.calaceiteresidencial.com/Wohnanlage/danke.asp" 
	}

	if (formulario.txtNombre.value=='')
	{
		alert(strMensajeNombre);
		formulario.txtNombre.focus();
		return (false);
	}
	if (formulario.txtApellidos.value=='')	
	{	
		alert(strMensajeApellido);
		formulario.txtApellidos.focus();
		return (false);
	}
	if (formulario.txtEmail.value=='')
	{
		alert(strMensajeEmail);
		formulario.txtEmail.focus();
		return (false);
	}
	else
	{
		if (ValidateEmail()==false) 
		{ 
			alert(strMensajeEmailCorrecto);
			formulario.txtEmail.focus();
			return (false);
		}	
	}
	   
	if (formulario.txtComentario.value=='')
	{
		alert(strMensajeComentario);
		formulario.txtComentario.focus();
		return (false);
	} 		
	else
	{ 
		formulario.action= url_destino;
	}	   
	
}  