// JavaScript Document

<!--jumpmenu
function MM_jumpMenu(targ,selObj,restore, url){ //v3.0
if(url != undefined) open(url, '', '_blank');
else
   eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->

//script para carregamento das paginas
function loadMsg(){
var el=document.getElementById('loading_page');
el.style.display="none";
}


// attach event after page loads
if( window.addEventListener ) {
window.addEventListener('load',loadMsg,false); //legacy
} else if( document.addEventListener ) {
document.addEventListener('load',loadMsg,false); //proper
} else if( window.attachEvent ) {
window.attachEvent("onload", loadMsg); //IE only
}

// confirma um comando de exclusão e chama o submitForm
function confirmar(msg, cmd) {
	if (confirm(msg)) 
	location.href=(cmd);
}


function abre(url,janela,larg,alt,scroll,pos1,pos2){
window.open(url,janela,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scroll+',resizable=no,copyhistory=no,top='+pos1+',left='+pos2+',screenY='+pos1+',screenX='+pos2+',width='+larg+',height='+alt);
}


function menu_over(src,clrOver) {
 if (!src.contains(event.fromElement)) {
  src.style.cursor = 'hand';
  src.bgColor = clrOver;
 }
}
function menu_out(src,clrIn) {
 if (!src.contains(event.toElement)) {
  src.style.cursor = 'default';
  src.bgColor = clrIn;
 }
}

function janela(param,w,h,nome) {
   var nomearq = param;
   var windowvar = window.open(nomearq,nome,"scrollbars=yes,location=no,directories=no,status=yes,menubar=no,resizable=no,toolbar=no,top=0,left=0,width="+ w + ",height=" +h );
}

function erro(msg) {
	alert(msg);
	return false;
}

function erro_focus(msg, obj) {
	alert(msg);
	obj.focus();
	return false;
}

//valida data
function validDate(obj){
 date=obj.value
if (/[^\d/]|(\/\/)/g.test(date))  {obj.value=obj.value.replace(/[^\d/]/g,'');obj.value=obj.value.replace(/\/{2}/g,'/'); return }
if (/^\d{2}$/.test(date)){obj.value=obj.value+'/'; return }
if (/^\d{2}\/\d{2}$/.test(date)){obj.value=obj.value+'/'; return }
if (!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(date)) return

 test1=(/^\d{1,2}\/?\d{1,2}\/\d{4}$/.test(date))
 date=date.split('/')
 d=new Date(date[2],date[1]-1,date[0])
 test2=(1*date[0]==d.getDate() && 1*date[1]==(d.getMonth()+1) && 1*date[2]==d.getFullYear())
 if (test1 && test2) return true
 alert("Data inválida")
 obj.select();
 obj.focus()
 return false
}

// verifica o email digitado.
function emailValido(mail) {
	return mail.match(/[0-9A-Za-z\.\_\-]+\@{1,1}[0-9A-Za-z\_\-]+\.{1,1}[0-9A-Za-z\_\-]+/);
}

// retorna se um campo está vazio desconsiderando espaços no início e no final
function vazio(valor) {
	s = new String(valor);
	s = s.replace(/^ +/, '');
	s = s.replace(/ +$/, '');
	return s.length == 0;
}

// retorna se um identificador contém apenas caracteres válidos
function idValido(id) {
	s = new String(id);
	validos = new String('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_');
	valido = true;
	for (i = 0; i < s.length; i++) valido = valido && validos.indexOf(s.charAt(i)) != -1;
	return valido && !vazio(id);
}




/* limpa form */
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
} 


/* limpa form e restaura padrões se nada for inserido */
function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}
function clickrecall(thisfield, defaulttext) {
if (thisfield.value == "") {
thisfield.value = defaulttext;
}
}


/* marcar todos */
function MarcarTodos(){
var nb;
var chk; 
if (document.formexclui.marcatodas.value == 0) { 
chk=1 
} else { 
chk=0 
} 
nb = document.formexclui.selecao.length 
for (var i=0;i<nb;i++) {
var e = document.formexclui.selecao[i];
e.checked = chk
} 
document.formexclui.marcatodas.value = chk;
}


//mostrar ou esconder div
function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}


/* selecionar com shift */
/*
var lastChecked = null;

        $(document).ready(function() {
                $('.chkbox').click(function(event) {
                        if(!lastChecked) {
                                lastChecked = this;
                                return;
                        }

                        if(event.shiftKey) {
                            var start = $('.chkbox').index(this);
                            var end = $('.chkbox').index(lastChecked);

                            for(i=Math.min(start,end);i<=Math.max(start,end);i++) {
                                        $('.chkbox')[i].checked = lastChecked.checked;
                                }
                        }

                        lastChecked = this;
                });
});
*/