// JavaScript Document
function FrmReserva_submit() {
      if (validaReserva()) {
           return true;
      }
      return false;
   }
function validaReserva() {
	var erro='';
	if (document.Frm.Nome.value.length<=3){
		erro=erro+'Digite seu Nome;\n';
		document.Frm.Nome.focus();
	}
	if (document.Frm.Endereco.value.length<=3){
		erro=erro+'Digite seu Endereço;\n';
		document.Frm.Endereco.focus();
	}
	if (document.Frm.Bairro.value.length<=3){
		erro=erro+'Digite seu Bairro;\n';
		document.Frm.Bairro.focus();
	}
	if (document.Frm.Cidade.value.length<=3){
		erro=erro+'Digite sua Cidade;\n';
		document.Frm.Cidade.focus();
	}
	if ( document.Frm.UF.value == 0 || document.Frm.UF.value == "" ){
		erro=erro+'Selecione o Estado;\n';
		document.Frm.UF.focus();
	}
	if ( document.Frm.CEP.value.length <= 5 ){
		erro=erro+'Digite o CEP!\n';
		document.Frm.CEP.focus();
	}
	if (document.Frm.Email.value.length<=3){
		erro=erro+'Digite seu Email;\n';
		document.Frm.Email.focus();
	}
	var email = document.Frm.Email.value;
	if (ValidaMail(email) == false) {
		erro+= 'Informe um email válido;\n';
	}
	if (document.Frm.Telefone.value.length < 10){
		erro=erro+'Digite o Telefone;\n';
		document.Frm.Telefone.focus();
	}
	if ( document.Frm.Cheque.checked == false && document.Frm.Dinheiro.checked == false ) {
		erro=erro+'Selecione a forma de Pagamento;\n';
	}
	/*if ( (document.Frm.Acomodacao1.value == 0 || document.Frm.Acomodacao1.value == "") && (document.Frm.Acomodacao2.value == 0 || document.Frm.Acomodacao2.value == "") && (document.Frm.Acomodacao3.value == 0 || document.Frm.Acomodacao3.value == "") ){
		erro=erro+'Selecione pelo menos uma acomodação;\n';
		document.Frm.Acomodacao1.focus();
	}*/
	if (erro!==''){
		alert('Verifique o(s) seguinte(s) erro(s): \n\n'+erro);
		return false;
	} else {
		return true;
	}
}
// ***********************************************************************
// VALIDA MAIL
// ***********************************************************************
function ValidaMail(mail) {
	if(mail.length < 5 || mail.indexOf("@") < 0 || mail.indexOf(".") < 0)
		return false;
	if (mail.indexOf(" ") > 0)
		return false;
	if (mail.charAt(0) == '@' || mail.charAt(0) == '.' || mail.charAt(mail.length-1)=='@' || mail.charAt(mail.length-1)=='.')
		return false;
	if (mail.indexOf("@")+1 == mail.indexOf("."))
		return false;
	return true;
}
// ***********************************************************************
// FORMATA FONE
// ***********************************************************************
function FormataFone(e, valor, nome) {
	var tecla;
	if (!e) var e = window.event;
	if (e.keyCode) tecla = e.keyCode;
	else if (e.which) tecla = e.which;
	if ((tecla == 13) || (tecla == 9) || (tecla == 39) || (tecla == 8) || (tecla > 47 && tecla < 58 ) )  {
        
		var Str;
		if (valor.length == 0) {
			Str = 'document.Frm.'+nome+'.value = document.Frm.'+nome+'.value + "(" ;';
			eval(Str);
		}
		if (valor.length == 3) {
			Str = 'document.Frm.'+nome+'.value = document.Frm.'+nome+'.value + ")" ;';
			eval(Str);
			Str = 'document.Frm.'+nome+'.value = document.Frm.'+nome+'.value + " " ;';
			eval(Str);
		}
	
		if (valor.length == 9) {
			Str = 'document.Frm.'+nome+'.value = document.Frm.'+nome+'.value + "-" ;';
			eval(Str);
		}
	    return true;
		
    } else {
       alert('Digite apenas números!');
       Str = 'document.Frm.'+nome+'.focus();';
       eval(Str);
       return false;
    }
}
// ***********************************************************************
// FORMATA CEP
// ***********************************************************************
function FormataCEP(e, valor, nome) {
	var tecla;
	if (!e) var e = window.event;
	if (e.keyCode) tecla = e.keyCode;
	else if (e.which) tecla = e.which;
	if ((tecla == 13) || (tecla == 9) || (tecla == 39) || (tecla == 8) || (tecla > 47 && tecla < 58 ) )  {
        
		var Str;
		if (valor.length == 5) {
			Str = 'document.Frm.'+nome+'.value = document.Frm.'+nome+'.value + "-" ;';
			eval(Str);
		}
	    return true;
		
    } else {
       alert('Digite apenas números!');
       Str = 'document.Frm.'+nome+'.focus();';
       eval(Str);
       return false;
    }
}
// ***********************************************************************
// FUNCAO AJAX MOSTRA IMG
// ***********************************************************************
function ajax() {
};
ajax.prototype.iniciar = function() {

    try{
        this.xmlhttp = new XMLHttpRequest();
    }catch(ee){
        try{
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(E){
                this.xmlhttp = false;
            }
        }
    }
    return true;
}

