/****************************************************************
*	Criado em: 30/01/2007			Por: ANDRÉ LUIZ
****************************************************************/

function ordenaPesquisa(it_acompanhante)	{
	if (it_acompanhante != 0)
	{		
		htm_filtro +=  '<form name=\"frm\">'
		var htm_filtro  = 	'<input type=\"hidden\" name=\"vc_termo\" value=\"\">';
		htm_filtro +=	'<table cellpadding=\"1\" cellspacing=\"3\" width=\"100%\">';
		htm_filtro +=	'<tr class=\"tr_02\" >';
		htm_filtro +=	'<td valign = \"top\" bgcolor=\"#A2B7E9\"><font color=\"#000000\"><b>Nome</b></font></td>';
		htm_filtro +=	'<td valign = \"top\" bgcolor=\"#A2B7E9\"><font color=\"#000000\"><b>Data de Nasc.</b></font></td>';
		htm_filtro +=	'<td valign = \"top\" bgcolor=\"#A2B7E9\"><font color=\"#000000\"><b>Sexo</b><br/></font></td>';
		htm_filtro +=	'<td valign = \"top\" bgcolor=\"#A2B7E9\"><font color=\"#000000\"><b>RG</b><br/></font></td>';
		htm_filtro +=	'</tr>';		
		for (i=0; i<it_acompanhante; i++) {
		    htm_filtro +=	'<tr>';
			htm_filtro +=	'<td valign = \"top\"><input type=\"text\" class=\"bx_00 bd_01\" name=\"vc_nomes\" value=\"\" maxlength=\"255\" style=\"width:100px;\"></td>';
			htm_filtro +=	'<td valign = \"top\"><input type=\"text\" name=\"dt_nascimento\" class=\"bx_00 bd_01\" maxlength=\"10\" style=\"width:65px;\"  onKeyUp=\"mascarar(this,\'##/##/####\');\" onBlur=\" verificaData(this);\"></td>';
			htm_filtro +=   '<td valign = \"top\"><select name=\"it_sexo\" class=\"bx_00 bd_01\" class=\"bd_01\" style=\"width:80px\">'
			htm_filtro +=	'<option value=\"\">Selecione</option>'
			htm_filtro +=   '<option value=\"Masculino\">Masculino</option>'
			htm_filtro +=   '<option value=\"Feminino\">Feminino</option>'
			htm_filtro +=   '</select></td>';
			htm_filtro +=   '<td valign = \"top\"><input type=\"text\" class=\"bx_00 bd_01\" name=\"vc_rg\" value=\"\" style=\"width:100px;\"></td>';
			htm_filtro +=	'</tr>';
		}
		htm_filtro +=	'</tr>';
		htm_filtro +=	'</table>';
		htm_filtro +=	'</form>';
	
		parent.document.all.js_filtro.innerHTML	= '';
		parent.document.all.js_filtro.innerHTML	= htm_filtro;;
	}
	else if (it_acompanhante == 0){
	{		
		parent.document.all.js_filtro.innerHTML	= '';	
	}
	
	
	}
}

/*# VALIDA E-MAIL [expressão regular] */
function verficaEmail(campo) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(campo)) {
		return	'';
	}
	return '- O E-MAIL digitado é inválido.\n';
}

/*# aceita só números digitados num campo */
function soNumero(evtKeyPress) {
	var nTecla;
	nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
	
	if((nTecla > 47 && nTecla < 58) || nTecla == 8 || nTecla == 9)
		return true;
	else
		return false;
}

/*# 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);
	}
}

/*# 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(); 
		}
	} 
}

/*# iFrame virtual [ crossBrowser ] #*/
function iframe_virtual(vc_url) {
	// pega iframeVirtual pelo ID ou cria um iframeVirtual caso ñ exista
	var tempIFrame		= (document.getElementById('iframe_virtual')) ? document.getElementById('iframe_virtual') : document.createElement('iframe');
	
	with(tempIFrame) {
		style.border	= '0px';
		style.width		= '0px';
		style.height	= '0px';
	
		setAttribute('id','iframe_virtual');
		setAttribute('name','iframe_virtual');
		setAttribute('src',vc_url);
	}
	
	IFrameObj		= document.body.appendChild(tempIFrame);
}

/*# 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;
	}
}

/*#  Valida LOGON */
function validaLogon(){
	
	var vc_erro = '';
	if(document.getElementById('vc_email').value == ''){
		vc_erro	+=	'- Insira o E-MAIL\n';
	}
	if(document.getElementById('vc_senha').value == ''){
		vc_erro	+=	'- Insira a SENHA\n';
	}
	
	if(vc_erro.length > 0){
		alert('- ATENÇÃO\n Os seguintes dados são obrigatórios\n\n'+vc_erro)	;
	}else
	{
		document.frm.submit();
		}
}

/*# 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;
}

/*# Alternativa ao getElementsByName [ apenas p/ o IE ] */
function getElementsByNameIE(vc_tag, vc_name) {
	var ar_elem		= document.getElementsByTagName(vc_tag);
	var ar_retorno	= new Array();
	var vc_atributo	= new String();
	
	for(i = 0, iarr = 0; i < ar_elem.length; i++) {
		vc_atributo = ar_elem[i].getAttribute('name');
		
		if(vc_atributo == vc_name) {
			ar_retorno[iarr] = ar_elem[i];
			iarr++;
		}
	}
	
	return ar_retorno;
}


/************************************************************************
*	MascaraMoeda CROSSBROWSER				ANDRÉ LUIZ					*
*																		*
*	Exemplo de chamada:		mascaraMoeda(this.value, this.id, event);	*
*************************************************************************/
function mascaraMoeda(valor,cx,evtKeyPress) {
	if (valor) {
		var doc     = eval('document.getElementById("'+cx+'")');
		var nTecla	= (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
		
		if (nTecla == 110 || nTecla == 188 || nTecla == 190 || nTecla == 194) {
			return false;
		} else {
			valor		= mascararCentavo(valor);
		
			if (mascararCentavo(valor).length > 2) {
				str			= valor.replace(".", "");
				doc.value	= str.substr(0,(str.length-2)) + "." + str.substr((str.length-2),str.length);
			} else {
				valor		= mascararCentavo(valor);
				
				if (valor.length == 1) {
					doc.value	= "0.0" + valor;
				} else {
					doc.value	= "0." + valor;
				}
			}
		}
	}
}
	
function mascararCentavo(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;
}


/*# alternativa ao getElementsByName [ APENAS P/ IE ] */
function getElementsByNameIE(vc_tag, vc_name) {
	var ar_elem		= document.getElementsByTagName(vc_tag);
	var ar_retorno	= new Array();
	var vc_atributo	= new String();
	
	for(i = 0, iarr = 0; i < ar_elem.length; i++) {
		vc_atributo = ar_elem[i].getAttribute('name');
		
		if(vc_atributo == vc_name) {
			ar_retorno[iarr] = ar_elem[i];
			iarr++;
		}
	}
	
	return ar_retorno;
}

/*# abre popUp */
function popUp(vc_url, W, H) {
	var W	= (W) ? parseInt(W) : parseInt(window.screen.width * 0.7);
	var H	= (H) ? parseInt(H) : parseInt(window.screen.height * 0.7);
	var X	= Math.ceil((window.screen.height - H) / 2);
	var Y	= Math.ceil((window.screen.width - W) / 2);
	
	window.open(vc_url, 'ap_select', 'width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,directories=no,toolbar=no').focus();
}

