	function AjaxAbrePagina(url, id, method, form, fc, sqlType, action, actionId)
	{
		time = new Date();	
		var segundo = time.getSeconds();			
		var minuto = time.getMinutes();
		
		if(url.split("?").length<=1)
			url = url + '?timex=' + minuto + '' + segundo
		else
			url = url + '&timex=' + minuto + '' + segundo
		
		var id       = id       || "";
		var method   = method   || "GET";	
		var form     = form     || 0;	
		var fc       = fc       || "";
		var sqlType  = sqlType  || "";
		var action   = action   || "";
		var actionId = actionId || "";
		
		var scriptJS = "";
		
		

		if (sqlType == "INSERT" || sqlType == "UPDATE")
		{
			//UPLOAD
			if (up["F"]) 
				return alert('Upload em processo...');

			var fields = existeTipoCampo(form, 'file');
		
			if (up["Q"]==0 && fields.length)
			{	
				fileErro=false;
				for(i=0;i<fields.length;i++)
				{
					if(fields[i].value=='')
						fileErro=true;
				}	
				if(!fileErro)			
				{
					uploadFile(form, fields);
					up["S"] = "AjaxAbrePagina(\"" + url + "\", \"" + id + "\", \"" + method + "\", \"" + form + "\", \"" + fc + "\", \"" + sqlType + "\", \"" + action + "\", \"" + actionId + "\")";
					return false;
				}
				
			}
		}
		
		if (sqlType)
		{
			if (sqlType == "DELETE")
			{
				if (!confirm("Deseja excluir registro?")) return;
			}	
			
			url += (url.indexOf("?") >= 0 ? "&" : "?") + "tpSql=" + sqlType;
		}

		var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
		
		req.onreadystatechange = function()
		{
			if (req.readyState == 4) {
				try
				{
					document.getElementById("divCarregando").style.display="none";
					
					
				}catch(e){}
				
				if (req.status == 200) {
					var retorno = urlDecode(req.responseText);
					
					if (id)
					{
						document.getElementById(id).innerHTML = retorno;

						scriptJS = document.getElementById(id).getElementsByTagName("script"); 
						for (var i = 0; i < scriptJS.length; i++) { 
							if (scriptJS[i].innerHTML)
								eval(scriptJS[i].innerHTML);
						}						
					}
					
					if(retorno=='exit'){
						document.location.href='index.php'
						return;						
					}

					if (sqlType)
					{					
						sucesso = retorno.charAt(0);
						retorno = retorno.substr(1, retorno.length);
						
						if(sucesso=='exit'){
							alert(1)
						}
						
						if (sucesso == '0' || sucesso== '3')
						{	
								
							if(sucesso=='0')
								alert(retorno);							
							
							if (sucesso == '3')
							{
								var divisao = new Array();
								var divisao = retorno.split("|");
								
								if(divisao[0]!='')
									alert(divisao[0]); //EXECUTA A MENSAGEM
									
								if(divisao[1]!='')
									eval(divisao[1]);  //EXECUTA O JAVASCRIPT									
							}
							
							//habilitaCampoForm(form, true);
						} else {
							if (sucesso == '2')
								alert(retorno);
								
							if (sucesso == '4')
							{
								var divisao = new Array();
								var divisao = retorno.split("|")
								
								if(divisao[0]!='')
									alert(divisao[0]); //EXECUTA A MENSAGEM
									
								if(divisao[1]!='')
									eval(divisao[1]);  //EXECUTA O JAVASCRIPT
								
							}
								
							if (action && actionId)
								AjaxAbrePagina(action, actionId);
						}

						//UPLOAD
						if (sqlType == "INSERT" || sqlType == "UPDATE")
							uploadInit();
					} else {
						//habilitaCampoForm(form, false);
					}
					
					if (fc)
					{
						eval(fc);					
					}
					
				} else {
					alert("Houve um problema ao obter os dados:\n" + req.statusText + "\n" + url);
				}
				
				AjaxTrataPagina(url);
			} else {
				
				try
				{
					document.getElementById("divCarregando").style.display ="";
				}catch(e){}
			}		
		}
		
		switch (method)
		{
			case "GET" :
					req.open("GET", url, true);
					req.send(null);			
				break;
				
			case "POST" : 
					var parametros = pegaValoresForm(form);
	
				    req.open("POST", url, true);
					req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
				    req.send(parametros);	
				break;		    	
		}			
	}
	
	function AjaxTrataPagina(url)
	{
		var urlPagina = url.indexOf("?") >= 0 ? url.substr(0, url.indexOf("?")) : url;
		
		//Ativando div principal		
		
		if(document.getElementById("DIVIndex"))
		{
			document.getElementById("DIVIndex").style.display = "";
		}
		
		if(document.getElementById("DIVIndexMenu2"))
		{
			document.getElementById("DIVIndexMenu2").style.display = "none";
		}
		
		try
		{
			//document.forms[0].elements[0].focus();
		}catch(e){ }
	}
