var checkGoldPrice = false;

function showGoldPrice(url) {
	if(checkGoldPrice == false) {
		var reqGoldPrice = GetXmlHttpObject();
		if (reqGoldPrice == null) {
			checkGoldPrice = false;
	  		return;
	  	}
		//alert(reqGoldPrice);
	  	checkGoldPrice = true;

		reqGoldPrice.onreadystatechange = function () {

			stateChangeGoldPrice(reqGoldPrice);
			try {
				if (reqGoldPrice.readyState == 4) {
					reqGoldPrice.abort();
					reqGoldPrice = null;
				}
			}
			catch(ex) {

			}
		};

		reqGoldPrice.open("GET",url,true);
		reqGoldPrice.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
		reqGoldPrice.setRequestHeader("Cache-Control", "no-cache");
		reqGoldPrice.send(null);
	}
}

function stateChangeGoldPrice(reqGoldPrice){
	if (reqGoldPrice.readyState==4){
  		var result = reqGoldPrice.responseText;

  		if(result != ""){
  			var arr = result.split("&");
  			window.document.getElementById("dateupdate_goldprice").innerHTML = arr[0];
  			var arrIndex = arr[1].split("#");
  			var arrDetail = Array(arrIndex.length);
			for(i=1; i<arrIndex.length; i++){
				arrDetail[i] = arrIndex[i].split(";");
			}

	  		for(i=1;i<arrDetail.length;i++){
	  			window.document.getElementById("goldType_"+i).innerHTML = arrDetail[i][0];
	  			window.document.getElementById("buy_"+i).innerHTML = convertGoldPriceToString(arrDetail[i][1]);
	  			window.document.getElementById("sell_"+i).innerHTML = convertGoldPriceToString(arrDetail[i][2]);
	  			/*window.document.getElementById("highest_"+i).innerHTML = convertGoldPriceToString(arrDetail[i][3]);
	  			window.document.getElementById("lowest_"+i).innerHTML = convertGoldPriceToString(arrDetail[i][4]);*/
	  		}
  		}
  	}
}

function convertGoldPriceToString(nStr){
	if(nStr == "0.0") return "--";
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
