﻿var pglang;
var imgpath;
var govtlab = "http://www.govtlab.gov.hk/";

// For Interactive Glossary of Chemical Terms search result page
if (location.href.indexOf("_result") != -1) {
  if (location.href.indexOf("e_result") != -1) {
    pglang = "en";
    imgpath = govtlab + "english/engimages/";
  } else if (location.href.indexOf("c_result") != -1) {
    pglang = "tc";
    imgpath = govtlab + "chinese/chiimages/";
  } else if (location.href.indexOf("s_result") != -1) {
    pglang = "sc";
    imgpath = govtlab + "sc/scimages/";
  }
}
// End Interactive Glossary of Chemical Terms

if (location.href.indexOf("/english/") != -1) {
  pglang = "en";
  imgpath = "engimages/";
} else if (location.href.indexOf("/chinese/") != -1) {
  pglang = "tc";
  imgpath = "chiimages/";
} else if (location.href.indexOf("/sc/") != -1) {
  pglang = "sc";
  imgpath = "scimages/";
}

function preload() {
  var a = new Array();
  var gifpath = "";

  for (i = 1; i < 11; i++) a[i] = imgpath + "mainbar" + i.toString() + "_f2.gif";

  // For Interactive Glossary of Chemical Terms search result page
  if (location.href.indexOf("e_result") != -1) {
    gifpath = govtlab + "english/g/";
  } else if (location.href.indexOf("c_result") != -1) {
    gifpath = govtlab + "chinese/g/";
  } else if (location.href.indexOf("s_result") != -1) {
    gifpath = govtlab + "sc/g/";
  } else {
    gifpath = "g/";
  }
  // End Interactive Glossary of Chemical Terms search result page

  a[11] = gifpath + "btn_about2.gif";
  a[12] = gifpath + "btn_access2.gif";
  a[13] = gifpath + "btn_anniver2.gif";
  a[14] = gifpath + "btn_contact2.gif";
  a[15] = gifpath + "btn_enquiry2.gif";
  a[16] = gifpath + "btn_forms2.gif";
  a[17] = gifpath + "btn_glossary2.gif";
  a[18] = gifpath + "btn_home2.gif";
  a[19] = gifpath + "btn_links2.gif";
  a[20] = gifpath + "btn_new2.gif";
  a[21] = gifpath + "btn_openhours2.gif";
  a[22] = gifpath + "btn_photo2.gif";
  a[23] = gifpath + "btn_pt_prog2.gif";
  a[24] = gifpath + "btn_public2.gif";
  a[25] = gifpath + "btn_symposium2.gif";
  a[26] = gifpath + "btn_tele2.gif";
  a[27] = gifpath + "btn_tender2.gif";
  a[28] = gifpath + "btn_test_methods2.gif";
  a[29] = gifpath + "btn_texchange2.gif";
  a[30] = gifpath + "btn_vacan2.gif";
  MM_preloadImages (a[1], a[2], a[3], a[4], a[6], a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], a[18], a[19], a[20], a[21], a[22], a[23], a[24], a[25], a[26], a[27], a[28], a[29], a[30]);
}

function validate(form) {
  if (form.query.value.length == 0) {
    if (location.href.indexOf("/english/") != -1 || location.href.indexOf("e_result") != -1) alert("Please enter keyword");
    if (location.href.indexOf("/chinese/") != -1 || location.href.indexOf("c_result") != -1) alert("請輸入關鍵字");
    if (location.href.indexOf("/sc/") != -1 || location.href.indexOf("s_result") != -1) alert("请输入关键词");
    form.query.focus();
    return false; 
  }
  return true;
}

