var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;
var showCut;
var finalCut;
var cutLine;
var underCutLine;
var madeCut;
var coursePar;
var roundsCompleted;

function loadXML() {

    var xmlDoc;
    // code for IE
    if (window.ActiveXObject) {
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    }
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument) {
        xmlDoc=document.implementation.createDocument("","",null);
    } else {
        alert('Your browser cannot handle this script');
    }
    
    xmlDoc.async=false;
    
    var dtmNow = new Date();
    var strMS = dtmNow.valueOf;
    xmlDoc.load("/2007/scoring/dyn/csum.xml");

    document.getElementById("eventName").innerHTML=showName(xmlDoc);
    document.getElementById("updateTime").innerHTML=showTime(xmlDoc);
    document.getElementById("leaderBoard").innerHTML=showTable(xmlDoc);
}

function showTable(mDoc) {

    var priorAve;
    var x=mDoc.getElementsByTagName('hole');
    var tbl="<table width='910' cellpadding='2' cellspacing='0' border='0' align='center' class='mainTbl'>";
    for (i=0;i<x.length;i++) {
        tbl += "<tr height='22' align='center' ";
        if (x[i].getAttribute('no') == 'Out' || x[i].getAttribute('no') == 'In' || x[i].getAttribute('no') == 'Total') {
            tbl += "class='evenplayername'>";
        } else {
            tbl += "class='oddplayername'>";

        }

        tbl += "<td width='10%'>";   
        tbl +=  x[i].getAttribute('no');
        tbl = tbl + "</td>";

        tbl += "<td width='10%'>";   
        tbl +=  x[i].getAttribute('yards');
        tbl = tbl + "</td>";

        tbl += "<td width='10%'>";   
        tbl +=  x[i].getAttribute('par');
        tbl = tbl + "</td>";

        tbl += "<td width='10%'>";   
        tbl +=  x[i].getAttribute('average');
        tbl = tbl + "</td>";

        tbl += "<td width='10%'>";
        if (x[i].getAttribute('rank') == 'NaN') {
            tbl += "&nbsp";
        } else {
            tbl +=  x[i].getAttribute('rank');
        }
        tbl = tbl + "</td>";

        tbl += "<td width='10%'>";
        if (x[i].getAttribute('drives') == 'NaN') {
            tbl += "&nbsp";
        } else {
            tbl +=  x[i].getAttribute('drives');
        }
        tbl = tbl + "</td>";

        tbl += "<td width='10%'>";
        if (x[i].getAttribute('fairways') == 'NaN%') {
            tbl += "&nbsp";
        } else {
            tbl +=  x[i].getAttribute('fairways');
        }
        tbl = tbl + "</td>";

        tbl += "<td width='10%'>";
        if (x[i].getAttribute('costofrough') == 'NaN') {
            tbl += "&nbsp";
        } else {

            tbl +=  x[i].getAttribute('costofrough');
        }
        tbl = tbl + "</td>";

        tbl += "<td width='10%'>";   
        tbl +=  x[i].getAttribute('gir');
        tbl = tbl + "</td>";

        tbl += "<td width='10%'>";   
        tbl +=  x[i].getAttribute('putts');
        tbl = tbl + "</td>";
        
        tbl += "</tr>";
    }
    tbl += "</table>";
    return tbl;
}

function showName(mDoc){
    var x=mDoc.getElementsByTagName('tournament');
    document.title = x[0].getAttribute('name');
    return x[0].getAttribute('name');
}

function showTime(mDoc){
    var x=mDoc.getElementsByTagName('event');
    return x[0].getAttribute('localtime') + '&nbsp;&nbsp;&nbsp;&nbsp;(' + x[0].getAttribute('GMT') + ')';
}

function InitializeTimer(){
    // Set the length of the timer, in seconds
    secs = 60
    StartTheTimer()
}

function StopTheClock(){
    if (timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer(){
    if (secs==0) {
        StopTheClock();
        loadXML();
        InitializeTimer();
    } else {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

function InitializePage(){
    loadXML();
    InitializeTimer();
}





