/***************************************************************************
START GENERAL SETUP
****************************************************************************/
function doOnLoad()
{
  theRolloverInit()
  theMenuInit()
  openMenus()
  MM_preloadImages('../images/nav/nav_aboutus_on.gif','../images/nav/nav_our_business_on.gif','../images/nav/nav_media_centre_on.gif','../images/nav/nav_ir_on.gif','../images/nav/nav_career_on.gif')
  trapChi()
}

function lib_bwcheck()
{
  this.ver=navigator.appVersion
  this.agent=navigator.userAgent
  this.dom=document.getElementById?1:0
  this.opera5=this.agent.indexOf("Opera 5")>-1
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
  this.ie8=(this.ver.indexOf("MSIE 8")>-1 && this.dom && !this.opera5)?1:0;
  this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  this.ie=this.ie4||this.ie5||this.ie6 || this.ie7||this.ie8
  this.mac=this.agent.indexOf("Mac")>-1
  this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
  this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 ||this.ie8 || this.ie7)
  return this
}
var bw=new lib_bwcheck()
if (bw.bw) onload = doOnLoad;

//onerror = tellerror
function tellerror(msg, url, linenumber)
{
  alert('Error message= '+msg+'\nURL= '+url+'\nLine Number= '+linenumber)
  return true
}

/***************************************************************************
START MOUSE ROLLOVER+ONCLICK EFFECTS
****************************************************************************/
var gTheRollver // rollover images array

function theRolloverInit()
{
  gTheRollover = new Array()
  gTheRollover[1]  = new makeTheRollover('nav_aboutus','divNav1')
  gTheRollover[2]  = new makeTheRollover('nav_our_business','divNav2')
  gTheRollover[3]  = new makeTheRollover('nav_media_centre','divNav3')
  gTheRollover[4]  = new makeTheRollover('nav_ir','divNav4')
  gTheRollover[5]  = new makeTheRollover('nav_career','divNav5')
}

function MM_findObj(n,d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n);
  return x;
}

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 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 b_roll()
{
  if (this.isOn) this.img.src = '../images/nav/' + this.name + ".gif"
  else this.img.src = '../images/nav/' + this.name + "_on.gif"

  this.isOn = !this.isOn
}

function b_mover(nav)
{
  if (nav) this.img.src = "../images/nav/" + nav + "/" + this.name + "o.jpg"
  else this.img.src = '../images/nav/' + this.name + "_on.gif"
  this.isOn = true
}

function b_mout(nav)
{
  if (nav) this.img.src = "../images/nav/" + nav + "/" + this.name + "s.jpg"
  else this.img.src = '../images/nav/' + this.name + "_off.gif"
  this.isOn = false
}

// create rollover objects
function makeTheRollover(obj,nest)
{
  nest = (!nest) ? "" : 'document.'+nest+'.'
  this.img = bw.dom ? document.getElementById(obj) : bw.ie4 ? document.all[obj] : bw.ns4 ? eval(nest+"document.images." +obj) : 0;
  if (bw.mac && bw.ie) this.img = eval('document.all.'+obj);
  this.roll = b_roll;
  this.mover = b_mover;
  this.mout = b_mout;
  this.isOn = false;
  this.name = obj;
  this.obj = obj + "Object";
  eval(this.obj + "=this")
}

var theCell = ""

function setCell(what)
{
  if (theCell == "")
  {
    gTheRollover[what].mover();
    theCell = what
  }
  else if (theCell == what)
  {
    gTheRollover[theCell].mout();
    theCell = ""
  }
  else
  {
    gTheRollover[theCell].mout();
    theCell = what
    gTheRollover[theCell].mover();
  }
}

function isChosen(what)
{
  if (what == theCell) return true
  else return false
}

/***************************************************************************
START DHTML MENU GENERATION
****************************************************************************/
var gMenuWidth=167                   // width of the menu buttons
var gMenuHeight=19                   // height of the menu buttons
var gMenuLeft=8                      // menus left
var gMenuTop=140                      // menus top
var gScrollSpeed=50                  // the scroll speed of the menu, the smaller value the faster
var gIsScrollLooping=0               // see if the scroll menus is running
var gWhichSubScroll=0                // set which layer to scroll
var gTheMenu                         // stores the menu pointers
var gMenuHeights                     // stores an array of heights of menus

