function mudaEstilo(id, estilo)
{

	var obj = document.getElementById(id);
	
	obj.className = estilo;
}


function chkCpf (valor, elemento)
{
  var aux = "";
  var cpf = valor;

  //Extrai somente os dígitos decimais, retirando os caracteres '.' e '-'
  for (i = 0; i <= cpf.length - 1; i++)
  {
    if ((cpf.charAt(i)).match(/\d/))
      aux += cpf.charAt(i);
    else if (!(cpf.charAt(i)).match(/[\.\-]/))
      return false;
  }

  //Verifica o tamanho do campo
  if (aux.length != 11)
	{
    alert('O CPF informado é inválido!');
		document.forms[0].elements[elemento].value = "";
		document.forms[0].elements[elemento].focus();
		return false;
	}
	
  //Calcula os dois dígitos verificadores
  var soma1 = soma2 = 0;
  for (i = 0; i <= 8; i++)
  {
    soma1 += aux.charAt(i) * (10-i);
    soma2 += aux.charAt(i) * (11-i);
  }
  var d1 = ((soma1 * 10) % 11) % 10;
  var d2 = (((soma2 + (d1 * 2)) * 10) % 11) % 10;

  //Compara os dois dígitos verificadores
  if ((d1 != aux.charAt(9)) || (d2 != aux.charAt(10)))
  {
    alert('O CPF informado é inválido!');
		document.forms[0].elements[elemento].value = "";
		document.forms[0].elements[elemento].focus();
		return false;
	}
  //Se chegou até aqui, o CPF é válido
  return true;
}

function chkCnpj(valor, elemento)
{
  var aux = "";
  var cnpj = valor;
  //Extrai somente os dígitos decimais, retirando os caracteres '.', '/' e '-'
  for (i = 0; i <= cnpj.length - 1; i++)
  {
    if ((cnpj.charAt(i)).match(/\d/))
      aux += cnpj.charAt(i);
    else if (!(cnpj.charAt(i)).match(/[\.\/\-]/))
      return false;
  }

  //Verifica o tamanho do campo
  if (aux.length != 14)
	{
    alert('O CNPJ informado é inválido!');
		document.forms[0].elements[elemento].value = "";
		document.forms[0].elements[elemento].focus();
 		return false;
	}

  //O número não pode ser '00000000000000'
  if (aux == '00000000000000')
	{
    alert('O CNPJ informado é inválido!');
		document.forms[0].elements[elemento].value = "";
		document.forms[0].elements[elemento].focus();
 		return false;
	}

  //Calcula os dois dígitos verificadores
  var soma1 = soma2 = 0;
  for (i = 0; i < 12; i++)
  {
    soma1 += aux.charAt(11 - i) * (2 + (i % 8));
    soma2 += aux.charAt(11 - i) * (2 + ((i + 1) % 8));
  }
  var d1 = 11 - (soma1 % 11); if (d1 > 9) d1 = 0;
  soma2 += d1 * 2;
  var d2 = 11 - (soma2 % 11); if (d2 > 9) d2 = 0;

  //Checa os dígitos de verificação
  if (aux.charAt(12) != d1 || aux.charAt(13) != d2)
  {
    alert('O CNPJ informado é inválido!');
		document.forms[0].elements[elemento].value = "";
		document.forms[0].elements[elemento].focus();
 		return false;
  }
  
  return true;
}

//Push and pop for arrays is not implemented in Internet Explorer
if (!Array.prototype.push)
{
	Array.prototype.push = function array_push()
	{
		for(var i = 0; i < arguments.length; i++)
			this[this.length] = arguments[i];
		return this.length;
	}
}
if (!Array.prototype.pop)
{
	Array.prototype.pop = function array_pop()
	{
		lastElement = this[this.length - 1];
		this.length = Math.max(this.length - 1, 0);
		return lastElement;
	}
}

//Função que implementa o método trim para ser utilizado por qualquer String
String.prototype.ltrim = function()
{
	//Retira os caracteres no começo da String
	return this.replace(/^\s*/, "");
}

//Função que implementa o método rtrim para ser utilizado por qualquer String
String.prototype.rtrim = function()
{
	//Retira os caracteres no final da String
	return this.replace(/\s*$/, "");
}

