// -----------------------------------
// Funções de seleção de checkboxes
// -----------------------------------
function selecionatudo(conjunto, unidade){
	var col_checks = document.all.item(conjunto);
	var ref_check=document.all.item(unidade);
	valor_final = ref_check.checked;
	if (col_checks.length!=null) {
		for (t=0; t<col_checks.length; t++) {
			var atual_check = col_checks(t);
			atual_check.checked=valor_final;
		}
	}
	else
	{
		col_checks.checked=valor_final;
	}
}
// -----------------------------------

// -----------------------------------
// Função de abertura de janela
// -----------------------------------
function abreJanela(caminho, nome, largura, altura, topo, esquerda) {
	window.open(caminho,nome,'toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,scrollbars=1,width='+largura+',height='+altura+',left='+topo+',top='+esquerda+'');
}
// -----------------------------------

// -----------------------------------
// Função para inserção de código em input text
// -----------------------------------
function insereTexto(formname, fieldname, fieldvalue, textside) {
	if (document.getElementById(formname)) {
		alert;
		if (document.getElementById(formname).document.getElementById(fieldname)) {
			if (textside == 'LEFT') {
				(document.getElementById(formname).document.getElementById(fieldname)).value = fieldvalue + (document.getElementById(formname).document.getElementById(fieldname)).value;
			} else {
				(document.getElementById(formname).document.getElementById(fieldname)).value = (document.getElementById(formname).document.getElementById(fieldname)).value + fieldvalue;
			}
		}
	}
}
// -----------------------------------

// -----------------------------------
// Funções de formatação para TEXTAREA
// -----------------------------------
function storeCaret (textEl) {
	if (textEl.createTextRange)
		textEl.caretPos = document.selection.createRange().duplicate();
}

function addComando (textEl, textIni, textFim) {
	if(textIni.indexOf('null')!=-1) return;
	textEl.focus();
	if (textEl.createTextRange && textEl.caretPos) {
		var caretPos = textEl.caretPos;
		caretPos.text=textIni + caretPos.text + textFim;
		storeCaret(textEl);
	} else {
		textEl.value  = textIni+textFim;
	}
}
// -----------------------------------

// -----------------------------------
// Funções que só permitem enter pulando para o próximo campo ou não permite
// -----------------------------------
	function noenter() {
  	return !(window.event && window.event.keyCode == 13);
  }

	function enter(nextfield) {
		if (window.event && window.event.keyCode == 13) {
			nextfield.focus();
			return false;
		} else {
			return true;
		}
	}
// -----------------------------------

