/** Equipe de Desenvolvimento **/

function submeter_form(axnmformul,axidform){
	axnmformul.submit();
}


function submeter_atividade(axatividade){
	parent.index_conteudo.document.location.href='atividades.jsp?axatividade=' + axatividade;
}

function zerar_regressiva(){
//	alert(parent.index_titulo.document.all.frmtimer);
	if (parent.index_titulo.document.all.frmtimer=='[object]'){
		parent.index_titulo.frmtimer.segundos.value=0;
	}
}

function valida_email(z){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(z)){
		return true;
	}
	alert('E-mail inválido !');
	return false;
}

function testa_enter(key,axform,axtpacao) {
	if (key==13) {
		submeter_form(axform,axtpacao);
	}
}

function tabsetup () {
	for(var i=0; i < numDiv; i++) {
		var panelDiv = document.getElementById(panelID+"panel"+i);
		var tabDiv = document.getElementById(panelID+"tab"+i);

		panelDiv.style.width = panelWidth;
		panelDiv.style.height = panelHeight;
		panelDiv.style.top = panelTop;
		panelDiv.style.left = tabLeft;
		tabDiv.style.height = tabHeight;
		tabDiv.style.width = tabWidth;
		tabDiv.style.left = panelDiv.style.pixelLeft + (i * tabWidth) + tabDivLeft;
		tabDiv.style.top = tabTop;

	}
}

function selectTab(n) {
	document.all.pform.pagina.value = n;
	for(var i=0; i < numDiv; i++) {
		var panelDiv = document.getElementById(panelID+"panel"+i);
		var tabDiv = document.getElementById(panelID+"tab"+i);
		var tdle = document.getElementById("pltdle"+i);
		var tdimg = document.getElementById("pltdimg"+i);
		var tdld = document.getElementById("pltdld"+i);
		var tdlex = document.getElementById("pltdle"+i+i);
		var tdlix = document.getElementById("pltdli"+i+i);
		var tdldx = document.getElementById("pltdld"+i+i);

		if (i==n) {
			tabDiv.style.zIndex = 9;
			tdle.className = 'tdlesel';
			tdimg.className = 'tdsel';
			tdld.className = 'tdldsel';
			tdlex.className = 'ce_aba_ati';
			tdlix.className = 'li_aba_ati';
			tdldx.className = 'cd_aba_ati';
			panelDiv.style.zIndex = 5;
			tabDiv.className = 'tabsel';
			panelDiv.style.visibility = 'visible'
		}
		else {
			tabDiv.style.zIndex = 3; //i+1;
			tdle.className = 'tdlenaosel';
			tdimg.className = 'tdnaosel';
			tdld.className = 'tdldnaosel';
			tdlex.className = 'ce_aba_desati';
			tdlix.className = 'li_aba_desati';
			tdldx.className = 'cd_aba_desati';
			panelDiv.style.zIndex = 5; //i+1;
			tabDiv.className = 'tabsel2';
			panelDiv.style.visibility = 'hidden'
		}
	}
}

function setar_layer(n){
	tabsetup();
	selectTab(n); // Indica o layer default
}

function exibir_login(idobj,ctrl){
	var tblogin = document.getElementById(idobj);
	ctrl = ctrl * 1000;
	setTimeout('show_login(tblogin)', ctrl);
}

function show_login(obj){
	obj.style.visibility = 'visible';
//	document.frmlogin.usuario.focus();
}


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_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_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;
}

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 btover(obj){
	obj.focus();
}

function btout(obj){
	obj.blur();
}

function logout(page){
	parent.top.location=page;
}

var theValue = 0;
function doIframe(sVal){
	theValue = ( typeof(sVal) != "undefined") ? sVal : theValue;
	try{if(parent.document.frames["FRAMENAME"].document.readyState){}}
		catch(e){setTimeout("doIframe()",1000);return;} // Error Check again in 1 sec
	if(parent.document.frames["FRAMENAME"].document.readyState == "complete")
	{
		parent.document.frames["FRAMENAME"].document.forms[0].INPUTNAME.value =
		theValue;
		// etc
	}
	else setTimeout("doIframe()",1000); // Not ready try in 1 sec again
}

