/**
 * LICENSE
 *
 * This source file is subject to the EWS Software License that is bundled
 * with this package in the file LICENSE.txt.
 * If you did not receive a copy of the license please send us an email
 * so we can send you a copy immediately.
 * Permission to copy and distribute verbatim copies of this source
 * are not granted.
 *
 * @copyright 	Copyright (c) 2008-2009 entrance web studio
 * @license	EWS Software License
 */

/**
 * Global javascript file.
 *
 * Defines some important functions for global access
 */

/**
  * Includes a javascript file.
  *
  * @param String file
  * @return void
  */
function include ( file ) {
	var head = document.getElementsByTagName ( "head" ) [ 0 ];
	
	// create new script tag
	var script = document.createElement ( "script" );
  script.setAttribute ( "type" , "text/javascript" );
  script.setAttribute ( "src" , file );

	head.appendChild ( script );
}


/**
 * Pseudo factory method to create elements.
 *
 * @param String element
 * @param Object properties
 * @return HTMLElement elem
 */
function createElement ( tagName , properties ) {
	var elem = document.createElement ( tagName );
	
	if ( ! elem )
		throw new Error ( "Cannot create DOM node. Invalid tag name supplied" );
	
	if ( properties != undefined ) {
		for ( var key in properties )
			elem.setAttribute ( key , properties [ key ] );
	}
	
	return elem;
}
