function escolha(valor){
	show("carregar");
	veja("docajax/detalhedoc.php","opc="+valor,preenche,"T","carregar");
//	show("saida");
}
function preenche(valor){
	var teste = pegaid("saida");
	teste.innerHTML = url_decode(valor);
	hide("carregar");
}


function pegaid(valor){
	return document.getElementById(valor);
}
function show(id){
   // W3C - Explorer 5+ and Netscape 6+
   document.getElementById(id).style.visibility = "visible";
}

function hide(id){
   // W3C - Explorer 5+ and Netscape 6+
   document.getElementById(id).style.visibility = "hidden";
}
//------------------------------------------
function geracabajax(){
     //verifica se o browser tem suporte a ajax
	  var 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;
            }
         }
      }

 return ajax;
}
//###############################################################
// Executa ajax 
// arquivo => arquivo.php que vai ser executado
// parametro => parametros para o send
// funcao => funcao executada quando realizar sucesso
// tipo => se o retorno e "X" xml "T" txt
// msg => id das mensagens

function veja(arquivo,parametro,funcao,tipo,msg){
	var xajax = geracabajax();
	//se tiver suporte ajax
	msg = pegaid(msg);
	if(xajax) {
		xajax.open("POST", arquivo, true);
		xajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xajax.onreadystatechange = function() {
			//enquanto estiver processando...emite a msg de carregando
			if(xajax.readyState == 1) {
				msg.innerHTML = "Carregando...";   
			}
			if(xajax.readyState == 4 ) {
				if(xajax.status==200){
					if(tipo.toUpperCase()=="X"){
						funcao(xajax.responseXML);
					} else {
						funcao(xajax.responseText);
					}
					msg.innerHTML = "Sucesso!";
				}
			}
		}
		xajax.send(parametro);
	}
}

    //============================================================================
    // codifica linhas para ser decodificado no php pelo rawurldecode()
    // by fabricio nogueira --- http://www.phpbrasil.com/articles/article.php/pagerRow/2/id/1182    li aqui
    // 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; 
}
//======================================================
// decodifica linhas codificadas com rawurlencode()
// url_decode version 1.0 
function url_decode(str) { 
	var n, strCode, strDecode = ""; 

	for (n = 0; n < str.length; n++) { 
			if (str.charAt(n) == "%") { 
				strCode = str.charAt(n + 1) + str.charAt(n + 2); 
				strDecode += String.fromCharCode(parseInt(strCode, 16)); 
				n += 2; 
			} else { 
				strDecode += str.charAt(n);
			}
		}
	return strDecode; 
}

