﻿function GM_ValidaEmailRegExp(vEmail) {
  //var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
  var RegExp = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
  if (RegExp.test(vEmail)) {
    return true;
  } else {
    return false;
  }
}

function GM_ValidaURLRegExp(vURL) {
  var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
  //var RegExp = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
  if (RegExp.test(vURL)) {
    return true;
  } else {
    return false;
  }
}

function mostra_oculta_detalhada(vID_Div1, vID_Div2) {
  var vPainel = document.getElementById(vID_Div1).style;
  var vSinal = document.getElementById(vID_Div2);
  if (vPainel.display == "none") {
    vPainel.display = "block";
    vSinal.innerHTML = "[-] Busca Detalhada";
  } else {
    vPainel.display = "none";
    vSinal.innerHTML = "[+] Busca Detalhada";
  }
}

function ValidaForm_Busca_Detalhada() {
  document.forms['form_busca_detalhada'].action = "resultado_busca.asp";
  document.forms['form_busca_detalhada'].submit();
}

function ValidaForm_Busca_Simples() {
  document.forms['form_busca_simples'].action = "resultado_busca.asp";
  document.forms['form_busca_simples'].submit();
}

//Conta o nº de caracteres inseridos num campo textarea do formulário
function textCounter(field, cntfield, maxlimit) {
  if (field.value.length > maxlimit) {
    field.value = field.value.substring(0, maxlimit);
  } else {
    cntfield.value = maxlimit - field.value.length;
  }
}

function GM_ShowTabs(IDTab,Total) {
  for (var i = 0; i < Total; i++) {
    j = i + 1;
    document.getElementById('TabCampoNome' + j).style.display = 'none';
    document.getElementById('TabCampoTexto' + j).style.display = 'none';
    document.getElementById('ShowA' + j).style.display = 'inline';
    document.getElementById('ShowB' + j).style.display = 'none';
  }
  if (!FCKeditorAPI.GetInstance("area_texto" + IDTab)) {
    vEditor = eval("oFCKeditor" + IDTab)
    var sBasePath = 'fckeditor/';
    vEditor = new FCKeditor('area_texto' + IDTab);
    vEditor.Height = 300;
    vEditor.Width = 550;
    vEditor.BasePath = sBasePath;
    vEditor.ReplaceTextarea();
  }
  document.getElementById('ShowA' + IDTab).style.display = 'none';
  document.getElementById('ShowB' + IDTab).style.display = 'inline';
  document.getElementById('TabCampoNome' + IDTab).style.display = 'block';
  document.getElementById('TabCampoTexto' + IDTab).style.display = 'block';

}

function GM_ShowTabsSimples(IDTab, Total, Area, IDArea) {
  for (var i = 0; i < Total; i++) {
    j = i + 1;
    document.getElementById('TabCampos' + j).style.display = 'none';
    document.getElementById('TabListagem' + j).style.display = 'none';
    document.getElementById('ShowA' + j).style.display = 'inline';
    document.getElementById('ShowB' + j).style.display = 'none';
  }
  //para o cadastrar imagem
  document.getElementById('id_painel_ativo').value = IDTab;
  document.getElementById('id_area_ativa').value = IDArea;
  //para o alterar posicoes
  document.getElementById('painel_ativo').value = IDTab;
  document.getElementById('area_ativa').value = IDArea;

  document.getElementById('TextoNome').innerHTML = Area;
  document.getElementById('ShowA' + IDTab).style.display = 'none';
  document.getElementById('ShowB' + IDTab).style.display = 'inline';
  document.getElementById('TabCampos' + IDTab).style.display = 'block';
  document.getElementById('TabListagem' + IDTab).style.display = 'block';
}

function GM_Envia_Busca_Simples_Detalhada() {
  document.forms['form_busca_simples'].action = "guia_pousadas_detalhe.asp";
  document.forms['form_busca_simples'].busca_detalhada.value = 1;
  document.forms['form_busca_simples'].submit();
}

function GM_Envia_Menu_Busca_Detalhada() {
  document.forms['form_menu_busca_detalhada'].action = "guia_pousadas_detalhe.asp";
  document.forms['form_menu_busca_detalhada'].busca_detalhada.value = 1;
  document.forms['form_menu_busca_detalhada'].submit();
}

