// JavaScript Document
function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function PonerRojo(iD, NombreCampo){
var nombre = document.getElementById(iD);
nombre.style.borderColor="red";
nombre.style.borderStyle="solid";
nombre.style.borderWidth="1";
if (NombreCampo=="Email"){
  if (!nombre.value) alert(""+NombreCampo+"");
  else alert("Direccion de Email invalida");
} else if (NombreCampo=="Sexo" || NombreCampo=="Pais") {
  alert("Debe elegir una opcion del campo de seleccion "+NombreCampo);
} else {
  alert(""+NombreCampo+"");
}
nombre.focus();
}

function PonerRojoNOJS(iD, NombreCampo){
var nombre = document.getElementById(iD);
nombre.style.borderColor="red";
nombre.style.borderStyle="solid";
nombre.style.borderWidth="1";
nombre.focus();
}

function Normalizar(iD){
// var nombre = document.getElementById(iD);
// var nombre = iD;
iD.style.borderColor="";
iD.style.borderStyle="";
iD.style.borderWidth="";
}
//
//
// Validador del Suscriptor
//
//
function Validar_suscriptores(){
  var nombre = document.getElementById("idnombre");
  var email = document.getElementById("idemail");

Normalizar(nombre);
Normalizar(email);
  if (!nombre.value){
    PonerRojo('idnombre','Name - All the fields are mandatory.');
    return false;
  }
  if (!isEmail(email.value)) {
    PonerRojo('idemail','E-mail - All the fields are mandatory.');
    return false;
  }
}
//
//
// Validador de la recomendar
//
//
function Validar_recomendar(){
  var nombre = document.getElementById("idnombre");
  var email = document.getElementById("idemail");
  var amigo = document.getElementById("idamigo");
  var emaila = document.getElementById("idemaila");

Normalizar(nombre);
Normalizar(email);
Normalizar(amigo);
Normalizar(emaila);
  if (!nombre.value){
    PonerRojo('idnombre','Nombre');
    return false;
  }
  if (!isEmail(email.value)) {
    PonerRojo('idemail','email');
    return false;
  }
    if (!amigo.value){
    PonerRojo('idamigo','Nombre de tu amigo');
    return false;
  }
  if (!isEmail(emaila.value)) {
    PonerRojo('idemaila','email');
    return false;
  }
}
//
//
// Validador de la consulta
//
//
function Validar_contacto(){
  var nombre = document.getElementById("idnombre");
  var email = document.getElementById("idemail");
  var nacionalidad = document.getElementById("idnacionalidad");
  var suite = document.getElementById("idsuite");
  var comentarios = document.getElementById("idcomentarios");

Normalizar(nombre);
Normalizar(email);
Normalizar(nacionalidad);
Normalizar(suite);
Normalizar(comentarios);
  if (!nombre.value){
    PonerRojo('idnombre','Name and Surname - All the fields are mandatory.');
    return false;
  }

  if (!isEmail(email.value)) {
    PonerRojo('idemail','El campo email está vacio');
    return false;
  }
  if (!nacionalidad.value){
    PonerRojo('idnacionalidad','Nacionality - All the fields are mandatory.');
    return false;
  }
  if (suite.value=="0"){
    PonerRojo('idsuite','Select a Suite');
    return false;
  }
  if (!comentarios.value){
    PonerRojo('idcomentarios','Coments - All the fields are mandatory.');
    return false;
  }
}
//
// Funcion habilitar otra forma de contacto
//
function otros_fun(){
	if (document.getElementById('idconocio').value=="Otros") {
	document.getElementById('idotros').disabled="";
	document.getElementById('idotros').style.borderColor="#888888";
	document.getElementById('idotros').style.borderStyle="solid";
	document.getElementById('idotros').style.borderWidth="1";
	}	
	else
	{
	document.getElementById('idotros').disabled="disabled";
	document.getElementById('idotros').style.borderColor="#FFFFFF";
	document.getElementById('idotros').style.borderStyle="solid";
	document.getElementById('idotros').style.borderWidth="1";
	}
}
//
//
// Validador del Libro de Huespedes
//
//
function Validar_ldhuespedes(){
  var nombre = document.getElementById("idnombre");
  var email = document.getElementById("idemail");
  var comentarios = document.getElementById("idcomentarios");

Normalizar(nombre);
Normalizar(email);
Normalizar(comentarios);
  if (!nombre.value){
    PonerRojo('idnombre','El campo Nombre es Obligatorio');
    return false;
  }
  if (!isEmail(email.value)) {
    PonerRojo('idemail','El campo email es Obligatorio');
    return false;
  }
  if (!comentarios.value){
    PonerRojo('idcomentarios','Debe completar el campo Comentario');
    return false;
  }
}