var dystart ;
var qTime = 0;
var vTime = 0;
var pView = 0;
var tTime;

function timeSet() {
	dystart = new Date();
	return true;
}

function getValue( obj ) {
	var val = 0;
	if( obj != null ) {
		if( obj.length != null ) {
			for( i=0; i<obj.length; i++ ) {
				val = val + parseInt(obj[i].getAttribute("value"));
			}
		}
		else {
			val = obj.getAttribute("value");
		}
	}
	return val;
}

var viewRatio   = 50;
var maxViewTime = 5000;

function timecheck( inQueryTime,inViewTime ) {
	var queryTbl = document.getElementById("queryTbl");
	if( queryTbl == null || dystart == 0 || dystart == null ) { return; }

	var viewTbl  = document.getElementById("viewTbl");
	var pageTbl  = document.getElementById("pageTbl");
	var totalTbl = document.getElementById("totalTbl");

	var qTime = getValue( inQueryTime );
	var vTime = getValue( inViewTime );

	var dyend = new Date();
	var pView = (dyend - dystart - qTime - vTime);
	var tTime = (dyend - dystart);

	totalTbl.style.backgroundColor = "transparent";

	queryTbl.title = "DB: "		+ qTime + " [ms]" ;
	viewTbl.title  = "JSP: "	+ vTime + " [ms]" ;
	pageTbl.title  = "IE: "		+ pView + " [ms]" ;
	totalTbl.innerHTML = Math.round( tTime / 100 )/10 + " [s]";

	if( tTime > maxViewTime ) {
		totalTbl.style.backgroundColor = "#ffff33";
		viewRatio = viewRatio * maxViewTime / tTime;
	}

	queryTbl.innerHTML = "&nbsp;";
	viewTbl.innerHTML  = "&nbsp;";
	pageTbl.innerHTML  = "&nbsp;";

	queryTbl.width = Math.floor( qTime / viewRatio +1 );
	viewTbl.width  = Math.floor( vTime / viewRatio +1 );
	pageTbl.width  = Math.floor( pView / viewRatio +1 );

	dystart = 0;
}
