/*============================================================
Name: Frame_ID.js
Date: August 16, 2007
Description: Assigns IDs to content table for Catster/Dogster
            to allow control of the frame around the content profile.
Author: Alice Billman (with Callie Jean and PJ)
URL: http://home.neo.rr.com/allybill/
==============================================================
June 30, 2008 - AJB
 Removed all IMG elements and the row just above the
 bottomFrame so we don't have to work around it any more!
==============================================================*/

function clearBG(obj) {
  obj.background = '';    // for IE
  obj.setAttribute('background', '');      // for Firefox
}

function assign_IDs() {
  /* Find the BodyDiv */
  var divBody = document.getElementById('BodyDiv');
  var contentTable = divBody.getElementsByTagName('table')[0];
  clearBG(contentTable);
  contentTable.id = 'contentTable';

  /* Top frame */
  var topFrame = contentTable.getElementsByTagName('td')[0];
  topFrame.id = 'topFrame';
  var topFrameImg = contentTable.getElementsByTagName('img')[0];
  /* Top frame image - remove it. */
  topFrame.removeChild(topFrameImg);
  /* Must reset the width since the image was removed. */
  topFrame.style.width = '644px';

  /* Left Frame is the 2nd row in table */
  var TR1 = contentTable.getElementsByTagName('tr')[1];
  /* Left Side frame (TD background) */
  var leftFrame = TR1.firstChild;
    while(leftFrame.nodeType!=1){
      leftFrame = leftFrame.nextSibling;
    }
  clearBG(leftFrame);
  leftFrame.id = 'leftFrame';

  /* Left Top corner frame image - remove it. */
  var topLeftFrame = leftFrame.getElementsByTagName('img')[0];
  leftFrame.removeChild(topLeftFrame);

  /* Grab center content just to help navigate through page */
  var profileContent = leftFrame.nextSibling;
    while(profileContent.nodeType!=1){
      profileContent = profileContent.nextSibling;
    }
  clearBG(profileContent);
  profileContent.id = 'profileContent';
  /* Default is 644px (:?).  Must set to 600 pixels. */
  profileContent.style.width = '600px';

  /* Right Side frame (TD background) */
  var rightFrame = profileContent.nextSibling;
    while(rightFrame.nodeType!=1){
      rightFrame = rightFrame.nextSibling;
    }
  clearBG(rightFrame);
  rightFrame.id = 'rightFrame';

  /* Right Top corner frame image - remove it. */
  var topRightFrame = rightFrame.getElementsByTagName('img')[0];
  rightFrame.removeChild(topRightFrame);

  /* Bottom Row -- This is a filler space which I loath.  REMOVE IT!*/
  var TR2 = TR1.nextSibling;
    while(TR2.nodeType!=1){
      TR2 = TR2.nextSibling;
    }
  var TR2parent = TR2.parentNode;
  TR2parent.removeChild(TR2);

  /* Bottom Frame - TR1 now has a new nextSibling */
  var TR3 = TR1.nextSibling;
    while(TR3.nodeType!=1){
      TR3 = TR3.nextSibling;
    }
  var bottomFrame = TR3.getElementsByTagName('td')[0];
  bottomFrame.id = 'bottomFrame';
  var bottomFrameImg = bottomFrame.getElementsByTagName('img')[0];
  /* Bottom frame image - remove it. */
  bottomFrame.removeChild(bottomFrameImg);
  }

/* This delays the execution until all the content is loaded. */
var alreadyrunflag=0 //flag to indicate whether target function has already been run

if (document.addEventListener)
  document.addEventListener("DOMContentLoaded", function(){alreadyrunflag=1; assign_IDs()}, false)
else if (document.all && !window.opera){
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
  var contentloadtag=document.getElementById("contentloadtag")
  contentloadtag.onreadystatechange=function(){
    if (this.readyState=="complete"){
      alreadyrunflag=1
      assign_IDs()
    }
  }
}
// For all other browsers
window.onload=function(){
  setTimeout("if (!alreadyrunflag) assign_IDs()", 0)
}