/****************************************************************
*	Criado em: 30/01/2007			Por: ANDRÉ LUIZ
****************************************************************/

/*# mostra/esconde responstas das FAQs */
function showHideResposta(vc_obj) {
	// verifica se o elemento existe
	if (document.getElementById(vc_obj)) {
		var obj_detalhe	= document.getElementById(vc_obj);
		
		if (obj_detalhe.style.display != 'none')
			obj_detalhe.style.display	= 'none';
		else
			obj_detalhe.style.display	= 'inline';
	}
}


/*# mostra/esconde forms */
function showHideForm(vc_obj) {
	// verifica se o elemento existe
	if (document.getElementById(vc_obj)) {
		var dv_00	= document.getElementById(vc_obj);
		
		if (dv_00.style.display != 'none')
			dv_00.style.display	= 'none';
		else
			dv_00.style.display	= 'block';
		
		// reseta form
		eval('document.frm_' + vc_obj + '.reset()');
	}
}

/*# 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';
}

/*# VALIDA E-MAIL 
function verficaEmail(campo) {
	var vc_err			= '';
	
	if (campo.length != 0) {
		invalidChars	= "/:,;!?<>*&^%$#(){}|~`";
		atPos			= campo.indexOf("@",1);
		periodPos		= campo.indexOf(".",atPos);
		
		for (i=0; i<invalidChars.lenght; i++) {
			badChar		= invalidChars.charAt(i);
			
			if (campo.length.indexOf(badChar,0) > -1) {
			 	vc_err = '- O E-MAIL digitado é inválido.\n';
			}
		}
		if (atPos == -1) {
			 vc_err	= '- O E-MAIL digitado é inválido.\n';
		}
		if(campo.indexOf("@",atPos+1) > -1) {
			 vc_err	= '- O E-MAIL digitado é inválido.\n';
		}
		if (periodPos == -1) {
			 vc_err	= '- O E-MAIL digitado é inválido.\n';
		}
		if ((periodPos+3) > campo.length) {
			 vc_err	= '- O E-MAIL digitado é inválido.\n';
		}
	}
	return vc_err;
}
*/

/*# 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');
	
	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);
}

function popup(actA){
		
		var W 	= 600; 	
		var H 	= 450;
		var X 	= Math.ceil( (window.screen.height - H) / 2 );
		var Y 	= Math.ceil( (window.screen.width - W) / 2 );

		window.open('popup/popup.asp?actA='+actA+'','popup', 'width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,toolbar=no');
}

function popup(actA, w, h){
		
		var W 	= w; 	
		var H 	= h;
		var X 	= Math.ceil( (window.screen.height - H) / 2 );
		var Y 	= Math.ceil( (window.screen.width - W) / 2 );

		window.open('popup/popup.asp?actA='+actA+'','popup', 'width='+W+',height='+H+',top='+X+',left='+Y+',location=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,toolbar=no');
}