//
// Author: Shelley Powers
// copyright: 1997
//
// modified to use W3C DOM and other functionality by Zoltan Hawryluk.

/* to hold the array of all classes */
var wdvlInitialized = false;
var wdvlObjs;
var debug = false;
var W3Cdom = document.getElementById && document.getElementsByTagName;
var oldNSdom = document.layers;
var IEdom = document.all && navigator.appName != "WebTV Internet Terminal" &&
		navigator.appName != "Konqueror";
var isDOM = (oldNSdom || IEdom || W3Cdom)
var mozdom = W3Cdom && (navigator.appName == "Netscape" || navigator.appName == "Mozilla");
var wdvlSupport_replace_html=mozdom || IEdom || oldNSdom;

// create cross-browser object
function
wdvlNewObject (obj)
{
  this.css1 = obj;
  this.name = (W3Cdom ? obj.id : obj.name);
  this.objResizeBy = objResizeBy;
  this.objHide = objHide;
  this.objShow = objShow;
  this.objIsHidden = objIsHidden;
  this.objGetLeft = objGetLeft;
  this.objGetTop = objGetTop;
  this.objGetAbsLeft = objGetAbsLeft;
  this.objGetAbsTop = objGetAbsTop;
  this.objSetTop = objSetTop;
  this.objSetLeft = objSetLeft;
  this.objMoveAbsolute = objMoveAbsolute;
  this.objMoveRelative = objMoveRelative;
  this.objGetWidth = objGetWidth;
  this.objGetHeight = objGetHeight;
  this.objSetHeight = objSetHeight;
  this.objSetWidth = objSetWidth;
  this.objSetZIndex = objSetZIndex;
  this.objGetZIndex = objGetZIndex;
  this.objSetClipRect = objSetClipRect;
  this.objGetClipLeft = objGetClipLeft;
  this.objGetClipRight = objGetClipRight;
  this.objGetClipTop = objGetClipTop;
  this.objGetClipBottom = objGetClipBottom;
  this.objGetClipWidth = objGetClipWidth;
  this.objGetClipHeight = objGetClipHeight;
  this.replace_html = replace_html;
  this.objChangeSource = objChangeSource;
  this.objSetBgColour = objSetBgColour;
  this.objSetFontSize = objSetFontSize;
  this.objGetFontSize = objGetFontSize;
  this.styleid = null;		/* This points to another wdvlObj object
				   *  which will contain the stylesheet properties
				 */
  this.iframe_frag = false;	/* used by the W3C implementation of
				   * replace_html();
				 */
  this.style = "";
}

var wdvlName = new Array();
var wdvlNameIndex = 0;

// resize element
function
objResizeBy (w_incr, h_incr)
{
  if (IEdom)
    {
      //this.css1.style.pixelLeft -= h_incr;
      //this.css1.style.pixelTop -= w_incr;
      this.css1.style.pixelWidth += (2 * h_incr);
      this.css1.style.pixelHeight += (2 * w_incr);
    }
  else if (oldNSdom) 
    {
      //this.css1.left -= w_incr / 2;
      this.css1.width -= w_incr / 2;
      //this.css1.top += h_incr / 2;
      this.css1.height += h_incr / 2;
    }
  else 
    {
	var style=document.getElementById(this.name);
	window.alert(show_props(style,"style"));
	style.offsetWidth -= w_incr / 2;
	style.offsetHeight += h_incr / 2;
    }
}

// hide element
function
objHide ()
{
  if (IEdom) {
    this.css1.style.visibility = "hidden";
    }
  else if (oldNSdom) 
    {
      if (this.css1.visibility)
	{
	  this.css1.visibility = "hidden";
	}
      else if (this.styleid.css1.visibility)
	{
	  this.styleid.css1.visibility = "hidden";
	}
    } 
  else if (W3Cdom) { 
	  /* alert(this.name);
	  alert(show_props(document.getElementById(this.name)), "S"); */
	  document.getElementById(this.name).style.visibility = "hidden";
  }


}

// show element
function
objShow ()
{
  if (IEdom)
    this.css1.style.visibility = "visible";
  else if (oldNSdom) 
    this.css1.visibility = "inherit";
  else if (W3Cdom)  {
    document.getElementById(this.name).style.visibility = "visible";
  }

}

