/**
 * Procura o próximo campo da tela e dá o foco para ele.
 */
function FF_GetProxCtrl(ctrlAtual) {
	if (F_isIExplorer()) {
		nProxCtrl = ctrlAtual.sourceIndex+1;
		proxCtrl = document.all[nProxCtrl];
		while (proxCtrl != null) {
			if (proxCtrl.nodeName == "INPUT") {
				return proxCtrl;
			}
			nProxCtrl++;
			proxCtrl = document.all[nProxCtrl];
		}
	} else {
		var elements = ctrlAtual.form.elements; 
		var length = elements.length;
		for (nProxCtrl=0; nProxCtrl < length; nProxCtrl++) {
			if (ctrlAtual == elements[nProxCtrl] &&	(nProxCtrl+1) <= length) {
				return elements[nProxCtrl+1];
			}
		}
	}
	return null;
}    

/**
 * Procura o próximo campo da tela e dá o foco para ele.
 */
function FF_GetForm(ctr) {
	while (ctr != null && ctr.tagName != "FORM") {
		ctr = ctr.parentNode;
	}
	return ctr;
}

/**
 * Varre o formulário, e desabilita todos os inputs, checkboxes, textareas, combos,
 * e radios acrescentando também o estilo "d" (desabilitado) ao campo quando possível.
 * Também esconde botões de grids.
 * Caso haja necessidade de algum controle específico ficar habilitado ou visível
 * crie um atributo no controle alwaysEnabled="true" ou alwaysVisible="true".
 */
function FF_desabilitaForm(objForm) {
	var length = objForm.length;
	for (var i = 0; i < length; i++) {
		var obj = objForm[i];
		var alwaysVisible = false;
		var alwaysEnabled = false;
		var objAlwaysVisible = obj.getAttribute('alwaysVisible');
		var objAlwaysEnabled = obj.getAttribute('alwaysEnabled');
		var objType = obj.type;
		var objReadOnly = obj.readOnly;
		var objNodeName = obj.nodeName;
		var objClassName = obj.className;
		var objDisabled = obj.disabled;
		
		if (objAlwaysVisible != null)
			alwaysVisible = new String(objAlwaysVisible).toUpperCase() == "TRUE";
		if (objAlwaysEnabled != null) 
			alwaysEnabled = new String(objAlwaysEnabled).toUpperCase() == "TRUE";
		if (objNodeName == "INPUT" && objType == "text" && !obj.readOnly && !alwaysEnabled) {
			disable(obj);
		} else if (objNodeName == "INPUT" && objType == "checkbox" && !objDisabled && !alwaysEnabled) {
			obj.disabled = true;
		} else if (objNodeName == "TEXTAREA" && !objReadOnly && !alwaysEnabled) {
			disable(obj);
		} else if (objNodeName == "SELECT" && !objDisabled && !alwaysEnabled) {
			disable(obj);
			obj.disabled = true;				
		} else if (objNodeName == "INPUT" && objType == "button" && objClassName == "spwBotaoGrid" && !alwaysVisible) {
			obj.style.visibility = "hidden";
		} else if (objNodeName == "INPUT" && objType == "radio") {
			obj.disabled = true;
		}
	}
}

function FF_desabilitaBotoes(objForm) {
	var length = objForm.length;
	for (var i = 0; i < length; i++) {
		var obj = objForm[i];
		B_desabilitaBotao(obj);
	}
}

function FF_habilitaBotoes(objForm) {
	var length = objForm.length;
	for (var i = 0; i < length; i++) {
		if (objForm[i].nodeName == "INPUT" && (objForm[i].type == "button" || objForm[i].type=="submit")) {
			objForm[i].disabled = false;
			if(objForm[i].getAttribute('oldClassName') != null){
				objForm[i].className = objForm[i].getAttribute('oldClassName');
			}           
		} 
	}
}

function FF_desabilitaGridListPaginada(objForm){
	var length = objForm.length;
	for (var i = 0; i < length; i++) {
		var obj = objForm[i];
		if(new String(obj.getAttribute('desabilitaOnSubmit')).toUpperCase() == "TRUE"){
			obj.disabled = true;
		}				
	}
}
