// Manipulação de Objetos
function manSelectText(Obj) {
	var objSel = document.getElementById(Obj);
	return objSel.options[objSel.selectedIndex].text;
}

function manSelectIndex(Obj) {
	var objSel = document.getElementById(Obj);
	return objSel.options[objSel.selectedIndex].value;
}

function returnTextSel(Obj) {
	var objSel = document.getElementById(Obj);
	return objSel.options[objSel.options[objSel.selectedIndex].index].text;
}

function manSelectValue(Obj) {
	var objSel = document.getElementById(Obj);
	return objSel.value;
}

function eLementos(recebeId) {
	return document.getElementById(recebeId);
}

function Css(Objeto, Classe) {
	if (eLementos(Objeto)) {
		eLementos(Objeto).className = Classe;
	}
}

function valueCampos(campo, texto) {
	eLementos(campo).value = texto;
}

function staCampo(campo, status) {
	eLementos(campo).disabled = status;
}

function display(Alvo, Estado) {
	if (eLementos(Alvo) != null) {
		if (eLementos(Alvo)) {
			eLementos(Alvo).style.display = Estado;
		}
	}
}

function displayElementos(Alvo) {
	if (eLementos(Alvo).style.display == 'none') {
		eLementos(Alvo).style.display = 'block';
	} else {
		eLementos(Alvo).style.display = 'none';
	}
}

function displayElementosListServ(Alvo1, Alvo2) {
	if (eLementos(Alvo1).style.display == 'none') {
		eLementos(Alvo1).style.display = 'block';
		Css(Alvo2, 'setaMenos');
	} else {
		eLementos(Alvo1).style.display = 'none';
		Css(Alvo2, 'setaMais');
	}
}

function alterClass(Alvo, Class) {
	eLementos(Alvo).className = Class;
}

function fnChk(Alvo, Acao, Qtd) {
	Cont = 0;
	while (Cont <= Qtd) {
		if (eLementos(Alvo + Cont)) {
			eLementos(Alvo + Cont).checked = Acao;
		}
		Cont++;
	}
}


//Mascara
function txtBoxFormat(objForm, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen, bolMask, sCod, nTecla;
	var ObjMascara = document.getElementById(objForm);

	if (document.all) {
		nTecla = evtKeyPress.keyCode;
	} else if (document.layers) {
		nTecla = evtKeyPress.which;
	}
	
	sValue = ObjMascara.value;
	sValue = sValue.toString().replace("-", "");
	sValue = sValue.toString().replace("-", "");
	sValue = sValue.toString().replace(".", "");
	sValue = sValue.toString().replace(".", "");
	sValue = sValue.toString().replace("/", "");
	sValue = sValue.toString().replace("/", "");
	sValue = sValue.toString().replace("(", "");
	sValue = sValue.toString().replace("(", "");
	sValue = sValue.toString().replace(")", "");
	sValue = sValue.toString().replace(")", "");
	sValue = sValue.toString().replace(" ", "");
	sValue = sValue.toString().replace(" ", "");
	fldLen = sValue.length;
	mskLen = sMask.length;
	
	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;
	while (i <= mskLen) {
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

		if (bolMask) {
			sCod += sMask.charAt(i);
			mskLen++;
		} else {
			sCod += sValue.charAt(nCount);
			nCount++;
		}

		i++;

	}

	ObjMascara.value = sCod;
	if (nTecla != 8) {
		if (sMask.charAt(i - 1) == "9") {
			return ((nTecla > 47) && (nTecla < 58));
		} else {
			return true;
		}
	} else {
		return true;
	}
} // JavaScript Document

function PopUp(Arquivo, Largura, Altura, Redir, Scroll) {
	window.open(Arquivo, 'blank', 'toolbar=no,location=no,directories=no,status=no,menubar=no,Scrollbars=' + Scroll + ',resizable=' + Redir + ',width=' + Largura + ',height=' + Altura + ',left=' + (screen.width - Largura) / 2 + ',top=' + (screen.height - Altura) / 2);
	//window.open(Arquivo,'blank', 'toolbar=no,location=no,directories=no,status=no,menubar=no,Scrollbars='+Scroll+',resizable='+Redir+',width='+Largura+',height='+Altura+',left=' + (screen.width - 400)/2 + ',top=' + (screen.height - 300)/2);
}

function concChk(Alvo, qtd) {
	var dadosChk = '';
	for (i = 1; i <= qtd; i++) {
		if (eLementos(Alvo + i)) {
			if (eLementos(Alvo + i).checked == true) {
				dadosChk = dadosChk + eLementos(Alvo + i).value + ',';
			}
		}
	}
	return dadosChk;
}

