// return the value of obj[selectedIndex] where obj is a option button
function getSelectedOption(obj) {
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].checked == true) {
			return obj[i].value;
		}
	}
}
function unmarkAllOption(obj) {
	for (var i = 0; i < obj.length; i++) {
		obj[i].checked = false;
	}
}

// se objOption[i].checked where obj[i].value match objField.value
function setSelectedOption(objField, obj) {
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].value == objField.value) {
			obj[i].checked = true;
			break;
		}
	}
}
function printThisPage() {
	var Browser;
	if (navigator.appName.toUpperCase().indexOf("EXPLORER") >= 0) {
		var Inicio = navigator.appVersion.indexOf(";") + 6;
		Browser = navigator.appVersion.substring(Inicio, navigator.appVersion.indexOf(";", Inicio) - 1);
		if (Browser >= 5) {
			window.print();
		} else {
			alert("Para imprimir pressione Ctrl+P");
		}
	} else {
		if (navigator.appName.toUpperCase().indexOf("NETSCAPE") >= 0) {
			Browser = navigator.appVersion.substring(0, 3);
			if (Browser >= 4.7) {
				window.print();
			} else {
				alert("Para imprimir pressione Ctrl+P");
			}
		} else {
			alert("Para imprimir pressione Ctrl+P");
		}
	}
}

// check functions
function checkDouble(key) {
	if (event.keyCode == 44) {
		event.keyCode = 46;
	}
	if (event.keyCode != 46 && (event.keyCode < 48 || event.keyCode > 57)) {
		event.keyCode = null;
	}
}
function checkText(key) {
}
function checkLong(key) {
	if (event.keyCode < 48 || event.keyCode > 57) {
		event.keyCode = null;
	}
}
function checkDouble(key) {
	if (event.keyCode < 48 || event.keyCode > 57) {
		if (event.keyCode == 44) {
			event.keyCode = 46;
		}
		if (event.keyCode != 46) {
			event.keyCode = null;
		}
	}
}
function checkDate(key) {
	if (event.keyCode != 45 && (event.keyCode < 47 || event.keyCode > 57)) {
		event.keyCode = null;
	}
}
function checkTime(key) {
	if (event.keyCode != 58 && (event.keyCode < 47 || event.keyCode > 57)) {
		event.keyCode = null;
	}
}
function isEmpty(obj) {
	if (obj.value.trim() == "") {
		return true;
	}
	return false;
}
function selectAllItem(listSource) {
	l1 = listSource.length;
	for (i = 0; i < l1; i++) {
		listSource.options[i].selected = true;
	}
}
function moveListItem(listSource, listDest) {
	l1 = listSource.length;
	for (i = 0; i < l1; i++) {
		if (listSource.options[i].selected == true) {
			l2 = listDest.length;
			achou = false;
			for (j = 0; j < l2; j++) {
				if (listSource.options[i].value == listDest.options[j].value) {
					achou = true;
					break;
				}
			}
			if (!achou) {
				listDest.options[l2] = new Option(listSource.options[i].text);
				listDest.options[l2].value = listSource.options[i].value;
			}
		}
	}
	for (i = l1 - 1; i >= 0; i--) {
		if (listSource.options[i].selected == true) {
			listSource.options[i] = null;
		}
	}
}
function moveAllListItem(listSource, listDest) {
	l1 = listSource.length;
	for (i = 0; i < l1; i++) {
		l2 = listDest.length;
		listDest.options[l2] = new Option(listSource.options[i].text);
		listDest.options[l2].value = listSource.options[i].value;
	}
	for (i = l1 - 1; i >= 0; i--) {
		listSource.options[i] = null;
	}
}
function readList(listSource, hiddenField) {
	l1 = listSource.length;
	r = "";
	for (i = 0; i < l1; i++) {
		r += listSource.options[i].value;
		if (i < (l1 - 1)) {
			r += ";";
		}
	}
	hiddenField.value = r;
}
function readListText(listSource, hiddenField) {
	l1 = listSource.length;
	r = "";
	for (i = 0; i < l1; i++) {
		r += listSource.options[i].text;
		if (i < (l1 - 1)) {
			r += ";";
		}
	}
	hiddenField.value = r;
}
function readListFull(listSource, hiddenField) {
	l1 = listSource.length;
	r = "";
	for (i = 0; i < l1; i++) {
		r += listSource.options[i].value + ";" + listSource.options[i].text;
		if (i < (l1 - 1)) {
			r += ";";
		}
	}
	hiddenField.value = r;
}
function open_help(page) {
	var janela = window.open(page, "help", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=500,height=480");
	janela.focus();
}

function maisDetalhes( div ) {
	if( document.getElementById(div).style.height == "1px" ) {
		document.getElementById(div).style.height="auto";
	} else {
		menosDetalhes(div);
	}
}
function menosDetalhes( div ) {
	document.getElementById(div).style.height="1";
}
function maisDetalhes2( div ) {
	document.getElementById(div).style.height="auto";
}

function desabilitarTela() {
	try {
		var h=document.body.clientHeight;
		if (document.body.scrollHeight > document.body.clientHeight) {
			h=document.body.scrollHeight;
		}
		
	    document.getElementById("graybox").style.height = h+"px";
		document.getElementById("graybox").style.visibility="visible";
	} catch (e) {
	}
}
function habilitarTela() {
	try {
		document.getElementById("graybox").style.visibility="hidden";
	} catch (e) {
	}
}

function desabilitarTela2() {
	try {
		var h=document.body.clientHeight;
		if (document.body.scrollHeight > document.body.clientHeight) {
			h=document.body.scrollHeight;
		}
		
	    document.getElementById("graybox2").style.height = h+"px";
		document.getElementById("graybox2").style.visibility="visible";
	} catch (e) {
	}
}
function habilitarTela2() {
	try {
		document.getElementById("graybox2").style.visibility="hidden";
	} catch (e) {
	}
}