// JavaScript Document
// ----- AJAX
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) {
	     //deixa apenas o elemento 1 no option, os outros sï¿½ excluï¿½os
		 document.forms[0].listCidades.options.length = 1;
	     
		 idOpcao  = document.getElementById("opcoes");
		 
	     ajax.open("POST", "cidades.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 
		 ajax.onreadystatechange = function() {
            //enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1) {
			   idOpcao.innerHTML = "Carregando...!";   
	        }
			//apï¿½ ser processado - chama funï¿½o processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXML(ajax.responseXML);
			   }
			   else {
			       //caso nï¿½ seja um arquivo XML emite a mensagem abaixo
				   idOpcao.innerHTML = "Selecione o estado";
			   }
            }
         }
		 //passa o cï¿½igo do estado escolhido
	     var params = "estado="+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) {
	     //percorre o arquivo XML paara extrair os dados
         for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//contï¿½do dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
			var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;
			
	        idOpcao.innerHTML = "Selecione a Cidade";
			
			//cria um novo option dinamicamente  
			var novo = document.createElement("option");
			    //atribui um ID a esse elemento
			    novo.setAttribute("id", "opcoes");
				//atribui um valor
			    novo.value = codigo;
				//atribui um texto
			    novo.text  = descricao;
				//finalmente adiciona o novo elemento
				document.forms[0].listCidades.options.add(novo);
		 }
	  }
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "Selecione o estado";
	  }	  
   }

// -----
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function AltMaiusc(campo)
{
   campo.value = campo.value.toUpperCase();
}

function AltMinusc(campo) 
{ 
   campo.value = campo.value.toLowerCase();
}

function verify()
{
	if( document.indique.ind_nome.value == "")
	{
		alert("Campo Nome em Indique um Amigo não foi preenchido");
		return false;
	}

	if( document.indique.ind_email.value == "")
	{
		alert("Campo Seu Email em Indique um Amigo não foi preenchido");
		return false;
	}
	
	if( document.indique.ind_destino.value == "")
	{
		alert("Campo Email do Amigo em Indique um Amigo não foi preenchido");
		return false;
	}	
}
function verifyNews()
{
	if( document.news.news_email.value == "")
	{
		alert("Campo Email em Newsletter não foi preenchido");
		return false;
	}
}
// ############################
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function AltMaiusc(campo)
{
   campo.value = campo.value.toUpperCase();
}

function AltMinusc(campo) 
{ 
   campo.value = campo.value.toLowerCase();
}

function verify()
{
	if( document.indique.ind_nome.value == "")
	{
		alert("Campo Nome em Indique a um Amigo nï¿½ foi preenchido");
		return false;
	}

	if( document.indique.ind_email.value == "")
	{
		alert("Campo Seu Email em Indique a um Amigo nï¿½ foi preenchido");
		return false;
	}
	
	if( document.indique.ind_destino.value == "")
	{
		alert("Campo Email do Amigo em Indique a um Amigo nï¿½ foi preenchido");
		return false;
	}	
}



function destino()
{
   url = document.frmAjax.listCidades.options[document.frmAjax.listCidades.selectedIndex].value
   if (url != "no") window.location = "./?modulo=profissionais&cidade="+url;
}

function addToFavorite(favTitle){

  if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {

    window.external.AddFavorite(location.href, unescape(favTitle));

  }

}