﻿function E$(i) { return document.getElementById(i); }

function loadXMLDoc(fname)
{
  var xmlDoc;
  // code for IE
  //alert("loadxmldoc_phrase1");
  if (window.ActiveXObject)
  {
    //alert("loadxmldoc_phrase2");
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async=false;
    xmlDoc.load(fname);
  }
  // code for Mozilla, Firefox, Opera, etc.
  else 
  {
    if (document.implementation && document.implementation.createDocument)
    {
      //alert("loadxmldoc_phrase3");
      //xmlDoc=document.implementation.createDocument("","",null);
      var xmlhttp = new window.XMLHttpRequest();
      xmlhttp.open("GET",fname,false);
      xmlhttp.send(null);
      xmlDoc = xmlhttp.responseXML.documentElement;
      xmlDoc.async=false;
    }
    else
    {
      //alert("loadxmldoc_phrase4");
      alert('Your browser cannot handle this script');
    }
  }
  //alert("loadxmldoc_phrase5");
  return(xmlDoc);
}

function apply_xslxml(htmlid,xmlfile,xslfile)
{
  //alert("phrase1");
  
  xml=loadXMLDoc(xmlfile);
  //alert("phrase1a");
  xsl=loadXMLDoc(xslfile);
  //alert("phrase1b");

  // code for IE
  if (window.ActiveXObject)
  {
    //alert("phrase2");
    ex=xml.transformNode(xsl);
    var obj = document.getElementById(htmlid);
    if (obj!=null) obj.innerHTML=ex;
  }
  else 
  {
    // code for Mozilla, Firefox, Opera, etc.
    if (document.implementation && document.implementation.createDocument)
    {
      //alert("phrase3");
      xsltProcessor=new XSLTProcessor();
      xsltProcessor.importStylesheet(xsl);
      resultDocument = xsltProcessor.transformToFragment(xml,document);
      document.getElementById(htmlid).innerHTML="";
      document.getElementById(htmlid).appendChild(resultDocument);
    }
    else
    {
      //alert("phrase4");
    }
  }
}

function switch_lang(fromlang,tolang)
{
  var url = window.location.toString().substr(0);
  var tourl = url.replace("\/"+fromlang+"\/","\/"+tolang+"\/");
  window.location = tourl;
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return "";
}


function WriteFlash(SWFfile, flashvar, width, height)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">');
    document.write('<param name="movie" value="'+SWFfile+'">');
    document.write('<param name="FlashVars" value="'+flashvar+'">');
    document.write('<param name="quality" value="high">');
    document.write('<param name="WMode" value="transparent">');
    document.write('<embed src="'+SWFfile+'" name="FlashVars" FlashVars="'+flashvar+'" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>');
    document.write('</object>');
}


//top-dropdown-menu
/*
 * DO NOT REMOVE THIS NOTICE
 *
 * PROJECT:   MyGosuMenu
 * VERSION:   1.5.5
 * COPYRIGHT: (c) 2003-2009 Cezary Tomczak
 * LINK:      http://www.gosu.pl/MyGosuMenu/
 * LICENSE:   BSD revised (free for any use)
 */

/*
  Todo, bugs to fix:
  - delay.show = 400 , delay.hide = 400
    go Product Three -> Live Demo -> Test Drive -> Test Three , go fast to Product Four.
    Result: 2 elements highlighted in the same section
  - delay.show = 0 , delay.hide = 400
    go Product Three -> Live Demo , section out , section over, seciont out.
    Result: Live Demo is not highlighted
  - active className changing, unnecessary blink
  - opera: hideSection() exceptions are throwed
*/