function
objIsHidden ()
{
  if (IEdom)
    return this.css1.style.visibility == "hidden" || 
	   this.css1.style.visibility == "" 
  else if (oldNSdom) 
    return (this.css1.visibility == "hidden" ||
		this.css1.visibility == "hide")
  else if (W3Cdom)  {

    /* mozilla seems to have a bug where the style.visibility may be "". */
    return document.getElementById(this.name).style.visibility.toLowerCase() 
		== "hidden" || 
	   document.getElementById(this.name).style.visibility == "";
  }

		/* Use .toLowerCase() because Opera uses "HIDDEN" */
}

// element's left position
function
objGetLeft ()
{
  if (IEdom)
    return this.css1.style.pixelLeft;
  else if (oldNSdom)
      return parseInt (this.css1.left);
  else if (W3Cdom)
      return document.getElementById(this.name).offsetLeft; 
}

// element's top position
function
objGetTop ()
{
  if (IEdom)
    return this.css1.style.pixelTop;
  else if (oldNSdom)
    return parseInt (this.css1.top);
  else if (W3Cdom)
    return document.getElementById(this.name).offsetTop;
}

// element's absolute left position: works on relatively positioned objects!
function
objGetAbsLeft ()
{
  if (IEdom ) 
      return this.css1.offsetLeft;
  else if (oldNSdom) 
      return this.css1.pageX;
  else if (W3Cdom) {
        if (document.defaultView) {
		var docObj = document.getElementById(this.name);
		return parseInt(document.defaultView.
			getComputedStyle(docObj, "").
			getPropertyValue("left"));
	} else { 	// Opera doesn't have this object
		return -1;
	}
  }
  // question: Mozilla?
}

function
objGetAbsTop ()
{
  if (IEdom ) 
    return this.css1.offsetTop;
  else if (oldNSdom) 
    return this.css1.pageY;
  else if (W3Cdom) {
	if (document.defaultView) {
		var docObj = document.getElementById(this.name);
		return parseInt(document.defaultView.
			getComputedStyle(docObj, "").
			getPropertyValue("top"));
	} else {
		return -1;
	}
  }
}


// set element's top position
function
objSetTop (top)
{
  if (IEdom)
    this.css1.style.pixelTop = top;
  else if (oldNSdom)
    this.css1.top = top;
  else if (W3Cdom) {

    /* This handles a difference between the Mozilla implementation of
    *  the DOM as well as the Opera version (Mozilla demands a px at the 
    *  end of the DOM, Opera doesn't).  
    */

    /* If .style.top is JUST a number, then just set it to top */
    if (parseInt(document.getElementById(this.name).style.top).toString() == 
        document.getElementById(this.name).style.top.toString()) {
    	   document.getElementById(this.name).style.top=top;

    /* Otherwise, set .style.top to be top + "px" */
    } else {
    	document.getElementById(this.name).style.top=top + "px";
    }
	
    //document.getElementById(this.name).offsetTop=top;
  }
}

// set element's left position
function
objSetLeft (left)
{
  if (IEdom)
    this.css1.style.pixelLeft = left;
  else if (oldNSdom)
    this.css1.left = left;
  else if (W3Cdom) {
    // document.getElementById(this.name).style.left = left;
    /* See notes for objSetTop() */
    /* If .style.left is JUST a number, then just set it to top */
    if (parseInt(document.getElementById(this.name).style.left).toString() ==
        document.getElementById(this.name).style.left.toString()) {
           document.getElementById(this.name).style.left=left;

    /* Otherwise, set .style.top to be top + "px" */
    } else {
        document.getElementById(this.name).style.left=left+ "px";
    }

  }
}

// make absolute move
function
objMoveAbsolute (newleft, newtop)
{
  this.objSetLeft (newleft);
  this.objSetTop (newtop);
}

// move relative to current location
function
objMoveRelative (left, top)
{
  this.objSetLeft (left + parseInt (this.objGetLeft ()));
  this.objSetTop (top + parseInt (this.objGetTop ()));
}

