//-------------------------------------------------------
// Regional Radio Works JavaScipt support routines
// (c) 2006 RepubliCorp P/L
// Version 1.2
// Author: John Bradnam
//-------------------------------------------------------

var NS4        = (document.layers) ? true : false
var NS6        = (navigator.userAgent.indexOf("Gecko") != -1) ? true : false
var MAC        = (navigator.appVersion.indexOf("Mac")!=-1) ? ((!NS6) && (!NS4)) : false
var MAC45      = (navigator.appVersion.indexOf("MSIE 4.5") != -1) ? true : false
var OPERA      = (navigator.userAgent.indexOf("Opera")!=-1) ? true : false
var NS61       = (parseInt(navigator.productSub) >= 20010726) ? true : false
var IE4        = (!document.getElementById && document.all) ? true : false;
var IE         = (document.all) ? true : false;
var KONQ       = (navigator.userAgent.indexOf("Konqueror")!=-1) ? true : false

var sCursor    = (NS6) ? "pointer" : "hand";
var sHidden    = (NS4) ? "hide" : "hidden";
var sVisible   = (NS4) ? "show" : "visible";
var sClassName = (IE)  ? "className" : "class";

var aTable       = null;

function MapAustraliaInitialize()
{
  var sText = "";
  var sState = "";
  var wY     = 0;
  //Preload all mouse over images
  for (var wIndex = 0; wIndex < aStatesText.length;wIndex++) {
    sText                = aStatesText[wIndex];
    wY                   = sText.lastIndexOf(",");
    sState               = sText.substr(wY+1);
    var oImg             = document.createElement("img");
    oImg.src = "Images/Australia Map - "+sState+".gif";
  } //for
  //Populate links
  var oLinks = document.getElementById("map_links");
  if (oLinks != null) {
	var sOut = "";
    for (var wIndex = 0; wIndex < aStatesText.length;wIndex++) {
      sText                = aStatesText[wIndex];
      wY                   = sText.lastIndexOf(",");
      sState               = sText.substr(wY+1);
      sText                = sText.substr(0,wY)
      if (wIndex != 0)
        sOut               = sOut + "<br>";
      sOut                 = sOut + "<a class=\"regionlink\" id=\"map_link_"+sState+"\""
	                              + " href=\"region select.asp?name=" + sState + "&state=" + escape(sText) + "\""
                                  + " onmouseover=\"MapOverlayOn(this,'"+sState+"');\""
                                  + " onmouseout=\"MapOverlayOff(this,'"+sState+"');\""
                                  + ">" + sText + "</a>";
    } //for
    oLinks.innerHTML = sOut;
  }
  //Divide image
  MapAustraliaDivide(aQLD,287,0,58);
  MapAustraliaDivide(aNSW,314,234,32);
  MapAustraliaDivide(aVIC,313,296,20);
  MapAustraliaDivide(aTAS,350,387,9);
  MapAustraliaDivide(aSA,182,184,38);
  MapAustraliaDivide(aWA,0,37,67);
  MapAustraliaDivide(aNT,182,7,45);
}

function MapAustraliaDivide(aState,xOfs,yOfs,dPercent)
{
  var oImgDiv              = null;
  var sText                = "";
  var wX                   = 0;
  var wY                   = 0;
  var oPntr                = null;
  var oImage = document.getElementById("map_image");
  if (oImage != null) {
	oImage.galleryImg      = false;
    var wWidth             = oImage.width;
    var wHeight            = oImage.height;
    var oDiv               = document.createElement("div");
    oDiv.style.width       = wWidth;
    oDiv.style.height      = wHeight;
    oDiv.style.position    = "relative";
    oDiv.style.overflow    = "hidden";
    oDiv.style.zIndex      = 1;
    var oPar               = oImage.parentNode;
    oImage                 = oPar.replaceChild(oDiv,oImage);
    oDiv.appendChild(oImage);
    for (var wIndex = 0; wIndex < aState.length;wIndex++) {
      oImgDiv              = document.createElement("img");
      oImgDiv.width        = 3;
      oImgDiv.height       = 3;
      oImgDiv.src          = "Images/wave00.gif";
      oImgDiv.id           = "map_image_" + wIndex.toString();
      oPntr                = document.createElement("div");
      oPntr.style.position = "absolute";
      oPntr.style.overflow = "hidden";
      oPntr.style.width    = 3;
      oPntr.style.height   = 3;
      oPntr.style.cursor   = sCursor;
      oPntr.style.zIndex   = 2;
      sText                = aState[wIndex];
      wX                   = sText.indexOf(",");
      if (wX != -1) {
        wY                 = sText.lastIndexOf(",");
        oPntr.style.left   = Math.floor(parseInt(sText.substr(0,wX),10) * dPercent / 100) - 1 + xOfs;
        oPntr.style.top    = Math.floor(parseInt(sText.substr(wX+1,wY - wX - 1),10) * dPercent / 100) - 1 + yOfs;
      }
      oImgDiv.alt          = sText.substr(wY+1);
      oPntr.appendChild(oImgDiv);
      oDiv.appendChild(oPntr);
    } //for
  }
}

