//*** O código abaixo foi desenvolvido  sobre direitos **************
// autor: kbaweb            *****************************************
// Modificado:  10/06/2006   ****************************************
// kbaWeb - Comunicação e Marketing - Todos os direitos reservados


try
{
		
	var nav_isIE = false;
	var activecombo;
	var req;
	var inicio=true;
	var activecontrole ; // controle que será alimentado pela pesquisa
	var searchstatus ; // controle que será alimentado pela pesquisa
	
	var xmlhttp=false;
		if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
		// branch for IE/Windows ActiveX version
		} else{
		nav_isIE = true;
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	
	var processarGeral= function(url,path){
		 if(xmlhttp.readyState != 2 && xmlhttp.readyState != 3) {
			xmlhttp.open('POST',path ,false);
			xmlhttp.setRequestHeader('Method',"POST" +  "HTTP/1.1");
			xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			xmlhttp.send(url);
		 }
	}
	
	function thisexist(val) {
		 processarGeral("action=thisexist&" + val,"../tools/ajax/JSXprocessar.php");
			 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					 var thevalue = urldecode(xmlhttp.responseText)
					 return thevalue; 
			  }  
	}
	
	
	function urldecode(texto){
		//Desfaz o urlencode
		texto=texto.replace(/\+/g," ");
		texto=unescape(texto);
		return texto;
	}
	function trim( text ) {
	   if(text==null) return null;
	   return text.replace(/^[ \t]+|[ \t]+$/g, "");
	}
	
	//*** aqui as functions para o  box search **************
	//***  script para agilizar a  pesquiza nos combos 
	//*** autor: kbaweb
	function formsearch(cp,table){
		contents="<img src='../images/img/search.gif'  id='imgopen' onclick=\"showboxsearch('"  + cp  +  "')\">";
		contents+="<div id='boxsearch' style='position:absolute;display:none'><input name='pes' type=text OnKeyUp=\"get_divsearch(this.value,'" +  table + "')\" size='15' maxlength='30'> <div class='boxsearch'   align='left' id='divsearchresults'> </div>  </div>";
		document.write(contents);
		return true;
	}
	
	function get_divsearch(val,Fp) {
	processarGeral("action=get_divsearch&compare=" + val  +"&Fp=" + Fp ,"../tools/ajax/JSXprocessar.php");
		  if (xmlhttp.readyState == 4 || xmlhttp.status == 200) {
				 var rcvdBox = document.getElementById("divsearchresults");
				 rcvdBox.innerHTML =  urldecode(xmlhttp.responseText) 
		  }
	}

	function put_in_control(optionValue,optionText) {
		var selectObject=document.getElementById(activecontrole);	
		var optionObject = new Option(optionText,optionValue)
		var optionRank = selectObject.options.length
		selectObject.options[optionRank]=optionObject
		selectObject.options[optionRank].selected = true
		hideboxsearch();
		try{
			document.forms[0].submit();
		}catch(e){}
	}
	function hideboxsearch(){
		document.getElementById('boxsearch').style.display='none';
	}
	function showboxsearch(qcontrol){
		activecontrole=qcontrol;
		if(searchstatus==1){ hideboxsearch();searchstatus=0;return true};
		var imgp=document.getElementById('imgopen');
		var dvs=document.getElementById('boxsearch');
		dvs.style.display='block';
		searchstatus=1;
	}

}catch(e){}