function GM_Envia_Busca_Detalhe(vID_Pousada, vCodigo_Ereservas) {
  document.form_detalhe.action = document.form_detalhe.action + "?id_pousada="+ vID_Pousada;
  document.form_detalhe.id_pousada.value = vID_Pousada;
  document.form_detalhe.codigo_ereserva.value = vCodigo_Ereservas;
  document.form_detalhe.submit();
}

function GM_Envia_Reservar_Promocoes(vID_Pousada, vCodigo_Ereservas) {
  if (vCodigo_Ereservas == 0) {
    document.formulario_filtro.id_pousada.value = vID_Pousada;
    document.formulario_filtro.codigo_ereserva.value = vCodigo_Ereservas;
    document.formulario_filtro.action = "reserva.asp";
    document.formulario_filtro.submit();
  } else {
  document.formulario_filtro.href = 'http://www.e-reserva.com.br/reservar.asp?codigo_hotel=' + vCodigo_Ereservas;
  }
}

function GM_Envia_Reservar_Agora(vID_Pousada, vCodigo_Ereservas) {
  if (vCodigo_Ereservas == 0) {
    document.form_detalhe.id_pousada.value = vID_Pousada;
    document.form_detalhe.codigo_ereserva.value = vCodigo_Ereservas;
    document.form_detalhe.action = "reserva.asp";
    document.form_detalhe.submit();
  } else {
    document.location.href = 'http://www.e-reserva.com.br/reservar.asp?codigo_hotel='+vCodigo_Ereservas;
  }
}

function Mostra_Aba(id_div){
  var hs = document.getElementById('container_abas').getElementsByTagName('h3');
  
  for (var i = 0; i < hs.length; i++) {
    document.getElementById('aba_' + i).style.display = 'none';
    if (hs.item(i).innerHTML == "") {
      hs.item(i).style.backgroundImage = '';
    } else {
      hs.item(i).style.backgroundImage = 'url(images/aba_off.jpg)';
    }
  }
  hs.item(id_div).style.backgroundImage = 'url(images/aba_on.jpg)';
  document.getElementById('aba_' + id_div).style.display = 'block';
}


function GM_AJAX_Promocao(vId, vCampoRetorno)
{
  //alert(Campo);
		var url = "asp_acao_ajax/ajax_busca_promocao.asp?id=" + vId 
		var ajax = GM_Verifica_ajax();
    if(ajax)
		{
				var Rnd = GM_Random();
        if(url.indexOf("?")>=0)
				{
					// já tem parametros vindos na url
        	url = url + "&" + Rnd;
        }
				else
				{ 
					url = url + "?" + Rnd;
				}
        ajax.onreadystatechange = GM_Status_ajax
        ajax.open("GET", url ,true);
        ajax.setRequestHeader("Cache-Control", "no-cache");
        ajax.setRequestHeader("Pragma", "no-cache");
        ajax.send(null);
        return true;
   }
		else
		{
        alert("Este navegador não tem suporte ao AJAX!");
				return false;
    }
    function GM_Status_ajax()
		{
        if (ajax.readyState==4)
				{
            if(ajax.status == 200)
						{
							var vRetorno = ajax.responseText;
							//alert(vRetorno);
						 document.getElementById(vCampoRetorno).innerHTML = vRetorno;
            }
						else
						{
                alert("Não foi possível trazer os dados da promoção!");
            }
            ajax = null
        }
    }
}

function GM_Envia_Promocao_Detalhe(vID_Pousada, vCodigo_Ereservas,vID_Promocao) {
  document.form_detalhe.lista_promocao.value = 4; //aba 4 é de promocao
  document.form_detalhe.id_pousada.value = vID_Pousada;
  document.form_detalhe.id_promocao.value = vID_Promocao;
  document.form_detalhe.codigo_ereserva.value = vCodigo_Ereservas;
  document.form_detalhe.submit();
}

function GM_Envia_Vitrine_Detalhe(vID_Pousada, vCodigo_Ereservas) {
  document.form_vitrine.id_pousada.value = vID_Pousada;
  document.form_vitrine.codigo_ereserva.value = vCodigo_Ereservas;
  document.form_vitrine.submit();
}

function GM_Envia_Destaque_Detalhe(vID_Pousada, vCodigo_Ereservas) {
  document.form_destaque.id_pousada.value = vID_Pousada;
  document.form_destaque.codigo_ereserva.value = vCodigo_Ereservas;
  document.form_destaque.submit();
}