// define menu heights
gMenuHeights = new Array()
gMenuHeights[1] = 100
gMenuHeights[2] = 40
gMenuHeights[3] = 60
gMenuHeights[4] = 204
gMenuHeights[5] = 22

// constructor
function makeTheMenu(obj,nest)
{
  nest = (!nest) ? "" : 'document.'+nest+'.'
  this.css = bw.dom ? document.getElementById(obj).style : bw.ie4 ? document.all[obj].style : bw.ns4 ? eval(nest+"document.layers." +obj) : 0;
  this.evnt = bw.dom ? document.getElementById(obj) : bw.ie4 ? document.all[obj] : bw.ns4 ? eval(nest+"document.layers." +obj) : 0;
  this.scrollHeight = bw.ns4 ? this.css.document.height : this.evnt.offsetHeight
  this.clipHeight = bw.ns4 ? this.css.clip.height : this.evnt.offsetHeight;
  this.up = b_goUp;
  this.down = b_goDown;
  this.moveIt = b_moveIt;
  this.shiftIt = b_shiftIt;
  this.clipTo = b_clipTo;
  this.obj = obj + "Object";
  eval(this.obj + "=this")
}

// function for moving layers
px = bw.ns4 || window.opera ? "" : "px"
function b_moveIt(x,y)
{
  this.x = x;
  this.y = y;
  this.css.left = this.x+px;
  this.css.top = this.y+px;
}

// function to add/subtract a certain amount of pixels from current location
function b_shiftIt(x,y)
{
  //this.moveIt(this.x + x, this.y + y)
  this.css.left = this.x + x
  this.css.top = this.y + y
}

// function for clipping layers
function b_clipTo(t,r,b,l)
{
  if (bw.ns4)
  {
    this.css.clip.top=t;
    this.css.clip.right=r;
    this.css.clip.bottom=b;
    this.css.clip.left=l;
  }
  else this.css.clip="rect("+t+"px "+r+"px "+b+"px "+l+"px)";
}

// menu initialization
function theMenuInit()
{
  gTheMenu = new Array()

  gTheMenu[0] = new Array()
  gTheMenu[0][0] = new makeTheMenu('divNav0')
  gTheMenu[0][0].moveIt(gMenuLeft,gMenuTop);
  gTheMenu[0][0].css.width=gMenuWidth;
  gTheMenu[0][0].css.visibility = "visible"
  gTheMenu[0][0].css.zIndex = 3

  for(i=1;i<=5;i++)
  {
    gTheMenu[i] = new Array()

    gTheMenu[i][0] = new makeTheMenu('divNav'+i)
    gTheMenu[i][0].moveIt(gMenuLeft,gMenuTop+(i*19));
    gTheMenu[i][0].css.width=gMenuWidth;
    gTheMenu[i][0].css.visibility = "visible"
    gTheMenu[i][0].css.zIndex = 3

    gTheMenu[i][1] = new makeTheMenu('divNav'+i+'Bg')
    gTheMenu[i][2] = new makeTheMenu('divNav'+i+'Menu','divNav'+i+'Bg')
    gTheMenu[i][3] = new makeTheMenu('divNav'+i+'MenuA','divNav'+i+'Bg.document.divNav'+i+'Menu')
    gTheMenu[i][4] = new makeTheMenu('divNav'+i+'MenuB','divNav'+i+'Bg.document.divNav'+i+'Menu')

    gTheMenu[i][1].moveIt(gMenuLeft,gMenuTop+((i+1)*19));
    gTheMenu[i][1].css.width=gMenuWidth;
    gTheMenu[i][1].css.height=gMenuHeights[i]
    gTheMenu[i][1].css.visibility = "hidden"
    gTheMenu[i][1].css.zIndex = 2

    gTheMenu[i][2].moveIt(0,0);
    gTheMenu[i][2].css.width=gMenuWidth;
    gTheMenu[i][2].css.height=gMenuHeights[i]

    gTheMenu[i][3].moveIt(20,5)
    gTheMenu[i][3].css.width=gMenuWidth-35;

    gTheMenu[i][4].moveIt(20,5)
    gTheMenu[i][4].css.width=gMenuWidth-35;
    gTheMenu[i][4].css.visibility = "hidden"
  }
}

