var PgmVer = "FormgridsJs ver 2.6 * 2010/02/13";
function openNewWin(fileName,winHeight,winWidth,winScroll,winDoc) {
  var openParms = "toolbar=0";
  if (arguments.length < 2) winHeight = 124;
  if (arguments.length < 3) winWidth = 600;
  if (arguments.length < 4) winScroll = 0;
  if (arguments.length == 5) { fileName = ""; openParms = "toolbar=1"; }
  openParms += ",location=0,directories=0,status=0,menubar=0,scrollbars=";
  openParms += winScroll + ",resizable=1,width=";
  openParms += winWidth + ",height="+winHeight;
  var windowName = new String(Math.round(Math.random() * 100000));
  winObj = window.open(fileName,windowName,openParms);
  if (arguments.length == 5) {
    winObj.document.open();
    winObj.document.write(unescape(winDoc));
    winObj.document.close();
  }
}
function openFullWin(theURL) {
  var windowName = new String(Math.round(Math.random() * 100000));
  window.open(theURL,windowName,"fullscreen=1,scrollbars=auto");
}
function openMaxWin(fileName) {
  var winHeight = window.screen.height - 81;
  var winWidth = window.screen.width - 11;
  openParms = "toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0,top=0,left=0,width=";
  openParms += winWidth + ",height="+winHeight;
  var windowName = new String(Math.round(Math.random() * 100000));
  window.open(fileName,windowName,openParms)
}
var myWindow;
var popImage;
function openImgWindow(theURL,imgName) {
  var winName = "PopWin";
  var features = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=200,height=200";
  popImage = imgName;
  myWindow = window.open(theURL,winName,features);
  setTimeout("myWindow.document.images.popImage.src=popImage;",1000);
}
function pageReload(argControl) {
  var theScript = "javascript:__doPostBack('"+argControl+"','')";
  top.window.opener.execScript(theScript, "JavaScript");
  window.close();                     	
}           	
function noHarvest(strUser,strDomain,strExtra,strSubj) {
  if (arguments.length < 4) strSubj = ""; else strSubj = "?subject="+strSubj;
  if (arguments.length < 3) strExtra = "";
  if (strDomain == "" || arguments.length < 2) strDomain = location.host.replace("www.","");
  return "<a "+strExtra+" href=\"mailto:"+strUser+"@"+strDomain+strSubj+"\">"+strUser+"@"+strDomain+"</a>";
}
var childLev = "";
function getRaceCardUrl(childLev) {
  if (!childLev) childLev = "";
  var cnty = location.search.replace("&login=guest","");
  cnty = cnty.substr(cnty.length-2);
  if (cnty == "") cnty = "ZA";
  return(childLev + "subscriber/fgRaceIndexB.aspx?cnty="+cnty);
}
function getHarnessCardUrl(childLev) {
  if (!childLev) childLev = "";
  var cnty = location.search.replace("&login=guest","");
  cnty = cnty.substr(cnty.length-2);
  if (cnty == "") cnty = "SE";
  return(childLev + "harness/swdRaceIndex.aspx?cnty="+cnty);
}
function getRaceResultsUrl(childLev) {
  if (!childLev) childLev = "";
  var cnty = location.search.replace("&login=guest","");
  cnty = cnty.substr(cnty.length-2);
  if (cnty == "") cnty = "ZA";
  return(childLev + "subscriber/fgRaceIndexB.aspx?opt=Result&cnty="+cnty);
}
function getHarnessResultsUrl(childLev) {
  if (!childLev) childLev = "";
  var cnty = location.search.replace("&login=guest","");
  cnty = cnty.substr(cnty.length-2);
  if (cnty == "") cnty = "SE";
  return(childLev + "harness/swdRaceIndex.aspx?opt=Result&cnty="+cnty);
}
function getRaceLbhUrl(childLev) {
  if (!childLev) childLev = "";
  var cnty = location.search.replace("&login=guest","");
  cnty = cnty.substr(cnty.length-2);
  if (cnty == "") cnty = "ZA";
  return(childLev + "subscriber/fgReports.aspx?cnty="+cnty);
}
var cLnkTitle = "";
var arrTxtColor = new Array();
var curTxtColor;
function findTitles(curLnk,argSel) {
  var HighStyle = getCookie("GridHighlight");
  if (HighStyle == "") HighStyle = "Flash";
  var idx = 0;
  if (argSel == "race") {
    cLnkTitle = curLnk.title;
    idx = 0;
    curLnk.title = "";
    if (HighStyle == "Flash") {
      curLnk.style.backgroundImage = "url(../images/glow_long.gif)";
      curLnk.style.borderColor = "red";
    }
  }
  else if (argSel == "dist") {
    cLnkTitle = "~|";
    if (curLnk.innerText) cLnkTitle += curLnk.innerText;
    else if (curLnk.textContent) cLnkTitle += curLnk.textContent;
    idx = 1;
  }
  else {
    curLnk.title = cLnkTitle;
    cLnkTitle = "";
  }
  if (!document.createElement || !document.getElementsByTagName) return false;
  if (!document.links) document.links = document.getElementsByTagName("a");
  for (var ti = 0; ti < document.links.length; ti++) {
    var lnk = document.links[ti];
    if (lnk.title && lnk.href.indexOf("?rn=") != -1) {
      if (lnk.title.split("|")[idx] == cLnkTitle.split("|")[idx]) {
        if (HighStyle == "Flash") {
          lnk.style.backgroundImage = "url(../images/glow_long.gif)";
          lnk.style.borderColor = "red";
        }
      }
      else {
        if (HighStyle == "Flash") {
          lnk.style.backgroundImage = "none";
          lnk.style.borderColor = "black";
        }
        else if (cLnkTitle != "") {
          lnk.style.backgroundImage = "url(../images/glow_not.gif)";
//           lnk.style.borderColor = "red";
          arrTxtColor[ti] = lnk.style.color;
          lnk.style.color = "black";
        }
        else {
          lnk.style.backgroundImage = "none";
//           lnk.style.borderColor = "black";
          if (lnk.style.color) lnk.style.color = arrTxtColor[ti];
        }
      }
    }
  }
  return true;
}
var arrBgColor = new Array();
var curBgColor;
function findHrefs(curLnk,argSel) {
  if (!document.createElement || !document.getElementsByTagName) return false;
  if (!document.links) document.links = document.getElementsByTagName("a");
  var ovrCnt = 0;
  curBgColor = curLnk.parentNode.parentNode.style.backgroundColor;
  for (var ti = 0; ti < document.links.length; ti++) {
    var lnk = document.links[ti];
    if (lnk.href && lnk.href.indexOf("?tr=") != -1) {
      if (lnk.href == curLnk.href && argSel == "ovr") {
        arrBgColor[ti] = lnk.parentNode.parentNode.style.backgroundColor;
        lnk.parentNode.parentNode.style.backgroundColor = "#fffacd";
        ovrCnt ++;
      }
      else {
        lnk.parentNode.parentNode.style.backgroundColor = arrBgColor[ti];
      }
    }
  }
  if (ovrCnt == 1) curLnk.parentNode.parentNode.style.backgroundColor = curBgColor;
  return true;
}
function toggleRes() {
  if (getCookie("res") != "low") {
    AddCss("../formgridsLowRes.css");
    document.cookie = "res=low;";
    document.getElementById("ResHigh").style.display = "none"; 
    document.getElementById("ResLow").style.display = "inline";
    //alert("low-"+getCookie("res"));
  }
  else {
    document.cookie = "res=high;";
    document.getElementById("ResHigh").style.display = "inline"; 
    document.getElementById("ResLow").style.display = "none";
    location.href = location.href;
    //alert("high-"+getCookie("res"));
  }
   
}
function getCookie(keyw) {
  var theCookie = document.cookie + ";";
  if (theCookie.length > 0 && theCookie.indexOf(keyw+"=",0) != -1) {
    var sPos = theCookie.indexOf(keyw+"=",0) + keyw.length + 1;
    var ePos = theCookie.indexOf(";",sPos);
    return theCookie.substr(sPos, ePos - sPos);
  }
  else return "";
}
// -- Allow the multiple onloads
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != "function") {
    window.onload = func;
  } 
  else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