function currencyFormat(fld, milSep, decSep, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true; // Enter

    //fld.value = whichCode+' ';  use para saber o valor da tecla pressionada whichCode

	if (whichCode == 0)  // Delete
    {
        fld.value = '0'+ decSep + '00';
	}	
	
	if (whichCode == 8)  // Backspace
    {
	    len = fld.value.length;
	    len = len-1
	    for(i = 0; i<len; i++)
		    if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	    aux = '';
	    for(; i < len; i++)
		    if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	}
	else
	{
	    key = String.fromCharCode(whichCode); // Get key value from key code
	    if (strCheck.indexOf(key) == -1) return false; // Not a valid key
	    len = fld.value.length;
	    for(i = 0; i<len; i++)
		    if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	    aux = '';
	    for(; i < len; i++)
		    if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	    aux += key;
	}
	len = aux.length;
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len > 2) 
	{
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) 
		{
			if (j == 3) 
			{
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		if (aux2.length > 15) return false; 
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
			fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}

function DecimalFormat(fld, qtDec, e) {
	var milSep = '.'
	var decSep = ','
	var sep = 0;
	var key = '';
	var i = j = k = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	var zeros = '';
	if (whichCode == 13) return true; // Enter
	key = String.fromCharCode(whichCode); // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false; // Not a valid key
	len = fld.value.length;
	for(i = 0; i<len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) fld.value = '';
	for(k = 0; k < qtDec; k++)
		zeros += '0';
	if ((len > 0) && (len <= qtDec)) fld.value = '0'+ decSep + zeros.substr(1,qtDec-len) + aux;
	if (len > qtDec) 
	{
		aux2 = '';
		for (j = 0, i = (len - (qtDec + 1)); i >= 0; i--) 
		{
			if (j == 3) 
			{
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		if (aux2.length > 15) return false; 
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
			fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - qtDec, len);
	}
	return false;
}

function VerificaFoco()
{
	var form = document.FormPrecificarEnvelope;
	form.txtCodigoBarras.value = form.txtAux1.value;
	var CodigoBarras = form.txtCodigoBarras.value;
	var len = CodigoBarras.length;
	if (len < 8)
	{
		form.txtCodigoBarras.focus();
	}
	else
	{
		
		if (form.txtCodigoCliente.value=='')
		{
			form.txtCodigoCliente.focus();
		}
		else if (form.txtCodigoBarrasItem.value=='')
		{
			form.txtCodigoBarrasItem.focus();
		}
		else if (form.txtCodigoItem.value == '')
		{
			form.txtCodigoItem.focus();
		}
		else
		{
			form.txtQuantidade.focus();
		}
	}
	ValidaCodigoBarras(document.FormPrecificarEnvelope);
	VerificaStatusEnvelope();
	ValidaCliente();
	ValidaItem();
	ValidaConfirmacao();

}

function TamanhoCodigoBarras()
{
	form = document.FormPrecificarEnvelope;
	var CodigoBarras = form.txtCodigoBarras.value;
	var len = CodigoBarras.length;
	if (len < 8)
	{
		if (len > 0)
		{
			alert('Codigo de Barras Invalido');
		}
		form.txtCodigoBarras.focus();
	}
}

function ValidaCodigoBarras(form)
{
	var valida;
	if (form.txtAux2.value=='1')
	{
		form.txtCodigoBarras.select();
		valida = false;
	}
	
	if (form.txtAux2.value=='2')
	{
		form.txtCodigoBarrasItem.select();
		valida = false;
	}
		
	if (valida==false)
	{
		alert('Codigo de Barras Invalido');
	}
}
function RecebeFoco(obj)
{
	obj.select();
}
function VerificaStatusEnvelope()
{
	form = document.FormPrecificarEnvelope;
	var valida = true;
	
	//Verifica se o status é Liberado para Venda
	if (form.txtAux2.value=='200')
	{
		alert('Envelope ja foi Precificado e esta Liberado para Venda');
		valida = false;
	}
	
	//Verifica se a unidade de negócio é Válida
	if (form.txtAux2.value=='UNIDADEINVALIDA')
	{
		alert('A Unidade de Negocio Deste Envelope e Invalida');
		valida = false;
	}
		
	if (!valida)
	{
		form.txtCodigoBarras.value = '';
		form.txtAux1.value = '';
		form.txtAux2.value = '';
		form.txtCodigoBarras.focus();
	}
}
function ValidaCliente() //Verifica se foi retornado erro de cliente Inexistente
{
	CampoCliente = document.getElementById('txtCodigoCliente');
	Aux2 = document.getElementById('txtAux2').value;
	if (Aux2=='999')
	{
		alert('Este Codigo de Cliente Nao Consta no Cadastro');
		CampoCliente.select();
	}
	
}
function ValidaItem() //Verifica se foi retornado erro de Item Inexistente
{
	form = document.FormPrecificarEnvelope;
	
	if (form.txtAux2.value=='888')
	{
		alert('Este Codigo de Item Nao Consta no Cadastro');
		form.txtCodigoItem.focus();
		form.txtCodigoItem.select();
	}
	
}

function ValidaConfirmacao() //Verifica se a confirmação do Envelope foi Aceita ou Não
{
	form = document.FormPrecificarEnvelope;
	
	if (form.txtAux2.value=='777')
	{
		if (confirm('Confirma a Precificacao do Envelope?'))
		{
			form.txtAux2.value='771';
			//document.form.submit();
		}
		else
		{
			txtAux2.value = '';
			form.txtCodigoItem.focus();
			form.txtCodigoItem.select();
		}
	}
	
}

// **************************************************************

function ShowPesquisar(CampoRetorno,Filtro,TipoPesquisa) 
{
	var retorno="";
	form = document.FormPrecificarEnvelope;

	if (TipoPesquisa=="Pessoas") 
	{
		retorno = showModalDialog("framePesquisarPessoas.aspx?TipoPessoa=" + Filtro,
		"window",'help:no;status:no;scroll:yes;edge:raised;dialogWidth:785px;edge:raised;dialogHeight:300px') 
	}
	else if (TipoPesquisa=="Itens")
	{
		retorno = showModalDialog("framePesquisarItens.aspx?idUnidadeNegocio=" + Filtro,
		"window",'help:no;status:no;scroll:yes;edge:raised;dialogWidth:785px;edge:raised;dialogHeight:300px') 
	}
	else if (TipoPesquisa=="ContaReceber")
	{
		retorno = showModalDialog("framePesquisarContaReceber.aspx",
		"window",'help:no;status:no;scroll:yes;edge:raised;dialogWidth:785px;edge:raised;dialogHeight:400px') 
	}
	else if (TipoPesquisa=="ContaPagar")
	{
		retorno = showModalDialog("framePesquisarContaPagar.aspx",
		"window",'help:no;status:no;scroll:yes;edge:raised;dialogWidth:785px;edge:raised;dialogHeight:400px') 
	}	
	else if (TipoPesquisa=="CEP")
	{
		retorno = showModalDialog("../aspx/Busca_cep.htm",
		"window",'help:no;status:no;scroll:yes;edge:raised;dialogWidth:360px;edge:raised;dialogHeight:370px') 
	}
		
	if(retorno!="" && retorno!=null)
	{
		document.getElementById(CampoRetorno).value=retorno;
		//document.form.submit();
	} 
	else
	{
		document.getElementById(CampoRetorno).focus();
	}
}

function FechaPagina()
{
	window.returnValue=document.getElementById('txtID').value;
	window.close();
}

// **************************************************************

function ShowPesquisarPessoa(CampoID,CampoDescricao,Filtro,TipoPesquisa) 
{
	var retorno="";

	retorno = showModalDialog("framePesquisarPessoas.aspx?TipoPessoa=" + Filtro,
		"window",'help:no;status:no;scroll:yes;edge:raised;dialogWidth:785px;edge:raised;dialogHeight:300px') 
		
	if(retorno!="" && retorno!=null)
	{
		document.getElementById(CampoID).value=retorno.substr(0,retorno.indexOf('#'));
		document.getElementById(CampoDescricao).value=retorno.substr(retorno.indexOf('#')+1);
		//document.form.submit();
	} 
	else
	{
		document.getElementById(CampoID).focus();
	}
}

function FechaPaginaPP()
{
	window.returnValue=document.getElementById('txtID').value+"#"+document.getElementById('txtDescricao').value;
	window.close();
}

// **************************************************************

function ShowPesquisarContaContabil(CampoID,CampoDescricao) 
{
	var retorno="";
	
	retorno = showModalDialog("framePesquisarContaContabil.aspx",
			"window",'help:no;status:no;scroll:yes;edge:raised;dialogWidth:485px;edge:raised;dialogHeight:600px') 
	
	if(retorno!="" && retorno!=null)
	{
		document.getElementById(CampoID).value=retorno.substr(0,retorno.indexOf('#'));
		document.getElementById(CampoDescricao).value=retorno.substr(retorno.indexOf('#')+1);
		//document.form.submit();
	} 
	else
	{
		document.getElementById(CampoID).focus();
	}
}


function FechaPaginaPCC()
{
	window.returnValue=document.getElementById('txtID').value+"#"+document.getElementById('txtDescricao').value;
	window.close();
}

// **************************************************************

function DesabilitaBotao(botao)
{
	document.getElementById(botao).disabled="disabled";
}

function validaCPF(Campo) {
	cpf = document.getElementById(Campo).value;
	valor = true;
	erro = new String;
	if (cpf.length > 0)
	{
		//substituir os caracteres que nao sao numeros
		if ((cpf.charAt(3) != ".") || (cpf.charAt(7) != ".") || (cpf.charAt(11) != "-"))
		{
			alert('O CPF deve ser digitado com a formatacao completa, ex: 123.123.123-12');
			Campo.select();
			return false;
		}
			
		if(document.layers && parseInt(navigator.appVersion) == 4){
			x = cpf.substring(0,3);
			x += cpf.substring(4,7);
			x += cpf.substring(8,11);
			x += cpf.substring(12,13);
			cpf = x;	
		} else {
			cpf = cpf.replace(".","");
			cpf = cpf.replace(".","");
			cpf = cpf.replace("-","");
		}

		if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
		var nonNumbers = /\D/;
		if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";	
		if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
				erro += "Numero de CPF invalido!"
		}
		var a = [];
		var b = new Number;
		var c = 11;
		for (i=0; i<11; i++){
			a[i] = cpf.charAt(i);
			if (i < 9) b += (a[i] *  --c);
		}
		if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
		b = 0;
		c = 11;
		for (y=0; y<10; y++) b += (a[y] *  c--); 
		if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
		if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
			erro +="Digito verificador com problema!";
		}
		if (erro.length > 0){
			alert(erro);
		document.getElementById(Campo).select();
		}
	}
	return true;
}

