var req;


function loadXMLDoc(url,valor)
{
	req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url+'?uf='+valor, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url+'?uf='+valor, true);
            req.send();
        }
    }
}


function processReqChange()
{
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
           
			document.getElementById('atualizar').innerHTML = req.responseText;
			
        } else {
            alert("Houve um problema ao obter os dados1:\n" + req.statusText);
        }
    }
}




function ajaxRD(valor)
{
	document.getElementById('atualizar').innerHTML = '<div align="center" style="margin-top:100px;"><img src="images/loading.gif"></div>';
	loadXMLDoc("atualizar.php",valor);
}


function loadXMLDoc2(url,valor)
{
	req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange2;
        req.open("GET", url+'?email='+valor, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange2;
            req.open("GET", url+'?email='+valor, true);
            req.send();
        }
    }
}


function processReqChange2()
{
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
           
		   document.getElementById('botao').innerHTML = '<input type="image" style="margin-top:5px;" src="imagens/bt-voltar2.jpg" onclick="javascript:newsletter(0)" width="80" height="22" border="0"/>';
			document.getElementById('atualizar2').innerHTML = req.responseText;
			
        } else {
            alert("Houve um problema ao obter os dados1:\n" + req.statusText);
        }
    }
}




function newsletter(valor)
{
	if(valor == 1)
	{
		valor = document.getElementById("email").value;
		document.getElementById('atualizar2').innerHTML = '<div align="center"><img src="images/loading.gif"></div>';
		loadXMLDoc2("xtNewsletter.php",valor);
	}
	else
	{
		document.getElementById('atualizar2').innerHTML = '   <table width="215" height="20" border="0" cellpadding="0" cellspacing="0">                           <tr>                             <td align="left" valign="middle">E-mail:</td>                             <td align="left" valign="top"><span style="padding:5px 0px; border-bottom:1px solid #CCCCCC;">                               <input type="text" name="email" id="email"  style="width:157px; height:14px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #333333; background-image:url(imagens/bg-form.jpg);"/>                             </span></td>                           </tr>                       </table>';	
		document.getElementById('botao').innerHTML = '<input type="image" style="margin-top:5px;" src="imagens/bt-cadastrar.jpg" onclick="javascript:newsletter(1)" width="80" height="22" border="0"/>';
	}
}


function loadXMLDoc3(url,valor, valor2)
{
	req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange3;
        req.open("GET", url+'?idItem='+valor+'&qtd='+valor2, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange3;
            req.open("GET", url+'?idItem='+valor+'&qtd='+valor2, true);
            req.send();
        }
    }
}


function processReqChange3()
{
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
           
			window.top.hidePopWin()
			//document.getElementById('atualizar').innerHTML = req.responseText;
			//alert(req.responseText);
			
        } else {
            alert("Houve um problema ao obter os dados1:\n" + req.statusText);
        }
    }
}




function atualizar3(valor, valor2)
{
	showPopWin('aguarde.html', 32, 32, null, false);
	loadXMLDoc3("atualizar3.php",valor, valor2);
}