/*# ALTERAR #*/
function alterar(vc_arquivo,id_item) {
	parent.formulario.location.href	= '../formularios/'+vc_arquivo+'.asp?act=2&id_'+vc_arquivo+'='+id_item;
}

/*# CONTA CARACTER #*/
function contaCaracter(vc_campo,it_caracter,it_limite) {
	if (vc_campo.value.length > it_limite) {
		vc_campo.value		= vc_campo.value.substring(0,it_limite);
	} else {
		it_caracter.value	= it_limite - vc_campo.value.length;
	}
}

/*# EXCLUIR #*/
function excluir(vc_arquivo,id_item) {
	var pergunta					= confirm('Você realmente deseja excluir este ítem?');
	
	if (pergunta) {
		parent.codigo.location.href = '../codigos/'+vc_arquivo+'.asp?act=3&id_'+vc_arquivo+'='+id_item;
	}
}

/*# IFRAME VIRTUAL #*/
function iframe_virtual(vc_url) {
	if (document.all.iframe_virtual)	{
		document.all.iframe_virtual.removeNode(true);
	}
	
	var tempIFrame					= document.createElement('iframe');
		tempIFrame.style.border		='0px';
		tempIFrame.style.width		='0px';
		tempIFrame.style.height		='0px';
		
		tempIFrame.setAttribute('id','iframe_virtual');
		tempIFrame.setAttribute('name','iframe_virtual');
		tempIFrame.setAttribute('src',vc_url);
	
	IFrameObj						= document.body.appendChild(tempIFrame);
}

/*# IMAGE CHANGER #*/
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_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.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

/*# INSERIR #*/
function inserir(arquivo) {
	parent.formulario.location.href = '../formularios/'+arquivo+'.asp?act=1';
}

/*# LOCAL #*/
function local(it_local, vc_local) {
	if (it_local == 1) {
		parent.document.all.vc_formulario.value	= 'formulário'+vc_local;
	} else if (it_local == 2) {
		parent.document.all.vc_relatorio.value	= 'relatório'+vc_local;
	}
}

/*# MASCARA */
function mascarar(vc_campo,vc_mascara) {
	var i		= vc_campo.value.length;
	var x		= vc_mascara.substring(0,1);
	var y		= vc_mascara.substring(i);
	
	if (y.substring(0,1) != x) {
		vc_campo.value += y.substring(0,1);
	}
}

/*# MASCARA MOEDA #*/
function mascaraMoeda(valor,cx) {
	if (valor) {
		var doc					= eval('document.all.'+cx);
		
		if (window.event.keyCode == 110 || window.event.keyCode == 188 || window.event.keyCode == 190 || window.event.keyCode == 194)	{
			doc.value			= valor.substr(0,(valor.length-1));
		} else {
			valor				= mascaraCentavo(valor);
			
			if (mascaraCentavo(valor).length > 2) {
				str				= valor.replace(".","");
				doc.value		= str.substr(0,(str.length-2))+"."+str.substr((str.length-2),str.length);
			} else {
				valor			= mascaraCentavo(valor);
				
				if (valor.length == 1) {
					doc.value	= "0.0"+valor;
				} else {
					doc.value	= "0."+valor;
				}
			}
		}
	}
}

function mascaraCentavo(mn_valor) {
	if (mn_valor.indexOf("0") == 0) {
		mn_valor	= mn_valor.replace("0.","");
		mn_valor	= mn_valor.replace("0.0","");
	}
	
	mn_valor		= mn_valor.replace(".","");

	return			mn_valor;
}

/*#SO NUMERO#
Alterado em: 07/08/06		Por: André Luiz */
function soNumero(e) {
	if (document.all) {
		var it_tecla	= event.keyCode;
	} else if(document.layers) {
		var it_tecla	= e.which;
	}
	
//	if (it_tecla == 45 || (it_tecla >= 48 && it_tecla <= 57) || (it_tecla >= 96 && it_tecla <= 105)) {
	if (it_tecla >= 48 && it_tecla <= 57) {
		return true;
	} else if (it_tecla != 8) {
		event.keyCode	= 0;
	} else {
		return true;
	}
}

/*# ORDERNAR #*/
function ordenar(vc_codigo,st_order) {
	self.location.href = vc_codigo+'.asp?'+st_order;
}

/*# PAGINAR #*/
function paginar(it_pag_total,vc_codigo,vc_string) {
	parent.paginacao.location.href	= '../paginacao.asp?vc_codigo='+vc_codigo+'&vc_string='+vc_string+'&it_pag_total='+it_pag_total;
}

/*# PAGINACAO #*/
function paginacao(vc_codigo,vc_string){
	parent.relatorio.location.href	= 'relatorios/'+vc_codigo+'.asp?'+vc_string;
}

/*# PALETA DE COR #*/
function paleta(vc_campo) {
	var obj						= eval('document.all.'+vc_campo);
	var dialog_cor				= showModalDialog('../editor_html/recursos/paleta.htm','','dialogWidth:148px;dialogHeight:159px;status:no;');
	if (dialog_cor)	{
		obj.style.color			= '#FFFFFF';
		obj.style.background	= dialog_cor;
		obj.value				= dialog_cor;
	}
}

/*# POP-UP SELECT #*/
function pop_select_limpar(vc_campo,vc_termo) {
	var vc_campo		= eval('document.all.'+vc_campo)

	if(vc_termo == 'clique e tecle ENTER'){
		vc_campo.value	= '';
	}	
}