// get element's width
function
objGetWidth ()
{
  if (IEdom)
    return this.css1.offsetWidth;	// was this.css1.style.pixelWidth
  else if (oldNSdom)
    return this.css1.clip.width;
  else if (W3Cdom)
    if (document.getElementById(this.name).offsetWidth)	
    	return parseInt (document.getElementById(this.name).offsetWidth);
    else 
	return parseInt (document.getElementById(this.name).style.width);
    // maybe ... not sure

}

// get element's height
function
objGetHeight ()
{
  if (IEdom)
    return this.css1.offsetHeight;	// was this.css1.style.pixelHeight
  else if (oldNSdom)
    return this.css1.clip.height;
  else if (W3Cdom)
    if (document.getElementById(this.name).offsetHeight)	
    	return parseInt (document.getElementById(this.name).offsetHeight);
    else 
	return parseInt (document.getElementById(this.name).style.height);
    // maybe ... not sure

}

// set element's width
function
objSetWidth (width)
{
  if (IEdom)
    {
      if (this.css1.style.pixelWidth)
      	this.css1.style.pixelWidth = width;
      this.css1.style.width = width;
      /* if (this.css1.offsetWidth)
        this.css1.offsetWidth = width; */
    }
  else if (oldNSdom)
    this.css1.clip.width = width;
  else if (W3Cdom) 
    document.getElementById(this.name).style.width = width;	
    // maybe .. not sure

}

// set element's height
function
objSetHeight (height)
{
  if (IEdom)
    {
      this.css1.style.pixelHeight = height;
      this.css1.offsetHeight = height;
    }
  else if (oldNSdom)
    this.css1.clip.height = height;
  else if (W3Cdom)
    document.getElementById(this.name).style.height = height;	// maybe .. not sure

}

// set element's zindex order
function
objSetZIndex (zindex)
{
  if (IEdom)
    this.css1.style.zIndex = zindex;
  else if (oldNSdom)
    this.css1.zIndex = zindex;
  else if (W3Cdom) 
    document.getElementById(this.name).style.zIndex = zindex;
}

// get element's current zindex order
function
objGetZIndex ()
{
  if (IEdom)
    return this.css1.style.zIndex;
  else if (oldNSdom)
    return this.css1.zIndex;
  else if (W3Cdom)
    return document.getElementById(this.name).zIndex;
}

// font size 
function objSetFontSize (fontSize) {
	if (W3Cdom) {
		this.css1.style.FontSize=fontSize;
	}
}

// font size 
function objGetFontSize (fontSize) {
	if (W3Cdom) {
		return this.css1.style.FontSize;
	}
}

// clip object
function
objSetClipRect (top, left, bottom, right)
{
  /* nned to know W3C equiv .. leave this alone for now */
  if (top == null)
    top = this.objGetClipTop ();
  if (left == null)
    left = this.objGetClipLeft ();
  if (bottom == null)
    bottom = this.objGetClipBottom ();
  if (right == null)
    right = this.objGetClipRight ();
  if (oldNSdom)
    {
      this.css1.clip.left = left;
      this.css1.clip.right = right;
      this.css1.clip.top = top;
      this.css1.clip.bottom = bottom;
    }
  else if (W3Cdom)
    {
        var strng = "rect(" + top + "," + right +
      		"," + bottom + "," + left + ")";
        document.getElementById(this.name).style.clip = strng;
    }
  else if (IEdom)
    {
      var strng = "rect(" + top + "," + right +
      "," + bottom + "," + left + ")";
      this.css1.style.clip = strng;
    }
}

function convert(s) {
	return parseInt(s);
}

// needed by IE for the objGetClip*() functions
function
get_entry (obj, indx)
{
  var strng = (IEdom)?obj.css1.style.clip:document.getElementById(obj.name).style.clip;
  strng = strng.slice (5, strng.length - 1);
  var rectNull =  (strng == "" );
  var entries = strng.split (" ");
  if (indx == "top")
    if (entries[0] == "auto" || rectNull)
      return obj.objGetTop ();
    else
      return convert (entries[0]);
  else if (indx == "left")
    if (entries[3] == "auto" || rectNull)
      return obj.objGetLeft ();
    else
      return convert (entries[3]);
  else if (indx == "bottom")
    if (entries[2] == "auto")
      return obj.objGetHeight ();
    else if (rectNull)
      return obj.objGetTop() + obj.objGetHeight();
    else
      return convert (entries[2]);
  else if (indx == "right")
    if (entries[1] == "auto" )
    return obj.objGetWidth ();
    else if (rectNull) 
       return obj.objGetWidth() + obj.objGetLeft();
  else
    return convert (entries[1]);

}



