function GetXmlHttpObject(handler)
{
   var objXMLHttp=null
   if (window.XMLHttpRequest)
   {
       objXMLHttp=new XMLHttpRequest()
   }
   else if (window.ActiveXObject)
   {
       objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
   }
   return objXMLHttp
}

function stateChanged()
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
		   document.getElementById("txtResult").innerHTML= xmlHttp.responseText;
   }
   else {
		   //alert(xmlHttp.status);
   }
	
}

function stateChanged2()
{
   if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
   {
		   document.getElementById("txtInt").innerHTML= xmlHttp.responseText;
   }
   else {
		   //alert(xmlHttp.status);
   }
	
}

// Will populate data based on input
function htmlData(url, qStr)
{
   if (url.length==0)
   {
       document.getElementById("txtResult").innerHTML="";
	   document.getElementById("txtInt").innerHTML="";
       return;
   }
   xmlHttp=GetXmlHttpObject()
   if (xmlHttp==null)
   {
       alert ("Browser does not support HTTP Request");
       return;
   }
   
   temp = url;
   url=url+"?"+qStr;
   url=url+"&sid="+Math.random();
   if (temp == "cidade.php")
		xmlHttp.onreadystatechange=stateChanged;
	else xmlHttp.onreadystatechange=stateChanged2;
   xmlHttp.open("GET",url,true) ;
   xmlHttp.send(null);
}

//pega o total de itens checados no form
function conta() {
var marcados = ' ';

// Aqui voce referencia o objeto form
var chk = document.res;

// Aqui voce varre todos os elementos do form
for(i=0;i<chk.length;i++){

     // Aqui voce checa o nome do elemento e se ele esta checado,
     if(chk.elements[i].name=='operadora[]' && chk.elements[i].checked==true)
        marcados += chk.elements[i].value + " "; // se estiver checado
  }

 //window.alert (marcados);
 //window.opener.document.form1.campo1.value=marcados;

 return marcados; 
} 

// Will populate data based on input
function htmlData2(url, qStr1)
{
   if (url.length==0)
   {
       document.getElementById("txtResult").innerHTML="";
       return;
   }
   xmlHttp=GetXmlHttpObject()
   if (xmlHttp==null)
   {
       alert ("Browser does not support HTTP Request");
       return;
   }

   qStr2 = conta();
   url=url+"?"+qStr1+"&opera="+qStr2;
   url=url+"&sid="+Math.random();
   xmlHttp.onreadystatechange=stateChanged;
   xmlHttp.open("GET",url,true) ;
   xmlHttp.send(null);
}