// capsule the properties
var $vtChartProps = {
	idImg:  'vtChartImg',
	width:  width,
	height: height,
	pair:   typeof(pair)=='undefined'?'':pair,
	period: typeof(period)=='undefined'?'':period,
	profile: typeof(profile)=='undefined'?'':profile
}

// this gets the basic url
function getUrlPref(id) {
	var url = document.getElementById(id).src;
	return url.substr(0, url.indexOf('/js/'));
}

// this loads the image into the prepared place
function addImage() {
	var urlpref = getUrlPref("vtChartImage");
	var url = urlpref+"/chartImage.php?pair="+$vtChartProps.pair+"&period="+$vtChartProps.period+"&width="+$vtChartProps.width+"&height="+$vtChartProps.height+"&profile="+$vtChartProps.profile;
	document.getElementById($vtChartProps.idImg).src = url;
}

// this adds the onLoad event
function onLoad($addImage) {
	var $root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
	if      ($root.addEventListener) { $root.addEventListener("load"  , $addImage, false); }
	else if ($root.attachEvent     ) { $root.attachEvent     ("onload", $addImage       ); }
}

// prepare a place for the image
document.write("<img id='"+$vtChartProps.idImg+"' alt='WebChart' src='' width='"+$vtChartProps.width+"' height='"+$vtChartProps.height+"'>");

// add onLoad event
onLoad(addImage);