// get current clip right 
function
objGetClipRight ()
{
  if (IEdom || W3Cdom)
    return get_entry (this, "right");
  else if (oldNSdom)
    return this.css1.clip.right;
}

// get current clip left
function
objGetClipLeft ()
{
  if (IEdom || W3Cdom)
    return get_entry (this, "left");
  else if (oldNSdom)
    return this.css1.clip.left;
}

// get current clip top
function
objGetClipTop ()
{
  if (IEdom || W3Cdom) 
    return get_entry (this, "top");
  else if (oldNSdom)
    return this.css1.clip.top;
}

// get current clip bottom
function
objGetClipBottom ()
{
  if (IEdom || W3Cdom)
    return get_entry (this, "bottom");
  else
    return this.css1.clip.bottom;
}

// get current clip bottom
function
objGetClipWidth ()
{
  if (oldNSdom) 
  	return this.css1.clip.width;
  else
	return this.objGetClipRight() - this.objGetClipLeft();
}

// get current clip bottom
function
objGetClipHeight ()
{
  if (oldNSdom) 
  	return this.css1.clip.height;
  else 
	return this.objGetClipBottom() - this.objGetClipTop();
}


function
replace_html (html_string)
{

  var newfrag, toDestroy, body;
  var div_id;

  /* this will be true for MSIE 4.x+ and mozilla M16+ .. 
     *  it is trivial
   */
  if (mozdom || this.css1.innerHTML)
    {
      this.css1.innerHTML = html_string;
    }
  else if (oldNSdom)
    {

      /* this NS 4.x way is *almost* as trivial ... note you cannot do this
         *  with relatively positioned <div>'s or <layers>'s - it will puke.
       */
      this.css1.document.open ();
      this.css1.document.write (html_string);
      this.css1.document.close ();


    }
  else if (W3Cdom)
    {

	if (document.getElementById(this.name).innerHTML) {
		document.getElementById(this.name).innerHTML=html_string;
	} else if (debug) {   /* browser doesn't support innerHTML */
		window.alert(
			"The replace_html() function of this DHTML library "+
			"does not work with the browser you have since " +
			"the W3C DOM Level 1 does not have a facility to " +
			"do so.");
	}





      /* this method below that is commented out was an experiment to do it
      *  using the W3C DOM Level 1, but it doesn't seem to work.  It is left
      *  here in commented form as a reference if it is attempted later.
      *
      *  It will replace the contents of the <div> or <span> container to the
      *  variable html_string by writing the HTML into the iframe
      *  called "_wdvlObjsIframe" (which was created in the wdvlCreateObjects() function).
      *  It then prunes the body's subtree of that iframe (which has a <div>
      *  whose id is the same as this.name) and appending it to the end of 
      *  the main document, while destroying the original <div>.  This may
      *  not work in all implementations because copying nodes from one
      *  document to the other is *supposed* to throw a WRONG_DOCUMENT_ERR 
      *  exception.  I keep it here in case it doesn't (as of this writing,
      *  Mozilla M14 and nightly builds of Mozilla M16 handle this correctly,
      *  but not M15.  Since M16 and up will handle the .innerHTML property,
      *  I don't have mozilla using this.
      *
      *  DOM Level 2 is supposed to have an importNode method that can
      *  handle copying nodes from one document to another, so this 
      *  function is the future will look at this.
      *  
      */

      
	//      div_id = this.name;
	//
	//      body = getBody ();
	//
	//      /* if the iframe "_wdvlObjsIframe" does not exist ... this is bad.  Spit out an
	//         *  javascript alert error and return
	//       */
	//      if (!frames._wdvlObjsIframe.document)
	//	{
	//	  window.alert ("Error! iframe '_wdvlObjsIframe' does not exist");
	//	  return;
	//	}
	//
	//      /* first: write the HTML content to the iframe "_wdvlObjsIframe" */
	//      frames._wdvlObjsIframe.document.open ();
	//      frames._wdvlObjsIframe.document.write ('<div id="' + div_id + '">' + html_string
	//					     + '</div>');
	//      frames._wdvlObjsIframe.document.close ();
	//
	//      /* next: get the HTML tree of "_wdvlObjsIframe"'s body tag and store it in newfrag */
	//      newfrag = frames["_wdvlObjsIframe"].document.getElementsByTagName ("body").item (0);
	//
	//      /* finally: destroy the old div and replace it with
	//         *  newfrag
	//       */
	//      if (!this.iframe_frag)
	//	{
	//	  toDestroy = document.getElementById (div_id);
	//	}
	//      else
	//	{
	//	  toDestroy = this.iframe_frag;
	//	}
	//
	//      this.iframe_frag = newfrag;
	//
	//      body.removeChild (toDestroy);	//destroy old div
	//
	//      body.appendChild (newfrag);	//create new div
	//
	//      /* body.removeChild(_iframe); */
	//      // may need to index;
	//      return;
    }
}

