//general settings..
var det_on    = false;
pic1= new Image(100,100); 
pic1.src="/images/ajax_loading.gif"; 
pic2= new Image(100,100); 
pic2.src="/images/spacer.gif";
	//set default params
	var base_url  = 'gen_candlestick.php';
	var graph     = null;
	var gWidth    = '540';
	var gHeight   = '240';
	var detach      = 'true';
	
function option_window(option)
{
	childWin=open(""+option+"&print_title_table=No","","width=650,height=450,resizable=yes,alwaysRaised=no,screenX=0,screenY=0,dependent=no,scrollbars=0");		
}

function showHidePanel(div){
	document.getElementById(div).style.display = (document.getElementById(div).style.display=='none') ? '' : 'none' ;
}

function inits() {
	document.getElementById('pair_ID').value         = pair_id;
	document.getElementById('timescale').value      = timescale;
	document.getElementById('candles').value = candles;
	document.getElementById('style').value = style;
	graph = document.getElementById('great_chart_image');
}

function go_again(counted_width, counted_height) {
	graph.src='/images/spacer.gif';
	//alert(counted_width);
	refrImg(counted_width, counted_height);
}

function refrImg(counted_width, counted_height) {
		//get_size();
		counted_width = counted_width || gWidth;
		counted_height = counted_height || gHeight;
		get_timescale();
		get_pair();		
		get_style();
		get_points();
		var newUrl = base_url + '?candles=' + candles + '&timescale=' + timescale + '&pair_ID=' + pair_id+ '&style='+style+'&chart_width='+counted_width+'&chart_height='+counted_height;
		graph.src = newUrl;
}



function get_pair() {
	opair_id = document.getElementById('pair_selected_id');
	pair_id = opair_id.value;
}

function get_points() {
	ocandles = document.getElementById('candles');
	candles  = ocandles.value;
}

function get_style() {
	ostyle = document.getElementById('style');
	style = ostyle.value;
}

function get_timescale() {
	otimescale = document.getElementById('timescale');
	timescale = otimescale.value;
}

function init()  {
	graph     = document.getElementById('great_chart_image');
	refrImg()
}


function get_size(mozilla_width,mozilla_height,ie_width,ie_height) {
	mozilla_width = mozilla_width || 0;
	mozilla_height = mozilla_height || 0;
	ie_width = ie_width || 0;
	ie_height = ie_height || 0;
		if (parseInt(navigator.appVersion)>3) {
		 if (navigator.appName=="Netscape" || window.opera ) {
		  gWidth = parseInt(window.innerWidth)-mozilla_width;
		  gHeight = parseInt(window.innerHeight)-mozilla_height;
		 }
		 if (navigator.appName.indexOf("Microsoft")!=-1) {
		  gWidth = parseInt(document.body.offsetWidth)-ie_width;
		  gHeight = parseInt(document.body.offsetHeight)-ie_height;
		 }
		}
	//alert('H'+gHeight+' W'+gWidth);
	if(isNaN(gWidth))gWidth=100;
	if(isNaN(gHeight))gHeight=100;
	if(gHeight<50)gHeight=225;
	if(gWidth<50)gWidth=298;
	
}

function change_to_static() {
	graph.src='/images/no_data.gif';
	graph.width = gWidth;
	graph.height = gHeight;
	graph.style.width = gWidth;
	graph.style.height = gHeight;
	//alert('Image width equals to \'' + graph.style.width + '\' and height equals to \'' + graph.style.height + '\', but gHeight=' + gHeight);
}