function MapInitialize(aActive)
{
  var sText = "";
  var sState = "";
  var oImage = document.getElementById("map_image");
  var oLinks = document.getElementById("map_links");
  aTable     = aActive;
  //Populate links
  if (oLinks != null) {
	var sOut = "";
    for (var wIndex = 0; wIndex < aActive.length;wIndex++) {
      sText                = aActive[wIndex];
      wY                   = sText.lastIndexOf(",");
      sText                = sText.substr(wY+1);
      if (wIndex != 0)
        sOut               = sOut + "<br>";
      sOut                 = sOut + "<a class=\"regionlink\" href=\"region information.asp?region="+escape(sText)+"\""
                                  + " onmouseover=\"MapMouseOverLink(this,aTable);\""
                                  + " onmouseout=\"MapMouseOutLink(this,aTable);\""
								  + " text=\""+escape(sText)+"\""
                                  + ">" + sText + "</a>";
    } //for
    oLinks.innerHTML = sOut;
  }
  //Divide image
  var oImgDiv              = null;
  var sText                = "";
  var wX                   = 0;
  var wY                   = 0;
  var oPntr                = null;
  if (oImage != null) {
	oImage.galleryImg      = false;
    var wWidth             = oImage.width;
    var wHeight            = oImage.height;
    var oDiv               = document.createElement("div");
    oDiv.style.width       = wWidth;
    oDiv.style.height      = wHeight;
    oDiv.style.position    = "relative";
    oDiv.style.overflow    = "hidden";
    oDiv.style.zIndex      = 1;
    var oPar               = oImage.parentNode;
    oImage                 = oPar.replaceChild(oDiv,oImage);
    oDiv.appendChild(oImage);
    for (var wIndex = 0; wIndex < aTable.length;wIndex++) {
      oImgDiv              = document.createElement("img");
      oImgDiv.width        = 17;
      oImgDiv.height       = 17;
      oImgDiv.src          = "Images/wave01.gif";
      oImgDiv.id           = "map_image_" + wIndex.toString();
	  if (fIE) {
		  oImgDiv.attachEvent("onmouseover",MapMouseOver);
		  oImgDiv.attachEvent("onmouseout",MapMouseOut);
		  oImgDiv.attachEvent("onclick",MapMouseClick);
	  }
	  else {
		  oImgDiv.setAttribute("onmouseover","MapMouseOver(this)");
		  oImgDiv.setAttribute("onmouseout","MapMouseOut(this)");
		  oImgDiv.setAttribute("onclick","MapMouseClick(this)");
	  }
      oPntr                = document.createElement("div");
      oPntr.style.position = "absolute";
      oPntr.style.overflow = "hidden";
      oPntr.style.width    = 17;
      oPntr.style.height   = 17;
      oPntr.style.cursor   = sCursor;
      oPntr.style.zIndex   = 2;
      sText                = aTable[wIndex];
      wX                   = sText.indexOf(",");
      if (wX != -1) {
        wY                 = sText.lastIndexOf(",");
        oPntr.style.left   = parseInt(sText.substr(0,wX),10) - 8;
        oPntr.style.top    = parseInt(sText.substr(wX+1,wY - wX - 1),10) - 8;
      }
      oImgDiv.alt          = sText.substr(wY+1);
      oPntr.appendChild(oImgDiv);
      oDiv.appendChild(oPntr);
    } //for
  }
} //MapInitialise
  
