function validarDatos(idioma) {
   d = document.reservaciones;
   if (idioma == 1) {
   if(validarCampo(d.cnombre, "Nombre", idioma) && validarEmail(d.cemail,idioma) && validarCampo(d.ctelefono, "Telefono", idioma) && validarCampo(d.cpersonas, "Número de Personas", idioma) && validarCampo(d.cnoches, "Número de Noches", idioma)) {
	   document.agregar.submit();
       return true;
   } }
      if (idioma == 2) {
   if(validarCampo(d.cnombre, "Name", idioma) && validarEmail(d.cemail, idioma) && validarCampo(d.ctelefono, "Telephone", idioma) && validarCampo(d.cpersonas, "Number of people", idioma) && validarCampo(d.cnoches, "Number of nights", idioma)) {
	   document.agregar.submit();
       return true;
   } }
   if (idioma == 3) {
   if(validarCampo(d.cnombre, "Nom", idioma) && validarEmail(d.cemail, idioma) && validarCampo(d.ctelefono, "Téléphone", idioma) && validarCampo(d.cpersonas, "Nombre de personnes", idioma) && validarCampo(d.cnoches, "Nombre de nuits", idioma)) {
	   document.agregar.submit();
       return true;
   } }
   return false;
}

function validarCampo( campo, msg, idioma ) {
   if( !noBlancos( campo ) ) {
      if (idioma==1){
	   alert('El campo <'+ msg + '> es requerido.');}
	  if (idioma==2){
	   alert('The field <'+ msg + '> is required.');}
	  if (idioma==3){
	   alert('Le champ <'+ msg + '> est exigé.');}
	  campo.focus();
       return false;
   }
   return true;
}

function noBlancos( field ) {
   for( i = 0; i < field.value.length; i++ )
      if( field.value.charAt( i ) != unescape("%20") )
          return true;
   return false;
}
function validarEmail (email, idioma){
if (!validaEmail (email)){
	if (idioma==1){
	    alert('El formato del e-mail no es válido.');}
	if (idioma==2){
	    alert('Invalid e-mail.');}
	if (idioma==3){
	    alert("E-mail n'est pas valide.");}
	 email.focus();
	 return false;
}
return true;
}
function validaEmail( s ) {
s = s.value
	if( chkChars( trim( s ) ) )
		return false;	
	var i = s.indexOf( "@" );
	var sLength = s.length - 1;
	if( ( i > 0 ) && ( i < sLength ) ) {
		s = s.substring( i + 1, sLength + 1 );
		i = s.indexOf(".");
		sLength = s.length - 1;
		if( (s.charAt( sLength ) != "." ) && ( s.indexOf("@") == -1 ) )
			if( i > 0 && i < sLength )
				return true;	
	}
	return false;
}

function trim( texto ) {
	var retorno = "";
	var i = 0;
	while( i < texto.length && texto.charAt(i++) == unescape("%20") );
	j = texto.length;
	while( j >= 0 && texto.charAt(--j) == unescape("%20") );        
	retorno = texto.substring( i-1, j+1 );
	return( retorno );
}

function chkChars( str ) {
	var exChar = "*+_" + unescape("%7E%5E%B4%60%27%22%21%24%25%23%26%28%29%3C%3E%2C%3B%3A%3F%5C%5D%5B%7B%7D ");
	var c;
	for( var i = 0; i < exChar.length; i++ ) {
		c = exChar.charAt( i );
		if( str.indexOf( c ) != -1 )
			return true;
	}
	return false;
}

var nav4 = window.Event ? true : false;
function acceptNum(evt){	
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
var key = nav4 ? evt.which : evt.keyCode;	
return (key <= 13 || (key >= 48 && key <= 57));
}