function
objChangeSource (sourcefile, width)
{

  if (IEdom)
    {
      var name = this.name;
      this.obj.src = sourcefile;
    }
  else if (oldNSdom)
    {
      var clipbottom;
      this.objHide ();
      clipbottom = this.objGetClipBottom ();
      this.obj.load (sourcefile, width);
      this.obj.clip.bottom = clipbottom;
      this.objShow ();
    }
  else if (W3Cdom) {	// this *may* be the case 
      if (document.getElementById(this.name).src) {
      	document.getElementById(this.name).src=sourcefile;
      } else {
	window.alert("The function objChangeSource() cannot to be executed "+
	  "since this browser does not support the src property");
      }
      //
  }
					/* w3c dom to come ... should be trivial */

}

function
objSetBgColour (c)
{
  if (IEdom)
    this.css1.style.backgroundColor = c;
  else if (oldNSdom)
    this.css1.bgColor = c;
  else if (W3Cdom) 
    document.getElementById(this.name).style.backgroundColor = c;
}

/* not cross browser .. so remove 
function
objSetBgImage (img)
{
  if (IEdom)
    this.css1.style.backgroundImage = img;
  if (oldNSdom)
    this.css1.bgImage = img;
  else if (W3Cdom)
    document.getElementById(this.name).style.backgroundImage = img;
} 
*/



function
indexNSObjs (layerArr)
{
  for (i = 0; i < layerArr.length; i++)
    // check to see if Netscape assigned block
    if (document.layers[i].id.substring (0, 3) != "_js")
      {
	if (debug)
	  {
	    window.alert ("object " + layerArr[i].id +
			  "is defined");
	  }
	wdvlObjs[layerArr[i].id] =
	  new wdvlNewObject (layerArr[i]);
	wdvlName[wdvlNameIndex] = layerArr[i].id;
	wdvlNameIndex++;

	// index internal layers within this layer
	if (layerArr[i].document.layers.length > 1)
	  indexNSObjs (layerArr[i].document.layers);
      }
}
     // function to instantiate equalizer objects