function DropMenuX(id) {

    /* Type of the menu: "horizontal" or "vertical" */
    this.type = "horizontal";

    /* Delay (in miliseconds >= 0): show-hide menu
     * Hide must be > 0 */
    this.delay = {
        "show": 0,
        "hide": 400
    }
    /* Change the default position of sub-menu by Y pixels from top and X pixels from left
     * Negative values are allowed */
    this.position = {
        "level1": { "top": 0, "left": 0},
        "levelX": { "top": 0, "left": 0}
    }

    /* fix ie selectbox bug ? */
    this.fixIeSelectBoxBug = true;

    /* Z-index property for .section */
    this.zIndex = {
        "visible": 500,
        "hidden": -1
    };

    // Browser detection
    this.browser = {
        "ie": Boolean(document.body.currentStyle),
        "ie5": (navigator.appVersion.indexOf("MSIE 5.5") != -1 || navigator.appVersion.indexOf("MSIE 5.0") != -1),
        "ie6": (navigator.appVersion.indexOf("MSIE 6.0") != -1)
    };

    if (!this.browser.ie) {
        this.browser.ie5 = false;
        this.browser.ie6 = false;
    }

    /* Initialize the menu */
    this.init = function() {
        if (!document.getElementById(this.id)) { return alert("DropMenuX.init() failed. Element '"+ this.id +"' does not exist."); }
        if (this.type != "horizontal" && this.type != "vertical") { return alert("DropMenuX.init() failed. Unknown menu type: '"+this.type+"'"); }
        if (this.browser.ie && this.browser.ie5) { fixWrap(); }
        fixSections();
        parse(document.getElementById(this.id).childNodes, this.tree, this.id);
    }

    /* Search for .section elements and set width for them */
    function fixSections() {
        var arr = document.getElementById(self.id).getElementsByTagName("div");
        var sections = new Array();
        var widths = new Array();

        for (var i = 0; i < arr.length; i++) {
            if (arr[i].className == "section") {
                sections.push(arr[i]);
            }
        }
        for (var i = 0; i < sections.length; i++) {
            widths.push(getMaxWidth(sections[i].childNodes));
        }
        for (var i = 0; i < sections.length; i++) {
            sections[i].style.width = (widths[i]) + "px";
        }
        if (self.browser.ie) {
            for (var i = 0; i < sections.length; i++) {
                setMaxWidth(sections[i].childNodes, widths[i]);
            }
        }
    }

    function fixWrap() {
        var elements = document.getElementById(self.id).getElementsByTagName("a");
        for (var i = 0; i < elements.length; i++) {
            if (/item2/.test(elements[i].className)) {
                elements[i].innerHTML = '<div nowrap="nowrap">'+elements[i].innerHTML+'</div>';
            }
        }
    }

    /* Search for an element with highest width among given nodes, return that width */
    function getMaxWidth(nodes) {
        var maxWidth = 0;
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType != 1 || /section/.test(nodes[i].className)) { continue; }
            if (nodes[i].offsetWidth > maxWidth) { maxWidth = nodes[i].offsetWidth; }
        }
        return maxWidth;
    }

    /* Set width for item2 elements */
    function setMaxWidth(nodes, maxWidth) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType == 1 && /item2/.test(nodes[i].className) && nodes[i].currentStyle) {
                if (self.browser.ie5) {
                    nodes[i].style.width = (maxWidth) + "px";
                } else {
                    nodes[i].style.width = (maxWidth - parseInt(nodes[i].currentStyle.paddingLeft) - parseInt(nodes[i].currentStyle.paddingRight)) + "px";
                }
            }
        }
    }

    /* Parse nodes, create events, position elements */
    function parse(nodes, tree, id) {
        for (var i = 0; i < nodes.length; i++) {
            if (1 != nodes[i].nodeType) {
                continue;
            }
            switch (true) {
                // .item1
                case /\bitem1\b/.test(nodes[i].className):
                    nodes[i].id = id + "-" + tree.length;
                    tree.push(new Array());
                    nodes[i].onmouseover = itemOver;
                    nodes[i].onmouseout = itemOut;
                    break;
                // .item2
                case /\bitem2\b/.test(nodes[i].className):
                    nodes[i].id = id + "-" + tree.length;
                    tree.push(new Array());
                    nodes[i].onmouseover = itemOver;
                    nodes[i].onmouseout = itemOut;
                    break;
                // .section
                case /\bsection\b/.test(nodes[i].className):
                    // id, events
                    nodes[i].id = id + "-" + (tree.length - 1) + "-section";
                    nodes[i].onmouseover = sectionOver;
                    nodes[i].onmouseout = sectionOut;
                    // position
                    var box1 = document.getElementById(id + "-" + (tree.length - 1));
                    var box2 = document.getElementById(nodes[i].id);
                    var el = new Element(box1.id);
                    if (1 == el.level) {
                        if ("horizontal" == self.type) {
                            box2.style.top = box1.offsetTop + box1.offsetHeight + self.position.level1.top + "px";
                            if (self.browser.ie5) {
                                box2.style.left = self.position.level1.left + "px";
                            } else {
                                box2.style.left = box1.offsetLeft + self.position.level1.left + "px";
                            }
                        } else if ("vertical" == self.type) {
                            box2.style.top = box1.offsetTop + self.position.level1.top + "px";
                            if (self.browser.ie5) {
                                box2.style.left = box1.offsetWidth + self.position.level1.left + "px";
                            } else {
                                box2.style.left = box1.offsetLeft + box1.offsetWidth + self.position.level1.left + "px";
                            }
                        }
                    } else {
                        box2.style.top = box1.offsetTop + self.position.levelX.top + "px";
                        box2.style.left = box1.offsetLeft + box1.offsetWidth + self.position.levelX.left + "px";
                    }
                    // sections, sectionsShowCnt, sectionsHideCnt
                    self.sections.push(nodes[i].id);
                    self.sectionsShowCnt.push(0);
                    self.sectionsHideCnt.push(0);
                    if (self.fixIeSelectBoxBug && self.browser.ie6) {
                        nodes[i].innerHTML = nodes[i].innerHTML + '<iframe id="'+nodes[i].id+'-iframe" src="javascript:false;" scrolling="no" frameborder="0" style="position: absolute; top: 0px; left: 0px; display: none; filter:alpha(opacity=0);"></iframe>';
                    }
                    break;
            }
            if (nodes[i].childNodes) {
                if (/\bsection\b/.test(nodes[i].className)) {
                    parse(nodes[i].childNodes, tree[tree.length - 1], id + "-" + (tree.length - 1));
                } else {
                    parse(nodes[i].childNodes, tree, id);
                }
            }
        }
    }

    /* event, item:onmouseover */
    function itemOver() {
        //debug("itemOver("+this.id+") , visible = " + self.visible);
        self.itemShowCnt++;
        var id_section = this.id + "-section";
        if (self.visible.length) {
            var el = new Element(self.visible.getLast());
            el = document.getElementById(el.getParent().id);
            if (/item\d-active/.test(el.className)) {
                el.className = el.className.replace(/(item\d)-active/, "$1");
            }
        }
        if (self.sections.contains(id_section)) {
            clearTimers();
            self.sectionsHideCnt[self.sections.indexOf(id_section)]++;
            var cnt = self.sectionsShowCnt[self.sections.indexOf(id_section)];
            var timerId = setTimeout(function(a, b) { return function() { self.showSection(a, b); } } (id_section, cnt), self.delay.show);
            self.timers.push(timerId);
        } else {
            if (self.visible.length) {
                clearTimers();
                var timerId = setTimeout(function(a, b) { return function() { self.showItem(a, b); } } (this.id, self.itemShowCnt), self.delay.show);
                self.timers.push(timerId);
            }
        }
    }

    /* event, item:onmouseout */
    function itemOut() {
        //debug("itemOut("+this.id+") , visible = " + self.visible);
        self.itemShowCnt++;
        var id_section = this.id + "-section";
        if (self.sections.contains(id_section)) {
            self.sectionsShowCnt[self.sections.indexOf(id_section)]++;
            if (self.visible.contains(id_section)) {
                var cnt = self.sectionsHideCnt[self.sections.indexOf(id_section)];
                var timerId = setTimeout(function(a, b) { return function() { self.hideSection(a, b); } }(id_section, cnt), self.delay.hide);
                self.timers.push(timerId);
            }
        }
    }

    /* event, section:onmouseover */
    function sectionOver() {
        //debug("sectionOver("+this.id+") , visible = " + self.visible);
        self.sectionsHideCnt[self.sections.indexOf(this.id)]++;
        var el = new Element(this.id);
        var parent = document.getElementById(el.getParent().id);
        if (!/item\d-active/.test(parent.className)) {
            parent.className = parent.className.replace(/(item\d)/, "$1-active");
        }
    }

    /* event, section:onmouseout */
    function sectionOut() {
        //debug("sectionOut("+this.id+") , visible = " + self.visible);
        self.sectionsShowCnt[self.sections.indexOf(this.id)]++;
        var cnt = self.sectionsHideCnt[self.sections.indexOf(this.id)];
        var timerId = setTimeout(function(a, b) { return function() { self.hideSection(a, b); } }(this.id, cnt), self.delay.hide);
        self.timers.push(timerId);
    }

    /* Show section (1 argument passed)
     * Try to show section (2 arguments passed) - check cnt with sectionShowCnt */
    this.showSection = function(id, cnt) {
        if (typeof cnt != "undefined") {
            if (cnt != this.sectionsShowCnt[this.sections.indexOf(id)]) { return; }
        }
        //debug("showSection("+id+", "+cnt+") , visible = " + this.visible);
        this.sectionsShowCnt[this.sections.indexOf(id)]++;
        if (this.visible.length) {
            if (id == this.visible.getLast()) { return; }
            var el = new Element(id);
            var parents = el.getParentSections();
            //debug("getParentSections("+el.id+") = " + parents);
            for (var i = this.visible.length - 1; i >= 0; i--) {
                if (parents.contains(this.visible[i])) {
                    break;
                } else {
                    this.hideSection(this.visible[i]);
                }
            }
        }
        var el = new Element(id);
        var parent = document.getElementById(el.getParent().id);
        if (!/item\d-active/.test(parent.className)) {
            parent.className = parent.className.replace(/(item\d)/, "$1-active");
        }
        if (document.all) { document.getElementById(id).style.display = "block"; }
        document.getElementById(id).style.visibility = "visible";
        document.getElementById(id).style.zIndex = this.zIndex.visible;
        if (this.fixIeSelectBoxBug && this.browser.ie6) {
            var div = document.getElementById(id);
            var iframe = document.getElementById(id+"-iframe");
            iframe.style.width = div.offsetWidth + parseInt(div.currentStyle.borderLeftWidth) + parseInt(div.currentStyle.borderRightWidth);
            iframe.style.height = div.offsetHeight + parseInt(div.currentStyle.borderTopWidth) + parseInt(div.currentStyle.borderBottomWidth);
            iframe.style.top = -parseInt(div.currentStyle.borderTopWidth);
            iframe.style.left = -parseInt(div.currentStyle.borderLeftWidth);
            iframe.style.zIndex = div.style.zIndex - 1;
            iframe.style.display = "block";
        }
        this.visible.push(id);
    }

    /* Emulating an empty non-existent section, we have to hide elements, works like showSection() */
    this.showItem = function(id, cnt) {
        if (typeof cnt != "undefined") {
            if (cnt != this.itemShowCnt) { return; }
        }
        this.itemShowCnt++;
        if (this.visible.length) {
            var el = new Element(id + "-section");
            var parents = el.getParentSections();
            //debug("showItem() getParentSections("+el.id+") = " + parents);
            for (var i = this.visible.length - 1; i >= 0; i--) {
                if (parents.contains(this.visible[i])) {
                    break;
                } else {
                    this.hideSection(this.visible[i]);
                }
            }
        }
    }

    /* Hide section (1 argument passed)
     * Try to hide section (2 arguments passed) - check cnt with sectionHideCnt */
    this.hideSection = function(id, cnt) {
        if (typeof cnt != "undefined") {
            if (cnt != this.sectionsHideCnt[this.sections.indexOf(id)]) { return; }
            if (id == this.visible.getLast()) {
                //debug("hideSectionAll("+id+", "+cnt+") , visible = " + this.visible);
                for (var i = this.visible.length - 1; i >= 0; i--) {
                    this.hideSection(this.visible[i]);
                }
                return;
            }
        }
        //debug("hideSection("+id+", "+cnt+") , visible = " + this.visible);
        var el = new Element(id);
        var parent = document.getElementById(el.getParent().id);
        if (/item\d-active/.test(parent.className)) {
            parent.className = parent.className.replace(/(item\d)-active/, "$1");
        }
        document.getElementById(id).style.zIndex = this.zIndex.hidden;
        document.getElementById(id).style.visibility = "hidden";
        if (document.all) { document.getElementById(id).style.display = "none"; }
        if (this.fixIeSelectBoxBug && this.browser.ie6) {
            var iframe = document.getElementById(id+"-iframe");
            iframe.style.display = "none";
        }
        if (this.visible.contains(id)) {
            if (id == this.visible.getLast()) {
                this.visible.pop();
            } else {
                //throw "DropMenuX.hideSection('"+id+"', "+cnt+") failed, trying to hide a section that is not the deepest visible section";
                return;
            }
        } else {
            //throw "DropMenuX.hideSection('"+id+"', "+cnt+") failed, cannot hide element that is not visible";
            return;
        }
        this.sectionsHideCnt[this.sections.indexOf(id)]++;
    }

    /* Element (.section, .item2 etc) */
    function Element(id) {

        this.menu = self;
        this.id = id;

        /* Get Level of given id
         * Examples: menu-1 (1 level), menu-1-4 (2 level) */
        this.getLevel = function() {
            var s = this.id.substr(this.menu.id.length);
            return s.substrCount("-");
        }

        /* Get parent Element */
        this.getParent = function() {
            var s = this.id.substr(this.menu.id.length);
            var a = s.split("-");
            a.pop();
            return new Element(this.menu.id + a.join("-"));
        }

        /* Check whether an element has a parent element */
        this.hasParent = function() {
            var s = this.id.substr(this.menu.id.length);
            var a = s.split("-");
            return a.length > 2;
        }

        /* Check whether an element has a sub-section */
        this.hasChilds = function() {
            return Boolean(document.getElementById(this.id + "-section"));
        }

        /* Get parent section elements for current section */
        this.getParentSections = function() {
            var s = this.id.substr(this.menu.id.length);
            s = s.substr(0, s.length - "-section".length);
            var a = s.split("-");
            a.shift();
            a.pop();
            var s = this.menu.id;
            var parents = [];
            for (var i = 0; i < a.length; i++) {
                s += ("-" + a[i]);
                parents.push(s + "-section");
            }
            return parents;
        }

        this.level = this.getLevel();
    }

    /* Clear all timers set with setTimeout() */
    function clearTimers() {
        for (var i = self.timers.length - 1; i >= 0; i--) {
            clearTimeout(self.timers[i]);
            self.timers.pop();
        }
    }

    var self = this;
    this.id = id; /* menu id */
    this.tree = []; /* tree structure of menu */
    this.sections = []; /* all sections, required for timeout */
    this.sectionsShowCnt = [];
    this.sectionsHideCnt = [];
    this.itemShowCnt = 0;
    this.timers = []; // timeout ids
    this.visible = []; /* visible section, ex. Array("menu-0-section", ..) , succession is important: top to bottom */
}

