/*********************************************************************************
' Criado em    :		27/12/2006			Por: ANDRÉ LUIZ
' Atualizado em:		24/01/2007			Por: RONI COSTA
' Atualizado em:		05/02/2007			Por: RONI COSTA
' Atualizado em:		22/03/2007			Por: RONI COSTA
'*********************************************************************************/

/*# mostra/esconde detalhes de alguma notícia */
function showHideDetalhe(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	= 'block';
	}
}


/*# mostra submenu */
function subMenu(vc_menu, vc_ativo) {
	
	vc_ativo	= (vc_ativo) ? vc_ativo.toLowerCase() : '';	// pega valor do link ativo e converte p/ minusculas
	
	// verifica se o elemento existe
	if (document.getElementById(vc_menu)) {
		var obj_menu	= document.getElementById(vc_menu);
		var vc_display	= obj_menu.style.display;	// guarda o valor do display
		
		hideAllMenu();	//	esconde todos os submenus
		
		if (vc_display != 'none')
			obj_menu.style.display	= 'none';
		else
			obj_menu.style.display	= 'block';
		
		if (vc_ativo.length > 0) {
			var ar_sub	= obj_menu.childNodes;	// monta array com os elementos contidos no submenu
			
			// percorre array
			for (var i in ar_sub) {
				// verifica se é o link correto a ser ativado
				if (ar_sub[i].nodeName == 'A' && ar_sub[i].getAttribute('secaoID') == vc_ativo) {
					ar_sub[i].className = 'lk_ativo';	// ativao link
					break;	//sai do laço
				}
			}
		}
	}
}


/*# esconde todos os submenus */
function hideAllMenu() {
	// verifica se o elemento existe
	if (document.getElementById('menu')) {
		var obj_li	= document.getElementById('menu').childNodes;	// pega todos os elementos filhos do menu
		
		// percorre por todos os elementos da array
		for (var i in obj_li) {
			// verifica se o elemento deve ser escondido
			if (obj_li[i].nodeName == 'LI' && obj_li[i].getAttribute('tipo') == 'subMN' && obj_li[i].style.display != 'none') {
				obj_li[i].style.display	= 'none';	// esconde elemento
			}
		}
	}
}



var i		= 0;	// contador das imgs (índice)
var it_lk	= 0;	// indice do link da 1ª img

/*# passa as imagens q estão declaradas na array 'ar_img' */
function slideShow(){
	
	//Recupera no form os valores e monta uma array
	ar_img			= document.getElementById("mantenedorVC").value.split(",");
	ar_lk			= document.getElementById("linkVC").value.split(",");
	ar_categoria	= document.getElementById("categoriaVC").value.split(",");
	
	if (!document.images.slide) return;	// caso ñ haja imagens, sai da função
	
	document.images.slide.src							= '../imagens/parceiro/'+ar_img[i];	// insere próxima imagem
	document.getElementById("vc_categoria").innerHTML	= ar_categoria[i] + ':';	// atualiza nome da categoria do financiador
	it_lk												= i;	// atualiza o indice do link da 1ª imagem
	 
	// verifica se chegou no fim das imagens p/ zerar o contador
	if (i < ar_img.length - 1)
		i++;
	else
		i	= 0;
		
	setTimeout("slideShow()",3000);	// muda a foto a cada 3 segundos
}

/*# abre o link da imagem atual */
function slideLink(){
	
	//Recupera no form os valores e monta uma array
	ar_img	= document.getElementById("mantenedorVC").value.split(",");
	ar_lk	= document.getElementById("linkVC").value.split(",");
	
	if (ar_lk[it_lk].length > 0){
		window.open(ar_lk[it_lk]);
	}else{
		void(null);
	}
}



/*#SO NUMERO#*/
function soNumero(evtKeyPress) {
	var nTecla;
	nTecla = (evtKeyPress.which) ? evtKeyPress.which : evtKeyPress.keyCode;
	
	if (nTecla == 17 || nTecla == 18){
		return true;
	}
	
	if (nTecla >= 48 && nTecla <= 57) {
		return true;
	} else if (nTecla != 8) {
		return false;
	} else {
		return true;
	}
		
	if (nTecla >= 96 && nTecla <= 105) {
		return true;
	} else if (nTecla != 8) {
		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("Please use a valid date!!"); 
			vc_campo.value	= '';
			vc_campo.focus(); 
		}
	} 
}


/*# 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;
	}
}

/*# 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);

}