function pheader() {
  document.write ("<table width='760' border='0' height='87' cellpadding='0' cellspacing='0' background='" + imgpath + "bkgdtexture.gif'>");
  document.write ("<form name='searchform' method='get' action='http://search.gov.hk/search.html' onSubmit='return validate(this);'>");
  document.write ("<input name=ui_lang type=hidden value='");
  switch (pglang) {
    case "en": document.write ("en'>"); break;
    case "tc": document.write ("zh-hk'>"); break;
    case "sc": document.write ("zh-cn'>");
  }
  document.write ("<input type='hidden' name='ui_charset' value='utf-8'>");
  document.write ("<input type='hidden' name='gp0' value='govtlab_home'>");
  document.write ("<input type='hidden' name='gp1' value='govtlab_home'>");
  document.write ("<input type='hidden' name='tpl_id' value='govtlab'>");
  document.write ("<input type='hidden' name='web' value='this'>");

  document.write ("<tr align='left' valign='top'>");
  document.write ("<td height='65' colspan='2' class='sidebar' background='" + imgpath + "bkgdtexture.gif'>");
  document.write ("<a href='http://www.govtlab.gov.hk' target='_top'>");
  document.write ("<img src='" + imgpath + "branding.gif' ");
  switch (pglang) {
    case "en": document.write ("alt='Government Laboratory'"); break;
    case "tc": document.write ("alt='香港政府化驗所'"); break;
    case "sc": document.write ("alt='香港政府化验所'");
  }
  document.write (" width='484' height='65' border='0'></a>");
  document.write ("</td>");
  document.write ("<td height='65' colspan='4' valign='top' background='" + imgpath + "bkgdtexture.gif'>");
  document.write ("<div align='center'>");
  document.write ("<a href='http://www.brandhk.gov.hk/brandhk/' target='_top'>");
  document.write ('<img src="' + imgpath + 'Brandhk.gif" ');
  switch (pglang) {
    case "en": document.write ('alt="Brand Hong Kong - Asia\'s world city"'); break;
    case "tc": document.write ('alt="香港品牌形象 - 亞洲國際都會"'); break;
    case "sc": document.write ('alt="香港品牌形象 - 亚洲国际都会"');
  }
  document.write (' name="brandhk" width="190" height="60" border="0" align="right"></a>');
  document.write ("</div>");
  document.write ("</td>");
  document.write ("</tr>");
  document.write ("<tr align='left' valign='bottom'>");
  document.write ("<td height='19' background='" + imgpath + "bkgdtexture.gif'>");
  document.write ("<span class='header'>");
  switch (pglang) {
    case "en": document.write ("<a href='http://www.gov.hk/en/residents/'>"); break;
    case "tc": document.write ("<a href='http://www.gov.hk/tc/residents/'>"); break;
    case "sc": document.write ("<a href='http://www.gov.hk/sc/residents/'>");
  }
  document.write ("<img src='" + imgpath + "mainbar1.gif' alt='GovHK 香港政府一站通' name='mainbar1' border='0' onMouseOver=MM_swapImage('mainbar1','','" + imgpath + "mainbar1_f2.gif',1) onMouseOut=MM_swapImgRestore()></a>");
  document.write ("<a href='javascript:tran_text();'>");
  document.write ("<img src='" + imgpath + "mainbar2.gif' ");
  switch (pglang) {
    case "en": document.write ("alt='Text only' "); break;
    case "tc": document.write ("alt='繁體純文字' "); break;
    case "sc": document.write ("alt='简体纯文字' ");
  }
  document.write ("name='mainbar2' border='0' onMouseOver=MM_swapImage('mainbar2','','" + imgpath + "mainbar2_f2.gif',1) onMouseOut=MM_swapImgRestore()>");
  document.write ("</a>");
  if (pglang == "tc") {
    document.write ("<a href='javascript:tran_gb();'>");
    document.write ("<img src='" + imgpath + "mainbar3.gif' alt='简体版' ");
  } else {
    document.write ("<a href='javascript:tran_b5();'>");
    document.write ("<img src='" + imgpath + "mainbar3.gif' alt='繁體版' ");
  }
  document.write ("name='mainbar3' border='0' onMouseOver=MM_swapImage('mainbar3','','" + imgpath + "mainbar3_f2.gif',1) onMouseOut=MM_swapImgRestore()>");
  document.write ("</a>");
  if (pglang == "en") {
    document.write ("<a href='javascript:tran_gb();'>");
    document.write ("<img src='" + imgpath + "mainbar4.gif' alt='简体版' ");
  } else {
    document.write ("<a href='javascript:tran_en();'>");
    document.write ("<img src='" + imgpath + "mainbar4.gif' alt='English' ");
  }
  document.write ("name='mainbar4' border='0' onMouseOver=MM_swapImage('mainbar4','','" + imgpath + "mainbar4_f2.gif',1) onMouseOut=MM_swapImgRestore()>");
  document.write ("</a>");
  document.write ("<img src='" + imgpath + "mainbar5.gif' border='0'>");
  document.write ("</span>");
  document.write ("</td>");
  document.write ("<td width='36' height='19' align='right' background='" + imgpath + "bkgdtexture.gif'>");
  document.write ("<input type='image' name='mainbar6' src='" + imgpath + "mainbar6.gif' border='0' ");
  switch (pglang) {
    case "en": document.write ("alt='Search'"); break;
    case "tc": document.write ("alt='搜尋'"); break;
    case "sc": document.write ("alt='搜寻'");
  }
  document.write (" onMouseOut=MM_swapImgRestore() onMouseOver=MM_swapImage('mainbar6','','" + imgpath + "mainbar6_f2.gif',1)>");
  document.write ("</td>");
  document.write ("<td width='80' height='19' valign='top' background='" + imgpath + "bkgdtexture.gif'>");
  document.write ("<input name='query' type='text' size='12'>");
  document.write ("</td>");
  document.write ("<td width='22' height='19' align='left' background='" + imgpath + "bkgdtexture.gif'>");
  document.write ("<input type='image' name='mainbar8' src='" + imgpath + "mainbar8.gif' border='0' ");
  switch (pglang) {
    case "en": document.write ("alt='Search'"); break;
    case "tc": document.write ("alt='搜尋'"); break;
    case "sc": document.write ("alt='搜寻'");
  }
  document.write (" onMouseOut=MM_swapImgRestore() onMouseOver=MM_swapImage('mainbar8','','" + imgpath + "mainbar8_f2.gif',1)>");
  document.write ("</td>");
  document.write ("<td width='67' height='19' align='left' background='" + imgpath + "bkgdtexture.gif'>");
  document.write ("<a href='map.htm' onMouseOut=MM_swapImgRestore() onMouseOver=MM_swapImage('mainbar9','','" + imgpath + "mainbar9_f2.gif',1)>");
  document.write ("<img name='mainbar9' src='" + imgpath + "mainbar9.gif' border='0' ");
  switch (pglang) {
    case "en": document.write ("alt='Site map'>"); break;
    case "tc": document.write ("alt='網頁指南'>"); break;
    case "sc": document.write ("alt='网页指南'>");
  }
  document.write ("</a>");
  document.write ("</td>");
  document.write ("<td width='29' height='19' align='left' background='" + imgpath + "bkgdtexture.gif'>");
  document.write ("<a href='");

  // For Interactive Glossary of Chemical Terms search result page
  if (location.href.indexOf("e_result") != -1) document.write (govtlab + "english/");
  if (location.href.indexOf("c_result") != -1) document.write (govtlab + "chinese/");
  if (location.href.indexOf("s_result") != -1) document.write (govtlab + "sc/");

  document.write ("contact.htm' onMouseOut=MM_swapImgRestore() onMouseOver=MM_swapImage('mainbar10','','" + imgpath + "mainbar10_f2.gif',1)>");
  document.write ("<img name='mainbar10' src='" + imgpath + "mainbar10.gif' border='0' ");
  switch (pglang) {
    case "en": document.write ("alt='Contact us'>"); break;
    case "tc": document.write ("alt='聯絡我們'>"); break;
    case "sc": document.write ("alt='联络我们'>");
  }
  document.write ("</a>");
  document.write ("</td>");
  document.write ("</tr>");
  document.write ("<tr align='left' valign='top' bgcolor='#BB3333'>");
  document.write ("<td height='2' colspan='6'><img src='" + imgpath + "reddot.gif'></td>");
  document.write ("</tr>");
  document.write ("</form>");
  document.write ("</table>");
}

