function $(obj) {
	return document.getElementById(obj);
}

// Início Validação de Formulário

function validacao(formulario){
	for(i=0;i<=formulario.length-1;i++){
		if ((formulario[i].type=="textarea")||(formulario[i].type=="file")||(formulario[i].type=="hidden")||(formulario[i].type=="text")||(formulario[i].type=="password")){
			if ((formulario[i].wmsg!="")&&(formulario[i].wmsg!=undefined)){
				if (formulario[i].email=="sim"){
					if((formulario[i].value=="")||(formulario[i].value.indexOf('@')==-1)||(formulario[i].value.indexOf('.')==-1)){
						alert(formulario[i].wmsg);
						try{
							formulario[i].focus();
						}
						catch(e){
							}				
						return false
					}	
				}else{
					if(formulario[i].value==""){
						alert(formulario[i].wmsg);
						try{
							formulario[i].focus();
						}
						catch(e){
	
							}
					
						return false
					}
				}
			}
		}	
	}
}

// Fim Validação de Formulário


function criaMascara(_RefObjeto, _Modelo)
{
	var valorAtual = _RefObjeto.value;        
	var valorNumerico = '';
	var nIndexModelo = 0;
	var nIndexString = 0;
	var valorFinal = '';
	var adicionarValor = true;
    
     
	// limpa a string valor atual para verificar 
	// se todos os caracteres são números
	for (i=0;i<_Modelo.length;i++){
		if (_Modelo.substr(i,1) != '#'){
			valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
  		}
 	}
      
 	// verifica se todos os caracteres são números
 	for (i=0;i<valorAtual.length;i++){
  		if (!isNaN(parseFloat(valorAtual.substr(i,1)))){
			valorNumerico = valorNumerico + valorAtual.substr(i,1);
  		}
 	}
      
 	// aplica a máscara ao campo informado usando
 	// o modelo de máscara informado no script
 	for (i=0;i<_Modelo.length;i++){
  		if (_Modelo.substr(i,1) == '#'){
    			if (valorNumerico.substr(nIndexModelo,1) != ''){
				valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
				nIndexModelo++;nIndexString++;
    			} 
    			else {
        			adicionarValor = false;
    			}
  		}
  		else {
     			if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != ''){
  				valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
				nIndexString++;
     			}
  		}
 	}
    
 	_RefObjeto.value = valorFinal 
}


function soNums(e,args)
{        
//  onKeyPress ="return (soNums(event,'(/){,}.'));"
	var valid_chars    = new Array();
   	if (document.all){
		var evt = event.keyCode;
	}
	else{
		var evt = e.charCode;
	}
   	var chr= String.fromCharCode(evt);
   	
	if (evt <20 || (evt >47 && evt<58) || (args.indexOf(chr)>-1 ) ){return true;}
   	return false;
}


// Início funções by Hargon

function ContaCaracteres(tamanho,form,campo){
   	var campo = document.forms[form].elements[campo];
	intCaracteres = tamanho - campo.value.length;
	if (intCaracteres > 0){
	      	return true;
	}
	else {
		campo.value = campo.value.substr(0,tamanho);
      		return false;
   	}
}

var mcomboGeral = 0;
function mostrarComboJQuery(camada){
	if (mcomboGeral == 0){		
		$j('#'+camada).slideDown('slow');
		mcomboGeral = 1;
	}else{
		$j('#'+camada).slideUp('slow');		
		mcomboGeral = 0;
	}
}

function escolheCombo(formulario,campo,codigo,nome,tipo){
	if (tipo != 1){
		new Effect.BlindUp('div_cd'+campo);
	}else{
		$j('#div_cd'+campo).hide('slow');
	}
	mcomboGeral = 0;
	document.forms[formulario].elements['txtcd'+campo].value = codigo;
	document.forms[formulario].elements['optcd'+campo].value = nome;
}

// Fim funções by Hargon



// Função de mascara de moeda
function Moeda(fld, e) 
{
	if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
	{ 
		var milSep = "."; 
		var decSep = ","; 
		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; 

		key = String.fromCharCode(whichCode); 

		if (strCheck.indexOf(key) == -1) 
			return false; 

		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++; 
		} 

		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; 

	} 
	else 
	{
		if (e.keyCod != 8) { // backspace
			e.keyCode = 0;
		}
	}
}


// Função de mascara e bloqueio de teclas não numéricas
function formata(valor)
{
	if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
	{ 
		if (document.getElementById(valor).value.length == 2 || document.getElementById(valor).value.length == 5 ){
			document.getElementById(valor).value += "/";
		}	
	}
	else {
		if (window.event.keyCod != 8) { // backspace
			window.event.keyCode = 0;
			//alert("Utilize apenas números!");
		}
	}
}


function favoritos(titulo, url)
{
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
		window.external.AddFavorite(url,titulo);		
	}
	else if (window.sidebar) {
		window.sidebar.addPanel(titulo, url,"");
	}
	else if(window.opera && window.print) {
		return true;
	}
}

function paginainicial(url){
	$("lnkPgnInicial").style.behavior='url(#default#homepage)'; 
	$("lnkPgnInicial").setHomePage(url);
	return false;
}
