// xobjectjs , adapted from (C) Shelley Powers, YASD, 1998 - 2000
// Each DOM gets its own object, with similar interfaces but differing implementations
//
// 28fev03 - Removed the clipping stuff, added timer attribute

// The W3C DOM Object
function dom_object(obj) {
	this.css2 = obj;
	this.name = obj.id;
	this.objResizeBy = domResizeBy;
	this.objHide = domHide;
	this.objShow = domShow;
	this.objDisplay = domDisplay;
	this.objGetLeft = domGetLeft;
	this.objGetTop = domGetTop;
	this.objSetTop = domSetTop;
	this.objSetLeft = domSetLeft;
	this.objMoveAbsolute = domMoveAbsolute;
	this.objMoveRelative = domMoveRelative;
	this.objGetWidth = domGetWidth;
	this.objGetHeight = domGetHeight;
	this.objSetHeight = domSetHeight;
	this.objSetWidth = domSetWidth;
	this.objSetZIndex = domSetZIndex;
	this.objGetZIndex = domGetZIndex;
	this.replace_html = domReplaceHTML;
	this.objReplaceHTML = domParamReplaceHTML;
	this.objReplaceText = domReplaceText;
	this.objGetVisibility = domGetVisibility;
	this.objTimer = null;
}

// The IE 4.x, 5.x, and  6.x DOM Object
function ie_object(obj) {
	this.css2 = obj;
	this.name = obj.id;
	this.objResizeBy = domResizeBy;
	this.objHide = domHide;
	this.objShow = domShow;
	this.objDisplay = domDisplay;
	this.objGetLeft = domGetLeft;
	this.objGetTop = domGetTop;
	this.objSetTop = domSetTop;
	this.objSetLeft = domSetLeft;
	this.objMoveAbsolute = domMoveAbsolute;
	this.objMoveRelative = domMoveRelative;
	this.objGetWidth = domGetWidth;
	this.objGetHeight = domGetHeight;
	this.objSetHeight = domSetHeight;
	this.objSetWidth = domSetWidth;
	this.objSetZIndex = domSetZIndex;
	this.objGetZIndex = domGetZIndex;
	this.replace_html = domReplaceHTML;
	this.objReplaceHTML = domParamReplaceHTML;
	this.objReplaceText = domReplaceText;
	this.objGetVisibility = domGetVisibility;
	this.objTimer = null;
}
// The Navigator DOM Object
function ns_object(obj) {
	this.css2 = obj;
	this.name = obj.name;
	this.objResizeBy = domResizeBy;
	this.objHide = nsobjHide;
	this.objShow = nsobjShow;
	this.objDisplay = nsobjDisplay;
	this.objGetLeft = nsobjGetLeft;
	this.objGetTop = nsobjGetTop;
	this.objSetTop = nsobjSetTop;
	this.objSetLeft = nsobjSetLeft;
	this.objMoveAbsolute = domMoveAbsolute;
	this.objMoveRelative = domMoveRelative;
	this.objGetWidth = nsobjGetWidth;
	this.objGetHeight = nsobjGetHeight;
	this.objSetHeight = nsobjSetHeight;
	this.objSetWidth = nsobjSetWidth;
	this.objSetZIndex = nsobjSetZIndex;
	this.objGetZIndex = nsobjGetZIndex;
	this.replace_html = nsreplace_html;
	this.objReplaceHTML = nsParamReplaceHTML;
	this.objReplaceText = nsReplaceText;
	this.objGetVisibility = nsVisibility;
	this.objTimer = null;
}

//*************************************************************************************
//
// The implementations
//
//*************************************************************************************


// The DOM Object Implementations
//
//*************************************************************************************
// rezise
function domResizeBy(wincr,hincr) {
   var wdth = this.objGetWidth();
   wdth += wincr;
   this.objSetWidth(wdth);
   
   var ht = this.objGetHeight();
   ht += hincr;
   this.objSetHeight(ht);
}
// element's left position
function domGetLeft() {
        var lt = parseInt(this.css2.style.left);
	return lt;
}
// element's top position
function domGetTop () {
        var tp = parseInt(this.css2.style.top);
	return tp;
}
// set element's top position
function domSetTop (top) {
	this.css2.style.top = top + "px";
}
// set element's left position
function domSetLeft(left) {
	this.css2.style.left = left + "px";
}
// get element's width
function domGetWidth() {
        var wd = parseInt(this.css2.style.width);
	return wd;
}
// get element's height
function domGetHeight() {
        var ht = parseInt(this.css2.style.height);
	return ht;
}
// set element's height
function domSetHeight(height) {
	this.css2.style.height = height + "px";
}
// set element's width
function domSetWidth(width) {
	this.css2.style.width = width + "px";
}
// hide element
function domHide() {
   this.css2.style.visibility = "hidden";
}
// show element
function domShow() {
   this.css2.style.visibility = "visible";
}
// display element
function domDisplay(type) {
   this.css2.style.display = type;
}
// make absolute move
function domMoveAbsolute(newleft, newtop) {
   this.objSetLeft(newleft);
   this.objSetTop(newtop);
}
// move relative to current location
function domMoveRelative(left, top) {
   this.objSetLeft(left + this.objGetLeft());
   this.objSetTop(top + this.objGetTop());    
}
// set element's zindex order
function domSetZIndex(zindex) {
   this.css2.style.zIndex = zindex;
}
// get element's current zindex order
function domGetZIndex(zindex) {
   return this.css2.style.zIndex;
}
// replace text (equivalent to innerText)
function domReplaceText(txt_string) {
   var nodes = this.css2.childNodes;
   var node = nodes.item(0);
   node.replaceData(0,node.length,txt_string);   
}
// replace html (innerHTML)
function domReplaceHTML(html_string) {
	this.css2.innerHTML = html_string;
} 
// replace HTML -- replace contents with specific object
function domParamReplaceHTML(tag,clss,id,contents) {
    this.objHide();
    var r = this.css2.ownerDocument.createRange();
    r.selectNodeContents(this.css2);
    r.deleteContents();

    var elem = document.createElement(tag);
    elem.setAttribute("id",id);
    elem.setAttribute("className",clss);
    var txt = document.createTextNode(contents);
    elem.appendChild(txt);
    this.css2.appendChild(elem); 
    this.objShow();
  }