// -- end allow the multiple onloads
function AddCss(cssFile){
  var lnk = CreateEl("link");
  lnk.setAttribute("type","text/css");
  lnk.setAttribute("rel","stylesheet");
  lnk.setAttribute("href",cssFile);
  lnk.setAttribute("media","screen");
  document.getElementsByTagName("head")[0].appendChild(lnk);
}
function CreateEl(x){
  return(document.createElement(x));
}

addLoadEvent(setRes);
//window.onload = function() {();};
function setRes() {
  if (getCookie("res") == "low") {
    AddCss("../formgridsLowRes.css");
    if (document.getElementById("ResHigh")) {
      document.getElementById("ResHigh").style.display = "none"; 
      document.getElementById("ResLow").style.display = "inline";
    }     
  }
}
function image() {};

num = 8;
pref = "pics/image";
ext = ".jpg";

image = new image();
for (var i = 0; i < num; i++) {
  image[i] = "<img class='randomPic' src='"+pref+i+ext+"' border='0' />";
}

function getImage() {
  return image[Math.floor(Math.random() * num)];
}


function buildDimmerDiv() {
  var brwsH = "100%";
  if (/msie|MSIE 6/.test(navigator.userAgent)) brwsH = window.screen.height + "px";
  document.write('<div id="dimmer" class="dimmer" style="width:100%; height:' + brwsH +';"></div>');
}
function activateDimmer() {
  document.getElementById("dimmer").style.visibility = "visible";
  hideSelects("hidden");
}
function activateLogin() {
  document.getElementById("dimmer").style.visibility = "visible";
  document.getElementById("LoginBox").style.visibility = "visible";
  document.getElementById("LoginBox").style.display = "block";
  hideSelects("hidden");
  hideObjects("hidden");
}
function cancelLogin() {
  document.getElementById("dimmer").style.visibility = "hidden";
  document.getElementById("LoginBox").style.visibility = "hidden";
  document.getElementById("LoginBox").style.display = "none";
  hideSelects("visible");
  hideObjects("visible");
}

function hideSelects(action) {
  if (action != "visible") action = "hidden";
  if (/msie|MSIE 6/.test(navigator.userAgent)) {
    for (var S = 0; S < document.forms.length; S++) {
      for (var R = 0; R < document.forms[S].length; R++) {
        if (document.forms[S].elements[R].options) {
          document.forms[S].elements[R].style.visibility = action;
        }
      }
    }
  }
}
function hideObjects(action) {
  if (action != "visible") action = "hidden";
  var arrObj = document.getElementsByTagName("object");
  for (var S = 0; S < arrObj.length; S++) {
    arrObj[S].style.visibility = action;
  }
}
buildDimmerDiv();
