/*
	TODO
	diese in den Quelltexten ersetzen durch bindOn (s.u.)
*/

Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    __method.call(object, event);
  }
}

Function.prototype.bindOnParameter = function(object) {
  var __method = this;
  var __args = arguments;
  return function(event) {
    __method.call(object, event, __args);
  }
}

Array.prototype.contains = function (element) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == element) {
      return true;
    }
  }
  return false;
};

function $(id) {
  return document.getElementById(id);
}


/*
neuer Kram
*/

Function.prototype.bindOn = function(object) {
  var __method = this;
  return function(event) {
    __method.call(object, event);
  }
}

function log(msg) {
  if ((typeof opera) != 'undefined') {
    opera.postError(msg);
  } else if ((typeof console) != 'undefined') {
  	if (console.log) {
    	console.log(msg);
    }
  }
}

Date.prototype.isBefore = function(otherDate) {
  var myMillis = this.getTime();
  var otherMilis = otherDate.getTime();
  return myMillis < otherMilis;
}


function addEvent(obj, eventName, handler) {
  if (obj.addEventListener) {
    obj.addEventListener(eventName, handler, false);
    return true;
  }
  if (obj.attachEvent) {
    return obj.attachEvent('on' + eventName, handler);
  }
  return false;
}

// http://www.quirksmode.org/js/findpos.html
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	return [curleft,curtop];
}

// http://www.quirksmode.org/viewport/compatibility.html
function findWinDim() {
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	
	return[x, y];
}

function check_height_fits(id) {
	var e = document.getElementById(id);
	if(e && e.clientHeight < (findWinDim()[1] - findPos(e)[1]) ) {
		return true;
	}
	return false;
}

