//////////////////////////////////////////////////////////////////////////
//
// NetWerk dhtml Bibliothek
// Autor: NetWerk GmbH
// Version: 1.1
// Datum: 03.05.2006
//
//////////////////////////////////////////////////////////////////////////
/// Update 1.1 (AG): getclass() und setclass()
/// Update 1.2 (MM): dump()
/// Update 1.3 (MM): Array-Object - compatibility with JavaScript 1.6

//////////////////////////////////////////////////////////////////////////
function browserobj() {
	this.ns4=document.layers&&!document.getElementById;
	this.ns6=document.getElementById&&!document.all;
	this.ie4=document.all;
	this.opr=navigator.userAgent.indexOf("Opera")+1;
	
	this.ms = document.all;
	this.ns = document.layers;
	this.dom = document.getElementById;
}
browserobj.prototype.innerWidth = function () {
	if(this.ns || this.opr) return window.innerWidth;
	else return document.body.offsetWidth;
}

var browser = new browserobj();

//////////////////////////////////////////////////////////////////////////
function divobj(id,width,height) {
	this.id = id;
	this.width = width;
	this.height = height;
	this.xpos = 0;
	this.ypos = 0;
}

divobj.prototype.getobject = function () {
	if(browser.dom) {
		if(typeof document.getElementById(this.id) == "object")	return document.getElementById(this.id);
		else return void(0);
	} else if(browser.ms) {
		if (typeof document.all[p2] == "object") return document.all[this.id];
		else return void(0);
	} else if(browser.ns) {
		if (typeof document[p2] == "object") return document[this.id];
		else return void(0);
	} else return void(0);
}

divobj.prototype.setstyle = function (name,value) {
	if(this.getobject()) {
//		if(browser.dom || browser.ms) this.getobject().style.setAttribute(name,value);
		if(browser.dom || browser.ms) this.getobject().style[name] = value;
		else if(browser.ns) this.getobject()[name] = value;
	}
}
divobj.prototype.getstyle = function (name) {
	if(this.getobject()) {
//		if(browser.dom || browser.ms) return this.getobject().style.getAttribute(name);
		if(browser.dom || browser.ms) return this.getobject().style[name];
		else if(browser.ns) return this.getobject()[name];
	}
}
divobj.prototype.setclass = function (value) {
	if(this.getobject()) {
		if(browser.dom || browser.ms) this.getobject().className = value;
		else if(browser.ns) this.getobject()['className'] = value;
	}
}
divobj.prototype.getclass = function () {
	if(this.getobject()) {
		if(browser.dom || browser.ms) return this.getobject().className;
		else if(browser.ns) return this.getobject()['className'];
	}
}
divobj.prototype.show = function () {
	if(browser.ns && !browser.dom) this.setstyle("visibility","show");
	else this.setstyle("visibility","visible");
}
divobj.prototype.visible = function () {
	var value = this.getstyle("visibility");
	if(value=="show" || value=="visible") return true
	else return false;
}
divobj.prototype.hide = function () {
	if(browser.ns && !browser.dom) this.setstyle("visibility","hide");
	else this.setstyle("visibility","hidden");
}
divobj.prototype.hidden = function () {
	var value = this.getstyle("visibility");
	if(value=="hide" || value=="hidden") return true
	else return false;
}
divobj.prototype.moveto = function (x,y) {
	if(x>=0) this.setstyle("left",x+"px");
	if(y>=0) this.setstyle("top",y+"px");
}
divobj.prototype.moveby = function (x,y) {
	this.setstyle("left",this.posx()+x+"px");
	this.setstyle("top",this.posy()+y+"px");
}
divobj.prototype.clip = function (t,r,b,l) {
	this.setstyle("clip","rect("+t+"px,"+r+"px,"+b+"px,"+l+"px)");
}
divobj.prototype.resize = function (w,h) {
	if(w>=0) this.setstyle("width",w+"px");
	if(h>=0) this.setstyle("height",h+"px");
}
divobj.prototype.posx = function () { return parseInt(this.getstyle("left")) }
divobj.prototype.posy = function () { return parseInt(this.getstyle("top")) }
divobj.prototype.posw = function () { return parseInt(this.getstyle("width")) }
divobj.prototype.posh = function () { return parseInt(this.getstyle("height")) }

divobj.prototype.getcontent = function (text) {
	var obj = this.getobject();
	if(obj) {
		if(browser.dom && obj.firstChild) {
			return obj.firstChild.nodeValue;
		}
		if(browser.ms) {
			return obj.innerText;
		}
	}
	return false;
}

divobj.prototype.setcontent = function (text) {
	var obj = this.getobject();
	if(obj) {
		if(browser.dom && obj.firstChild) {
			obj.firstChild.nodeValue = text;
			return true;
		}
		if(browser.ms) {
			obj.innerText = text;
			return true;
		}
		if(browser.ns) {
			obj.document.open();
			obj.document.write(text);
			obj.document.close();
			return true;
		}
	}
	return false;
}

function divobj_help_posx(obj) {
	if(browser.dom) {
		if (obj.offsetParent) return (obj.offsetLeft + divobj_help_posx(obj.offsetParent));
		else return (obj.offsetLeft);
	} else {
		return obj.pageX;
	}
}
function divobj_help_posy(obj) {
	if(browser.dom) {
		if (obj.offsetParent) return (obj.offsetTop + divobj_help_posy(obj.offsetParent));
		else return (obj.offsetTop);
	} else {
		return obj.pageY;
	}
}

//////////////////////////////////////////////////////////////////////////
// Array.prototype.indexOf
// (JavaScript 1.6)
//
if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

//
// Array.prototype.lastindexOf
// (JavaScript 1.6)
//
if (!Array.prototype.lastIndexOf)
{
  Array.prototype.lastIndexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]);
    if (isNaN(from))
    {
      from = len - 1;
    }
    else
    {
      from = (from < 0)
           ? Math.ceil(from)
           : Math.floor(from);
      if (from < 0)
        from += len;
      else if (from >= len)
        from = len - 1;
    }

    for (; from > -1; from--)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

//
// Array.prototype.forEach
// (JavaScript 1.6)
//
if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        fun.call(thisp, this[i], i, this);
    }
  };
}

//
// Array.prototype.filter
// (JavaScript 1.6)
//
if (!Array.prototype.filter)
{
  Array.prototype.filter = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var res = new Array();
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
      {
        var val = this[i]; // in case fun mutates this
        if (fun.call(thisp, val, i, this))
          res.push(val);
      }
    }

    return res;
  };
}

//
// Array.prototype.map
// (JavaScript 1.6)
//
if (!Array.prototype.map)
{
  Array.prototype.map = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var res = new Array(len);
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        res[i] = fun.call(thisp, this[i], i, this);
    }

    return res;
  };
}

//
// Array.prototype.some
// (JavaScript 1.6)
//
if (!Array.prototype.some)
{
  Array.prototype.some = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this &&
          fun.call(thisp, this[i], i, this))
        return true;
    }

    return false;
  };
}

//
// Array.prototype.every
// (JavaScript 1.6)
//
if (!Array.prototype.every)
{
  Array.prototype.every = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this &&
          !fun.call(thisp, this[i], i, this))
        return false;
    }

    return true;
  };
}

//////////////////////////////////////////////////////////////////////////
// Dump array/hash/object
// inspired by the print_r function of PHP
//
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
 for(var item in arr) {
  var value = arr[item];
 
  if(typeof(value) == 'object') { //If it is an array,
   dumped_text += level_padding + "'" + item + "' ...\n";
   dumped_text += dump(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  }
 }
} else { //Stings/Chars/Numbers etc.
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
}
