function mostra_foto(foto,wdh,hgt){
	posL = screen.availWidth/2 - wdh/2;
	posT = screen.availHeight/2 - hgt/2;
	str = 'width='+wdh+', height='+hgt+', left='+posL+', top='+posT+', scrollbars=no';
	window.open('mostra_foto.php?foto='+ foto, '', str);
}
function upContato(){
	document.getElementById("fale_cotacao").style.display = 'none';	
	document.getElementById("fale_contato").style.display = 'block';
}
function upCotacao(){
	document.getElementById("fale_contato").style.display = 'none';
	document.getElementById("fale_cotacao").style.display = 'block';
}

function enviar(form){	
	document.form.submit();	
}

function enviarCotacao(){	
	document.formCotacao.submit();	
}

function enviarContato(form){	
	document.formContato.submit();	
}

function showClock(obj){
	document.write('<embed src="http://www.clocklink.com/clocks/'
		+ obj.clockfile
		+ '?TimeZone=' + obj.TimeZone
	);
	if( obj.DateFormat != undefined && obj.DateFormat != "" )document.write('&DateFormat=' + obj.DateFormat);
	document.write('&TimeFormat=' + obj.TimeFormat
		+ '&Place=' + obj.Place
		+ '&Target=' + obj.Target
		+ '&From=' + obj.From
		+ '&Title=' + obj.Title
		+ '&Message=' + obj.Message
		+ '" width="' + obj.width
		+ '" height="' + obj.height
		+ '" wmode="' + obj.wmode
		+ '" type="application/x-shockwave-flash">'
	);
}

function cotacao() {
	var navegador = navigator.appName.toLowerCase(); 
	var mozilla = navegador.indexOf("netscape")+1;

    var tmp = document.getElementById("cotacao").innerHTML;
	document.getElementById("cotacao").innerHTML = '';

	tam = tmp.length;
	table = '<table width=\"190\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">';
    var codigo = mozilla ? table+tmp.substr(218,tam) : table+tmp.substr(214,tam);
    document.getElementById("cotacao").innerHTML = codigo;
}

function formataData(id) {
		//Criaremos esta variável para evitar a digitação de nomes longos
		var campo = document.getElementById(id);		
		//if (data.value.charAt(3) == "/" || data.value.charAt(3) == "/")
		if( campo.value.length == 2 || campo.value.length == 5 )
		{
			/* Aqui vemos uma outra forma de se fazer acesso ao objeto.
			Procurem pela propriedade id na declaração da tag, e ache o objeto.
			Traduzindo: o valor do objeto, cujo id é igual a 'data', receberá
			ele mesmo +(concatenando) a barra de separação '/'
			*/
			campo.value += "/";			
		}	
}

 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ão excluídos
		 document.forms[0].listdestinos.options.length = 1;
	     
		 idOpcao  = document.getElementById("opcoes");
		 
	     ajax.open("POST", "destinos.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ós ser processado - chama função processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXML(ajax.responseXML);
			   }
			   else {
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   idOpcao.innerHTML = "   Primeiro selecione a origem   ";
			   }
            }
         }
		 //passa o código da origem escolhida
	     var params = "origem="+valor;
         ajax.send(params);
      }
   }
   
   function processXML(obj){
      //pega a tag destino
      var dataArray   = obj.getElementsByTagName("destino");
      
	  //total de elementos contidos na tag destino
	  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éudo dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
			var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;
			
	        idOpcao.innerHTML = "   Selecione uma das opções abaixo  ";
			
			//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].listdestinos.options.add(novo);
		 }
	  }
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "  Primeiro selecione a origem  ";
	  }	  
   }