function epfooter() {
  document.write ('<td class="engLastDate">');
  document.write ('2010<sup>&copy;</sup> | <a href="');

  // For Interactive Glossary of Chemical Terms search result page
  if (location.href.indexOf("e_result") != -1) document.write (govtlab + "english/");
  if (location.href.indexOf("c_result") != -1) document.write (govtlab + "chinese/");
  if (location.href.indexOf("s_result") != -1) document.write (govtlab + "sc/");

  document.write ('notice.htm">Important notices</a> | <a href="');

  // For Interactive Glossary of Chemical Terms search result page
  if (location.href.indexOf("e_result") != -1) document.write (govtlab + "english/");
  if (location.href.indexOf("c_result") != -1) document.write (govtlab + "chinese/");
  if (location.href.indexOf("s_result") != -1) document.write (govtlab + "sc/");

  document.write ('privacy.htm">Privacy Policy</a>');
  document.write ('</td>');
  document.write ('<td align="right" class="engLastDate">');
  EngLastUpdate();  // function in lastupdate.js
  document.write ('</td>');
}

function cpfooter() {
  var p = (pglang=='tc')?'私隱政策':'私隐政策';
  document.write ('<td class="chiLastDate">');
  document.write ('2010<sup>&copy;</sup> | <a href="');

  // For Interactive Glossary of Chemical Terms search result page
  if (location.href.indexOf("e_result") != -1) document.write (govtlab + "english/");
  if (location.href.indexOf("c_result") != -1) document.write (govtlab + "chinese/");
  if (location.href.indexOf("s_result") != -1) document.write (govtlab + "sc/");

  document.write ('notice.htm">重要告示</a> | <a href="');

  // For Interactive Glossary of Chemical Terms search result page
  if (location.href.indexOf("e_result") != -1) document.write (govtlab + "english/");
  if (location.href.indexOf("c_result") != -1) document.write (govtlab + "chinese/");
  if (location.href.indexOf("s_result") != -1) document.write (govtlab + "sc/");

  document.write ('privacy.htm">' + p + '</a>');
  document.write ('</td>');
  document.write ('<td align="right" class="chiLastDate">');
  ChiLastUpdate(); // function in lastupdate.js
  document.write ('</td>');
}
