//Função para criar um Objeto XMLHttp.
function getxmlhttp () {
	// Criar uma variável booleana para verificar a existência de uma instância
	//  Microsoft active x válida.
	var xmlhttp = false;

	//Verificar se estamos usando IE.
	try {
		// Se a versão JavaScript for maior que 5.
		xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP");
	} catch (e) {
		// Se não, então usar o objeto active x mais antigo.
		try {
			    // Se estivermos usando IE.
				xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
		} catch (E) {
				// Ou devemos estar usando um navegador diferente do IE.
				xmlhttp = false;
		}
	}
	// Se estivermos usando um navegador diferente do IE, criar uma 
	//instância JavaScript do Objeto.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	  xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function processajax (mth,page,defID,str) {
  	  // Achar um objeto XMLRttpRequest para uso.
	  xmlhttp = getxmlhttp ();
      var obj = document.getElementById(defID); 
	  if (mth =="GET") { 
  	     xmlhttp.open (mth, page);
  	     xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1");
  	     xmlhttp.onreadystatechange = function () {
	        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		      obj.innerHTML = xmlhttp.responseText;
		    } 
	     }
	     xmlhttp.send(null);	  	  
	  }else {
 		 xmlhttp.open(mth, page, true);
		 xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1");
		 xmlhttp.onreadystatechange = function () {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		 }
		 xmlhttp.send(str);
	  }
}

//Funções para enviar um formulário
function getformvalues (fobj) {
	var str = "";
	aok = true;
	var val;

	//Executa uma lista de todos os objetos contidos dentro do formulário.
	for (var i = 0; i < fobj.elements.length; i++) {
		if (fobj.elements[i].type == "checkbox") {
			if (fobj.elements[i].checked) {
 		       str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
			}
		}else {
            if (fobj.elements[i].type == "radio") {
               if (fobj.elements[i].checked) {
                  str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
               }
            } else {
                str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
			}
		}
	}
	// Em seguida retornar os valores da string;
	return str;
}