function MapMouseOver(oImg)
{
  if ((oImg == null) || (oImg.tagName == null))
	  oImg = event.srcElement;
  oImg.src   = "Images/wave.gif";
  var oLinks = document.getElementById("map_links");
  var oAnc = oLinks.firstChild;
  while ((oAnc != null) && (unescape(oAnc.getAttribute("text")) != oImg.alt))
    oAnc = oAnc.nextSibling;
  if (oAnc != null)
    oAnc.className = "regionlinkhover";
}

function MapMouseOut(oImg)
{
  if ((oImg == null) || (oImg.tagName == null))
	  oImg = event.srcElement;
  oImg.src   = "Images/wave01.gif";
  var oLinks = document.getElementById("map_links");
  var oAnc = oLinks.firstChild;
  while ((oAnc != null) && (unescape(oAnc.getAttribute("text")) != oImg.alt))
    oAnc = oAnc.nextSibling;
  if (oAnc != null)
    oAnc.className = "regionlink";
}

function MapMouseClick(oImg)
{
  if ((oImg == null) || (oImg.tagName == null))
	  oImg = event.srcElement;
  try {
    window.location.href = "region information.asp?region="+escape(oImg.alt);
  }
  catch (wError) {
  }
}

function MapMouseOverLink(oAnc,aLoc)
{
  var sText = unescape(oAnc.getAttribute("text"));
  var wIndex = 0;
  while ((wIndex < aLoc.length) && (aLoc[wIndex].indexOf(sText) == -1))
    wIndex   = wIndex + 1;
  if (wIndex < aLoc.length) {
    var sId   = "map_image_" + wIndex.toString();
    var oImg  = document.getElementById(sId);
    if (oImg != null)
      oImg.src = "Images/wave.gif";
  }
}

function MapMouseOutLink(oAnc,aLoc)
{
  var sText = unescape(oAnc.getAttribute("text"));
  var wIndex = 0;
  while ((wIndex < aLoc.length) && (aLoc[wIndex].indexOf(sText) == -1))
    wIndex   = wIndex + 1;
  if (wIndex < aLoc.length) {
    var sId   = "map_image_" + wIndex.toString();
    var oImg  = document.getElementById(sId);
    if (oImg != null)
      oImg.src = "Images/wave01.gif";
  }
}

function MapOverlayOn(oAnc,sState)
{
  var oImg  = document.getElementById("map_image");
  if (oImg != null)
    oImg.src = "Images/Australia Map - "+sState+".gif";
  if (oAnc.tagName != "A") {
    var oAnc = document.getElementById("map_link_"+sState);
    if (oAnc != null)
      oAnc.className = "regionlinkhover";
  }
}

function MapOverlayOff(oAnc,sState)
{
  var oImg  = document.getElementById("map_image");
  if (oImg != null)
    oImg.src = "Images/Australia Map.gif";
  if (oAnc.tagName != "A") {
    var oAnc = document.getElementById("map_link_"+sState);
    if (oAnc != null)
      oAnc.className = "regionlink";
  }
}

function RrbNavigationMouseOver(sImg)
{
  var oAnc  = event.srcElement;
  var oRow  = oAnc.parentElement.parentElement.parentElement;
  var oImg = oRow.cells(0).firstChild.firstChild;
  if (oImg != null)
    oImg.src = "Images/Bullet round red.gif";
}

function RrbNavigationMouseOut(sImg)
{
  var oAnc  = event.srcElement;
  var oRow  = oAnc.parentElement.parentElement.parentElement;
  var oImg = oRow.cells(0).firstChild.firstChild;
  if (oImg != null)
    oImg.src = "Images/Bullet round gray.gif";
}

function RemoveSlashFromText(sRawText)
{
  var sText  = sRawText;
  var wSlash = sText.indexOf("/");
  while (wSlash != -1) {
    sText  = sText.substr(0,wSlash) + sText.substr(wSlash + 1);
    wSlash = sText.indexOf("/");
  }
  return sText;
}

//------------ end of location.js ---------------