var tempHtml;
var tempStr1;
var tempStr2;
if (section == null)	var section = 0;
if (level1 == null)	var level1 = "";
if (level2 == null)	var level2 = "";
if (level3 == null)	var level3 = "";
if (level4 == null)	var level4 = "";
if (level5 == null)	var level5 = "";
if (level6 == null)	var level6 = "";
if (level7 == null)	var level7 = "";

var levelArray = new Array();
var idArray = new Array();

if (selectArray == null)	var selectArray = null;
var id1 = null;
var id2 = null;
var id3 = null;
var id4 = null;
var id5 = null;
var id6 = null;
var id7 = null;

if (location.search != '')
{
	if (GetParam('section'))	section = GetParam('section');
	if (GetParam('level1'))	level1 = GetParam('level1');
	if (GetParam('level2'))	level2 = GetParam('level2');
	if (GetParam('level3'))	level3 = GetParam('level3');
	if (GetParam('level4'))	level4 = GetParam('level4');
}

var titlePadding = 12;
var titleSubTitle = "";
var treeLinkSubTitle = "";
var treeLinkPadding = 10;

var link = location.href.toString();

getLevel();
function genDivs(divID)
{
	if (!document.getElementById(divID))
		{
			document.write('<span id="'+divID+'" ></span>');
		}
}

function checkLang()
{
	var astr = link;
	var langs = languages;

	var va = langs;
	for (var item in va)
		{
			if (astr.indexOf(("/" + item + "/")) > -1)
				{
					return item;
				}
		}

	return false;
}

function checkStr(astr, bstr)
{
//alert(astr + " : " + bstr);
	var va = [".", "/", "_"];
	for (var item in va)
		{
			if (astr.indexOf(("/" + bstr + va[item])) > -1)
				{
					return true;
				}
			if (astr.indexOf(("_" + bstr + va[item])) > -1)
				{
					return true;
				}
		}

	return false;
}

function setLevel(obj)
{
	for (var m=0; m<obj.length; m++)
		{		
			if (checkStr(link, obj[m].id))
				{
					levelArray.push(obj[m].id);
					idArray.push(m);
					
					if (typeof(obj[m].subSection)!='undefined')
						{
							setLevel(obj[m].subSection);
						}
					break;
				}
		}
}

function getLevel() {
	var obj = sectionArray[section];
	link = location.href.toString();
	setLevel(obj);
}

function elem(tag, content){ 
	var ret = document.createElement(tag);  
	ret.innerHTML = content;  
	return ret;
}

function genPulldown() {
	
	document.write('<div style="position:relative; margin: 0px auto !important; width:990px; display:block; text-align:left;">');
}

function genPulldownStr(id) {
	var s = sectionArray[1];
	var str = '';
	var section = s[id];
	if (typeof(section.subSection)=='undefined') return '';
	
//	str += '<div id="pulldown_'+id+'" style="visibility:hidden;position:relative;"onMouseOut="MM_showHideLayers(\'pulldown_'+id+'\',\'\',\'hide\');" onMouseOver="MM_showHideLayers(\'pulldown_'+id+'\',\'\',\'show\');">';

	str += '<div id="pulldown_'+id+'" style="top:0px; visibility:hidden;position:relative;"onMouseOut="MM_showHideLayers(\'pulldown_'+id+'\',\'\',\'hide\');" onMouseOver="MM_showHideLayers(\'pulldown_'+id+'\',\'\',\'show\');">';

//str += '<div style="visibility:show;position:relative;" onMouseOut="subNavMotion(\'pulldown_'+id+'\',0);" onMouseOver="subNavMotion(\'pulldown_'+id+'\',1);">';
	
	str += '<div style="position:absolute; width:140px; padding:0px 0px 0px 0px; overflow:hidden;" >';
	str += '	<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	str += '		<tr>';
	str += '			<td>';
	str += '			<a href="'+path+ section.link+'" onMouseOut="MM_showHideLayers(\'pulldown_'+i+'\',\'\',\'hidden\');" onMouseOver="MM_showHideLayers(\'pulldown_'+i+'\',\'\',\'show\');">';
	str += '				<img id="nav_'+section.id+'" src="'+path+'images/common/nav_'+section.id+'_f2.gif" alt="'+section.name+'" border="0">';
	str += '</a>';
	str += '</td>';
	str += '		</tr>';
	str += '		<tr>';
	str += '			<td style="background:url('+path+'images/common/bg_pull.gif) repeat-x top; padding:22px 0px 10px 0px; background-color:#EE620D;">';
	str += '				<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	
	//sub nav link
	for (var i=0; i<section.subSection.length; i++)
		{
			var subSection = section.subSection[i];
			
			str += '					<tr>';
			str += '						<td>';
			
			str += '						<a href="'+path+subSection.link+'" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage(\''+section.id+'_'+subSection.id+'\',\'\',\''+path+'images/common/nav_'+section.id+'_'+subSection.id+'_f2.gif\',1);">';
			str += '<img src="'+path+'images/common/nav_'+section.id+'_'+subSection.id+'.gif" alt="'+subSection.name+'" name="'+section.id+'_'+subSection.id+'" width="140" height="22" border="0">';
			//str += '</a>';
			
			str += '						</td>';
			str += '					</tr>';
		}
	//end of sub nav link
	
	str += '				</table>';
	str += '			</td>';
	str += '		</tr>';
	str += '	</table>';
	str += '</div>';
	str += '</div>';
	
	return str;
}

