
/*checar navegador do usuario*/
var sAgent = navigator.userAgent;
var bIsIE = sAgent.indexOf("MSIE") > -1;
var bIsNav = sAgent.indexOf("Mozilla") > -1 && !bIsIE;

/*************************************************************************************************************************************/
// Validacao de Campos
//desbitlitar clique direito

function bloquearBotaoDireito(e) 
{
	var rightclick;
	if (!e) 
		var e = window.event;
		
	if (e.which) 
		rightclick = (e.which == 3);
	else if (e.button) 
			rightclick = (e.button == 2);
			
	//alert('Rightclick: ' + rightclick); // true or false]
	if (rightclick==2||rightclick==3) 
	{
		oncontextmenu = 'return false';
 	}
}

//document.onmousedown = bloquearBotaoDireito
//document.oncontextmenu = new Function("return false;")


function f_retira_strigs(selectObj, evt)
{
	
	var keyCode = 0;
	var ret_val = true;
	if (evt) 
	{
		keyCode = evt.keyCode || evt.which;
	}
	else 
	{
		// The old version of this file did not use the evt parameter
		// and would only work under IE.
		keyCode = window.event.keyCode;
	}
	
	//alert(keyCode);
	
	if(keyCode == 44 || keyCode == 39)
		return false;
	else
		return true;

}

function trim(string)
{
	//caso tenha espaços no fim
	while(string.charAt(string.length - 1) == ' ')
	{
		string = string.substring(0, string.length - 1);
	}
	//caso tenha espaços no início
	while(string.charAt(0) == ' ')
	{
		string = string.substring(1, string.length);
	}
	
	return string;
}

