function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_changeProp(objName,x,theProp,theValue) { //v3.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}


  function MarcarComboPorValor(_RefObject, _ValueObject){
    for (i=0;i<_RefObject.length;i++){
      if (_RefObject.options[i].value.toLowerCase() == _ValueObject.toLowerCase()){
       _RefObject.options[i].selected = true;  
  }}}
  

    function zeraCombo(__Ref){
      for (_Y=__Ref.options.length-1;_Y>0;_Y--)
        __Ref.options[_Y] = null
    }   


 function docjslib_getRealLeft(imgElem) {
  	xPos = eval(imgElem).offsetLeft;
  	tempEl = eval(imgElem).offsetParent;
    	while (tempEl != null) {
    		xPos += tempEl.offsetLeft;
    		tempEl = tempEl.offsetParent;
    	}
  	return xPos;
  }
  function docjslib_getRealTop(imgElem) {
  	yPos = eval(imgElem).offsetTop;
  	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
    		yPos += tempEl.offsetTop;
    		tempEl = tempEl.offsetParent;
    	}
  	return yPos;
  } 


	function MarcarRadioPorValor(refRadio, ValorRadio)
	{
		for (i=0;i<refRadio.length;i++)
		{
			if (refRadio[i].value.toLowerCase() == ValorRadio.toLowerCase())
				refRadio[i].checked = true;			
		}
	}
	
	function VerificaValidadeEmail(EmailInformado)
	{
		if (/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(EmailInformado))
			return true;
		else
			return false;
	}
	
	function VerificaSomenteNumeros(ValorInformado)
	{
		if (/^[+]?\d*$/.test(ValorInformado))
			return true;
		else
			return false;
	}
	
	function VerificaSomenteData(ValorInformado)
	{
		if (/^([0-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/[1-2](0|8|9)[0-9][0-9]$/.test(ValorInformado))
			return true;
		else
			return false;
	}
	
	function VerificaSomenteHoraMinuto(ValorInformado)
	{
		if (/^\d{2}(:\d{2})?$/.test(ValorInformado))
			return true;
		else
			return false;
	}
	
	function DesabilitaBotoesComando(botaoSubmit, botaoResetCancelar)
	{
		if (botaoResetCancelar != null)
			botaoResetCancelar.style.display = 'none';
		
		botaoSubmit.value = ' ... Aguarde, enviando informações ... ';
		botaoSubmit.disabled = true;
	}
	
	function VerificaAlgumRadioMarcado(RadioOrigem)
	{
		var AlgumRadioMarcado = false;
		
		for (i=0;i<RadioOrigem.length;i++)
			if (RadioOrigem[i].checked)
				AlgumRadioMarcado = true;
			
		return AlgumRadioMarcado;
	}
	
	function RemoveTodosItensCombo(ObjReferencia)
	{
		zeraCombo(ObjReferencia)
	}

	function AbreTelaPreenchimentoCampoEmpresa(CampoIdEmpresa, CampoEmpresa, CampoEndereco, CampoCEP, CampoBairro, CampoEstado, CampoCidade, BaseHref)
	{	
		var urlTelaPreenchimento = 'telaspreenchimento/sis_tlp_listagemempresas_fontetodascadastradas.asp';
		var left = (screen.width - 640 - 20) / 2,top = (screen.height - 350 - 35) / 2;
		var features = "width=640, height=430,status=yes,scrollbars=yes,resizable=no,left="+ left +",top="+ top +"";
			
			if (BaseHref != null && BaseHref != 'undefined')
				urlTelaPreenchimento = BaseHref + urlTelaPreenchimento;
			
			
			ObjJanelaPreenchimentoCampos = window.open(urlTelaPreenchimento, "winAbretelaPreenchimentoCampos", features);
			if (ObjJanelaPreenchimentoCampos == null) ObjJanelaPreenchimentoCampos.opener = self;
			
			// guarda as configurações de quais são os campos que devem ser preenchidos
			ObjJanelaPreenchimentoCampos.opener.CampoIdEmpresa = CampoIdEmpresa;
			ObjJanelaPreenchimentoCampos.opener.CampoEmpresa = CampoEmpresa;
			ObjJanelaPreenchimentoCampos.opener.CampoEndereco = CampoEndereco;
			ObjJanelaPreenchimentoCampos.opener.CampoCEP = CampoCEP;
			ObjJanelaPreenchimentoCampos.opener.CampoBairro = CampoBairro;
			
			ObjJanelaPreenchimentoCampos.opener.CampoEstado = CampoEstado;
			ObjJanelaPreenchimentoCampos.opener.CampoCidade = CampoCidade;
			
			
	}

	function CarregarComboCidades(ComboEstado, ComboCidade, CidadeSelecionada)
	{
		var url = "sis_aux_combocidadesporestado.asp"
		+ "?ufestado=" + ComboEstado.options[ComboEstado.selectedIndex].value
		+ "&rnd=" + new Date().getTime();
		
		// remote todos os itens do combo
		RemoveTodosItensCombo(ComboCidade);
		
		// adicionando mensagem de aguarde
		ComboCidade.options[0] = new Option("Aguarde...", "");
		
		new Ajax.Request(url, 
		{   
			method: 'post',  
			encoding: 'UTF-8',
			
			onSuccess: function(transport) { 
				//alert(transport.responseText)
			    
				var ArrayCidades = transport.responseText.split("|");
				
				ComboCidade[0] = new Option("","");
				
				for (i=0;i<ArrayCidades.length;i++)
					ComboCidade.options[i+1] = new Option(ArrayCidades[i],ArrayCidades[i]);
				
				if (CidadeSelecionada != "")
					MarcarComboPorValor(ComboCidade, CidadeSelecionada);
			},
			onFailure: function(transport)
			{
				alert('Um ou mais erros ocorreram com a página. Tente por favor novamente.\n'
					+ 'Caso o problema persista, tente recarregar toda a página ou entre \n'
					+ 'em contato conosco.');
			} 
		}); 

	}
	
	function CarregarComboCidades(ComboEstado, ComboCidade, CidadeSelecionada, ChecarCidadeExisteADM)
	{	
		
		var url = "sis_aux_combocidadesporestado.asp"
		+ "?ufestado=" + ComboEstado.options[ComboEstado.selectedIndex].value
		+ "&rnd=" + new Date().getTime();
		
		// remote todos os itens do combo
		RemoveTodosItensCombo(ComboCidade);
		
		// adicionando mensagem de aguarde
		ComboCidade.options[0] = new Option("Aguarde...", "");
		
		new Ajax.Request(url, 
		{   
			method: 'post',  
			encoding: 'UTF-8',
			
			onSuccess: function(transport) { 
			    //alert(transport.responseText)
			    
				var ArrayCidades = transport.responseText.split("|");
				
				ComboCidade[0] = new Option("","");
				
				for (i=0;i<ArrayCidades.length;i++)
					ComboCidade.options[i+1] = new Option(ArrayCidades[i],ArrayCidades[i]);
				
				if (CidadeSelecionada != "")
					MarcarComboPorValor(ComboCidade, CidadeSelecionada);
				
				if (ChecarCidadeExisteADM)
				{
					if (ComboCidade.selectedIndex == 0)
					{
						self.location = redir
					}
				} 
			},
			onFailure: function(transport)
			{
				alert('Um ou mais erros ocorreram com a página. Tente por favor novamente.\n'
					+ 'Caso o problema persista, tente recarregar toda a página ou entre \n'
					+ 'em contato conosco.');
			} 
		}); 

	}
	
	function FormataCNPJ(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);
      }
}