function genNav() {
	var s = sectionArray[1];
	
	tempHtml = '';
	tempHtml += '<div style="position:absolute; top:39; width:990px; height:25px; background-color:#333333;" class="navBg"></div>';
	tempHtml += '<div id="nav" style="position:absolute; top:39; width:990px; height:25px;z-index:1;">';
	tempHtml += '	<table border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '		<tr valign="bottom">';
	tempHtml += '			<td><img src="'+path+'images/common/spacer.gif" width="25" height="1"></td>';
	
	for (var i=0; i<s.length; i++)
		{
			var section = s[i];
			tempHtml += '			<td height="25" style="padding:0px 45px 0px 0px;">';
			tempHtml += genPulldownStr(i);
//			tempHtml += '			<a href="'+path+ section.link+'" onMouseOut="MM_swapImgRestore();MM_showHideLayers(\'pulldown_'+i+'\',\'\',\'hidden\');" onMouseOver="MM_swapImage(\'nav_'+section.id+'\',\'\',\''+path+'images/common/nav_'+section.id+'_f2.gif\',1);MM_showHideLayers(\'pulldown_'+i+'\',\'\',\'show\');">';

			tempHtml += '			<a href="'+path+ section.link+'" onMouseOut="MM_showHideLayers(\'pulldown_'+i+'\',\'\',\'hidden\');" onMouseOver="MM_showHideLayers(\'pulldown_'+i+'\',\'\',\'show\');">';

			tempHtml += '<img id="nav_'+section.id+'" src="'+path+'images/common/nav_'+section.id+'.gif" alt="'+section.name+'" border="0">';
			tempHtml += '</a>';
			tempHtml += '</td>';
			
//tempHtml += '			<a href="'+path+ section.link+'" onMouseOut="MM_showHideLayers(\'pulldown_'+i+'\',\'\',\'hidden\');" onMouseOver="subNavMotion(\'pulldown_'+i+'\',1);"><img src="'+path+'images/common/nav_'+section.id+'.gif" alt="'+section.name+'" border="0"></a>';

//tempHtml += '			<a href="'+path+ section.link+'" onMouseOut="subNavMotion(\'pulldown_'+i+'\',0);" onMouseOver="subNavMotion(\'pulldown_'+i+'\',1);"><img src="'+path+'images/common/nav_'+section.id+'.gif" alt="'+section.name+'" border="0"></a>';

tempHtml += '</td>';
		}
	
	tempHtml += '		</tr>';
	
	tempHtml += '	</table>';
	tempHtml += '</div>';
	

	tempHtml += '<div id="nav_bg" style="position:absolute; top:64; width:990px; height:3px;"><img src="'+path+'images/common/bg_nav.png" width="990" height="3"></div>';
			
	document.write(tempHtml);
}

function genTreelink() {
	var s = sectionArray[1];
	

	tempHtml = '';
	tempHtml += '						<table width="650" border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '							<tr>';
	tempHtml += '								<td align="right" height="13"><a href="'+path+'index.htm"><img src="'+path+'images/common/logo_head.gif" alt="Nan Fung Group" width="128" height="13" hspace="25" border="0"></a></td>';
	tempHtml += '							</tr>';
	tempHtml += '							<tr valign="top">';
	tempHtml += '								<td align="right" style="padding:40px 25px 0px 0px;">';
	tempHtml += '									<table border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '										<tr valign="top">';
	

	var section = s;
	for (var i=0; i<idArray.length; i++)
		{
			var section = section[idArray[i]];
			tempHtml += '<td class="treelink">';
			
			if (section.link != '')
				{
					tempHtml += '<a href="'+path+ section.link+'" class="treelink">';
				}
			
			if (i >= (idArray.length-1))
				{
					tempHtml += '<strong>'+section.name+'</strong>';
				}
			else
				{
					tempHtml += section.name;
				}
				
			if (section.link != '')
				{
					tempHtml += '</a>';
				}
			tempHtml += '</td>';
			
			if (i >= (idArray.length-1)) break;
			
			tempHtml += '<td style="padding:6px 0px 0px 0px;"><img src="'+path+'images/common/arrow_orange.gif" width="3" height="5" hspace="4"></td>';
			section = section.subSection;
		}
	
	
	tempHtml += '										</tr>';
	tempHtml += '									</table>';
	tempHtml += '								</td>';
	tempHtml += '							</tr>';
	tempHtml += '						</table>';
			
	document.write(tempHtml);
}

function genRegionSelector()
{
	var tempHtml = '';
	
	var s = idArray[4];

	tempHtml += '<span style="position:relative;width:1px;height:1px;"><div style="position:absolute;width:210px;height:21px;display:block;top:8px;left:417px;">';
	if (s == 0) {
		// for Resi 
		tempHtml += '<span><a href="develop_hk_comm.htm"  onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage(\'develop_hk_comm_switch_btn\',\'\',\'../images/business/develop_hk_comm_btn_f2.gif\',1);" ><img id="develop_hk_comm_switch_btn" src="../images/business/develop_hk_comm_btn.gif" border="0" alt="COMMERICAL" title="COMMERICAL"></a><a href="develop_hk_resi_island.htm"><img style="position:relative;left:8px;margin:0px;padding:0px;" src="../images/business/develop_hk_resi_btn_f2.gif"  border="0"  alt="RESIDENTIAL" title="RESIDENTIAL"></a></span>';
	} else if (s == 1) {
		// for Resi the same
		tempHtml += '<span><a href="develop_hk_comm.htm"  onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage(\'develop_hk_comm_switch_btn\',\'\',\'../images/business/develop_hk_comm_btn_f2.gif\',1);" ><img id="develop_hk_comm_switch_btn" src="../images/business/develop_hk_comm_btn.gif" border="0" alt="COMMERICAL" title="COMMERICAL"></a><a href="develop_hk_resi_island.htm"><img style="position:relative;left:8px;margin:0px;padding:0px;" src="../images/business/develop_hk_resi_btn_f2.gif"  border="0"  alt="RESIDENTIAL" title="RESIDENTIAL"></a></span>';
	} else {
		// for Comm
		tempHtml += '<span><a href="develop_hk_comm.htm"><img src="../images/business/develop_hk_comm_btn_f2.gif" border="0" alt="COMMERICAL" title="COMMERICAL"></a><a href="develop_hk_resi_island.htm" style="position:relative;left:8px;margin:0px;padding:0px;" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage(\'develop_hk_resi_switch_btn\',\'\',\'../images/business/develop_hk_resi_btn_f2.gif\',1);" ><img id="develop_hk_resi_switch_btn" src="../images/business/develop_hk_resi_btn.gif" border="0"  alt="RESIDENTIAL" title="RESIDENTIAL"></a></span>';
	}
	tempHtml += '</div></span>';
	document.write(tempHtml);
}

