/***********************************************************/
// Diciembre 2006 - Cristian Mendoza
// Dominio: http://www.alojargentina.com.ar
// Validacion de distintos tipos de campos de formulario:
/***********************************************************/



// funcion de windows status
// window.defaultStatus='..:: alojargentina ::..'

//  si cadena es texto no vacio o no                                     
function vacio(cadena)
  {                                    // DECLARACION DE CONSTANTES
    var blanco = " \n\t" + String.fromCharCode(13); // blancos
	
   // DECLARACION DE VARIABLES
    var i;                             // indice en cadena
    var es_vacio;                      // cadena es vacio o no
    for(i = 0, es_vacio = true; (i < cadena.length) && es_vacio; i++) // INICIO
      es_vacio = blanco.indexOf(cadena.charAt(i)) != - 1;
    return(es_vacio);
  }
  
// validamos si el E-mail ingresado tiene el formato correcto

function ValidaEmail(email) {
	if (email.indexOf('@')<2 || email.lastIndexOf('.')<=email.indexOf('@')+2 || email.length<8 || email.indexOf('.')+1>=email.length) {
	   return false;
	   }
	else {return true;}
}

// FUNCION QUE NOS PERMITE INGRESAR SOLO NUMEROS

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; 
		 //alert('Solo ingrese numeros');
return (key <= 13 || (key >= 48 && key <= 57));
}

// FUNCION VALIDA UNICAMENTE SI ES TEXTO			  
/* dice si car es alfanumerico                                               */
function alfanumerico(car)
  {
    return(alfabetico(car) || numerico(car));
  }


/* dice si car es alfabetico                                                 */
function alfabetico(car)               // DECLARACION DE CONSTANTES
  {                                    // caracteres alfabeticos
    var alfa = "ABCDEFGHIJKLMNOPQRSTUWXYZabcdefghijklmnopqrstuvxyz";
	//alert('El campo contiene caracteres no válidos.\n \"Ingrese solo texto\"');
    return(alfa.indexOf(car) != - 1);  // INICIO
  }


/* dice si car es numerico                                                   */
function numerico(car)
  {                                    // DECLARACION DE CONSTANTES
    var num = "0123456789";            // caracteres numericos
    return(num.indexOf(car) != - 1);   // INICIO
  }



// -- no usada para validar campos vacios --//

function EsEspacioVacio(strText) {
    var vacio = false;
    var espacio = 0
    if (strText.length > 0 ){
    	    while (strText.substring(0,1) == ' ') {
		strText = strText.substring(1, strText.length);
		espacio ++;
	    }

	    while (strText.substring(strText.length-1,strText.length) == ' '){
		strText = strText.substring(0, strText.length-1);
		espacio ++;

	    }
	if((espacio>0) && strText.length==0){
		vacio = true;
	}

    }
    return vacio;
}


function ValidaEspacioVacio(_valor) {
	if(EsEspacioVacio(_valor.value)){
		alert('El campo no debe contener espacios');
		_valor.focus();
		_valor.value='';
	}
}
// -- fin no usada para validar campos vacios --//


// VALIDAR EL FORMULARIO EN ESPAÑOL PARA EL INGRESO DE PROPIEDADES NUEVAS

