// 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.objGetPageLeft = domGetPageLeft;
	this.objGetTop = domGetTop;
	this.objGetPageTop = domGetPageTop;
	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.objSetClipRect = domSetClipRect;
	this.objGetClipRect = domGetClipRect;
	this.objGetClipLeft = domGetClipLeft;
	this.objGetClipRight = domGetClipRight;
	this.objGetClipTop = domGetClipTop;
	this.objGetClipBottom = domGetClipBottom;
	this.replace_html = domReplaceHTML;
	this.objReplaceHTML = domParamReplaceHTML;
	this.objReplaceText = domReplaceText;
	this.objGetVisibility = domGetVisibility;
}


// The DOM Object Implementations
//
//*************************************************************************************


function domResizeBy(wincr,hincr) {
   var wdth = this.objGetWidth();
   wdth += wincr;
   this.objSetWidth(wdth);
   
   var ht = this.objGetHeight();
   ht += hincr;
   this.objSetHeight(ht);
}

// elements page left position
function domGetPageLeft()
{
	var x = 0;
	x = parseInt(this.offsetLeft);
	return x;
}
	
// elements page top position
function domGetPageTop()
{
	var y = 0;	
	y = parseInt(this.offsetTop);
	return y;
}

// 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());    
}

// return clipping rectangle
function domGetClipRect() {
   return this.css2.style.clip;
}

// clip object
function domSetClipRect(top, left, bottom, right) {
   if (top == null) top = this.objGetClipTop();
   if (left == null) left = this.objGetClipLeft();
   if (bottom == null) bottom = this.objGetClipBottom();
   if (right == null) right = this.objGetClipRight();
   strng = "rect(" + top + "px, " + right + "px, " + bottom + "px, " + left + "px)";
  this.css2.style.clip = strng;
}

// convert string to value
function convert(strng) {
    var i = parseInt(strng);
    return i;
}

// get clipping value for specific dimension
function get_entry(obj,indx) {
	strng = obj.css2.style.clip;
        if (strng.length > 0) {
	   strng = strng.slice(5,strng.length-1);
	   var entries = strng.split(" ");
           }
        else {
            var entries = new Array(5);
            for (i = 0; i < entries.length; i++)
                entries[i] = "auto";
            }
	if (indx == "top") {
		if (entries[0] == "auto") 
                   return 0;
		else
		   return convert(entries[0]);
            }
	else if (indx == "left") {
		if (entries[3] == "auto") 
		   return 0;
		else
		   return convert(entries[3]);
		}
	else if (indx == "bottom"){
		if (entries[2] == "auto") {
		   return obj.objGetHeight();
                   }
		else
		   return convert(entries[2]);
              }
	else if (indx == "right") {
		if (entries[1] == "auto") 
		   return obj.objGetWidth();
		else
		   return convert(entries[1]);
		}
	
}
	
// clip object on left
function domGetClipLeft() {
	return get_entry(this,"left");
}

// clip object on right
function domGetClipRight() {
	return get_entry(this, "right");
}

// clip object at top
function domGetClipTop() {
	return get_entry(this,"top");
}

// clip object at bottom
function domGetClipBottom() {
	return get_entry(this,"bottom");
}

// 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 (equivalent to innerHTML)
function domReplaceHTML(html_string) {

 // not implemented yet 
    
  }

// 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;
}