function MM_formtCep(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 AbreJanelaBuscarDadosEnderecoPorCep()
	{
		var pattern_ = new Object();
		pattern_.cep = /^\d{5}(-\d{3})?$/;
		pattern_.data = /^([0-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/19[0-8][0-9]$/;
    
		if (document.formCadastro.cep.value == '')
		{
			alert('Preencha o campo Cep !');
			document.formCadastro.cep.focus();
			return false;
		}
      
		if (document.formCadastro.cep.value != '')
		{
			var patCep = pattern_['cep'];
			var verificaCep = patCep.exec(document.formCadastro.cep.value);
			
			if (!verificaCep)
			{
				alert('Preencha corretamente o campo Cep !');
				document.formCadastro.cep.focus(); document.formCadastro.cep.select();
				return false;
			}
		}
		
		var url = 'sis_cep_completarenderecoporcep.asp?LocalizarCEP=' + document.formCadastro.cep.value;
		var left = (screen.width - 570 - 20) / 2,top = (screen.height - 250 - 35) / 2;
		var features = "width=620, height=320,status=yes,scrollbars=yes,resizable=no,left="+ left +",top="+ top +"";
			ObservacoesWin = window.open(url, "BuscarEnderecoPorCep", features);
			if (ObservacoesWin.opener == null) ObservacoesWin.opener = self;
	}
	
	function AdicionaInformacoesEndereco(Endereco, Numero, Bairro, Cidade, Estado)
	{
		document.formCadastro.Endereco.value = Endereco + ', ' + Numero;
		document.formCadastro.Bairro.value = Bairro;
				
		MarcarComboPorValor(document.formCadastro.estado, Estado);
		CarregarComboCidades(document.formCadastro.estado, document.formCadastro.cidade, Cidade);
	}
	
function AdicionarParticipante(IdParticipante,IdEvento)
	{
		var UrlValidacoes = "eve_ger_gravarparticipante.asp?IdParticipante="+IdParticipante+"&IdEvento="+IdEvento;
		
		new Ajax.Request(UrlValidacoes, 
		{   
			method: 'post',  
			encoding: 'UTF-8',
			parameters: $('formPesquisa').serialize(true),
			
			onSuccess: function(transport) { 
			
				
				if (transport.responseText == "erro|participanteexistente")
				{
					alert("Esse participante já está relacionado a este evento.");
					return false;
				}
				
				document.getElementById("painel").innerHTML = "<script>window.location.reload()</script>";
			
			},
			onFailure: function(transport)
			{
				alert('Um ou mais erros ocorreram com a página. Tente por favor novamente.\n'
					+ 'Caso o problema persista, tente recarregar toda a página ou entre \n'
					+ 'em contato conosco.'+UrlValidacoes);
			} 
		});
	}

	
	