function doCalculate() {
	var objRows = document.getElementById('tblMBPrice').rows;
	var strImg = '<img width="17" height="17" alt="" src="http://www.imacusers.com/wp-content/uploads/2008/10/arrowup.png" title="Gone up" class="alignleft size-medium wp-image-134"/>';
	if(objRows != "" && objRows.length > 0) {
		var nRows = objRows.length;
		var nDollarPrice = parseFloat(document.getElementById('txtExchangeRate').value);
		if(isNaN(nDollarPrice)) {
			alert("Please enter a valid exchange rate!");
			return;
		}
		for(var i=1; i < nRows; i++) {
			if(objRows[i].cells.length > 1) {
				var nUSPrice = parseInt(objRows[i].cells[2].innerHTML.replace(",","")); //TODO: use regex to clean non-nums
				var nUSPriceInINR = nUSPrice * nDollarPrice ;
				var nIndiaPrice = parseInt(objRows[i].cells[4].innerHTML.replace(",",""));
				var nPercentageDiff = Math.round((((nIndiaPrice - nUSPriceInINR) / nUSPriceInINR) * 100) * 100) / 100;

				objRows[i].cells[3].innerHTML = formatNumber(Math.round(nUSPriceInINR * 100) / 100);
				objRows[i].cells[5].innerHTML = formatNumber(Math.round((nIndiaPrice - nUSPriceInINR) * 100) / 100);
				if(nPercentageDiff > 0) {
					objRows[i].cells[6].innerHTML = strImg + nPercentageDiff + "%";
				}
				else {
					objRows[i].cells[6].innerHTML = nPercentageDiff + "%";
				}
			}
		}
	}
}

function formatNumber(nStr) {
	var nCount = 0;
	var arrd, arrx;
	var strNum = "";

	nStr += "";
	arrd = nStr.split(".");
	if(typeof(arrd)  == "object" && arrd.length > 1) {
		arrx = arrd[0].split("");
	}
	else {
		arrx = nStr.split("");
		arrd = new Array();
		arrd.push("00");
		arrd.push("00");
	}
	for(var i = arrx.length - 1; i >=0; i--) {
		nCount++;
		strNum = arrx[i] + strNum;
		if(nCount == 3 && i > 0) {
			strNum = "," + strNum;
			nCount = 0;
		}

	}
	return strNum + "." + arrd[1];
}
