function ajaxInit(){
	var req;
	try {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
  		try {
    		req = new ActiveXObject("Msxml2.XMLHTTP");
  		} catch(ex) {
    		try {
      			req = new XMLHttpRequest();
    		} catch(exc) {
      			alert("Esse browser não tem recursos para uso do Ajax");
      			req = null;
    		}
  		}
	}
	return req;
}

function AjaxPost(url,posData) {
	ajax = ajaxInit();
	ajax.onreadystatechange = procesResp;
	ajax.open("POST", url, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(posData);
}

function procesResp() {
  document.getElementById('contents').innerHTML="<h1>Searching...</h1>";
  if (ajax.readyState == 4) {
    if (ajax.status == 200) {
      document.getElementById('contents').innerHTML=ajax.responseText;
    } else {
         alert("Erro: "+ajax.responseText);
    }
  }
}

function criaSTR(){
   var frm=document.searchfrm.elements;
   var indCampo=0;
   var strPost="";
   var tipoCampo;
   while(frm[indCampo]){
      tipoCampo=frm[indCampo].type;
      checkado=frm[indCampo].checked;
      if(tipoCampo!="reset" && tipoCampo!="submit" && tipoCampo!="button"){
         if(tipoCampo!="radio")
            strPost=strPost+frm[indCampo].name+"="+frm[indCampo].value+"&";
         else
            if(checkado)
               strPost=strPost+frm[indCampo].name+"="+frm[indCampo].value+"&";
      }
      indCampo++;
   }
   return strPost+"null";
}

function busca(){
   strPost=criaSTR();
   AjaxPost("ledir.php",strPost);
}

function carrega(url,alvo){
   	ajax = ajaxInit();
	ajax.onreadystatechange = function(){
		document.getElementById(alvo).innerHTML="<h1>Loading...</h1>";
		if (ajax.readyState == 4) {
			if (ajax.status == 200) {
				document.getElementById('contents').innerHTML=ajax.responseText;
			} else {
				alert("Error: "+ajax.responseText);
			}
		}
	}
	ajax.open("GET", url, true);
	ajax.send(null);
}