function validarTabela(p_id)
{
	
	if(document.getElementById(p_id))
	{
		trs = document.getElementById(p_id).childNodes;
		//trs = tbody[0].childNodes;//document.getElementById(p_id).childNodes;
		
		for(i = 0; i < trs.length;i++)
		{
			
			tds = trs[i].childNodes;
			//alert(1)
			for(j = 0; j < tds.length; j++)
			{
				filhos_tds = tds[j].childNodes;
				//alert(filhos_tds.length)
				for(k = 0; k < filhos_tds.length; k ++)
				{
					//alert(3)
					if(filhos_tds[k])
					{
						
						//alert(filhos_tds[k].id);
						if(filhos_tds[k].type)
						{	
							if(filhos_tds[k].type == "text")
							{
								
								text = trim(filhos_tds[k].value)
								if( text == '')
								{
									return false;
								}
							}
							else if(filhos_tds[k].type == "textarea")
							{
								
								tam = trim(filhos_tds[k].value).length;
								//alert(tam);
								if( tam == 0)
								{
									return false;
								}
							}
						}
					}
				}
			}
		}
	}
	else
	{
		alert("O elementeo de id "+p_id+" nao existe!");
		return false;
	}
	
	return true;
}
function apagarDadosTabela(p_id)
{
	
	if(document.getElementById(p_id))
	{
		trs = document.getElementById(p_id).childNodes;
		
		for(i = 0; i < trs.length;i++)
		{
			//alert(trs[i].tagName)
			tds = trs[i].childNodes;
			//alert(1)
			for(j = 0; j < tds.length; j++)
			{
				filhos_tds = tds[j].childNodes;
				//alert(filhos_tds.length)
				for(k = 0; k < filhos_tds.length; k ++)
				{
					//alert(2)
					if(filhos_tds[k])
					{
						if(filhos_tds[k].type)
						{	
							tipo = filhos_tds[k].type;
							if(tipo == "text" || tipo == 'hidden' || tipo == 'password' )
							{
								
								//alert(filhos_tds[k].value);
								filhos_tds[k].value = '';
							}
							else if(tipo == 'textarea'){
								filhos_tds[k].value = '';	
							}
								
							
						}
					}
				}
			}
		}
	}
	else
	{
		alert("O elemento de id "+p_id+" não existe!");
	}

}
function limit_keys(selectObj, type, evt, limite)
{
	
	/*origem descnhecida!
	modificada por MAU (MAURICIO BARROS)
	MAU>limit_keys(selectObj, type, evt, limite): 
	Permite que o usuario digite somente caracteres com o tipo selecionado em type.
	selectObj: Id do campo a ser validado.
	type: tipo de dado do campo: alphanum;
								 numeric;
								 float;
								 date;
	limite: Maxlength do campo;
	*chamada:onKeyUp="return limit_keys(this, 'numeric', event, 4);" onKeyPress="return limit_keys(this, 'numeric', event, 4);" onKeyDown="return limit_keys(this, 'numeric', event, 4);"
	*/
	
	nr_carecteres = selectObj.value.length;
	var keyCode = 0;
	var ret_val = true;
	//alert('ok');
	
	if (evt) 
	{
		keyCode = evt.keyCode || evt.which;
	}
	else 
	{
		// The old version of this file did not use the evt parameter
		// and would only work under IE.
		keyCode = window.event.keyCode;
	}
	
	
	if(nr_carecteres >= limite)
	{
		ok = 'false';
		
		if(!( keyCode == 8 || keyCode == 39 || keyCode == 37 || keyCode == 46))
		{
			return false;
			
		}
	}
	
	//alert(keyCode);
	// Allow special characters: BACKSPACE, TAB, RETURN, LEFT ARROW,RIGHT ARROW to go through
	if(keyCode == 8)// ((keyCode == 8) || (keyCode == 9) || (keyCode == 13) || (keyCode == 37) || (keyCode == 39)) 
	{
		return (ret_val);
	}
	
	if (type == 'phone') 
	{
		// Numeric values and punctuation are OK
		ret_val = test_keycode( '0123456789()-.', keyCode);
	}
	else if (type == 'alphanum') 
	{
		ret_val = ((keyCode >= 48) && (keyCode <= 57)) || ((keyCode >= 65) && (keyCode <= 90)) 
			   || ((keyCode >= 97) && (keyCode <= 122)) ||  keyCode == 32 || (keyCode == 8) || (keyCode == 37) || (keyCode == 46) ;
	}
	else if (type == 'numeric') 
	{
		// Simply test for a numeric value
		ret_val = ((keyCode >= 48) && (keyCode <= 57));
	}
	else if (type == 'float') 
	{
		// Simply test for a numeric value
		ret_val = ((keyCode >= 48) && (keyCode <= 57)) || keyCode <= 44 ;
	}
	else if (type == 'date') 
	{	
		var strtmp = '';
		var rExpr = new RegExp("[0-9/]");
		var inicio = selectObj.value.length - 1;
		var text = selectObj.value;

		if(keyCode != 8)
		{
			if(rExpr.test(text.substr(inicio, 1)) != true)
				strtmp = text.substr(0, inicio);
				
			if(text.length == 3 && text.substr(2, 1) != '/')
				strtmp = text.substr(0, 2) + '/' + text.substr(2, 1);
				
			if(text.length == 6 && text.substr(5, 1) != '/')
				strtmp = text.substr(0, 5) + '/' + text.substr(5, 1);
				
			if(strtmp != '')
				selectObj.value = strtmp;
		}
	}
	return (ret_val);
}



function validaEmail(p_email) 
{
	
	if (p_email.value != "")
	{
		prim = p_email.value.indexOf("@")
		if(prim < 2) 
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}
		if(p_email.value.indexOf("@",prim + 1) != -1) 
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}
		if(p_email.value.indexOf(".") < 1) 
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}
		if(p_email.value.indexOf(" ") != -1) 
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}		
		if(p_email.value.indexOf(".@") > 0) 
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}
		if(p_email.value.indexOf("@.") > 0) 
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}
		if(p_email.value.indexOf(".com.br.") > 0) 
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}
		if(p_email.value.indexOf("/") > 0) 
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}
		if(p_email.value.indexOf("[") > 0) 
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}
		if(p_email.value.indexOf("]") > 0) 
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}
		if(p_email.value.indexOf("(") > 0) 
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}
		if(p_email.value.indexOf(")") > 0)
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}
		if(p_email.value.indexOf("..") > 0) 
		{
			//alert("O e-mail informado parece não estar correto.");
			p_email.focus();
			p_email.select();
			return false;
		}
		
		return true;
	}
}


