/**

 * compatibility.js

 *

 * Dit bestand bevat alle minimale javascript om de modules en componenten van edit werkend te houden.

 *

 * @author Martin Borsboom

 */



/**

 * addLoadEvent

 * http://simonwillison.net/2004/May/26/addLoadEvent/

 *

 * Hiermee kan je diverse functies toevoegen aan window.onLoad

 * Onderin dit script worden de functies toegevoegd.

 *

 * voorbeeld:

 * mijnHenkFunctie = myHenk() {

 *    alert('henk is van mij!');

 * }

 * addLoadEvent(mijnHenkFunctie);

 * // myHenk() wordt nu uitgevoerd wanneer de pagina klaar is met laden :)

 *

 * @author Simon Willison

 * @param var func naam van je functie

 */

function addLoadEvent(func) {

	var oldonload = window.onload;

	if (typeof window.onload != 'function') {

		window.onload = func;

	} else {

		window.onload = function() {

			if (oldonload) {

				oldonload();

			}

			func();

		}

	}

}





/**

 * setFocus om de focus in een element te zetten

 */

function setFocus(element) {

	if(element) {

		element.focus();

		moveCaret(element);		

		if(typeof FormGenerator_inputFocus == 'function') { 

			FormGenerator_inputFocus( element );

		}	

		

	}

}



/**

 * moveCaret om de cursor in een textbox te verplaatsen

 *

 * @param element el is het element waarin dit moet gebeuren (moet gefocused)

 * @int pos is de positie van de cursor

 */

function moveCaret(el) {

	

	var pos = el.value.length;

	if(pos < 1) {

		return;

	}

	

	if (document.selection) { 

	 var oSel = document.selection.createRange();

	 oSel.moveEnd ('character', pos);

	 oSel.select();

	}

	else if (el.selectionStart || el.selectionStart == '0') {

	 el.selectionStart = 0;

	 el.selectionEnd = pos;

	}

	

}



/**

 *

 */

function Size(width, height) {

	this.width = width;

	this.height = height;

}



/**

 *

 */

function getBodySize() {

	

  var myWidth = 0; 

	var myHeight = 0;

	

  if( typeof( window.innerWidth ) == 'number' ) {

    myWidth = window.innerWidth;

    myHeight = window.innerHeight;

  } 

	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

    myWidth = document.documentElement.clientWidth;

    myHeight = document.documentElement.clientHeight;

  } 

	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

    myWidth = document.body.clientWidth;

    myHeight = document.body.clientHeight;

  }

	

	return new Size(myWidth, myHeight);

}



/**

 *

 */ 

function getObjectSize(elem) {



	var objectWidth = 0;

	var objectHeight = 0;

	

	objectWidth = elem.offsetWidth;

	objectHeight = elem.offsetHeight;



	return new Size(objectWidth, objectHeight);

}



/** 

 * preloadImg() img proloaden b.v. voor een mouse over

 *

 * @param string img de afbeelding die je wilt preloaden

 */

preloadImg = function ( img ){

	image = new Image()

	image.src = img

}
