String.prototype.trim = function()
    {
        return this.replace(/^\s*/, "").replace(/\s*$/, "");
    }




function janela(file, window, larg, altura){
    window_=open(file,window,'directories=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=no,width=' + larg + ',height='  + altura);
    window_.moveTo((screen.width-larg)/2,(screen.height-altura)/2-20);
}



function addicionaAssinante() {
		
    nome = $("#nome_cadastro").val();
    email = $("#email_cadastro").val();
    site = $("#site").val();
		
    $.ajax(
		
    {
            type: "POST",
            url: getBaseURL() + 'assinantes/add/',
            data: "acao=efetuarCadastro&nome=" + nome + "&email=" + email + "&site=" + site,
		
            beforeSend: function() {
			
                $("#loadCadastro").html("Aguarde..");
		
            },
		
            success: function(txt) {
			
                if(txt == 'vazio'){
					
                    $("#loadCadastro").html("");
                    $("#loadCadastro").html('* Todos os campos são obrigatórios');
                }
			
                if(txt == 'emailfalso'){
					
                    $("#loadCadastro").html("");
                    $("#loadCadastro").html('* Digite um e-mail válido');
					
                }
                if(txt == 'existente'){
					
                    $("#loadCadastro").html("");
                    $("#loadCadastro").html('e-mail já cadastrado!');
					
                }
                if(txt == 'sucesso'){
					
                    $("#loadCadastro").html("");
                    alert("Cadastro efetuado com sucesso!");
                    $("#nome_cadastro, #email_cadastro").val("");
					
                }
				
		
            }
		
        }
	
        );

}

function dedicarMusica() {
		
    nome = $("#nome").val();
    musica = $("#musica").val();
    mensagem = $("#mensagem").val();
		
    $.ajax(
		
    {
		
            type: "POST",
            url: getBaseURL() + 'musicas/envia/',
            data: "acao=enviaMusica&nome=" + nome + "&musica=" + musica + "&mensagem=" + mensagem,
		
            beforeSend: function() {
                $("#loadCadastroMusica").html("Aguarde..");
            },
		
            success: function(txt) {
			
                if(txt == 'vazio'){
					
                    $("#loadCadastroMusica").html("");
                    $("#loadCadastroMusica").html('* Todos os campos são obrigatórios');
					
                }
			
                if(txt == 'sucesso'){
					
                    $("#loadCadastroMusica").html("");
                    alert("Dados enviados com sucesso!");
                    $("#nome, #musica , #mensagem").val("");
					
                }
				
		
            }
		
        }
	
        );

}


function abrirMapa() {
	
    cidade_destino = $("#cidade_destino").val();
    cidade_origem = $("#cidade_origem").val();
	
    $.ajax(
	
    {
	
            type: "POST",
            url: getBaseURL() + 'hotel/localizacao/localizar/',
            data: "cidade_origem=" + cidade_origem + "&cidade_destino=" + cidade_destino,
		
            beforeSend: function() {
                $("#mapa").html("Aguarde..");
            },
	
            success: function(txt) {
		
                if(txt == 'vazio'){
				
                    alert("Informe a cidade de Origem");
					
                }else
                    $("#mapa").html(txt);
		
		
            }
	
        }

        );

}



function solicitarReserva() {
		
    nome = $("#nome").val();
    telefone = $("#telefone").val();
    email = $("#email").val();
    mensagem = $("#mensagem").val();
		
    $.ajax(
		
    {
		
            type: "POST",
            url: getBaseURL() + 'hotel/reservas/solicita/',
            data: "acao=enviaMusica&nome=" + nome + "&telefone=" + telefone + "&mensagem=" + mensagem + "&email=" + email,
		
            beforeSend: function() {
                $("#loadCadastroReserva").html("Aguarde..");
            },
		
            success: function(txt) {
			
                if(txt == 'vazio'){
					
                    $("#loadCadastroReserva").html("");
                    $("#loadCadastroReserva").html('* Todos os campos são obrigatórios');
						
                }
			
                if(txt == 'sucesso'){
					
                    $("#loadCadastroReserva").html("");
                    alert("Dados enviados com sucesso!");
                    $("#nome, #telefone , #email, #mensagem").val("");
					
                }
				
		
            }
		
        }
	
        );

}


function votaEnquete() {
		
    id_enquete = $("#enquetes_id").val();
		
    erro = true;
		
    $(".enquete input[type=radio]").each(function(v){
			
        check = $(this).attr('checked');
			
        if(check == true){
            opca_votada = $(this).attr('value');
            erro = false;
        }
    });
		
    if(erro){
        alert("Escolha alguma opção");
        return false;
    }
    $.ajax(
		
    {
		
            type: "POST",
            url: getBaseURL() + 'enquetes/votar/',
            data: "id_enquete=" + id_enquete + "&opca_votada=" + opca_votada,
		
            beforeSend: function() {
			
                $("#loadEnquete").html("Aguarde..");
		
            },
		
            success: function(txt) {
			
                $("#loadEnquete").hide();
				
                if(txt == 'ja_votado')
                    alert("Você já participou dessa enquete!");
                else{
					
                    mostraResultadoEnquete(id_enquete);
                    alert("Obrigado por participar!");
                }
				
            }
		
        }
	
        );

}


function mostraResultadoEnquete(id_enquete) {
		
				
    $.ajax(
		
    {
		
            type: "POST",
            url: getBaseURL() + 'enquetes/',
            data: "id_enquete=" + id_enquete ,
		
            beforeSend: function() {
			
                $("#loadEnquete").html("Aguarde..");
                $(".enquete").empty();
		
            },
		
            success: function(txt) {
			
                $(".enquete").empty();
                $(".enquete").html(txt);
				
            }
		
        }
	
        );

}



function cidadesEmpresas(estado) {
	
    
    $("#ajax_marca").empty();
    
    $.ajax(
	
    {
	
            type: "POST",
            url: getBaseURL() + '/admin/cidades/',
            data: "id_estado=" + estado,
	
            beforeSend: function() {
                $("#ajax_marca").append("<span class='requerido'> Carregando Cidades ... </span>");
            },
	
            success: function(txt) {
		
                $(".cidade_provisoria").hide();
                $(".cidade_edit").hide();

                $('#ajax_marca').html(txt);
                $("#loadl").hide();
	
            }
	
        }

        );

}




function get_acoes(id_pagina) {
	
	 	
    $("#loadl, #load_page").empty();
    var id_usuario = $('#id_usuario').val();
		
    $.ajax(
		
    {
		
            type: "POST",
            url: getBaseURL() + 'admin/acoes/',
            data: "id_pagina=" + id_pagina + '&id_usuario=' + id_usuario,
		
            beforeSend: function() {
			
                $("#load_page").append("<span class='requerido'> Carregando ... </span>");
		
            },
		
            success: function(txt) {
			
                $('#load_page').html('');
                $('#load_page').html(txt);
		
            }
		
        }
	
        );

}



function getBaseURL() {
	
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));

    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }

}