//Função que implementa o método trim para ser utilizado por qualquer String
String.prototype.trim = function()
{
	//Retira os caracteres no começo e no final da String
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

//checa os campos obrigatórios q  não foram preenchidos
function checaCampo(form)
{
	for(i = 0; i < form.elements.length; i++)
	{
		valorCampo = form.elements[i].value.trim();
		nomeCampo  = form.elements[i].id;
		
		//Valida os campos de entrada requeridos
		if (valorCampo == "" && (form.elements[i].className == "campoEntrada requerido"))
		{
			alert('Erro: O campo "'+ nomeCampo +'" deve ser informado!');
			form.elements[i].focus();
			return false;
		}

		//Valida campos de entrada do tipo Radio
		if (form.elements[i].className == "campoRadio requerido")
		{
			var selecionado = false;
			var campos = document.getElementsByName(form.elements[i].name);
			for (var j = 0; j < campos.length; j++)
				if (campos[j].checked)
					selecionado = true;
			if (!selecionado)
			{
				alert('Erro: Uma das opções do campo "'+ nomeCampo +'" deve ser selecionada!');
				campos[0].focus();
				return false;
			}
		}
	}
	
	return true;
}  //fim função checaCampo

function limit(campo, limite)
{
	tamanho = campo.value.length;
	
	if(tamanho > limite)
	{
		alert('A quantidade máxima de caracteres não pode ser superior a ' + limite + '!');
		var aux = new String(campo.value);
		campo.value = aux.substring(0, limite);
	}
}

function limpaCampo(campo, vlr)
{
	campo.value = vlr;
}

function atribuiClasse(campo, classe)
{
	campo.className = classe;
}

//Oculta/Mostra elementos
function mostraCampo(item, vlrCampo, vlrComp)
{
	if (vlrCampo == vlrComp)
		item.style.display='inline';
	else
		item.style.display='none';
}

function mostraItem(item, item2)
{
	if (item.style.display == 'none')
	{
		item.style.display = 'inline';

		if(item2)
		{
			Aberto = new Image(16, 13) 
			item2.title = "Reduzir";
			Aberto.src = "imagens/icoTabAberta.gif"
			item2.src = Aberto.src
		}
	}
	else
	{
		item.style.display='none'
		if(item2)
		{
			Fechado = new Image(16, 13)
			item2.title = "Expandir";
			Fechado.src = "imagens/icoTabFechada.gif"
			item2.src = Fechado.src
		}
	}
}

//Abre popups no site
function openPopUp(url, alt, larg, barR)
{
	open(url, 'popup', 'statusbar=0, menubar=0, scrolling=0, scrollbars=' + barR +', height=' + alt + ', width=' + larg);
}

function abrePopUp(url, wind, alt, larg, barR)
{
	open(url, wind, 'statusbar=0, menubar=0, scrolling=0, scrollbars=' + barR +', height=' + alt + ', width=' + larg);
}

function geraSenha(campoNome, campoSenha)
{
	var s = "    Teste de trim   ";

	if(campoNome.value != '')
	{
		//A nova senha
		var senha = "";

		//Divide o nome usando o espaço como parâmetro
		var nome = new String(campoNome.value);
		var partes = nome.split(" ");

		//Pega a 1º letra de cada palavra
		for(var i = 0; i < partes.length; i++)
		{
			//Vai para o próximo loop se existir alguma preposição no nome
			switch (partes[i].toLowerCase())
			{
				case 'da':
				case 'das':
				case 'de':
				case 'do':
				case 'dos':
					continue;
			}

			senha += partes[i].substring(0, 1);
		} //fim for
		
		num = Math.round(Math.random() * 1000000) % 10000;
		
		senha += num;

		campoSenha.value = senha;
	} //fecha if
	else
	{
		window.alert("Favor preenher o campo '" + campoNome.id + "'!");
		campoNome.focus();
	}
} //fecha função geraSenha

//Menu Lateral --------------------------------------------
// Node object
function Node(id, pid, name, url, title, target, isopen, img){
	this.id			= id;
	this.pid		= pid;
	this.name		= name;
	this.url		= url;
	this.title      = title;
	this.target	    = target;
	this.img		= img;

	this._io		= isopen || false;
	this._ls		= false;
	this._hc		= false;
	this._is		= false;
}


// Tree object
function dTree(objName){

// Variables
// ----------------------------------------------------------------------------

	this.arrNodes		= [];
	this.arrRecursed	= [];
	this.arrIcons		= [];
	this.rootNode		= -1;
	this.strOutput		= '';
	this.selectedNode	= null;

	this.instanceName = objName;
	this.imgFolder 	  = '../imagens/sistema/imgMenu/';
	this.target 	  = null;
	this.hasLines     = true;
	this.clickSelect  = true;
	this.folderLinks  = true;
	this.useCookies   = true;


// Funções
// ----------------------------------------------------------------------------


	// Adds a new node to the node array
	this.add = function(id, pid, name, url, title, target, isopen, img)
	{
		this.arrNodes[this.arrNodes.length] = new Node(id, pid, name, url, title, target, isopen, img);
	}

	// Outputs the tree to the page
	this.draw = function()
	{
		if (document.getElementById)
		{
			this.preloadIcons();
			if (this.useCookies) this.selectedNode = this.getSelected();
			this.addNode(this.rootNode);

			document.writeln(this.strOutput);
		}
		else
		{
			document.writeln('Browser not supported.');
		}
	}

	this.openAll = function()
	{
		this.oAll(true);
	}

	this.closeAll = function()
	{
		this.oAll(false);
	}


// Private
// ----------------------------------------------------------------------------

	// Prealoads images that are used in the tree
	this.preloadIcons = function()
	{
		if (this.hasLines)
		{
			this.arrIcons[0] = new Image();
			this.arrIcons[0].src = this.imgFolder + 'plus.gif';
			this.arrIcons[1] = new Image();
			this.arrIcons[1].src = this.imgFolder + 'plusbottom.gif';
			this.arrIcons[2] = new Image();
			this.arrIcons[2].src = this.imgFolder + 'minus.gif';
			this.arrIcons[3] = new Image();
			this.arrIcons[3].src = this.imgFolder + 'minusbottom.gif';
		}
		else
		{
			this.arrIcons[0] = new Image();
			this.arrIcons[0].src = this.imgFolder + 'nolines_plus.gif';
			this.arrIcons[1] = new Image();
			this.arrIcons[1].src = this.imgFolder + 'nolines_plus.gif';
			this.arrIcons[2] = new Image();
			this.arrIcons[2].src = this.imgFolder + 'nolines_minus.gif';
			this.arrIcons[3] = new Image();
			this.arrIcons[3].src = this.imgFolder + 'nolines_minus.gif';
		}
		this.arrIcons[4] = new Image();
		this.arrIcons[4].src = this.imgFolder + 'folder.gif';
		this.arrIcons[5] = new Image();
		this.arrIcons[5].src = this.imgFolder + 'folderopen.gif';
	}

	// Recursive function that creates the tree structure
	this.addNode = function(pNode)
	{
		for (var n=0; n<this.arrNodes.length; n++)
		{
			if (this.arrNodes[n].pid == pNode)
			{
				var cn = this.arrNodes[n];
				cn._hc = this.hasChildren(cn);
				cn._ls = (this.hasLines) ? this.lastSibling(cn) : false;
				if (cn._hc && !cn._io && this.useCookies) cn._io = this.isOpen(cn.id);

				if (this.clickSelect && cn.id == this.selectedNode)
				{
						cn._is = true;
						this.selectedNode = n;
				}

				if (!this.folderLinks && cn._hc) cn.url = null;


				// If the current node is not the root
				if (this.rootNode != cn.pid)
				{
					// Write out line & empty icons
					for (r=0; r<this.arrRecursed.length; r++)
						this.strOutput += '<img src="' + this.imgFolder + ( (this.arrRecursed[r] == 1 && this.hasLines) ? 'line' : 'empty' ) + '.gif" alt="" />';

					// Line & empty icons
					(cn._ls) ? this.arrRecursed.push(0) : this.arrRecursed.push(1);

					// Write out join icons
					if (cn._hc)
					{
						this.strOutput += '<a href="javascript: ' + this.instanceName + '.o(' + n + ');">'
							+ '<img id="j' + this.instanceName + n + '" src="' + this.imgFolder;
						if (!this.hasLines)
							this.strOutput += 'nolines_';

						this.strOutput += ( (cn._io) ? ((cn._ls && this.hasLines) ? 'minusbottom' : 'minus') : ((cn._ls && this.hasLines) ? 'plusbottom' : 'plus' ) )
							+ '.gif" alt="" /></a>';
					}
					else
						this.strOutput += '<img src="' + this.imgFolder + ( (this.hasLines) ? ((cn._ls) ? 'joinbottom' : 'join' ) : 'empty') + '.gif" alt="" />';
				}

				// Start the node link
				if (cn.url)
				{
					this.strOutput += '<a href="' + cn.url + '"';
					if (cn.title) this.strOutput += ' title="' + cn.title + '"';
					if (cn.target) this.strOutput += ' target="' + cn.target + '"';
					if (this.target && !cn.target) this.strOutput += ' target="' + this.target + '"';

					// If hightlight link is on
					if (this.clickSelect)
					{
						if (cn._hc)
						{
							if (this.folderLinks)
								this.strOutput += ' onclick="javascript: ' + this.instanceName + '.s(' + n + ');"';
						}
						else
						{
							this.strOutput += ' onclick="javascript: ' + this.instanceName + '.s(' + n + ');"';
						}
					}

					this.strOutput += '>';
				}
				if ((!this.folderLinks || !cn.url) && cn._hc && cn.pid != this.rootNode)
				{
					this.strOutput += '<a href="javascript: ' + this.instanceName + '.o(' + n + ');">';
				}

				// Write out folder & page icons
				this.strOutput += '<img id="i' + this.instanceName + n + '" src="' + this.imgFolder;
				this.strOutput += (cn.img) ? cn.img : ((this.rootNode == cn.pid) ? 'base' : (cn._hc) ? ((cn._io) ? 'folderopen' : 'folder') : 'page') + '.gif';
				this.strOutput += '" alt="" />';

				// Write out span
				this.strOutput += '<span id="s' + this.instanceName + n + '" class="' + ((this.clickSelect) ? ((cn._is ? 'nodeSel' : 'node')) : 'node') + '">';


				// Write out node name
				this.strOutput += cn.name;

				this.strOutput += '</span>';

				// Close the link
				if (cn.url || (!this.folderLinks && cn._hc)) this.strOutput += '</a>';

				this.strOutput += '<br />\n';

				// If node has children write out divs and go deeper
				if (cn._hc)
				{
					this.strOutput += '<div id="d' + this.instanceName + n + '" style="display:'
					+ ((this.rootNode == cn.pid || cn._io) ? 'block' : 'none')
					+ ';">\n';
					this.addNode(cn.id);
					this.strOutput += '</div>\n';
				}
				this.arrRecursed.pop();
			}
		}
	}

	// Checks if a node has any children
	this.hasChildren = function(node)
	{
		for (n=0; n<this.arrNodes.length; n++)
			if (this.arrNodes[n].pid == node.id) return true;
		return false;
	}

	// Checks if a node is the last sibling
	this.lastSibling = function(node)
	{
		var lastId;
		for (n=0; n< this.arrNodes.length; n++)
			if (this.arrNodes[n].pid == node.pid) lastId = this.arrNodes[n].id;
		if (lastId==node.id) return true;
		return false;
	}

	// Checks if a node id is in a cookie
	this.isOpen = function(id)
	{
		openNodes = this.getCookie('co' + this.instanceName).split('.');
		for (n=0;n<openNodes.length;n++)
			if (openNodes[n] == id) return true;
		return false;
	}

	// Checks if the node is selected
	this.isSelected = function(id)
	{
		selectedNode = this.getCookie('cs' + this.instanceName);
		if (selectedNode)
		{
			if (id==selectedNode)
			{
				this.selectedNode = id;
				return true
			}
		}
		return false;
	}

	// Returns the selected node
	this.getSelected = function()
	{
		selectedNode = this.getCookie('cs' + this.instanceName);
		if (selectedNode)	return selectedNode;
		return null;
	}

	// Highlights the selected node
	this.s = function(id)
	{
		cn = this.arrNodes[id];
		if (this.selectedNode != id)
		{
			if (this.selectedNode)
			{
				eOldSpan = document.getElementById("s" + this.instanceName + this.selectedNode);
				eOldSpan.className = "node";
			}

			eNewSpan = document.getElementById("s" + this.instanceName + id);
			eNewSpan.className = "nodeSel";

			this.selectedNode = id;
			if (this.useCookies) this.setCookie('cs' + this.instanceName, cn.id);
		}
	}

	// Toggle Open or close
	this.o = function(id)
	{
		cn = this.arrNodes[id];

		(cn._io) ? this.nodeClose(id,cn._ls) : this.nodeOpen(id,cn._ls);
		cn._io = !cn._io;

		if (this.useCookies) this.updateCookie();
	}

	// Open or close all nodes
	this.oAll = function(open)
	{
		for (n=0;n<this.arrNodes.length;n++)
		{
			if (this.arrNodes[n]._hc && this.arrNodes[n].pid != this.rootNode)
			{
				if (open)
				{
					this.nodeOpen(n, this.arrNodes[n]._ls);
					this.arrNodes[n]._io = true;
				}
				else
				{
					this.nodeClose(n, this.arrNodes[n]._ls);
					this.arrNodes[n]._io = false;
				}
			}
		}
		if (this.useCookies) this.updateCookie();
	}

	// Open a node
	this.nodeOpen = function(id, bottom)
	{
		eDiv	= document.getElementById('d' + this.instanceName + id);
		eJoin	= document.getElementById('j' + this.instanceName + id);
		eIcon	= document.getElementById('i' + this.instanceName + id);
		eJoin.src = (bottom) ?  this.arrIcons[3].src : this.arrIcons[2].src;
		if (!this.arrNodes[id].img) eIcon.src = this.arrIcons[5].src;
		eDiv.style.display = 'block';
	}

	// Close a node
	this.nodeClose = function(id, bottom)
	{
		eDiv	= document.getElementById('d' + this.instanceName + id);
		eJoin	= document.getElementById('j' + this.instanceName + id);
		eIcon	= document.getElementById('i' + this.instanceName + id);
		eJoin.src = (bottom) ? this.arrIcons[1].src : this.arrIcons[0].src;
		if (!this.arrNodes[id].img) eIcon.src = this.arrIcons[4].src;
		eDiv.style.display = 'none';
	}

	// Clears a cookie
	this.clearCookie = function()
	{
		var now = new Date();
		var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
		this.setCookie('co'+this.instanceName, 'cookieValue', yesterday);
		this.setCookie('cs'+this.instanceName, 'cookieValue', yesterday);
	}

	// Sets value in a cookie
	this.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
		document.cookie =
			escape(cookieName) + '=' + escape(cookieValue)
			+ (expires ? '; expires=' + expires.toGMTString() : '')
			+ (path ? '; path=' + path : '')
			+ (domain ? '; domain=' + domain : '')
			+ (secure ? '; secure' : '');
	}

	// Gets a value from a cookie
	this.getCookie = function(cookieName) {
		var cookieValue = '';
		var posName = document.cookie.indexOf(escape(cookieName) + '=');
		if (posName != -1)
		{
			var posValue = posName + (escape(cookieName) + '=').length;
			var endPos = document.cookie.indexOf(';', posValue);
			if (endPos != -1)
				cookieValue = unescape(document.cookie.substring(posValue, endPos));
			else
				cookieValue = unescape(document.cookie.substring(posValue));
		}
		return (cookieValue);
	}

	// Returns ids of open nodes as a string
	this.updateCookie = function()
	{
		sReturn = '';
		for (n=0;n<this.arrNodes.length;n++)
		{
			if (this.arrNodes[n]._io && this.arrNodes[n].pid != this.rootNode)
			{
				if (sReturn) sReturn += '.';
				sReturn += this.arrNodes[n].id;
			}
		}
		this.setCookie('co' + this.instanceName, sReturn);
	}

// tree object ends
}


