var oDecrypt = new ObjDecrypt("oDecrypt");

function help(param)
{if (param=="init")
 {oDecrypt.mensagem("Digite parte do nome do logradouro em PROCURAR POR e clique em LOCALIZAR");}
 if (param=="search")
 {oDecrypt.mensagem("Clique sobre o nome do logradouro para maiores informações");
  oDecrypt.mensagem("Digite parte do nome do logradouro em PROCURAR POR e clique em LOCALIZAR para uma nova consulta");
 }
 if (param=="detail")
 {oDecrypt.mensagem("Para visualizar o logradouro no mapa selecione um QUARTEIRAO e clique em VISUALIZAR O MAPA");
  oDecrypt.mensagem("Para realizar uma nova consulta clique VOLTAR");
 }
 if (param=="map")
 {oDecrypt.mensagem("Para ver o mapa superior clique CIMA");
  oDecrypt.mensagem("Para ver o mapa inferior clique BAIXO");
  oDecrypt.mensagem("Para ver o mapa anterior clique ESQUERDA");
  oDecrypt.mensagem("Para ver o mapa posterior clique DIREITA");
  oDecrypt.mensagem("Para realizar uma nova consulta clique NOVA PESQUISA");
 }
 oDecrypt.iniciar();
}

function Ponteiro(x,y,x1,y1,x2,y2,Calibragem)
{var obj, h, w, l, t, st;
 if (!x)
 {l=0;
  t=0;
  st="hidden";
 }
 else
 {obj=MM_findObj("img_mapa");
  h=parseInt(obj.style.height)-1;
  w=parseInt(obj.style.width)-1;
  if (obj.tagName!="IMG") obj=obj.getElementsByTagName('img')[0];
  l=getPositionLeft(obj);
  t=getPositionTop(obj);
  lw=(l + w);
  th=(t + h);
  if (Calibragem)
  {ld=Math.round(w*0-40);
   td=Math.round(h*0-40);}
  else
  {ld=Math.round(w*(x-x1)/(x2-x1)-40);
   td=Math.round(h*(y2-y)/(y2-y1)-40);}
  st="visible";
 }
 clipTop=0;
 clipBottom=81;
 clipLeft=0;
 clipRight=81;
 if (td < 0) {clipTop=(td*-1);}
 if ((t+td+81) > th) {clipBottom=81-(t+td+80-th);}
 if (ld < 0) {clipLeft=(ld*-1);}
 if ((l+ld+81) > lw) {clipRight=81-(l+ld+80-lw);}

 if ((clipTop > 81) || (clipLeft > 81) || (clipBottom < 0) || (clipRight < 0))
 {clipTop=0;
  clipBottom=81;
  clipLeft=0;
  clipRight=81;
  l=0;
  t=0;
  st="hidden";
 }

 obj=MM_findObj("idaponta");
 if (obj.style) {obj=obj.style;}
 obj.clip="rect("+ clipTop + " " + clipRight + " " + clipBottom + " " +  clipLeft + ")"; 
 obj.top=(t + td) + "px";
 obj.left=(l + ld) + "px";
 obj.visibility=st;
}

function Hidrante(x,y,x1,y1,x2,y2,Calibragem,Objeto)
{var obj, h, w, l, t, st;
 if (!x)
 {l=0;
  t=0;
  st="hidden";
 }
 else
 {obj=MM_findObj("img_mapa");
  h=parseInt(obj.style.height)-1;
  w=parseInt(obj.style.width)-1;
  if (obj.tagName!="IMG") obj=obj.getElementsByTagName('img')[0];
  l=getPositionLeft(obj);
  t=getPositionTop(obj);
  lw=(l + w);
  th=(t + h);
  if (Calibragem)
  {ld=Math.round(w*0-9);
   td=Math.round(h*0-20);}
  else
  {ld=Math.round(w*(x-x1)/(x2-x1)-9);
   td=Math.round(h*(y2-y)/(y2-y1)-20);}
   st="visible";
 }
 clipTop=0;
 clipBottom=29;
 clipLeft=0;
 clipRight=40;
 if (td < 0) {clipTop=(td*-1);}
 if ((t+td+29) > th) {clipBottom=29-(t+td+28-th);}
 if (ld < 0) {clipLeft=(ld*-1);}
 if ((l+ld+40) > lw) {clipRight=40-(l+ld+39-lw);}

 if ((clipTop > 29) || (clipLeft > 40) || (clipBottom < 0) || (clipRight < 0))
 {clipTop=0;
  clipBottom=29;
  clipLeft=0;
  clipRight=40;
  l=0;
  t=0;
  st="hidden";
 }

 obj=MM_findObj(Objeto);
 if (obj.style) {obj=obj.style;}
 obj.clip="rect("+ clipTop + " " + clipRight + " " + clipBottom + " " +  clipLeft + ")"; 
 obj.top=(t + td) + "px";
 obj.left=(l + ld) + "px";
// obj.top=(t) + "px";
// obj.left=(l) + "px";
 obj.visibility=st;
}

function detail(param)
{document.search.eixo.value=param;
 document.search.submit();
}

function move(param)
{document.map.mapa.value=param;
 document.map.submit();
}

function ObjDecrypt(id, data, delay)
{
	this.turn = 0;
	this.id = id;
	this.data = data ? data : "|| | ||| |";
	this.delay = delay ? delay : 3000;
	this.done = 1;
	this.msglist = new Array;
	this.msgix = -1;
	this.timer = null;
	this.mensagem = function(m) {
		this.msglist[this.msglist.length] = m;
	}
	this.iniciar = function() {
		if(this.msglist.length > 0) {
			this.msgix++;
			if(this.msgix >= this.msglist.length) this.msgix = 0;
			this.scheduler();
		}
		else
			window.status = 'Nenhuma mensagem definida!';
		return true;
	}
	this.scheduler = function() {
		window.setTimeout(this.id + ".decrypt('" + this.msglist[this.msgix] + "',2,3)", this.delay);
	}
	this.decrypt = function(text, max, delay) {
		if(!this.turn) {
			window.status=text;
			this.done=1;
			this.iniciar();
		}
		else {
			if(this.done) {
			    this.done = 0;
    			this.decrypt_helper(text, max, delay, 0, max);
			}
		}
	}
	this.decrypt_helper = function(text, runs_left, delay, charvar, max) {
		if(!this.done) {
			runs_left = runs_left - 1;
			var status = text.substring(0,charvar);
			for(var current_char = charvar; current_char < text.length; current_char++)
				status += this.data.charAt(Math.round(Math.random()*this.data.length));
			window.status = status;
			var rerun = this.id + ".decrypt_helper('" + text + "'," + runs_left + "," + delay + "," + charvar + "," + max + ");"
			var new_char = charvar + 1;
			var next_char = this.id + ".decrypt_helper('" + text + "'," + max + "," + delay + "," + new_char + "," + max + ");"
			if(runs_left > 0)
				window.setTimeout(rerun, delay);
			else {
				if (charvar < text.length)
					window.setTimeout(next_char, Math.round(delay*(charvar+3)/(charvar+1)));
				else {
					this.done = 1;
					this.iniciar();
				}
			}
		}
	}
	return this;
}

function MM_findObj(n, d) 
{ //v4.0
 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 && document.getElementById) x=document.getElementById(n);
 return x;
}

function getPositionLeft(This){
 var el = This;var pL = 0;
 while(el){pL+=el.offsetLeft;el=el.offsetParent;}
 return pL
}

function getPositionTop(This){
 var el = This;var pT = 0;
 while(el){pT+=el.offsetTop;el=el.offsetParent;}
 return pT
}