function validateFormPropiedad(formObj) {
	var errors = new Array();
	var errorMessages = '';
	
	if (vacio(formObj.elements['nombre'].value)) {errors[errors.length] = 'Nombre. => \"Ingrese unicamente texto\"';}
	if (vacio(formObj.elements['apellido'].value)) {errors[errors.length] = 'Apellido. => \"Ingrese unicamente texto\"';}
	if (vacio(formObj.elements['pais_propietario'].value)) {errors[errors.length] = 'País del Propietario.';}
	if (vacio(formObj.elements['ocupacion'].value)) {errors[errors.length] = 'Ocupación. => \"Ingrese unicamente texto\"';}
	if (vacio(formObj.elements['telefono'].value)) {errors[errors.length] = 'Teléfono. => \"Ingrese unicamente numeros\"';}
	if (!ValidaEmail(formObj.elements['email'].value)) {errors[errors.length] = 'E-mail. => \"Ingrese una dirección de correo válida\"';}
	if (vacio(formObj.elements['pais_propietario'].value)) {errors[errors.length] = 'País del Propietario.';}
	if (vacio(formObj.elements['calle'].value)) {errors[errors.length] = 'Calle.';}
	if (vacio(formObj.elements['ciudad'].value)) {errors[errors.length] = 'Ciudad. => \"Ingrese unicamente texto\"';}
	if (vacio(formObj.elements['zona'].value)) {errors[errors.length] = 'Zona. => \"Ingrese unicamente texto\"';}
			
	if (errors.length>0) {
		for(var i=0; i<errors.length; i++) {
			errorMessages += '   - '+errors[i]+'\n';
		}
		alert('Es necesario que ingrese:\n\n'+errorMessages+'\n');
		return false;
	}
}

// VALIDAR EL FORMULARIO EN INGLES PARA EL INGRESO DE PROPIEDADES NUEVAS

function validateFormPropiedadEN(formObj) {
	var errors = new Array();
	var errorMessages = '';
	
	if (vacio(formObj.elements['nombre'].value)) {errors[errors.length] = 'First Name. => \"Only Text\"';}
	if (vacio(formObj.elements['apellido'].value)) {errors[errors.length] = 'Last Name. => \"Only Text\"';}
	if (vacio(formObj.elements['pais_propietario'].value)) {errors[errors.length] = 'Country Property.';}
	if (vacio(formObj.elements['ocupacion'].value)) {errors[errors.length] = 'Occupation. => \"Only Text\"';}
	if (vacio(formObj.elements['telefono'].value)) {errors[errors.length] = 'Phone. => \"Only Number\"';}
	if (!ValidaEmail(formObj.elements['email'].value)) {errors[errors.length] = 'Email.';}
	if (vacio(formObj.elements['pais'].value)) {errors[errors.length] = 'Country.';}
	if (vacio(formObj.elements['calle'].value)) {errors[errors.length] = 'Street.';}
	if (vacio(formObj.elements['ciudad'].value)) {errors[errors.length] = 'City. => \"Only Text\"';}
	if (vacio(formObj.elements['zona'].value)) {errors[errors.length] = 'Area. => \"Only Text\"';}
		
	if (errors.length>0) {
		for(var i=0; i<errors.length; i++) {
			errorMessages += '   - '+errors[i]+'\n';
		}
		alert('Is obligatory:\n\n'+errorMessages+'\n');
		return false;
	}
}


// VALIDAR FORMULARIO DE RESERVAS EN ESPAÑOL


function validaFormReserva(formObj) {
	var errors = new Array();
	var errorMessages = '';
	
	if (vacio(formObj.elements['titulo'].value)) {errors[errors.length] = 'No tiene seleccionado algo para reservar.';}
	if (vacio(formObj.elements['nombre'].value)) {errors[errors.length] = 'El nombre.';} 
	if (vacio(formObj.elements['apellido'].value)) {errors[errors.length] = 'El apellido.';} 
	if (!ValidaEmail(formObj.elements['email'].value)) {errors[errors.length] = 'Una dirección de correo válida en el campo \"Email\".';} 
	if (!ValidaEmail(formObj.elements['email_conf'].value)) {errors[errors.length] = 'Una dirección de correo válida en el campo \"Confirmación de Email\".';} 
	if (formObj.elements['email'].value != formObj.elements['email_conf'].value) {errors[errors.length] = 'Las direcciones de Email ingresadas no coinciden.';}
	if (vacio(formObj.elements['conocio'].value)) {errors[errors.length] = '¿Cómo nos conocio?';}
	if (vacio(formObj.elements['pais'].value)) {errors[errors.length] = 'El País de Residencia.';}

	if (!formObj.elements['acepto'].checked) {errors[errors.length] = 'La aceptación de las políticas de Alojargentina.';}
	
	if (errors.length>0) {
		for(var i=0; i<errors.length; i++) {
			errorMessages += '   - '+errors[i]+'\n';
		}
		alert('Es necesario que ingrese:\n\n'+errorMessages+'\n');
		//alert(formObj.elements['titulo'].value+'bla');
		return false;
	}
}