function comparaData(datai_str, dataf_str)
{
	//datas obrigatoriamente no formato DD/MM/AAAA
	dti = new String(datai_str);
	dtf = new String(dataf_str);
	anof = dtf.substr(6);
	anoi = dti.substr(6);
	mesf = dtf.substr(3, 2);
	mesi = dti.substr(3, 2);
	diaf = dtf.substr(0, 2);
	diai = dti.substr(0, 2);
	if(anof < anoi)
	{
		return 'ERRO';
	}
	else
	{
		if(anof == anoi && mesf < mesi)
		{
			return 'ERRO';
		}
		else
		{
			if(anof == anoi && mesf == mesi && diaf < diai)
			{
				return 'ERRO';
			}
			else
			{
				return 'SIGA';
			}
		}
	}
}


/**********************************************************************************************************************************/
function formataValor(campo,tammax,teclapres,form) 
{
	/*MAU>
	 origem desconhecida
	 modificada por MAU (MAURICIO BARROS)
	 function formataValor(campo,tammax,teclapres,form): trasforma o conteudo de um campo em formato de moeda 
	 separao com "." e "," (1.222.222,01).OBS. chamada: onKeyDown = "return formataValor(this.id, 13, event);"
	 */
	
	var tecla = teclapres.keyCode;
	vr = document.getElementById(campo).value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;
	
	if(vr == '')
		vr = 0;
	
	if(tam >= tammax)
	{
		ok = 'false';
		
		if(!( tecla == 8 || tecla == 39 || tecla == 37 || tecla == 46))
		{
			return false;
			
		}
	}
	
	
	if (tam < tammax && tecla != 8)
	{ 
		tam = vr.length + 1; 
	}
	if (tecla == 8 )
	{ 
	tam = tam - 1; 
	}
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
	{
		if ( tam <= 2 )
		{
			document.getElementById(campo).value = vr; 
		}

		if ( (tam > 2) && (tam <= 5) )
		{
			document.getElementById(campo).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); 
		}

		if ( (tam >= 6) && (tam <= 8) )
		{
			document.getElementById(campo).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
		}

		if ( (tam >= 9) && (tam <= 11) )
		{
			document.getElementById(campo).value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
		}

		if ( (tam >= 12) && (tam <= 14) )
		{
			document.getElementById(campo).value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
		}

		if ( (tam >= 15) && (tam <= 17) )
		{
			document.getElementById(campo).value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
		}
	} 
	else 
	{
		return false;
	}
}

