/*
 * Hantec JS utilities.
 */
var updateCnt = 4;
var hotTime = 1000 / updateCnt;
//var hotTime = 600;
var forexPrefix = "fx";
var imgUp = '<img src="img/pic_arrow_up.gif" alt="up" border="0">';
var imgDown = '<img src="img/pic_arrow_down.gif" alt="down" border="0">';
var doFade = false;

//alert("Update Cnt: " + updateCnt);

// color
var blackColor = "#000000";
var goldColor = "#FFD700";
var redColor = "#FF9999";
var greenColor = "#90EE90";
var dimgrayColor = "#696969";

//time format from [0-24] to [0-12] (without AM / PM )
function formatTime(val) {
	var a = new Number(val.substring(0,val.indexOf(":")));
	if (a > 12) {
		a -= 12;
	}

	var b = val.substring(val.indexOf(":"),val.length);
	return a + b;
}

//format a decimal number to a fixed number of decimals
function formatDecimal(value, decimals, keepZero, enlarge) {
	var mul = new String("1");
	var zero = new String("0");

	for (var i = decimals; i > 0; i--) {
		mul += zero;
	}
	value = Math.round(value * mul);
	value = value / mul;
	var strVal = new String(value);
	if (!keepZero) {
		return strVal;
	}

	var nowDecimals = 0;
	var dot = strVal.indexOf(".");
	if (dot == -1) {
		strVal += ".";
	} else {
		nowDecimals = strVal.length - dot - 1;
	}

	for (var i = nowDecimals; i < decimals; i++) {
		strVal = strVal + zero;
	}

	// NEW - START
	if (enlarge) {
		var len = strVal.length;
		if(dot != len - 2) {
//            var retVal = strVal.substring(0, len - 2) + '<div class="lastDigits">' + strVal.substring(len - 2) + '</div>';
			var retVal = strVal.substring(0, len - 2) + '<div class="' + enlarge + '">' + strVal.substring(len - 2) + '</div>';
		} else {
//            var retVal = strVal.substring(0, len - 3) + '<div class="lastDigits">' + strVal.substring(len - 3) + '</div>';
			var retVal = strVal.substring(0, len - 3) + '<div class="' + enlarge + '">' + strVal.substring(len - 3) + '</div>';
		}
	} else {
		retVal = strVal;
	}
	// NEW - END

	//return strVal;
	return retVal;
}


function showHot(mode, row, itemName, up) {
//	var item = parent.topFrame.document.getElementById(itemName);
	var item = document.getElementById(itemName);

	if (mode == 'Simple') {
		if (up) {
			item.style.backgroundColor = greenColor;
		} else {
			item.style.backgroundColor = redColor;
		}

		if (row % 2 == 1) {
			setTimeout(itemName + ".style.backgroundColor = '#FFFFFF'", hotTime);
		} else {
			setTimeout(itemName + ".style.backgroundColor = '#FFFFFF'", hotTime);
		}
	} else if (mode == 'Advanced') {
		if (up) {
			item.style.color = blackColor;
			item.style.backgroundColor = greenColor;
		} else {
			item.style.color = blackColor;
			item.style.backgroundColor = redColor;
		}

		if(row % 2 == 1) {
//			setTimeout("parent.topFrame." + itemName + ".style.color = '#FFFFFF';" + itemName + ".style.backgroundColor = '#666666'", hotTime);
			setTimeout("showCold('" + itemName + "')", hotTime);
		} else {
//			setTimeout("parent.topFrame." + itemName + ".style.color = '#FFFFFF';" + itemName + ".style.backgroundColor = '#666666'", hotTime);
			setTimeout("showCold('" + itemName + "')", hotTime);
		}
	}
}

function showCold(itemName) {
//	var item = parent.topFrame.document.getElementById(itemName);
	var item = document.getElementById(itemName);
	item.style.color = '#FFFFFF';
	item.style.backgroundColor = '#666666';
}

function openPopup(strUrl) {
	window.open(strUrl + '&t=?' + Math.random(), 'popup', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=yes,left=100,top=100,width=610,height=420');
}

// block escape key
document.onkeydown = checkEscape;
document.onkeypress = checkEscape;
function checkEscape(e) {
	if (!e) {
		e = event;
	}
	if (e.keyCode == 27) {
		return false;
	}
}
