// JavaScript Document

function ajax(url,div)
{ 

mostra=document.getElementById(div);
//alert(nick);
//alert(dest);
//alert(msg);

    req = null; 
    // Procura por um objeto nativo (Mozilla/Safari) 
    if (window.XMLHttpRequest) { 
        req = new XMLHttpRequest(); 
        req.onreadystatechange = processReqChange; 
        req.open("GET",url,true); 
        req.send(null); 
    // Procura por uma versão ActiveX (IE) 
    } else if (window.ActiveXObject) { 
        req = new ActiveXObject("Microsoft.XMLHTTP"); 
        if (req) { 
		
		
            req.onreadystatechange = processReqChange; 
         req.open("GET",url,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) { 
		
            // procura pela div id="news" e insere o conteudo 
            // retornado nela, como texto HTML 
            
			mostra.innerHTML = req.responseText; 
			
        } else { 
            alert("Houve um problema ao obter os dados:\n" + req.statusText); 
        } 
    } 
}

// JavaScript Document online

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// JavaScript Document orçamento

   function Dados(valor) {
      //verifica se o browser tem suporte a ajax
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
	  //se tiver suporte ajax
	  if(ajax) {

   	     ajax.open("POST", "orca.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

		 ajax.onreadystatechange = function() {
  			//após rocessado - chama função processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
      if(ajax.responseXML) {
			      processXML(ajax.responseXML);
			   }

            }
         }
		 //passa o código do estado escolhido
	     var params = "item="+valor;
         ajax.send(params);
      }
   }

   function processXML(obj){
      //pega a tag cidade
   var dataArray = obj.getElementsByTagName("cidade");

   //total de elementos contidos na tag cidade

   if(dataArray.length > 0) {

   for (var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//contéudo dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
			var address =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;

             addTableRow(address);


		 }
	  }
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "--Voltou vazio--";
	  }
   }


   function addTableRow(address) {
    var row = document.createElement("tr");
    var cell = createCellWithText(address);
    row.appendChild(cell).style.cssText="font-weight:bold; font-family: Arial; font-size: 12px; color: #000080;";

        document.getElementById("resultsBody").appendChild(row);
}

function createCellWithText(text) {
    var cell = document.createElement("td");
    var textNode = document.createTextNode(text);
    cell.appendChild(textNode);

    return cell;


}

//função teste
function valida_orc() {
	if (form2.nome.value=="") {
		alert("* Favor preencher o campo Nome!");
	 form2.nome.focus();
    return false;
		}
	if (form2.email.value=="") {
		alert("* Favor preencher o campo E-mail!");
	  form2.email.focus();
    return false;
		}
if (form2.assunto.value=="nulo") {
		alert("* Favor preencher o campo Assunto!");
	 form2.assunto.focus();
    return false;
		}
	}
form.php.submit();
