ie = (document.all)? true:false;
// Compatibilizando o event.type para Mozilla
function MOZEventHandlers(_eventos){var i; for (i=0; i< _eventos.length; i++){document.addEventListener(_eventos[i], function(e){window.event = e;}, true);}}
if(!document.all){MOZEventHandlers(["click","mousedown","mouseup","mouseover","mouseout","mousemove","keyup","keydown","load","focus","blur"]);}
//-->

//-- Centralizar o site
function siteCenter(){
	var objBODY = document.getElementsByTagName("body");
	var objAllContent = document.getElementById("allContent");
	objAllContent.style.left = ((objBODY[0].offsetWidth - 760) / 2) + "px";
	objAllContent.style.display = "block";
}
	
//-- Menu superior
function menuItem(id, status){
	var objMenu = document.getElementById(id);
	if(status == 1){
		objMenu.className = "menu_item menu_item_over";
	}else{
		objMenu.className = "menu_item";
	}
}

// Menu popup
var timePopup;
function menuPopup(Event){
	var idPopup = document.getElementById("menu_completo");
	var objBody = document.getElementsByTagName("body");
	
	if(window.event){
		e = window.event;
		var objTarget = (!ie)? e.relatedTarget:e.fromElement;
	}

	if(Event == 0){
		if(idPopup.style.display != "block" && objTarget.getAttribute("id") == "abrir_menuPopup"){
			if(IE6){
				idPopup.style.position = "absolute";
				idPopup.style.top = "25px";
				idPopup.style.right = "10px";
			}else{
				idPopup.style.top = 20 + ((event.clientY - ((ie)? event.offsetY:event.layerY)) - objBody[0].scrollTop) +"px";
				idPopup.style.left = -100 + ((event.clientX - ((ie)? event.offsetX:event.layerX)) - objBody[0].scrollLeft) +"px";
			}
			idPopup.style.display = "block";
		}
		window.clearTimeout(timePopup);
	}else if(Event == 1){
		timePopup = window.setTimeout('menuPopup(2)',2000);
	}else{
		idPopup.style.display = "none";
		window.clearTimeout(timePopup);
	}

}

function AtivarAba(aba)
{
    if ( aba == 'Aluno')
    {
        document.getElementById('lg_stc_1').style.display = '';
        document.getElementById('lg_stc_2').style.display = 'none';
        document.getElementById('abaAluno').className = 'lg_menu_escuro';
        document.getElementById('abaGestor').className = 'lg_menu_claro';
        
    }
    else
    {
        document.getElementById('lg_stc_1').style.display = 'none';
        document.getElementById('lg_stc_2').style.display = '';    
        document.getElementById('abaAluno').className = 'lg_menu_claro';
        document.getElementById('abaGestor').className = 'lg_menu_escuro';
    }
}

function AbreHelpCenter()
{
    window.open('http://helpcentersebrae.webaula.com.br/atendimento/Login.aspx?chave=41-af87dd40e82bf25dd523b5d71fa3ae94&nome=&email=&observacoes=&referer=superprofesionales.webaula.com.br','HelpCenter','width=750,height=550,top=0,left=0,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no');
}

function Estrageiro(blnEstrangeiro)
{
    if (blnEstrangeiro)
    {
        document.getElementById('NaoSouEstrangeiro').style.display = '';
        document.getElementById('SouEstrangeiro').style.display = 'none';    
        document.getElementById('tdLogin').innerHTML = 'LOGIN*';
    }
    else
    {
        document.getElementById('NaoSouEstrangeiro').style.display = 'none';
        document.getElementById('SouEstrangeiro').style.display = '';    
        document.getElementById('tdLogin').innerHTML = 'CPF*';
    
    }
}

function AbreVerificador()
{
	divPopup('divVerificador', '', 'URL', 'http://verificador.webaula.com.br/webaula/default.aspx?pl=<%=Application("PalavraChave")%>', 675, 540, 'middle', 'middle', false, true, true);
}

function AbreCursoDemo(lngCodCurso)
{
	var objJanelaSala;
	objJanelaSala = window.open("/salaframe.asp?curso=" + lngCodCurso + "&turma=0&aluno=0&nomealuno=Demonstração&demonstracao=s", "Topicos", "toolbar=0,status=0,menubar=0,resizable=1,left=1,top=1,width=800,height=545");
}

function AbrirMeuCadastro()
{
    divPopup('divCadastro', '', 'URL', '/cadastro.asp', 750, 500, 'middle', 'middle', false, true, true);    
}

