    var nCurrMenu = 1;
	var nNewsTimeout = null;
	var nNewsStartOffset = 0;
	var nNewsEndOffset = 0;
	var nGlobalStopNews = 0;
    var nGlobalFadeMenu = 300;
	var cGlobalMainContainer = "#idMainCnt";
	var nGlobalMenuMode = 0;

  

								 
								 
	  var aSMenuArray1Timer = null;
	  var aSMenuArray1 = new Array();
								 
	  var aSMenuArray2Timer = null;
	  var aSMenuArray2 = new Array(
								   new Array("Apresentação", null, "showpage.php?i=2&j=1", null),
								   new Array("Doutrina", null, "showpage.php?i=2&j=2", null),
								   new Array("Nossa História", null, "showpage.php?i=2&j=3", null),
								   new Array("Show de Slides", null, "slideshow.php", null)
								 );
								 
	  var aSMenuArray3Timer = null;
	  var aSMenuArray3 = new Array(
								   new Array("Visão Geral", null, "igrejas.php", null),
								   new Array("Primeira Região", null, "igrejas.php?igr=-1", null),
								   new Array("Segunda Região", null, "igrejas.php?igr=-2", null),
								   new Array("Terceira Região", null, "igrejas.php?igr=-3", null),
								   new Array("Quarta Região", null, "igrejas.php?igr=-4", null),
								   new Array("Acampamentos", null, "igrejas.php?igr=-6", null),
								   new Array("Projetos Sociais", null, "igrejas.php?igr=-7", null),
								   new Array("Japão", null, "igrejas.php?igr=-5", null)
								 );
								 
								 
	  var aSMenuArray4Timer = null;
	  var aSMenuArray4 = new Array(
								   new Array("Visão Geral", null, "showpage.php?i=4", null),
								   new Array("Acampamentos", null, "showpage.php?i=4&j=1", null),
								   new Array("Missões", null, "showpage.php?i=4&j=2", null),
								   new Array(
								          "Projetos Sociais", 
										  null, 
										  "showpage.php?i=4&j=3", 
										  new Array(
										        new Array("Instituto Amar", null, "showpage.php?i=4&j=3&k=1", null),
												new Array("Projeto Aba", null, "showpage.php?i=4&j=3&k=2", null)
										      )
										),
								   new Array("Crianças", null, "showpage.php?i=4&j=4", null),
								   new Array("Jovens", null, "showpage.php?i=4&j=5", null),
								   new Array("Profissionais", null, "showpage.php?i=4&j=6", null),
								   new Array("Famílias", null, "showpage.php?i=4&j=7", null),
								   new Array("Terceira Idade", null, "showpage.php?i=4&j=8", null),
								   new Array("Língua Japonesa", null, "showpage.php?i=4&j=9", null),
								   new Array("Eventos", null, "showpage.php?i=4&j=10", null),
								   new Array(
								          "Recursos", 
										  null, 
										  "showpage.php?i=4&j=3", 
										  new Array(
										        new Array("Audiovisual", null, "media.php", null),
												new Array("Mensagens", null, "mensagens.php", null),
												new Array("Bíblia", null, "biblia.php", null)
										      )
										)
								 );
								 
		/*						 
	  var aSMenuArray5Timer = null;
	  var aSMenuArray5 = new Array(
								   new Array("Visão Geral", null, "showpage.php?i=5", null),
								   new Array("Palestras/Estudos", null, "media.php", null),
								   new Array("Pregações", null, "mensagem.php", null),
								   new Array("Bíblia", null, "biblia.php", null)
								 );
			*/	
      var aSMenuArray5Timer = null;
	  var aSMenuArray5 = new Array();
			
	  var aSMenuArray6Timer = null;
	  var aSMenuArray6 = new Array(
								   new Array("Visão Geral", null, "showpage.php?i=6", null),
								   new Array("Hora H", null, "horah.php", null),
								   new Array("Livros", null, "showpage.php?i=6&j=2", null)
								 );
								 
	  var aSMenuArray7Timer = null;
	  var aSMenuArray7 = new Array();
   

	  var aSMenuArray8Timer = null;
	  var aSMenuArray8 = new Array();
								 
    function SendMail(cServer, cFiller, cUser) {
      window.location.assign("mailto:"+cUser+"@"+cServer);
    }
  
    function holyMenuIn(nIndex) {
	 if (nGlobalMenuMode==1) {
	   if (nIndex!=nCurrMenu) {
	     $("#idMenu"+nIndex+"l").removeClass('cMenuL');
	     $("#idMenu"+nIndex+"r").removeClass('cMenuR');
	 
	     $("#idMenu"+nIndex+"l").addClass('cMenuLF');
	     $("#idMenu"+nIndex+"r").addClass('cMenuRF');
	    }	  
	  }
  	  jsGlobalOverMenu(nIndex);
	}
	
    function holyMenuOut(nIndex) {
	  if (nGlobalMenuMode==1) {
	    if (nIndex!=nCurrMenu) {
	      $("#idMenu"+nIndex+"l").removeClass('cMenuLF');
	      $("#idMenu"+nIndex+"r").removeClass('cMenuRF');	 
	     $("#idMenu"+nIndex+"l").addClass('cMenuL');
	     $("#idMenu"+nIndex+"r").addClass('cMenuR');
	    }
	  }
	  jsGlobalOutMenu(nIndex);
	}
	
	function holyNewsTimeout() {
	  if (nGlobalStopNews==0) {
	    var nTop = $('#idNewsScroll').scrollTop();
	    $('#idNewsScroll').scrollTop($('#idNewsScroll').scrollTop()+1);
	    if ($('#idNewsScroll').scrollTop()==nTop) $('#idNewsScroll').scrollTop(nNewsStartOffset);
	  }
	  
	  var nWait = 50;
	  for(var i=1;i<=nGlobalTotNews;i++) {
	    if (Math.round($("#idGNews"+i).offset().top)==0) {		   
		  nWait = 3000;
		  break;
		}
	  }	      
	  nNewsTimeout = setTimeout("holyNewsTimeout()", nWait);
	}
	
	function holyStartTimeout() {	  
	  nNewsTimeout = setTimeout("holyNewsTimeout()", 50);
	}
	
	
	function jsGlobalOverMenu(nIndex) {
	  // Mostra o menu
	  $('#aSMenuArray'+nIndex).show();
	}
	
	function jsGlobalOutMenu(nIndex) {
	  // Esconde o menu após 1 segundo
	  var cMenuArray = 'aSMenuArray'+nIndex;
	  var nVal = setTimeout("jsMyHideSubMenuDo(-1, '"+cMenuArray+"')", 200);
	  eval(cMenuArray+"Timer = "+nVal);		
	}
	
	
	function holyGlobalLoadPage(nIndex) {
	  nCurrMenu = nIndex;
	  nGlobalStopNews = 0;
	  
	  var S = '';
	  
	  if (nGlobalMenuMode==1) {
	    S += '<div id="idMenu1l" class="cMenuL'+((nIndex==1)?'C':'')+'"></div><div id="idMenu1r" class="cMenuR'+((nIndex==1)?'C':'')+'"><a onmouseout="holyMenuOut(1);" onmouseover="holyMenuIn(1);" href="index.php">Principal</a></div>';
	    S += '<div id="idMenu2l" class="cMenuL'+((nIndex==2)?'C':'')+'"></div><div id="idMenu2r" class="cMenuR'+((nIndex==2)?'C':'')+'"><a onmouseout="holyMenuOut(2);" onmouseover="holyMenuIn(2);" href="showpage.php?i=2">Quem Somos</a></div>';
	    S += '<div id="idMenu3l" class="cMenuL'+((nIndex==3)?'C':'')+'"></div><div id="idMenu3r" class="cMenuR'+((nIndex==3)?'C':'')+'"><a onmouseout="holyMenuOut(3);" onmouseover="holyMenuIn(3);" href="igrejas.php">Onde Estamos</a></div>';
	    S += '<div id="idMenu4l" class="cMenuL'+((nIndex==4)?'C':'')+'"></div><div id="idMenu4r" class="cMenuR'+((nIndex==4)?'C':'')+'"><a onmouseout="holyMenuOut(4);" onmouseover="holyMenuIn(4);" href="showpage.php?i=4">O Que Fazemos</a></div>';
	    //S += '<div id="idMenu5l" class="cMenuL'+((nIndex==5)?'C':'')+'"></div><div id="idMenu5r" class="cMenuR'+((nIndex==5)?'C':'')+'"><a onmouseout="holyMenuOut(5);" onmouseover="holyMenuIn(5);" href="showpage.php?i=5">Recursos</a></div>';
	    S += '<div id="idMenu6l" class="cMenuL'+((nIndex==6)?'C':'')+'"></div><div id="idMenu6r" class="cMenuR'+((nIndex==6)?'C':'')+'"><a onmouseout="holyMenuOut(6);" onmouseover="holyMenuIn(6);" href="showpage.php?i=6">Publicações</a></div>';	  
	    S += '<div id="idMenu7l" class="cMenuL'+((nIndex==7)?'C':'')+'"></div><div id="idMenu7r" class="cMenuR'+((nIndex==7)?'C':'')+'"><a onmouseout="holyMenuOut(7);" onmouseover="holyMenuIn(7);" href="showpage.php?i=7">Links</a></div>';
	    S += '<div id="idMenu8l" class="cMenuL'+((nIndex==8)?'C':'')+'"></div><div id="idMenu8r" class="cMenuR'+((nIndex==8)?'C':'')+'"><a onmouseout="holyMenuOut(8);" onmouseover="holyMenuIn(8);" href="showpage.php?i=8">Contato</a></div>';
        $("#idTop").append('<img id="idImgNews" style="position:absolute;left:264px;top:2px;cursor:pointer;" src="pics/news.png" onclick="window.location=\'news.php\'" title="Novidades" alt="Novidades">');		
		$("#idTop").append('<img id="idImgSearch" style="position:absolute;left:820px;top:0px;cursor:pointer;" src="pics/search.png" onclick="holyPerformSearch();" title="Pesquisa" alt="Pesquisa">');		
        if (globalLogged==1) {	
          $("#idTop").append('<img id="idImgLogin" style="position:absolute;left:820px;top:22px;cursor:pointer;" src="pics/logout.gif" onclick="window.location=\'logout.php\'" title="Logoff" alt="Logoff">');
        }
        else {
          $("#idTop").append('<img id="idImgLogin" style="position:absolute;left:820px;top:22px;cursor:pointer;" src="pics/login.gif" onclick="holyPerformLogin(830,80);" title="Login" alt="Login">');
        }	  		
	  }
	  else {
	    S += '<div style="position:absolute;left:10px;top:12px;font-size:8pt;">';
	    S += '<a id="idMenu1l" class="cMenuK'+((nIndex==1)?'C':'')+'" onmouseout="holyMenuOut(1);" onmouseover="holyMenuIn(1);" href="index.php">Principal</a> | ';
		S += '<a id="idMenu2l" class="cMenuK'+((nIndex==2)?'C':'')+'" onmouseout="holyMenuOut(2);" onmouseover="holyMenuIn(2);" href="showpage.php?i=2">Quem Somos</a> | ';
		S += '<a id="idMenu3l" class="cMenuK'+((nIndex==3)?'C':'')+'" onmouseout="holyMenuOut(3);" onmouseover="holyMenuIn(3);" href="igrejas.php">Onde Estamos</a> | ';
		S += '<a id="idMenu4l" class="cMenuK'+((nIndex==4)?'C':'')+'" onmouseout="holyMenuOut(4);" onmouseover="holyMenuIn(4);" href="showpage.php?i=4">O Que Fazemos</a> | ';
		S += '<a id="idMenu6l" class="cMenuK'+((nIndex==6)?'C':'')+'" onmouseout="holyMenuOut(6);" onmouseover="holyMenuIn(6);" href="showpage.php?i=6">Publicações</a> | ';
		S += '<a id="idMenu7l" class="cMenuK'+((nIndex==7)?'C':'')+'" onmouseout="holyMenuOut(7);" onmouseover="holyMenuIn(7);" href="showpage.php?i=7">Links</a> | ';
		S += '<a id="idMenu8l" class="cMenuK'+((nIndex==8)?'C':'')+'" onmouseout="holyMenuOut(8);" onmouseover="holyMenuIn(8);" href="showpage.php?i=8">Contato</a></div>'
		
		S += '<div  id="idImgLogin" style="position:absolute;left:630px;top:12px;font-size:8pt;width:200px;text-align:right">';
		S += '<a class="cMenuK" href="news.php">Novidades</a>';
		S += ' | <a class="cMenuK" href="javascript:holyPerformSearch(830,80)">Pesquisa</a>';
        if (globalLogged==1) {	
          S += ' | <a class="cMenuK" href="logout.php">Logout</a>';
        }
        else {
		  S += ' | <a class="cMenuK" href="javascript:holyPerformLogin(830,80)">Login</a>';
        }	  		
		S += '</div>';		
		//S += '<div style="position:absolute;left:600px;top:12px;font-size:8pt;background-color:white;width:200px;">';
		//S += 'Login | Buscar <input class="cEdit" name="TEXT" type="TEXT" style="width:40px;height:16px;font-size:7pt;">';
		//S += '</div>';
	  }
	  
	  
	  $('#idMenuContainer').html(S);
	  $('#idNewsInfo').html(aGlobalNews);
	  
	  for (var i=1; i<=7; i++) {
        if (eval('aSMenuArray'+i+'.length')!=0) {
	      var nX = $('#idMenu'+i+'l').position().left+8;
	      var nY = $('#idMenu'+i+'l').position().top+16+80;
	      jsMyCreateSubMenu('aSMenuArray'+i, [], nX, nY, 120, 1000); 
		}
	  }	  
	  
	  S = '';
	  S += "<div class='cShadow50' style='position:absolute;left:10px;top:20px;font-size:7pt;color:black; padding:0px 10px 0px 10px'> 2010 | Igreja Evangélica Holiness do Brasil | Todos os direitos reservados </div>";
	  S += "<div class='cShadow50' style='position:absolute;left:600px;top:20px;font-size:7pt;color:black; padding:0px 10px 0px 10px'> +55 11 3628 7133 | <a href='mailto:contato@holiness.org.br'>contato@holiness.org.br</a> </div>";
	  
	  S += "<a href='/dc/rss.php'><img src='pics/rss.png' title='Assine o RSS para receber atualizações' alt='RSS' style='position:absolute;border:none;top:4px;left:810px;'></a>";
	  $('#idBottom').html(S);
	  
	  nNewsStartOffset = $('#idNewsScroll').offset().top;
	  nNewsEndOffset = $('#idEndScroll').offset().top;
	  holyStartTimeout();      
	}
	
	
	function jsRepeat(str, i) {
      if (isNaN(i) || i <= 0) return "";
      return str + jsRepeat(str, i-1);
    }

	
    function jsStrZero(x, n) {
     var zeros = jsRepeat("0", n);
     return String(zeros + x).slice(-1 * n)
    }


		function jsMyRemoveMenu(cIdMenu, aMenuArray) {
	  $('#'+cIdMenu+'0').remove();
	}
	
	
	function jsMyHideSubMenuDo(i, cMenuArrayEval) {	
	  if (i<0) {
	    if (eval(cMenuArrayEval+"Timer")!=null) clearTimeout(eval(cMenuArrayEval+"Timer"));		
		eval(cMenuArrayEval+"Timer = null");
		//$('#'+cMenuArrayEval).css("display", "none");
		//$('#'+cMenuArrayEval).fadeOut(nGlobalFadeMenu);
		$('#'+cMenuArrayEval).hide();
	  }
	  else {
	    if (eval(cMenuArrayEval+"["+i+"][3]")!=null) {
	  
	      var cIdMenu = "";
	      for (var j=0; j<cMenuArrayEval.length; j++) {
	        if ((cMenuArrayEval.charAt(j)=="[")||(cMenuArrayEval.charAt(j)=="]")) {
		      cIdMenu += "_";
		    }
		    else {
		      cIdMenu += cMenuArrayEval.charAt(j);
		    }
	      }
	    
	      //$('#'+cIdMenu+('_'+i+'__3_')).css("display", "none");
		  //$('#'+cIdMenu+('_'+i+'__3_')).fadeOut(nGlobalFadeMenu);
		  $('#'+cIdMenu+('_'+i+'__3_')).hide();
		
	      if (eval(cMenuArrayEval+"["+i+"][1]")!=null) clearTimeout(eval(cMenuArrayEval+"["+i+"][1]"));		
	      eval(cMenuArrayEval+"["+i+"][1] = null");
		}
	  }
	}
	
	function jsMyHideSubMenu(i, cMenuArrayEval) {	
	  if (eval(cMenuArrayEval+"["+i+"][3]")!=null) { // Existe submenu para este link?
	    // Existe um timeout definido?
		if (eval(cMenuArrayEval+"["+i+"][1]")!=null) clearTimeout(eval(cMenuArrayEval+"["+i+"][1]"));		
		var nVal = setTimeout("jsMyHideSubMenuDo("+i+", '"+ cMenuArrayEval+"')", 100);
		eval(cMenuArrayEval+"["+i+"][1] = "+nVal);
	  }
	  
	  // Procura pelo pai. Criar um time para apaga-lo
	  var cMenuArrayPai = cMenuArrayEval;
	  while (1) {
	    var nContAbreColchetes = 0;
	    var nPosAbreColchetes = 0;
	    for (var k=cMenuArrayPai.length-1; k>0; k--) {
	      if (cMenuArrayPai.charAt(k)=="[") {
		    ++nContAbreColchetes;
		    nPosAbreColchetes = k;
		    if (nContAbreColchetes>=2) break;
		  }
	    }
	  
	    if (nContAbreColchetes>=2) {
	      var nPosFechaColchetes = 0;
		  for (var k=nPosAbreColchetes; k<cMenuArrayPai.length; k++) {
		    if (cMenuArrayPai.charAt(k)=="]") {
		      nPosFechaColchetes = k;
		      break;
		    }
		  }
		
		
		  var nIndex = parseInt(cMenuArrayPai.substr(nPosAbreColchetes+1, nPosFechaColchetes-nPosAbreColchetes-1));
          cMenuArrayPai = cMenuArrayPai.substring(0, nPosAbreColchetes);
		
		  if (eval(cMenuArrayPai+"["+nIndex+"][1]")!=null) clearTimeout(eval(cMenuArrayPai+"["+nIndex+"][1]"));		
		  var nVal = setTimeout("jsMyHideSubMenuDo("+nIndex+", '"+cMenuArrayPai+"')", 100);
		  eval(cMenuArrayPai+"["+nIndex+"][1] = "+nVal);
		
	    }
	    else {
		  if (eval(cMenuArrayPai+"Timer")!=null) clearTimeout(eval(cMenuArrayPai+"Timer"));		
		  var nVal = setTimeout("jsMyHideSubMenuDo(-1, '"+cMenuArrayPai+"')", 100);
		  eval(cMenuArrayPai+"Timer = "+nVal);
		  break;
	    }
	  }
	}
	
    function jsMyShowMenu(cMenuArray) {
	  $('#'+cMenuArray).fadeIn(nGlobalFadeMenu);
	  var nVal = setTimeout("jsMyHideSubMenuDo(-1, '"+cMenuArray+"')", 5000);
	  eval(cMenuArray+"Timer = "+nVal);	
	}
	
	
	function jsMyShowSubMenu(j, cMenuArrayEval) {
	  var nLen = eval(cMenuArrayEval+".length");
	  
	  var cIdMenu = "";
	  for (var i=0; i<cMenuArrayEval.length; i++) {
	    if ((cMenuArrayEval.charAt(i)=="[")||(cMenuArrayEval.charAt(i)=="]")) {
		  cIdMenu += "_";
		}
		else {
		  cIdMenu += cMenuArrayEval.charAt(i);
		}
	  }

	  
	  for (var i=0; i<nLen; i++) {	  
	    if (i==j) {
	      if (eval(cMenuArrayEval+"["+i+"][3]")!=null) {
	        //$('#'+cIdMenu+('_'+j+'__3_')).css("display", "block");
			//$('#'+cIdMenu+('_'+j+'__3_')).fadeIn(nGlobalFadeMenu);
			$('#'+cIdMenu+('_'+j+'__3_')).show();
			
			// não existe timer habilitado
			eval(cMenuArrayEval+"["+i+"][1]= null");
	      }
		  
		  
		  // Procura pelo pai. Se houver um timer habilitado, apague-o
		  var cMenuArrayPai = cMenuArrayEval;
		  
		  while (1) {
		    var nContAbreColchetes = 0;
		    var nPosAbreColchetes = 0;
		    
			for (var k=cMenuArrayPai.length-1; k>0; k--) {
		      if (cMenuArrayPai.charAt(k)=="[") {
			    ++nContAbreColchetes;
			    nPosAbreColchetes = k;
			    if (nContAbreColchetes>=2) break;
			  }
		    }
			
			
		    if (nContAbreColchetes>=2) {
			  var nPosFechaColchetes = 0;
		      for (var k=nPosAbreColchetes; k<cMenuArrayPai.length; k++) {
		        if (cMenuArrayPai.charAt(k)=="]") {
		          nPosFechaColchetes = k;
		          break;
		        }
		      }
			  
		      var nIndex = parseInt(cMenuArrayPai.substr(nPosAbreColchetes+1, nPosFechaColchetes-nPosAbreColchetes-1));
              cMenuArrayPai = cMenuArrayPai.substring(0, nPosAbreColchetes);
			  if (eval(cMenuArrayPai+"["+nIndex+"][1]")!=null) clearTimeout(eval(cMenuArrayPai+"["+nIndex+"][1]"));
			  eval(cMenuArrayPai+"["+nIndex+"][1] = null");
		    }
		    else {
		      if (eval(cMenuArrayPai+"Timer")!=null) clearTimeout(eval(cMenuArrayPai+"Timer"));
			  eval(cMenuArrayPai+"Timer = null");
			  break;
		    }
		    
		  }
		  
		}
		else {
	      if (eval(cMenuArrayEval+"["+i+"][3]")!=null) {
	        //$('#'+cIdMenu+('_'+i+'__3_')).css("display", "none");
			//$('#'+cIdMenu+('_'+i+'__3_')).fadeOut(nGlobalFadeMenu);
			$('#'+cIdMenu+('_'+i+'__3_')).hide();
			if (eval(cMenuArrayEval+"["+i+"][1]")!=null) clearTimeout(eval(cMenuArrayEval+"["+i+"][1]"));
			eval(cMenuArrayEval+"["+i+"][1]= null")
	      }
		}
	  }
	}
	
	function jsMyCreateMenu(cMenuArray, aIndex, x, y, w, nZOrder, cShow) {
	  var cHTML = "";
	  cHTML += "<div style='display:block;float:left;background-image:url(pics/graymenutl.png);width:7px;height:7px;'></div>";
	  cHTML += "<div style='float:left;background-image:url(pics/graymenutm.png);width:"+(w-7-11)+"px;height:7px;'></div>";
	  cHTML += "<div style='display:block;float:left;background-image:url(pics/graymenutr.png);width:11px;height:7px;'></div>";

	  	  
	  // Cria cada uma das linhas do menu
	  
	  var cMenuArrayEval = cMenuArray;
	  var cIdMenu = cMenuArray;
	  for (var i=0; i<aIndex.length; i++) {
	    cMenuArrayEval += "["+aIndex[i]+"]";
		cIdMenu += "_"+aIndex[i]+"_";
	  }
	  
	  
	  var nLen = eval(cMenuArrayEval+".length");
	  for (var i=0; i<nLen; i++) {
	    cHTML += "<div style='float:left;background-image:url(pics/graymenuml.png);width:7px;height:18px;clear:both;'></div>";
	    cHTML += "<div style='float:left;background-image:url(pics/graymenumm.png);width:"+(w-7-11)+"px;height:18px;'>";
		cHTML += "<a href='' class='idMenu0' onmouseover='jsMyShowSubMenu("+i+", \""+cMenuArrayEval+"\");'"+
		         " onmouseout='jsMyHideSubMenu("+i+", \""+cMenuArrayEval+"\");'>"+
		         eval(cMenuArrayEval+"["+i+"][0]")+
				 "</a>";
		cHTML += "</div>";
		
		if (eval(cMenuArrayEval+"["+i+"][3]")!=null) {
		  cHTML += "<div style='float:left;background-image:url(pics/graymenumrs.png);width:11px;height:18px;'></div>";
		}
		else {
	      cHTML += "<div style='float:left;background-image:url(pics/graymenumr.png);width:11px;height:18px;'></div>";
		}
		
		
		// Cria os submenus
		if (eval(cMenuArrayEval+"["+i+"][3]")!=null) {
		  var aNewArray = new Array();
		  for (var j=0; j<aIndex.length; j++) aNewArray[j] = aIndex[j];
		  
		  aNewArray[aIndex.length] = i;
		  aNewArray[aIndex.length+1] = 3;
		  
		  jsMyCreateMenu(cMenuArray, aNewArray, x+w-30, y+7+18*i+1, w, nZOrder*10+i, 'N');
		}
	  }
	  
	  cHTML += "<div style='float:left;background-image:url(pics/graymenubl.png);width:7px;height:11px;clear:both;'></div>";
	  cHTML += "<div style='float:left;background-image:url(pics/graymenubm.png);width:"+(w-7-11)+"px;height:11px;'></div>";
	  cHTML += "<div style='float:left;background-image:url(pics/graymenubr.png);width:11px;height:11px;'></div>";

	  $(cGlobalMainContainer).append("<div id='"+cIdMenu+"' style='width:"+w+"px;position:absolute; z-index:"+nZOrder+"; left:"+x+"px; top:"+y+"px;"+((cShow=="S")?"":"display:none")+"'>"+cHTML+"</div>");
	  if (cShow=="S") {
	    var nVal = setTimeout("jsMyHideSubMenuDo(-1, '"+cMenuArray+"')", 5000);
		eval(cMenuArray+"Timer = "+nVal);
	  }
	}

	
	function jsMyCreateSubMenu(cMenuArray, aIndex, x, y, w, nZOrder) {
	  var cHTML = "";
	  var cLinkClass = "";
	  
	  if (nGlobalMenuMode==1) {
	    cHTML += "<div style='display:block;float:left;background-image:url(pics/graymenutl.png);width:7px;height:7px;'></div>";
	    cHTML += "<div style='float:left;background-image:url(pics/graymenutm.png);width:"+(w-7-11)+"px;height:7px;'></div>";
	    cHTML += "<div style='display:block;float:left;background-image:url(pics/graymenutr.png);width:11px;height:7px;'></div>";
		cLinkClass = "idMenu0";
	  }
	  else {
	    cHTML += "<div style='display:block;float:left;background-image:url(pics/shadowgreen90.png);border-top:solid 1px black;border-left:solid 1px black;border-right:solid 1px black;width:"+(w-2)+"px;height:7px;'></div>";
		cLinkClass = "cMenu1";
	  }

	  	  
	  // Cria cada uma das linhas do menu
	  
	  var cMenuArrayEval = cMenuArray;
	  var cIdMenu = cMenuArray;
	  for (var i=0; i<aIndex.length; i++) {
	    cMenuArrayEval += "["+aIndex[i]+"]";
		cIdMenu += "_"+aIndex[i]+"_";
	  }
	  
	  
	  var nLen = eval(cMenuArrayEval+".length");
	  for (var i=0; i<nLen; i++) {	    
	    var cLink = "<a href='"+eval(cMenuArrayEval+"["+i+"][2]")+"' class='"+cLinkClass+"' onmouseover='jsMyShowSubMenu("+i+", \""+cMenuArrayEval+"\");'"+
		            " onmouseout='jsMyHideSubMenu("+i+", \""+cMenuArrayEval+"\");'>"+
		            eval(cMenuArrayEval+"["+i+"][0]")+
				    "</a>";
					
		if (nGlobalMenuMode==1) {			
	      cHTML += "<div style='float:left;background-image:url(pics/graymenuml.png);width:7px;height:18px;clear:both;'></div>";
	      cHTML += "<div style='float:left;background-image:url(pics/graymenumm.png);width:"+(w-7-11)+"px;height:18px;'>";
		  cHTML += cLink;
		  cHTML += "</div>";		
		  if (eval(cMenuArrayEval+"["+i+"][3]")!=null) {
		    cHTML += "<div style='float:left;background-image:url(pics/graymenumrs.png);width:11px;height:18px;'></div>";
		  }
		  else {
	        cHTML += "<div style='float:left;background-image:url(pics/graymenumr.png);width:11px;height:18px;'></div>";
		  }
		}
		else {
		  cHTML += "<div style='float:left;background-image:url(pics/shadowgreen90.png);border-left:solid 1px black;border-right:solid 1px black;width:"+(w-2)+"px;height:18px;'>"+cLink+"</div>";
		}
		
		
		// Cria os submenus
		if (eval(cMenuArrayEval+"["+i+"][3]")!=null) {
		  var aNewArray = new Array();
		  for (var j=0; j<aIndex.length; j++) aNewArray[j] = aIndex[j];
		  
		  aNewArray[aIndex.length] = i;
		  aNewArray[aIndex.length+1] = 3;
		  
		  jsMyCreateSubMenu(cMenuArray, aNewArray, x+w-30, y+7+18*i+1, w, nZOrder*10+i);
		}
	  }
	  
	  if (nGlobalMenuMode==1) {
	    cHTML += "<div style='float:left;background-image:url(pics/graymenubl.png);width:7px;height:11px;clear:both;'></div>";
	    cHTML += "<div style='float:left;background-image:url(pics/graymenubm.png);width:"+(w-7-11)+"px;height:11px;'></div>";
	    cHTML += "<div style='float:left;background-image:url(pics/graymenubr.png);width:11px;height:11px;'></div>";
	  }
	  else {
	    cHTML += "<div style='display:block;float:left;background-image:url(pics/shadowgreen90.png);border-bottom:solid 1px black;border-left:solid 1px black;border-right:solid 1px black;width:"+(w-2)+"px;height:7px;'></div>";
	  }

	  $(cGlobalMainContainer).append("<div id='"+cIdMenu+"' style='width:"+w+"px;position:absolute;z-index:"+nZOrder+"; left:"+x+"px; top:"+y+"px;display:none;font-size:0px;'>"+cHTML+"</div>");
	}
	
	
	function jsCreatePanel(cIdPanel, x, y, w, h, nZOrder) {
      var cHTML = "";
	  cHTML += "<div style='display:block;float:left;background-image:url(pics/ptl.png);width:7px;height:7px;'></div>";
	  cHTML += "<div id='"+cIdPanel+"Caption' style='float:left;background-image:url(pics/ptm.png);width:"+(w-7-11)+"px;height:7px;'></div>";
	  cHTML += "<div style='display:block;float:left;background-image:url(pics/ptr.png);width:11px;height:7px;'></div>";
	  
      cHTML += "<div style='float:left;background-image:url(pics/pml.png);width:7px;height:"+(h-7-11)+"px;clear:both;'></div>";
	  cHTML += "<div style='float:left;background-image:url(pics/pmm.png);width:"+(w-7-11)+"px;height:"+(h-7-11)+"px;'></div>";
	  cHTML += "<div style='float:left;background-image:url(pics/pmr.png);width:11px;height:"+(h-7-11)+"px;'></div>";
	  
      cHTML += "<div style='float:left;background-image:url(pics/pbl.png);width:7px;height:11px;clear:both;'></div>";
	  cHTML += "<div style='float:left;background-image:url(pics/pbm.png);width:"+(w-7-11)+"px;height:11px;'></div>";
	  cHTML += "<div style='float:left;background-image:url(pics/pbr.png);width:11px;height:11px;'></div>";
	  
	  $(cGlobalMainContainer).append("<div id='"+cIdPanel+"' style='position: absolute; z-index:"+nZOrder+"; left:"+x+"px; top:"+y+"px; width:"+w+"px; height:"+h+"px;'>"+cHTML+"</div>");
	}
	
	function jsCreateWindow(cIdPanel, cTemplate, aW, cCaption, x, y, w, h, nZOrder, cContent, nModal) {
	  if ($("#"+cIdPanel).length>0) $("#"+cIdPanel).remove();
	  if ($("#"+cIdPanel+"_back").length>0) $("#"+cIdPanel+"_back").remove();

        var cHTML = "";
	    cHTML += "<div style='display:block;float:left;background-image:url("+cTemplate+"tl.png);width:"+aW[0]+"px;height:"+aW[1]+"px;'></div>";
	    cHTML += "<div style='float:left;background-image:url("+cTemplate+"tm.png);width:"+(w-aW[0]-aW[2])+"px;height:"+aW[1]+"px;'></div>";
	    cHTML += "<div style='display:block;float:left;background-image:url("+cTemplate+"tr.png);width:"+aW[2]+"px;height:"+aW[1]+"px;'></div>";
	  
        cHTML += "<div style='float:left;background-image:url("+cTemplate+"ml.png);width:"+aW[0]+"px;height:"+(h-aW[1]-aW[3])+"px;clear:both;'></div>";
	    cHTML += "<div id='"+cIdPanel+"Util' style='float:left;background-image:url("+cTemplate+"mm.png);width:"+(w-aW[0]-aW[2])+"px;height:"+(h-aW[1]-aW[3])+"px;'>";	    
		cHTML += "<div style='width:"+(w-aW[0]-aW[2]-2)+"px; height:"+(aW[5])+"px;cursor:move;padding:1px;border-bottom:solid 1px green;'>";
	    cHTML += "<div id='"+cIdPanel+"Title' style='float:left;width:"+(w-aW[0]-aW[2]-4-aW[4])+"px; height:"+(aW[5])+"px;cursor:move;font-family:helvetica;font-size:11pt;font-weight:bold;color:#d0d0d0;'>"+cCaption+"</div>";
	    var cAux = 'jsRemoveWindow("'+cIdPanel+'")';
	    cHTML += "<div style='float:left;width:"+(aW[4])+"px;height:"+(aW[5])+"px;background-image:url("+cTemplate+"close.png);cursor:pointer;' onclick='"+cAux+"');'></div>";
	    cHTML += "</div>";
		cHTML += "<div id='"+cIdPanel+"_content' style='overflow:auto;clear:both;'>"+cContent+"</div>";
	    cHTML += "</div>";
	    cHTML += "<div style='float:left;background-image:url("+cTemplate+"mr.png);width:"+aW[2]+"px;height:"+(h-aW[1]-aW[3])+"px;'></div>";	  
        cHTML += "<div style='float:left;background-image:url("+cTemplate+"bl.png);width:"+aW[0]+"px;height:"+aW[3]+"px;clear:both;'></div>";
	    cHTML += "<div style='float:left;background-image:url("+cTemplate+"bm.png);width:"+(w-aW[0]-aW[2])+"px;height:"+aW[3]+"px;'></div>";
	    cHTML += "<div style='float:left;background-image:url("+cTemplate+"br.png);width:"+aW[2]+"px;height:"+aW[3]+"px;'></div>";
	  
	    var bw = 840;
		var bh = $(cGlobalMainContainer).height();
		
		if (nModal!=0) {
		  // Coloca uma barreira para impossibiltar o acesso aos items que ficarão em segundo plano, criando um efeito de janela modal
          $(cGlobalMainContainer).append("<div id='"+cIdPanel+"_back' style='position: absolute; z-index:"+(nZOrder-1)+"; left:"+0+"px; top:"+0+"px; width:"+bw+"px; height:"+bh+"px;background-image:url(pics/blackshadow.png);'></div>");
		} 
		
		// Adiciona a janela à estrutura da página
	    $(cGlobalMainContainer).append("<div id='"+cIdPanel+"' style='position: absolute; z-index:"+nZOrder+"; left:"+x+"px; top:"+y+"px; width:"+w+"px; height:"+h+"px;'>"+cHTML+"</div>");
	  
	    // Torna a janela arrastável
	    $('#'+cIdPanel).draggable({handle:('#'+cIdPanel+'Title')});
	  
	}
	
	function jsRemoveWindow(cIdPanel) {
	  if ($('#'+cIdPanel).length>0) $('#'+cIdPanel).remove();
	  if ($('#'+cIdPanel+'_back').length>0) $('#'+cIdPanel+'_back').remove();
	}
	
	function jsForceSubmit(cFormName) {
	  $('#'+cFormName).submit();
	}	
	
	

	
	function holyPerformSearch(X,Y) {
	  var cContent = "";
	  var cAux = '';
	  cContent += "<p style='font-family:helvetica; color:white; font-size:10pt; text-align:justify; font-weight:bold;padding: 2px;'>";
	  cContent += "Digite a palavra or frase que deseja pesquisar em nosso conteúdo. A pesquisa será realizada em todas as páginas e publicações contidas em nosso site.";
	  cContent += "</p>";
	  cContent += "<form id='idFormSearch' method='POST' action='globalsearch.php' onsubmit=''>";
	  cContent += "<input id='TEXT' name='TEXT' type='TEXT' style='width:350px;'>";
	  cContent += "</form>";
	  
	  cAux = 'jsForceSubmit("idFormSearch");';
	  cContent += "<div style='margin-left:80px; margin-top:10px;' class='cGreenButton' onclick='"+cAux+"'>Pesquisar</div>";
	  
	  cAux = 'jsRemoveWindow("idSearch");';
	  cContent += "<div style='margin-left:10px; margin-top:10px;' class='cGreenButton' onclick='"+cAux+"'>Cancelar</div>";
	  
	  //var nX = $("#idImgSearch").position().left;
	  //var nY = $("#idImgSearch").position().top;
	  nX = X;
	  nY = Y;
	  
	  
	  jsCreateWindow('idSearch', 'pics/greenwin', new Array(16, 16, 26, 26, 20, 20), 'Pesquisa', nX-400, nY+10, 400, 220, 1000, cContent);
	  
	  $("#TEXT").focus();
	}
	
	function holyPerformLoginSubmit() {
	  var nX = $("#idLogin").position().left;
	  var nY = $("#idLogin").position().top;	   
  
	  var nLH = 0;
	  var cContent = '';
	  if ($('#USER').val()=='') {
	    cContent += '<p style="line-height:20px;margin:0px 0px 2px 0px;font-family:Helvetica;font-size:10pt;color:white;font-weight:bold;">O nome do usuário não pode estar em branco.</p>';
		nLH += 22;
	  }
	  if ($('#PASS').val()=='') {
	    cContent += '<p style="line-height:20px;margin:0px 0px 2px 0px;font-family:Helvetica;font-size:10pt;color:white;font-weight:bold;">A senha não pode estar em branco.</p>';
		nLH += 22;
	  }
	  if ($('#CAPTCHA').val()=='') {
	    cContent += '<p style="line-height:20px;margin:0px 0px 2px 0px;font-family:Helvetica;font-size:10pt;color:white;font-weight:bold;">Os dígitos de verificação devem ser informados.</p>';
		nLH += 22;
	  }
	  
	  if (cContent=='') {
	    jsForceSubmit("idFormLogin");
	  }
	  else {
		var cAux = 'jsRemoveWindow("idLoginError");';
	    cContent += "<div style='margin:120px; margin-top:10px;' class='cGreenButton' onclick='"+cAux+"'>Fechar</div>";
	    jsCreateWindow('idLoginError', 'pics/greenwin', new Array(16, 16, 26, 26, 20, 20), 'Atenção', nX-32, nY+32, 400, 110+nLH, 1100, cContent);
	  }
	}
	
	function holyPerformLogin(X,Y) {
	  var cContent = "";
	  var cAux = '';
	  cContent += "<p style='font-family:helvetica; color:white; font-size:10pt; text-align:justify; font-weight:bold;padding: 2px;'>";
	  cContent += "<img src='p.php?r="+Math.round(Math.random()*65535)+Math.round(Math.random()*65535)+"' style='float:right; border:solid 2px green; margin:4px 0px 0px 8px;'>";
	  cContent += "Digite seu nome de usuário, a sua senha e escreva no espaço correspondente à <u>Verificação</u> as letras e os número desenhados na figura ao lado para entrar no sistema.";  
	  cContent += "</p>";
	  cContent += "<form id='idFormLogin' method='POST' action='login.php'>";
	  cContent += "<table style='font-family:helvetica;color:yellow;font-size:10pt;font-weight:bold;'>";
	  cContent += "<tr>";
	  cContent += "<td>Nome</td>";
	  cContent += "<td><input id='USER' name='USER' type='TEXT' style='width:200px;'></td>";
	  cContent += "</tr>";
	  cContent += "<tr>";
	  cContent += "<td>Senha</td>";
	  cContent += "<td><input id='PASS' name='PASS' type='PASSWORD' style='width:200px;'></td>";
	  cContent += "</tr>";
      cContent += "<tr style='text-align:middle;'>";
	  cContent += "<td>Verificação</td>";
	  cContent += "<td><input id='CAPTCHA' name='CAPTCHA' type='TEXT' style='width:200px;'></td>";
	  cContent += "</tr>";	  	  
	  cContent += "</table>";
	  cContent += "</form>";
	  
	  cAux = 'jsForceSubmit("idFormLogin");';
	  cContent += "<div style='margin-left:80px; margin-top:10px;' class='cGreenButton' onclick='holyPerformLoginSubmit();'>Entrar</div>";
	  
	  cAux = 'jsRemoveWindow("idLogin");';
	  cContent += "<div style='margin-left:10px; margin-top:10px;' class='cGreenButton' onclick='"+cAux+"'>Cancelar</div>";
	  
	  var nX = $("#idImgLogin").position().left;
	  var nY = $("#idImgLogin").position().top;
	  nX = X;
	  nY = Y;
	  
	  //alert("nX="+nX+", nY="+nY);	  
	  
	  jsCreateWindow('idLogin', 'pics/greenwin', new Array(16, 16, 26, 26, 20, 20), 'Login', nX-400, nY+10, 400, 320, 1000, cContent);
	  
	  $("#USER").focus();
	}
	
	
	function holyLoadMap(cBaseElement, cMaps, cInfo) {
      var nW = 600;
	  var nH = 500;
	  var nX = $("#"+cBaseElement).position().left;
	  var nY = $("#"+cBaseElement).position().top;
	  
	  jsCreateWindow('idMap', 'pics/greenwin', new Array(16, 16, 26, 26, 20, 20), 'Localização no Mapa', nX, nY-nH, nW, nH, 1000, "");
	  
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById('idMap_content'));
        map.setCenter(new GLatLng(cMaps), 15);
        map.openInfoWindow(map.getCenter(), document.createTextNode(cInfo));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl()); 
	  }	
   
	}

	