function
wdvlCreateObjects ()
{
  var i, j, theelements, thespanelements;
  var debug = false;
  var runagin = false;

  if (wdvlCreateObjects.arguments.length != 0) {
 	/* This means "Please reindex" ... experimental */
	runagain=true;
  }


  if (wdvlInitialized && !runagain)
    return false;

  if (debug)
    window.alert ("enter");

  if (IEdom)
    {
      if (debug) 
	alert('IE!!!');

      theelements = document.all.tags ("DIV");
      thespanelements = document.all.tags ("SPAN");

      wdvlObjs = new Array ();

      for (i = 0; i < theelements.length; i++)
	{
	  if (theelements[i].id != "")
	    {
	      wdvlObjs[theelements[i].id] =
		new wdvlNewObject (theelements[i]);
		wdvlName[wdvlNameIndex] = theelements[i].id;
		wdvlNameIndex++;
	      if (debug)
		window.alert ("DIV " + theelements[i].id + " is created");
	    }
	}
      for (i = 0; i < thespanelements.length; i++)
	{
	  if (thespanelements[i].id != "")
	    {
	      wdvlObjs[thespanelements[i].id] =
		new wdvlNewObject (thespanelements[i]);
		wdvlName[wdvlNameIndex] = thespanelements[i].id;
		wdvlNameIndex++;
	      if (debug)
		window.alert ("SPAN " + thespanelements[i].id + " is created");
	    }
	}

    }
  else if (oldNSdom)
    {
      if (debug) 
	alert('NS4!!!');

      wdvlObjs = new Array (document.layers.length);
      indexNSObjs (self.document.layers);
    }
  else if (W3Cdom)
    {
	if (debug)
		alert('W3C');

	if (!document.getElementsByTagName) {
		window.alert("This browser is not fully W3C DOM Level 1 \
		  compliant, and will not be able to use this dynamic   \
		  application.  If you are using Opera, the latest      \
		  version available at http://www.opera.com will fix    \
		  this problem");
		return true;
	}
	var theelements=new Array();
      theelements[0] = document.getElementsByTagName("div");
      theelements[1] = document.getElementsByTagName("span"); 
      wdvlObjs = new Array ();
      for (j = 0; j <= 1; j++ ) {
	      for (i = 0; i < theelements[j].length; i++)
		{
		  if (theelements[j][i]) {
			  var obj = theelements[j][i];
			  object = obj.style;
			  theclass = obj.className;
			  theid = obj.id;
		
			  if (obj.id != "" && !wdvlObjs.id)
			    {
			      wdvlObjs[obj.id] = new wdvlNewObject (obj);
			      wdvlName[wdvlNameIndex] = obj.id;
			      wdvlNameIndex++;
		
			    }
                  }
	
		}
	}
    }

  if (debug)
    window.alert ("exit");
  wdvlInitialized = true;
  return false;
}

function
wdvlWindowWidth ()
{
  if (window.innerWidth) 
    return window.innerWidth;
  else if (document.documentElement && document.documentElement.clientWidth)
    return document.documentElement.clientWidth;
  else if (document.body)
    return document.body.clientWidth;
  else 
    return document.body.offsetWidth;
}

function
wdvlWindowHeight ()
{
  if (window.innerHeight)
    return window.innerHeight;
  else if (document.documentElement && document.documentElement.clientHeight)
    return document.documentElement.clientHeight;
  else if (document.body)
    return document.body.clientHeight;
  else 
    return document.body.offsetHeight;
}

function wdvlSetWindowWidth(n) {
  if (window.innerWidth)
    window.innerWidth = n;
  else 
    window.resizeTo(n, wdvlWindowHeight());
}

function wdvlSetWindowHeight(n) {
  if (window.innerHeight)
    window.innerHeight = n;
  else 
    window.resizeTo(wdvlWindowWidth(), n);
}

function
wdvlMouseX (e)
{
  if (oldNSdom)
    return e.pageX;
  else if (IEdom)
    return window.event.clientX + document.body.scrollLeft;
  else if (W3Cdom) 
    if (e.pageX) 
    	return e.pageX;
    else 
	return e.clientX;
}

function
wdvlMouseY (e)
{
  if (oldNSdom)
    return e.pageY;
  else if (IEdom)
    return window.event.clientY + document.body.scrollTop;
    if (e.pageY) 
    	return e.pageY;
    else 
	return e.clientY;
}

function
wdvlScrollX ()
{
  if (oldNSdom || mozdom) {
    return window.pageXOffset;
  } else if (IEdom) {
	/* Holy crap: IE make up your mind!  The first is used by IE in 
	*  strict mode, the second in compatibility mode
	*/
	if (document.documentElement && document.documentElement.scrollLeft) {
		return document.documentElement.scrollLeft;
	} else {
    		return document.body.scrollLeft;
	}
  } else if (W3Cdom) {
    return window.scrollX;
  }

}

function
wdvlScrollY ()
{
  
  if (IEdom)
	if (document.documentElement && document.documentElement.scrollTop) {
		return document.documentElement.scrollTop;
	} else {
    		return document.body.scrollTop;
	}
  else if (W3Cdom)
    return window.scrollY;
}

