// SimpleAPI
// set of functions for easily manipulating layers, a simple alternative to using the DynLayer
// 19990326

// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/

// warning: these have not been test, please email me a fix if there's any problems

// get the style object reference
function getObject(id,nestref) {

	if (is.ns) {
	 if (is.v >= 5) {
		return document.getElementById (id);
	 } else {
	   //return (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document;
	   return document.layers[id].document;
	 }
	}
	if (is.ie) return document.all[id].style;
}

// get the element object reference
function getElement(id,nestref) {
	if (is.ns) return getObject(id,nestref)
	if (is.ie) return document.all[id]
}

// get the element object reference
/**
function getDOMElement(id) {
  if (is.ns && is.v < 5) { return document.layers[id]; } else
  if (is.ie) { return document.all[id]; }
  return document.getElementById (id);
}
**/

// get the element object reference
function getDOMElement(id) {
  if (document.getElementById)   return document.getElementById (id);
  if (document.layers) { 
     return document.layers[id]; 
  } else if (document.all) { 
    return document.all[id]; 
  }

  return null;

}



// show and hide functions
function show(obj) {
  if (is.ns && is.v < 5) obj.visibility = "show"
  else if (is.ns && is.v >= 5) obj.style.visibility = "visible"
  else if (is.ie) obj.visibility = "visible"
}
function hide(obj) {
  if (is.ns && is.v < 5) obj.visibility = "hide"
  else if (is.ns && is.v >= 5) obj.style.visibility = "hidden"
  else if (is.ie) obj.visibility = "hidden"
}

// movement functions
function getX(obj) {
	if (is.ns) return obj.css.left
	else return obj.css.pixelLeft
}
function getY(obj) {
	if (is.ns) return obj.css.top
	else return obj.css.pixelTop
}
function setX(obj,x) {
	if (is.ns) obj.css.left = x
	else obj.css.pixelLeft = x
}
function setY(obj,y) {
	if (is.ns) obj.css.top = y
	else obj.css.pixelTop = y
}
function moveTo(obj,x,y) {
	if (x!=null) setX(obj,x)
	if (y!=null)setY(obj,y)
}
function moveBy(obj,x,y) {
	setX(obj,getX(obj)+x)
	setY(obj,getY(obj)+y)
}

function resizeLayer (id) {
  var obj;

  if (is.ns && is.v < 5) {
    obj = document.layers[id];
  } else {
    obj = document.getElementById (id);
  }

  if (is.ns && is.v < 5) {
    /*alert (obj.clip.width + " " + obj.clip.height);
    alert (obj.);
    obj.clip.width = obj.width;
    obj.clip.height = obj.height;*/
    //obj.resizeTo (obj.clip.width, obj.clip.height);
    alert (obj.toSource());
    //obj.resizeBy (0,0);
  }
}

// layer write function
function layerWrite(elm,text) {  // use getElement()    
  if (is.ns && is.v < 5) {
    elm.open();
    elm.write(text);
    elm.close();
  }
  else elm.innerHTML = text
}

// background color
function setbg(obj,color) {
	if (is.ns) obj.document.bgColor = color
	else obj.backgroundColor = color
}

function setStyle (id_or_obj, name, value)
{
  var obj = null;

  //  window.status = "TYPE: " + typeof(id_or_obj);

  if (typeof(id_or_obj) == 'string') 
    obj =  getDOMElement (id_or_obj);
  else
    obj = id_or_obj;
  
  if (obj && obj.style)	
    {
      obj.style[name] = value;
    }
}