/* Finds the index of the first occurence of item in the array, or -1 if not found */
if (typeof Array.prototype.indexOf == "undefined") {
    Array.prototype.indexOf = function(item) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === item) {
                return i;
            }
        }
        return -1;
    }
}

/* Check whether array contains given string */
if (typeof Array.prototype.contains == "undefined") {
    Array.prototype.contains = function(s) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === s) {
                return true;
            }
        }
        return false;
    }
}

/* Counts the number of substring occurrences */
if (typeof String.prototype.substrCount == "undefined") {
    String.prototype.substrCount = function(s) {
        return this.split(s).length - 1;
    }
}

/* Get the last element from the array */
if (typeof Array.prototype.getLast == "undefined") {
    Array.prototype.getLast = function() {
        return this[this.length-1];
    }
}

//end-of-menu

//footer-flyout-menu
//Source from: http://www.leigeber.com/
var DDSPEED = 10;
var DDTIMER = 15;
var OFFSET = -2;
var ZINT = 100;

function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    c.style.display = 'block';
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.left = (h.offsetWidth + OFFSET) + 'px';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    ZINT = ZINT + 1;
    c.style.zIndex = ZINT;
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = Math.round((c.maxh - currh) / DDSPEED);
  }else{
    dist = Math.round(currh / DDSPEED);
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if(currh > (c.maxh - 2) && d == 1){
    clearInterval(c.timer);
  }else if(dist < 1 && d != 1){
    clearInterval(c.timer);
    c.style.display = 'none';
  }
}
//end-of-menu