// return visibility
function domGetVisibility() {
    return this.css2.style.visibility;
}

// The IE Object Implementations
//
//*****************************************************************************

// replace html (with specific element)
function ieParamReplaceHTML(tag, clss, id, contents) {
    var strng = "<" + tag + " class='" + clss + "' id='" + id + "'>";
    strng = strng + contents;
    strng = strng + "</" + tag +  ">";
    this.css2.innerHTML = strng;
     }

// The Navigator 4.x Object Implementations
//
//*****************************************************************************

// hide element
function nsobjHide() {
	this.css2.visibility = "hidden";
}
// show element
function nsobjShow() {
	this.css2.visibility = "inherit";
}
// element display
function nsobjDisplay(type) {
   if (type == "none")
       this.objHide();
   else
       this.objShow();
}
// element's left position
function nsobjGetLeft() {
	return this.css2.left;
}
// element's top position
function nsobjGetTop () {
	return this.css2.top;
}
// set element's top position
function nsobjSetTop(top) {
	this.css2.top = top;
}
// set element's left position
function nsobjSetLeft(left) {
	this.css2.left = left;
}
// get element's width
function nsobjGetWidth() {
	return this.css2.clip.width;
}
// get element's height
function nsobjGetHeight() {
	return this.css2.clip.height;
}
// set element's width
function nsobjSetWidth(width) {
	this.css2.clip.width = width;
}
// set element's height
function nsobjSetHeight(height) {
	this.css2.clip.height = height;
}
// set element's zindex order
function nsobjSetZIndex(zindex) {
	this.css2.zIndex = zindex;
}
// get element's current zindex order
function nsobjGetZIndex() {
	return this.css2.zIndex;
}
// replace html (navigator)
function nsreplace_html(html_string) {
	this.css2.document.write(html_string);
	this.css2.document.close();
}
// Param replace
function nsParamReplaceHTML(tag, clss, id, contents) {
    var strng = "<" + tag + " class='" + clss + "' id='" + id + "'>";
    strng = strng + contents;
    strng = strng + "</" + tag + ">";
    this.css2.document.write(strng);
    this.css2.document.close();
    }
function nsReplaceText(text_string) {
  // this function not implemented
}
function nsVisibility() {
   return this.css2.visibility;
}


//****************************************************************************************
//
// Create the objects
//
// The result is an array of dom object
//****************************************************************************************


// For IE 4.x, pull all DIV blocks into object array
function create_ie_objects() {
   theelements = document.all.tags("DIV");
   theobjs = new Array();
   for (i = 0; i < theelements.length; i++){
      if (theelements[i].id != "") {
	   theobjs[theelements[i].id] = new ie_object(theelements[i]);
	   }
      }
}

// For Navigator 4.x, pull all DIV blocks into object array
function create_ns_objects(newarray) {
   theobjs = new Array();
   for (i = 0; i < document.layers.length; i++){
     if (document.layers[i].name != "") 
   	 theobjs[document.layers[i].name] = new ns_object(document.layers[i]);
     }
}

// For W3C DOM (Navigator 6.x, Mozilla, IE 6.x), 
// pull all named DIV blocks into an array
function create_dom_objects() {
  theelements = document.getElementsByTagName("DIV");
  theobjs = new Array();
  for (i = 0; i < theelements.length; i++) {
      var obj = theelements[i];
      if (obj.id != "")
         theobjs[obj.id] = new dom_object(obj);
      }
}


function create_objects() {

    // Internet Explorer 4.x, 5.x, 6.x
    if (navigator.appName == "Microsoft Internet Explorer")
	   create_ie_objects();
    else // Navigator or Mozilla
        if (navigator.appName == "Mozilla" || navigator.appName == "Netscape")
           if (navigator.appVersion.indexOf("4.") == -1)
	      create_dom_objects();
           else 
  	      create_ns_objects();
}

//*****************************************************************************
//Helper function
//
//*****************************************************************************

// convert string to value
function convert(strng) {
    var i = parseInt(strng);
    return i;
}
