// JavaScript Document

function redireciona(url) {
	
	window.location = url;
	
};

function st(texto) {

	self.status = texto;
	
	return true;
	
};

function toolTip(obj, texto) {
	
	st(texto);
	obj.title = texto;
	
};

function validaValor(input) { 

	var valor = parseFloat(input.value);

	if (valor)
		input.value = (parseInt(input.value)==valor)?valor + ".00":valor;
	else
		input.value = "0.00"

};

function deselTodos(lst) {

	lst = document.getElementById(lst);
	
	changeSelList(lst,false);
	
}

function selTodos(lst) {
	
	lst = document.getElementById(lst);
	lst.multiple = true;
	
	changeSelList(lst,true);
	
};

function changeSelList(lst, selected) {
	
	for(var i=0; i < lst.length; i++)
		lst.options[i].selected = selected;
	
};

function delSelecteds(lst) {

	var obj = document.getElementById(lst);
	
	for(i=0; i < obj.length; i++)
		if (obj.options[i].selected)
   		obj.remove(i); 
	
};

function insItem(to,texto,valor) {

	var newOpt = document.createElement('option');

	newOpt.value = valor;
	newOpt.text = texto;
	newOpt.title = texto;
	
	try {
		to.add(newOpt, null); // standards compliant; doesn't work in IE
  }
	catch(ex) {
		to.add(newOpt); // IE only
	}

};

function addItem(from,to) {

	from = document.getElementById(from);
	to = document.getElementById(to);
	
	for(var i=0; i < from.length; )
		if (from.options[i].selected) {
			insItem(to,from.options[i].text,from.options[i].value);
			from.remove(i);
		} else i++;
		
};

function selItens(itens, from) {
	
	if (typeof(from) == "string")
		from = document.getElementById(from);
	for(var j=0; j < itens.length; j++)
		for(var i=0; i < from.length; i++ ) {
			if (from.options[i].value == itens[j])
				from.options[i].selected = true;
		}
				
};

function copiaConteudo(from,to) {
	
	if (typeof(from) == "string")
		from = document.getElementById(from);

	if (typeof(to) == "string")
		to = document.getElementById(to);
	
	for(var i=0; i < from.length; i++ )
		insItem(to,from.options[i].text,from.options[i].value);
	
};

function edtItem(to,valor,novoTexto) {

	for(var i=0; i < to.length; i++ )
		if (to.options[i].value == valor) {
			to.options[i].text = novoTexto;
			break;
		};

	
};

function mostra(objId) {
	
	var obj = document.getElementById(objId);
	
	obj.className = "" ;

};


function mostra(objId,valorPadrao) {
	
	var obj = document.getElementById(objId);
	
	obj.className = "" ;
	obj.value = valorPadrao;
	
};

function esconde(objId) {

	var obj = document.getElementById(objId);
	
	obj.className = "esconde" ;
	
};
