/*
function showAll2(){
	flashMovie = document.getElementById("amline");
	flashMovie.hideGraph(1);
	//flashMovie.showAll(); 
}
*/
function showGraph2 (id){
	flashMovie = document.getElementById("amline");
	flashMovie.showGraph(id);
}

function hideGraph2(id){
	flashMovie = document.getElementById("amline");
	flashMovie.hideGraph(id);
}

function onoff(id, element){
	var el = document.getElementById(element);
	if (el.checked){
		showGraph2(id);
	}else{
               	hideGraph2(id);
	}
}

function setPeriod(interval){
	$('.bonds_graph_date').each(function(){
		//$(this).css('text-decoration', 'underline');
		$(this).removeClass('button-active');
	});
	//$('#bonds_graph_date_' + interval).css('text-decoration', 'none');
	$('#bonds_graph_date_' + interval).addClass('button-active');

	var send = $.ajax
	({	
		type: "post",
		url: '/ajax/',
		data: {action:'reload_bonds_graph', id:interval},
		dataType: "json",
		success: onSetPeriod
	});
}
			
function onSetPeriod(oReq){
	var json = oReq;
	//navigation gor graph...
	var id = json.id;
	var send = $.ajax
	({	
		type: "post",
		url: '/ajax/',
		data: {action:'reload_bonds_graph_nav', id:id},
		dataType: "json",
		success: onOnSetPeriod
	});
	
	var data = json.data;
	var settings = json.settings;
	flashMovie = document.getElementById("amline");
	flashMovie.setData(data, false);
	flashMovie.setSettings(settings, false);
	flashMovie.rebuild();
	flashMovie.showAll();
	
	var sections = $('#benchmark_count').val();
	for (var i=1; i<=sections;i++){
		$('#segments_' + i).attr('checked', 'checked');
	}
	$('#benchmark').attr('checked', 'checked');
}			

function onOnSetPeriod(oReq){
	var json = oReq;
	var str = json.str
	$('#bond_graph_nav').html(str);
	if(typeof $.fn.formstyle == 'function') {
		$('#bond_graph_nav input.i-checkbox').checkboxstyle();
	}
	
}

function checkBenchmark(_id){
	var pos = _id.indexOf("_")+1;
	var id = _id.substr(pos);

	var sections = $('#benchmark_count').val();
	var str = '#benchmark_' + id;
	var element = $(str).val();
	if (element>=0){
		var el = document.getElementById(_id);
		var benchmark_el = document.getElementById("benchmark");
		if (el.checked){
			if (benchmark_el.checked){
				showGraph2(element);
			}
		}else{
			var flag = false;
			for (var i=1; i<=sections;i++){
				var tmp_name = '#benchmark_' + i;
				var tmp_el = document.getElementById('segments_' + i);
				if (tmp_el.checked){
					if ($(tmp_name).val()==element){
						flag = true;
						break;
					}
				}
			}
			if (flag == false){
               			hideGraph2(element);
			}
		}
	}
}

function onoffBenchmark(){

	var benchmark_el = document.getElementById("benchmark");
	var sections = $('#benchmark_count').val();
	//alert(sections);
	if (benchmark_el.checked){
		for (var i=1; i<=sections;i++){
			var tmp_el = document.getElementById('segments_' + i);
			if (tmp_el.checked){
				var tmp_name = '#benchmark_' + i;
				showGraph2($(tmp_name).val());
				//alert($(tmp_name).val());
			}
		}
	}else{
		for (var i=1; i<=sections;i++){
			var tmp_el = document.getElementById('segments_' + i);
			if (tmp_el.checked){
				var tmp_name = '#benchmark_' + i;
				hideGraph2($(tmp_name).val());
				//alert($(tmp_name).val());
				//???
			}
		}
	}
}