function formataMoedaPontoVirgula(vr)
{
	/*MAU>
	Origem UFG 13/09/2006- autor MAU(Mauricio barros)
	Com base em outras funceos
	
	formataMoedaPontoVirgula: retrona o vr em formato de moeda acrecentenado . e , s******/
	
	vr = new String(vr);
	
		//recolocar zero a direita.
		str_total = new String(vr);
		pos_ponto = str_total.indexOf(".");
		if(pos_ponto > -1) 
		{
			
			pri_casa = str_total.substring(pos_ponto + 1, pos_ponto + 2);
			sec_casa = str_total.substring(pos_ponto + 2, pos_ponto + 3);
			
			if(!pri_casa)
				str_total = str_total+".00";
			else  if(!sec_casa)
					str_total = str_total+"0";
					   
			vr = str_total;
		}
		else
			vr = vr+".00";

	
	
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;
	
	if(vr == '')
		vr = 0;
		
	
	if ( tam <= 2 )
	{
		vr = vr; 
	}

	if ( (tam > 2) && (tam <= 5) )
	{
		vr = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); 
	}

	if ( (tam >= 6) && (tam <= 8) )
	{
		vr = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
	}

	if ( (tam >= 9) && (tam <= 11) )
	{
		vr = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
	}

	if ( (tam >= 12) && (tam <= 14) )
	{
		vr = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); 
	}

	if ( (tam >= 15) && (tam <= 17) )
	{
		vr = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
	}

	return vr;
}
/****************************************************************************************************************/
function formataMoedaPonto(valor)
{
	/*MAU> 
	Origem UFG 13/09/2006 - autor MAU(mauricio Barros)
	
	function formataMoedaPonto(valor): formata valor para tipo ponto flutuante em formato 
	que pode ser interpretado de forma correta em operacoes aritmeticas em javascript, muito util 
	quando se trabalha com moedas.
	*/
	
	if(valor == '')
	{
		valor = 0;
	}
	else
	{
		vet_valor = valor.split(".");
		
		for(i = 0; i < vet_valor.length -1; i++)
		{
			
			valor = valor.replace( ".", "" );
		}
		
		valor       = valor.replace( ",", "." );
		vet_valor   = valor.split(".");
		vet_valor_0 = vet_valor[0];
		

		vet_valor_0_retorno = vet_valor_0;
		
		for( i =0 ; i < vet_valor_0.length -1; i++)
		{
			if(vet_valor_0[i] != 0 || i ==  vet_valor_0.length -2 )
			{
				vet_valor_0_retorno = vet_valor_0.substr(i);
				break;
			}
		}
		
		if(vet_valor[1])
			valor = vet_valor_0_retorno+"."+vet_valor[1];
		else
			valor = vet_valor_0_retorno+".00";

		
	}
	
	return valor; 
}

/*************************************************************************************************/
function arredonda(valor , casas )
{
   /*MAU> 
  	Origem  http://lib.seven.com.br/ampliar.asp?codcat=18&codartigo=423
	Colaborador..: João Batista Neto
	Categoria(s).: Javascript;
	Versão.......: 0.01b
	Data.........: 31/12/2002 02:08:24
	Visualizado..: 3705 vezes
	Fonte........: Internet
	
   function arredonda(valor , casas ) :areendodar numero em ponto flutuante com precisao definido pelo parametro casas, retorna valor com tioo float****************/

   valor = parseFloat(valor);
   var novo = Math.round( valor * Math.pow( 10 , casas ) ) / Math.pow( 10 , casas );

   return novo;

}
/*******************************************************************************************************************/
/* Formatação para qualquer mascara */

function formatar(src, evento, mask) 
{
  /*MAU>
  fonte:http://lib.seven.com.br/ampliar.asp?codcat=18&codartigo=733
  Colaborador..: Rafael S. Matos
	Exemplos:
	CEP
	OnKeyPress="formatar(this, event, '#####-###')"
	CPF
	OnKeyPress="formatar(this, event, '###.###.###-##')"
	DATA
	OnKeyPress="formatar(this, event, '##/##/####')"
  */
  	if(!permiteNumeros(evento))
  		return false;
  
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	
	alert(texto.substring(0,1)+'-'+saida);
	
	
	
	if (texto.substring(0,1) != saida){
		src.value += texto.substring(0,1);
	}
}
//*******************************************************************************************************************/
/* Validação de data */

function verificaData(src)
{
	if(src.value != ''){
		
         erro = 0;
         hoje = new Date();
         anoAtual = hoje.getFullYear();
         barras = src.value.split("/");
         
         if(barras.length == 3){
			dia = barras[0];
			mes = barras[1];
			ano = barras[2];
			resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) && (ano <= anoAtual + 10 && ano >= 1900));
			if (!resultado){
		         return false;
			}
			
			return true;
         }
		 else{
		 	return true;
         }
	}
} // doDate

