﻿<!--

var arVersion = navigator.appVersion.split("MSIE") ;

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function EscolheCotaAnterior(data) {
	window.location = "internas.aspx?secao=relatorios&data=" + data ;
}

function TrocaClass() {
	var a=TrocaClass.arguments;

	for(i=0;i<=(a.length-2);i+=2) {
		objElem = document.getElementById(a[i]);
		objElem.className = a[i+1];
	}
}

var heightMenu = 0 ;
var heightMenuMax = 165 ;
var incremento = 10 ;
var menuTimer ;
var isOpen = false ;
var isClosing = false ;

function menuControl(menu,op) {
	ReposicionaMenuSites();
	window.clearTimeout(menuTimer) ;
	
	if (op == "abrir") {
		if (!isOpen) {
			showMenu(menu) ;
		}
	}
	else if (op == "fechar") {
		if (isOpen) {
			menuTimer = setTimeout("hideMenu('" + menu + "');",400) ;
		}
		else {
			hideMenu(menu) ;
		}
	}
}

function showMenu(menu) {
	objMenu = document.getElementById(menu) ;
	objMenu.style.visibility = "visible" ;
	
	if (heightMenu < heightMenuMax) {
		
		if ( (heightMenu + incremento) > heightMenuMax ) {
			heightMenu = heightMenuMax;
		}
		else {
			heightMenu = heightMenu + incremento ;
		}
		
		objMenu.style.height = heightMenu + "px" ;
		menuTimer = window.setTimeout("showMenu('" + menu + "');",1) ;
	}
	else {
		window.clearTimeout(menuTimer) ;
		isOpen = true ;
	}
	
}

function hideMenu(menu) {
	isOpen = false ;
	objMenu = document.getElementById(menu) ;

	if (heightMenu > 1) {
		
		if ( (heightMenu - incremento) < 1 ) {
			heightMenu = 1;
			objMenu.style.visibility = "hidden" ;
		}
		else {
			heightMenu = (heightMenu - incremento) ;
		}
		
		objMenu.style.height = heightMenu + "px" ;
		menuTimer = window.setTimeout("hideMenu('" + menu + "');",1);
	}
	else {
		objMenu.style.visibility = "hidden" ;
		window.clearTimeout(menuTimer) ;
	}
}

function ReposicionaMenuSites() {
	objDiv = MM_findObj('divLinkSitesBanif') ;
	leftPos = findPosX(objDiv) ;
	topPos = findPosY(objDiv);
	objMenu = document.getElementById('sitesBanifContainer') ;
	objMenu.style.top = parseInt((topPos - heightMenuMax - 18)) + "px" ;
	objMenu.style.left = parseInt(leftPos) + "px" ;

	//objMenu.style.bottom = document.body.scrollHeight - 300;
	//alert(objMenu.style.bottom) ;
}

function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent) {
			    break;
			}
			obj = obj.offsetParent;
		}
	else if(obj.x) {
		curleft += obj.x;
	}
		
	return curleft-34;
}

function findPosY(obj)  // Get full top offset
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop ;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