function jsCheckData(cFieldName) {
   var aMes = new Array (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   var cDNasc = $('#'+cFieldName).val();
   var nDia = 0;
   var nMes = 0;
   var nAno = 0;
   // se digitou 8 caracteres sem barras, é porque digitou errado. vamos tentar arrumar
   if ((cDNasc.indexOf("/")<0)&&(cDNasc.length==8)) {
     cDNasc = cDNasc.substr(0, 2)+"/"+cDNasc.substr(2, 2)+"/"+cDNasc.substr(4, 4);
     $('#'+cFieldName).val(cDNasc);
   }
   var aDNasc = cDNasc.split("/");
   if (aDNasc.length>=0) {
     nDia = parseFloat(aDNasc[0]);
   }
   if (aDNasc.length>=1) {
     nMes = parseFloat(aDNasc[1]);
   }
   if (aDNasc.length>=2) {
     nAno = parseFloat(aDNasc[2]);
     if ((nAno<100)&&(nAno>10)) nAno = nAno+1900;
     if ((nAno<100)&&(nAno<=10)) nAno = nAno+2000;
   }
   if (cDNasc.length==0) {
     return("A Data deve ser fornecida\n");
   }
   else if (isNaN(nMes)||(nMes<1)||(nMes>12)) {
     return("Mês inválido na Data\n");
   }
   else if (isNaN(nDia)||(nDia<1)||(nDia>aMes[nMes-1])) {
     return("Dia inválido na Data\n");
   }
   else if (isNaN(nAno)||(nAno>=2100)||(nAno<1900)) {
     return("Ano inválido na Data\n");
   }
   else {
     return("");
   }
  }
  
function jsCheckCombo(cFieldName, cCaption) {
  if ($("#"+cFieldName).attr("selectedIndex")<0) {
    return("Selecione um valor para "+cCaption+"!\n");
  }
  else {
    return("");
  }
}


function jsCheckDataValue(cDNasc) {
   var aMes = new Array (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   var nDia = 0;
   var nMes = 0;
   var nAno = 0;
   
   // se digitou 6 caracteres sem barras, é porque digitou errado. vamos tentar arrumar
   if ((cDNasc.indexOf("/")<0)&&(cDNasc.length==6)) {
     cDNasc = cDNasc.substr(0, 2)+"/"+cDNasc.substr(2, 2)+"/"+cDNasc.substr(4, 2);
   }
   
   // se digitou 8 caracteres sem barras, é porque digitou errado. vamos tentar arrumar
   if ((cDNasc.indexOf("/")<0)&&(cDNasc.length==8)) {
     cDNasc = cDNasc.substr(0, 2)+"/"+cDNasc.substr(2, 2)+"/"+cDNasc.substr(4, 4);
   }
   
   var aDNasc = cDNasc.split("/");
   if (aDNasc.length>=0) {
     nDia = parseFloat(aDNasc[0]);
   }
   if (aDNasc.length>=1) {
     nMes = parseFloat(aDNasc[1]);
   }
   if (aDNasc.length>=2) {
     nAno = parseFloat(aDNasc[2]);
     if ((nAno<100)&&(nAno>10)) nAno = nAno+1900;
     if ((nAno<100)&&(nAno<=10)) nAno = nAno+2000;
   }
   if (cDNasc.length==0) {
     return("Erro: A Data deve ser fornecida");
   }
   else if (isNaN(nMes)||(nMes<1)||(nMes>12)) {
     return("Erro: Mês inválido na Data");
   }
   else if (isNaN(nDia)||(nDia<1)||(nDia>aMes[nMes-1])) {
     return("Erro: Dia inválido na Data");
   }
   else if (isNaN(nAno)||(nAno>=2100)||(nAno<1900)) {
     return("Erro: Ano inválido na Data");
   }
   else {
     return(jsStrZero(nDia, 2)+"/"+jsStrZero(nMes, 2)+"/"+jsStrZero(nAno, 4));
   }
}

sprintfWrapper = {
 
	init : function () {
 
		if (typeof arguments == "undefined") { return null; }
		if (arguments.length < 1) { return null; }
		if (typeof arguments[0] != "string") { return null; }
		if (typeof RegExp == "undefined") { return null; }
 
		var string = arguments[0];
		var exp = new RegExp(/(%([%]|(\-)?(\+|\x20)?(0)?(\d+)?(\.(\d)?)?([bcdfosxX])))/g);
		var matches = new Array();
		var strings = new Array();
		var convCount = 0;
		var stringPosStart = 0;
		var stringPosEnd = 0;
		var matchPosEnd = 0;
		var newString = '';
		var match = null;
 
		while (match = exp.exec(string)) {
			if (match[9]) { convCount += 1; }
 
			stringPosStart = matchPosEnd;
			stringPosEnd = exp.lastIndex - match[0].length;
			strings[strings.length] = string.substring(stringPosStart, stringPosEnd);
 
			matchPosEnd = exp.lastIndex;
			matches[matches.length] = {
				match: match[0],
				left: match[3] ? true : false,
				sign: match[4] || '',
				pad: match[5] || ' ',
				min: match[6] || 0,
				precision: match[8],
				code: match[9] || '%',
				negative: parseInt(arguments[convCount]) < 0 ? true : false,
				argument: String(arguments[convCount])
			};
		}
		strings[strings.length] = string.substring(matchPosEnd);
 
		if (matches.length == 0) { return string; }
		if ((arguments.length - 1) < convCount) { return null; }
 
		var code = null;
		var match = null;
		var i = null;
 
		for (i=0; i<matches.length; i++) {
 
			if (matches[i].code == '%') { substitution = '%' }
			else if (matches[i].code == 'b') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(2));
				substitution = sprintfWrapper.convert(matches[i], true);
			}
			else if (matches[i].code == 'c') {
				matches[i].argument = String(String.fromCharCode(parseInt(Math.abs(parseInt(matches[i].argument)))));
				substitution = sprintfWrapper.convert(matches[i], true);
			}
			else if (matches[i].code == 'd') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)));
				substitution = sprintfWrapper.convert(matches[i]);
			}
			else if (matches[i].code == 'f') {
				matches[i].argument = String(Math.abs(parseFloat(matches[i].argument)).toFixed(matches[i].precision ? matches[i].precision : 6));
				substitution = sprintfWrapper.convert(matches[i]);
			}
			else if (matches[i].code == 'o') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(8));
				substitution = sprintfWrapper.convert(matches[i]);
			}
			else if (matches[i].code == 's') {
				matches[i].argument = matches[i].argument.substring(0, matches[i].precision ? matches[i].precision : matches[i].argument.length)
				substitution = sprintfWrapper.convert(matches[i], true);
			}
			else if (matches[i].code == 'x') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
				substitution = sprintfWrapper.convert(matches[i]);
			}
			else if (matches[i].code == 'X') {
				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16));
				substitution = sprintfWrapper.convert(matches[i]).toUpperCase();
			}
			else {
				substitution = matches[i].match;
			}
 
			newString += strings[i];
			newString += substitution;
 
		}
		newString += strings[i];
 
		return newString;
 
	},
 
	convert : function(match, nosign){
		if (nosign) {
			match.sign = '';
		} else {
			match.sign = match.negative ? '-' : match.sign;
		}
		var l = match.min - match.argument.length + 1 - match.sign.length;
		var pad = new Array(l < 0 ? 0 : l).join(match.pad);
		if (!match.left) {
			if (match.pad == "0" || nosign) {
				return match.sign + pad + match.argument;
			} else {
				return pad + match.sign + match.argument;
			}
		} else {
			if (match.pad == "0" || nosign) {
				return match.sign + match.argument + pad.replace(/0/g, ' ');
			} else {
				return match.sign + match.argument + pad;
			}
		}
	}
}
 
