// side flash linking

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_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_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_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() { //v6.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 ChgUrl(submenu, subbutton) {
 //alert(submenu + " " + subbutton);

//if found  /news/ , then return position let substring cut it , else it will return -1
url = location.href;
cut = url.lastIndexOf("/news/"); //找不到就return -1
url = url.substring(0, cut+1);

//alert(submenu + "=" + subbutton);

  if (submenu=="")
  {
    submenu=1;
  }

  if (subbutton=="")
  {
    subbutton=0;
  }


  if(submenu==1 && subbutton==1)
   window.location = url + "service_createsmart.htm";

  if(submenu==1 && subbutton==2)
   window.location = url + "service_designsupport.htm";

  if(submenu==1 && subbutton==3)
   window.location = url + "service_film.htm";

  if(submenu==1 && subbutton==4)
   window.location = url + "service_digital.htm";

  if(submenu==1 && subbutton==5)
   window.location = url + "service_support.htm";


  if(submenu==2 && subbutton==0)
   window.location = url + "about.htm";

  if(submenu==2 && subbutton==1)
   window.location = url + "about_organisation.htm";

  if(submenu==2 && subbutton==2)
   window.location = url + "about_vision.htm";

  if(submenu==2 && subbutton==3)
   window.location = url +  "logo.htm";


 if(submenu==3 && subbutton==1)
   window.location = url + "whats_new_event.htm";
   
 if(submenu==3 && subbutton==2)
   window.location = url + "whats_new_pr.htm";

 if(submenu==3 && subbutton==3)
   window.location = url + "whats_new_hof_spikesasia.htm";

 if(submenu==3 && subbutton==4)
   window.location = url + "whats_new_report.htm";   

 if(submenu==3 && subbutton==5)
   window.location = url + "whats_new_rl.htm";
   
/*
 if(submenu==3 && subbutton==1)
   window.location = url + "whats_new_event.htm";
   
 if(submenu==3 && subbutton==2)
   window.location = url + "whats_signature.htm";   

 if(submenu==3 && subbutton==3)
   window.location = url + "whats_new_pr.htm";

 if(submenu==3 && subbutton==4)
   window.location = url + "whats_new_hof.htm";

 if(submenu==3 && subbutton==5)
   window.location = url + "whats_new_report.htm";   

 if(submenu==3 && subbutton==6)
   window.location = url + "whats_new_rl.htm";
*/


 if(submenu==4 && subbutton==1)
   window.location = url + "news_press_release.htm";

 if(submenu==4 && subbutton==2)
   window.location = url + "news_archive.htm";



 if(submenu==5 && subbutton==1)
   window.location = url + "links_related.htm";

 if(submenu==5 && subbutton==2)
   window.location = url + "links_site.htm";




 if(submenu==6 && subbutton==1)
   window.location = url + "access_detail.htm";


 if(submenu==6 && subbutton==2)
   window.location = url + "access_charge.htm";



 if(submenu==7 && subbutton==1)
   window.location = url + "tools_glossary.htm";

 if(submenu==7 && subbutton==2)
   window.location = url + "tools_Software.htm";



 if(submenu==8 && subbutton==1)
   window.location = url + "faq_special.htm";

 if(submenu==8 && subbutton==2)
   window.location = url + "faq_location.htm";

 if(submenu==8 && subbutton==3)
   window.location = url + "faq_permits.htm";



 if(submenu==9 && subbutton==1)
   window.location = url + "event_calendar.htm";

 if(submenu==9 && subbutton==2)
   window.location = url + "signature_event_10.htm";	

  if(submenu==9 && subbutton==3)
   window.location = url + "service_createsmart.htm";

  if(submenu==9 && subbutton==4)
   window.location = url + "service_designsupport.htm";

  if(submenu==9 && subbutton==5)
   window.location = url + "service_film.htm";

  if(submenu==9 && subbutton==6)
   window.location = url + "service_digital.htm";

  if(submenu==9 && subbutton==7)
   window.location = url + "service_support.htm";







// window.location = "index3.php?submenu=" + submenu + "&subbutton=" + subbutton;
}

// for navi bar 

function ChgUrl2(mainmenu) { 

//if found  /news/ , then return position let substring cut it , else it will return -1
url = location.href;
cut = url.lastIndexOf("/news/"); //找不到就return -1
url = url.substring(0, cut+1);

if(mainmenu==1)
   window.location = url+ "home.htm";
if(mainmenu==2)
   window.location = url+ "about.htm";
if(mainmenu==3)
   window.location = url+ "whats_new_event.htm";
if(mainmenu==4)
   window.location = url+ "news_press_release.htm";
if(mainmenu==5)
   window.location = url+ "service.htm";
if(mainmenu==6)
   window.location = url+ "event_calendar.htm";
if(mainmenu==7)
   window.location = url+ "consultation.htm";
if(mainmenu==8)
   window.location = url+ "faq_special.htm";

if(mainmenu==9)
   window.location = url+ "contact_us.htm";

if(mainmenu==10)
   window.location = url+ "sitemap.htm";
}


// for change language

