var myImage = new Image() 
var trackAvail = false

myImage.onload = TrackUser;

function BodyLoaded () {
  myImage.src = "http://www.mebn.net/images/spacer.gif"
}

function DoNothing () {
}

function TrackUser() {
  trackAvail = true
  myImage.onload = DoNothing;

     var newscript  = document.createElement("script")
     newscript.type = "text/javascript"
     newscript.src  = "http://www.mebn.net/include/CDLinkUsage.js"
     document.body.appendChild(newscript)
     setTimeout("WriteCDLinkUsage()", 1000)
}

function WriteCDLinkUsage() {
  myImage.onload = DoNothing;
  var ip;

    if (typeof TrackCDLinkUsage != 'undefined') {
       TrackCDLinkUsage(myImage, document.URL, 'Homepage')
    }
}

function TrackLink (Code, URL) {
  var w

  var loc = new String(document.location)
  loc = loc.toLowerCase();

  if (trackAvail || loc.substring(0, 4) == "http") {  // can connect online, or already online
//    alert("about to track link " + Code)
    if (typeof TrackCDLinkUsage != 'undefined') {
//      alert("calling function")
      TrackCDLinkUsage(myImage, document.URL, Code)
    }

    if (loc.indexOf("http") >= 0 && Code != "Feedback" && Code != "FAQ") {  // we are working from the web not the CD, let's not open a window
      window.document.location = URL;
    }
    else {
      if (typeof openAppWindow != 'undefined') {
        if (URL.indexOf(".asp") >= 0 || URL.indexOf(".com") >= 0) 
          openRegularWindow(URL);
        else
          openAppWindow(URL);
      }
      else {
        w = window.open(URL, "")
      }
    }
  }
  else {  //not connected
    if (URL.toLowerCase().substring(0, 4) == "http") {  //are we going online, warn them
      if (confirm("You need to be online to proceed. Would you like to continue?")) {
        if (typeof openAppWindow != 'undefined') {
          openAppWindow(URL)
        }
        else {
          w = window.open(URL, "")
        }
      }
    }
    else {  // going locally, just go
      if (typeof openAppWindow != 'undefined') {
        openAppWindow(URL)
      }
      else {
        w = window.open(URL, "")
      }

    }
  }
}


function TrackLinkOffline (Code, URL) {
  var w

  var loc = new String(document.location)
  loc = loc.toLowerCase();

  if (trackAvail || loc.substring(0, 4) == "http") {  // can connect online, or already online
//    alert("about to track link " + Code)
    if (typeof TrackCDLinkUsage != 'undefined') {
//      alert("calling function")
      TrackCDLinkUsage(myImage, document.URL, Code)
    }
    w = window.open(URL, "")
  }
  else {  //not connected
      w = window.open(URL, "")
  }
}

function TrackLinkOnly (Code, URL) {
  var w

  var loc = new String(document.location)
  loc = loc.toLowerCase();

  if (trackAvail || loc.substring(0, 4) == "http") {  // can connect online, or already online
//    alert("about to track link " + Code)
    if (typeof TrackCDLinkUsage != 'undefined') {
//      alert("calling function")
      TrackCDLinkUsage(myImage, document.URL, Code)
    }
  }
  else {  //not connected
    if (URL.toLowerCase().substring(0, 4) == "http") {  //are we going online, warn them
      if (confirm("You need to be online to proceed. Would you like to continue?")) {
        //w = window.open(URL, "")
      }
    }
  }
}

