﻿
function drawInfoTable(record)
{
    return'<td class="mainContent">'+
    '<table cellspacing="0" cellpadding="0" border="0">\x0A<tr>'+
    '<td width="101" class="subtitle">Venue:</td>\x0A'+
    '<td width="202" class="subtitle">'+record[1]+'</td>\x0A'+
    '<td width="115" class="subtitle">FTD:</td>\x0A'+
    '<td width="435" class="subtitle">'+record[6]+'</td>\x0A'+
    '</tr>\x0A'+
    '<tr>\x0A'+
    '<td width="101" class="subtitle">Event Name:</td>\x0A'+
    '<td width="202" class="subtitle">'+record[2]+'</td>\x0A'+
    '<td width="115" class="subtitle">Followed By:</td>\x0A'+
    '<td width="435" class="subtitle">'+record[7]+'</td>\x0A'+
    '</tr>\x0A'+
    '<tr>\x0A'+
    '<td width="101" class="subtitle">Date:</td>\x0A'+
    '<td width="202" class="subtitle">'+record[3]+'</td>\x0A'+
    '<td width="115" class="subtitle">Drivers:</td>\x0A'+
    '<td width="435" class="subtitle">'+record[8]+'</td>\x0A'+
    '</tr>\x0A<tr>\x0A<td width="101" class="subtitle">Chair:</td>\x0A'+
    '<td width="202" class="subtitle">'+record[4]+'</td>\x0A'+
    '<td width="115" class="subtitle">Runs:</td>\x0A'+
    '<td width="435" class="subtitle">'+record[9]+'</td>\x0A'+
    '</tr>\x0A'+
    '<tr>\x0A'+
    '<td width="101" class="subtitle">Event Status:</td>\x0A'+
    '<td width="202" class="subtitle">'+record[5]+'</td>\x0A'+
    '<td width="115" class="subtitle">First Car Off:</td>\x0A'+
    '<td width="435" class="subtitle">'+record[14]+'</script></td>\x0A'+
    '</tr>\x0A'+
    '</table>\x0A';
}
function noPenalty(theField)
{
    if(theField=="")
    {
        return"-";
    }else
    {
        return theField;
    }
}

function roundStringResult(num)
{
    var n;
    n=Number(num)
    return n.toFixed(3);
}

function roundResult(num)
{
    return num.toFixed(3);
}

function paxTime(index,time)
{
    var x;x=time*index;
    return roundResult(x);
}

function variance(best,time)
{
    var x;x=time-best;
    if(x==0)
    {
        return'<< Your Best!';
    }
return roundResult(x);
}

function compVariance(best,time)
{
    var x;
    x=time-best;
    if(x==0)
    {
        return'0.000';
    }
return roundResult(x);
}



function drawErrorBox(errMessage)
{
    return'<table class="warningTable" <tr><td height="100" align=center width="500">'+errMessage+' Please wait!</td></tr></table>';
}

// All timer init functions start here

var globalTimerRef;


function getStatus(){
  s=document.getElementById('status').title
  if (s=='LIVE'){
    return true
  }
  return false
}


function initFullResults() {

getResults('fullResults.txt','renderPage')

 if (getStatus()) {

self.clearInterval(globalTimerRef)
globalTimerRef = self.setInterval("getResults('fullResults.txt','renderPage')",61251)
}
}

function initBestPax() {

 getResults('bestpax.txt','renderPaxResults')

  if (getStatus()) {

  self.clearInterval(globalTimerRef)
globalTimerRef = window.setInterval("getResults('bestpax.txt','renderPaxResults')",61251)
}
}

function initBestRuns() {

getResults('bestruns.txt','renderBestRuns')

 if (getStatus()) {

 self.clearInterval(globalTimerRef)
globalTimerRef = window.setInterval("getResults('bestruns.txt','renderBestRuns')",61251)
}
}

function initTopDrivers() {

getResults('top.txt','renderTopDrivers')

 if (getStatus()) {

 self.clearInterval(globalTimerRef)
globalTimerRef = window.setInterval("getResults('top.txt','renderTopDrivers')",61251)
}
}


function getResults(pURL,pFunc)
{
    if(window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
        eval('xmlhttp.onreadystatechange='+pFunc+';');
        xmlhttp.open("GET",pURL,true);
        xmlhttp.send(null);
    }else if(window.ActiveXObject)
        {
            xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
            if(xmlhttp){eval('xmlhttp.onreadystatechange='+pFunc+';');
            xmlhttp.open('GET',pURL,false);
            xmlhttp.send();
        }
    }
}

//**********************************************************************************************************************

//Update the menu based on the current selection.
function updateMenuBar()
{
        document.getElementById("results").className=""
        document.getElementById("pax").className=""
        document.getElementById("bestruns").className=""
        document.getElementById("topdrivers").className=""
        document.getElementById("about").className=""

}

function makeCursor(par)
{
    par.style.cursor="pointer";
}

function printPage(text)
{
    text=document;
    print(text);
}


//Trim off any whitespace on carid
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

//Update the Last Update component
function lastUpdate(theDate) {
     document.getElementById('lastUpdate').innerHTML=theDate;
}