function genTop() {
	var section = sectionArray[1];
	//section = section[idArray[0]];
	var index = idArray.length;
	var lv = 3;
	if (index>lv)
		{
			index = lv;
		}
	if ((idArray[0] == 1)
	&& (idArray[1] == 1)
	&& (idArray[2] == 0)
	)
		{
			index = 4;
		}
	
	for (var i=0; i<index; i++)
		{
			section = (i<(index-1))?section[idArray[i]].subSection:section[idArray[i]];
			//section = section.subSection;			
		}
	
	tempHtml = '';
	tempHtml += '<table width="990" border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '	<tr valign="top">';
	tempHtml += '		<td width="340" style="background:url(\''+path+'images/banner/bg_'+section.id+'1.jpg\') repeat-y;"><img src="'+path+'images/banner/'+section.id+'.jpg" width="340" height="600"></td>';
	tempHtml += '		<td width="650" style="padding:20px 0px 0px 0px; background-color:#FFFFFF;">';
			
	document.write(tempHtml);
}

function genEnd() {
	tempHtml = '';
	tempHtml += '		</td>';
	tempHtml += '	</tr>';
	tempHtml += '</table>';
	tempHtml += '</div>';
			
	document.write(tempHtml);
}

function genFooter(pad) {
	tempHtml = '';
	
	var t_bldg = genBuildingCode();
	
	//var lang = checkLang(link, languages);
	var lang = checkLang();
	//alert(lang);
	
	if (pad) {
		var str = pad;
	} else {
		var str = 0;
	}
	
	tempHtml += '						<table border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '							<tr valign="bottom">';
	tempHtml += '								<td align="right" style="padding:0px 12px 0px 0px;">';
	tempHtml += '									<table border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '										<tr>';
	tempHtml += '											<td align="right">';
	tempHtml += '												<table border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '													<tr>';
	
	var tmp_cnt = 0; // used for hide sitemap | , no use later.
	for (var item in languages)
		{
			var it  = languages[item];
			if (item == lang) continue;
				
			tempHtml += '														<td class="treelink"><a href="javascript:changeLanguage(\''+item+'\');" class="treelink" style="font-size:12px;">'+it+'</a></td>';

			if (tmp_cnt <1) {
			tempHtml += '														<td class="treelink" align="center" style="padding:0px 5px 0px 5px;">|</td>';
			}
			tmp_cnt++;
		}
	
	
//	tempHtml += '														<td class="treelink"><a href="#" class="treelink">Sitemap</a></td>';
	tempHtml += '													</tr>';
	tempHtml += '												</table>';
	tempHtml += '											</td>';
	tempHtml += '										</tr>';
	tempHtml += '										<tr>';
	tempHtml += '											<td align="right" class="treelink">Copyright &copy; 2008 Nan Fung Group</td>';
	tempHtml += '										</tr>';
	tempHtml += '									</table>';
	tempHtml += '								</td>';
	if (t_bldg == 'QSC')
		tempHtml += '								<td align="center" width="100"><a href="http://www.queenscube.com" target="_blank"><img src="'+path+'images/common/qsc_logo.gif" alt="Queen\'s Cube"  border="0"></a></td>';		
	tempHtml += '								<td><a href="'+path+'index.htm"><img src="'+path+'images/common/logo.gif" alt="Nan Fung" width="49" height="64" border="0"></a></td>';
	tempHtml += '							</tr>';
	tempHtml += '						</table>';
	
	document.write(tempHtml);
}

function genMFooter(pad) {
	tempHtml = '';
	
	//var lang = checkLang(link, languages);
	var lang = checkLang();
	//alert(lang);
	
	if (pad) {
		var str = pad;
	} else {
		var str = 0;
	}
	
	tempHtml += '						<table border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '							<tr valign="bottom">';
	tempHtml += '								<td align="right" style="padding:0px 12px 0px 0px;">';
	tempHtml += '									<table border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '										<tr>';
	tempHtml += '											<td align="right">';
	tempHtml += '												<table border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '													<tr>';
	
	
	for (var item in languages)
		{
			var it  = languages[item];
			if (item == lang) continue;
				
			tempHtml += '														<td class="treelink"><a href="javascript:changeLanguage(\''+item+'\');" class="treelink" style="font-size:12px;">'+it+'</a></td>';
			tempHtml += '														<td class="treelink" align="center" style="padding:0px 5px 0px 5px;">|</td>';
		}
	
	
	//tempHtml += '														<td class="treelink"><a href="#" class="treelink">Sitemap</a></td>';
	tempHtml += '													</tr>';
	tempHtml += '												</table>';
	tempHtml += '											</td>';
	tempHtml += '										</tr>';
	tempHtml += '										<tr>';
	tempHtml += '											<td align="right" class="treelink">Copyright &copy; 2008 Nan Fung Group</td>';
	tempHtml += '										</tr>';
	tempHtml += '									</table>';
	tempHtml += '								</td>';
	tempHtml += '								<td><a href="'+path+'index.htm"><img src="'+path+'images/common/logo.gif" alt="Nan Fung" width="49" height="64" border="0"></a></td>';
	tempHtml += '							</tr>';
	tempHtml += '						</table>';
	
	document.write(tempHtml);
}