//tabs
function loadtab(holderid,contentid,tabdiv)
{
  if (true)
  {
    var holder = document.getElementById(holderid);
    var content = document.getElementById(contentid);
    holder.innerHTML = content.innerHTML;
    
    switch (tabdiv.id)
    {
        case "block2tab1":
            tabdiv.className="selected_ticket_tab1";
            break;
        case "block2tab2":            
            tabdiv.className="selected_ticket_tab2";
            break;            
        case "block2tab3":
            tabdiv.className="selected_ticket_tab3";
            break;            
        case "block2tab4":
            tabdiv.className="selected_ticket_tab4";
            break;            
        case "block2tab5":
            tabdiv.className="selected_ticket_tab5";
            break;            
        default:     
            tabdiv.className="selectedtab";
            break;
    }
    var sib = tabdiv.nextSibling;
    while (sib!=null)
    {
      sib.className="tab";
      sib = sib.nextSibling;
    }
    sib = tabdiv.previousSibling;
    while (sib!=null)
    {
      sib.className="tab";
      sib = sib.previousSibling;
    }
  }
}

//ticketing specific

function track_ticket_booklet()
{
    pageTracker._trackPageview('/downloads/ticketing_booklet.pdf');
}

function track_startTime()
{
    pageTracker._trackPageview('/downloads/GameSchedule_StartTime.pdf');
}

