function in_array (valor, matriz) {
  var texto = "¬" + matriz.join("¬") + "¬";
  var er = new RegExp ("¬" + valor + "¬", "gim");
  return ( (texto.match (er)) ? true : false );
}

function confirmRedirect(msg, url)
{
	if(confirm(msg))
	{
		location.href = url;
	}
}

function mudaCor(e, cor)
{
	document.getElementById(e).style.background = cor;
}

function statusI(e, bool)
{
		document.getElementById(e).disabled = bool;
}

function mostra(id)
{
	this.document.getElementById(id).style.display='inline';
}
function esconde(id)
{
	this.document.getElementById(id).style.display='none';
}

var divs = new Array();
function hidAll(inline)
{
	var i = 0;
	for(i =0 ; i < divs.length; i++){
		if(divs[i] == inline ){
			if(document.getElementById(divs[i]).style.display != "inline" ){
				document.getElementById(divs[i]).style.display='inline';
			}else{
				document.getElementById(divs[i]).style.display='none';
			}
		//	document.getElementById(divs[i]).style.display='inline';
		}else{
			document.getElementById(divs[i]).style.display='none';
		}
	}
}

function hidAll2(inline, divs2)
{
	var i = 0;
	for(i =0 ; i < divs2.length; i++){
		if(divs2[i] == inline){
			document.getElementById(divs2[i]).style.display='inline';
		}else{
			document.getElementById(divs2[i]).style.display='none';
		}
	}
}
function hidAll3(inline, divs2,classIn,classOut)
{
	var i = 0;
	for(i =0 ; i < divs2.length; i++){
		if(divs2[i] == inline){
			document.getElementById(divs2[i]).style.display='inline';
			// Altera a classe da celula da tabela com nome: ab_[divs2[i]]->nome padrao da abas			
			document.getElementById('ab_'+divs2[i]).className=classIn;
		}else{
			document.getElementById(divs2[i]).style.display='none';
			// Altera a classe da celula da tabela com nome: ab_[divs2[i]]->nome padrao da abas
			document.getElementById('ab_'+divs2[i]).className=classOut;
		}
	}
}
function toggleDisplay(id)
{
	if(this.document.getElementById( id).style.display=='none')
	{
		this.document.getElementById( id).style.display='inline';
		if(this.document.getElementById(id+"link") != undefined)
		{
			this.document.getElementById(id+"link").style.display='none';
		}
	}else
	{
		this.document.getElementById(  id).style.display='none';
		if(this.document.getElementById(id+"link") != undefined)
		{
			this.document.getElementById(id+"link").style.display='inline';
		}
	}
		
}


function sww(id)
{
	document.getElementById(id).style.display='none';
}

function re_load() {
	history.go(0)
}

// Funções para o usso do httprequest

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)) || 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; 
} 

// 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; 
} 
//-->  

var req;
var div;

function enviaGet(script,funcao)
{
	document.getElementById(div).innerHTML = "Carregando...";
	req = null;
	// Procura por um objeto nativo (Mozilla/Safari)
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", script+funcao, true);
		req.send(null);
		// Procura por uma versao ActiveX (IE)
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange;
			req.open("GET", script+funcao,true);
			req.send();
		}
	}

}

function enviaPost(script,funcao)
{
	document.getElementById(div).innerHTML = "<font  style='background-color: #FF9999;'>Carregando...</font>";
	req = null;
	// Procura por um objeto nativo (Mozilla/Safari)
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		// Procura por uma versao ActiveX (IE)
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (req) {
		req.onreadystatechange = processReqChange;
		req.open("POST", script, true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.send(funcao);
	}
}

function processReqChange()
{
	// apenas quando o estado for "completado"
	if (req.readyState == 4) {
		// apenas se o servidor retornar "OK"
		if (req.status == 200) {
			// procura pela div id="atualiza" e insere o conteudo
			// retornado nela, como texto HTML
			document.getElementById(div).innerHTML = url_decode(req.responseText);
		} else {
			alert("Houve um problema ao obter os dados:\n" + req.statusText);
		}
	}
}

function setDiv(nome)
{
	div = nome;
}

function atualiza(script, funcao)
{
	loadXMLDoc(script,funcao);
}
// FIM :: Funções para o usso do httprequest

/*
// SCRIPT DRAG
var ie=document.all
var ns6=document.getElementById&&!document.all

var dragapproved=false
var z,x,y

function move(e){
	if (dragapproved){
		z.style.left=ns6? temp1+e.clientX-x: temp1+event.clientX-x
		z.style.top=ns6? temp2+e.clientY-y : temp2+event.clientY-y
		return false
	}
}

function drags(e){
	if (!ie&&!ns6)
	return
	var firedobj=ns6? e.target : event.srcElement
	var topelement=ns6? "HTML" : "TBODY"


proibido = new Array();
proibido[0] = "INPUT";
proibido[1] = "TEXTAREA";
proibido[2] = "RADIO";
proibido[3] = "CHECKBOX";
proibido[4] = "A";
proibido[5] = "IMG";

	while (firedobj.tagName!=topelement&&firedobj.className!="drag")
	{
		if(in_array(firedobj.tagName, proibido))
		{
			break;
		}
		firedobj=ns6? firedobj.parentNode : firedobj.parentElement
	}
	if (firedobj.className=="drag"){
		dragapproved=true
		z=firedobj
		temp1=parseInt(z.style.left+0)
		temp2=parseInt(z.style.top+0)
		x=ns6? e.clientX: event.clientX
		y=ns6? e.clientY: event.clientY
		document.onmousemove=move
		return false
	}
}
document.onmousedown=drags
document.onmouseup=new Function("dragapproved=false")
// FIM :: SCRIPT DRAG

*/
function atribuiPopup(hiddenId, textId, valueHidden, valueText)
{
	hidden = document.getElementById(hiddenId);
	text = document.getElementById(textId);
	hidden.value = valueHidden;
	text.value = valueText;
}

function limpa_selectbox(comboID, valorPadrao, disabled)
{
	combo = document.getElementById(comboID);
	combo.length = 0;
	
	if(valorPadrao != "")
	{
		combo.options[combo.length] = new Option(valorPadrao,'');
	}
	
	if( disabled )
	{
		combo.disabled = "disabled";
	}
}