/****************************************************************
*	Criado em: 30/01/2007			Por: ANDRÉ LUIZ
****************************************************************/

/*# preload de imagens */
function imagePreload(){
	var ar_imagem	= imagePreload.arguments;
	var im_load		= new Image();
	
	for(var i=0; i < ar_imagem.length; i++){
		im_load.src	= arguments[i];
	}
}

/*# troca a imagem da lateral do site */
function trocaImagem(vc_imagem){
	var im_destaque		= document.images['im_destaque'];
	var vc_imagem		= (vc_imagem) ? new String('imagens/layout/' + vc_imagem) : new String('imagens/layout/none.gif');
	var im_nova			= new Image();
	
	im_nova.src			= vc_imagem
	im_destaque.src		= im_nova.src;
}


/*# 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';
}

/*# CONTA CARACTER #*/
function contaCaracter(campoVC,caracterN,limiteN) {
	if (campoVC.value.length > limiteN) {
		campoVC.value	= campoVC.value.substring(0,limiteN);
	} else {
		caracterN.value	= limiteN - campoVC.value.length;
	}
}

/*# 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);
}


/************************************************************************
*	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;
}

/*# mostra/esconde submenu */
function subMenu(vc_menu, vc_submenu, it_display){
	var lk_menu								= document.getElementById(vc_menu);
	var dv_submenu							= document.getElementById(vc_submenu);
	var it_display							= (it_display)		? it_display	: 0;
	var vc_display							= (it_display == 0)	? 'none'		: 'block';
	var vc_bgPos							= (it_display == 0)	? 'top left'	: 'top right';
	
	if(lk_menu.style.backgroundPosition != vc_bgPos){
		lk_menu.style.backgroundPosition	= vc_bgPos;
		dv_submenu.style.display			= vc_display;
	}
}

/*# faz com queo  iFrame de conteúdo ocupe todo o WIDTH disponível de acordo com a resolução */
function resizeFrame(){
	var iFrame			= document.getElementById('conteudo');
	var winWidth		= document.body.offsetWidth;
	var latWidth		= 263 + 2;	// os 2px somados pertencem as bordas */
	
	with(iFrame.style){
		width	= parseInt(winWidth - latWidth) + 'px';
		display	= 'block';
	}
}


/*# GET RADIO VALUE  #*/
function radioValue(radio_array){
	var i;
	for (i = 0; i < radio_array.length; ++i)
		if (radio_array[i].checked)
			return radio_array[i].value;
	return null;
}

/*# ativa/desativa MUDO no player (usado apenas na HOME do site) */
function playerMudo(blMudo){
	var lkPlayerMudo							= document.getElementById('lkPlayerMudo');
	
	if (blMudo){
		document.getElementById('player').src	= 'blank.htm';
		lkPlayerMudo.onclick					= function() { playerMudo(false); }
		lkPlayerMudo.innerHTML					= 'Desligar Mudo';
		lkPlayerMudo.title						= lkPlayerMudo.innerHTML;
		lkPlayerMudo.style.backgroundImage		= 'url(imagens/layout/bt_14.gif)';
	} else {
		document.getElementById('player').src	= 'player.asp';
		lkPlayerMudo.onclick					= function() { playerMudo(true); }
		lkPlayerMudo.innerHTML					= 'Ligar Mudo';
		lkPlayerMudo.title						= lkPlayerMudo.innerHTML;
		lkPlayerMudo.style.backgroundImage		= 'url(imagens/layout/bt_13.gif)';
	}
	
	return false;
}