// Fim do menu lateral
// ------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------
//Início das funções para o tratamento de tabview
function tabview_aux(TabViewId, id)
{
   var TabView = document.getElementById(TabViewId);
   
   // ----- Abas -----
   
   var Tabs = TabView.firstChild;
   while (Tabs.className != "Tabs" ) Tabs = Tabs.nextSibling;
   
   var Tab = Tabs.firstChild;
   var i   = 0;
   
   do
   {
      if (Tab.tagName == "A")
      {
         i++;
         Tab.href      = "javascript:tabview_switch('"+TabViewId+"', "+i+");";
         Tab.className = (i == id) ? "Active" : "";
         Tab.blur();
      }
   } while (Tab = Tab.nextSibling);
   
   // ----- Páginas -----
   
   var Pages = TabView.firstChild;
   while (Pages.className != 'Pages') Pages = Pages.nextSibling;
   
   var Page = Pages.firstChild;
   var i = 0;
   
   do
   {
      if (Page.className == 'Page')
      {
         i++;
         if (Pages.offsetHeight) Page.style.height = (Pages.offsetHeight - 2) + "px";
         Page.style.overflow = "auto";
         Page.style.display  = (i == id) ? 'block' : 'none';
      }
   } while (Page = Page.nextSibling);

	if (id == 1)
		document.getElementById("btnAnterior").disabled = true;
	else
		document.getElementById("btnAnterior").disabled = false;
	if (i == id)
		document.getElementById("btnProximo").disabled = true;
	else
		document.getElementById("btnProximo").disabled = false;
}

