function showUpdate( str )
{
  var newStatus = "";
  
  if( str[0].checked == true ) {
    newStatus = str[0].value;
    document.getElementById("open").checked=true;
    document.getElementById("currentStatus").innerHTML=newStatus;
  }
  else {
    newStatus = str[1].value;
    document.getElementById("closed").checked=true;
    document.getElementById("currentStatus").innerHTML=newStatus;
  }
   
  if (newStatus.length==0) { 
    document.getElementById("currentStatus").innerHTML="";
    return;
  }
  if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }
  else {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
      document.getElementById("currentStatus").innerHTML=xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET","update.php?q="+newStatus,true);
  xmlhttp.send();
}


function sendEmail(emailText)
{
  var email = "";

  // holds the decoded email address
  for (i=0; i < emailText.length; i++)
  {
    // remove spaces if necessary
    if (emailText.charAt(i) != " ")
      email = email + emailText.charAt(i);
  }
  // compose email address
  email = "mailto:" + email.toLowerCase() + "@" + "kpfc.asn.au";
  
  location.href = email;
}

function toggleBox(boxName)
{
  targetBox = document.getElementById(boxName);
  if (targetBox.style.display == 'block') {
    targetBox.style.display = 'none';
  }
  else {
    targetBox.style.display = 'block';
  }
}

function showPastCommittee(latestYear,earliestYear,start)
{
  maxYears = 10;
  var yearID = new Array();
  
  // Load array of available years
  for( var i = 0; latestYear - i >= earliestYear; i++ ) {
    yearID[i] = latestYear - i;
  }

  // Display the committee members for the most recent years.
  for( var i = 0; i < yearID.length; i++ ) {
    
    // If the latest year displayed is the latest year available then disable the button.
    if( start < latestYear )
      document.getElementById('l-button').removeAttribute("disabled");
    else
      document.getElementById('l-button').disabled=true;
      
    // If the earliest year displayed is the earliest year available then disable the button.
    if( start-maxYears+1 > earliestYear )
      document.getElementById('r-button').removeAttribute("disabled");
    else
      document.getElementById('r-button').disabled=true;

    targetBox = document.getElementById('y' + yearID[i]);
    if( yearID[i] > start || yearID[i] <= start - maxYears )
      targetBox.style.display = 'none';
    else
      targetBox.style.display = 'block';
  }
}

function display_season( year )
{
  // Clear any previously displayed results.
  document.getElementById('results2').innerHTML = "";

  var season = new Array();
  season[0] = 'teams2004';
  season[1] = 'teams2005';
  season[2] = 'teams2006';
  season[3] = 'teams2007';
  season[4] = 'teams2008';
  season[5] = 'teams2009';
  season[6] = 'teams2010';
  season[7] = 'teams2011';
  season[8] = 'teams2012';
  
  for( var i=0; i < season.length; i++ )
  {
    try 
    {
      if( year == i )
      {
        targetBox = document.getElementById(season[i]);
        targetBox.style.display = 'block';
      }
      else
      {
        targetBox = document.getElementById(season[i]);
        targetBox.style.display = 'none';
      }
    }
    catch(err)
    {
      null;
    }
  }
}


// Function to display the team results and player of the match for the selected team in 'Team Results'.
function display_team(team_name)
{
  teamFile = "<object><embed src='/results/" + team_name + ".pdf' type='application/pdf'  width=100% height=100%></embed></object>";
  
  document.getElementById('results2').innerHTML = teamFile;
}


function alternaterows()
{
  tables = document.getElementsByTagName("table");
  rows = tables[0].rows;
  for( var i = 0; i < rows.length; i++ )
  {
    // Change the background colour for alternate rows.
    if( i % 2 == 0 )
    {
      rows[i].style.backgroundColor = "#CCCCCC";
    }
    else
    {
      rows[i].style.backgroundColor = "#eeeeee";
    }
  }
}