// VALIDAR FORMULARIO DE RESERVAS EN INGLES


function validaFormReservaEN(formObj) {
	var errors = new Array();
	var errorMessages = '';
	
	if (vacio(formObj.elements['titulo'].value)) {errors[errors.length] = 'You must select a content to reserve.';}
	if (vacio(formObj.elements['nombre'].value)) {errors[errors.length] = 'First Name.';} 
	if (vacio(formObj.elements['apellido'].value)) {errors[errors.length] = 'Last Name.';} 
	if (!ValidaEmail(formObj.elements['email'].value)) {errors[errors.length] = 'Email.';} 
	if (!ValidaEmail(formObj.elements['email_conf'].value)) {errors[errors.length] = 'Confirm Email.';} 
	if (formObj.elements['email'].value != formObj.elements['email_conf'].value) {errors[errors.length] = 'The mail does not agree.';}
	if (vacio(formObj.elements['conocio'].value)) {errors[errors.length] = '¿How did you know about us?';}
	if (vacio(formObj.elements['pais'].value)) {errors[errors.length] = 'Country of residence.';}
	
	if (!formObj.elements['acepto'].checked) {errors[errors.length] = "You must accept Alojargentina's terms of use";}
		
	if (errors.length>0) {
		for(var i=0; i<errors.length; i++) {
			errorMessages += '   - '+errors[i]+'\n';
		}
		alert('Obligatory fields:\n\n'+errorMessages+'\n');
		return false;
	}
}

// VALIDAR FORMULARIO DE CONTACTO EN ESPAÑOL

function vFormContacto(formObj) {
	var errors = new Array();
	var errorMessages = '';
	
	if (vacio(formObj.elements['nombre'].value)) {errors[errors.length] = 'El nombre.';} 
	if (vacio(formObj.elements['apellido'].value)) {errors[errors.length] = 'El Apellido.';} 
	if (vacio(formObj.elements['pais'].value)) {errors[errors.length] = 'El País.';}
	if (!ValidaEmail(formObj.elements['email'].value)) {errors[errors.length] = 'Escriba una dirección de correo válida en el campo \"Email\".';} 
	if (!ValidaEmail(formObj.elements['email_conf'].value)) {errors[errors.length] = 'Escriba una dirección de correo válida en el campo \"Confirmación de Email\".';} 
	if (formObj.elements['email'].value != formObj.elements['email_conf'].value) {errors[errors.length] = 'Las direcciones de Email ingresadas no coinciden.';}
	if (vacio(formObj.elements['motivo'].value)) {errors[errors.length] = 'El motivo de la consulta.';}
	if (vacio(formObj.elements['mensaje'].value)) {errors[errors.length] = 'Su Mensaje.';}
		
	if (errors.length>0) {
		for(var i=0; i<errors.length; i++) {
			errorMessages += '   - '+errors[i]+'\n';
		}
		alert('Es necesario que ingrese:\n\n'+errorMessages+'\n');
		return false;
	}
}

// VALIDAR FORMULARIO DE CONTACTO EN INGLES

function vFormContactoEN(formObj) {
	var errors = new Array();
	var errorMessages = '';
	
	if (vacio(formObj.elements['nombre'].value)) {errors[errors.length] = 'First Name.';} 
	if (vacio(formObj.elements['apellido'].value)) {errors[errors.length] = 'Last Name.';} 
	if (vacio(formObj.elements['pais'].value)) {errors[errors.length] = 'Country.';}
	if (!ValidaEmail(formObj.elements['email'].value)) {errors[errors.length] = 'Email.';} 
	if (!ValidaEmail(formObj.elements['email_conf'].value)) {errors[errors.length] = 'Confirm Email.';} 
	if (formObj.elements['email'].value != formObj.elements['email_conf'].value) {errors[errors.length] = 'The mail does not agree.';}
	if (vacio(formObj.elements['motivo'].value)) {errors[errors.length] = '\"Subject\" is Obligatory.';}
	if (vacio(formObj.elements['mensaje'].value)) {errors[errors.length] = 'Comments is Obligatory.';}
		
	if (errors.length>0) {
		for(var i=0; i<errors.length; i++) {
			errorMessages += '   - '+errors[i]+'\n';
		}
		alert('Obligatory fields:\n\n'+errorMessages+'\n');
		return false;
	}
}

