var eOpenMenu = null;

//******************************************************************************************

function OpenMenu(eSrc, eMenu)
{

	if (document.all)
	{
        var varLateralEsquerda = document.all("frmTela").offsetLeft;
    }
    
	if (document.layers)
	{
        var varLateralEsquerda = document.layers("frmTela").offsetLeft;
    }

    // var eMenuLeft = eSrc.parentElement.offsetLeft + divMenuBar.offsetLeft + 82;

	if ( document.location.href.indexOf('default') != -1)
	{
	    var eMenuLeft = eSrc.parentElement.parentElement.offsetLeft + divMenuBar.offsetLeft + varLateralEsquerda + 3;
	}
	else
	{
	    var eMenuLeft = eSrc.parentElement.parentElement.offsetLeft + divMenuBar.offsetLeft + varLateralEsquerda + 3;
	}
    
	if (eMenuLeft >= 800) {
		eMenuLeft = eMenuLeft - ( eSrc.parentElement.parentElement.offsetWidth - 22 );
	}

	if (document.all)
	{
		eMenu.style.left = eMenuLeft;
		// eMenu.style.top = divMenuBar.offsetHeight + divMenuBar.offsetTop + 50;
		eMenu.style.top = divMenuBar.offsetHeight + divMenuBar.offsetTop - 3;
		eMenu.style.visibility = "visible";
	}
	else if (document.layers)
	{
		eMenu.left = eMenuLeft;
		// eMenu.top = divMenuBar.offsetHeight + divMenuBar.offsetTop + 50;
		eMenu.top = divMenuBar.offsetHeight + divMenuBar.offsetTop - 3;
		eMenu.visibility = "visible";
	}

	eOpenMenu = eMenu;
}

//******************************************************************************************

function CloseMenu(eMenu)
{
	if (document.all)
	{
		eMenu.style.visibility = "hidden";
	}
	else if (document.layers)
	{
		eMenu.visibility = "hidden";
	}
	eOpenMenu = null;
}

//******************************************************************************************

function MenuBar_over()
{
	var eSrc = window.event.srcElement;

	if ("IMG" == eSrc.tagName.toUpperCase())
	{
	
		if (document.all)
		{
			var eMenu = document.all[eSrc.parentElement.parentElement.id.replace("tdMenuBarItem","divMenu")];
		}
		else if (document.layers)
		{
			var eMenu = document.layers[eSrc.parentElement.parentElement.id.replace("tdMenuBarItem","divMenu")];
		}

		if (eOpenMenu && eOpenMenu != eMenu) 
		{
			CloseMenu(eOpenMenu);
		}
		if (eMenu) 
		{
			OpenMenu(eSrc,eMenu);
		}
	}
}

//******************************************************************************************

function MenuBar_out()
{
	var eTo = window.event.toElement;

	if (eOpenMenu && eTo && !eOpenMenu.contains(eTo) && "tblMenuBar" != eTo.id) 		
	{
		CloseMenu(eOpenMenu)
	}
}

//******************************************************************************************

function Menu_out()
{
	var eSrc = window.event.toElement;
    
	if (eOpenMenu && !eOpenMenu.contains(eSrc) && !divMenuBar.contains(eSrc)) 
	{
		CloseMenu(eOpenMenu)
	}
}

//******************************************************************************************

function imgExplorer_onClick(strCDDetalhe, strCorBotao)
{

    var intDetalhe = false;

	//Constroi o nome do objeto TR ou da coleção de objetos TR do detalhe selecionado
	strNomeObjetoDetalheSelecionado = 'trDetalhe'+strCDDetalhe;

	//Constroi o nome do objeto IMG
	strNomeImagemDetalheSelecionado = 'imgExplorer'+strCDDetalhe;

	//Cria uma referencia a coleção de detalhes para o detalhe selecionado com base no nome do objeto criado anteriormente
	objDetalheSelecionado = document.getElementsByTagName("tr")

	//Controi um loop em cada um dos objetos TR 
	for (intIndex = 0; intIndex < objDetalheSelecionado.length; intIndex++)
	{

		if (objDetalheSelecionado[intIndex].id == strNomeObjetoDetalheSelecionado )
		{

			//Verifica se os detalhes estão abertos
			if ( objDetalheSelecionado[intIndex].style.cssText.indexOf('block') > 0 )
			{
				objDetalheSelecionado[intIndex].style.display = 'none';
				intDetalhe = false;
			}
			else
			{
				objDetalheSelecionado[intIndex].style.display = 'block';
				intDetalhe = true;
			};

		}

	}

	if ( document.all(strNomeImagemDetalheSelecionado).src.indexOf('images/btn_mais_') != -1 )
	{
		//Altera a imagem do botão Explorer (Mais e Menos Detalhe)
		document.all(strNomeImagemDetalheSelecionado).src = 'images/btn_menos_' + strCorBotao + '.gif';
	}
	else
	{
		//Altera a imagem do botão Explorer (Mais e Menos Detalhe)
		document.all(strNomeImagemDetalheSelecionado).src = 'images/btn_mais_' + strCorBotao + '.gif';
	};

	return true;
	

}

