/*		// Teste de form
		var x, texto;
		for (x in form)
			texto += x + '\t\t'
		alert(texto);
*/
// JavaScript Document

// Abre um popup
function newPopup (URL, nome, altura, largura) {
	window.open (URL,'','height=' + altura + ', width=' + largura);
}

function newPopupScrolling (URL, nome, altura, largura) {
	window.open (URL,'','scrollbars=yes, height=' + altura + ', width=' + largura);
}

// Serve para a paginaçao de dados
function vaiParaPagina (valor) {
	form.paginaAtual.value = valor;
	buscarForm();
}

function mudaItensPorPagina (valor) {
	form.itensPorPagina.value = valor;
	form.paginaAtual.value = 1;
	buscarForm();
}

function selecionaTodos(objCampoAtual, objCampos) {
	len=document.form.elements.length;
	if (objCampoAtual.checked) {
		for (i=0;i<len;i++){
			if (document.form.elements[i].type=='checkbox'){
				document.form.elements[i].checked=true;
			}
		}
	} else {
		for (i=0;i<len;i++){
			if (document.form.elements[i].type=='checkbox'){
				document.form.elements[i].checked=false;
			}
		}
	}
}

function buscarForm() {
	form.submit_consulta.value = "Buscar";
	form.submit();
}

function inserirForm() {
	form.submit_inserir.value = "Inserir";
	form.submit();
}

function validarForm() {
	form.submit_validar.value = "Validar";
	form.submit();
}


function excluirForm() {
	if (confirm('Deseja realmente excluir os itens selecionados?')) {
		form.submit_excluir.value = "Excluir";
		form.submit();
	}
	else {
		return;
	}
}

function alterarForm() {
	form.submit_alterar.value = "Alterar";
	form.submit();
}

function obtemAltura(id) {
	return document.getElementById(id).clientHeight;
}

function obtemLargura(id) {
	return document.getElementById(id).clientWidth;
}

function retornaValorPopup(campo, valor, nome) {
	var objValor = eval('window.opener.form.' + campo);
	objValor.value = nome;
	var objNome = eval('window.opener.form.' + campo + 'Id');
	objNome.value = valor;
	window.close();
}

function retornaValor(campo, valor) {
//	var x, y;
//	for (x in window.opener.form)
//		y += x + '\t';
//	alert(y);
	
	var objValor = eval('window.opener.form.' + campo);
	objValor.value = valor;
	window.close();
}

function abreJanela (caminho) {
	document.location = caminho;
}

function mostraDiv (obj) {
	if (obj.style.display == 'none')
		obj.style.display = 'block';
	else
		obj.style.display = 'none';
}

	// Qdo o mouse tá sobre o link
	function sublinha (obj) {
		obj.style.textDecoration = 'underline';
		obj.style.cursor = 'hand';
	} 
	function volta (obj){
		obj.style.textDecoration = 'none';
		obj.style.cursor = 'default';
	}
		function vaiPara(URL) {
		if (URL) {
			document.location = URL;
		}
	}
function DOMgetElementsByClassName($node,$className){
       /* Description: retorna um array com todos os elementos dentro
          de $node que possuam a classe indicada em $className
       Versão: 1.0 - 30/08/2006
       Author: Micox - Náiron J.C.G - micoxjcg@yahoo.com.br
       Site:   http://elmicox.blogspot.com 
       Não retire estas informações pra não infringir direitos autorais!
       */
    var $node, $atual, $className, $retorno = new Array(), $novos = new Array();
    $retorno = new Array();
    for (var $i=0;$i<$node.childNodes.length;$i++){
       $atual = $node.childNodes[$i];
       if($atual.nodeType==1){// 1 = XML_ELEMENT_NODE
          $classeAtual = $atual.className; 
          if(new RegExp("\\b"+$className+"\\b").test($classeAtual)){
             $retorno[$retorno.length] = $atual;
          }
          if($atual.childNodes.length>0){
             $novos = DOMgetElementsByClassName($atual,$className);
             if($novos.length>0){
                $retorno = $retorno.concat($novos);
             }
          }
       }
    }
    return $retorno;
    }

    function addEvent(obj, evType, fn){
       //adiciona evento, versao crossbrowser
       //retirado de http://elcio.com.br/crossbrowser/#7
       if (obj.addEventListener){
          obj.addEventListener(evType, fn, true)}
       if (obj.attachEvent){
          obj.attachEvent("on"+evType, fn)}
       }
function ativaHover(classe) {
            //ativa o hover para elementos n?o links, por causa de bug do IE
            //retirado de http://www.maujor.com/tutorial/ddownmenu-a.php
            var pais = DOMgetElementsByClassName(document.body,classe);
            for (var j=0; j<pais.length; j++) {
                        var sfEls = pais[j].getElementsByTagName("LI");
                        for (var i=0; i<sfEls.length; i++) {
                                   sfEls[i].onmouseover=function() {
                                               this.className+=" over";
                                   }
                                   sfEls[i].onmouseout=function() {
                                               this.className=this.className.replace(new RegExp(" over\\b"), "");
                                   }
                        }
            }
}

addEvent(window,"load",function () { ativaHover("menu-vv"); });