function VerificaSimulador() {
	
	objForm = document.getElementById("GraficoForm")
	
	pass = true;
	var d = new Date();

	// Não selecionou nenhum fundo
	if (Checked < 1) {
		msg = "Ao menos 1 fundo deve ser selecionado.";
		pass = false;
	}
	
	if ( (pass) && (Checked < 2) ) {
		
		pass = false;
		
		for (i=0; i<objForm.Indicador.length; i++) {
			if (objForm.Indicador[i].checked) {
				pass = true;
			}
		}

		msg = "Selecione um segundo fundo ou um indicador.";
	}
	
	if ( (pass) && (objForm.dataInicio.value.length == 0) ) {
		msg = "Informe a data inicial desejada.";
		pass = false;
	}
	else if ( (pass) && (objForm.dataInicio.value.length < 10) ) {
		msg = "Data inicial inválida. A data inicial deve estar no formato 'dd/mm/aaaa'.";
		pass = false;
	}
	else if (pass) {
		dataInicio = objForm.dataInicio.value ;
		diaInicio = dataInicio.substr(0,2);
		mesInicio = dataInicio.substr(3,2);
		anoInicio = dataInicio.substr(6,4);
		
		if ( (parseInt(mesInicio) > 12) || (parseInt(anoInicio) < 2004) || (parseInt(anoInicio) > d.getFullYear()) || ( (parseInt(anoInicio) == d.getFullYear()) && (parseInt(mesInicio) > d.getMonth()) && ( parseInt(diaInicio) >= parseInt(d.getDay()) ) )) {
			msg = "Data inicial inválida. A data inicial deve ser maior ou igual a 01 janeiro de 2004 e menor que a data final.";
			pass = false;
		}
	}


	if ( (pass) && (objForm.dataFinal.value.length == 0) ) {
		msg = "Informe a data final desejada.";
		pass = false;
	}
	else if ( (pass) && (objForm.dataFinal.value.length < 10) ) {
		msg = "Data final inválida. A data final deve estar no formato 'dd/mm/aaaa'.";
		pass = false;
	}
	else if (pass) {
		dataFinal = objForm.dataFinal.value ;
		diaFinal = dataFinal.substr(0,2);
		mesFinal = dataFinal.substr(3,2);
		anoFinal = dataFinal.substr(6,4);
		
		dataInicio = objForm.dataInicio.value ;
		diaInicio = dataInicio.substr(0,2);
		mesInicio = dataInicio.substr(3,2);
		anoInicio = dataInicio.substr(6,4);
		
		if ( (parseInt(mesFinal) > 12) || (parseInt(anoFinal) < 2004) || (parseInt(anoFinal) > d.getFullYear()) || ( (parseInt(anoFinal)) == (parseInt(d.getFullYear())) && (parseInt(mesFinal)) == (parseInt(d.getMonth())) && (parseInt(diaFinal)) == (parseInt(d.getDay())) ) ) {
			msg = "Data final inválida. A data final deve ser maior ou igual a 01 de janeiro de 2004 e menor que a data atual.";
			pass = false;
		}
		else {

			if ( ( parseInt(anoFinal) < parseInt(anoInicio) ) || ( ( parseInt(anoFinal) == parseInt(anoInicio) ) && ( parseInt(mesFinal) <= parseInt(mesInicio) ) && ( parseInt(diaFinal) <= parseInt(diaInicio) ) ) ) {
				msg = "Data final inválida. A data final deve ser maior que a data inicial.";
				pass = false;
			}
			
		}
	}
	
	
	if (pass) {
		objForm.submit();
	}
	else {
		alert(msg) ;
		return false;
	}
}

function isDate(data) {
	data_atual = new Date();
	ano_minimo = 1900;
	ano_maximo = data_atual.getFullYear();
	dataArray = data.split("/");

	if(dataArray.length != 3) {
		return false;
	}
	else {
		dia = dataArray[0];
		mes = dataArray[1];
		ano = dataArray[2];

		//Verifica se todos os caracteres são números
		if (!(isInteger(dia)) || !(isInteger(mes)) || !(isInteger(ano))) {
			return false;
		}
		else {
			//Verifica o ano
			if ((ano.length < 4) || ((+ano < ano_minimo) || (+ano > ano_maximo))) {
				return false;
			}
			
			//Verifica se o dia e o mes são válidos
			if ((+dia > 31) || (+mes > 12)) {
				return false;
			}
			else {
				
				//Verifica se a data inserida é no futuro (não permite)
				if ( (+ano == ano_maximo) && (+mes > ((data_atual.getMonth())+1)) ) {
					return false;
				}
				else {
					if ( (+mes == ((data_atual.getMonth())+1)) && (+dia > data_atual.getDate()) ) {
						return false;
					}
				}
				
				//Verifica ano bisexto e meses com 30 dias
				if (+mes == 2) {
					if ((((+ano % 4) == 0) && (+dia > 29)) || (((+ano % 4) != 0) && (+dia > 28))) {
						return false;
					}
				}
				else {
					if (((+mes == "4")||(+mes == "6")||(+mes == "9")||(+mes == "11")) && (+dia > 30)) {
						return false;
					}
				}
			}
		}
	}
	return true;
}

function SoNumeros() {
	
	e = window.event;
	
	if ( typeof( e.keyCode ) == 'number'  ) {
		if (e.keyCode < 48 || e.keyCode > 57)
			e.returnValue = false;
	}
	else if ( typeof( e.which ) == 'number' ) {
		if (e.keyCode < 48 || e.keyCode > 57)
			return false;
	}
	else if( typeof( e.charCode ) == 'number'  ) {
		if (e.keyCode < 48 || e.keyCode > 57)
			return false;
	}
}