// ----- Funções -------------------------------------------------------------

function tabview_switch(TabViewId, id)
{
   document.getElementById("paginaAtual").value = id;

   tabview_aux(TabViewId, id);
}

//Utilizar sempre esta função desta forma: tabview_initialize('TabView');
//Pode ser utilizado um bloco javascript para carregar as abas no meio do documento.
function tabview_initialize(TabViewId)
{
   tabview_switch(TabViewId,  1);
}

function abrePagina(proximo)
{
	var paginaAtual = document.getElementById("paginaAtual");
	var pagAtual = parseInt(paginaAtual.value);
	
	if (proximo)
		pagAtual++;
	else
		pagAtual--;
	
	tabview_switch("TabView", pagAtual);
}
//Fim das funções para o tratamento de tabview
//-------------------------------------------------------------------------------------------

//Não utilizar mais, deve-se usar atribuiClasse
function atribuiValor(campo, vlr)
{
	campo.flag = vlr;
}

function mascara(mascara, vlr, campo, frm)
{
  vlr = removeMask(vlr);
  tam = vlr.length;
  tamMask = mascara.length;
  resp = '';
  i = tam - 1;
  j = tamMask - 1;
  while (j >= 0 && i >= 0){
    if (i < tamMask){
      if (mascara.charAt(j) != '9'){
	    resp = mascara.charAt(j) + resp;
	  }
	  else{
	    resp = vlr.charAt(i) + resp;
		i--;
	  }
		j--;
	}
	else{
	  resp = vlr.charAt(i) + resp;
	  i--;
	}
  }//fecha while
  document.forms[frm].elements[campo].value = resp;
}//fim function mascara valor moeda