function f_mask_date(p_obj, evt)
{
	var strtmp = '';
	var rExpr = new RegExp("[0-9]");
	var inicio = p_obj.value.length - 1;
	var text = p_obj.value;
	
	if (evt) 
		key = evt.keyCode || evt.which;
	else 
		key = window.event.keyCode;
			
	if(key != 8)
	{
		if(rExpr.test(text.substr(inicio, 1)) != true)
			strtmp = text.substr(0, inicio);
			
		if(text.length == 3 && text.substr(2, 1) != '/')
			strtmp = text.substr(0, 2) + '/' + text.substr(2, 1);
			
		if(text.length == 6 && text.substr(5, 1) != '/')
			strtmp = text.substr(0, 5) + '/' + text.substr(5, 1);
			
		if(strtmp != '')
			p_obj.value = strtmp;
	}
	
}

function calculaTamanho(pTamanho,pPeenchido)
{
	//Utilizar no envento onKeyUp
	var valRetorno = '';
	valRetorno = pTamanho - pPeenchido.value.length;
	return valRetorno;
}

function tamanhoTxtArea(pTxtArea,pTamanho)
{ 
	//Utilizar no envento onKeyUp
	if (pTxtArea.value.length >= pTamanho)
	{
		 return pTxtArea.value.substr(0,pTamanho);
	}
	else
	{
	 	return pTxtArea.value;
	}
}

/*************************************

ALTERAÇÕES: AURÉLIO LUIZ
DATA: 26/11/2007
FUNCIONALIDADES: IMPLEMENTADO MÉTODOS PARA VALIDAÇÃO E FORMATAÇÃO DE HORAS

*************************************/

// valida uma hora digitada no formato hh:mm
// hora: id do input a ser validado
// obrigatorio: valida se o input pode estar vazio (0) ou nao (!=0)
function validaHora(hora, obrigatorio){ 

	var hora = document.getElementById(hora);  
	if((obrigatorio == 1) || (obrigatorio == 0 && hora.value != "")){  
         if(hora.value.length < 5){
			alert("Formato da hora inválido. Por favor, informe a hora no formato correto: hh:mm");  
			hora.focus();
			return false
         }
         if(hora.value.substr(0,2) > 23 || isNaN(hora.value.substr(0,2))){  
             alert("Formato da hora inválido.");  
             hora.focus();
             return false
         }  
         if(hora.value.substr(3,2) > 59 || isNaN(hora.value.substr(3,2))){
             alert("Formato do minuto inválido.");
             hora.focus();  
             return false
		}  
		return true;
	}
}

// formata máscara de hora e só permite digitação de números
// input: elemento input a ser formatado
// evnt: evento associado ao input
function formataHora(input, evnt){

	if (input.value.length == 2){  
    	if(bIsIE){
        	input.value += ":";
        }else{  
        	if(evnt.keyCode == 0){
            	input.value += ":";
			}
		}
	}
}

/*************************************

ALTERAÇÕES: AURÉLIO LUIZ
DATA: 09/01/2008
FUNCIONALIDADES: IMPLEMENTADO MÉTODO PARA CHECAR USUÁRIO EXISTENTE

*************************************/


// usada no cadastro, mostra um alerta caso o usuario já exista
// url: arquivo responsavel pela consulta sql
// metodo: metodo da requisição
// modo:
// form: nome do formulario onde se encontra o input
// input: id do input a ser validado
function envia(url, metodo, modo, input){

	var username = document.getElementById(input).value;	
	remoto  = new ajax();
	xmlhttp = remoto.enviar(url + "?username=" + username, metodo, modo );
	
	if(xmlhttp) {
		document.getElementById('alerta').className = 'alerta';
		document.getElementById('alerta').innerHTML = 'Este usuário já está cadastrado!';
	} else {
		document.getElementById('alerta').className = '';
		document.getElementById("alerta").innerHTML = '';
	}
}