function track_comp_prices()
{
    pageTracker._trackPageview('/downloads/competition_details_and_ticket_prices.pdf');
}

function track_hkticket()
{
    pageTracker._trackPageview('/outgoing/www.hkticketing.com');
}

function mouseovertab(tabdiv)
{
   /* if (tabdiv.className!="selectedtab")
    tabdiv.className="ontab"; */
    //alert(tabdiv.id+" : "+tabdiv.className+" : "+tabdiv.className.indexOf("selected"));
    if (tabdiv.className.indexOf("selected")<0)
    {
        switch (tabdiv.id)
        {
            case "block2tab1":
                tabdiv.className="on_ticket_tab1";
                break;
            case "block2tab2":
                tabdiv.className="on_ticket_tab2";
                break;            
            case "block2tab3":
                tabdiv.className="on_ticket_tab3";
                break;            
            case "block2tab4":
                tabdiv.className="on_ticket_tab4";
                break;            
            case "block2tab5":
                tabdiv.className="on_ticket_tab5";
                break;            
            default:     
                tabdiv.className="ontab";
                break;
        }    
    }
}

function mouseouttab(tabdiv)
{
  if (tabdiv.className.indexOf("selected")!==0)
    tabdiv.className="tab";
}
//end-of-menu

//scrolling partner banners

