// JavaScript Document
acompanhe = {
	idEmpreendimento : 0,
	dtStatus : null,
	statusAtual : 0,
	divStatusAtual : '',
	statusTamanhoFinal : 0,
	flgSentidoAtual : 0,
	
	inicia : function(){
		acompanhe.idEmpreendimento = document.getElementById('hidIdEmpreendimento').value;
		acompanhe.carregaDrop();
	},
	
	carregaDrop : function(){
		empreendimento.retornaDatasAcompanhe(acompanhe.idEmpreendimento,acompanhe.carregaDropRetorno);
	},
	
	carregaDropRetorno : function(retorno){
		var dt = retorno.value;
		if(dt!=null && typeof(dt) == "object"){
			var drop = document.getElementById('dropStatusMes');
			drop.length = 0;
			for(i=0;i<dt.Rows.length;i++){
				var row = dt.Rows[i];
				var data = new Date();
				data = row.dataStatus;
				var mesInteiro = data.getMonth()+1;
				var mes = FG.retornaStringMes(mesInteiro);
	
				if(data.getYear()<1000)
					var ano = data.getYear()+1900;
				else
					var ano = data.getYear();
				
				if(i==0)
					acompanhe.carregaStatus(ano +'-'+ mesInteiro +'-1');
				var novo = document.createElement("option");
			    novo.setAttribute("id", "opcoes");
			    novo.value = ano +'-'+ mesInteiro +'-1';
			    novo.text  = mes + ' de ' + ano;
				drop.options.add(novo);

			}
		}
	},
	
	carregaStatus : function(data){
		//document.getElementById('divStatus').innerHTML = 'Carregando...';
		//alert(data);
		//alert(acompanhe.idEmpreendimento);
		empreendimento.retornaStatusAcompanhe(data,acompanhe.idEmpreendimento,acompanhe.carregaStatusRetorno);
	},
	
	carregaStatusRetorno : function(retorno){
		acompanhe.dtStatus = retorno.value;
		if(acompanhe.dtStatus!=null && typeof(acompanhe.dtStatus) == "object"){
			acompanhe.statusAtual=0;
			acompanhe.controlaCarregaBarraStatus();
			//alert(acompanhe.dtStatus.Rows.length);
			//document.getElementById('divStatus').innerHTML = '';
			//acompanhe.carregaDadosStatus();
		}
	},
	
	/*carregaDadosStatus : function(){
		if(acompanhe.statusAtual<acompanhe.dtStatus.Rows.length){
			var row = acompanhe.dtStatus.Rows[acompanhe.statusAtual];
			var conteudoHTM = document.getElementById('divTemplateStatus').innerHTML;
			conteudoHTM = conteudoHTM.replace('_VALOR_',row.valor);
			conteudoHTM = conteudoHTM.replace('_ID_',row.idStatus);
			conteudoHTM = conteudoHTM.replace('_STATUS_',row.status + '%');
			
			document.getElementById('divStatus').innerHTML += conteudoHTM;
			acompanhe.statusAtual++;
			setTimeout(acompanhe.carregaDadosStatus,10);
		}else{
			acompanhe.statusAtual=0;
			acompanhe.controlaCarregaBarraStatus();
		}flgSentidoAtual
	},*/
	
	controlaCarregaBarraStatus : function(){
		if(acompanhe.statusAtual<acompanhe.dtStatus.Rows.length){
			
			var row = acompanhe.dtStatus.Rows[acompanhe.statusAtual];
			acompanhe.divStatusAtual = 'divStatus' + acompanhe.statusAtual;
			var div = document.getElementById(acompanhe.divStatusAtual);
			if(div.style.width=='')
				var width=0;
			else
				var width = FG.retiraPXString(div.style.width);
			//alert(acompanhe.statusAtual + '-' + row.status + '-' + row.valor);
			document.getElementById('divStatusNum' + acompanhe.statusAtual).innerHTML= row.status + '%';
			acompanhe.statusTamanhoFinal = row.status*2;
			if(acompanhe.statusTamanhoFinal<width){
				acompanhe.flgSentidoAtual=-1;
				acompanhe.carregaBarraStatus();
			}else if(acompanhe.statusTamanhoFinal>width){
				acompanhe.flgSentidoAtual=1;
				acompanhe.carregaBarraStatus();
			}else if(acompanhe.statusTamanhoFinal==width){
				acompanhe.statusAtual++;
				setTimeout(acompanhe.controlaCarregaBarraStatus,100);
			}
			
			
		}
	},
	
	carregaBarraStatus : function(){
		var div = document.getElementById(acompanhe.divStatusAtual);
		if(div.style.width=='')
			var width=0;
		else
			var width = FG.retiraPXString(div.style.width);
		
		if(width<acompanhe.statusTamanhoFinal && acompanhe.flgSentidoAtual==1){
			width+=5;
			div.style.width=width + 'px';
			setTimeout(acompanhe.carregaBarraStatus,25);
		}else if(width>acompanhe.statusTamanhoFinal && acompanhe.flgSentidoAtual==-1){
			width-=5;
			div.style.width=width + 'px';
			setTimeout(acompanhe.carregaBarraStatus,25);
		}else{
			acompanhe.statusAtual++;
			setTimeout(acompanhe.controlaCarregaBarraStatus,100);
		}
		
	}
	
}
	