// Check browser type
var isIE = false;
var isOther = false;
var isNS4 = false;
var isNS6 = false;
if(document.getElementById){
  if(!document.all) {
    isNS6=true;
  }
  if(document.all) {
    isIE=true;
  }
} else {
  if(document.layers) {
    isNS4=true;
  } else {
    isOther=true;
  }
}

if (!isIE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
  if (isIE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  }
  else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX;
    tempY = e.pageY;
  }  
  if (tempX < 0){tempX = 0;}
  if (tempY < 0){tempY = 0;}  
  return true;
}

function GetStyle(layerID) {
  var returnLayer;
  if(isIE) {
    returnLayer = eval("document.all." + layerID + ".style");
  }
  if(isNS6) {
    returnLayer = eval("document.getElementById('" + layerID + "').style");
  }
  if(isNS4) {
    returnLayer = eval("document." + layerID);
  }
  if(isOther) {
    returnLayer = "null";
    alert("-[Error]-\nYour browser probably did not render this page correctly.");
  }
  return returnLayer;
}

function GetTag(tagID)
{
  var returnLayer;
  if (isIE)
  {
    returnLayer = eval("document.all.tags('" + tagID + "')");
  }
  if (isNS6) {
    returnLayer = eval("document.getElementsByTagName('" + tagID + "')");
  }
  if (isNS4) {
    returnLayer = eval("document.getElementsByTagName('" + tagID + "')");
  }
  if (isOther) {
    returnLayer = "null";
    alert("-[Error]-\nYour browser probably did not render this page correctly.");
  }
  return returnLayer;
}

function GetLayer(layerID)
{
  var returnLayer;
  if (isIE) {
    returnLayer = eval("document.all." + layerID);
  }
  if (isNS6) {
    returnLayer = eval("document.getElementById('" + layerID + "')");
  }
  if (isNS4) {
    returnLayer = eval("document." + layerID);
  }
  if (isOther) {
    returnLayer = "null";
    alert("-[Error]-\nYour browser probably did not render this page correctly.");
  }
  return returnLayer;
}

function GetObjectLayer(byObject)
{
  var returnLayer;
  if (isIE)
    returnLayer = byObject

  if (isNS6)
    returnLayer = byObject

  if (isNS4)
    returnLayer = eval("document." + byObject.id);

  if (isOther)
    returnLayer = "null";

  return returnLayer;
}

function GetObjectStyle(byObject)
{
  var returnStyle;
  if (isIE)
    returnStyle = byObject.style

  if (isNS6)
    returnStyle = byObject.style

  if (isNS4)
    returnStyle = eval("document." + byObject.id)

  if (isOther)
    returnStyle = "null";

  return returnStyle;
}

function HideShow(ID, onoff) {
  if ((onoff == 0) || (onoff == 1)) {
    // by switch
    if (onoff == 0) {
      GetStyle(ID).visibility = "hidden";
      vis_state = 0;
    } else if (onoff == 1) {
      GetStyle(ID).visibility = "visible";
      vis_state = 99;
    }
  } else {
    // by previous state
    if((GetStyle(ID).visibility == "visible") || (GetStyle(ID).visibility == "")) {
      GetStyle(ID).visibility = "hidden";
      vis_state = 0;
    } else if(GetStyle(ID).visibility == "hidden") {
      GetStyle(ID).visibility = "visible";
      vis_state = 99;
    }
  }
  return vis_state;
}

function Expando(ID, onoff)
{
  // Turn all off, then turn on the one tabID
  var allDivs = GetTag("DIV")
  var showExpando = GetLayer(ID);
  
  for (var i = 0; i < allDivs.length; i++)
  {
    if (allDivs[i].className == showExpando.className)
    {
      allDivs[i].style.display = "none";
    }
  }
  showExpando.style.display = "block";
  return 0;
}

function breakout_of_frame()
{
  if (self != top) {top.location = self.location;}
}

function pop_help(hlp_ob, vis) {
  GetStyle(hlp_ob).zIndex = HideShow(hlp_ob, vis);
  // Check where the cursor is located relative to the window
  GetStyle(hlp_ob).left = tempX;
  GetStyle(hlp_ob).top = tempY + 20;
  
  return;
}

