function menu(cod){
	switch(cod){
		case 0:	location.href = "http://www.royaltiesdopetroleo.ucam-campos.br/index.php"; break;
		case 1: location.href = "http://www.royaltiesdopetroleo.ucam-campos.br/index.php?cod=1"; break;
		case 2: location.href = "index.php"; break;
		case 3: location.href = "http://www.royaltiesdopetroleo.ucam-campos.br/index.php?cod=3"; break;
		case 4: location.href = "http://www.royaltiesdopetroleo.ucam-campos.br/index.php?cod=4"; break;
	}
}

function selStatus(cod_controle){
	document.forms['frm_status'].cod_controle.value = cod_controle;
	document.forms['frm_status'].submit();
}


function esconderSpan(item){
	item.style.display='none';
}

function mostrarSpan(item){
	item.style.display='';
}
function marcarRadio(item){
	item.checked="true";
}

function mOvr(src,clrOver) {
	if (!src.contains(event.fromElement)){
		src.style.cursor = 'hand';
		src.bgColor = clrOver;
	}
}

function mOut(src,clrIn) {
	if (!src.contains(event.toElement)){
		src.style.cursor = 'default';
		src.bgColor = clrIn;
	}
}

function opcao(op){
	document.forms['formOpcao'].cod_controle.value = 2;
	document.forms['formOpcao'].cod_opcao.value = op;
	document.forms['formOpcao'].submit();
}

function beneficiario(op){
	if ((op=="estados") || (op=="municipios")){
		document.forms['formBeneficiario'].cod_controle.value = 2;
	}
    else if (op=="total"){
			document.forms['formBeneficiario'].cod_controle.value = 4;
	}
	else{
		document.forms['formBeneficiario'].cod_controle.value = 3;
	}
	document.forms['formBeneficiario'].cod_selecao.value = op;
	document.forms['formBeneficiario'].submit();
}


function validaBeneficiario(nform){
	marcado = -1;
	for (i=0; i<nform.elements.length; i++) {
		if (nform.elements[i].checked) {
			marcado++;
		}
	}
	if (marcado == -1) {
		alert("Selecione uma das opções.");
		return false;
	}
	if (marcado>=1000){
		alert("Você selecionou "+marcado+" beneficiarios.\n\nNão é permitido selecionar mais de 900 beneficiários de uma vez.");
		return false;
	}
	return true;
}

function marcarTodos(nform){
	for (i=0; i<nform.elements.length; i++) {
		nform.elements[i].checked = true;
	}
}

function desmarcarTodos(nform){
	for (i=0; i<nform.elements.length; i++) {
		nform.elements[i].checked = false;
	}
}



function validaPeriodo(nform){
	//Opcao mensal
	if((nform.cod_tempo.value=='mensal') && (nform.ano_inicial.value==nform.ano_final.value)){
		if(nform.mes_final.value < nform.mes_inicial.value){
			alert ("Mês/Trimestre Inicial maior do que Mês/Trimestre Final.");
			return false;
		}
	}
	
	//Opcao trimestral
	if((nform.cod_tempo.value=='trimestral') && (nform.ano_inicial.value==nform.ano_final.value)){
		if(nform.mes_final.value < nform.mes_inicial.value){
			alert ("Trimestre Inicial maior do que Trimestre Final.");
			return false;
		}
	}

	//Todas opcoes
	if(nform.ano_final.value < nform.ano_inicial.value){
		alert ("Ano Inicial maior do que Ano Final.");
		return false;
	}
	return true;
}



function marcar(id_check, id_td) {
	document.getElementById(id_check).checked=!document.getElementById(id_check).checked;	
}

function abrir(URL) {

   var width = 800;
   var height = 420;

   var left = 99;
   var top = 99;

   window.open(URL,'Grafico', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

function checkAll(nform) {
	var f = nform;
	var c = f.toggle.checked;
	var n2 = 0;
	for (i=0; i < f.elements.length; i++) {
		cb = eval( 'f.cb' + i );
		if (cb) {
			cb.checked = c;
			n2++;
		}
	}
}

function checkId(id) {
	document.getElementById(id).checked = !document.getElementById(id).checked;	
}