function
wdvlSelectedText ()
{
  if (IEdom)
    {
      var sel = document.selection.createRange ();
      sel.expand ("word");
      return sel.text;
    }
  else if (document.getSelection)
    return document.getSelection ();
  else {
    alert("wdvlSelectedText() is not supported in this browser");
    return "";
  }   
}

/* a debugging function ... very useful. */
function
show_props (obj, objName, style, CRs, onlyNames, search)
{
  var result = ""
  var count=0;

  if (!obj) {
	return result;
  }

  for (var i in obj)
   {
	if (search && 
	    i.toString().toLowerCase().indexOf(search.toLowerCase())  == -1 ){
		; // do nothing
	} else {
	      result += objName + "." + i.toString() 
		if (!onlyNames) 
			result += " = " + obj[i];
	      count++;
	      if (CRs || count%3==0)
		result+= "\n";
	      else 
		result+= ", ";
	}
   }
   return result
}

/* used in wdvlCreateObjects() for the w3c DOM */
function addClassAttr (idobj, classobj)
      {
      window.alert (classobj);
      for (var i in idobj.css1)
      {
      if (!idobj.css1[i])
      {
      idobj.css1[i] = classobj.css1[i];
      }
      }
      }

      function getBody ()
      {
      if (W3Cdom && navigator.appName == "Microsoft Internet Explorer")
      {
      resultElement = document.body;
      }
      else
      {
      resultElement = document.getElementsByTagName ("body").item (0);
      }
      return resultElement;
      }


function wdvlMouseEvent(func) {

        if (oldNSdom){
                document.captureEvents(Event.MOUSEMOVE);
        }

        document.onmousemove = func;
        window.onmousemove = func;
        window.onmouseover=func;

}


/* These functions were stolen from javascript.faqts: 
	http://www.faqts.com/knowledge_base/view.phtml/aid/1939 */

function getStyleClass (className) {
  var re = new RegExp("\\." + className + "$", "gi");
  if (document.all) {
    for (var s = 0; s < document.styleSheets.length; s++)
      for (var r = 0; r < document.styleSheets[s].rules.length; r++)
        if (document.styleSheets[s].rules[r].selectorText.search(re) 
!= -1) {
          return document.styleSheets[s].rules[r].style;
        }
  }
  else if (document.getElementById) {
    for (var s = 0; s < document.styleSheets.length; s++)
      for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
        if (document.styleSheets[s].cssRules[r].selectorText.search
(re) != -1) {
          document.styleSheets[s].cssRules[r].sheetIndex = s;
          document.styleSheets[s].cssRules[r].ruleIndex = s;
          return document.styleSheets[s].cssRules[r].style;
        }
  }
  else if (document.layers)
    return document.classes[className].all;
  return null;
}
function getStyleClassProperty (className, propertyName) {
  var styleClass = getStyleClass(className);
  if (styleClass)
    return styleClass[propertyName];
  else 
    return null;
}

function Document(object_string) {
	var i;
	var total_object;

	if (!oldNSdom) {
		return eval("document." + object_string);
	} 

	for (i=0; i<wdvlName.length; i++) {
		total_object=eval("document.layers." + wdvlName[i] + 
				".document." + object_string);
		
		if (total_object) {
			return total_object;
		}
	}		
	return 0;
}