function init() {
  //==========================================================================================
  // if supported, initialize TransMenus
  //==========================================================================================
  // Check isSupported() so that menus aren't accidentally sent to non-supporting browsers.
  // This is better than server-side checking because it will also catch browsers which would
  // normally support the menus but have javascript disabled.
  //
  // If supported, call initialize() and then hook whatever image rollover code you need to do
  // to the .onactivate and .ondeactivate events for each menu.
  //==========================================================================================
  if (TransMenu.isSupported()) {
    TransMenu.initialize();
    // hook all the highlight swapping of the main toolbar to menu activation/deactivation
    // instead of simple rollover to get the effect where the button stays hightlit until
    // the menu is closed.
    menu1.onactivate = function() { document.getElementById("home").className = "hover"; };
    menu1.ondeactivate = function() { document.getElementById("home").className = ""; };

    menu2.onactivate = function() { document.getElementById("information").className = "hover"; };
    menu2.ondeactivate = function() { document.getElementById("information").className = ""; };

    menu3.onactivate = function() { document.getElementById("nowthen").className = "hover"; };
    menu3.ondeactivate = function() { document.getElementById("nowthen").className = ""; };

    menu4.onactivate = function() { document.getElementById("merchandise").className = "hover"; };
    menu4.ondeactivate = function() { document.getElementById("merchandise").className = ""; };

    menu5.onactivate = function() { document.getElementById("registration").className = "hover"; };
    menu5.ondeactivate = function() { document.getElementById("registration").className = ""; };

    menu6.onactivate = function() { document.getElementById("contacts").className = "hover"; };
    menu6.ondeactivate = function() { document.getElementById("contacts").className = ""; };

/*    document.getElementById("registration").onmouseover = function() {
      ms.hideCurrent();
      this.className = "hover";
    }

    document.getElementById("registration").onmouseout = function() { this.className = ""; }
    */
  }
}


function changecss( theClass, element, setValue )
{
  //Last Updated on June 23, 2009
  //documentation for this script at
  //http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
  var cssRules;

  var added = false;
  for (var S = 0; S < document.styleSheets.length; S++)
  {

    if (document.styleSheets[S]['rules']) {
      cssRules = 'rules';
    } else if (document.styleSheets[S]['cssRules']) {
      cssRules = 'cssRules';
    } else {
      //no rules found... browser unknown
    }

    for (var R = 0; R < document.styleSheets[S][cssRules].length; R++)
    {
      if (document.styleSheets[S][cssRules][R].selectorText == theClass)
      {
        if(document.styleSheets[S][cssRules][R].style[element])
        {
          document.styleSheets[S][cssRules][R].style[element] = setValue;
          added=true;
          break;
        }
      }
    }
    
    if(!added)
    {
      if(document.styleSheets[S].insertRule)
      {
        document.styleSheets[S].insertRule(theClass+' { '+element+': '+setValue+'; }',document.styleSheets[S][cssRules].length);
      } else if (document.styleSheets[S].addRule) {
        document.styleSheets[S].addRule(theClass,element+': '+setValue+';');
      }
    }
    // alert(value);
   }
}

function docHighlight( value ) {
  
  var category = new Array();
  category[0] = '.c000001';
  category[1] = '.c000010';
  category[2] = '.c000100';
  category[3] = '.c000101';
  category[4] = '.c000110';
  category[5] = '.c001000';
  category[6] = '.c001001';
  category[7] = '.c001100';
  category[8] = '.c001101';
  category[9] = '.c010000';
  category[10] = '.c010001';
  category[11] = '.c010100';
  category[12] = '.c011000';
  category[13] = '.c011001';
  category[14] = '.c011100';
  category[15] = '.c011101';
  category[16] = '.c100000';
  category[17] = '.c100100';
  category[18] = '.c101000';
  category[19] = '.c101100';
  category[20] = '.c110000';
  category[21] = '.c110001';
  category[22] = '.c111000';
  category[23] = '.c111100';
  category[24] = '.c111101';
  category[25] = '.c111110';
  category[26] = '.c111111';
  
  for( var i=0; i <= 26; i++ )
  {
    if( category[i].charAt( value ) == '1' ) {
      changecss( category[i], 'color', '#0000FF' );
    }
    else {
      changecss( category[i], 'color', '#7E96BA' );
    }
  }
}