function AbrirCertificados()
{
    divPopup('divCertificados', '', 'URL', '/certificadosPopup.asp?abaSelecionada=1', 685, 250, 'middle', 'middle', false, true, true);    
}
function AbrirDuvidas()
{
    divPopup('divDuvidas', '', 'URL', '/faq_home.asp?OcultarFechar=S', 600, 500, 'middle', 'middle', false, true, true);
}
function AbrirTutorial()
{
    divPopup('divTutorial', '', 'URL', '/tutorial.asp', 800, 600, 'middle', 'middle', false, true, true);
}
function AbrirHistorico(lngCodAluno)
{
    divPopup('divHistorico', '', 'URL', '/meuhistorico.asp?codaluno=' + lngCodAluno, 900, 520, 'middle', 'middle', false, true, true);    
}
function CPFValido(CPF)
{
    if (CPF=="") return true;

    if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" || CPF == "22222222222" || CPF == "33333333333" || CPF == "44444444444" || CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" || CPF == "88888888888" || CPF == "99999999999")
	{
        return false;
	}
		
    soma = 0;
    for (i=0; i < 9; i ++)
            soma += parseInt(CPF.charAt(i)) * (10 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
            resto = 0;
    if (resto != parseInt(CPF.charAt(9)))
            return false;
    soma = 0;
    for (i = 0; i < 10; i ++)
            soma += parseInt(CPF.charAt(i)) * (11 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
            resto = 0;
    if (resto != parseInt(CPF.charAt(10)))
            return false;
    return true;
}
//Retorna o conteudo de uma url acessada
function RPC(_strURL,_Handle,_MethodPost,_Conteudo){
    //Variáveis internas
    var strRetornoURL;
    var oXMLHTTP;
    var strTipoFunction="function";
    var strStatusHTTP="complete";
    var blnModoAssincrono = (( _Handle ) ? true : false );
    var Method=(_MethodPost!=true)? "GET" : "POST";

    try{ //Criando instância de objeto xmlhttp
        try
        {oXMLHTTP=new ActiveXObject("Msxml2.XMLHTTP");}catch(e1){
	        try
	        {oXMLHTTP=new ActiveXObject("Microsoft.XMLHTTP");}catch(e2){
		        try
		        {oXMLHTTP=new XMLHttpRequest();}catch(e3){
			        oXMLHTTP=null;
		        }
	        }
        }
        
        if ( typeof oXMLHTTP == "object" )
        {
	        //Executando a url informada
	        oXMLHTTP.open(Method, _strURL, blnModoAssincrono);
	        oXMLHTTP.setRequestHeader('Content-Type',"application/x-www-form-urlencoded;charset=iso-8859-1");

	        if(blnModoAssincrono){ //Verifica se o modo solicitado é o Assíncrono
		        oXMLHTTP.onreadystatechange=function (){
			        if(oXMLHTTP.readyState==4 || oXMLHTTP.readyState==strStatusHTTP){
				        if(oXMLHTTP.status==200){
					        strRetornoURL=oXMLHTTP.responseText;
					        //Verificando necessidade de codificação dos dados
					        if(typeof _Handle==strTipoFunction){
						        eval(_Handle(strRetornoURL));
					        }
				        }
			        }
		        }
		        oXMLHTTP.send(_Conteudo);
	        }
	        else
	        {
		        oXMLHTTP.send(_Conteudo);
		        if(oXMLHTTP.status==200)
		        {
			        strRetornoURL=oXMLHTTP.responseText;
		        }
	        }
        }
    }catch(e){}
    finally{
        return strRetornoURL;
    }
}

var lngCodAluno = -1;
function Autenticar(blnAcessarMatricula)
{
    var cpf = document.getElementById("txtCPF");
    var senha = document.getElementById("txtSenhaAluno");
    
    if ( cpf.value == "" )
    {
        alert("O campo " + document.getElementById("tdLogin").innerHTML.replace("*", "") + " é de preechimento obrigatório. Preencha o " + document.getElementById("tdLogin").innerHTML.replace("*", "") + ".");
        cpf.focus();
        return false;
    }
    
    if ( document.getElementById("tdLogin").innerHTML == "CPF*" && !CPFValido(cpf.value) )
    {
        alert("O " + document.getElementById("tdLogin").innerHTML.replace("*", "") + " não é valido. Preencha o campo " + document.getElementById("tdLogin").innerHTML.replace("*", "") + " com um valor válido.");
        cpf.focus();
        return false;
    }
    
    if ( senha.value == "" )
    {
        alert("O campo Senha é de preechimento obrigatório. Preencha a Senha.");
        senha.focus();
        return false;
    }
    
    var strURL = "/HotSite/login.asp?Usuario=" + escape(cpf.value) + "&Senha=" + escape(senha.value);
    var retorno = RPC(strURL, null, false);
    retorno = unescape(retorno);
    
    if ( retorno.split(";").length == 2 )
    {
        if( retorno.split(";")[0].toUpperCase() == "TRUE")
        {
            if ( blnAcessarMatricula )
            {
                AcessarMatricula();
            }
            else
            {
                Logar();
            }
        }
        else
        {
            //
            // ToDo: Replace de CPF para o Tipo do LOGIN
            //
            alert(retorno.split(";")[1]);
            document.getElementById("txtSenhaAluno").value = "";
            document.getElementById("txtCPF").focus();
        }
    }
    else
    {
        alert("Ocorreu um erro ao tentar logar.\nTente novamente.");
        document.getElementById("txtSenhaAluno").value = "";
        document.getElementById("txtCPF").focus();
    }
    return false;
} 

function Logar()
{
    document.getElementById("frmLogin").reset();
    document.getElementById("divLogin").style.display = "none";
    document.getElementById("divLogado").style.display = "";
    
    var retorno = RPC("/hotsite/rpcDadosAluno.asp", "", true, "");
    
    retorno = unescape(retorno);
    
    if ( retorno.split(";").length == 4 )
    {
        document.getElementById("Foto").src = retorno.split(";")[0];
        
        var ultimoAcesso = retorno.split(";")[1]
        
        if (ultimoAcesso != "")
        { 
            document.getElementById("spmUltimoAcesso").innerHTML = "Seu último acesso foi no dia " + ultimoAcesso;
        }
        else
        {
            document.getElementById("spmUltimoAcesso").innerHTML = "";
        }
        
        document.getElementById("spmNome").innerHTML = retorno.split(";")[2].split(" ")[0];
        lngCodAluno = retorno.split(";")[3];
    } 
}  

function Deslogar()
{
    document.getElementById("divLogin").style.display = "";
    document.getElementById("divLogado").style.display = "none";
    RPC("/logout.asp", null, false);
}

function ValidaLoginGestor()
{
    with (document.frmLoginGestor)
    {    	
        if ( txtLogin.value == "" )
        {
            alert("Preencha o Login.");
            txtLogin.focus();
            return false;
        }
        
        if ( txtSenha.value == "" )
        {
            alert("Preencha a Senha.");
            txtSenha.focus();
            return false;
        }
        
        //Codificando valores para que os campos login e senha aceitem caracteres especiais. 
        var strForm = "txtsenha=" + escape(txtSenha.value) + "&txtlogin=" + escape(txtLogin.value);
        
        
        var strRetorno = RPC("/Gestor/rpcVerificarLogin.asp", null, true, strForm);
        
        if ( strRetorno != "" )
        {
            alert("Usuário ou senha inválidos, tente novamente!");
            return false;
        }			
        return true;
    }   
}

function AcessarMatricula()
{
    window.location.href = "/HOTSITE/MATRICULA.ASP";
}

function Matricular()
{
    document.getElementById('divMatricula').style.display = 'none';
    if ( ! document.frmMatricula.rdoCurso )
    {
	document.getElementById('divMatricula').style.display = 'block';
        alert("Não há curso disponível para matrícula.")
        return;
    }
    else if ( ! document.frmMatricula.rdoCurso.length  &&  ! document.frmMatricula.rdoCurso.checked)
    {
        document.getElementById('divMatricula').style.display = 'block';
	alert("Você deve selecionar o curso que deseja se matricular.")
        return;
    }
    else if ( document.frmMatricula.rdoCurso.length )
    {
        for ( var i = 0; i < document.frmMatricula.rdoCurso.length; i++ )
        {
            if ( document.frmMatricula.rdoCurso[i].checked )
            {
                document.getElementById('divMatricula').style.display = 'block';
		document.frmMatricula.submit();
                return
            }
        }
        document.getElementById('divMatricula').style.display = 'block';
	alert("Você deve selecionar o curso que deseja se matricular.")
        return;
    }
    
    document.getElementById('divMatricula').style.display = 'none';
    document.frmMatricula.submit();
} 

function EmailValido ( _strConteudo )
{
    var blnRetorno = false;
    try{
        blnRetorno = /^([\w\.\-])+\@(([\w\-])+\.)+([\w ]{2,4})$/.test( _strConteudo );
    }catch(e){
        this.Message(e);
    }finally{
        return blnRetorno;
    }
}
function AbrirNoticia(lngCodNoticia)
{
    if ( ! lngCodNoticia )
    {
        lngCodNoticia = codNoticia;
    }
    divPopup("divPopupNoticia", "", "URL", '/noticias.asp?chamadaDivPopUp=divPopupNoticia&irpara=default.asp&CodNoticia=' + lngCodNoticia, 500, 350, 20, 20, true, true, true);
}

function CarregarNoticia(indice)
{
    var noticiaFoto     = document.getElementById("noticiaFoto");
    var noticiaTitulo   = document.getElementById("noticiaTitulo");
    var noticiaData     = document.getElementById("noticiaData");
    var noticiaSinopse  = document.getElementById("noticiaSinopse");
    var noticiaFonte    = document.getElementById("noticiaFonte");
       
    codNoticia                  = arrNotiticas[indice - 1][0];
    noticiaTitulo.innerHTML     = arrNotiticas[indice - 1][2];
    noticiaData.innerHTML       = arrNotiticas[indice - 1][1];
    noticiaSinopse.innerHTML    = arrNotiticas[indice - 1][3];    
    noticiaFonte.innerHTML      = arrNotiticas[indice - 1][5];
    noticiaFoto.src             = "/imagens/noticias/" + arrNotiticas[indice - 1][4];
}
function trim(string) {
	while (string.substring(0,1) == ' ') {
			string = string.substring(1,string.length);
	}
	while (string.substring(string.length-1,string.length) == ' ') {
			string = string.substring(0,string.length-1);
	}
	return string;
}

function fechaCaixa(id)
{
    fecharDivPopup(id);
}

function DataValida(Data){

	if (Data == "")
	{
		alert("Por favor, informe a Data.");
		return false;
	}
	else if ((Data.indexOf("/") < 2) || (Data.indexOf("/", 3) < 5))
	{
		window.alert ('Informe o campo data no padrão dd/mm/aaaa.')
		return false;
	} 
	else 
	{
		DataDia = Data.substring(0,2);
		DataMes = Data.substring(3,5);
		DataAno = Data.substring(6,10);
		if (isNaN(DataDia) == true || isNaN(DataMes) == true || isNaN(DataAno) == true)
		{
			alert('Data inválida.')
			return false;
		}
		data = new Date();
		ano = data.getYear()
		if(DataAno < 1900){
			alert ('Ano inválido!')
			return false;
		}
		if (DataMes > 12 || DataMes < 1)
		{
			window.alert ('Mês inválido.')
			return false;
		}
		if (DataDia > 31 || DataDia < 1)
		{
			window.alert ('Dia inválido.')
			return false;
		}
		if (DataMes==1)
		{
			ultdia = 31
		}
		if (DataMes==2)
		{
			if ((DataAno % 4) == 0)
			{
				ultdia = 29
			} 
			else 
			{
				ultdia = 28
			}
		}
		if ((DataMes==3)||(DataMes==5)|| (DataMes==7)||(DataMes==8)||(DataMes==10)||(DataMes==12))
		{
			ultdia = 31
		}
		if ((DataMes==4)||(DataMes==6) || (DataMes==9) || (DataMes==11))
		{
			ultdia = 30
		}
		if (DataDia>ultdia)
		{
			window.alert ('Data inválida')
			return false;
		}
				
		return true
	}
}
function FSNumeros(strPermissao){
	var	KeyCode = event.keyCode;
	var strPermitido = " KeyCode != 46 && KeyCode != 37 && KeyCode != 39 && KeyCode != 8 && KeyCode != 9  && KeyCode != 33 && KeyCode != 34 && KeyCode != 35 && KeyCode != 36 && KeyCode != 16 && KeyCode != 109 && KeyCode != 189";
	if (strPermissao != "")
	{
		if (strPermissao.indexOf(",") != -1){
			strPermissao = strPermissao.split(",");
			for(i=0; i < strPermissao.length; i++){
				strPermitido += " && KeyCode!= " + parseInt(strPermissao[i]);
			}
		}
		else
		{
			strPermitido += " && KeyCode!= " + parseInt(strPermissao);
		}
		strPermitido = eval(strPermitido);
		if ((KeyCode < 48 || KeyCode > 57) && (KeyCode < 96 || KeyCode > 105) && (strPermitido))
		{
			event.cancelBubble;
			event.returnValue= false;
			return false;
		}
	}
	else
	{
		if ((KeyCode < 48 || KeyCode > 57) && (KeyCode < 96 || KeyCode > 105) && (eval(strPermitido)))
		{
			event.cancelBubble;
			event.returnValue= false;
			return false;
		}
	}
}