//remove as máscaras
function removeMask(vlr)
{
  vlr = vlr.replace(",","");
  vlr = vlr.replace("-","");
  vlr = vlr.replace("/","");
  
  for(x=1; x<=5; x++)
  {
    vlr = vlr.replace(".","");
  }
  return vlr;
}

//remove um caracter especifico passado via parametro
function removeCaracter(caracter, campo, form)
{

	var vlrAux = document.forms[form].elements[campo].value;

	var vlr = vlrAux.replace(caracter, "");
	
	document.forms[form].elements[campo].value = vlr;
		
}

//Formata o cpf. --> Revisar
function maskCPF(cpf, elemento)
{
   var mycpf = ''; 
   mycpf = mycpf + cpf;
   
   if (mycpf.length == 3)
   { 
      mycpf = mycpf + '.'; 
      document.forms[0].elements[elemento].value = mycpf; 
   }
   if (mycpf.length == 7)
   { 
      mycpf = mycpf + '.'; 
      document.forms[0].elements[elemento].value = mycpf; 
   } 
   if (mycpf.length == 11)
   { 
      mycpf = mycpf + '-'; 
      document.forms[0].elements[elemento].value = mycpf; 
   } 
   if (mycpf.length == 14)
   { 
   	  //terminou de digitar vai checar a validade do CPF
	  checaCPF(mycpf);
   } 
} //fecha função maskCPF 

