function SetDefault() {
so = PresetOrder();
NewSetSortOrder(so,StartPos);
cookiePut("WeekScroll","");
cookiePut("WeekStart","0");
}



function SortCompare(frst,secnd) {
res = 0;
switch(SortOrder) {

case 0 : 
          if (frst.s < secnd.s)
            res= 1;
          else
          if (frst.s > secnd.s)   
            res = -1;
          else res= 0;
          break;



case 1:
          if (frst.u.toLowerCase() > secnd.u.toLowerCase())
            res= 1;
          else
          if (frst.u.toLowerCase() < secnd.u.toLowerCase())   
            res = -1;
          else res= 0;
          break;

case 2: 
          if (frst.op > secnd.op)
            res= 1;
          else
          if (frst.op < secnd.op)   
            res = -1;
          else
          if (frst.t > secnd.t)
            res= 1;
          else
          if (frst.t < secnd.t)   
            res = -1;
          else res= 0;
          break;

default : 

          if (frst.mp > secnd.mp)
            res= 1;
          else
          if (frst.mp < secnd.mp)   
            res = -1;
          else
          if (frst.t1 > secnd.t1)
            res= 1;
          else
          if (frst.t1 < secnd.t1)   
            res = -1;
          else
          if (frst.t2 > secnd.t2)
            res= 1;
          else
          if (frst.t2 < secnd.t2)   
            res = -1;
          else res= 0;
          break;
} // end case
if(SortDir != "A")
     res = res * -1;          
return res;                    
}

function buildTable(doSort) {
if (screen.width <1024) {
fsize = 8
}
else
fsize=12;
	
divsection=document.getElementById("JSTable");
msgsection=document.getElementById("JSMessage");

if (ResultList.length > 0)
{ // if there's data
if (doSort){
  ResultList.sort(SortCompare);
  setCookies();
 }
EndPos = StartPos + ScrollSize;
if (EndPos > ResultList.length-1)
  EndPos = ResultList.length-1;






headerHTML = "<table cellpadding='0' cellspacing='0' class='SheetTable' align='center'> "+



             '   <tr><th>Position</th>' +
             '   <th><a href="javascript:SetSortOrder(1)">'  + getImageTag(1) + 'Name</a></th>' +
             '   <th>Correct/<br>Incorrect</th>' +
             '   <th><a href="javascript:SetSortOrder(0)">'  + getImageTag(0) + 'Score</a></th>' +
             '   <th>Tie Breakers<br>tb1/tb2</th>' +
             '   <th><a href="javascript:SetSortOrder(2)">'  + getImageTag(2) + 'Outstanding<br>Points</a></th>' +
             '   <th><a href="javascript:SetSortOrder(3)">'  + getImageTag(3) + 'Max<br>Possible</a></th>' +
             '   <th>Counting On</th>' +
             '<tr>';



colHTML = "";
	

	
  outHTML = "";
  Z=1;
  for (i=StartPos;i <= EndPos;i++) {
  Res = ResultList[i];
  if (Res.H == "") {
  
           Res.H = '<td>' + Res.s + '</td><td>'  + Res.u +'</td><td nowrap>' + Res.c +'/' + Res.i+ '</td><td>' + Res.t +'</td><td>' +Res.t1 + '/' + Res.t2 + '</td><td>' + Res.op + '</td><td>' + Res.mp + '</td><td>' + Res.co + '</td></tr>';
     }                  
  if (Z==2) { // z==2
    if (Res.u.toUpperCase()==User.toUpperCase()) { // is user
       outHTML= outHTML + '<tr bgcolor="#00BFBF" class="TableBold">' + Res.H;  
       }  // is user
       else
       { // isn't user
       outHTML= outHTML + '<tr bgcolor="#BFBFBF">' + Res.H;  
       } // isn't user
    } //  2
  else  { //not 2 
    if (Res.u.toUpperCase()==User.toUpperCase()) { // is user
       outHTML= outHTML + '<tr bgcolor="#00BFBF" class="TableBold">' + Res.H;  
    }  // is user
    else 
    { //isn't user
    outHTML= outHTML + '<tr>' + Res.H;
    } // isn't user
  } // not 2
  Z++;
  if (Z==3) Z=1;
  } // end for
divsection.innerHTML=headerHTML + colHTML + outHTML + colHTML;
} // if there's data
else
divsection.innerHTML= '<h2><i>No records found </i></h2>';
msgsection.style.visibility="hidden";
divsection.style.visibility="visible";
ItemName = cookieGet("WeekScroll");
if (ItemName != null && ItemName !='') {
  TheButton = document.getElementById(ItemName);
  if (TheButton !=null)
    TheButton.scrollIntoView();
}
	
} // end buildTable