var scrollspeed = 70;
function scrollpartners()
{
  var length = 1401; //117*11+114*1
  var step = 3;

  var frontbox = document.getElementById('partner_front');
  var endbox = document.getElementById('partner_end');
 
  var fl;
  var el;
  if (frontbox.style.left=='') fl = 0;
  else fl = parseInt(frontbox.style.left);
  if (endbox.style.left=='') el = length;
  else el = parseInt(endbox.style.left);

  fl = fl -step;
  el = el -step;
  if (fl<=-1*length) fl = length;
  if (el<=-1*length) el = length;
  frontbox.style.left = fl+"px";
  endbox.style.left = el+"px";

  setTimeout('scrollpartners()',scrollspeed);
}

//post-loading generic
var dmx;
function postload()
{
  dmx = new DropMenuX('menu1');
  dmx.delay.show = 0;
  dmx.delay.hide = 400;
  dmx.position.levelX.left = 2;
  dmx.init();  

  setmedaltable();
  if (E$("countdown_st")!=null) {
    setcountdown();
    setInterval("setcountdown()",60000);
  }
  setrbanner1();
  //scroll partners
  setTimeout('scrollpartners()',scrollspeed);
  
}

//right banner random images
var rbanner1=new Array();
rbanner1[0]="images/banner_ticketing_01.gif";
rbanner1[1]="images/banner_ticketing_02.gif";
rbanner1[2]="images/banner_ticketing_03.gif";

function setrbanner1()
{
    var r=Math.floor(Math.random()*3);
    var img = document.getElementById('rbannerimg1');
    var link = document.getElementById('rbannerlink1');
    if (img!=null && link!=null)
    {
        img.src=link_prefix+rbanner1[r];
        link.href=link_prefix+"participation/ticketing.html";
    }
}


// index flash pictures
var interval = 3000;
var timeoutInterval;
var curIDX = 0;
var imgArr=new Array();
imgArr[0]="/images/highlight_1.jpg";
imgArr[1]="/images/highlight_2.jpg";
imgArr[2]="/images/highlight_3.jpg";
imgArr[3]="/images/highlight_4.jpg";
imgArr[4]="/images/highlight_5.jpg";
imgArr[5]="/images/highlight_6.jpg";
imgArr[6]="/images/highlight_7.jpg";
imgArr[7]="/images/highlight_8.jpg";
var maxIDX = imgArr.length;

