// JavaScript Document


// menu
<!--
  var IE = document.all ? true : false;
  var Xpos = 0;
  var Ypos = 0;
  var MenuID=0;
  var SubMenuID=0;
  if (!IE) document.captureEvents(Event.MOUSEMOVE);
  document.onmousemove = getXYpos;
  function getXYpos(e) {
    if (IE) {
      Xpos = event.clientX + document.body.scrollLeft;
      Ypos = event.clientY + document.body.scrollTop;
    } else {
      Xpos = e.pageX;
      Ypos = e.pageY;
    }
    if (Xpos < 0) Xpos = 0;
    if (Ypos < 0) Ypos = 0;
    return true;
  }
  var timeout = 10000;
  function resetTimer() {
    clearTimeout(timeout);
  }
  function setTimer() {
    timeout = setTimeout("doRestore()", 1000);
    return true;
  }
  function doRestore() {
  //alert(SubMenuID);
//    if (Xpos < 955 && Ypos < 131) {
//    if (Xpos < 730 && Ypos < 240 && Ypos > 124) {
    if (Xpos < 730 && Ypos < 180 && Ypos > 124) {
      resetTimer();
      setTimer();
    } else {
       Onload_showHideLayers(MenuID,SubMenuID) 
      resetTimer();
	  //MM_swapImgRestore();
    }
    return true;
  }

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}


function movstart(a,time){
movx=setInterval("mov("+a+")",10)
}
function movover(){
clearInterval(movx)
}
function mov(a){
scrollx=news.document.body.scrollLeft
scrolly=news.document.body.scrollTop
scrolly=scrolly+a
news.window.scroll(scrollx,scrolly)
}
function o_down(theobject){
object=theobject
while(object.filters.alpha.opacity>60){
object.filters.alpha.opacity+=-10}
}
function o_up(theobject){
object=theobject
while(object.filters.alpha.opacity<100){
object.filters.alpha.opacity+=10}
}
function wback(){
if(news.history.length==0){window.history.back()}
else{news.history.back()}
}




function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}





function win(url,name, w, h) {
l=(window.screen.width/2)-(w/2);
t=(window.screen.height/2)-(h/2);

features = "width="+w+",height="+h+",left="+l+",top="+t;
features += ",screenX="+l+",screenY="+t;
features += ",scrollbars=0,resizable=0,location=0";
features += ",menubar=0,toolbar=0,status=0";

tour=window.open(url, name, features);
tour.focus();
}



function movstart(a,time){
movx=setInterval("mov("+a+")",10)
}
function movover(){
clearInterval(movx)
}
function mov(a){
scrollx=news.document.body.scrollLeft
scrolly=news.document.body.scrollTop
scrolly=scrolly+a
news.window.scroll(scrollx,scrolly)
}
function o_down(theobject){
object=theobject
while(object.filters.alpha.opacity>60){
object.filters.alpha.opacity+=-10}
}
function o_up(theobject){
object=theobject
while(object.filters.alpha.opacity<100){
object.filters.alpha.opacity+=10}
}
function wback(){
if(news.history.length==0){window.history.back()}
else{news.history.back()}
}


// popup win

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



var ns6,ns4,ie4;
 
// Show/Hide functions for non-pointer layer/objects
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
ns6 = false;
 
//if the DOM is not IE and not NS4, it must be NS6
if (ns4 == ie4) {
 ns6 = true;
 ie4 = ns4 = false;
}
 
var URL,width,height,scroll,menubar,toolbar,poplocation,resize,xPos,yPos,newWin,winName,center,alignLeft;
function openWin(URL,width,height,scroll,menubar,poplocation,toolbar,resize,xPos,yPos,winName,center,alignLeft,fullscreen){
 var focusFail = false;
 if (width == "") width = 785;
 if (height == "") height = screen.availHeight - (screen.availHeight / 5);
 if (poplocation == "") poplocation = "no";
 if (scroll == "") scroll = "auto";
 if (menubar =="") menubar = "no";
 if (toolbar == "") toolbar = "no";
 if (resize == "") resize = "yes";
 if (xPos == "") xPos = "5";
 if (yPos == "") yPos = "5";
 if (winName == "") winName = "win";
 if (center == "yes"){
  var centerWidth = screen.availWidth/2;
  var centerHeight = screen.availHeight/2;
  tempW = width/2;
  tempH = height/2;
  xPos = centerWidth - tempW;
  yPos = centerHeight - tempH;
 }
 if (alignLeft == "yes"){
  xPos = screen.availWidth - width - 7
 }
 if (fullscreen == "yes"){
  xPos = 0;
  yPos = 0;
  if (navigator.appVersion.indexOf("mac") == 1){
   width = screen.availWidth;
   height = screen.availHeight;
  } else {
   width = screen.availWidth - 7;
   height = screen.availHeight - 20;
  }
 }
 var features ="width=" +width+ ",height=" +height+ ",location=" +poplocation+ ",scrollbars=" +scroll+ ",menubar=" +menubar+ ",toolbar=" +toolbar+ ",resizable=" +resize+ ",left=" +xPos+ ",top=" +yPos;
  newWin = window.open(URL,winName,features);
 if (navigator.appVersion.indexOf("NT")!= -1){
  if (navigator.appVersion.indexOf("NT 5")!= -1){
   focusFail = false;
  } else if (ie4 == true) focusFail = true;
 }
 if (focusFail == false){
  if (window.focus) newWin.focus();
 }
}