sprintf = sprintfWrapper.init;

function sortDist(a,b) {
  return a[0] - b[0];
}

function holyGetDistanceResult(cResult) {
  var cStr = "";
  var cAddr = "";
  
  if ($('#idGDE').val()=="") {
    $("#"+cResult).html("O endereço não pode ser vazio");
    return;
  }
  
  if ($('#idGDC').val()=="") {
    $("#"+cResult).html("O nome da cidade não pode ser vazio");
    return;
  }  
  
  cAddr += ($('#idGDE').val())+","+($('#idGDB').val())+","+($('#idGDC').val())+","+($('#idGDES').val());
    
  geocoder = new GClientGeocoder();
      
  geocoder.getLatLng(
	  cAddr,
	  function (point) {
	    if (!point) {
		  cStr = "Endereço inválido: "+cAddr;
		  $("#"+cResult).html(cStr);
		}
		else {
		  var aDist = new Array(aGlobalIgrInfo.length);
		  meuend = new GLatLng(point.lat(), point.lng());
		  for (var i=0;i<aGlobalIgrInfo.length;i++) {
		    var nDist = meuend.distanceFrom(new GLatLng(aGlobalIgrInfo[i][9], aGlobalIgrInfo[i][10]));
			aDist[i] = new Array(nDist/1000, i);			
			cStr += "<p>"+aGlobalIgrInfo[i][0]+"("+aGlobalIgrInfo[i][9]+","+aGlobalIgrInfo[i][10]+")="+nDist+"km</p>";
		  }
		  aDist.sort(sortDist)
		  
		  cStr = "";
		  var nMax = aGlobalIgrInfo.length;
		  if (nMax>5) nMax = 5;
		  for (var i=0;i<nMax;i++) {
		    if (i==1) cStr += "<p style='font-weight:bold;margin:0px 0px 5px 0px;'>Outros resultados (em ordem de distância)</p>";
			if (i==0) {
		      cStr += "<p style='margin:0px;font-weight:bold;'><a href='igrejas.php?igr="+aGlobalIgrInfo[aDist[i][1]][11]+"'>"+aGlobalIgrInfo[aDist[i][1]][0]+": "+sprintf("%.2f",aDist[i][0])+"km</a></p>";
			  cStr += "<p style='margin:0px 0px 0px 10px'>"+aGlobalIgrInfo[aDist[i][1]][1]+"</p>";
			  cStr += "<p style='margin:0px 0px 0px 10px'>"+aGlobalIgrInfo[aDist[i][1]][2]+"</p>";
			  cStr += "<p style='margin:0px 0px 0px 10px'>"+aGlobalIgrInfo[aDist[i][1]][3]+"</p>";
			  cStr += "<p style='margin:0px 0px 5px 10px'>"+aGlobalIgrInfo[aDist[i][1]][4]+"</p>";
			}
			else {
			  cStr += "<p style='margin:0px 0px 2px 10px'><a href='igrejas.php?igr="+aGlobalIgrInfo[aDist[i][1]][11]+"'>"+aGlobalIgrInfo[aDist[i][1]][0]+": <span style='font-weight:bold'>"+sprintf("%.2f",aDist[i][0])+"km</span></a></p>";
			}
		  }
		  
		  $("#"+cResult).html(cStr);		  
		}
	  }
	);
 


}


