function autoNewLine(input, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var RETURN = 13;
	
	if(keyCode == RETURN) {
		//Captura TABLE, BODY
		var table = input;
		var tr;
		while(table.nodeName != 'TABLE') {
			table = table.parentNode;
			if (table.nodeName == 'TR') {
				tr = table;
			}
		}
		var body = table.tBodies[0];
		
		//identifica se a tr que ele pertence é a ultima
		var ultima = body.rows[body.rows.length - 1] == tr;
	
		if (ultima) {
			//Captura o metodo
			var metodo = eval ('newLine' + table.id);
			metodo.call();
			//Detecta proximo a receber foco
			var ultimaTr = body.rows[body.rows.length - 1];
			var tdData = ultimaTr.cells[1];
			//Muda o foco
			var proximo = tdData.getElementsByTagName('INPUT')[0];
			proximo.focus();
		}
	}
	return false;
}

/* Funcao para controlar aparecimento de campos mediante opção de combobox*/
function mostraCamposCombobox(combobox, valor, nomes){
	var arrayNomes = nomes.split(";");
	
	/*Se o elemento estiver marcado*/
	if (combobox.value == valor){
		for (i = 0; i<arrayNomes.length; i++){
			elementToHide = document.getElementsByName(arrayNomes[i]);
			if (elementToHide != null){
				elementToHide.style.visibility = "hidden";
			}
		}
	}
	/*Se o elemento não estiver marcado*/
	else{
		for (i = 0; i<arrayNomes.length; i++){
			elementToHide = document.getElementsByName(arrayNomes[i]);
			if (elementToHide != null){
				elementToHide.style.visibility = "visible";
			}
		}
	}
}

/* Funcao para controlar a marcação de atores (Primário/Secundário)*/
function desmarcaCheckboxAtor(checkbox, fieldName){
	var fieldNames = fieldName.split(".");
	var fieldPrefix = fieldNames[0];
	var fieldSufix = fieldNames[1];
	if (fieldSufix == 'primario' && checkbox.checked) {
		checkboxSecundario = document.getElementsByName(fieldPrefix +'.secundario')[0];
		checkboxSecundario.checked = false;
	} else if (fieldSufix == 'secundario' && checkbox.checked) {
		checkboxPrimario = document.getElementsByName(fieldPrefix +'.primario')[0];
		checkboxPrimario.checked = false;
	}
}

function mostraDivDisponiveis(divName, combobox, valorCombobox){
	var div = document.getElementById(divName);
	
	if (combobox.value != valorCombobox) {
		div.style.display = "none";
	} else {
		div.style.display = "";
	}
}

/*
* Limpa os dados do formulario da pagina
* por enquanto, só funciona para campos text, checkbox e select
*/
function clearAll(){
	/*Limpa os inputs tipo texto*/
	var textFields=document.getElementsByTagName('input')
	for (var i_tem = 0; i_tem < textFields.length; i_tem++){
		if (textFields[i_tem].type=='text' && textFields[i_tem].name != 'pageSize'){
			textFields[i_tem].value="";
		}
	}
	/*Limpa os inputs tipo checkbox*/
	var textFields=document.getElementsByTagName('input')
	for (var i_tem = 0; i_tem < textFields.length; i_tem++){
		if (textFields[i_tem].type=='checkbox'){
			textFields[i_tem].checked=false;
		}
	}
	/*Limpa os select-one*/
	var textFields=document.getElementsByTagName('select')
	for (var i_tem = 0; i_tem < textFields.length; i_tem++){
		textFields[i_tem].value="<null>";
	}
}

function getElementsByName_iefix(tag, name) {
	if (isNN) {
		return document.getElementsByName(name);
	}
	var elem = document.getElementsByTagName(tag);
	var arr = new Array();
	for(i = 0,iarr = 0; i < elem.length; i++) {
		att = elem[i].getAttribute("name");
		if(att == name) {
			arr[iarr] = elem[i];
			iarr++;
		}
	}
	return arr;
}

//sobrescrita para alerta de alteracao
function indicaAlteracaoVisualmente(){
	var btnM = document.getElementById("btn_salvar");
	btnM.style.border = "1px solid red";
	btnM.style.backgroundColor = "#FFFFEE";
	btnM.style.color = "red";
}