var Checked = 0 ;
var objAtual;
var quantFundos ;

function ChecaFundos(item) {

	//alert(document.getElementById('quantFundos'););
	quantFundos = document.GraficoForm.quantFundos.value;

	Checked = 0;

	//verifica quantos checkboxes estão marcados
	for(i=1; i<=quantFundos; i++) 
	{
		objAtual = document.getElementById('Fundo' + i);
		if(objAtual.checked) {
			Checked = Checked + 1;
		}
	}

	//alert(Checked);

	if (Checked == 2)
	{
		for(i=1; i<=quantFundos; i++) 
		{
			objAtual = document.getElementById('Fundo' + i);
			if(!objAtual.checked) {
				objAtual.disabled = true;
			}
		}
	}
	else
	{
		for(i=1; i<=quantFundos; i++) 
		{
			objAtual = document.getElementById('Fundo' + i);
			objAtual.disabled = false;
		}
	}
	
	obterLimitesDataSimulador()
}


function getBrowser()   
{   
    if(window.XMLHttpRequest)   
    {   
        return "mozilla";   
    }   
    else if(window.ActiveXObject)   
    {   
        return "ie";   
    }   
}   

function doXMLRequester()   
{   
    if(getBrowser() == "ie")   
    {   
        return new ActiveXObject("Microsoft.XMLHTTP");   
    }   
    else if(getBrowser() == "mozilla")   
    {   
        return new XMLHttpRequest();   
    }   
}   
  
//Obtém os limites das dadas de consulta para a montagem do gráfico do simulador
function obterLimitesDataSimulador()
{
	var dataMinima;
	var dataMaxima;
	var arrayDataMaxRetorno;
	var arrayDataMinRetorno;
	var dataMaxRetorno;
	var dataMinRetorno;
	var idFundoAtual = ""; //id do fundo selecionado
	var arrayDatas;
	var cont = 0;
	var strFundos = ""

	//iniciar ajax-loader
	document.getElementById("tdValidacaoData").innerHTML = "<img src='imagens/ajax-loader.gif' alt='aguarde' />";

	//Varrer os fundos selecionados
	for (i=0;i<document.GraficoForm.elements.length;i++)
	{
		if (document.GraficoForm.elements[i].type == "checkbox")
		{
			//verificar se o fundo está marcado
			if (document.GraficoForm.elements[i].checked == true)
			{
				strFundos = strFundos + document.GraficoForm.elements[i].value + "|";
			}
		}			
	}

	//alert("strFundos="+strFundos);
	
	strFundos = strFundos.substr(0,strFundos.length-1);
	
	if (strFundos != "") 
	{
		var oHTTPRequest = doXMLRequester();  
		oHTTPRequest.open("get", "obterLimitesDataSimulador.asp?strFundos="+strFundos, true);
		oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oHTTPRequest.onreadystatechange = function () 
		{
			if (oHTTPRequest.readyState==4) {
				//alert(oHTTPRequest.responseText);
				//document.getElementById("tdValidacaoData").innerHTML = oHTTPRequest.responseText;
				
				arrayDatas = oHTTPRequest.responseText.split("|");
				
				dataMinRetorno = arrayDatas[0];
				dataMaxRetorno = arrayDatas[1];
				
				//Setar os valores para validação
				document.GraficoForm.dataMinima.value = dataMinRetorno;
				document.GraficoForm.dataMaxima.value = dataMaxRetorno;
				
				//colocar a data no formato 'dd/mm/aaaa'
				dataMinima = dataMinRetorno.substr(6,2) + "/" + dataMinRetorno.substr(4,2) + "/" + dataMinRetorno.substr(0,4)
				dataMaxima = dataMaxRetorno.substr(6,2) + "/" + dataMaxRetorno.substr(4,2) + "/" + dataMaxRetorno.substr(0,4)	
				
				//Atualizar os limites do período para consulta
				document.getElementById("tdValidacaoData").innerHTML = "Período disponível para consulta:<br /> de <strong>"+dataMinima+"</strong> a <strong>"+dataMaxima+"</strong>";
			}
		}
		oHTTPRequest.send(null);
	}
	else
	{
		document.getElementById("tdValidacaoData").innerHTML = "<br />";
	}

}


//-->