//******************************************************************************************

function Entrar()
{

	var varEmail = document.frmLogin.txtEmail.value;
	var varCPF = document.frmLogin.txtCPF.value;
	var varTipoRelacionamento = document.frmLogin.cmbTipoLogin.value;
	
	if ( varEmail == '' )
	{
		alert('Por favor, informe seu e-mail.');
		document.frmLogin.txtEmail.focus();
		return false;
	}

	if ( varCPF == '' )
	{
		alert('Por favor, informe seu CPF.');
		document.frmLogin.txtCPF.focus();
		return false;
	}
	

	if ( varTipoRelacionamento == '1' )
	{
		document.frmLogin.method = "post";
		document.frmLogin.action = "https://www.ciaeduc.com.br/frmEspacoInterativo_01.asp";
		document.frmLogin.target = "_top";
		document.frmLogin.submit();
	}
	else if ( varTipoRelacionamento == '2' )
	{
		document.frmLogin.method = "post";
		document.frmLogin.action = "https://www.ciaeduc.com.br/exchange/";
		document.frmLogin.target = "_top";
		document.frmLogin.submit();
	}
	else if ( varTipoRelacionamento == '3' )
	{
		alert('Esta transação ainda não está liberada. Em breve você poderá contar com mais este canal de acesso à Companhia de Educação.');
	}
	else if ( varTipoRelacionamento == '4' )
	{
		alert('Esta transação ainda não está liberada. Em breve você poderá contar com mais este canal de acesso à Companhia de Educação.');
	}
	else if ( varTipoRelacionamento == '' )
	{
		alert('Por favor, selecione o tipo de relacionamento com a Companhia de Educação.');
		document.frmLogin.cmbTipoLogin.focus();
	}


}

//******************************************************************************************

function EntrarEspaco()
{

	var varEmail = document.frmLogin.txtEmail.value;
	var varPWD = document.frmLogin.txtPWD.value;
	var varCPF = document.frmLogin.txtCPF.value;
	var varAccKey = document.frmLogin.txtAccKey.value;

	if ( varEmail == '' )
	{
		alert('Por favor, informe seu e-mail.');
		document.frmLogin.txtEmail.focus();
		return false;
	}

	if ( varPWD == '' )
	{
		alert('Por favor, informe sua senha.');
		document.frmLogin.txtPWD.focus();
		return false;
	}
	
	if ( varCPF == '' )
	{
		alert('Por favor, informe seu CPF.');
		document.frmLogin.txtCPF.focus();
		return false;
	}

	if ( !Valida_CPF( frmLogin.txtCPF ) )
	{
		frmLogin.txtCPF.focus();
		return false;
	}

	frmLogin.txtCPF.value = PreencheComZerosAEsquerda(frmLogin.txtCPF.value, 11);

	if ( varAccKey == '' )
	{
		alert('Por favor, informe sua chave de acesso.');
		document.frmLogin.txtAccKey.focus();
		return false;
	}

	document.frmLogin.method = "post";
	document.frmLogin.action = "xml/xmlHTTP_EfetuaLogin.asp";
	document.frmLogin.target = "_top";
	document.frmLogin.submit();

}

//*****************************************************************************************
// Evento onKeyPress do campo CPF para aceitar apenas número
//*****************************************************************************************

function txtCPF_onkeypress() 
{

	var Tecla = window.event.keyCode;

	if ( Tecla > 47 && Tecla < 58 )
	{
		event.returnValue = true;
	}
	else
	{
		event.returnValue = false;
	}
}