/***********************************************************************
* http://www.faqts.com/knowledge_base/view.phtml/aid/7157
************************************************************************/
function getCalculatedProperty(objName, property) {

    // ***** Internet Explorer 4+ DOM *****
    if (IEdom) {
	if (property == "width") return eval(objName + ".offsetWidth") + "px";

	if (property == "height") return eval(objName + ".offsetHeight") + "px";

	if (property == "clip") {
	    cssp = eval(objName + ".style.clip");

	    if (cssp == "") {
		cssStr = "rect(0px ";
		cssStr += getCalculatedProperty(objName, "width") + " ";
		cssStr += getCalculatedProperty(objName, "height") + " ";
		cssStr += "0px)";
		return cssStr;
	    }
	    return cssp;
	}

	if (property == "top") return eval(objName + ".offsetTop") + 'px';

	if (property == "left") return eval(objName + ".offsetLeft") + 'px';

        // Else, use 'currentStyle' to find the rest

	return eval(objName + ".currentStyle." + property);
    }
    // ***** W3C Compatible DOM (NN6, Mozilla 16, etc.) *****
    if (W3Cdom) {
        docObj = document.getElementById(objName);
		
        if (property == "visibility") {
	    cssp = docObj.style.visibility;
	    return (cssp == "") ? "inherit" : cssp;
	}

	if (property == "clip") {
	    cssp = docObj.style.clip;

	    if (cssp == "") {
		cssStr = "rect(0px "; 
		cssStr += getCalculatedProperty(objName, "width") + " ";
		cssStr += getCalculatedProperty(objName, "height") + " ";
		cssStr += "0px)";
		return cssStr;
	    }
	    return cssp;
	}

	if (property == "zIndex") {
	    cssp = docObj.style.zIndex;
	    return (cssp == "") ? "inherit" : cssp;
	}

	cssp = document.defaultView.getComputedStyle
		(docObj, "").getPropertyValue(property);

	return (cssp == "") ? "unknown" : cssp;
    }

    // ***** Netscape Navigator 4+ DOM *****

    if (oldNSdom) {
	docObj = document.layers[objName];

	if (property == "visibility") {
	    cssp = docObj.visibility;
	    return (cssp == "hide") ? "hidden" : (cssp == "show") ?
		 "visible" : "inherit";
	}

	if (property == "clip") {
	    cssStr = "rect(" + docObj.clip.top + "px ";
	    cssStr += docObj.clip.right + "px ";
	    cssStr += docObj.clip.bottom + "px ";
	    cssStr += docObj.clip.left + "px)";
	    return cssStr;
	}

	if ((property == "width") || (property == "height")) {
	    return eval("docObj.clip." + property) + "px";
	}

	if (property == "top") property = "pageY";
	if (property == "left") property = "pageX";

	cssp = eval("docObj." + property);

	if (property != "zIndex") cssp += "px";

	return cssp;
    }

}

/* From scottandrew.com: */
function wdvlAddEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener) {
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    // alert('Handler could not be attached');
    return false;
  }
}

function wdvlRemoveEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

function wdvlEventTarget(e) {
	if (e.toElement) {
		return e.toElement;
	} else if (e.currentTarget) {
		return e.currentTarget;
	} else {
		return null;
	}
}


function getElementsByClass(cls, obj) {
	var a, b, c, i, j, o;

	if (!obj) {
		b = document.getElementsByTagName("body").item(0);
	} else {
		b=obj;
	}
	a = b.getElementsByTagName("*");
	o = new Array();
	j = 0;
	for (i = 0; i < a.length; i++) {
		if (a[i].className == cls) {
			o[j] = a[i];
			j++;
		}
	}
	return o;
}

// wdvlDocumentWidth and wdvlDocumentHeight are based on ideas from
// http://www.quirksmode.org/viewport/compatibility.html
function wdvlDocumentWidth() {
	var test1 = document.body.scrollWidth;
	var test2 = document.body.offsetWidth;
	if (test1 > test2) // all but Explorer Mac
	{
		return document.body.scrollWidth;
	}
	else // Explorer Mac;
	     //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		return document.body.offsetWidth;
	}
}

function wdvlDocumentHeight() {
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight;
	if (test1 > test2) // all but Explorer Mac
	{
		return document.body.scrollHeight;
	}
	else // Explorer Mac;
	     //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		return document.body.offsetHeight;
	}
}

// -------------------------------------------------------------------
// TabNext()
// Function to auto-tab phone field
// Arguments:
//   obj :  The input object (this)
//   event: Either 'up' or 'down' depending on the keypress event
//   len  : Max length of field - tab when input reaches this length
//   next_field: input object to get focus after this one
// -------------------------------------------------------------------
function TabNext(obj,event,len,next_field) {
	var phone_field_length=0;
	if (event == "down") {
		phone_field_length=obj.value.length;
		}
	else if (event == "up") {
		if (obj.value.length != phone_field_length) {
			phone_field_length=obj.value.length;
			if (phone_field_length == len) {
				next_field.focus();
				}
			}
		}
	}
