/*
'********************************************************************************
' Criado em:		17/10/2006			Por: ANDRÉ LUIZ [REPOSITÓRIO]
'********************************************************************************
*/

/*#ONLOAD#*/
window.name = 'ag_browser';

/*# funcionalidades das TAGs */
sfHover = function() {
	if (document.getElementById("nav")) {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



/*# funcionalidades do menu */
mnHover = function() {
	if (document.getElementById("menu")) {
		var sfEls = document.getElementById("menu").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" mnHover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" mnHover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", mnHover);

/*# controla dropDown ao visualizar um submenu de forma a ele ñ ficar em cima do submenu */
var it_tempo	= 0;
function showDD() {
	it_tempo	= setTimeout('showDropDown()', 100);
}

function showDropDown() {
	if (document.getElementById('dd_tipo')) {
		var dd_tipo	= document.getElementById('dd_tipo').style.display	= 'block';
	}
}

function hideDropDown() {
	clearTimeout(it_tempo);
	if (document.getElementById('dd_tipo')) {
		var dd_tipo	= document.getElementById('dd_tipo').style.display	= 'none';
	}
}


/*# adiciona site aos favoritos */
function addBookmark(title,url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	}
	else if( document.all ) {
		window.external.AddFavorite( url, title);
	}
	else {
		return true;
	}
}

/*# IFRAME VIRTUAL #*/
function iframeVirtual(urlVC) {
	codigo.location.href			= urlVC;
}

/*# GET RADIO VALUE #*/ //Retorna o value de um grupo de rádio com mesmo nome
function get_radio_value (radio_array)
{
 var i;
 for (i = 0; i < radio_array . length; ++ i)
  if (radio_array [i] . checked)
   return radio_array [i] . value;
 return null;
}


/*# 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;
	}
}

/*# VERIFICAR INDIQUE SITE #*/
function verificar_indiqueSite(){

	var vc_erro	=	'';
	if(document.getElementById('nomeVCI').value == '') {vc_erro	+=	'- Seu Nome\n';}
	if(document.getElementById('emailVCI').value == ''){vc_erro 	+=	'- Seu E-mail\n';}
	if(document.getElementById('nome2VCI').value == ''){vc_erro 	+=	'- Nome do amigo\n';}
	if(document.getElementById('email2VCI').value == ''){vc_erro += 	'- E-mail do amigo\n';}
	if(vc_erro.length > 0){
		alert('- ATENÇÃO \n \nPreencha os seguintes campos: \n'+vc_erro);
	}else{
		document.indicacaoFRM.submit();
	}
}


/*# VERIFICAR FALE CONOSCO PALESTRA #*/
function verificar_faleconosco(){

	var vc_erro	=	'';
	if(document.getElementById('vc_nome').value == '') {vc_erro	+=	'- Nome\n';}
	if(document.getElementById('vc_email').value == ''){vc_erro 	+=	'- E-mail\n';}
	if(document.getElementById('vc_telefone').value == ''){vc_erro 	+=	'- Telefone\n';}
	if(document.getElementById('tx_mensagem').value == ''){vc_erro += 	'- Mensagem\n';}
	if(vc_erro.length > 0){
		alert('- ATENÇÃO \n \nPreencha os seguintes campos: \n'+vc_erro);
	}else{
		document.faleconoscoFRM.submit();
	}
}


/*# MUDA ORDEM DO PACOTE #*/
function mudaOrderPacote(it_order,vc_string){
			
	if (it_order > 0){
		location.href	= "?"+vc_string+"&order_pacoteIT="+it_order;
	}
}



/*#SO NUMERO#*/
function soNumero(eventoN) {
	if (document.all) {
		var teclaN = event.keyCode;
	} else if(document.layers) {
		var teclaN = eventoN.which;
	}
	
	if (teclaN >= 48 && teclaN <= 57) {
		return true;
	} else if (teclaN != 8) {
		if (document.all) {
			event.keyCode	= 0;
		} else if(document.layers) {
			eventoN.which	= 0;
		}
	} else {
		return true;
	}
}


/*# VERIFICA DATA #*/
function verificaData(campoVC) { 
	if (campoVC.value.length > 0) {  
		diaN = (campoVC.value.substring(0,2)); 
		mesN = (campoVC.value.substring(3,5)); 
		anoN = (campoVC.value.substring(6,10)); 
		erroN = 0; 
		
		if ((diaN < 01) || (diaN < 01 || diaN > 30) && (mesN == 04 || mesN == 06 || mesN == 09 || mesN == 11 ) || diaN > 31) { 
			erroN = 1; 
		} 

		if (mesN < 01 || mesN > 12 ) { 
			erroN = 1; 
		} 

		if (mesN == 2 && (diaN < 01 || diaN > 29 || (diaN > 28 && (parseInt(anoN / 4) != anoN / 4)))) { 
			erroN = 1; 
		} 

		if ((anoN < 1900) || (anoN>2078)){
			erroN = 1;
		}
		
		if (erroN == 1) { 
			campoVC.value	= '';
			campoVC.focus(); 
			alert("Por favor, preencha uma data válida!"); 
		}
	} 
}


/*# mostra detalhes do pedido e esconde o resumo do mesmo
	Utilizado em 'Historico de Pedidos' */
function showDetalhes(id) {
	if (document.getElementById(id)) {
		document.getElementById(id).style.display				= 'none';
		
		// resolve problema de incompatibilidade entre IE e FF
		if (document.all) {
			document.getElementById('DET_' + id).style.display	= 'block';
		} else {
			document.getElementById('DET_' + id).style.display	= 'table-row';
		}
	}
}


/*# esconde detalhes do pedido e mostra o resumo do mesmo
	Utilizado em 'Historico de Pedidos' */
function hideDetalhes(id) {
	if (document.getElementById(id)) {
		// resolve problema de incompatibilidade entre IE e FF
		if (document.all) {
			document.getElementById(id).style.display		= 'block';
		} else {
			document.getElementById(id).style.display		= 'table-row';
		}
		
		document.getElementById('DET_' + id).style.display	= 'none';
	}
}

/*# LOGOFF #*/
function logoff(actA) {
	codigo.location.href='codigos/logoff.asp?actA='+actA;
}


/*REEMITIR BOLETO*/
function reemitirBoleto(id_pedido) {

	codigo.location.href= 'pagamentos/itau.asp?pedidoID='+id_pedido+'&reemissao_historicoIT=1';
}

function gravaBusca(vc_termo){
	iframeVirtual('temp/conta_busca.asp?vc_termo='+vc_termo);
	return false;
}

/*FUNÇÃO UTILIZADA PARA CONTABILIZAR OS DOWNLOADS*/
function contabilizaDownloads(id_arquivo, id_palestra, id_matricula){
	iframeVirtual('temp/conta_downloads_arquivo.asp?arquivoID='+id_arquivo+'&palestraID='+id_palestra+'&matriculaID='+id_matricula+'');	
	//iframeVirtual('temp/conta_downloads_arquivo.asp?arquivoVC='+vc_arquivo+'&arquivoID='+id_arquivo+'&palestraID='+id_palestra+'&matriculaID='+id_matricula+'');		
}

function el(id)
{
    return document.getElementById(id);
}

function downloadClick(idPalestra,idMatricula)
{
    frm = window.frames['if_' + (idPalestra) + '_' + (idMatricula)];
    frm.location = 'about:blank';
    frm.document.write('<HTML><BODY style="margin: 0; font-family: arial; color: red; font-size: 12px">Aguarde, download sendo processado...</BODY></HTML>');

    id = 'downloadAtivo_' + (idPalestra) + '_' + (idMatricula);
    el(id).style.display = 'block';
    
    frm.location = 
        'web2/Palestras/downloadPalestra.aspx?idPalestra=' + 
        (idPalestra) + '&idMatricula=' + (idMatricula) +
        '&rnd=' + Math.random();
        
    escondeAoIniciarDownload(idPalestra,idMatricula,id);
    
    sp = el('spDownloads_' + (idPalestra) + '_' + (idMatricula));
    count = parseInt(sp.innerHTML.substr(sp.innerHTML.length-2));
    if (count > 0)
    {
        count--;
        sp.innerHTML = sp.innerHTML.substr(0, sp.innerHTML.length-1) + (count);
    }
}

function escondeAoIniciarDownload(idPalestra,idMatricula,id)
{
    frm = window.frames['if_' + (idPalestra) + '_' + (idMatricula)];
    try
    {
        ocupado = ((frm.document.readyState != 'complete') && (frm.document.readyState != 'interactive'));
    }
    catch(err)
    {
        ocupado = 0;
    }
    
    if (frm.modoErro) // erro
    {
    }
    else if (!ocupado)
        el(id).style.display = 'none';
    else if (!window.document.readyState && !window.busy)
        setTimeout('el(\'' + id + '\').style.display = \'none\'', 10000);
    else
        setTimeout('escondeAoIniciarDownload(' + (idPalestra) + ',' + (idMatricula) + ',\'' + id + '\')', 1000);
}