var urlArr=document.location.href.split("/");
var currSubDom = urlArr[2].split(".");
var THISHOSTNAME = currSubDom[0] + ".housingauthority.gov.hk";
var toEN = '/hdw/en/residential/hos07/phase3/';
var toB5 = '/hdw/b5/residential/hos07/phase3/';
var toGB = '/hdw/gb/residential/hos07/phase3/';

function switchLanguage(lang)
{
	var host1, host2, host3, host4, host5, host6;
	
	host1 = "ht";
	host2 = "tp://";
	host5 = ".gov.hk";
	
	if (currSubDom[0].substr(0,1).toLowerCase()=="s")
	{
		currSubDom[0].length=="2"?host3="ww":host3="wcm";
		currSubDom[0].length=="2"?host4="w.housingauthority":host4="s.housingauthority";
		currSubDom[0].length=="2"?host6="www":host6="wcms";
	}
	else
	{
		currSubDom[0].length=="3"?host3="ww":host3=currSubDom[0];
		currSubDom[0].length=="3"?host4="w.housingauthority":host4=".housingauthority";
		currSubDom[0].length=="3"?host6="sc":host6="sctest";
	}
	
	if (lang == "toGB")
	{
		var targetURL = host1 + host2 + host6 + ".housingauthority.gov.hk/gb/" + THISHOSTNAME + eval("toB5") + urlArr[urlArr.length-1];
		SetCookie('scURL', targetURL);
		
		if (currSubDom[0].substr(0,1).toLowerCase()=="s")
			document.location.href = host1 + host2 + host6 + ".housingauthority.gov.hk/gb/www.housingauthority.gov.hk/scDisclaimer";
		else
			document.location.href = '/scDisclaimer';
	}
	else
	{
		document.location.href = host1 + host2 + host3 + host4 + host5 + eval(lang) + urlArr[urlArr.length-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 showChiLink()
{
	var subDom = currSubDom[0].substr(0,2);
	if (subDom.toLowerCase() == "sc")
		document.write("<img id=\"header\" name=\"header\" src=\"/hdw/content/static/images/b5/residential/hos07/phase3/header.jpg\" usemap=\"#map_header\" alt=\"\" /><map id=\"map_header\" name=\"map_header\"><area shape=\"rect\" coords=\"15,6,151,33\" href=\"http://www.housingauthority.gov.hk/gb\" alt=\"香港房屋委員會\" title=\"香港房屋委員會\" /><area shape=\"rect\" coords=\"554,19,609,31\" href=\"#\" onClick=\"switchLanguage('toEN');return false;\" alt=\"ENGLISH\" title=\"ENGLISH\" /><area shape=\"rect\" coords=\"623,19,657,31\" href=\"#\" onClick=\"switchLanguage('toB5');return false;\" alt=\"繁體版\" title=\"繁體版\" /><area shape=\"rect\" coords=\"670,19,715,31\" href=\"#\" onClick=\"window.close()\" alt=\"關閉\" title=\"關閉\" /></map>");
	else
		document.write("<img id=\"header\" name=\"header\" src=\"/hdw/content/static/images/b5/residential/hos07/phase3/header.jpg\" usemap=\"#map_header\" alt=\"\" /><map id=\"map_header\" name=\"map_header\"><area shape=\"rect\" coords=\"15,6,151,33\" href=\"http://www.housingauthority.gov.hk/b5\" alt=\"香港房屋委員會\" title=\"香港房屋委員會\" /><area shape=\"rect\" coords=\"554,19,609,31\" href=\"#\" onClick=\"switchLanguage('toEN');return false;\" alt=\"ENGLISH\" title=\"ENGLISH\" /><area shape=\"rect\" coords=\"621,19,657,31\" href=\"#\" onClick=\"switchLanguage('toGB');return false;\" alt=\"簡體版\" title=\"簡體版\" /><area shape=\"rect\" coords=\"670,19,715,31\" href=\"#\" onClick=\"window.close()\" alt=\"關閉\" title=\"關閉\" /></map>");
}

////////////////////////////////////////////////////////
// standard functions for preloading and swapping images
////////////////////////////////////////////////////////

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 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_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 preloadImage(thisSection)
{
	var imgArr = new Array();
	var a=0;
	var imgPath = "/hdw/content/static/images/b5/residential/hos07/phase3/";
	
	imgArr[a++] = imgPath + "nav_btn1_on.jpg";
	imgArr[a++] = imgPath + "nav_btn2_on.jpg";
	imgArr[a++] = imgPath + "nav_btn3_on.jpg";
	imgArr[a++] = imgPath + "nav_btn4_on.jpg";
	imgArr[a++] = imgPath + "nav_btn5_on.jpg";
	
	if(thisSection==5)	// General information
	{
		imgArr[a++] = imgPath + "left_nav_si_generalinformation_on.jpg";
		imgArr[a++] = imgPath + "left_nav_si_informationbrochures_off.jpg";
		imgArr[a++] = imgPath + "left_nav_si_priceinformation_off.jpg";
		imgArr[a++] = imgPath + "left_nav_si_viewing_off.jpg";
		imgArr[a++] = imgPath + "left_nav_si_resaleflats_off.jpg";
		imgArr[a++] = imgPath + "left_nav_si_video_off.jpg";
		imgArr[a++] = imgPath + "left_nav_si_ballotresults_off.jpg";
	}
	else	// Other sections
	{
		imgArr[a++] = imgPath + "left_nav_courtInfo_on.jpg";
		imgArr[a++] = imgPath + "left_nav_informationBrochure_on.jpg";
		imgArr[a++] = imgPath + "left_nav_photoKiosk_on.jpg";
		imgArr[a++] = imgPath + "left_nav_priceInformation_on.jpg";
		imgArr[a++] = imgPath + "left_nav_resaleFlats_on.jpg";
		imgArr[a++] = imgPath + "left_nav_resaleFlatsInformation_on.jpg";
		imgArr[a++] = imgPath + "left_nav_salesBrochure_on.jpg";
		imgArr[a++] = imgPath + "left_nav_video_on.jpg";
		imgArr[a++] = imgPath + "left_nav_VirtualTour_on.jpg";
	}
	
	var d=document;
	var f=p=0;
	
	if(d.images)
	{
		d.preload_image=new Array();
	
		for(var f=0; f<imgArr.length; f++)
		{
			d.preload_image[p] = new Image;
			d.preload_image[p++].src = imgArr[f];
		}
	}
}

function openPDF(thisPdfURL) {
  thisPdfURL = 'http://hos.housingauthority.gov.hk'+thisPdfURL; 
	openPDFwin  = window.open(thisPdfURL,"openPDF","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=500");
	openPDFwin.focus();
}

function changeBtn(imgSrc,changefrom,changeto){	
	changeLink = imgSrc.src;
	changeLink = changeLink.replace("_"+changefrom,"_"+changeto);
	imgSrc.src = changeLink;
}
