/*# 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;
	}
}

function cancelar(id_pagamento) {
	var pergunta					= confirm('Você realmente deseja cancelar este boleto?');
	
	if (pergunta) {
		parent.codigo.location.href = '../codigos/pagamento.asp?act=4&id_pagamento='+id_pagamento;
	}
}

/*# 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;
				}
			}
		}
	}
}

/*# MASCARA MOEDA DA PARCELA#*/
function mascaraMoedaParcela(valor,cx) {
	if (valor) {
		var doc					= 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 >= 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;
	}
}

/*# LIMPA POP SELECT */
function limpa_pop_select(campo) {
	var id_item			= eval('document.all.'+campo.replace('vc', 'id'));
	var vc_item			= eval('document.all.'+campo);
	
	if (vc_item.value == '') {
		id_item.value	= '';
		vc_item.value	= 'clique e tecle ENTER';
	}
}

/*# POP SELECT #*/
function pop_select_default(vc_campo) {
	if (typeof(vc_campo) != "object") {
		var vc_campo	= eval('document.frm.'+vc_campo);
	}

	if(vc_campo.value == '') {
		vc_campo.value	= 'clique e tecle ENTER';
	}
}

/*# 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');
	}	
}

/*# POP SELECT COMPOSTO - (USADO NO DOM) #*/
function pop_select_composto(vc_campo,vc_termo,vc_codigo){

	/* ESTA PARTE É PARA O POP DE PESQUISA NÃO TRAGA OS QUE JÁ ESTÃO SELECIONADAS */
	var trID = eval('document.all.'+vc_campo.replace('vc','id')+'_item');
	var vc_excessao = '';
	var x = 0
	
	if (typeof(trID) == 'object' && trID.length > 0){
		for (i=0;i<trID.length;i++){
			vc_excessao += trID[i].value + ','
		}
		vc_excessao = vc_excessao.substring(0,vc_excessao.length-1)
	}
	else if (typeof(trID) == 'object'){
		vc_excessao = trID.value
	}
	
	var vc_campo	= vc_campo.replace('vc','select_composto');
	
	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_codigo='+vc_codigo+'&vc_termo='+vc_termo+'&vc_excessao='+vc_excessao,'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();	
}

/*# 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(); 
		}
	} 
}

/*# verifica se a data de INÍCIO é menor que a de FIM */
function validaPeriodo(dt_inicio, dt_fim) {
	var dt_inicio  	= dt_inicio.value.split('/');
	var dt_fim 		= dt_fim.value.split('/');
	var vc_inicio  	= '';
	var vc_fim 		= '';
	var tx_msg		= '';

	var inicio		= new Date(dt_inicio[2], dt_inicio[1], dt_inicio[0], 0, 0, 0, 0);
	var fim			= new Date(dt_fim[2], dt_fim[1], dt_fim[0], 0, 0, 0, 0);
	
	if (fim < inicio)
		// ERRO
		return false;
	else
		// OK
		return true;
}