function genJumpMenu(y) {
	tempHtml = '';
	tempHtml += '<div id="jumpmenu" style="position:relative; width:110px; visibility:hidden;">';
	tempHtml += '							<div style="position:absolute; left:0; top:18;">';
	tempHtml += '								<table width="110" border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '									<tr>';
	tempHtml += '										<td width="5" valign="bottom" style="background:url('+path+'images/common/jump_bg.gif) repeat-y left; background-color:#FFFFFF;"><img src="'+path+'images/common/jump_b_l.gif" width="5" height="19"></td>';
	tempHtml += '										<td style="border-bottom:#D6D6D6 1px solid; padding:4px 0px 0px 0px; background:url('+path+'images/common/jump_bg_b.gif) repeat-x bottom; background-color:#FFFFFF;">';
	tempHtml += '											<table width="100%" border="0" cellspacing="0" cellpadding="2">';
	tempHtml += '												<tr>';
	tempHtml += '													<td class="jump"><a href="prize.htm" class="jump">2011</a></td>';
	tempHtml += '												</tr>';
	tempHtml += '												<tr>';
	tempHtml += '													<td class="jump"><a href="prize_2010.htm" class="jump">2010</a></td>';
	tempHtml += '												</tr>';
	tempHtml += '												<tr>';
	tempHtml += '													<td class="jump"><a href="prize_2009.htm" class="jump">2009</a></td>';
	tempHtml += '												</tr>';
	tempHtml += '												<tr>';
	tempHtml += '													<td class="jump"><a href="prize_2008.htm" class="jump">2008</a></td>';
	tempHtml += '												</tr>';
	tempHtml += '												<tr>';
	tempHtml += '													<td class="jump"><a href="prize_2007.htm" class="jump">2007</a></td>';
	//tempHtml += '													<td class="jump" bgcolor="#EFEFEF">2007</td>';
	tempHtml += '												</tr>';
	tempHtml += '												<tr>';
	tempHtml += '													<td class="jump"><a href="prize_2006.htm" class="jump">2006</a></td>';
	tempHtml += '												</tr>';
	tempHtml += '												<tr>';
	tempHtml += '													<td class="jump"><a href="prize_2005.htm" class="jump">2005</a></td>';
	tempHtml += '												</tr>';
	tempHtml += '												<tr>';
	tempHtml += '													<td class="jump"><a href="prize_2004.htm" class="jump">2004</a></td>';
	tempHtml += '												</tr>';
	tempHtml += '												<tr>';
	tempHtml += '													<td class="jump"><a href="prize_2001.htm" class="jump">2001</a></td>';
	tempHtml += '												</tr>';
	tempHtml += '											</table>';
	tempHtml += '										</td>';
	tempHtml += '										<td width="5" valign="bottom" style="background:url('+path+'images/common/jump_bg.gif) repeat-y right; background-color:#FFFFFF;"><img src="'+path+'images/common/jump_b_r.gif" width="5" height="19"></td>';
	tempHtml += '									</tr>';
	tempHtml += '								</table>';
	tempHtml += '							</div>';
	tempHtml += '						</div>';
	tempHtml += '						<table border="0" cellspacing="0" cellpadding="0" style="cursor:pointer;" onClick="MM_showHideLayers(\'jumpmenu\',\'\',\'show\');">';
	tempHtml += '							<tr>';
	tempHtml += '								<td width="2"><img src="'+path+'images/common/jump_l.gif" width="2" height="18"></td>';
	tempHtml += '								<td width="81" style="background:url('+path+'images/common/jump_m.gif) repeat-x; padding:0px 0px 0px 5px;" class="jump">'+y+'</td>';
	tempHtml += '								<td width="22"><img src="'+path+'images/common/jump_r.gif" width="22" height="18"></td>';
	tempHtml += '							</tr>';
	tempHtml += '						</table>';
	
	document.write(tempHtml);
}

function getX(obj){
	var ParentObj=obj;
	var left=obj.offsetLeft;
	while(ParentObj=ParentObj.offsetParent){
		left+=ParentObj.offsetLeft;
	}
	return left;
}

function getY(obj){
	var ParentObj=obj;
	var top=obj.offsetTop;
	while(ParentObj=ParentObj.offsetParent){
		top+=ParentObj.offsetTop;
	}
	return top;
}

function subNavMotion(id, f) {
//alert(id);
	var obj = document.getElementById(id);
	
	if (typeof(obj.timeOut)!='undefined')
		{
			clearTimeout(obj.timeOut);
		}
	
	var speed = 2;
	var t = (f=='1')?-43:-1000;
	var objY = getY(obj);
	var d = (t - objY)/speed;

	if (Math.abs(d) > speed) {
		obj.style.top = (objY + d) + 'px';
		obj.timeOut = setTimeout(function () {subNavMotion(id,f);}, 50);
	} else {
		//alert("ko");
		//obj.style.top = t + "px";
	}
}


