/****************************************************************
*	Criado em:		30/01/2007			Por: ANDRÉ LUIZ
*	Alterado em:	18/12/2007			Por: ANDRÉ LUIZ
****************************************************************/

/*# 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);
}

function showNatal(vc_display){
	if(document.getElementById('id_mensagem_natal')){
		document.getElementById('id_mensagem_natal').style.display = vc_display;
	}

	//with(document.geElementById('id_mensagem_natal')){
		//style.display = vc_display
	//}
}

/********************************************************************************
Desenvolvido em:	13/08/2007		Autor: 			ANDRÉ LUIZ
Alterado em:		15/08/2007		Autor: 			ANDRÉ LUIZ

Funcionalidade:	Abre a janela de pop-up em javascript
********************************************************************************/
/*# abre popUps via DOM e AJAX */
function winPopUpDOM(W, H, it_zIndex, vc_titulo, vc_url) {
	var win	= new Window({className:"alphacube", width:W, height:H, zIndex:it_zIndex, resizable:false, title:vc_titulo,  draggable:true, maximizable:false, minimizable:false, wiredDrag:true, url:vc_url, destroyOnClose:true, showEffect:Effect.SlideDown, hideEffect: Effect.SlideUp, fps:40, duration:12});
	win.showCenter(true);
	win.refresh(this);
}


/********************************************************************************
Desenvolvido em:	13/08/2007		Autor: 			ANDRÉ LUIZ

Funcionalidade:	Rolar DIV com conteúdo sem usar barra de rolagem
********************************************************************************/
var it_tempo	= 0;

function scrollUp(it_velocidade, vc_div) {
	var it_velocidade			= (it_velocidade) ? parseInt(it_velocidade) : 0;
	var dv_conteudo				= document.getElementById(vc_div);
	var it_altura				= 0;
	
	if (it_velocidade > 0 && dv_conteudo.scrollTop != it_altura) {
		dv_conteudo.scrollTop	= parseInt(dv_conteudo.scrollTop - it_velocidade);
		
		it_tempo	= setTimeout("scrollUp(" + it_velocidade + ", '" + vc_div + "')", 50);
	} else {
		clearTimeout(it_tempo);
		return false;
	}
}

function scrollDown(it_velocidade, vc_div) {
	var it_velocidade			= (it_velocidade) ? parseInt(it_velocidade) : 0;
	var dv_conteudo				= document.getElementById(vc_div);
	var it_altura				= parseInt(dv_conteudo.scrollHeight);
	
	if (it_velocidade > 0 && dv_conteudo.scrollTop < it_altura) {
		dv_conteudo.scrollTop	= parseInt(dv_conteudo.scrollTop + it_velocidade);
		
		it_tempo	= setTimeout("scrollDown(" + it_velocidade + ", '" + vc_div + "')", 50);
	} else {
		clearTimeout(it_tempo);
		return false;
	}
}


/*# fecha imagem de natal [homepage] */
function hideImage(vc_id){
	var vc_id		= new String(vc_id);
	
	if(vc_id.length > 0){
		var im_00	= document.getElementById(vc_id);
		im_00.style.visibility	= 'hidden';
	}
	return false;
}

function imgRand(numTotal, numSort) {
	
	numPossibilidades = numTotal - numSort; 
    aleat = Math.random() * numPossibilidades; 
    aleat = Math.floor(aleat) ;
    sorteado = parseInt(numSort) + aleat;
	document.images['imagem'].src='imagens/layout/img_rnd'+sorteado+'.jpg';
}

function iniciarRand(){
	setInterval('ordImg(document.images["imagem"].getAttribute("valor"))',5000);
}

function ordImg(numero) {
	var im_nova       = new Image(); 
	
	var sorteado = parseInt(numero) + 1;
    if (sorteado > 10) {
		sorteado = 1;
	    im_nova.src       = 'imagens/layout/img_rnd'+sorteado+'.jpg';
        document.images['imagem'].src = im_nova.src;
	} else {
		im_nova.src       = 'imagens/layout/img_rnd'+sorteado+'.jpg';
        document.images['imagem'].src = im_nova.src;
	}
	document.images['imagem'].setAttribute("valor", sorteado);
}