function b_goUp(move)
{
  if (this.y < 0)
  {
    this.moveIt(this.x,this.y-move)
    if (gIsScrollLooping) setTimeout(this.obj+".up("+move+")",gScrollSpeed)
  }
}

function b_goDown(move)
{
  if (this.y > -this.scrollHeight + 145)
  {
    this.moveIt(this.x,this.y-move)
    if (gIsScrollLooping) setTimeout(this.obj+".down("+move+")",gScrollSpeed)
  }
}

function scroll(theLayer,theSpeed)
{
  gIsScrollLooping = true;
  if (theSpeed>0) gTheMenu[theLayer][gWhichSubScroll].down(theSpeed)
  else gTheMenu[theLayer][gWhichSubScroll].up(theSpeed)
}

function noScroll()
{
  gIsScrollLooping = false
}

// open and close menus
function doMenu(num)
{
  if (theCell != "")
  {
    for (i=theCell+1;i<=5;i++) gTheMenu[i][0].shiftIt(0,0)

    if (theCell != num)
    {
      gTheMenu[theCell][1].css.visibility = "hidden"
      gTheMenu[theCell][1].clipTo(0,gMenuWidth,0,0)
      gTheMenu[num][1].css.visibility = "visible"
      gTheMenu[num][1].clipTo(0,gMenuWidth,gMenuHeights[num],0)
      for (i=num+1;i<=5;i++) gTheMenu[i][0].shiftIt(0,gMenuHeights[num])
    }
    else
    {
      gTheMenu[theCell][1].css.visibility = "hidden"
      gTheMenu[theCell][1].clipTo(0,gMenuWidth,0,0)
    }
  }
  else
  {
    for (i=num+1;i<=5;i++) 
    gTheMenu[i][0].shiftIt(0,gMenuHeights[num])
    gTheMenu[num][1].css.visibility = "visible"
    gTheMenu[num][1].clipTo(0,gMenuWidth,gMenuHeights[num],0)
  }
}

function setSub(num)
{
  gWhichSubScroll = num
}

// function that opens the menus according to which main and sub sections
function openMenus()
{
  // if the menu needs to be opened, do it here
  if (main_section)
  {
    doMenu(main_section)
    setCell(main_section)
  }
}


