var req;

function getXMLHttpRequest(metodo,url,tpChamada,callback,paramPost) {
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP")
	}
	
	req.open("POST",url,tpChamada);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
	req.onreadystatechange = eval(callback);
	req.send(paramPost);
}

function erro_ok(msg,endereco) {

	var novoDiv  = document.createElement("div");
	novoDiv.id = "divErroX1308";
	
	var novaTable= document.createElement("table");
	var novaTbody= document.createElement("tbody");
	var n1Tr	 = document.createElement("tr");
	var n2Tr	 = document.createElement("tr");
	var n11Td	 = document.createElement("td");
	var n12Td	 = document.createElement("td");
	var n21Td	 = document.createElement("td");
	var n12TdText 	 = document.createTextNode(msg);
	var n11TdImg	 = document.createElement("img");
	n11TdImg.src  = "/Ofm_Imprensa/imgs/erro.gif";
	
	n11Td.appendChild(n11TdImg);
	n1Tr.appendChild(n11Td);
	n12Td.appendChild(n12TdText);
	n1Tr.appendChild(n12Td);
	novaTbody.appendChild(n1Tr);
	novaTbody.appendChild(n2Tr);
	n2Tr.appendChild(n21Td);
	n21Td.appendChild(document.createTextNode("X"));
	n1Tr.appendChild(n21Td);
	novaTable.appendChild(novaTbody);
	novoDiv.appendChild(novaTable);
	
	if (endereco == undefined) {
		document.onclick = function() {document.body.removeChild(document.getElementById('divErroX1308'));document.onclick = function() {};}; 
	} else {
		document.onclick = function() {window.location=endereco}; 		
	}
	
	document.body.appendChild(novoDiv);
	
	novaTable.align = "center";
	n11Td.width = "50px";
	n12Td.width =(novoDiv.offsetWidth - 50);
	n11Td.className = "p-left";
	n12Td.className = "p-center";
	n21Td.className = "p-right";
	novoDiv.className = "janela";

	novoDiv.style.left = ((document.body.offsetWidth/2) - (novoDiv.offsetWidth/2)) + "px";
	novoDiv.style.top  = ((document.body.offsetHeight/2) - (novoDiv.offsetHeight/2)) + "px";
	
}

function carregando(isCarregando) {
	if (isCarregando != 4 && document.getElementById("loadingX1308") == null) {
	
		var novoDiv  = document.createElement("div");
		var novaImg	 = document.createElement("img");
		var txt = document.createTextNode("Carregando...");
		var tabela = document.createElement("table");
		var tcorpo = document.createElement("tbody");
		var ttr = document.createElement("tr");
		var ttd = document.createElement("td");
		var ttd2 = document.createElement("td");
		
		tabela.appendChild(tcorpo);
		tcorpo.appendChild(ttr);
		ttr.appendChild(ttd);
		ttr.appendChild(ttd2);
		
		ttd.appendChild(novaImg);
		ttd2.appendChild(txt);
		
		novaImg.src  = "/Ofm_Imprensa/imgs/loading.gif";
		tabela.id = "imgX1308";
		novoDiv.id = "loadingX1308";
		
		novoDiv.style.position = "absolute";
		novoDiv.style.top  = "45%";
		novoDiv.style.left = "25%";
		
		novoDiv.style.height =  "100px";
		novoDiv.style.width  = "400px";

	    document.body.appendChild(tabela);
	    document.body.appendChild(novoDiv);
		w3Opacity.set('loadingX1308',80);
		
	} else if (isCarregando == 4) {
			if (document.getElementById("loadingX1308") != null) {
				document.body.removeChild(document.getElementById('loadingX1308'));
				document.body.removeChild(document.getElementById('imgX1308'));
			}	
	}
}

function limpaTabela(objeto){

	for (var i=0; i<objeto.childNodes.length; i++)
	{
		if (objeto.childNodes[i].nodeName=="TBODY"){
			limpaTabela(objeto.childNodes[i]);
			if (objeto.childNodes[i].id == "tbodyX1308") {
				objeto.removeChild(objeto.childNodes[i]);
			}
		} else if (objeto.childNodes[i].nodeName=="TR" && objeto.childNodes[i].id != "cabecalho"){
			objeto.removeChild(objeto.childNodes[i]);
		}
	}	
}

function constroiStringPedido(servlet,formulario) {
	var pedido = servlet;
	for (var i = 0 ; i < formulario.length ; i++) {
		if (formulario.elements[i].type != "button") {
			pedido += formulario.elements[i].name + "=" + formulario.elements[i].value + "&";
		}
	}
	return pedido.substr(0,pedido.length -1);
}

function stringCheckbox() {
	formulario = document.form1;
	var retorno= "";
	for (var i = 0 ; i < formulario.length ; i++) {
		try {
		if (formulario.elements[i].type == "checkbox" && formulario.elements[i].className == "interesse") {
			if (formulario.elements[i].checked == true) {
				retorno += formulario.elements[i].value+",";
			}
		}
		} catch (e) {
			// error
		}	
	}
	
	return retorno;
}

// Adiciona novas tags Options dentro da lista passada como parāmetro.
function addOption(lista,texto,valor,selecionado) {
	if (lista != null && lista.options != null) {
		lista.options[lista.options.length] = new Option(texto,valor,false,selecionado);
	}
}

// Adiciona novas tags Options dentro da lista passada como parāmetro.
function limpaOption(lista) {
	if (lista != null && lista.options != null) {
		for (var i = lista.options.length; i > 0; i-- ) {
			lista.remove(lista.options[i]);
		}			
	}
}