
   var isBusy = false;
   
   function handleLogin(login, passwd) {
   			document.getElementById('loginErr').innerHTML= "Aguarde um momento...";
   			var pURL = "action.php?_act=" + encodeBase64('0') + "&login=" + login + "&passwd=" + passwd;
				getXMLHttpRequest(pURL,loadID);
  }

  // function to handle asynchronous call
  function loadID() {
       if (xmlhttp.readyState==4) {
              if (xmlhttp.status==200) {
              		if (xmlhttp.responseText == 1) {
              			window.location = "site.php?_pid="+encodeBase64('4');
              		} else {
                     	document.getElementById('loginErr').innerHTML= "As suas credenciais est&atilde;o incorrectas";
                    }
              }
       }
  }

    
     
     function getXMLHttpRequest(pURL, pHandler) {
          //create the Cross-browser XMLHttpRequest object
          if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
                 xmlhttp=new XMLHttpRequest();
                if (xmlhttp.overrideMimeType) {
                       xmlhttp.overrideMimeType('text/xml');
                }      
                xmlhttp.onreadystatechange=pHandler;
                if (isBusy)
                {
                     xmlhttp.abort();
                }
                xmlhttp.open("GET", pURL, true);
                isBusy = true;
                xmlhttp.onreadystatechange = pHandler;
                xmlhttp.send(null);
         } else if (window.ActiveXObject) { //IE
                xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
                if (xmlhttp) {
                       xmlhttp.onreadystatechange=pHandler;
                       xmlhttp.open('GET', pURL, false);
                       xmlhttp.send();
                }
         }
    }
  
     
     function loadXMLString(dname)
     {
          var xmlDoc;
          // code for IE
          if (window.ActiveXObject)
          {
              xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
              xmlDoc.async=false;
              xmlDoc.loadXML(dname);
          }
          // code for Mozilla, Firefox, Opera, etc.
          else if (document.implementation && document.implementation.createDocument)
          {
               parser=new DOMParser();
               xmlDoc=parser.parseFromString(dname,"text/xml");
          }
          else
          {
              alert('Your browser cannot handle this script');
          }
         
          return(xmlDoc);
     }