function validaCNPJ(Campo) {
	
	CNPJ = document.getElementById(Campo).value;
	erro = new String;
	if (CNPJ.length > 0)
	{
		if (CNPJ.length < 18) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
		if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
			if (erro.length == 0) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
		}
		//substituir os caracteres que nao sao numeros
		if(document.layers && parseInt(navigator.appVersion) == 4){
			x = CNPJ.substring(0,2);
			x += CNPJ.substring(3,6);
			x += CNPJ.substring(7,10);
			x += CNPJ.substring(11,15);
			x += CNPJ.substring(16,18);
			CNPJ = x;	
		} else {
			CNPJ = CNPJ.replace(".","");
			CNPJ = CNPJ.replace(".","");
			CNPJ = CNPJ.replace("-","");
			CNPJ = CNPJ.replace("/","");
		}
		var nonNumbers = /\D/;
		if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas numeros! \n\n";	
		var a = [];
		var b = new Number;
		var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
		for (i=0; i<12; i++){
			a[i] = CNPJ.charAt(i);
			b += a[i] * c[i+1];
		}
		if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
		b = 0;
		for (y=0; y<13; y++) {
			b += (a[y] * c[y]); 
		}
		if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
		if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
			erro +="Digito verificador com problema!";
		}
		if (erro.length > 0){
			alert(erro);
			document.getElementById(Campo).select();
			return false;
		}
	}
	return true;
}



