// JavaScript Document

function upCode(url) {
	request = ajaxInit();
    request.open("GET",url,true);
    request.onreadystatechange=function(){
        if(request.readyState==4){
            var txt = request.responseText;
			var xml = request.responseXML;
			alert(xml);
        }
    }
    request.send(null);
}

function ajaxInit() {
	var req;
	try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
	catch(e) {
		try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(ex) {
			try { req = new XMLHttpRequest(); }
			catch(exc) { alert("Esse browser não tem recursos para uso do Ajax"); req = null; }
		}
	}
	return req;
}

function xmlMicoxArvore(xmlNode,identacao){
		//by Micox: micoxjcg@yahoo.com.br
		var arvoreTxt=""; //esta var armazenara o conteudo
		for(var i=0;i<xmlNode.childNodes.length;i++){//percorrendo os filhos do nó
		if(xmlNode.childNodes[i].nodeType == 1){//ignorar espaços em branco
		//pegando o nome do nó
		arvoreTxt = arvoreTxt + identacao + xmlNode.childNodes[i].nodeName + ": "
		if(xmlNode.childNodes[i].childNodes.length==0){
			//se nao tiver filhos eu já pego o nodevalue
			arvoreTxt = arvoreTxt + xmlNode.childNodes[i].nodeValue 
			for(var z=0;z<xmlNode.childNodes[i].attributes.length;z++){
				var atrib = xmlNode.childNodes[i].attributes[z];
				arvoreTxt = arvoreTxt + " (" + atrib.nodeName + " = " + atrib.nodeValue + ")";
				}
				arvoreTxt = arvoreTxt + "<br />\n";
				}else if(xmlNode.childNodes[i].childNodes.length>0){
					//se tiver filhos eu tenho que pegar o valor pegando o valor do primeiro filho
					arvoreTxt = arvoreTxt + xmlNode.childNodes[i].firstChild.nodeValue;
					for(var z=0;z<xmlNode.childNodes[i].attributes.length;z++){
						var atrib = xmlNode.childNodes[i].attributes[z];
				arvoreTxt = arvoreTxt + " (" + atrib.nodeName + " = " + atrib.nodeValue + ")";
				}
				//recursividade para carregas os filhos dos filhos
				arvoreTxt = arvoreTxt + "<br />\n" + xmlMicoxArvore(xmlNode.childNodes[i],identacao + "> > ");
			}
		}
	}
	document.getElementById('deBug').innerHTML = arvoreTxt;
	return arvoreTxt;
}


function foco(campo) { document.getElementById(campo).focus(); }

function carregaFlash(caminho,largura,altura) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+largura+'" height="'+altura+'">');
	document.write('<param name="allowScriptAccess" value="sameDomain">');
	document.write('<param name="movie" value="'+caminho+'">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="bgcolor" value="">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="menu" value="false">');
	document.write('<embed src="'+caminho+'" quality="high" wmode="transparent" allowScriptAccess="sameDomain" align="middle"  pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+largura+'" height="'+altura+'"></embed>');
	document.write('</object>');
}

function carregaFlashTop(caminho,largura,altura) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+largura+'" height="'+altura+'">');
	//document.write('<param name="allowScriptAccess" value="sameDomain">');
	document.write('<param name="movie" value="'+caminho+'">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="bgcolor" value="">');
	document.write('<param name="wmode" value="transparent">');
	//document.write('<param name="menu" value="false">');
	document.write('<embed src="'+caminho+'" quality="high" wmode="transparent" allowScriptAccess="sameDomain"   pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+largura+'" height="'+altura+'" style="margin-left:10px; display:block; width:'+largura+'px; height:'+altura+'px; overflow:hidden;"></embed>');
	document.write('</object>');
}

function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function addOption(valor,nome,campo_option,selected) {
	elOptNew = document.createElement('option');
	nome = trimAll(nome);
	valor = trimAll(valor);
	elOptNew.text = nome;
	elOptNew.value = valor;
	var elSel = document.getElementById(campo_option);
	//alert (valor + " - " + nome);
	try { elSel.add(elOptNew, null); } // standards compliant; doesn't work in IE
	catch(ex) { elSel.add(elOptNew); } // IE only
	if (selected == valor) { elOptNew.selected = 'selected'; } else { elOptNew.selected = ''; }
}

function clearOptions(campo) {
	campo_tipos = document.getElementById(campo);
	if(campo_tipos) {
		var i;
		for (i = campo_tipos.length - 1; i>=0; i--) { campo_tipos.remove(i); }
	}
}

function OpenClose(objeto) {
	obj = document.getElementById(objeto);
	if (obj.style.display == 'none') { obj.style.display = 'block' } else { obj.style.display = 'none'; }
}