<!--
// 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);
}

function formatUrl(url) {
	return 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)
		{
			url = replace(url, "&", escape("&"));
		}
	}
	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){
	nw  = window.open(formatUrl(url),"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){ 
	nw  = window.open(formatUrl(url),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;
}
//-->