function switchLang(newlang){
	url = location.href;
	var langArr=new Array("en", "tc", "sc");
	for (i=0;i<=langArr.length-1;i++){
		if(url.lastIndexOf("/"+langArr[i]+"/")>0){
			new_url=	url.replace("/"+langArr[i]+"/","/"+newlang+"/");
		}
	}
	if(newlang=="textonly"){
	for (i=0;i<=langArr.length-1;i++){
		if(url.lastIndexOf("/"+langArr[i]+"/")>0){
			new_url=	url.replace("/"+langArr[i]+"/","/text_only/"+langArr[i]+"/");
		}
	}
	//new_url=url.replace("M_mark","M_mark/textonly");
	}
	if(newlang=="graphic"){
	for (i=0;i<=langArr.length-1;i++){
		if(url.lastIndexOf("/text_only/"+langArr[i]+"/")>0){
			new_url=	url.replace("/text_only/"+langArr[i]+"/","/"+langArr[i]+"/");
		}
	}
	//new_url=url.replace("M_mark/textonly","M_mark");
	}

	window.open(new_url,"_self");
		
}

// for search 
function gosearch(value , lang){

Encoder.EncodeType = "numerical";


var value = Encoder.htmlEncode(value);


//alert(value + "=" + lang);


value=escape(value);

time = Math.round(((new Date()).getTime()-Date.UTC(1970,0,1))/1000);

switch(lang){
  
  case "tc":
    url="http://gp.search.gov.hk/search?output=xml_no_dtd&client=depts&proxystylesheet=ogcio_home_adv_frontend&" + time + "=sessionid&gp1=mardep_createhk_home&gp0=mardep_createhk_home&site=mardep_createhk_home&web=this&q=" + value + "&&&tpl_id=stdsearch&ui_lang=zh";
    window.open(url,"name","height=768,width=700,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,status=yes");
    break;

   case "en":
    url="http://gp.search.gov.hk/search?output=xml_no_dtd&client=depts&proxystylesheet=ogcio_home_adv_frontend&" + time + "=sessionid&gp1=mardep_createhk_home&gp0=mardep_createhk_home&site=mardep_createhk_home&web=this&q=" + value + "&&&tpl_id=stdsearch&ui_lang=zh-cn&filter=0";
    window.open(url,"name","height=768,width=700,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,status=yes");
    break;

   case "sc":
    url="http://gp.search.gov.hk/search?output=xml_no_dtd&client=depts&proxystylesheet=ogcio_home_adv_frontend&" + time + "=sessionid&gp1=mardep_createhk_home&gp0=mardep_createhk_home&site=mardep_createhk_home&web=this&q=" + value + "&tpl_id=stdsearch&ui_lang=zh-cn&filter=0";
    window.open(url,"name","height=768,width=700,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,status=yes");
    break;
 }
}




// for egt midify date


function date_ddmmmyy(date)
{
  var d = date.getDate();
  var m = date.getMonth() + 1;
  var y = date.getYear();

  // handle different year values 
  // returned by IE and NS in 
  // the year 2000.
  if(y>= 2000)
  {
    y -= 2000;
  }
  if(y>= 100)
  {
    y -= 100;
  }

  // could use splitString() here 
  // but the following method is 
  // more compatible
  var mmm = 
    ( 1==m)?"01":( 2==m)?"02":(3==m)?"03":
    ( 4==m)?"04":( 5==m)?"05":(6==m)?"06":
    ( 7==m)?"07":( 8==m)?"08":(9==m)?"09":
    (10==m)?"10":(11==m)?"11":"12";

  return "" +
    (d<10?"0"+d:d) + "-" +
    mmm + "-" +
    (y<10?"0"+y:y);
}


//
// get last modified date of the 
// current document.
//
function date_lastmodified()
{
  var lmd = document.lastModified;
  var s   = "Unknown";
  var d1;

  // check if we have a valid date
  // before proceeding

  var ktoday = new Date(document.lastModified);
  var kdd=ktoday.getDate();
var kmm=ktoday.getMonth()+1;
var kyy=ktoday.getFullYear();

 
  if(0 != (d1=Date.parse(lmd)))
  {
    //s = "" + date_ddmmyy(new Date(document.lastModified));
	s = "" + date_ddmmmyy(new Date(d1));


  }

  return s;
}




//for print page

var gAutoPrint = true;

function processPrint(div_id){

if (document.getElementById != null){

var html = "<HTML>\n<HEAD>\n";

if (document.getElementsByTagName != null){

var headTags = document.getElementsByTagName("head");

if (headTags.length> 0) html += headTags[0].innerHTML;

}

html += "\n</HE" + "AD>\n<BODY>\n";

var printReadyElem = document.getElementById(div_id);

if (printReadyElem != null) html += printReadyElem.innerHTML;

else{

alert("Error, no contents.");

return;

}

html += "\n</BO" + "DY>\n</HT" + "ML>";

var printWin = window.open("","processPrint", "height=800, width=700, top=0, left=0, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=no, status=no");

printWin.document.open();

printWin.document.write(html);

printWin.document.close();

if (gAutoPrint) printWin.print();

} else alert("Browser not supported.");

}// end of function





function createDiv(){

	/*

  if(document.getElementById("news"))
     document.getElementById("print_menu").innerHTML = "<input type='image' src='../../images/printer2.png'  height='15' border='0'   onclick=\"processPrint('content_overflow')\" ><img src='../../images/space.gif' width='93' height='1' border='0'>";
  
  if(document.getElementById("whats_new") || document.getElementById("faq") || document.getElementById("notice") || document.getElementById("service1") || document.getElementById("service2") || document.getElementById("service3") || document.getElementById("service4") || document.getElementById("service5") || document.getElementById("links") || document.getElementById("consultaion") || document.getElementById("news_room")  || document.getElementById("contact_us")  || document.getElementById("sitemap"))
    document.getElementById("print_menu").innerHTML = "<input type='image' src='../images/printer2.png'  height='15' border='0'   onclick=\"processPrint('content_overflow')\" ><img src='../images/space.gif' width='93' height='1' border='0'>";

*/

}