//*****************************************************************************************
// Preenche Valor Com Zeros A Esquerda
//*****************************************************************************************

function PreencheComZerosAEsquerda(intValor, intTamanho) 
{

	if (intValor.length < intTamanho) {

	   for (intContador = 1; intTamanho - intValor.length; intContador++) {
	       intValor = "0" + intValor;
	   }

	}
	else if(intValor.length > intTamanho) {

	   if (intValor.substring(1, 2) == "0")
	      intValor = intValor.substring(1, intValor.length);
	   else {
	      intValor = intValor.substring(1, intValor.length-1);
	   }

	}

	return(intValor);
}

//*****************************************************************************************
// Validador de CPF
//*****************************************************************************************

function Valida_CPF( textBox, textBoxValue) 
{

	textBoxValue = textBox.value;

	var strDigito = textBoxValue.substring( textBoxValue.length, textBoxValue.length-2 );
	var strNumero = textBoxValue.substring( 0, textBoxValue.length-2 );

	if ( textBoxValue == "00000000000" || textBoxValue == "11111111111" ||
		 textBoxValue == "22222222222" || textBoxValue == "33333333333" ||
		 textBoxValue == "44444444444" || textBoxValue == "55555555555" ||
		 textBoxValue == "66666666666" || textBoxValue == "77777777777" ||
		 textBoxValue == "88888888888" || textBoxValue == "99999999999" ) {

		alert("O CPF informado é inválido, favor checá-lo.");
		textBox.focus();
		return false;

	}

	strCPF = CalculaDigitoModulo11( strNumero, 2, 1 );

	if ( strDigito == strCPF ) {
		return true;
	}
	else
	{
		alert("O CPF informado é inválido, favor checá-lo.");
		textBox.focus();
		return false;
	}

}

//*****************************************************************************************
// Calculo do DV do CPF
//*****************************************************************************************

function CalculaDigitoModulo11( strNumero, intDigitoSaida, strTipoValidacao ) 
{

	if (strTipoValidacao == 1) intLimiteMultiplicador = 12
	if (strTipoValidacao == 2) intLimiteMultiplicador = 9

	for ( indiceA = 1; indiceA <= intDigitoSaida; indiceA++) {

		intSoma = 0
		intMultiplicador = 2

		for ( intIndiceB = strNumero.length; intIndiceB > 0 ; intIndiceB-- ) {

			intSoma = intSoma + (intMultiplicador * parseInt( strNumero.substring( intIndiceB, intIndiceB-1 ) ,10 ) )

			intMultiplicador++

			if ( intMultiplicador > intLimiteMultiplicador ) intMultiplicador = 2
		}

		intSoma = (intSoma * 10) % 11
		if (intSoma == 10) strNumero = strNumero + "0"
		else strNumero = strNumero + intSoma
	}

  	return strNumero.substring( strNumero.length - intDigitoSaida, strNumero.length )

}

//******************************************************************************************
// User click do espaço interativo
//*****************************************************************************************

function getUserClick( varSource, varTarget )
{

    if ( varSource == 2 )
    {
    
        if ( varTarget == 3 )
        {
            window.navigate('frmEspacoInterativo_03.asp');
            return true;
        }
        
        if ( varTarget == 4 )
        {
            
            window.navigate('frmEspacoInterativo_04.aspx');
            return true;
        }

        alert('Em breve você contará com mais este serviço da Companhia de Educação.');
        return false;
        
    }        

}

//*****************************************************************************************


function ImprimeExtrato()
{

	document.frmExtratoCliente.action='frmImprimeExtrato.asp'; 
	document.frmExtratoCliente.target='_blank';
	document.frmExtratoCliente.submit();

	document.frmExtratoCliente.action='frmContrato_01.asp'; 
	document.frmExtratoCliente.target='_top';

}

//*****************************************************************************************

function ImprimeCobertura()
{

	document.frmCoberturaCliente.action='frmImprimeCobertura.asp'; 
	document.frmCoberturaCliente.target='_blank';
	document.frmCoberturaCliente.submit();

	document.frmCoberturaCliente.action='frmContrato_02.asp'; 
	document.frmCoberturaCliente.target='_top';

}

//*****************************************************************************************
