function getXmlHttpRequest()
 {    
 if(window.XMLHttpRequest)
  return new XMLHttpRequest();
 else
  if(window.ActiveXObject)
   return new ActiveXObject("Microsoft.XMLHTTP");
 }

function openAjax(loaddiv,div,url,param)
 {
 xmlhttp = getXmlHttpRequest();
 xmlhttp.open("POST",url,true);
 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; utf-8");
 
 xmlhttp.onreadystatechange = function()
  {
  if(xmlhttp.readyState == 0)
   {
   document.getElementById(loaddiv).innerHTML = "Falha ao carregar o documento.";
   }
  if(xmlhttp.readyState == 1)
   {
   document.getElementById(loaddiv).innerHTML = "Documento em processo de cria&ccedil;&atilde;o ...<br/>Isso pode demorar alguns segundos.";
   }
  if(xmlhttp.readyState == 2)
   {
   document.getElementById(loaddiv).innerHTML = "Documento em processo de verificação ...";
   }
  if(xmlhttp.readyState == 3)
   {
   document.getElementById(loaddiv).innerHTML = "Organizando o documento ...<br/>Isso pode demorar alguns segundos.";
   }
  if(xmlhttp.readyState == 4)
   {
   document.getElementById(loaddiv).innerHTML = "";
   document.getElementById(div).innerHTML = xmlhttp.responseText;
   }
  }

 xmlhttp.send(param);
 }
 
function openAjaxGet(loaddiv,div,url,param)
 {
 xmlhttp = getXmlHttpRequest();
 xmlhttp.open("GET",url,true);
 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; utf-8");
 
 xmlhttp.onreadystatechange = function()
  {
  if(xmlhttp.readyState == 0)
   {
   document.getElementById(loaddiv).innerHTML = "Falha ao carregar o documento.";
   }
  if(xmlhttp.readyState == 1)
   {
   document.getElementById(loaddiv).innerHTML = "Documento em processo de cria&ccedil;&atilde;o ...<br/>Isso pode demorar alguns segundos.";
   }
  if(xmlhttp.readyState == 2)
   {
   document.getElementById(loaddiv).innerHTML = "Documento em processo de verificação ...";
   }
  if(xmlhttp.readyState == 3)
   {
   document.getElementById(loaddiv).innerHTML = "Organizando o documento ...<br/>Isso pode demorar alguns segundos.";
   }
  if(xmlhttp.readyState == 4)
   {
   document.getElementById(loaddiv).innerHTML = "";
   document.getElementById(div).innerHTML = xmlhttp.responseText;
   }
  }

 xmlhttp.send(param);
 }
 
 
function mudaestado(estado)
{
	openAjaxGet('content','content','estados/'+estado+'/index.html','');
}

function mudaestadoecidade(estado,cidade)
{
	openAjaxGet('content','content','estados/'+estado+'/'+cidade+'index.html','');
}

function abrirpagina(pag)
{
	openAjax('mainContent','mainContent',pag,'');
}
