<!--
// browser detection
var ns4=document.layers
var ns6=document.getElementById&&!document.all
var ie4=document.all
var loadready=0

function ImgOn(Nam) {
    if (loadready == 1) {
	if (document.images) {
		document.images[Nam].src = eval(Nam+ "_on.src");
	}
    }
}

function ImgOff(Nam) {
    if (loadready == 1) {
	if (document.images) {
		document.images[Nam].src = eval(Nam+ "_off.src");
	}
    }
}	

function hideLayer(div) {
    if (loadready==1) {
	if(ie4)	document.all[div].style.visibility="hidden";	
	if(ns4)	eval('document.layers.'+div+'.visibility="hide"');
	if(ns6)	document.getElementById(div).style.visibility="hidden";
    }
}

function showLayer(div) {
    if (loadready == 1)	{
	if(ie4)	document.all[div].style.visibility="visible";	
	if(ns4)	eval('document.layers.'+div+'.visibility="show"');
	if(ns6)	document.getElementById(div).style.visibility="visible";
    }
}

function mImgOn(divName,imgName) {
    if (loadready == 1)	{	
	if(ie4 || ns6)
	{
		document.images[imgName].src = eval(imgName+ "_on.src")
	}
	if(ns4)
	{
		imgOn(divName.substring(1, (divName.length)));
		showLayer(divName);
		document.layers[divName].document.images[imgName].src = eval(imgName + "_on.src")
	}
    }
}

function mImgOff(divName,imgName) {
    if (loadready == 1)	{	
	if(ie4 || ns6)
	{
		document.images[imgName].src = eval(imgName+ "_off.src")
	}
	if(ns4)
	{
		imgOff(divName.substring(1, (divName.length)));
		document.layers[divName].document.images[imgName].src = eval(imgName + "_off.src")
		hideLayer(divName);
	}
    }
}

function closeWindow(){
	self.close()
}

function goToURL(thisURL) {
	self.location = thisURL;
}

function thirdNavigateTo() {
	goToURL(document.thirdNavSection.thirdNavSectionListing[document.thirdNavSection.thirdNavSectionListing.selectedIndex].value);
}

//isBypass = 'kanhanBypass' if you want to bypass KanHan server
function formatUrl(url, isBypass) {
  
//  alert(location.hostname +' == '+ THISHOSTNAME)
	var url2 = url;

	if (location.hostname != THISHOSTNAME && url.indexOf("://") < 0) {
	//for translation server
		var tmpUrl = url;
		if (url.indexOf("?") >= 0) {
			tmpUrl = url.substring(0, url.indexOf("?") -1);
		}
		var re = /\.[a-zA-Z0-9]+$/gi;
		if (tmpUrl.match(re)) {
			var re_html = /\.html{0,1}$/gi;
			if (!tmpUrl.match(re_html)) {
				url = replace(url, "/b5/", "/gb/");
			}
		}
		url = "/gb/" + THISHOSTNAME + url;
	} else {
	   var brVer = navigator.userAgent;
	   var brVerId = brVer.indexOf('MSIE');

		if (brVerId > 0)
		{
			// Commment by David Lee on 20080117  1747 to solve banner popup problem
      //url = replace(url, "&", escape("&"));
		}
	}

	// added by Jacky on 20090212 to solve flash minisite GB problem
	if(url2.indexOf("#kanhanbypass#") >= 0) {
		url = url2.replace("#kanhanbypass#","");
		url = "ht"+"tp://" + THISHOSTNAME + url;
	}

	if(isBypass == 'kanhanBypass') {
		url = url.replace("sc.housingauthority.gov.hk/gb/","");
		url = url.replace("sctest.housingauthority.gov.hk/gb/","");
	}

	return url;
}