function pop_select(vc_campo,vc_termo) {
	var vc_campo	= vc_campo.replace('vc','select');
	
	if(event.keyCode==13){
		var W		= 330; 	
		var H		= 430;
		var X		= 50;
		var Y		= Math.ceil( (window.screen.width - W) / 2 );
		
		window.open('../relatorios/'+vc_campo+'.asp?vc_termo='+vc_termo,'ap_select','width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,directories=no,toolbar=no');
	}	
}

function pop_select_dois_argumentos(vc_campo,vc_termo1, vc_termo2) {
	var vc_campo	= vc_campo.replace('vc','select');
	
	if(event.keyCode==13){
		var W		= 330; 	
		var H		= 430;
		var X		= 50;
		var Y		= Math.ceil( (window.screen.width - W) / 2 );
		
		window.open('../relatorios/'+vc_campo+'.asp?vc_termo1='+vc_termo1+'&vc_termo2='+vc_termo2,'ap_select','width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,directories=no,toolbar=no');
	}	
}


function pop_select_preenche(id_campo,vc_campo,tx_campo) {
	var id_item 										= String('id_'+tx_campo);
	var vc_item 										= String('vc_'+tx_campo);

	window.opener.eval('document.all.'+id_item).value	= id_campo;
	window.opener.eval('document.all.'+vc_item).value	= vc_campo;
	window.close();	
}

function pop_select_pesquisa() {
	document.psq.submit();
}

/*# PESQUISA POP_SELECT #*/
function pop_select(vc_campo,vc_termo) {
	var vc_campo	= vc_campo.replace('vc','select');
	
	if(event.keyCode==13){
		var W		= 500; 	
		var H		= 430;
		var X		= Math.ceil( (window.screen.height - H) / 2 );
		var Y		= Math.ceil( (window.screen.width - W) / 2 );
		
		window.open('../relatorios/'+vc_campo+'.asp?vc_termo='+vc_termo,'ap_select','width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,directories=no,toolbar=no');
	}	
}

/*# SETOR #*/
function setor(vc_setor,id_setor) {
	var id_aba										= document.all.id_aba.value;
	
	if (id_aba) {
		eval('document.all.'+id_aba+'_e').src		= "../imagens/ab_01_off.gif";
		eval('document.all.'+id_aba+'_c').className	= 'bg_ab_off';
		eval('document.all.'+id_aba+'_d').src		= "../imagens/ab_03_off.gif";
	}
	
	var ab_01										= eval('document.all.'+vc_setor+'_e');
	var ab_02										= eval('document.all.'+vc_setor+'_c');
	var ab_03										= eval('document.all.'+vc_setor+'_d');

	ab_01.src										= "../imagens/ab_01_on.gif";
	ab_02.className									= 'bg_ab_on';
	ab_03.src										= "../imagens/ab_03_on.gif";
	
	document.all.id_aba.value						= vc_setor;

	parent.parent.setor.location.href				= '../setores/'+vc_setor+'.asp?id_setor='+id_setor;
}

/*# UPLOAD #*/
function upload_open() {
	var W		= 160; 	
	var H		= 40;
	var X		= 180;
	var Y		= Math.ceil( (window.screen.width - W) / 2 );
	
	pp_upload	= window.open('../upload.asp','ft_upload','width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,toolbar=no');
}

var	pp_upload	= '';

function upload_close() {
	if (pp_upload) {
		pp_upload.window.close();
	}
}

/*# VERIFICA DATA #*/
function verificaData(vc_campo) { 
	if (vc_campo.value.length > 0) {  
		it_dia		= (vc_campo.value.substring(0,2)); 
		it_mes		= (vc_campo.value.substring(3,5)); 
		it_ano		= (vc_campo.value.substring(6,10)); 
		it_erro		= 0; 
		
		if ((it_dia < 01) || (it_dia < 01 || it_dia > 30) && (it_mes == 04 || it_mes == 06 || it_mes == 09 || it_mes == 11 ) || it_dia > 31) { 
			it_erro	= 1; 
		} 

		if (it_mes < 01 || it_mes > 12 ) { 
			it_erro	= 1; 
		} 

		if (it_mes == 2 && (it_dia < 01 || it_dia > 29 || (it_dia > 28 && (parseInt(it_ano / 4) != it_ano / 4)))) { 
			it_erro	= 1; 
		} 

		if ((it_ano < 1900) || (it_ano>2078)){
			it_erro	= 1;
		}
		
		if (it_erro == 1) { 
			alert("Por favor, preencha uma data válida!"); 
			vc_campo.value	= '';
			vc_campo.focus(); 
		}
	} 
}

/*# VISUALIZAR #*/
function visualizar(vc_arquivo,id_item) {
	var W	= 600; 	
	var H	= 400;
	var X	= Math.ceil( (window.screen.height - H) / 2 ) - 20;
	var Y	= Math.ceil( (window.screen.width - W) / 2 ) - 16;
	
	window.open('../relatorios/'+vc_arquivo+'.asp?id='+id_item,vc_arquivo+'_'+id_item,'width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,toolbar=no');
}


function ampliar(vc_arquivo,it_largura,it_altura) {
	var W	= it_largura; 	
	var H	= it_altura;
	var X	= Math.ceil( (window.screen.height - H) / 2 ) - 20;
	var Y	= Math.ceil( (window.screen.width - W) / 2 ) - 16;
	
//	window.open('../imagens/banco/'+vc_arquivo,'','width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,toolbar=no');
	window.open('../pop/imagem.asp?arquivoVC='+vc_arquivo+'&alturaIT='+it_altura+'&larguraIT='+it_largura,'','width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,toolbar=no').focus();
}