//formata os campos de data --> Revisar
//1º parâmetro é o valor, o 2º a posição do campo
function maskData(data, elemento)
{
   //numero(elemento);
   var mydata = ''; 
   mydata = mydata + data; 

   if (mydata.length == 2)
   { 
      mydata = mydata + '-'; 
      document.forms[0].elements[elemento].value = mydata; 
   } 
   if (mydata.length == 5)
   { 
      mydata = mydata + '-'; 
      document.forms[0].elements[elemento].value = mydata; 
   } 
   if (mydata.length == 10)
   { 
      //verificaData(elemento); 
   } 
} //fecha função maskData

function formataData(data, elemento)
{
   var mydata = ''; 
   mydata = mydata + data; 
	
   if (mydata.length == 2)
   { 
      mydata = mydata + '-'; 
      document.getElementById(elemento).value = mydata
   } 
   if (mydata.length == 5)
   { 
      mydata = mydata + '-'; 
      document.getElementById(elemento).value = mydata
   } 
   if (mydata.length == 10)
   { 
      //verificaData(elemento); 
   } 
} 

function mostraDiv(item)
{
	alert(item);
}

//submete o formulário
function frmSubmit(frm)
{
	frm.submit();
}

//submete o formulário
function frmSubmitAcao(frm, acao)
{
	frm.action = "?pg=" + acao;
	frm.submit();
}

