// JavaScript Document

function createRequestObject() {
   var req;
   if(window.XMLHttpRequest){
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      // There is an error creating the object,
      // just as an old browser is being used.
      alert('Problem creating the XMLHttpRequest object');
   }
   return req;

}

function handleDivTag(divtag)
{
   var divtag;
   return divtag;
}

// Make the XMLHttpRequest object
var http = createRequestObject();


// Create the Divtag Handler -- Mainly an IE 6 Fix
var divhandler = new handleDivTag(null);

function sendRequest(act, divtag) {
	// Open PHP script for requests
	http.open('get', act);
	http.onreadystatechange = handleResponse;
	divhandler.divtag = divtag;
	// Send request
	http.send(null);
}

function sendRequestPost(act, divtag) {
	// Open PHP script for requests
	http.open('post', act);
	http.onreadystatechange = handleResponse;
	divhandler.divtag = divtag;
	// Send request
	http.send(null);
}

function sendRequestGet(act, divtag) {
   // Open PHP script for requests
   http.open('get', act);
   http.onreadystatechange = handleResponse;
   divhandler.divtag = divtag;
   http.send(null);

}

function changeInputValue(act, inputId) {
	// Open PHP script for requests
	http.open('post', act);
	http.onreadystatechange = handleResponseValue;
	divhandler.inputId = inputId;
	// Send request
	http.send(null);
}

function handleResponse() {

   if (http.readyState == 1) {
	
	   // Loading
	   document.getElementById(divhandler.divtag).innerHTML = "<img src=\"loading.gif\" />";
   
   }else if(http.readyState == 4 && http.status == 200){
   
      // Text returned FROM the PHP script
      var response = http.responseText;
	 /* Comentar este if, para o caso de nao existir resposta(nula), de modo a nao ficar o loader activo */
     //  if (response) {
			 // UPDATE ajaxTest content
			 document.getElementById(divhandler.divtag).innerHTML = response;
     //  }

   }

}

function handleResponseValue() {

	if(http.readyState == 4 && http.status == 200){
   
    // Text returned FROM the PHP script
    	var response = http.responseText;
		/* Comentar este if, para o caso de nao existir resposta(nula), de modo a nao ficar o loader activo */
     
		if (response) {
			// UPDATE ajax input value
			document.getElementById(divhandler.inputId).value = response;
		}

   	}

}