function genRegions() {
	tempHtml = '';
	var s = sectionArray[1];
	var section = s;
	var sn = '';
	
	for (var i=0; i<idArray.length; i++)
		{
			if (i<(idArray.length-1))
				{
					if (i>0)
						{
							sn += section[idArray[i]].id + '_';
						}
					section = section[idArray[i]].subSection;
				}
		}
	
	tempHtml += '<table border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '	<tr>';

	//section[(idArray.length-1)];
	
	for (var i=0; i<section.length; i++)
		{
			tempHtml += '	<td style="padding:0px 10px 0px 0px;">';
			
			
			if (i == idArray[(idArray.length-1)])
				{
					tempHtml += '		<img src="../images/'+s[idArray[0]].id+'/'+sn+section[i].id+'_f2.gif" alt="'+section[i].name+'" name="'+sn+section[i].id+'" height="17" border="0">';
				}
			else
				{
					tempHtml += '<a href="'+sn+section[i].id+'.htm" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage(\''+sn+section[i].id+'\',\'\',\'../images/'+s[idArray[0]].id+'/'+sn+section[i].id+'_f2.gif\',1);">';
					tempHtml += '<img src="../images/'+s[idArray[0]].id+'/'+sn+section[i].id+'.gif" alt="'+section[i].name+'" name="'+sn+section[i].id+'" height="17" border="0">';
					tempHtml += '</a>';
				}
			
			 
				
			tempHtml += '</td>';
		}
		
	tempHtml += '	</tr>';
	tempHtml += '</table>';
	
	document.write(tempHtml);
}

function  stringReplaceAll(str, AFindText,ARepText){
  raRegExp = new RegExp(AFindText,"g");
  return str.replace(raRegExp,ARepText);
}

function borderHighlight(t, f)
{
	var imgs = t.getElementsByTagName('img');
	var tds = t.getElementsByTagName('td');
	var s1 = '/shadow_';
	var s2 = '/border_';
	if (!f)
		{
			s1 = '/border_';
			s2 = '/shadow_';
		}
		
	for (var i=0; i< tds.length; i++)
		{
			var td = tds[i].style.background;
			if (td.indexOf(s1)==-1) continue;
			if (td.indexOf('/shadow_bg_m')!=-1) continue;
			tds[i].style.background = td.replace(s1, s2);
		}
		
	for (var i=0; i<imgs.length; i++)
		{
			var src = imgs[i].src;
			if (src.indexOf(s1)==-1) continue;
			imgs[i].src = src.replace(s1, s2);
		}
}

function genSingleBuilding(sn, name)
{
	var obj = buildingObj[name];
	var str;
	str = '';
	str += '<table onMouseOut="borderHighlight(this, false);" onMouseOver="borderHighlight(this, true);" border="0" cellspacing="0" cellpadding="0" title="'+buildingObj[name]['locations']+'">';
	str += '	<tr valign="top">';
	str += '		<td width="5"><img src="../images/common/shadow_t_l.gif" width="5" height="5"></td>';
	str += '		<td width="122" style="background:url(../images/common/shadow_bg_t.gif) repeat-x top;"><img src="../images/common/spacer.gif" width="5" height="5"></td>';
	str += '		<td width="5"><img src="../images/common/shadow_t_r.gif" width="5" height="5"></td>';
	str += '	</tr>';
	str += '	<tr valign="top">';
	str += '		<td style="background:url(../images/common/shadow_bg_l.gif) repeat-y left;"><img src="../images/common/spacer.gif" width="5" height="5"></td>';
	str += '		<td style="background:url(../images/common/shadow_bg_m.gif) repeat-x bottom; padding:0px 0px 2px 0px;" height="132">';
	str += '			<table width="122" border="0" cellspacing="0" cellpadding="0">';
	str += '				<tr>';
	str += '					<td colspan="2"><a href="'+sn+'info.htm#'+name+'"><img src="../images/business/'+sn+name+'.jpg" width="122" height="96" border="0"></a></td>';
	str += '				</tr>';
	str += '				<tr>';
	str += '					<td class="gray" style="padding:0px 0px 0px 4px;" height="36"><a href="'+sn+'info.htm#'+name+'" class="treelink"><strong>'+obj.title+'</strong></a></td>';
	str += '					<td align="right" valign="top" style="padding:4px 4px 0px 0px;"><img src="../images/common/pt_open_2.gif" width="5" height="5"></td>';
	str += '				</tr>';
	str += '			</table>';
	str += '		</td>';
	str += '		<td style="background:url(../images/common/shadow_bg_r.gif) repeat-y right;"><img src="../images/common/spacer.gif" width="5" height="5"></td>';
	str += '	</tr>';
	str += '	<tr valign="top">';
	str += '		<td><img src="../images/common/shadow_b_l.gif" width="5" height="5"></td>';
	str += '		<td style="background:url(../images/common/shadow_bg_b.gif) repeat-x bottom;"><img src="../images/common/spacer.gif" width="5" height="5"></td>';
	str += '		<td><img src="../images/common/shadow_b_r.gif" width="5" height="5"></td>';
	str += '	</tr>';
	str += '</table>';
	
	return str;
}

function genBuilding()
{
	var s = sectionArray[1];
	var section = s;
	var sn = '';
	var buildings;
	
	var lid = '';
	
	for (var i=0; i<idArray.length; i++)
		{
			if (i<(idArray.length-1))
				{
					if (i>0)
						{
							sn += section[idArray[i]].id + '_';
						}
					section = section[idArray[i]].subSection;
					
				}
			buildings = section[idArray[i]].buildings;
			lid = section[idArray[i]].id;
		}
	

	sn += lid + '_';

	tempHtml = '';
	
	tempHtml += '<table width="558" border="0" cellspacing="0" cellpadding="0">';

	tempHtml += '	<tr valign="top">';
	for (var i=0; i<buildings.length; i++)
		{
			if ((i>0) && !(i%4))
				{
					tempHtml += '	</tr>';
					tempHtml += '	<tr valign="top">';
				}
			tempHtml += '		<td style="padding:10px 0px 0px 0px;">';
			tempHtml += genSingleBuilding(sn, buildings[i]);
			tempHtml += '		</td>';
			

			if ((i%4)<3)
				{
					tempHtml += '		<td><img src="../images/common/spacer.gif" width="10" height="1"></td>';
				}
		}
		
	tempHtml += '</table>';
	
	document.write(tempHtml);
}

