/*	Base
	All the basic javascript functions we hold dearly.
*/

/* 	Shorthand
*/

function $e(id)
{
	return $(id).get(0);
}

String.prototype.trim = function() {
	return $.trim(this);
}


/* 	XML related functions
*/

function getNodeList(xmlNode, strNodeName, alwaysArray)
{
	var childs = xmlNode.childNodes;
	var nodeList = new Array();

	for(c in childs)
	{
		if(childs[c].nodeName == strNodeName)
			nodeList.push(childs[c]);
	}

	if(nodeList.length > 1 || alwaysArray){
		return nodeList;
	} else {
		return nodeList[0];
	}
}

function getNodeValue(xmlNode, strNodeName){

    if(typeof(xmlNode) != 'array')
	{
		return getNodeList(xmlNode, strNodeName).firstChild.nodeValue;
	} else
	{
		return getNodeList(xmlNode, strNodeName)[0].firstChild.nodeValue;
	}
}

function getNodeAttribute(xmlNode, strNodeName, attName){
	if(typeof(xmlNode) != 'array')
	{
		return getNodeList(xmlNode, strNodeName).attributes[attName].value;
	} else
	{
		return getNodeList(xmlNode, strNodeName)[0].attributes[attName].value;
	}
}


/* 	Pressing Return fires a specific function
*/

function handleKeyPress(e, targetFunction){
	var key=e.keyCode || e.which;

	if (key==13){
		eval(targetFunction);
	}
}