//


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}





function win(url,name, w, h) {
l=(window.screen.width/2)-(w/2);
t=(window.screen.height/2)-(h/2);

features = "width="+w+",height="+h+",left="+l+",top="+t;
features += ",screenX="+l+",screenY="+t;
features += ",scrollbars=0,resizable=0,location=0";
features += ",menubar=0,toolbar=0,status=0";

tour=window.open(url, name, features);
tour.focus();
}


	  
// languages switch
var host = "http://www.housingauthority.gov.hk/";
var host1 = "ht";
var host2 = "tp://";
var host3 = "ww";
var host4 = "w.housingauthority";
var host5 = ".gov.hk/";
//var host = "http://wcms.housingauthority.gov.hk/";
//var host1 = "ht";
//var host2 = "tp://";
//var host3 = "wc";
//var host4 = "ms.housingauthority";
//var host5 = ".gov.hk/";

var theUrl=window.document.location.toString();
var url_start_hdw= theUrl.lastIndexOf("/hdw/")+7;
var url_start_tx= theUrl.lastIndexOf("/tx/")+6;
var url_end = theUrl.length;

function to_b5(){
var url_b5= host1 + host2 + host3 + host4 + host5 + "hdw/b5"+theUrl.substring(url_start_hdw,url_end);
document.location.href=url_b5
}
function to_en(){
var url_en= host1 + host2 + host3 + host4 + host5 + "hdw/en"+theUrl.substring(url_start_hdw,url_end);
document.location.href=url_en
}
function to_gb(){
var targetURL= "http://sc.housingauthority.gov.hk/gb/www.housingauthority.gov.hk/hdw/b5"+theUrl.substring(url_start_hdw,url_end);
//var targetURL= "http://sctest.housingauthority.gov.hk/gb/wcms.housingauthority.gov.hk/hdw/b5"+theUrl.substring(url_start_hdw,url_end);
//SetCookie('scURL', targetURL);
//document.location.href = '/scDisclaimer';
document.location.href=targetURL;
}
function to_txEN(){
var url_txEn= host1 + host2 + host3 + host4 + host5 + "tx/en"+theUrl.substring(url_start_hdw,url_end);
document.location.href=url_txEn
}
function to_txB5(){
var url_txB5= host1 + host2 + host3 + host4 + host5 + "tx/b5"+theUrl.substring(url_start_hdw,url_end);
if (theUrl.lastIndexOf("/gb/")>0)
{
var url_txB5= host + "tx/b5"+theUrl.substring(url_start_hdw,url_end);
} 
document.location.href=url_txB5
}
function to_txGB(){
var targetURL= "http://sc.housingauthority.gov.hk/gb/www.housingauthority.gov.hk/tx/b5"+theUrl.substring(url_start_hdw,url_end);
//var targetURL= "http://sctest.housingauthority.gov.hk/gb/wcms.housingauthority.gov.hk/tx/b5"+theUrl.substring(url_start_hdw,url_end);
//SetCookie('scURL', targetURL);
//document.location.href = '/scDisclaimer';
document.location.href=targetURL;
}
function txto_b5(){
var url_b5= host1 + host2 + host3 + host4 + host5 + "hdw/b5"+theUrl.substring(url_start_tx,url_end);
if (theUrl.lastIndexOf("/gb/")>0)
{
var url_b5= host + "hdw/b5"+theUrl.substring(url_start_tx,url_end);
}
document.location.href=url_b5
}
function txto_EN(){
var url_en= host1 + host2 + host3 + host4 + host5 + "hdw/en"+theUrl.substring(url_start_tx,url_end);
document.location.href=url_en
}
function txto_gb(){
var targetURL= "http://sc.housingauthority.gov.hk/gb/www.housingauthority.gov.hk/hdw/b5"+theUrl.substring(url_start_tx,url_end);
//var targetURL= "http://sctest.housingauthority.gov.hk/gb/wcms.housingauthority.gov.hk/hdw/b5"+theUrl.substring(url_start_tx,url_end);
//SetCookie('scURL', targetURL);
//document.location.href = '/scDisclaimer';
document.location.href=targetURL;
}
function txto_txEN(){
var url_txEn= host1 + host2 + host3 + host4 + host5 + "tx/en"+theUrl.substring(url_start_tx,url_end);
document.location.href=url_txEn
}
function txto_txB5(){
var url_txB5= host1 + host2 + host3 + host4 + host5 + "tx/b5"+theUrl.substring(url_start_tx,url_end);
document.location.href=url_txB5
}
function txto_txGB(){
var targetURL= "http://sc.housingauthority.gov.hk/gb/www.housingauthority.gov.hk/tx/b5"+theUrl.substring(url_start_tx,url_end);
//var targetURL= "http://sctest.housingauthority.gov.hk/gb/wcms.housingauthority.gov.hk/tx/b5"+theUrl.substring(url_start_tx,url_end);
//SetCookie('scURL', targetURL);
//document.location.href = '/scDisclaimer';
document.location.href=targetURL;
}

function changeTxt() {
	if (location.hostname == "sc.housingauthority.gov.hk")
	//if (location.hostname == "sctest.housingauthority.gov.hk")
	{
		to_txGb();
	}
	else {
		to_txB5();
	}
}
//