function genBuildingImage()
{
	var id = getSharpParam();
	var s = sectionArray[1];
	var section = s;
	var sn = '';
	var buildings;
	var lid = '';
	
	for (var i=0; i<idArray.length; i++)
		{
			if (i<(idArray.length-1))
				{
					if (i>1)
						{
							sn += section[idArray[i]].id + '_';
						}
					section = section[idArray[i]].subSection;
				}
			buildings = section[idArray[i]].buildings;
			lid = section[idArray[i]].id;
		}

	sn += lid + '_' + id;

	tempHtml = '';
	tempHtml += '<img src="../images/business/'+sn+'.jpg" width="264" height="211" border="0">';
	document.write(tempHtml);
}

function genBuildingTitle()
{
	var id = getSharpParam();
	if (typeof(buildingObj[id]) == 'undefined') return;
	var title = buildingObj[id].title;
	document.write(title);
}

function genBuildingCode()
{
	var id = getSharpParam();
	if (typeof(buildingObj) == 'undefined') return;
	if (typeof(buildingObj[id]) == 'undefined') return;
	var bldgcode = buildingObj[id].bldgcode;
	return bldgcode;
}

function genTitle(type)
{
	var title = titleVars[type];
	document.write(title);
}

function genBackgroundColor(type)
{
	var id = getSharpParam();
	if (typeof(buildingObj[id]) == 'undefined') 
	{
		return;
	}
	else
	{
		var background_color = buildingObj[id].background_color;
		document.body.style.backgroundColor = background_color;
	}
}

function genBuildingDesc()
{
	var id = getSharpParam();
	
  if (typeof(buildingObj[id]) == 'undefined') return;
	tempHtml = '';
	tempHtml += '<table width="100%" border="0" cellspacing="0" cellpadding="2">';
	for (var item in titleVars)
		{
			var it = titleVars[item];
			var cont = buildingObj[id][item];
			
			if (cont == null || cont == '') continue;
			
			tempHtml += '	<tr valign="top">';
			
			if (item=='salesbrochure' || item=='priceplan' || item=='prelimagreement' || item=='agreement')
			{
				if (cont.indexOf('http') >= 0)
					cont = '<a href="'+cont+'" class="orange" target="_blank">' + it + '</a>';
				else	
					cont = '<a href="#'+id+'" class="orange" onClick="maxwindow(\''+cont+'\')" >' + it + '</a>';
					
				tempHtml += '		<td width="55" colspan="3" class="gray"><nobr>'+cont+'</nobr></td>';				
			}		
			else
			{
				tempHtml += '		<td width="55" class="gray"><nobr>'+it+'</nobr></td>';
				tempHtml += '		<td width="15" class="gray">:</td>';
				
				if (item=='url')
				{
					cont = '<a href="'+cont+'" target="_blank" class="gray">' + cont +	'</a>';
				}													
				tempHtml += '		<td class="'+((item=='enquiry')?'orange':'gray')+'">'+cont+'</td>';
			}				
			

			tempHtml += '	</tr>';
		}
	tempHtml += '</table>';
	document.write(tempHtml);
}

function genNextBuildingBtn()
{
	var id = getSharpParam();
	
	var s = sectionArray[1];
	var section = s;
	var sn = '';
	var buildings;
	
	var lid = '';
	
	for (var i=0; i<idArray.length; i++)
		{
			if (i<(idArray.length-1))
				{
					if (i>0)
						{
							sn += section[idArray[i]].id + '_';
						}
					section = section[idArray[i]].subSection;
					
				}
			buildings = section[idArray[i]].buildings;
			lid = section[idArray[i]].id;
		}
	
	var currentIndex = 0;
	for (var i=0; i<buildings.length; i++)
		{
			if (id == buildings[i])
				{
					currentIndex = 1+i;
					break;
				}
		}
	if (currentIndex>=(buildings.length-1))
		{
			currentIndex = 0;
		}
	
	var str = '';
	str = '<a href="?'+buildings[currentIndex]+'" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage(\'btn_next\',\'\',\'../images/common/btn_next_f2.gif\',1);"><img src="../images/common/btn_next.gif" alt="Next" name="btn_next" width="56" height="15" hspace="3" vspace="2" border="0"></a>';
	document.write(str);
}

