// Validación contacta.htm

function validar(Ctrl, Mensaje)
{
  alert(Mensaje);
  Ctrl.focus();
  return;
}

function es_email(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validacionForm() {

 	todo_ok=true;
 	var Mensaje_nombre, M_habitacion, M_email,M_pais;
 
 	if (document.forms['form1'].lang.value=="es"){
		Mensaje_nombre="Debes introducir tu nombre";M_habitacion="Debe seleccionar el tipo de habitación.";
		M_email="Debe introducir un email válido.";M_pais="Indique su país";
		}
 	if (document.forms['form1'].lang.value=="en"){
		Mensaje_nombre="You must enter your name";M_habitacion="You must enter a room type.";
		M_email="You must enter a valid email address.";M_pais="Please specify your country.";
		}
 	if (document.forms['form1'].lang.value=="de"){
		Mensaje_nombre="Bitte geben Sie einen Vornamen an.";M_habitacion="You must enter an apartment type.";
		M_email="Bitte geben Sie einen email an.";M_pais="Bitte geben Sie Ihr land an.";
		}
 	if (document.forms['form1'].lang.value=="it"){
		Mensaje_nombre="Specifica il tuo nome.";M_habitacion="You must enter an apartment type.";
		M_email="Specifica il tuo email.";M_pais="Specifica il paese.";
		}
 	if (document.forms['form1'].lang.value=="fr"){
		Mensaje_nombre="Veuillez indiquer votre nom.";M_habitacion="You must enter an apartment type.";
		M_email="Veuillez indiquer votre email.";M_pais="Veuillez préciser votre pays";
		}


 			if(document.forms['form1'].nombre.value=="" && todo_ok) {
    		validar(document.forms['form1'].nombre, Mensaje_nombre)
    		todo_ok=false;
			 }

			if(document.forms['form1'].habitacion.value=="0" && todo_ok) {
  		    validar(document.forms['form1'].habitacion, M_habitacion)
    		todo_ok=false;
 			}

 			if((!es_email(document.forms['form1'].email.value)) && (todo_ok)) {
   			validar(document.forms['form1'].email, M_email)
    		todo_ok=false;
 			}  
  
  			if(document.forms['form1'].pais.value=="" && todo_ok) {
   			validar(document.forms['form1'].pais, M_pais)
   			todo_ok=false;
			 }

 			if (todo_ok==true) document.forms['form1'].submit();
			
 		

}