/*************************************

ALTERAÇÕES: AURÉLIO LUIZ
DATA: 09/01/2008
FUNCIONALIDADES: IMPLEMENTADO MÉTODO QUE PERMITE APENAS A DIGITAÇÃO DE NÚMEROS

*************************************/


// evento: evento associado ao input
// input: elemento ao qual se vai associar a função
// chamada: onkeypress="return permiteNumeros(event);"
function permiteNumeros(evento){
	
	if(bIsIE){
		if((evento.keyCode >= 48 && evento.keyCode <= 57) || evento.keyCode == 13){
			return true;
		}
		else
			return false;
	}
	else{
		if((evento.which >= 48 && evento.which <= 57) || evento.which == 8 || evento.which == 0 || evento.keyCode == 13){
			return true;
		}
		else
			return false;
	}
}



/*************************************

ALTERAÇÕES: AURÉLIO LUIZ
DATA: 12/04/2008
FUNCIONALIDADES: IMPLEMENTADO MÉTODO QUE FORMATA UM NUMERO EM VALOR MONETÁRIO AO DIGITAR

*************************************/

// chamada: formataMoeda(document.forms.id_formulario.id_input, casas_decimais);

addEvent = function(o, e, f, s){
	var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
	r[r.length] = [f, s || o], o[e] = function(e){
		try{
			(e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
			e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
			e.target || (e.target = e.srcElement || null);
			e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
		}catch(f){}
		for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
		return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
	for(var i = (e = o["_on" + e] || []).length; i;)
		if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
			return delete e[i];
	return false;
};

function formataMoeda(o, n, dig, dec){
	o.c = !isNaN(n) ? Math.abs(n) : 2;
	o.dec = typeof dec != "string" ? "," : dec, o.dig = typeof dig != "string" ? "." : dig;
	addEvent(o, "keypress", function(e){
		if(e.key > 47 && e.key < 58){
			var o, s, l = (s = ((o = this).value.replace(/^0+/g, "") + String.fromCharCode(e.key)).replace(/\D/g, "")).length, n;
			if(o.maxLength + 1 && l >= o.maxLength) return false;
			l <= (n = o.c) && (s = new Array(n - l + 2).join("0") + s);
			for(var i = (l = (s = s.split("")).length) - n; (i -= 3) > 0; s[i - 1] += o.dig);
			n && n < l && (s[l - ++n] += o.dec);
			o.value = s.join("");
		}
		e.key > 30 && e.preventDefault();
	});
}



/*************************************

ALTERAÇÕES: AURÉLIO LUIZ
DATA: 28/04/2008
FUNCIONALIDADES: IMPLEMENTADO MÉTODO QUE RETORNA UMA STRING ALEATORIA COM 32 CARACTERES

*************************************/

function textoAleatorio(){
	
	var data = new Date();
	
	var letras = 'abcdefghiklmnopqrstuvwxyz'+data.getTime();
	var aleatorio = '';
	
	for (var i = 0; i<32; i++){
		var rnum = Math.floor(Math.random() * letras.length);
		aleatorio += letras.substring(rnum, rnum + 1);
	}
	
	return aleatorio;
}



function extensaoArquivo(file){
	
	var tipo = "";
	
	if (file.value != ""){
	
		arquivo = (file.value);
		tipo    = arquivo.substring(arquivo.length-4,arquivo.length);
		tipo    = tipo.toLowerCase()
	}
	
	return tipo;
}

/*************************************

ALTERAÇÕES: AURÉLIO LUIZ
DATA: 20/06/2008
FUNCIONALIDADES: IMPLEMENTADO MÉTODO QUE PERMITE LIMITAR O TAMANHO MÁXIMO DE UM TEXTAREA

*************************************/

// obj: objeto html textarea
function maxLength(obj){
	
	var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length>mlength)
		obj.value = obj.value.substring(0,mlength)
}