//isBypass = 'kanhanBypass' if you want to bypass KanHan server
function formatUrl2(url, isBypass) {
	if (location.hostname != THISHOSTNAME && url.indexOf("://") < 0) {
	//for translation server
		var tmpUrl = url;
		if (url.indexOf("?") >= 0) {
			tmpUrl = url.substring(0, url.indexOf("?") -1);
		}
		var re = /\.[a-zA-Z0-9]+$/gi;
		if (tmpUrl.match(re)) {
			var re_html = /\.html{0,1}$/gi;
			if (!tmpUrl.match(re_html)) {
				url = replace(url, "/b5/", "/gb/");
			}
		}
		url = "/gb/" + THISHOSTNAME + url;
	} 

	if(isBypass == 'kanhanBypass') {
		if (url.indexOf("sctest.")>=0){
      url = url.replace("sctest.housingauthority.gov.hk/gb/","");
    }else{
		  url = url.replace("sc.housingauthority.gov.hk/gb/","");
		}
	}
	return url;
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function popup(url, width, height, isBypass){
	nw  = window.open(formatUrl(url, isBypass),"cdaNewWin","toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height);
	nw.focus();
}

function popup2(url,width,height, isBypass){
	nw  = window.open(formatUrl2(url, isBypass),"cdaNewWin","toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height);
	nw.focus();
}

function popup(url, width, height,winName, isBypass){
	//alert(3)
	//alert(width)
	//alert(height)
	//alert(winName)
	//alert(isBypass)
	//alert('formatUrl: '+ formatUrl(url, isBypass))
	nw  = window.open(formatUrl(url, isBypass),winName,"toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height);
	nw.focus();
}

function popupVideo(redirPage, lang){
	var toB5 = '/hdw/content/document/b5/aboutus/gallery/stream/';
	var toEN = '/hdw/content/document/en/aboutus/gallery/stream/';
	var toGB = '/hdw/content/document/gb/aboutus/gallery/stream/';

	var toUrl = toB5;
	if (lang == "b5") {
		var urlArr=document.location.href.split("/");
		var currSubDom = urlArr[2].split(".");

		if (currSubDom[0].substr(0,1).toLowerCase()=="s") {
			toUrl = toGB;
		}
	} else if (lang == "en") {
		toUrl = toEN;
	} else if (lang == "gb") {
		toUrl = toGB;
	}

	toUrl = toUrl + redirPage;
	
	nw  = window.open(toUrl,"popVideoWin","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=10,height=10");
}

function popup2(url, width, height,winName, isBypass){	
  nw  = window.open(formatUrl2(url, isBypass),winName,"toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height);
	nw.focus();
}

function goToInteractiveMap(url){
	nw  = window.open(formatUrl(url),"interactiveMap","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=760,height=600");
	nw.focus();
}

function getCookieVal (offset) 
   {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
   }

function GetCookie (name) 
   {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) 
      {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break; 
      }
   return '1';
   }

function SetCookie (name, value) 
   {
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   var path = (argc > 3) ? argv[3] : "/";
   var domain = (argc > 4) ? argv[4] : null;
   var secure = (argc > 5) ? argv[5] : false;
   document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + "housingauthority.gov.hk")) +
        ((secure == true) ? "; secure" : "");
   }

function DeleteCookie () 
   {
   var exp = new Date();
   exp.setTime (exp.getTime() - 1000000000);  // This cookie is history (changed -1 to make it previous time)
   var cval = GetCookie ('DemoName');
   document.cookie ='DemoName' + "=" + cval + "; expires=" + exp.toGMTString();
   }

function resetRandomNumber() {
	noOfSets = 3;
	imageShow = Math.ceil(Math.random()*noOfSets);
//	DeleteCookie();
	SetCookie("imageSet", imageShow);
}

function randomMainPhoto(imgPath, imgWidth, imgHeight, imgAlt) { 
	var imageShow;
	var height;
	var width;
//	imageShow = GetCookie("imageSet");	
	if (imgWidth != "") {
		width = " width=" + imgWidth + " ";
	}
	
	if (imgHeight != "") {
		height = " height=" + imgHeight + " ";
	}
//	alert("<IMG SRC=\"" + imgPath  + "\" " + width + height + " BORDER=\"0\" ALT=\"" + imgAlt + "\">");
	document.write("<IMG SRC=\"" + imgPath  + "\" " + width + height + " BORDER=\"0\" ALT=\"" + imgAlt + "\">");
}

function getCurrentPath() {
	var curPath = "/print" + location.pathname;
	return curPath;
}
//-->
