<!--
var stockDte;
var indexDte;
var stockInfo;

function createStockURL(lang){
	var d=new String(self.document.location.host);
	var re = /sc.hangseng.com/g;
	if (re.test(d)) { 		//detect simplified chinese
		document.write ('<form name="quoteform" method="get" action="ht' + 'tp:/' + '/ww' + 'w.hang' + 'seng.com/' + 'c_' + 'investment/stock_quote.asp" > <input type="hidden" name="visited" value="Y" />');
  }else if (lang=="e"){
 		document.write ('<form name="quoteform" method="get" action="http://www.hangseng.com/e_investment/stock_quote.asp" > <input type="hidden" name="visited" value="Y" />');
  }else{
 		document.write ('<form name="quoteform" method="get" action="http://www.hangseng.com/c_investment/stock_quote.asp" > <input type="hidden" name="visited" value="Y" />');
  }
}

function createTimeStamp(lang){
	var html='';
	var i;
	var d=new String(self.document.location.host);
	var sc=false;
	var re = /sc.hangseng.com/i;
  if (re.test(d)) { 		//detect simplified chinese
			sc=true;
	}
	setStockInfo();
	html += (lang=="e"?"Index last updated:":"\u6307 \u6578 \u6700 \u5F8C \u66F4 \u65B0:") + ' ' + formatDate(indexDte) + ' ' + formatTime(indexDte,false) + ';<br>';
	html += (lang=="e"?"stock quote as at":"\u80A1 \u50F9 \u76F4 \u81F3:")                 + ' ' + formatDate(stockDte) + ' ' + formatTime(stockDte,false);
	document.write(html);
}

function createStocks(lang) {
	var html='';
	var i;
	var d=new String(self.document.location.host);
	var sc=false;
	var re = /sc.hangseng.com/i;
  if (re.test(d)) { 		//detect simplified chinese
			sc=true;
	}
	
	setStockInfo();

	html+='<table width="100%" cellspacing="0" cellpadding="0" border="0">';
	bg='';
	for (i=0; i<stockInfo.length && i<3; i++)	{
		var arw = (parseFloat(stockInfo[i].chg)>=0)?'/hsb/image/up.gif':'/hsb/image/dn.gif';
		var chg = (parseFloat(stockInfo[i].chg)>=0)?parseFloat(stockInfo[i].chg):parseFloat(stockInfo[i].chg) * -1;
		if (parseFloat(stockInfo[i].chg)==0) arw = '/hsb/com/spacer.gif';
		
		html+='<tr>';

			html+='<td class="index"><div align="left">';
			if (i<=1)	// HSI and HSCEI
				html+=(lang=='e'?stockInfo[i].code:stockInfo[i].chi_desc);
			else      // Stock price of Hang Seng Bank
				html+=(lang=='e'?'Hang Seng Bank':'\u6052 \u751F \u9280 \u884C');			
			html+='</font></div></td>';

			html+='<td class="index"><div align="right">' + formatNumber(stockInfo[i].price) + '</div></td>';
			html+='<td class="index"><div align="right">&nbsp;<img src="' + arw + '" width="10" height="11" >&nbsp;';
			html+='' + formatNumber(chg) + '</div></td>';

		html+='</tr>';
	}
	html+='</table>';
	document.write(html);
}

function formatNumber(amount) {
	amount+='';
	var dot=amount.indexOf('.');
	if (dot>=0) {
		amount+='0000';
		num=amount.substr(0,dot+3);
	}
	else {
		num=amount+'.00';	
	}
	return num;
}

function formatNumber2(amount) {
	// returns the amount in the .99 format 
  amount -= 0;
	// amount = (Math.round(amount*100))/100;
  amount = (Math.floor(amount*100))/100;
  return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

function formatDate(d) {
	var yyyy=d.getFullYear();
	var mm=d.getMonth();
	mm+=1;
	var dd=d.getDate();
 	return(dd+'-'+mm+'-'+yyyy);
}

function formatTime(d,s) {
	var hh=d.getHours();
	var mm=d.getMinutes();
	var ss=d.getSeconds();
	if (mm<10) mm='0'+mm;
	if (ss<10) ss='0'+ss;
 	return ((s)?(hh+':'+mm+':'+ss):(hh+':'+mm));
}
//-->