function emitirBoleto(vc_arquivo,id_item) {
	var W	= 700; 	
	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('../../pagamentos/itau.asp?id_pagamento='+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');
}

/*# 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');
}

/*POP-UP PARA O CALENDÁRIO*/
function pop_calendario(vc_campo,dt_now) {
	if(dt_now != ''){
		var vc_date	= dt_now;
		}
	var W = 338;
	var H = 155;
	var X = Math.ceil( (window.screen.height - H) / 2 );
	var Y = Math.ceil( (window.screen.width - W) / 2 );
	window.open('../visualizacoes/calendario.asp?vc_campo='+vc_campo+'&date='+vc_date+'','pp_calendario','width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=yes,menubar=no,scrollbars=no,resizable=no,directories=no,toolbar=no');
}

/*PREENCHER A DATA SELECIONADA NA JANELA QUE ABRIU - ELA É INVOCADA PELA FUNÇÃO ACIMA*/
function preencher_data(vc_campo1,vc_valor){
	if(vc_campo1 != '' && vc_valor != ''){
		var campovc 	= eval('window.opener.document.all.'+vc_campo1+'');
		campovc.value	= vc_valor;
		campovc.focus();
		window.close();
	}
}

function desabilitaCampos(it_tipo){
	if(it_tipo == 1){
		if(document.all.dt_inscricao.value.length > 0){
			document.all.dt_inicial.disabled = true;
			document.all.dt_final.disabled = true;
		} else {
			document.all.dt_inicial.disabled = false;
			document.all.dt_final.disabled = false;
		}
	} else {
		if(document.all.dt_inicial.value.length > 0 || document.all.dt_final.value.length > 0){
			document.all.dt_inscricao.disabled = true;
		} else {
			document.all.dt_inscricao.disabled = false;
		}
	}
}

function mudaTipoData(id_status){
	if(id_status == 3){
		var htm_filtro ='<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">';
		htm_filtro +=	'<tr>';
		htm_filtro +=	'<td colspan=\"2\"><b>Data de Vencimento</b></td>';
		htm_filtro +=	'</tr>';
		htm_filtro +=	'<tr>';
		htm_filtro +=	'<td colspan=\"2\"><input type=\"text\" name=\"dt_inicial_vencimento\" maxlength=\"10\" style=\"width:85px;\" class=\"bx_01\" onKeyPress=\"return soNumero(event);\" onKeyUp=\"mascarar(this,\'##/##/####\');\" onBlur=\"verificaData(this);\"> a <input type=\"text\" name=\"dt_final_vencimento\" maxlength=\"10\" style=\"width:85px;\" class=\"bx_01\" onKeyPress=\"return soNumero(event);\" onKeyUp="mascarar(this,\'##/##/####\');\" onBlur=\"verificaData(this);\"></td>';
		htm_filtro +=	'</tr>';
		htm_filtro +=	'</table>';
	} else {
		var htm_filtro ='<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">';
		htm_filtro +=	'<tr>';
		htm_filtro +=	'<td colspan=\"2\"><b>Data de Emissão</b></td>';
		htm_filtro +=	'</tr>';
		htm_filtro +=	'<tr>';
		htm_filtro +=	'<td colspan=\"2\"><input type=\"text\" name=\"dt_inicial_emissao\" maxlength=\"10\" style=\"width:85px;\" class=\"bx_01\" onKeyPress=\"return soNumero(event);\" onKeyUp=\"mascarar(this,\'##/##/####\');\" onBlur=\"verificaData(this);\"> a <input type=\"text\" name=\"dt_final_emissao\" maxlength=\"10\" style=\"width:85px;\" class=\"bx_01\" onKeyPress=\"return soNumero(event);\" onKeyUp="mascarar(this,\'##/##/####\');\" onBlur=\"verificaData(this);\"></td>';
		htm_filtro +=	'</tr>';
		htm_filtro +=	'</table>';
	}
	document.all.td_opcao.innerHTML	= '';
	document.all.td_opcao.innerHTML	= htm_filtro;
}

function liberaPagamento(id_pagamento) {
	parent.codigo.location.href = '../codigos/pagamento_liberacao.asp?id_pagamento='+id_pagamento;
}

function verificaBaixa(){
	if(frm.dt_de.value.length == 0){
		alert('Preencha a DATA DE INÍCIO.');
		return false;
	}
	if(frm.dt_ate.value.length == 0){
		alert('Preencha a DATA DE FIM.');
		return false;
	}
}

function ficha_medica(id_cliente){
	parent.formulario.location.href = '../formularios/ficha_medica.asp?id_cliente='+id_cliente;
}

/*# GALERIA #*/
function galeria(act,vc_arquivo,id_item) {
	parent.formulario.location.href	= '../formularios/galeria_arquivo.asp?act='+act+'&id_'+vc_arquivo+'='+id_item;
}

function pop_select_pesquisa() {
	document.psq.submit();
}

/*# GET RADIO VALUE  #*/
function get_radio_value (radio_array)
{
 var i;
 for (i = 0; i < radio_array . length; ++ i)
  if (radio_array [i] . checked)
   return radio_array [i] . value;
 return null;
}

/*# REPLACE GERAL - Função replace que substitui todos e não só um como a padrão #*/
function replaceGeral(vc_texto, vc_str_1, vc_str_2){
	/*		vc_texto	= String onde será procurado o valor
			vc_str_1	= Valor que deve ser substituido.
			vc_str_2	= Valor por qual deve ser substituido		*/
			
	while (vc_texto.indexOf(vc_str_1) > 0){
		vc_texto	= vc_texto.replace(vc_str_1,vc_str_2);
	}

	return vc_texto;
}

/*# TRIM - Função que verifica se há espaços no início e fim de uma string, semelhante ao trim #*/
function trim(vc_string) {

	 //Remove os espaços do Inicio
	 while ((vc_string.substring(0,1) == ' ') || (vc_string.substring(0,1) == '\n') || (vc_string.substring(0,1) == '\r')) {
	   vc_string = vc_string.substring(1,vc_string.length);
	 }
	
	 //Remove os espaços do Final
	 while ((vc_string.substring(vc_string.length-1,vc_string.length) == ' ') || (vc_string.substring(vc_string.length-1,vc_string.length) == '\n') || (vc_string.substring(vc_string.length-1,vc_string.length) == '\r'))	{
	   vc_string = vc_string.substring(0,vc_string.length-1);
	 }
	
	return vc_string;
}