/**
 * 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 {
		for (nProxCtrl=0; nProxCtrl < ctrlAtual.form.elements.length; nProxCtrl++) {
			if (ctrlAtual == ctrlAtual.form.elements[nProxCtrl] &&
				(nProxCtrl+1) <= ctrlAtual.form.elements.length) {
				return ctrlAtual.form.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) {
	for (var i = 0; i < objForm.length; i++) {
		alwaysVisible = false;
		alwaysEnabled = false;
		if (objForm[i].getAttribute('alwaysVisible') != null)
			alwaysVisible = new String(objForm[i].getAttribute('alwaysVisible')).toUpperCase() == "TRUE";
		if (objForm[i].getAttribute('alwaysEnabled') != null) 
			alwaysEnabled = new String(objForm[i].getAttribute('alwaysEnabled')).toUpperCase() == "TRUE";
		if (objForm[i].nodeName == "INPUT" && objForm[i].type == "text" && !objForm[i].readOnly && !alwaysEnabled) {
			objForm[i].readOnly = true;
			objForm[i].className = objForm[i].className + " d";
		} else if (objForm[i].nodeName == "INPUT" && objForm[i].type == "checkbox" && !objForm[i].disabled && !alwaysEnabled) {
			objForm[i].disabled = true;
		} else if (objForm[i].nodeName == "TEXTAREA" && !objForm[i].readOnly && !alwaysEnabled) {
			objForm[i].readOnly = true;
			objForm[i].className = objForm[i].className + " d";
		} else if (objForm[i].nodeName == "SELECT" && !objForm[i].disabled && !alwaysEnabled) {
			objForm[i].disabled = true;
			objForm[i].className = objForm[i].className + " d";
		} else if (objForm[i].nodeName == "INPUT" && objForm[i].type == "button" && objForm[i].className == "spwBotaoGrid" && !alwaysVisible) {
			objForm[i].style.visibility = "hidden";
		} else if (objForm[i].nodeName == "INPUT" && objForm[i].type == "radio") {
			objForm[i].disabled = true;
		}
	}
}

function FF_desabilitaBotoes(objForm) {
	for (var i = 0; i < objForm.length; i++) {
		if (objForm[i].nodeName == "INPUT" && (objForm[i].type == "button" || objForm[i].type=="submit")) {
			if(objForm[i].className.indexOf('-o') != -1){
				objForm[i].setAttribute('oldClassName',objForm[i].className);
				objForm[i].className = objForm[i].className.substring(0,objForm[i].className.length-2) + '-d';
			}else if(objForm[i].className.indexOf('-d') == -1){
				objForm[i].setAttribute('oldClassName',objForm[i].className);
				objForm[i].className = objForm[i].className + '-d';
			}
			objForm[i].disabled = true;
		} 
	}
}

function FF_habilitaBotoes(objForm) {
	for (var i = 0; i < objForm.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');
			}           
		} 
	}
}