function display_map(lattitude, longitude, text)
{
  if (GBrowserIsCompatible())
    {
      var map = new GMap2(document.getElementById("map_canvas"));
      map.setCenter(new GLatLng(lattitude, longitude), 16);
      map.setUIToDefault();
      map.setMapType(G_HYBRID_MAP);
      // map.openInfoWindow(map.getCenter(), document.createTextNode(text));
      
      var point = new GLatLng(lattitude, longitude);

      var iconPlayer = new GIcon(); 
      iconPlayer.image = 'http://www.kpfc.asn.au/_images/plr.png';
      //iconPlayer.shadow = 'http://www.kpfc.asn.au/_images/plr_shadow.png';
      iconPlayer.iconSize = new GSize(40, 40);
      iconPlayer.shadowSize = new GSize(40, 40);
      iconPlayer.iconAnchor = new GPoint(6, 20);
      iconPlayer.infoWindowAnchor = new GPoint(5, 1);


      var options = { 
        icon: iconPlayer,
        clickable: false
      };

      var marker = new GMarker(point, options);

      map.addOverlay(marker);
    }
}

function hideHistory() {
  var historical = new Array();
  historical[0] = 'history1';
  historical[1] = 'history2';
  historical[2] = 'history3';
  historical[3] = 'history4';
  historical[4] = 'history5';
  historical[5] = 'history6';
  historical[6] = 'history7';
  historical[7] = 'history8';
  historical[8] = 'history9';
  historical[9] = 'history10';
  historical[10] = 'history11';
  
  for( var i=0; i < historical.length; i++ ) {
    targetBox = document.getElementById(historical[i]);
    targetBox.style.display = 'none';
  }
}

function hideLink( myLink ) {
  targetBox = document.getElementById(myLink);
  targetBox.style.display = 'none';
}

function activityDates( kpCalendar ) {
  var noActivity = new Array();

  for ( var i=0; i < 366; i++ ) {
    noActivity[i] = 'kpNone'+(i+1);
  }
  
  for ( var j=0; j < noActivity.length; j++ ) {
    if ( kpCalendar == 1 ) {
      try {
        targetBox = document.getElementById(noActivity[j]);
        targetBox.style.display = 'none';
      }
      catch(err) {
        null;
      }
    }
    else {
      try {
        targetBox = document.getElementById(noActivity[j]);
        targetBox.style.display = 'block';
      }
      catch(err) {
        null;
      }
    }
  }
}

function displayCalendar( startWeek ) {
  var showWeeks = 5;
  var startDay = ((startWeek-1)*7)+1;
  var endDay = startDay+(showWeeks*7);
  var displayDay = new Array();
  
  if( startDay <= 1 ) {
    document.getElementById('upButton').disabled = true;
    document.getElementById('upButton1').disabled = true;
  }
  else {
    document.getElementById('upButton').removeAttribute("disabled");
    document.getElementById('upButton1').removeAttribute("disabled");
  }
    
  if( endDay >= 364 ) {
    document.getElementById('downButton').disabled = true;
    document.getElementById('downButton1').disabled = true;
  }
  else {
    document.getElementById('downButton').removeAttribute("disabled");
    document.getElementById('downButton1').removeAttribute("disabled");
  }
    
                        //for ( var i=startDay-7; i <= startDay+(showWeeks*7)+7; i++ ) {
  for ( var i=1; i <= 364; i++ ) {
    displayDay[i] = 'day'+i;
    if( i < startDay || i >= endDay )
      document.getElementById(displayDay[i]).style.display = 'none';
    else
      document.getElementById(displayDay[i]).style.display = 'block';
  }
}