function genDetailMenu(t)
{
	var id = getSharpParam();
	
	var s = sectionArray[1];
	var section = s;
	var sn = '';
	var buildings;
	
	var lid = '';
	var cid = '';
	
	for (var i=0; i<idArray.length; i++)
		{
			if (i<(idArray.length-1))
				{
					if (i>0)
						{
							sn += section[idArray[i]].id + '_';
						}
					section = section[idArray[i]].subSection;
					
				}
			buildings = section[idArray[i]].buildings;
			cid = section[idArray[i]].id;
			lid = section[idArray[i]].id;
		}
	

	sn += lid + '_';
			//gallery = section[idArray[i]].gallery;
			//floorplan = section[idArray[i]].floorplan;
	
	tempHtml = '';
	
	tempHtml += '<table border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '	<tr>';
	
	tempHtml += '<td style="padding:0px 0px 0px 10px;">';
	if (t == 'info')
		{
			tempHtml += '<img src="../images/common/detail_info_f2.gif" alt="Info" name="detail_info" width="42" height="17" border="0">';
		}
	else
		{
			tempHtml += '<a href="'+sn+'info.htm#'+id+'" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage(\'detail_info\',\'\',\'../images/common/detail_info_f2.gif\',1);">';
			tempHtml += '<img src="../images/common/detail_info.gif" alt="Info" name="detail_info" width="42" height="17" border="0">';
			tempHtml += '</a>';
		}
	tempHtml += '</td>';
	
	var floorplan = [];
	if (levelArray[3] == 'comm')
		{
			floorplan = buildingObj[id].floorplan;
		}
	else
		{
			floorplan = buildingObj[id].floorplan_resi;
		}
	
	if (floorplan.length > 0)
		{
			tempHtml += '<td style="padding:0px 0px 0px 10px;">';
			if (t == 'floorplan')
				{
					tempHtml += '<img src="../images/common/detail_floor_f2.gif" alt="Floor Plan" name="detail_floor" width="72" height="17" border="0">';
				}
			else
				{
					tempHtml += '<a href="'+sn+'floorplan.htm#'+id+'" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage(\'detail_floor\',\'\',\'../images/common/detail_floor_f2.gif\',1);">';
					tempHtml += '<img src="../images/common/detail_floor.gif" alt="Floor Plan" name="detail_floor" width="72" height="17" border="0">';
					tempHtml += '</a>';
				}
			tempHtml += '</td>';
		}
	
	var gallery = [];
	if (levelArray[3] == 'comm')
		{
			gallery = buildingObj[id].gallery.length;
		}
	else
		{
			gallery = buildingObj[id].gallery_resi.length;
		}
	if (gallery > 0)
		{
			tempHtml += '<td style="padding:0px 0px 0px 10px;">';
			if (t == 'gallery')
				{
					tempHtml += '<img src="../images/common/detail_gallery_f2.gif" alt="Gallery" name="detail_gallery" width="57" height="17" border="0">';
				}
			else
				{
					tempHtml += '<a href="'+sn+'gallery.htm#'+id+'" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage(\'detail_gallery\',\'\',\'../images/common/detail_gallery_f2.gif\',1);">';
					tempHtml += '<img src="../images/common/detail_gallery.gif" alt="Gallery" name="detail_gallery" width="57" height="17" border="0">';
					tempHtml += '</a>';
				}
			tempHtml += '</td>';
		}
		
	tempHtml += '	</tr>';
	tempHtml += '</table>';
	
	document.write(tempHtml);
}

function genFloorplans()
{
	var id = getSharpParam();
	var s = sectionArray[1];
	var section = s;
	var sn = '';
	var buildings;
	
	var lid = '';
	
	for (var i=0; i<idArray.length; i++)
		{
			if (i<(idArray.length-1))
				{
					if (i>1)
						{
							sn += section[idArray[i]].id + '_';
						}
					section = section[idArray[i]].subSection;
					
				}
			buildings = section[idArray[i]].buildings;
			lid = section[idArray[i]].id;
		}
	
	sn += lid + '_' + id;

	tempHtml = '';
	

	var obj = [];
	if (levelArray[3] == 'comm')
		{
			obj = buildingObj[id].floorplan;
		}
	else
		{
			obj = buildingObj[id].floorplan_resi;
		}
	
	tempHtml += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';

	tempHtml += '	<tr valign="top">';
	
	for (var i=0; i<obj.length; i++)
		{
			if ((i>0) && !(i%2))
				{
					tempHtml += '	</tr>';
					tempHtml += '	<tr valign="top">';
				}
			tempHtml += '		<td style="padding:10px 0px 0px 0px;" class="fullHeight">';
			var k = 1 + i;
			
			tempHtml += genSingleFloorplan(sn, k, obj[i]);
			tempHtml += '		</td>';
			
			 if ((i%2)<1)
				{
						tempHtml += '<td><img src="../images/common/spacer.gif" width="1" height="1"></td>';
				}
		}
		
	tempHtml += '	</tr>';
	tempHtml += '</table>';
	
	document.write(tempHtml);
}


