function createXMLHTTP() 
{
var ajax;

try{
    ajax = new XMLHttpRequest();
	}
catch(ee){
    	  try{
          	  ajax = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE da MS
    		  }
		   catch(e){
           			try{
            			ajax = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE da MS
        				}
					catch(E){
            				 ajax = false;
        					 }
    					}
					}
			return ajax;
}

 
 
 // url_encode version 1.0
 function url_encode(str) 
 {     
	var hex_chars = "0123456789ABCDEF";     
	var noEncode = /^([a-zA-Z0-9\_\-\.])$/;     
	var n, strCode, hex1, hex2, strEncode = "";     
	
	for(n = 0; n < str.length; n++) 
	{         
		if (noEncode.test(str.charAt(n))) 
		{             
			strEncode += str.charAt(n);         
		} 
		else 
		{
			strCode = str.charCodeAt(n);
			hex1 = hex_chars.charAt(Math.floor(strCode / 16));
			hex2 = hex_chars.charAt(strCode % 16);
			strEncode += "%" + (hex1 + hex2);         
		}     
	}     
	
	return strEncode; 
} 

function modNewsletter(nomDiv, endereco)
 {
	 document.getElementById(nomDiv).innerHTML = 'Cadastrando Newsletter...';
     var oHTTPRequest = createXMLHTTP(); 
     oHTTPRequest.open("post", "modNewsletter.asp", true); 
	 oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
     oHTTPRequest.onreadystatechange=function()
  	 {
	  	if (oHTTPRequest.readyState==4)
	 	{
       	   document.getElementById(nomDiv).innerHTML = oHTTPRequest.responseText;
		}
	 }

     oHTTPRequest.send("end=" + endereco);
 }
 
 
 function modContato(nomDiv, nom, tel, email, mens)
 {
	 document.getElementById(nomDiv).innerHTML = 'Enviando mensagem...';
     var oHTTPRequest = createXMLHTTP(); 
     oHTTPRequest.open("post", "modContato.asp", true); 
	 oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");

     oHTTPRequest.onreadystatechange=function()
  	 {
	  	if (oHTTPRequest.readyState==4)
	 	{
       	   document.getElementById(nomDiv).innerHTML = oHTTPRequest.responseText;
		}
	 }

	 mens = url_encode(mens);
	 
     oHTTPRequest.send("nom=" + nom + "&tel=" + tel + "&email=" + email + "&mens=" + mens);
 } 

 
  function modVerificaVendedor(nomDiv, cod)
 {
	 document.getElementById(nomDiv).innerHTML = 'Verificando...';
     var oHTTPRequest = createXMLHTTP(); 
     oHTTPRequest.open("post", "modVerificaVendedor.asp", true); 
	 oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");

     oHTTPRequest.onreadystatechange=function()
  	 {
	  	if (oHTTPRequest.readyState==4)
	 	{
       	   document.getElementById(nomDiv).innerHTML = oHTTPRequest.responseText;
		}
	 }

     oHTTPRequest.send("cod=" + cod);
 } 
 

function modAtualizaPedido(nomDiv, tipAtual, itemPedido, valItem)
 {
 	 document.getElementById(nomDiv).innerHTML = 'Atualizando...';
     var oHTTPRequest = createXMLHTTP(); 
     oHTTPRequest.open("post", "modAtualizaPedido.asp", true); 
	 oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");

     oHTTPRequest.onreadystatechange=function()
  	 {
	  	if (oHTTPRequest.readyState==4)
	 	{
       	   document.getElementById(nomDiv).innerHTML = oHTTPRequest.responseText;
		}
	 }

	 oHTTPRequest.send("tipAtual=" + tipAtual + "&itemPedido=" + itemPedido  + "&valItem=" + valItem);
 } 

 function modAtualizaPedidoTextos(nomDiv, idtPedido, tipo, texto)
 {
 	 document.getElementById(nomDiv).innerHTML = 'Atualizando...';
     var oHTTPRequest = createXMLHTTP(); 
     oHTTPRequest.open("post", "modAtualizaPedidoTextos.asp", true); 
	 oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");

     oHTTPRequest.onreadystatechange=function()
  	 {
	  	if (oHTTPRequest.readyState==4)
	 	{
       	   document.getElementById(nomDiv).innerHTML = oHTTPRequest.responseText;
		}
	 }

	 texto = url_encode(texto);
	 
	 oHTTPRequest.send("idtPedido=" + idtPedido + "&tipo=" + tipo + "&texto=" + texto);
 } 