/***************************************************************************
MENU CUSTOMIZATION
****************************************************************************/
function writeMenu()
{
  document.write('<div id="divNav0" class="cssTheMenu"><img src="../images/nav/nav_background_color.gif" border="0" width=167 height=19></div>')

  document.write('<div id="divNav1" class="cssTheMenu"><a href="#" onclick="doMenu(1); setCell(1); return false;" onMouseOut="if (!isChosen(1)) gTheRollover[1].mout();" onMouseOver="if (!isChosen(1)) gTheRollover[1].mover();" onfocus="if(this.blur)this.blur();"><img id="nav_aboutus" name="nav_aboutus" src="../images/nav/nav_aboutus_off.gif" width="167" height="19" border="0" alt="公司概覽"></a></div>')
  document.write('<div id="divNav2" class="cssTheMenu"><a href="#" onclick="doMenu(2); setCell(2); return false;" onMouseOut="if (!isChosen(2)) gTheRollover[2].mout();" onMouseOver="if (!isChosen(2)) gTheRollover[2].mover();" onfocus="if(this.blur)this.blur();"><img id="nav_our_business" name="nav_our_business" src="../images/nav/nav_our_business_off.gif" width="167" height="19" border="0" alt="企業概況"></a></div>')
  document.write('<div id="divNav3" class="cssTheMenu"><a href="#" onclick="doMenu(3); setCell(3); return false;" onMouseOut="if (!isChosen(3)) gTheRollover[3].mout();" onMouseOver="if (!isChosen(3)) gTheRollover[3].mover();" onfocus="if(this.blur)this.blur();"><img id="nav_media_centre" name="nav_media_centre" src="../images/nav/nav_media_centre_off.gif" width="167" height="19" border="0" alt="傳媒中心"></a></div>')
  document.write('<div id="divNav4" class="cssTheMenu"><a href="#" onclick="doMenu(4); setCell(4); return false;" onMouseOut="if (!isChosen(4)) gTheRollover[4].mout();" onMouseOver="if (!isChosen(4)) gTheRollover[4].mover();" onfocus="if(this.blur)this.blur();"><img id="nav_ir" name="nav_ir" src="../images/nav/nav_ir_off.gif" width="167" height="19" border="0" alt="投資者專欄"></a></div>')
  document.write('<div id="divNav5" class="cssTheMenu"><a href="#" onclick="doMenu(5); setCell(5); return false;" onMouseOut="if (!isChosen(5)) gTheRollover[5].mout();" onMouseOver="if (!isChosen(5)) gTheRollover[5].mover();" onfocus="if(this.blur)this.blur();"><img id="nav_career" name="nav_career" src="../images/nav/nav_career_off.gif" width="167" height="19" border="0" alt="招聘"></a></div>')


  document.write('<div id="divNav1Bg" class="cssTheMenuBg">')
  document.write('<div id="divNav1Menu" class="cssTheMenuTextClip">')
  document.write('<div id="divNav1MenuA" class="cssTheMenuText">')
  document.write('<table border="0" cellpadding="0" cellspacing="0">')
  document.write('<tr>')
  document.write('<td class="normalGrey">')
  for (i=1;i<=gMenuLabels[1][0]*2;i+=2)
  {
    if (main_section == 1 && sub_section == 0 && sub_item*2-1 == i) document.write('<img src="../images/nav/section_point_on.gif" border="0"><img src="../images/space.gif" border="0" width="7" height="1"><span class="nav_selected">' + gMenuLabels[1][i] + '</span><br><img src="../images/space.gif" border="0" width="1" height="4"><BR>')
    else document.write('<img src="../images/nav/section_point_off.gif" border="0"><img src="../images/space.gif" border="0" width="7" height="1"><a href="' + gMenuLabels[1][i+1] + '" class="normalGrey">' + gMenuLabels[1][i] + '</a><br><img src="../images/space.gif" border="0" width="1" height="4"><BR>')
  }
  document.write('</td>')
  document.write('</tr>')
  document.write('</table>')
  document.write('</div>')
  document.write('<div id="divNav1MenuB" class="cssTheMenuText"></div>')
  document.write('</div>')
  document.write('</div>')


  document.write('<div id="divNav2Bg" class="cssTheMenuBg">')
  document.write('<div id="divNav2Menu" class="cssTheMenuTextClip">')
  document.write('<div id="divNav2MenuA" class="cssTheMenuText">')
  document.write('<table border="0" cellpadding="0" cellspacing="0">')
  document.write('<tr>')
  document.write('<td class="normalGrey">')
  for (i=1;i<=gMenuLabels[2][0]*2;i+=2)
  {
    if (main_section == 2 && sub_section == 0 && sub_item*2-1 == i) document.write('<img src="../images/nav/section_point_on.gif" border="0"><img src="../images/space.gif" border="0" width="7" height="1"><span class="nav_selected">' + gMenuLabels[2][i] + '</span><br><img src="../images/space.gif" border="0" width="1" height="4"><BR>')
    else document.write('<img src="../images/nav/section_point_off.gif" border="0"><img src="../images/space.gif" border="0" width="7" height="1"><a href="' + gMenuLabels[2][i+1] + '" class="normalGrey">' + gMenuLabels[2][i] + '</a><br><img src="../images/space.gif" border="0" width="1" height="4"><BR>')
  }
  document.write('</td>')
  document.write('</tr>')
  document.write('</table>')
  document.write('</div>')
  document.write('<div id="divNav2MenuB" class="cssTheMenuText"></div>')
  document.write('</div>')
  document.write('</div>')


  document.write('<div id="divNav3Bg" class="cssTheMenuBg">')
  document.write('<div id="divNav3Menu" class="cssTheMenuTextClip">')
  document.write('<div id="divNav3MenuA" class="cssTheMenuText">')
  document.write('<table border="0" cellpadding="0" cellspacing="0">')
  document.write('<tr>')
  document.write('<td class="normalGrey">')
  for (i=1;i<=gMenuLabels[3][0]*2;i+=2)
  {
    if (main_section == 3 && sub_section == 0 && sub_item*2-1 == i) document.write('<img src="../images/nav/section_point_on.gif" border="0"><img src="../images/space.gif" border="0" width="7" height="1"><span class="nav_selected">' + gMenuLabels[3][i] + '</span><br><img src="../images/space.gif" border="0" width="1" height="4"><BR>')
    else document.write('<img src="../images/nav/section_point_off.gif" border="0"><img src="../images/space.gif" border="0" width="7" height="1"><a href="' + gMenuLabels[3][i+1] + '" class="normalGrey">' + gMenuLabels[3][i] + '</a><br><img src="../images/space.gif" border="0" width="1" height="4"><BR>')
  }
  document.write('</td>')
  document.write('</tr>')
  document.write('</table>')
  document.write('</div>')
  document.write('<div id="divNav3MenuB" class="cssTheMenuText"></div>')
  document.write('</div>')
  document.write('</div>')


  document.write('<div id="divNav4Bg" class="cssTheMenuBg">')
  document.write('<div id="divNav4Menu" class="cssTheMenuTextClip">')
  document.write('<div id="divNav4MenuA" class="cssTheMenuText">')
  document.write('<table border="0" cellpadding="0" cellspacing="0">')
  document.write('<tr>')
  document.write('<td class="normalGrey">')
  for (i=1;i<=gMenuLabels[4][0]*2;i+=2)
  {
    if (main_section == 4 && sub_section == 0 && sub_item*2-1 == i) document.write('<img src="../images/nav/section_point_on.gif" border="0"><img src="../images/space.gif" border="0" width="7" height="1"><span class="nav_selected">' + gMenuLabels[4][i] + '</span><br><img src="../images/space.gif" border="0" width="1" height="4"><BR>')
    else document.write('<img src="../images/nav/section_point_off.gif" border="0"><img src="../images/space.gif" border="0" width="7" height="1"><a href="' + gMenuLabels[4][i+1] + '" class="normalGrey">' + gMenuLabels[4][i] + '</a><br><img src="../images/space.gif" border="0" width="1" height="4"><BR>')
  }
  document.write('</td>')
  document.write('</tr>')
  document.write('</table>')
  document.write('</div>')
  document.write('<div id="divNav4MenuB" class="cssTheMenuText"></div>')
  document.write('</div>')
  document.write('</div>')


  document.write('<div id="divNav5Bg" class="cssTheMenuBg">')
  document.write('<div id="divNav5Menu" class="cssTheMenuTextClip">')
  document.write('<div id="divNav5MenuA" class="cssTheMenuText">')
  document.write('<table border="0" cellpadding="0" cellspacing="0">')
  document.write('<tr>')
  document.write('<td class="normalGrey">')
  for (i=1;i<=gMenuLabels[5][0]*2;i+=2)
  {
    if (main_section == 5 && sub_section == 0 && sub_item*2-1 == i) document.write('<img src="../images/nav/section_point_on.gif" border="0"><img src="../images/space.gif" border="0" width="7" height="1"><span class="nav_selected">' + gMenuLabels[5][i] + '</span><br><img src="../images/space.gif" border="0" width="1" height="4"><BR>')
    else document.write('<img src="../images/nav/section_point_off.gif" border="0"><img src="../images/space.gif" border="0" width="7" height="1"><a href="' + gMenuLabels[5][i+1] + '" class="normalGrey">' + gMenuLabels[5][i] + '</a><br><img src="../images/space.gif" border="0" width="1" height="4"><BR>')
  }
  document.write('</td>')
  document.write('</tr>')
  document.write('</table>')
  document.write('</div>')
  document.write('<div id="divNav5MenuB" class="cssTheMenuText"></div>')
  document.write('</div>')
  document.write('</div>')
}
