﻿ function jCommon()
{
    var tpl;
    var This = this;
    //** metodos privativos
    var render = {
        subMenuHotel: function(pCodhotel)
        {
            var sb = new StringBuilder();            
            sb.append("&nbsp;");

            //-- Tipos Acomodação
            tpl.UI.tpl_spanClick.onclick = "javascript:jmenu.goTo.hotelEditar(" + pCodhotel + ")";
            tpl.UI.tpl_spanClick.text = "hotel";
            sb.append("&nbsp;"+ tpl.UI.tpl_spanClick.getHtml());
            
            //-- Tipos Acomodação
            tpl.UI.tpl_spanClick.onclick = "javascript:jmenu.goTo.hotelTiposAcomodacao(" + pCodhotel + ")";
            tpl.UI.tpl_spanClick.text = "tipos acomodação";
            sb.append(tpl.UI.tpl_spanClick.getHtml());
            
            //-- Tipos Alimentação
            tpl.UI.tpl_spanClick.onclick = "javascript:jmenu.goTo.hotelTiposAlimentacao(" + pCodhotel + ")";
            tpl.UI.tpl_spanClick.text = "tipos alimentação";
            sb.append(tpl.UI.tpl_spanClick.getHtml());            			
            
			//-- Detalhes
			tpl.UI.tpl_spanClick.onclick = "javascript:jsHotelDetalhes.exec.main(" + pCodhotel + ")";
			tpl.UI.tpl_spanClick.text = "detalhes";
			sb.append(tpl.UI.tpl_spanClick.getHtml());
            
            //-- Fotos
            tpl.UI.tpl_spanClick.onclick = "javascript:jsHotelFoto.exec.main(" + pCodhotel + ")";
            tpl.UI.tpl_spanClick.text = "fotos";
            sb.append(tpl.UI.tpl_spanClick.getHtml()); 

            //-- Hotéis Hotel Características
            sb.append("<a href='javascript:jmenu.goTo.hoteis_hotelCaracteristicas(" + pCodhotel + ")'>hotéis características</a>");
            
            sb.append("<br />");
            return sb.toString();
        },
        load: function(pDiv)
        {
            $html(pDiv, "<br /><br /><div style='text-align:center;'><img src='imagens/load.gif' alt=''></div>");
        },
        sucessoCadastro: function(pDiv, pMensagem)
		{   
		    var sb = new StringBuilder();			
			tpl.tpl_mensagem.img_msg = 'imagens/ico_sucesso.gif';
			tpl.tpl_mensagem.msg_1 = pMensagem;	
			tpl.tpl_mensagem.msg_2 = '';
			tpl.tpl_mensagem.msg_3 = '';
			sb.append(tpl.tpl_mensagem.getHtml());							
			$html(pDiv, sb.toString());
			
			//var msg = '<div style="text-align: center; padding:20px;"><img src="imagens/success_icon.gif" alt=""><br /><br />' + (pMensagem == undefined ? "" : pMensagem) + '</div>';
			//$html(pDiv, msg);
		},
		erroCadastro: function(pDiv, pErro)
		{
		    var sb = new StringBuilder();
			tpl.tpl_mensagem.img_msg = 'imagens/ico_erro.gif';
			tpl.tpl_mensagem.msg_1 = pErro;
			tpl.tpl_mensagem.msg_2 = '';
			tpl.tpl_mensagem.msg_3 = '';
			sb.append(tpl.tpl_mensagem.getHtml());
			$html(pDiv, sb.toString());				
			
		    //var msg = '<div style="text-align: center; padding:20px;"><img src="imagens/error_icon.png" alt=""><br /><br />' + (pErro == undefined ? "" : pErro); + '</div>';
		    //$html(pDiv, msg);
		},
		sucessoExcluir: function(pDiv, pErro)
		{
		    var sb = new StringBuilder();			
			tpl.tpl_mensagem.img_msg = 'imagens/ico_sucesso.gif';
			tpl.tpl_mensagem.msg_1 = pErro;	
			tpl.tpl_mensagem.msg_2 = '';
			tpl.tpl_mensagem.msg_3 = '';
			sb.append(tpl.tpl_mensagem.getHtml());							
			$html(pDiv, sb.toString());
			
		    //var msg = '<div style="text-align: center; padding:20px;">Cadastro Excluído com sucesso!<br />' + pErro; + '</div>';
		    //$html(pDiv, msg);
		},
		erroExcluir: function(pDiv, pErro)
		{
		    var sb = new StringBuilder();			
			tpl.tpl_mensagem.img_msg = 'imagens/ico_erro.gif';
			tpl.tpl_mensagem.msg_1 = pErro;	
			tpl.tpl_mensagem.msg_2 = '';
			tpl.tpl_mensagem.msg_3 = '';
			sb.append(tpl.tpl_mensagem.getHtml());							
			$html(pDiv, sb.toString());
			
//		    var msg = '<div style="text-align: center; padding:20px;">Problemas ao Excluir o cadastro!<br />' + pErro; + '</div>';
//		    $html(pDiv, msg);
		},
		erroMensagem: function(pIDcampo, pDiv, pNomeCampo, pMsg)
		{
			//var msg = '<div style="text-align: center; padding:20px;">Problemas ao efetuar o cadastro!<br />' + pErro; + '</div>';
		    $html(pDiv, pMsg);
			//alert(pNomeCampo + pMsg);
		},
		setHotelGeral : function(pCodHotel)
        {
            var jDTHotel = new jDatatable(Hotel.listarHotelGeral(pCodHotel).value);
            
            tpl.hotel.tpl_hotelGeral.codigoHotel = pCodHotel;
            tpl.hotel.tpl_hotelGeral.redeHotel = jDTHotel.getDrValue(0,"nomeRede");
            tpl.hotel.tpl_hotelGeral.categoriaHotel = jDTHotel.getDrValue(0,"nomeCategoria");
            tpl.hotel.tpl_hotelGeral.tipoHotel = jDTHotel.getDrValue(0,"tipoHotel");
            tpl.hotel.tpl_hotelGeral.codigoMtur = jDTHotel.getDrValue(0,"CodMtur");
            tpl.hotel.tpl_hotelGeral.cnpjHotel = jDTHotel.getDrValue(0,"Cnpj");
            tpl.hotel.tpl_hotelGeral.razaoSocial = jDTHotel.getDrValue(0,"RazaoSocial");
            tpl.hotel.tpl_hotelGeral.nomeFantasia = jDTHotel.getDrValue(0,"NomeFantasia");
            
            $html(ctrlRefs.divHotelGeral(),tpl.hotel.tpl_hotelGeral.getHtml());
        },	
        optionSelecione: function()
        {
            var sb = new StringBuilder();
            tpl.tpl_option.value = "";
            tpl.tpl_option.text = "";
            sb.append(tpl.tpl_option.getHtml());
            return sb.toString();
        },
        optionPais: function()
        {
            var sb = new StringBuilder();
            var jDtPais = new jDatatable(Pais.listar(0).value);
            var total = jDtPais.getTotRegs();
            sb.append(render.optionSelecione());
            for (var i = 0; i < total; i++)
            {
                tpl.tpl_option.value = jDtPais.getDrValue(i, "CodPais");
                tpl.tpl_option.text = jDtPais.getDrValue(i, "Nome");
                sb.append(tpl.tpl_option.getHtml());
            };
            return sb.toString();
        },
        setEmpresaGeral : function(pCodEmpresa)
        {
            var jDTEmpresa = new jDatatable(Empresas.listar(pCodEmpresa).value); 
            
            var _codEmpresa = parseInt(jDTEmpresa.getDrValue(0,"CodEmpresa"));
            var jDTTipoEmpresa = new jDatatable(TiposEmpresa.getNome(_codEmpresa).value); 
            var _tipoEmpresa = jDTTipoEmpresa.getDrValue(0,"Nome");
            
            tpl.empresa.tpl_empresaGeral.codigoEmpresa = jDTEmpresa.getDrValue(0,"CodEmpresa");
            tpl.empresa.tpl_empresaGeral.tipoEmpresa = _tipoEmpresa;
            tpl.empresa.tpl_empresaGeral.codigoMtur = jDTEmpresa.getDrValue(0,"CodMtur");
            tpl.empresa.tpl_empresaGeral.cnpjEmpresa = jDTEmpresa.getDrValue(0,"Cnpj");
            tpl.empresa.tpl_empresaGeral.razaoSocial = jDTEmpresa.getDrValue(0,"RazaoSocial");
            tpl.empresa.tpl_empresaGeral.nomeFantasia = jDTEmpresa.getDrValue(0,"NomeFantasia");
            
            $html(ctrlRefs.divEmpresaGeral(),tpl.empresa.tpl_empresaGeral.getHtml());
        },	
        setTarifarioHotelGeral : function(pNometarifario, pNomeEmpresa, pNomeHotel)
        {
            
            tpl.tarifario.Hoteis.tpl_tarifarioHotelGeral.nomeTarifario = pNometarifario;
            tpl.tarifario.Hoteis.tpl_tarifarioHotelGeral.nomeEmpresa = pNomeEmpresa;
            tpl.tarifario.Hoteis.tpl_tarifarioHotelGeral.grupoEmpresas = pNomeHotel;
            
            $html(ctrlRefs.divTarifarioHotelGeral(),tpl.tarifario.Hoteis.tpl_tarifarioHotelGeral.getHtml());
                  
        },	        
        setTarifarioParqueGeral : function(pCodTarifario, pNomeEmpresa, pNomeTarifario)
        {
            //var jDTTarifarios = new jDatatable(TarifariosParque.listarTarifario(pCodTarifario).value);   

            //tpl.tarifario.Parques.tpl_tarifarioParqueGeral.codigoTarifario = pCodTarifario;
            tpl.tarifario.Parques.tpl_tarifarioParqueGeral.nomeTarifario = pNomeTarifario;
            tpl.tarifario.Parques.tpl_tarifarioParqueGeral.nomeEmpresa = pNomeEmpresa;
            //tpl.tarifario.Parques.tpl_tarifarioParqueGeral.grupoEmpresas = jDTTarifarios.getDrValue(0,"nomeGrupo");
                        
            $html(ctrlRefs.divTarifarioParqueGeral(),tpl.tarifario.Parques.tpl_tarifarioParqueGeral.getHtml());
        }
    };
    
    this.showPelicula = function()
    {
        $("fundoLogin").style.display = '';
        var tplCommon = new Template('Common');
        $('fmLogin').innerHTML = tplCommon.tpl_peliculaFechamento.getHtml();
        $('fmLogin').style.display = '';
    };

    this.hiddenPelicula = function()
    {
        $("fundoLogin").style.display = 'none';
        $('fmLogin').style.display = 'none';
    };    
    
   
    //DOM node ctrlRefs
    var ctrlRefs = {
        mainConteudo: function(){return $('mainConteudo');}, //Div principal\
        divHotelGeral: function(){return $('divHotelGeral');},
        divEmpresaGeral: function(){return $('divEmpresaGeral');},
        divTarifarioParqueGeral: function(){return $('divTarifarioParqueGeral');},
        divTarifarioHotelGeral: function(){return $('divTarifarioHotelGeral');}
    };    
    
    var startEnv = {
        validaDatasTarifas: function(pValidadeDe, pValidadeAte, pReservaDe, pReservaAte)
        {
           if ( (pValidadeDe!= null) && (pValidadeAte != null) && (pReservaDe != null) && (pReservaAte != null))
           {           
                if ((pReservaDe!= null) && (pReservaAte != null))
			    {			    
			        pReservaDe = pReservaDe.addHours(23);
			        pReservaDe = pReservaDe.addMinutes(59);
			        pReservaDe = pReservaDe.addSeconds(59);
    			    
			        pReservaAte = pReservaAte.addHours(23);
			        pReservaAte = pReservaAte.addMinutes(59);
			        pReservaAte = pReservaAte.addSeconds(59);
    			    
			        pValidadeDe = pValidadeDe.addHours(23);
			        pValidadeDe = pValidadeDe.addMinutes(59);
			        pValidadeDe = pValidadeDe.addSeconds(59);
    			    
			        pValidadeAte = pValidadeAte.addHours(23);
			        pValidadeAte = pValidadeAte.addMinutes(59);
			        pValidadeAte = pValidadeAte.addSeconds(59);
    			    
                    if (pReservaDe >= Date.now())
                    {
                        if (pReservaDe > pReservaAte)
                        {
                            alert('Preencha a data de Reservas Até maior que a data Reservas De');
                            return false;
                        };
                    }
                    else
                    {
                        alert('Favor inserir uma data Reserva De maior ou igual que a Data Atual');
                        return false;
                    };
			    };
    			
			    if ((pValidadeDe!= null) && (pValidadeAte != null)) 
			    {
                    if (pValidadeDe >= Date.now())
                    {
			            if (pValidadeDe > pValidadeAte)
			            {
			               alert('Preencha a data de Validade Até maior que a data Validade De');
			               return false;
			            };
                    }
                    else         
                    {
                         alert('Favor inserir uma data Validade De maior ou igual que a Data Atual');
                         return false;
                    };
                };
			    if ( (pReservaAte!= null) && (pValidadeAte != null) ) 
			    { 
			        if (pReservaAte > pValidadeAte)
			        {
			           alert('A Data de Reserva Até não pode ser maior que a Validade Até');
			           return false;
			        };
			        if(pReservaDe > pValidadeDe)
			        {
			           alert('A Data de Reserva De não pode ser maior que a Validade De');
			           return false;
			        };
			    };
			    if ( (pValidadeDe!= "") && (pValidadeAte != "") && (pReservaDe != "") && (pReservaAte != "")){
			       return true;
			    }
			    else
			    {
			        alert("Informe as datas de Checkin e Reserva");
			        return false;
			    };	
			
			};
			return true;
        },
        formataNumeroDecimal: function(numero)
		{
		    var aux = new Array();
		    aux = numero.split(',');
		    if(aux[0] == "")
		    {
		        return "0," + aux[1];
		    }
		    else
		    {
		        return numero;
		    };
		},
        controlaValidadeData: function(dataControle, dataTela, tipoComparacao)
        {
            if(tipoComparacao == "fim")
            {
                if(dataControle >= dataTela)
                {
                    return true;
                }
                else
                {
                    return false;
                };
            }
            else
            {
                if(tipoComparacao == "inicio")
                {
                    if(dataControle <= dataTela)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    };
                }
                else
                {
                    return false;
                };
            };
        },
        formataTelefoneDB: function(fone)
        {
            if (fone.length > 5 && fone.length < 12)
            {
                    //---- Limpa caracteres dos telefones do BD de integração
                    var i=0;
                    var len = fone.length-1;
                    for(i; i < len; i++)
                    {
                        if ((fone.charAt(i)==")") || (fone.charAt(i)=="(") || (fone.charAt(i)=="-")  || (fone.charAt(i)==" ") || (fone.charAt(i)=="."))
                        {
                            fone = fone.substr(0,i) + "" + fone.substr(i+1);
                        };
                    };
                    
                    //--- Verifica se é 0800 ou 0300
                    i=0;
                    len = fone.length-1;
                    var aux = fone.substr(0,4);
                    if ((aux == "0800") || (aux == "0300"))
                    {
                        if (len<10)
                        {
                            fone = fone.substr(0,4) + "-" + fone.substr(4);
                        };
                    }
                    else
                    {
                        if (len>0)
                        {                    
                            i=len;
                            var fim = false;
                            while(i>=0)
                            {
                                //-- 1ª - Adiciona '-' antes do 4 últimos dígitos -> xxxx-xxxx 
                                if (i==len-4)
                                {
                                    fone = fone.substr(0,i+1) + "-" + fone.substr(i+1);
                                };
                                //-- 2ª - Adiciona '-' antes do 8 últimos dígitos -> )xxxx-xxxx
                                if (i==len-8)
                                {
                                    fone = fone.substr(0,i+1) + ")" + fone.substr(i+1);
                                };
                                //-- 3ª - Caso o número seja maior que 10 caracteres -> (xx)xxxx-xxxx
                                if (i==len-10)
                                {
                                    fone = fone.substr(0,i+1) + "(" + fone.substr(i+1); 
                                    fim = true;
                                } ;                   
                                i--;
                            };
                            //-- Adiciona '(' no início - Caso o número seja maior que 10 caracteres porque não entrou na 3ª condição
                            if(!fim) 
                            {
                                fone = "(" + fone;
                            };
                         };
                    };
                    return fone;
            }
            else
            {
                return fone;
            };
        },
        formataTelefoneAgencias: function(fone)
        {
            fone = fone.replace('(','');
            fone = fone.replace(')','');
            if(fone.substr(0,1) == "0" && fone.substr(0,4) != "0800" && fone.substr(0,4) != "0300")
            {
                fone = fone.replace('0','');
            };
            if(fone.substr(0,2) == "55")
            {
                fone = fone.replace('55','');
            };
            fone = fone.replace(' ','');            
            fone = fone.replace('-','');
            fone = fone.replace('-','');
            if (fone.length > 5 && fone.length < 12)
            {
                    //---- Limpa caracteres dos telefones do BD de integração
                    var i=0;
                    var len = fone.length-1;
                    for(i; i < len; i++)
                    {
                        if ((fone.charAt(i)==")") || (fone.charAt(i)=="(") || (fone.charAt(i)=="-")  || (fone.charAt(i)==" ") || (fone.charAt(i)=="."))
                        {
                            fone = fone.substr(0,i) + "" + fone.substr(i+1);
                        };
                    };
                    
                    //--- Verifica se é 0800 ou 0300
                    i=0;
                    len = fone.length-1;
                    var aux = fone.substr(0,4);
                    if ((aux == "0800") || (aux == "0300"))
                    {
                        if (len<10)
                        {
                            fone = fone.substr(0,4) + "-" + fone.substr(4);
                        };
                    }
                    else
                    {
                        if (len>0)
                        {                    
                            i=len;
                            var fim = false;
                            while(i>=0)
                            {
                                //-- 1ª - Adiciona '-' antes do 4 últimos dígitos -> xxxx-xxxx 
                                if (i==len-4)
                                {
                                    fone = fone.substr(0,i+1) + "-" + fone.substr(i+1);
                                };
                                //-- 2ª - Adiciona '-' antes do 8 últimos dígitos -> )xxxx-xxxx
                                if (i==len-8)
                                {
                                    fone = fone.substr(0,i+1) + ")" + fone.substr(i+1);
                                };
                                //-- 3ª - Caso o número seja maior que 10 caracteres -> (xx)xxxx-xxxx
                                if (i==len-10)
                                {
                                    fone = fone.substr(0,i+1) + "(" + fone.substr(i+1); 
                                    fim = true;
                                } ;                   
                                i--;
                            };
                            //-- Adiciona '(' no início - Caso o número seja maior que 10 caracteres porque não entrou na 3ª condição
                            if(!fim) 
                            {
                                fone = "(" + fone;
                            };
                         };
                    };
                    return fone;
            }
            else
            {
                return fone;
            };
        }   
    };
    
    var formataCNPJ = function(Campo, teclapres)
    {
        if(window.event)
        {
            var tecla = teclapres.keyCode;
        }
        else
        { 
            tecla = teclapres.which;
        };
        
        var vr = new String(Campo.value);
        vr = vr.replace(".", "");
        vr = vr.replace(".", "");
        vr = vr.replace("/", "");
        vr = vr.replace("-", "");

        tam = vr.length + 1;
      
        if (tecla != 9 && tecla != 8)
        {
            if (tam > 2 && tam < 6)
                Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
            if (tam >= 6 && tam < 9)
                Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
            if (tam >= 9 && tam < 13)
                Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
            if (tam >= 13 && tam < 15)
                Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
        };
    };
    
    var formataCEP = function(e,src,mask) 
    {
        if(window.event) 
        { 
            _TXT = e.keyCode; 
        }
        else if(e.which) 
        {   
            _TXT = e.which; 
        };
        
        if(_TXT > 47 && _TXT < 58) 
        {
            var i = src.value.length; 
            var saida = mask.substring(0,1); 
            var texto = mask.substring(i);
            
            if (texto.substring(0,1) != saida) 
            { 
                src.value += texto.substring(0,1); 
            };
            return true; 
        } 
        else 
        { 
            if (_TXT != 8) 
            { 
                return false; 
            }
            else 
            { 
                return true; 
            };
        };
    };
    
    function SoNumeros(e)
    {
        try
        {
            var carCode = ( window.event ? event.keyCode : e.which );
            
            if ((carCode == 9) || (carCode == 46) || (carCode == 44) ||(carCode >= 96) || (carCode > 57)|| (carCode < 48))
            {
	            if((carCode == 8) || (carCode == 0))
	            {
	                return true;
	            };
    	        
	            if((carCode == 46) || (carCode == 44))
	            {
	                return true;
	            };
		        return false;
	        };
	        return true;
	    }
        catch(ex){};
    };
    
    function formataTelefone(e)
    {
        var carCode = ( window.event ? event.keyCode : e.which );

        if (carCode != 8)
        {    
            if (e.value.length == 4)
            {
                //--- Verifica se é 0800 ou 0300
                var aux = e.value.substr(0,4);
                if ((aux == "0800") || (aux == "0300"))
                {
                    e.value = e.value + "-";
                }
                else
                {
                    e.value = "(" + e.value.substr(0,2) + ")" + e.value.substr(2,e.value.length); 
                };
            };
            if (e.value.length == 8)
            {
                //--- Verifica se NÃO é 0800 ou 0300
                var aux = e.value.substr(0,4);
                if ((aux != "0800") && (aux != "0300"))
                {
                    e.value = e.value + "-";
                };
            };  
            
            //--- Limita em 10 o tamanho do fone 0800          
//            if (e.value.length >= 10)
//            {
//                var aux = e.value.substr(0,4);
//                if ((aux == "0800") || (aux == "0300"))
//                {
//                    $(e.id).maxLength = 11;
//                }                
//            }
        };
    };
    
    function formataCPF(obj)
    {
        switch(obj.value.length)
        {
            case 3: obj.value += '.';
            break;

            case 7: obj.value += '.';
            break;

            case 11: obj.value += '-';
            break;
        };
    };
    
    function formataHora(obj)
    {
        switch(obj.value.length)
        {
            case 3: obj.value += ':';
            break;
        };
    };    
    
    function formataData(campoData, e)
    {
       var carCode = ( window.event ? event.keyCode : e.which );
       if(carCode != 8)
       {
           var data = campoData.value;
           if (data.length == 2)
           {
               data = data + '/';
               $(campoData.id).value = data;
               return true;                
           };
           if (data.length == 5)
           {
               data = data + '/';
               $(campoData.id).value = data;
               return true;
           };
       };
    };
    
    function formataHora(campo, e)
    {
        var carCode = ( window.event ? event.keyCode : e.which );
        if(carCode != 8)
        {
            var hora = campo.value;
            if (hora.length == 2)
            {
                hora += ':';
                $(campo.id).value = hora;
                return true;                
            };
        };
    };
    
    
    function formataMoeda(pTextBox, SeparadorMilesimo, SeparadorDecimal, e)
    {
        var sep = 0;
        var key = '';
        var i = j = 0;
        var len = len2 = 0;
        var strCheck = '0123456789';
        var aux = aux2 = '';
        var whichCode = (window.Event) ? e.which : e.keyCode;
        if (whichCode == 13) return true;
        key = String.fromCharCode(whichCode); 
        if (strCheck.indexOf(key) == -1) return false;
        len = pTextBox.value.length;
        for(i = 0; i < len; i++)
            if ((pTextBox.value.charAt(i) != '0') && (pTextBox.value.charAt(i) != SeparadorDecimal)) break;
        aux = '';
        for(; i < len; i++)
            if (strCheck.indexOf(pTextBox.value.charAt(i))!=-1) aux += pTextBox.value.charAt(i);
        aux += key;
        len = aux.length;
        if (len == 0) pTextBox.value = '';
        if (len == 1) pTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
        if (len == 2) pTextBox.value = '0'+ SeparadorDecimal + aux;
        if (len > 2) 
        {
            aux2 = '';
            for (j = 0, i = len - 3; i >= 0; i--) 
            {
                if (j == 3) 
                {
                    aux2 += SeparadorMilesimo;
                    j = 0;
                };
                aux2 += aux.charAt(i);
                j++;
            };
            pTextBox.value = '';
            len2 = aux2.length;
            for (i = len2 - 1; i >= 0; i--)
            pTextBox.value += aux2.charAt(i);
            pTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
        };
        return false;
    };
    
    function formataTaxa(pTextBox, SeparadorMilesimo, SeparadorDecimal, e)
    {
        var sep = 0;
        var key = '';
        var i = j = 0;
        var len = len2 = 0;
        var strCheck = '0123456789';
        var aux = aux2 = '';
        var whichCode = (window.Event) ? e.which : e.keyCode;
        if (whichCode == 13) return true;
        key = String.fromCharCode(whichCode); 
        if (strCheck.indexOf(key) == -1) return false;
        len = pTextBox.value.length;
        for(i = 0; i < len; i++)
            if ((pTextBox.value.charAt(i) != '0') && (pTextBox.value.charAt(i) != SeparadorDecimal)) break;
        aux = '';
        for(; i < len; i++)
            if (strCheck.indexOf(pTextBox.value.charAt(i))!=-1) aux += pTextBox.value.charAt(i);
        aux += key;
        len = aux.length;
        if (len == 0) pTextBox.value = '';
        if (len == 1) pTextBox.value = '000'+ SeparadorDecimal + "000" + aux;
        if (len == 2) pTextBox.value = '000'+ SeparadorDecimal + "00" + aux;
        if (len == 3) pTextBox.value = '000'+ SeparadorDecimal + "0" + aux;
        if (len == 4) pTextBox.value = '000'+ SeparadorDecimal + aux;
        if (len > 4 && len < 8) 
        {
            aux2 = '';
            for (j = 0, i = len - 5; i >= 0; i--) 
            {
                if (j == 5) {
                    aux2 += SeparadorMilesimo;
                    j = 0;
                };
                aux2 += aux.charAt(i);
                j++;
            };
            pTextBox.value = '';
            len2 = aux2.length;
            for (i = len2 - 1; i >= 0; i--)
            pTextBox.value += aux2.charAt(i);
            pTextBox.value += SeparadorDecimal + aux.substr(len - 4, len);
        };
        return false;
    };
    
    createPesqInc = {    
        empresas: function(pDt, pIndice, pPesqInc)
        {
            pDt = clPesqInc.getPesqIncLocalidades("", pIndice).value; 
            
            if(pDt)            
                pPesqInc = new jPesqInc('divPescIncEmpresa' + pIndice, 'vCodEmpresa' + pIndice, 'codEmpresa' + pIndice, pDt, 'Empresa ' + pIndice, 'form', '3');            
        }
    };

    
    //** métodos publicos
    this.exec = {
        load: function(pDiv)
        {
            render.load(pDiv);
        },
		sucessoCadastro: function(pDiv, pMensagem)
		{
			render.sucessoCadastro(pDiv, pMensagem);
		},	
		erroCadastro: function(pDiv, pErro)
		{
			render.erroCadastro(pDiv, pErro);
		},
		sucessoExcluir: function(pDiv, pErro)
		{
			render.sucessoExcluir(pDiv, pErro);
		},		
		erroMensagem: function(){
			render.erroMensagem(pIDcampo,pDiv,pNomeCampo,pMsg);
		},
		getOptionSelecione: function()
		{
		    return render.optionSelecione();
		},
		setHotelGeral : function(pCodHotel)
		{
		    render.setHotelGeral(pCodHotel);
		},
		setTarifarioHotelGeral : function(pCodTarifario)
		{
		    render.setTarifarioHotelGeral(pCodTarifario);
		},
	    setEmpresaGeral : function(pCodEmpresa)
		{
		    render.setEmpresaGeral(pCodEmpresa);
		},	
	    setTarifarioParqueGeral : function(pCodTarifario,pNomeEmpresa, pNomeTarifario)
		{
		    render.setTarifarioParqueGeral(pCodTarifario, pNomeEmpresa, pNomeTarifario);
		},				
		formataCNPJ: function(Campo, teclapres)
		{
		    formataCNPJ(Campo, teclapres);
		},
		formataCEP: function(e,src,mask)
		{
		    formataCEP(e,src,mask);
		},
		soNumeros: function(e)
		{
		    return SoNumeros(e);
		},
		formataMoeda: function(pTextBox, SeparadorMilesimo, SeparadorDecimal, e)
		{
		    return formataMoeda(pTextBox, SeparadorMilesimo, SeparadorDecimal, e);
		},
		formataTaxa: function(pTextBox, SeparadorMilesimo, SeparadorDecimal, e)
		{
		    return formataTaxa(pTextBox, SeparadorMilesimo, SeparadorDecimal, e);
		},
		formataTelefone: function(e)
		{
		    return formataTelefone(e);
		},
		formataTelefoneDB: function(e)
		{
		    var fone;
		    fone = startEnv.formataTelefoneDB(e);
		    return fone;
		},
		formataTelefoneAgencias: function(e)
		{
		    var fone;
		    fone = startEnv.formataTelefoneAgencias(e);
		    return fone;
		},
		formataCPF: function(obj)
		{
		    formataCPF(obj);
		},
		formataHora: function(obj)
		{
		    formataHora(obj);
		},
		formataData: function(obj, e)
		{
		    formataData(obj, e);
		},
		formataHora: function(obj, e)
		{
		    formataHora(obj, e);
		},
        menssagemForm:function(imgType, msg1, msg2, msg3)
		{			
			if($('divBotoes'))
			{
				$('divBotoes').style.display = 'none';
			};
			
			var sb = new StringBuilder();
			
			if (imgType == 'sucesso') 
			{
				tpl.tpl_mensagem.img_msg = 'imagens/ico_sucesso.gif';
				tpl.tpl_mensagem.msg_1 = msg1;
				tpl.tpl_mensagem.msg_2 = msg2;
				tpl.tpl_mensagem.msg_3 = msg3;
			};
			
			if (imgType == 'erro') {
				tpl.tpl_mensagem.img_msg = 'imagens/ico_erro.gif';
				tpl.tpl_mensagem.msg_1 = msg1;
				tpl.tpl_mensagem.msg_2 = msg2;
				tpl.tpl_mensagem.msg_3 = msg3;
			};
			
			sb.append(tpl.tpl_mensagem.getHtml());
							
			return sb.toString();			
		},
		createPesqInc: function(pTipo ,pDt, pIndice, pPesqInc)
		{
		    switch(pTipo)
		    {
		        case 'empresa':
		            createPesqInc.empresas(pDt, pIndice, pPesqInc);
		            break;
		        default:
		            break;
		    };
		},
		subMenuHotel: function(pCodHotel)
		{
		    return render.subMenuHotel(pCodHotel);
		},
		controlaValidadeData: function(dataControle, dataTela, tipoComparacao)
		{
		    return startEnv.controlaValidadeData(dataControle, dataTela, tipoComparacao);
		},
		validaDatasTarifas: function(pValidadeDe, pValidadeAte, pReservaDe, pReservaAte)
		{
		    return startEnv.validaDatasTarifas(pValidadeDe, pValidadeAte, pReservaDe, pReservaAte);	
		},
		formataNumeroDecimal: function(numero)
		{
		    return startEnv.formataNumeroDecimal(numero);
		},
		changeColorTrOnMouseOver: function(pCampo)
		{
		    pCampo.style.backgroundColor = "#F1F1F1";		    
		},
		changeColorTrOnMouseOut: function(pCampo)
		{
		    pCampo.style.backgroundColor = "#FFFFFF";	    
		},
		getOptionPais: function()
		{
		    return render.optionPais();
		}
	};
	
	this.constructor = new function()
	{
	    tpl = new Template("Common");	    
	};
};

function atualizaIframe()
{
    
};