ajax.prototype.ocupado = function() {
    estadoAtual = this.xmlhttp.readyState;
    return (estadoAtual && (estadoAtual < 4));
}

ajax.prototype.processa = function() {
    if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {
        return true;
    }
}

ajax.prototype.enviar = function(url, metodo, modo) {
    if (!this.xmlhttp) {
        this.iniciar();
    }
    if (!this.ocupado()) {
        if(metodo == "GET") {
            this.xmlhttp.open("GET", url, modo);
            this.xmlhttp.send(null);
        } else {        
            this.xmlhttp.open("POST", url, modo);
            this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
            this.xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
            this.xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
            this.xmlhttp.setRequestHeader("Pragma", "no-cache");
            this.xmlhttp.send(url);
        }    

        if (this.processa) {
            return unescape(this.xmlhttp.responseText.replace(/\+/g," "));
        }
    }
    return false;
}
// ***********************************************************************
// ENVIA - QUARTO 1
// ***********************************************************************
function envia(url, metodo, modo) {
	var Acomodacao = document.getElementById('Frm').Acomodacao1.value;
    remoto  = new ajax();
    xmlhttp = remoto.enviar(url + "?Acomodacao=" + Acomodacao, metodo, modo );
    if(xmlhttp == false) {
        document.getElementById('Acomodacao1').className = 'erro';
        document.getElementById('ViewIMG').className = 'alerta2';
        document.getElementById("ViewIMG").innerHTML = 'Imagem não cadastrada!';
    } else {
        document.getElementById('Acomodacao1').className = 'texto';
        document.getElementById("ViewIMG").innerHTML = '<img src=\"fotos/acomodacoes/'+Acomodacao+'\" />';
    }    
}
// ***********************************************************************
// ENVIA - QUARTO 2
// ***********************************************************************
function envia2(url, metodo, modo) {
	var Acomodacao = document.getElementById('Frm').Acomodacao2.value;
    remoto  = new ajax();
    xmlhttp = remoto.enviar(url + "?Acomodacao=" + Acomodacao, metodo, modo );
    if(xmlhttp == false) {
        document.getElementById('Acomodacao2').className = 'erro';
        document.getElementById('ViewIMG').className = 'alerta2';
        document.getElementById("ViewIMG").innerHTML = 'Imagem não cadastrada!';
    } else {
        document.getElementById('Acomodacao2').className = 'texto';
        document.getElementById("ViewIMG").innerHTML = '<img src=\"fotos/acomodacoes/'+Acomodacao+'\" />';
    }    
}
// ***********************************************************************
// ENVIA - QUARTO 3
// ***********************************************************************
function envia3(url, metodo, modo) {
	var Acomodacao = document.getElementById('Frm').Acomodacao3.value;
    remoto  = new ajax();
    xmlhttp = remoto.enviar(url + "?Acomodacao=" + Acomodacao, metodo, modo );
    if(xmlhttp == false) {
        document.getElementById('Acomodacao3').className = 'erro';
        document.getElementById('ViewIMG').className = 'alerta2';
        document.getElementById("ViewIMG").innerHTML = 'Imagem não cadastrada!';
    } else {
        document.getElementById('Acomodacao3').className = 'texto';
        document.getElementById("ViewIMG").innerHTML = '<img src=\"fotos/acomodacoes/'+Acomodacao+'\" />';
    }    
}