// VALIDAR FORMULARIO DE POSTALES --ESPAÑOL

function vFormPostal(formObj) {
	var errors = new Array();
	var errorMessages = '';
	
	if (vacio(formObj.elements['sunombre'].value)) {errors[errors.length] = 'Tu nombre.';}
	if (!ValidaEmail(formObj.elements['sumail'].value)) {errors[errors.length] = 'Tu e-mail.';}
	if (vacio(formObj.elements['elnombre'].value)) {errors[errors.length] = 'Nombre del Destinatario.';}
	if (!ValidaEmail(formObj.elements['elmail'].value)) {errors[errors.length] = 'El e-mail del Destinatario.';}
	if (vacio(formObj.elements['titulo'].value)) {errors[errors.length] = 'El Titulo.';}
	if (vacio(formObj.elements['mensaje'].value)) {errors[errors.length] = 'El Mensaje.';}
	if (vacio(formObj.elements['firma'].value)) {errors[errors.length] = 'La Firma.';}
	//if (vacio(formObj.elements['acepto'].value)) {errors[errors.length] = 'I accept Alojargentina.com&#8217;s use policies.';}

	if (errors.length>0) {
		for(var i=0; i<errors.length; i++) {
			errorMessages += '   - '+errors[i]+'\n';
		}
		alert('Es necesario que ingrese:\n\n'+errorMessages+'\n');
		return false;
	}
}


// VALIDAR FORMULARIO DE POSTALES INGLES

function vFormPostalEN(formObj) {
	var errors = new Array();
	var errorMessages = '';
	
	if (vacio(formObj.elements['sunombre'].value)) {errors[errors.length] = 'Your Name.';}
	if (!ValidaEmail(formObj.elements['sumail'].value)) {errors[errors.length] = 'Your e-mail.';}
	if (vacio(formObj.elements['elnombre'].value)) {errors[errors.length] = 'Addressee name.';}
	if (!ValidaEmail(formObj.elements['elmail'].value)) {errors[errors.length] = 'Addressee e-mail.';}
	if (vacio(formObj.elements['titulo'].value)) {errors[errors.length] = 'Title.';}
	if (vacio(formObj.elements['mensaje'].value)) {errors[errors.length] = 'Message.';}
	if (vacio(formObj.elements['firma'].value)) {errors[errors.length] = 'Signature.';}
	//if (vacio(formObj.elements['acepto'].value)) {errors[errors.length] = 'I accept Alojargentina.com&#8217;s use policies.';}
	
	if (errors.length>0) {
		for(var i=0; i<errors.length; i++) {
			errorMessages += '   - '+errors[i]+'\n';
		}
		alert('Is obligatory:\n\n'+errorMessages+'\n');
		return false;
	}
}

// VERIFICAR CASILLA DE TERMINOS CHECKED
function verificarCasilla(form)

{
    if (form.acepto.checked == false)
    {
    alert("I accept Alojargentina.com's use policies");

    form.acepto.focus(); return true;
    }
//form.submit()
}

// FUNCION QUE DESHABILITA LAS TECLAS DE COPIAR Y PEGAR
// CRISTIAN MENDOZA FEBRERO 2007

document.onkeydown = desabilitar; // Teclas Precionada 
document.onselectstart = selecionar; //Anular la Selecion de Texto 
document.oncontextmenu = selecionar; //Anular el Boton Der del Mouse 

function selecionar() { 
return false; 
} 