function PopStart(page, width, height, windowname, showToolBar, showLocation, showStatus, showMenuBar, showScrollBars, isResizable)
{
    if (!showToolBar || showToolBar != "yes")
        showToolBar = "no"
    if (!showLocation || showLocation != "yes")
        showLocation = "no"
    if (!showStatus || showStatus != "yes")
        showStatus = "no"
    if (!showMenuBar || showMenuBar != "yes")
        showMenuBar = "no"
    if (!showScrollBars || showScrollBars != "no")
        showScrollBars = "yes"
    if (!isResizable || isResizable != "yes")
        isResizable = "no"

    var _WindowName = (windowname ? windowname : page.split(".")[0])

    if (isNaN(width))
        width=800;

    if (isNaN(height))
        height=470;

    newWin = window.open(page, _WindowName, "width=" + width + ",height=" + height + ","
        + "toolbar=" + showToolBar + ","
        + "location=" + showLocation + ","
        + "status=" + showStatus + ","
        + "menubar=" + showMenuBar + ","
        + "scrollbars=" + showScrollBars + ","
        + "resizable=" + isResizable);
    if (window.focus) {newWin.focus()}
}

function TabChange(tabID)
{
  // Turn all off, then turn on the one tabID
  var allDivs = GetTag("DIV")
  var showTab = GetLayer(tabID);
  var showTabBtn = GetLayer("btn" + tabID);
  
  for (var i = 0; i < allDivs.length; i++)
  {
    if (allDivs[i].className == showTab.className)
    {
      allDivs[i].style.display = "none";
      var tabButton = GetLayer("btn" + allDivs[i].id);
      tabButton.style.borderStyle = "none";
      tabButton.style.borderWidth = "0px";
    }
  }
  showTab.style.display = "block";
  showTabBtn.style.borderStyle = "outset";
  showTabBtn.style.borderWidth = "2px";
}

function ToggleSelection(objectID)
{
  // Turn all off, then turn on the one tabID
  var allTR = GetTag("TD");
  var locLayer = GetLayer(objectID)
  var locLayerStyle = GetStyle(objectID)

  for (var i = 0; i < allTR.length; i++)
  {
    if (allTR[i].className.search("inboxItem_") != -1)
    {
      if (allTR[i].className == "inboxItem_read")
        GetStyle(allTR[i].id).backgroundColor = "white"
      else
        GetStyle(allTR[i].id).backgroundColor = "#F5DEB3"
    }
  }

	locLayerStyle.backgroundColor = "#EEEEEE"
}

function DoButton(it)
{
  var oLayer = GetObjectStyle(it)
  if (oLayer.backgroundColor == "gainsboro")
  {
    oLayer.color = "#CF7006"
    oLayer.backgroundColor = "silver"
    oLayer.borderStyle = "solid"
    oLayer.borderWidth = "1px"
  }
  else
  {
    oLayer.color = "#FF9933"
    oLayer.backgroundColor = "gainsboro"
    oLayer.borderStyle = "outset"
    oLayer.borderWidth = "2px"
  }
}

function ClickButton(what)
{
  switch (what.id)
  {
    case "idInboxDelete":
      var allInput = GetTag("INPUT")
      var delWhat = ""
      for (var i = 0; i < allInput.length; i++)
      {
        if (allInput[i].id.search(/^in(\d+)$/) != -1 && allInput[i].checked)
        {
          delWhat += RegExp.$1 + ","
        }
      }
      delWhat = delWhat.replace(/^,|,$/,"")
      if (delWhat != "")
        top.location = "deletemessage.php?id=" + delWhat
      break
    case "idSentBoxDelete":
      var allInput = GetTag("INPUT")
      var delWhat = ""
      for (var i = 0; i < allInput.length; i++)
      {
        if (allInput[i].id.search(/^in(\d+)$/) != -1 && allInput[i].checked)
        {
          delWhat += RegExp.$1 + ","
        }
      }
      delWhat = delWhat.replace(/^,|,$/,"")
      if (delWhat != "")
        top.location = "deletemessage.php?id=" + delWhat
      break
    case "idMCSignup":
        //top.location = "signup.php?type=mc&back=myprofile.php";
      break;
    default:
      break
  }
}

function RadioCheckbox(what)
{
  var allInput = GetTag("INPUT")
/*
  for (var i = 0; i < allInput.length; i++)
  {
    if allInput[i].id.search(new regexp(what.id)) != -1
  }
*/
}