//só deixa preencher os campos numéricos com os valores especificados na variável numeros
function isNumero(elemento, frm)
{
   var numeros = "/-,.0123456789";
   var temp;
   var campo;
   campo = document.forms[frm].elements[elemento].value;
   nome = document.forms[frm].elements[elemento].id;

   for (var i=0; i < campo.length; i++)
   {
      temp = campo.substring(i,i+1);
      if (numeros.indexOf(temp)==-1)
	  {
         alert("O campo " + nome + " deve possuir apenas valores numéricos!");
         document.forms[frm].elements[elemento].value = "";
		 document.forms[frm].elements[elemento].focus();
         return false;
      }
   }		   
   return true;
} //fim função numero

//checa se o cpf é válido
function checaCPF(VAL)
{
	VAL = removeMask(''+ VAL + '');

   if (VAL.length != 11 || VAL == "00000000000" || VAL == "11111111111" ||
      VAL == "22222222222" || VAL == "33333333333" || VAL == "44444444444" ||
	  VAL == "55555555555" || VAL == "66666666666" || VAL == "77777777777" ||
	  VAL == "88888888888" || VAL == "99999999999"){
	  return false;
	  }
	  soma = 0;
	  
	for (i=0; i < 9; i ++)
	   soma += parseInt(VAL.charAt(i)) * (10 - i);
	   resto = 11 - (soma % 11);

	if (resto == 10 || resto == 11)
		resto = 0;
	
	if (resto != parseInt(VAL.charAt(9)))
		return false;
	soma = 0;
	
	for (i = 0; i < 10; i ++)
		soma += parseInt(VAL.charAt(i)) * (11 - i);
		
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(VAL.charAt(10))){
		return false;
		}
	return true;
}//fim cpf

//função para colocar máscara em valores monetários
function formataMoeda(mascara, vlr)
{
	vlr = removeMask(''+ vlr + '');
	tam = vlr.length;

	tamMask = mascara.length;

	resp = '';
	i = tam - 1;
	j = tamMask - 1;
	while (j >= 0 && i >= 0)
	{
		if (i < tamMask)
		{
			if (mascara.charAt(j) != '9')
			{
				resp = mascara.charAt(j) + resp;
			}
			else
			{
				resp = vlr.charAt(i) + resp;
				i--;
			}

			j--;
		}
		else
		{
			resp = vlr.charAt(i) + resp;
			i--;
		}
	}//fecha while

	return resp;
}//fim function mascara valor moeda




<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//-->