function desabilitar() { 
// Combinacion de Teclas con el Control 
if (event.ctrlKey) { 
switch(window.event.keyCode) { 
case 67: //Ctrl-C -- Copiar --- 
case 86: //Ctrl-V -- Pegar --- 
event.keyCode = 0; 
return false; 

// aqui se pondran todas las combinaciones
// de teclas previstas para bloquear pero
// ya se encuentran en otra función 

default: 
break; 
    } 
  } 
} 

// NUEVAS FUNCIONES BLOQUEO DE KEY / TECLAS


function validaField(e,tipo)
{
    funcion = true;
    if (navigator.appName == 'Microsoft Internet Explorer')
        key = window.event.keyCode;
    else
        key = e.which;
    if(key != 0){
    	if(tipo == 'alf'){
    		if ((key < 65 || key > 122 || (key > 90 && key < 97))
			&& key != 32 && key != 8
			&& key != 225 && key != 233 && key != 237 && key != 243 && key != 250 //minisculas
			&& key != 193 && key != 201 && key != 205 && key != 211 && key != 218 //mayusuculas
			&& key != 209 && key != 241
            && (key < 48 || key > 57)
            && key != 0
            && key != 46
            && key != 44
			)
			{funcion =  false; }
    	 }
    	else if(tipo == 'log'){
    		if ((key < 65 || key > 122 || (key > 90 && key < 97))
			&& key != 225 && key != 233 && key != 237 && key != 243 && key != 250 //minisculas
			&& key != 193 && key != 201 && key != 205 && key != 211 && key != 218 //mayusuculas
			&& key != 209 && key != 241
            && (key < 48 || key > 57)
            && key != 0 && key != 8
			)
			{funcion =  false; }
    	 }
    	else if(tipo == 'txt'){
    		if ((key < 65 || key > 122 || (key > 90 && key < 97))
			&& key != 32 && key != 8
			&& key != 225 && key != 233 && key != 237 && key != 243 && key != 250 //minisculas
			&& key != 193 && key != 201 && key != 205 && key != 211 && key != 218 //mayusuculas
			&& key != 209 && key != 241
			)
			{funcion =  false; }
    	 }
    	else if(tipo == 'mail'){
    		if ((key < 65 || key > 122 || (key > 90 && key < 97))
			&& key != 32 && key != 8
			&& key != 225 && key != 233 && key != 237 && key != 243 && key != 250 //minisculas
			&& key != 193 && key != 201 && key != 205 && key != 211 && key != 218 //mayusuculas
            && (key < 48 || key > 57)
            && key != 0
            && key != 46
            && key != 95
            && key != 64
			)
			{funcion =  false; }
    	 }
    	 else if(tipo == 'mailMINUS'){
    		if ((key < 96 || key > 122)
			&& key != 8
            && (key < 48 || key > 57)
            && key != 0
            && key != 46
            && key != 95
            && key != 64
			)
			{funcion =  false; }
    	 }
    	else if (tipo == 'num'){
	    	if ((key < 48 || key > 57) && key != 0 && key != 8)
	    	{ funcion = false  }
    	}
	    else if (tipo == 'fch'){
	 		if ((key < 47 || key > 57) && key != 0 && key != 8)
	 		{funcion = false}
	    }
	    else if (tipo == 'tel'){
		    if (key ==39)
		    {	 funcion = false }
	    }
	    else if (tipo == 'calif'){
		    if ((key < 45 || key > 57 ) && key != 47 )
		    { funcion = false	}
	    }
	    else if (tipo == 'hora'){
		    if ((key < 48 || key > 57) && key != 0 && key != 8 && key!=58)
		    {	 funcion = false }
	    }
	    if(tipo == 'conoc'){
    		if ((key < 65 || key > 122 || (key > 90 && key < 97))
			&& key != 32 && key != 8
			&& key != 225 && key != 233 && key != 237 && key != 243 && key != 250 //minisculas
			&& key != 193 && key != 201 && key != 205 && key != 211 && key != 218 //mayusuculas
			&& key != 209 && key != 241
            && (key < 48 || key > 57)
            && key != 0
            && key != 46
            && key != 44
            && key != 40
            && key != 41
            && key != 37
			)
			{funcion =  false; }
    	 }
    }
    return funcion;
}