function holyGetDistance(cParent) {
  var cContent = "";
  var cAux = '';
  cContent += '<table border=0 style="width:550px;font-family:helvetica;font-size:10pt">';
  cContent += '<tr style="height:35px"><td style="font-weight:bold;width:80px;">Endereço</td><td colspan=2><input id="idGDE" type="TEXT" style="width:240px" value=""></td></tr>';
  cContent += '<tr style="height:35px"><td style="font-weight:bold">Bairro</td><td colspan=2><input id="idGDB" type="TEXT"></td></tr>';
  
  cContent += '<tr style="height:35px">';
  cContent += '<td style="font-weight:bold">Cidade</td>';
  cContent += '<td><input id="idGDC" type="TEXT" value=""></td>';
  cAux = 'holyGetDistanceResult("idGetDistanceResult");';
  cContent += "<td style='width:80px'><div class='cGreenButton' onclick='"+cAux+"'>Pesquisar</div></td>";  
  cContent += '</tr>';
  
  cContent += '<tr style="height:35px">';
  cContent += '<td style="font-weight:bold">Estado</td>';
  cContent += '<td><input id="idGDES" type="TEXT"></td>';
  cAux = 'jsRemoveWindow("idGetDistance");';
  cContent += "<td style='width:80px'><div class='cGreenButton' onclick='"+cAux+"'>Fechar</div></td>";    
  cContent += '</tr>';
  
  cContent += '</table>'; 
  cContent += '<p style="font-weight:bold;margin:0px 10px 0px 0px;">Resultado</p>'; 
  cContent += '<div id="idGetDistanceResult" style="padding:5px;overflow:auto;width:540px;height:200px;font-family:helvetica;font-size:10pt;background-color:rgb(200,255,200);border:green 1px black;"></div>';
  cContent += '<p style="font-size:8pt;margin:2px;">This product includes GeoLite data created by MaxMind, available from http://maxmind.com/</p>';

    
	  
  var nX = $("#"+cParent).position().left;
  var nY = $("#"+cParent).position().top;
	  
  jsCreateWindow('idGetDistance', 'pics/greenwin', new Array(16, 16, 26, 26, 20, 20), 'Forneça seu endereço para encontrarmos a igreja mais próxima', nX+10, nY+10, 600, 460, 1000, cContent);
  $("#idGDE").focus();	  
}


$(window).unload(function() {
  GUnload();
});