function ImageRotator() 
{
    if (curIDX == maxIDX)
    {
        curIDX = 0;
    }
    
    document.getElementById("flash_pic").style.marginTop = "0px";
    document.getElementById("flash_pic").src = imgArr[curIDX];
    
    document.getElementById("highlight_ovals").innerHTML = "";
    for (var i=0; i < maxIDX; i++)
    {
        if (i == curIDX)
        {
            document.getElementById("highlight_ovals").innerHTML += "<img src='/images/oval_on.gif' class='oval' />";
        }
        else
        {
            document.getElementById("highlight_ovals").innerHTML += "<a href='javascript:Goto("+i+")'><img src='/images/oval_off.gif' class='oval' border='0' /></a>";
        }
    }
    curIDX++;
    timeoutInterval = setTimeout("ImageRotator()", interval);
}

function Goto(myIDX)
{
    curIDX = myIDX;
    clearTimeout(timeoutInterval);
    ImageRotator(); 
}

//countclock popup

function clockPopup() {
    window.open("/en/countdown.php","countDownClock","width=600,height=480,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes");
}

function clockPopup_tc() {
    window.open("/tc/countdown.php","countDownClock","width=600,height=480,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes");
}

function clockPopup_sc() {
    window.open("/sc/countdown.php","countDownClock","width=600,height=480,directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes");
}

//share in facebook
function fbs_click() {
    u=location.href;
    t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}

//ajax
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try { // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest(); }
  catch (e) { // Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  }
  return xmlHttp;
}

function stateChanged(ajaxelement, xmlhttp) 
{ 
  if (xmlhttp.readyState==4)
  {
    ajaxelement.innerHTML=xmlhttp.responseText;
    if (ajaxelement.id == "info_tab_content")
    {
        scroller.init(); correctPNG();
    }
  }
}
function ajax_loadcontent(contentdivid,contentfile)
{
  var xmlhttp=GetXmlHttpObject();
  var ajaxelement = document.getElementById(contentdivid);  ajaxelement.innerHTML = "";
  xmlhttp.onreadystatechange=function() { stateChanged(ajaxelement,xmlhttp); }
  xmlhttp.open("GET",contentfile,true);
  xmlhttp.send(null);
}

//end-of-ajax

//right medal table
function setmedaltable()
{
  if (E$("master_medal")!=null) {
	  apply_xslxml('master_medal','/upload/medalTally/xml'+link_prefix+'medalTally.xml','/xsl/medal.xsl');
  }
}

//calculate and set countdown statement
function setcountdown()
{
  if (E$("countdown_st")!=null) {
    var myDate = new Date(); 
    var m = myDate.getUTCMonth()+1;
    var d = myDate.getUTCDate();
    var u = myDate.getUTCMinutes();
    var s = myDate.getUTCSeconds();
    var h = myDate.getUTCHours();
    
    if (m!=12 || d>5 || (m==12 && d==5 && h>12) || (m==12 && d==5 && h==12 && u>0))
    {
        //alert('m='+m+',d='+d+',h='+h+',u='+u);
        E$("countdown_st").style.display="none";
    }    
    else {
        var cday = 5-d;
        var ch; var cm;
        if (h>=12) { cday--; ch = 24-(h-12);}
        else { ch=12-h;}
        if (u>0) { ch--; cm = 60-u; } else {cm=0;}
        //alert(cday+'day '+ch+'hour '+cm+' min');
        //E$("countdown_st").innerHTML
        var st;
        switch (link_prefix) {
            case "/tc/": st = "距離東亞運動會開幕尚有X天H小時M分鐘"; break;
            case "/sc/": st = "距离东亚运动会开幕尚有X天H小时M分钟"; break;
            default: st = "X day(s) H hour(s) M min(s) countdown to the Opening Ceremony on 5 Dec"; break;                            
        }
        var c = st.replace("X","<span style='font-size: 30px; font-weight: bold; color: #fb9e1e;'>"+cday+"</span>");      
        c = c.replace("H","<span style='font-size: 30px; font-weight: bold; color: #fb9e1e;'>"+ch+"</span>");      
        c = c.replace("M","<span style='font-size: 30px; font-weight: bold; color: #fb9e1e;'>"+cm+"</span>");      

        E$("countdown_st").innerHTML = c;
        E$("countdown_st").style.display="";
    }      
  }
}