function genSingleFloorplan(sn, index, txt)
{
	var str;
	var tImageH = '710';
	var tImageW = '700';
	var tPImageH = '702';
	var tPImageW = '700';
	
	if (sn+'_'+index+'_lrg.gif'=='hk_comm_maons_1_lrg.gif' || sn+'_'+index+'_lrg.gif'=='hk_comm_tseunc_1_lrg.gif' || sn+'_'+index+'_lrg.gif'=='hk_comm_nanfpc_2_lrg.gif' || sn+'_'+index+'_lrg.gif'=='hk_comm_nanfpc_1_lrg.gif')
	{
		tImageW	= '1000';
		tImageH = '900';
		tPImageW = '1000';
		tPImageH = '900';
	}	  
	
	if (sn+'_'+index+'_lrg.gif'=='hk_comm_tseunc_2_lrg.gif')
	{
		tImageW	= '920';
		tImageH = '900';
		tPImageW = '920';
		tPImageH = '900';
	}	  
	
	str = '';
	str += '<table width="278" border="0" cellspacing="0" cellpadding="0" class="fullHeight">';
	str += '	<tr valign="top">';
	str += '		<td width="5" height="5"><img src="../images/common/shadow_t_l.gif" width="5" height="5"></td>';
	str += '		<td width="268" style="background:url(../images/common/shadow_bg_t.gif) repeat-x top;"><img src="../images/common/spacer.gif" width="5" height="5"></td>';
	str += '		<td width="5"><img src="../images/common/shadow_t_r.gif" width="5" height="5"></td>';
	str += '	</tr>';
	str += '	<tr valign="top">';
	str += '		<td style="background:url(../images/common/shadow_bg_l.gif) repeat-y left;"><img src="../images/common/spacer.gif" width="5" height="5"></td>';
	str += '		<td class="fullHeight">';
	str += '			<table width="100%" border="0" cellspacing="0" cellpadding="0" class="fullHeight">';
	str += '				<tr>';
	str += '					<td colspan="2" align="center" height="196"><a href="javascript:popupHtml(\'../images/business/floorplan/'+sn+'_'+index+'_lrg.gif\','+tImageW+', '+tImageH+', \'floorplan\');"><img src="../images/business/floorplan/'+sn+'_'+index+'.gif" width="215" height="176" vspace="10" border="0"></a></td>';
	str += '				</tr>';
	str += '				<tr valign="top" bgcolor="#EEEEE9">';
	str += '					<td class="treelink" style="padding:0px 0px 0px 10px;"><strong>'+txt+'</strong></td>';
	str += '					<td align="right" valign="top" style="padding:3px 10px 2px 0px;"><a href="javascript:popupHtml(\'../images/business/floorplan/'+sn+'_'+index+'_lrg.gif\','+tImageW+', '+tImageH+', \'floorplan\');" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage(\'icon_print\',\'\',\'../images/common/icon_print_f2.gif\',1);"><img src="../images/common/icon_print.gif" name="icon_print" width="16" height="15" border="0"></a></td>';
	str += '				</tr>';
	str += '			</table>';
	str += '		</td>';
	str += '		<td style="background:url(../images/common/shadow_bg_r.gif) repeat-y right;"><img src="../images/common/spacer.gif" width="5" height="5"></td>';
	str += '	</tr>';
	str += '	<tr valign="top">';
	str += '		<td height="5"><img src="../images/common/shadow_b_l.gif" width="5" height="5"></td>';
	str += '		<td style="background:url(../images/common/shadow_bg_b.gif) repeat-x bottom;"><img src="../images/common/spacer.gif" width="5" height="5"></td>';
	str += '		<td><img src="../images/common/shadow_b_r.gif" width="5" height="5"></td>';
	str += '	</tr>';
	str += '</table>';
	
	return str;
}



function genGallery()
{
	var id = getSharpParam();
	var s = sectionArray[1];
	var section = s;
	var sn = '';
	var buildings;
	
	var lid = '';
	
	for (var i=0; i<idArray.length; i++)
		{
			if (i<(idArray.length-1))
				{
					if (i>1)
						{
							sn += section[idArray[i]].id + '_';
						}
					section = section[idArray[i]].subSection;
					
				}
			buildings = section[idArray[i]].buildings;
			lid = section[idArray[i]].id;
		}
	

	sn += lid + '_' + id;

	tempHtml = '';
	

	var obj = [];
	if (levelArray[3] == 'comm')
		{
			obj = buildingObj[id].gallery;
		}
	else
		{
			obj = buildingObj[id].gallery_resi;
		}

	tempHtml += '<table width="578" border="0" cellspacing="0" cellpadding="0">';

	tempHtml += '	<tr valign="top">';
	
	
	for (var i=0; i<obj.length; i++)
		{
			if ((i>0) && !(i%3))
				{
					tempHtml += '	</tr>';
					tempHtml += '	<tr valign="top">';
				}
			tempHtml += '		<td style="padding:10px 0px 0px 0px;">';
			tempHtml += genSingleGallery(sn+'_'+(1+i), obj, i);
			tempHtml += '		</td>';
			
			 if ((i%3)<2)
				{
					tempHtml += '		<td><img src="../images/common/spacer.gif" width="1" height="1"></td>';
				}
		}
		
	tempHtml += '	</tr>';
	tempHtml += '</table>';
	
	document.write(tempHtml);
}


function genSingleGallery(sn, obj, i)
{
	var str;
	str = '';
	str += '<table width="186" border="0" cellspacing="0" cellpadding="0">';
	str += '	<tr valign="top">';
	str += '		<td width="5"><img src="../images/common/shadow_t_l.gif" width="5" height="5"></td>';
	str += '		<td width="176" style="background:url(../images/common/shadow_bg_t.gif) repeat-x top;"><img src="../images/common/spacer.gif" width="5" height="5"></td>';
	str += '		<td width="5"><img src="../images/common/shadow_t_r.gif" width="5" height="5"></td>';
	str += '	</tr>';
	str += '	<tr valign="top">';
	str += '		<td style="background:url(../images/common/shadow_bg_l.gif) repeat-y left;"><img src="../images/common/spacer.gif" width="5" height="5"></td>';
	str += '		<td style="background:url(../images/common/shadow_bg_m.gif) repeat-x bottom;">';
	
	str += '<a href="../images/business/gallery/'+sn+'_lrg.jpg" rel="lightbox[nanfung]" date="" desc="'+obj[i]+'">';
	str += '<img src="../images/business/gallery/'+sn+'.jpg" width="176" height="140" border="0">';
	str += '</a>';
	
	str += '</td>';
	str += '		<td style="background:url(../images/common/shadow_bg_r.gif) repeat-y right;"><img src="../images/common/spacer.gif" width="5" height="5"></td>';
	str += '	</tr>';
	str += '	<tr valign="top">';
	str += '		<td><img src="../images/common/shadow_b_l.gif" width="5" height="5"></td>';
	str += '		<td style="background:url(../images/common/shadow_bg_b.gif) repeat-x bottom;"><img src="../images/common/spacer.gif" width="5" height="5"></td>';
	str += '		<td><img src="../images/common/shadow_b_r.gif" width="5" height="5"></td>';
	str += '	</tr>';
	str += '</table>';
	
	return str;
}

function changeMap(m)
{
	var map = document.getElementById('map');
	map.src = '../images/business/develop_map'+((m=='')?'':'_')+m+'.gif';
}
