try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}

var ajax =
{
    listarCidades : function ()
    {

            idRetorno = 'cidade';
            
            estado = basico.retornaValorSelect('estado');
            
            url = 'include/request.php?acao=procurar_cidades&id=' + estado;

            param = null;

            xmlhttp.open('GET', url , true);

            xmlhttp.onreadystatechange = function()
            {
                                       if  (xmlhttp.readyState == 1)
                                       {
                                          basico.$doc(idRetorno).innerHTML = '<option>Carregando...</option>';
                                       }


                                       if (xmlhttp.readyState == 4)
                                       {
                                          /*
                                          if(xmlhttp.status == 200) {
                                          */
                                             resposta = xmlhttp.responseText;

                                             basico.$doc(idRetorno).innerHTML = '<option>--Selecione--</option>' + resposta;
                                          //}

                                       }
            }

            xmlhttp.send(param);
    } ,
    
    confirmarCompra : function (form )
    {

                    param = this.camposForm(form);

                    url = 'include/request.php?acao=confirmar_compra';

                    xmlhttp.open('POST', url , true);

                    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

                    xmlhttp.onreadystatechange = function()
                    {
                                               if  (xmlhttp.readyState == 1)
                                               {
                                                   /*script.$doc('mensagem_final').innerHTML = '<img src="images/ajax.gif>&nbsp;Enviando.Aguarde...';*/
                                               }

                                               if (xmlhttp.readyState == 4)
                                               {
                                                  if (xmlhttp.status == 200)
                                                  {
                                                     resposta = xmlhttp.responseText;

                                                     alert ( resposta );
                                                     /*form.reset();*/

                                                  }
                                               }
                    }
                    xmlhttp.send(param);
    } ,
    camposForm : function(oForm){
		var aParams = new Array();
		for (var i=0 ; i < oForm.length; i++) {
			var sParam = oForm[i].id;

            if ( oForm[i].type == 'checkbox')
            {
               if ( oForm[i].checked)
               {
                  sParam += "=";
			      sParam += oForm[i].value;
			      aParams.push(sParam);
               }
            }
            else
            {
			    sParam += "=";
			    sParam += oForm[i].value;
			    aParams.push(sParam);
			}
		}
		return aParams.join("&");
	}
}