function DesabilitaBotao(botao)
{
	document.getElementById(botao).disabled="disabled";
}

function formataTelefone(fld, e) {
	var qtDec = 4
	var milSep = ''
	var decSep = '-'
	var sep = 0;
	var key = '';
	var i = j = k = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	var zeros = '';
	if (fld.value.length > 8) return true;
	if (whichCode == 13) return true; // Enter	
	key = String.fromCharCode(whichCode); // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false; // Not a valid key
	len = fld.value.length;
	for(i = 0; i<len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) fld.value = '';
	for(k = 0; k < qtDec; k++)
		zeros += '0';
	if ((len > 0) && (len <= qtDec)) fld.value = '0'+ decSep + zeros.substr(1,qtDec-len) + aux;
	if (len > qtDec) 
	{
		aux2 = '';
		for (j = 0, i = (len - (qtDec + 1)); i >= 0; i--) 
		{
			if (j == 3) 
			{
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		if (aux2.length > 15) return false; 
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
			fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - qtDec, len);
	}
	return false;
}


//Função para digitação somente de Número com opção de adicionar Caracter Especial
function SomenteNumero(e, CharEspecial) 
{
	var key = '';
	var strCheck = '0123456789' + CharEspecial;
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true; // Enter
	key = String.fromCharCode(whichCode); // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false; // Not a valid key
}

//Função para formatação de CPF, CNPJ, Data com Duas Casas, CEP, HoraMinuto Telefone
function FormataCampo(fld, e, tipo) 
{
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true; // Enter
	key = String.fromCharCode(whichCode); // Get key value from key code
	
	if (whichCode == 0)  // Delete
    {
        fld.value = '';
        return false;
	}	

	if (whichCode == 8)  // Backspace
    {
	    len = fld.value.length;
	    len = len-1
	    aux = '';
	    for(; i < len; i++)
		    if (strCheck.indexOf(fld.value.charAt(i))!=-1)
		        if ((i = (len-1)) && (fld.value.charAt(i) = '.'))
		            break;
		        else
		            aux += fld.value.charAt(i);
		fld.value = aux;
		return false;
	}
	
	if (strCheck.indexOf(key) == -1) return false; // Not a valid key
	len = fld.value.length;

	if (tipo.toUpperCase()=='CPF')
	{
		if (len==3) fld.value += '.';
		if (len==7) fld.value += '.';
		if (len==11) fld.value += '-';
	}
	if (tipo.toUpperCase()=='CLASSIFICACAO')
	// Ex.: 1.3.3.01.001
	{  
		if (len==1) fld.value += '.';
		if (len==3) fld.value += '.';
		if (len==5) fld.value += '.';
		if (len==8) fld.value += '.';		
		if (len==12) fld.value += '.';		
	}	
	if (tipo.toUpperCase()=='CNPJ')
	{
		if (len==2) fld.value += '.';
		if (len==6) fld.value += '.';
		if (len==10) fld.value += '/';
		if (len==15) fld.value += '-';
	}
	if (tipo.toUpperCase()=='CEP')
	{
		if (len==2) fld.value += '.';
		if (len==6) fld.value += '-';
	}
	
	if (tipo.toUpperCase()=='DATA2')
	{
		if (len==2) fld.value += '/';
		if (len==5) fld.value += '/';
	}
	
	if (tipo.toUpperCase()=='HORAMINUTO')
	{
		if (len==2) fld.value += ':';
	}

	if (tipo.toUpperCase()=='TELEFONE')
	{
		if (len==4) fld.value += '-';
	}
	
	return true;
}

//Função para Saltar para próximo campo conforme o número de  caracteres digitados
function PulaProximoCampo(CampoAtual, MaxLen, ProximoCampo, e, Valida)
{
	var RetornoNumerico
	
	if (Valida.toUpperCase()=='NUMERICO')
	{
	 RetornoNumerico = SomenteNumero(e, '');
	}
	if (RetornoNumerico==false) return false;
	
	var len = 0;
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true; // Enter
	key = String.fromCharCode(whichCode); // Get key value from key code

	len = CampoAtual.value.length;
	if (len == MaxLen-1)
	{
		CampoAtual.value += key;
		document.getElementById(ProximoCampo).select();
		return false;
	}
	return true;
}

function dateValid(objName) 
{
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	// var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	//strDate = datefield.value;
	strDate = objName;
	if (strDate.length < 1) 
	{
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{
				err = 1;
				return false;
			}
			else 
			{
				strDay = strDateArray[0];
			}
			booFound = true;
		}
	}
	if (booFound == false) 
	{
		if (strDate.length>5) 
		{
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	//Adjustment for short years entered
	if (strYear.length == 2) 
	{
		strYear = '20' + strYear;
	}
	strTemp = strDay;
	strDay = strMonth;
	strMonth = strTemp;
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) 
	{
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) 
	{
		for (i = 0;i<12;i++) 
		{
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 
			{
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) 
		{
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) 
	{
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) 
	{
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) 
	{
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) 
	{
		err = 7;
		return false;
	}
	if (intMonth == 2) 
	{
		if (intday < 1) 
		{
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) 
		{
			if (intday > 29) 
			{
				err = 9;
				return false;
			}
		}
		err = 10;
		return false;
	}
	return true;
}
function LeapYear(intYear) 
{
	if (intYear % 100 == 0) 
	{
		if (intYear % 400 == 0) 
		{ 
			return true; 
		}
	}
	else 
	{
		if ((intYear % 4) == 0) 
			{ 
				return true;
			}
	}
	return false;
}

// funções usadas para limitar a quantidade de caracteres 
// no controle TEXBOX com a opção MultLine ativada
function textCounter(field,MaxLength)
{ 
	obj = document.all(field); 
	if (MaxLength !=0) 
	{ 
		if (obj.value.length > MaxLength) 
			obj.value = obj.value.substring(0, MaxLength); 
	}
}


// funções usadas para alternar imagem em botões, com o mouseover
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_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_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;
}

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 FormatarHora(campo,e) 
//{
//var cod="";
//if(document.all) {cod=event.keyCode;} else {cod=e.which;} 
//if(cod == 08 || cod == 13 || cod == 46) return;
//if (cod < 48 || cod > 57)
//{
//if (cod < 45 || cod > 57) alert("Digite somente Caracteres Numéricos!");
//cod=0;
//campo.focus(); return false;
//}
//tam=campo.value.length; 
//if(tam > 4) return false;
//var caract = String.fromCharCode(cod); 
//if(tam == 2) {campo.value+=":"+caract; return false;}
//campo.value+=caract; return false;
//}
//var Ano,Mes,Dia;
//function ValidarData(vData)
//{
//if (vData==0) { alert("Favor informar a data."); return false; }
//var Parte=vData.split("/"); 
//Ano=Parte[2];
//Mes=Parte[1];
//Dia=Parte[0];
//if (Parte.join("").length != 8) { alert("Digite a Data corretamente."); return false; }
//if (isNaN(Parte.join(""))) {alert("Data deve ser numérica."); return false;}
////if (Ano &lt; 1500) {alert("Verifique o ano."); return false;}
//Data1 = new Date(Ano,Mes-1,Dia);
//if (Mes < 1 || Mes > 12) {alert("Mes incorreto, favor retificar."); return false;}
//if (Dia < 1 || Dia > 31) {alert("Dia incorreto, favor retificar."); return false;}
//if (Dia > 30 || (Dia > 28 && Mes == 02 )) 
//{
 //D = Data1.getDate();
 //if (D &lt; Dia)
 //{
 //alert("Dia maior que 30 em mes indevido ou\n fevereiro com dia 29 em ano não bissexto,\n favor retificar.");
 //return false; 
 //}
//}
//Hoje = new Date();
//Ano2 = Hoje.getFullYear();
//Mes2 = Hoje.getMonth(); 
//Dia2 = Hoje.getDate(); 
//Hoje = new Date(Ano2,Mes2,Dia2);
//
//Data1 = Data1.getTime();
//Hoje = Hoje.getTime(); 
//if (Hoje > Data1) {alert("Data não deve ser menor que a data atual."); return false;}
//return true;
//}
//function ValidarHora(hora)
//{
//var msg="";
//var erro="";
//var h = (hora.substring(0,hora.indexOf(':')));
//var m = (hora.substring(hora.indexOf(':')+1,hora.length));  
//if (hora.substring(2,3) != ":" || hora.length &lt; 5) 
//{
//alert("Informe hora no formato hh:mm.");
//document.agenda.Hora.focus();
//document.agenda.Hora.select(); &amp;nbsp;
//return false;}
//if (h < 0 || h > 23 || isNaN(h)) {msg+="Hora incorreta!\n"; erro=true;}
//if (m < 0 || m > 59 || isNaN(m)) {msg+="Minuto incorreto!"; erro=true;}
//if (new Date().getTime() > new Date(Ano,Mes-1,Dia,h,m,00).getTime())
 //{ msg+="Se data igual a data atual,\n horário deve ser maior que horário atual.", erro=true;} 
//if (erro==true) 
//{
//alert(msg); erro="";
//document.agenda.Hora.focus();
//document.agenda.Hora.select(); 
//return false;
//} 
//else { return true; } //("Hora OK!")
//}
//function ValidarAg(dData,hHora)
//{
 //if (!ValidarData(dData)) return false;
 //if (!ValidarHora(hHora)) return false;
//}

