	var time = null;			  
	var TEMPO_PADRAO = 100;
	var ultimabusca = '';
	var cont = 0;
	
	function AjaxRequest() {
	     Ajax = false;
	     if (window.XMLHttpRequest) { // Mozilla, Safari,...
	         Ajax = new XMLHttpRequest();
	     } else if (window.ActiveXObject) { // IE
	         try {
	             Ajax = new ActiveXObject("Msxml2.XMLHTTP");
	         } catch (e) {
	             try {
	                 Ajax = new ActiveXObject("Microsoft.XMLHTTP");
	             } catch (e) {}
	         }
	     }		
	} 
		
	function getPosition(element){
		  var elem=element,tagname="",x=0,y=0;
		  while ((typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined"))
		  {
		    y+=elem.offsetTop;    
		    x+=elem.offsetLeft;  
		    tagname=elem.tagName.toUpperCase();
		    if (tagname=="BODY")
		      elem=0;
		    if (typeof(elem)=="object")
		      if (typeof(elem.offsetParent)=="object")
		        elem=elem.offsetParent;
		  }
		  position=new Object();
		  position.x=x;
		  position.y=y;
		  return position;
		}
	
	
	function mostratexto(vo) {
	document.getElementById("divlista").style.display="none";
		if (vo.replace(" ","")!='' && vo.length!=0){
			var agora = new Date();
			if(time==null) { time = agora; }
			var dif = (agora-time);
			cont = 0;
			monitoraTempo();
			//selecionarProdutos(vo);
			time=agora;
		}
	}			
			  
	function monitoraTempo() {
		if(time!=null&&document.getElementById("Dominio").value!=ultimabusca) {
			var agora = new Date();
			var dif = (agora-time);
			if(dif>=TEMPO_PADRAO) {
				// Processar a requisição
				selecionarProdutos();
				time=agora; // para não chamar novamente
				cont = 99;				
				//ultimabusca = document.getElementById("Dominio").value;
			} 
		} 
		cont++;
		if(cont==1) {	
			setTimeout('monitoraTempo()',TEMPO_PADRAO);
		} else {
			cont = 0;
		}
	}	
	
	function selecionarProdutos() {
		AjaxRequest();
		Ajax.onreadystatechange = mostraValores;
  		Ajax.open('GET', 'php/lista_mais.php?descricao='+document.getElementById("Dominio").value, true);
  		Ajax.send(null);
	}
	
	function mostraValores(){
		var resultado="";
		var resdom="";
		var domhtml="";
		ultimabusca = document.getElementById("Dominio").value;
		var _dom= document.getElementById("domlista");
		if (Ajax.readyState == 4) {
          if (Ajax.status == 200) {          	
				var doc 		= Ajax.responseText;
				var resultado= doc.split(",");
				for (var i=0;i<resultado.length; i++){
					if (resultado[i]!=''){
						resdom=resultado[i].split("#");
						domhtml += "<a class=\"maispesquisados\" href=\"#\" onClick=\"escolhapalavra('"+resdom[0]+"','"+resdom[1]+"')\">"+resdom[0]+"."+resdom[1]+"</a><br>";
					}
				}
			}
		}
		if (resultado.length>1){
			_dom.innerHTML=domhtml;
			document.getElementById("divlista").style.display=""
		}
	}	
	
	function escolhapalavra(e,d){
		if (e!=''){
			document.getElementById("Dominio").value=e;
			var radioObj=document.forms['formulario'].elements['TLD'];
 			if (d=='co.pt')
 				radioObj[0].checked=true;
 			if (d=='lda.pt')
 				radioObj[1].checked=true;
		}
		//document.getElementById("divlista").style.display="none";
		document.formulario.submit();
	}
	
	function fecharobj(obj){
		document.getElementById(obj).style.display="none";
	}
	
	function fechar(obj){
		 setTimeout("fecharobj('"+obj+"')",500);
	}
		
	
	// PESQUISA
	function pesquisar(){
			if (document.getElementById("Dominio").value.length>1)
				document.getElementById("formulario").submit();
		}
		
  function avisopesquisar(txt,txt2){
			if (document.getElementById("Dominio").value.length<1)
				ddrivetip(txt, 300);
			if (document.getElementById("Dominio").value.length==1)
				ddrivetip(txt2, 300);
		} 
	
	function recuperar(n){
		if (n=='login'){
			document.getElementById("recuperardominio").style.display="none";
			document.getElementById("logindominio").style.display="";
		}else{
			document.getElementById("logindominio").style.display="none";
			document.getElementById("recuperardominio").style.display="";
		}
	}

	// Login registo
	function loginreg(){
		if (document.formlogin.regdominio.value.length>1 && document.formlogin.regemail.value.length>1 && 		document.formlogin.regpassw.value.length>1)
			document.formlogin.submit();
		} 

	//recuperar password
	function loginrec(mess){
		if (document.formrecuperar.recdominio.value.length>1 && document.formrecuperar.recemail.value.length>1)
			document.formrecuperar.submit();
	}
	
	/***********************************************
		* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
		* This notice MUST stay intact for legal use
		* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
		***********************************************/
		
		var offsetfromcursorX=12 //Customize x offset of tooltip
		var offsetfromcursorY=10 //Customize y offset of tooltip
		
		var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
		var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).
		
		document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
		//document.write('<img id="dhtmlpointer" src="img/arrow2.gif">') //write out pointer image
		document.write('<img id="dhtmlpointer" src="img/espaco.gif">') //write out pointer image
		
		var ie=document.all
		var ns6=document.getElementById && !document.all
		var enabletip=false
		if (ie||ns6)
		var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
		
		var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""
		
		function ietruebody(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
		}
		
		function ddrivetip(thetext, thewidth, thecolor){
		if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
		}
		}
		
		function positiontip(e){
		if (enabletip){
		var nondefaultpos=false
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20
		
		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
		
		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000
		
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth){
		//move the horizontal position of the menu to the left by it's width
		tipobj.style.left=curX-tipobj.offsetWidth+"px"
		nondefaultpos=true
		}
		else if (curX<leftedge)
		tipobj.style.left="5px"
		else{
		//position the horizontal position of the menu where the mouse is positioned
		tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
		pointerobj.style.left=curX+offsetfromcursorX+"px"
		}
		
		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight){
		tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
		nondefaultpos=true
		}
		else{
		tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
		pointerobj.style.top=curY+offsetfromcursorY+"px"
		}
		tipobj.style.visibility="visible"
		if (!nondefaultpos)
		pointerobj.style.visibility="visible"
		else
		pointerobj.style.visibility="hidden"
		}
		}
		
		function hideddrivetip(){
		if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden"
		pointerobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
		}
		}
		
		document.onmousemove=positiontip
