var _imagesUrl = 'http://images.myschool.lu/imageserver/Portlets/Gyana/Images/';
if (!window.gyanaPopup)
{
	function gyanaPopup(url, name, width, height)
	{
		var win = window.open(url, name, 'width=' + width + ', height=' + height + ',scrollbars=yes,resizable=yes');
		win.opener = top;
		win.moveTo(Math.max(0, Math.round((screen.width-width) / 2)), Math.max(0, Math.round((screen.height-height) / 2)));
		win.focus();
	}
}
if (!window.XMLHttpRequest)
{
	window.XMLHttpRequest = function()
	{
		var xmlHttp = null;
		var ex;
		try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0"); } catch (ex)
		{
			try { xmlHttp = new ActiveXObject("MSXML2.XMLHTTP"); } catch (ex)
			{
				try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (ex){}
			}
		}
		return xmlHttp;
	}
}
if (!window.parseXML)
{
	window.parseXML = function(strXML)
	{
		try //Internet Explorer
		{
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async = "false";
			xmlDoc.loadXML(strXML);
			return xmlDoc;
		}
		catch(e)
		{
			try //Firefox, Mozilla, Opera, etc.
			{
				parser = new DOMParser();
				xmlDoc = parser.parseFromString(strXML, "text/xml");
				return xmlDoc;
			}
			catch(e)
			{
				alert(e.message);
				return null;
			}
		}
	}
}
if (!window.XBrowserAddHandler)
{
	function XBrowserAddHandler(target, eventName, handlerName)
	{ 
		if (target.addEventListener)
			target.addEventListener(eventName, function(e) {target[handlerName](e);}, false);
		else if (target.attachEvent)
			target.attachEvent('on'+eventName, function(e) {target[handlerName](e);});
		else
		{ 
			var originalHandler = target['on'+eventName]; 
			if (originalHandler)
				target['on'+eventName] = function(e) {originalHandler(e);target[handlerName](e);}; 
			else
				target['on'+eventName] = target[handlerName]; 
		} 
	}
}
if (!window.toggleSection)
{
	function toggleSection(sectionName, persistentFieldId)
	{
		if (!persistentFieldId || persistentFieldId == null)
			persistentFieldId = 'hdn' + sectionName + 'Expanded';
			
		var isExpanded = !($(persistentFieldId).value == 'true');

		$('div' + sectionName + 'Content').style.display = (isExpanded) ? 'block' : 'none';
		$('img' + sectionName + 'RightIcon').src = _imagesUrl + ((isExpanded) ? 'minuB16px.png' : 'plusB16px.png');
		$('div' + sectionName + 'Header').style.marginBottom = (isExpanded) ? '0px' : '12px';

		$(persistentFieldId).value = isExpanded;
	}
}
if (!window.setFloat)
{
	function setFloat(element, cssFloat)
	{
		if (document.all) // IE
			element.style.styleFloat = cssFloat;
		else
			element.style.cssFloat = cssFloat;
	}
}
if (!window.removeChildNodes)
{
	function removeChildNodes(parentId)
	{
		while ($(parentId).childNodes.length>0)
			$(parentId).removeChild($(parentId).childNodes[0]);
	}
}
if (!window.escapeHTML)
{
	function escapeHTML(str)
	{
		 var div = document.createElement('div');
		 var text = document.createTextNode(str);
		 div.appendChild(text);
		 return div.innerHTML;
	};
}
if (!window.getUrlParameter)
{
	function getUrlParameter(name)
	{
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = '[\\?&]' + name + '=([^&#]*)';
		var regex = new RegExp(regexS);
		var results = regex.exec(window.location.href);
		return (results != null) ? results[1] : '';
	}
}
if (!window.createDiv)
{
	function createDiv(width, cssFloat, text, styles)
	{
		var div = document.createElement('div');
		
		if (width != null)
			div.style.width = width;
		
		if (cssFloat != null)
			setFloat(div, cssFloat);
		
		if (text != null)
			div.appendChild(document.createTextNode(text));

		if (styles)
			for (var name in styles)
				eval('div.style.' + name + ' = \'' + styles[name] + '\'');
		
		return div;
	}
}
if (!window.getMouseCoordinates)
{
	function getMouseCoordinates(e) // works on IE6,FF,Moz,Opera7
	{
		if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

		if (e)
		{
			if (e.pageX || e.pageY)
			{ // this doesn't work on IE6!! (works on FF,Moz,Opera7)
				return { x : e.pageX, y : e.pageY };
			}
			else if (e.clientX || e.clientY)
			{ // works on IE6,FF,Moz,Opera7
				return { x : e.clientX + document.body.scrollLeft, y : e.clientY + document.body.scrollTop };
			}
		}
	} 
}
if (!window.showFloatingResource)
{
	function showFloatingResource(event, divId)
	{
		var coords = getMouseCoordinates(event);
		
		$(divId).style.left = (coords.x + 10) + 'px';
		$(divId).style.top = (coords.y - 20) + 'px';
		$(divId).style.display = 'block';
	}

	function hideFloatingResource(divId)
	{
		$(divId).style.display = 'none';
	}
}
if (!window.createImageButton)
{
	function createImageButton(imageUrl, toolTip)
	{
		var btn = document.createElement('img');
		btn.src = imageUrl;
		btn.style.cursor = 'pointer';
		btn.style.marginLeft = '3px';
		btn.setAttribute('alt', toolTip);
		btn.setAttribute('title', toolTip);
		
		return btn;
	}
}
if (!window.setAlternateClassNames)
{
	function setAlternateClassNames(listName, baseClass)
	{
		var items = $(listName).getElementsByTagName('li');
		for (var i = 0, j = 0; i < items.length; i++)
			if (items[i].className.indexOf(baseClass) == 0)
			{
				var className = (j++ % 2 != 0) ? baseClass : baseClass + '_Alternate';
				items[i].className = className;
				items[i].originalClassName = className;
			}
	}
}
if (!window.getViewportSize)
{
	function getViewportSize()
	{
		var viewport = { width : 0, height : 0 };

		// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
		if (typeof window.innerWidth != 'undefined')
		{
			viewport.width = window.innerWidth,
			viewport.height = window.innerHeight
		}
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
		{
			viewport.width = document.documentElement.clientWidth,
			viewport.height = document.documentElement.clientHeight
		}
		// older versions of IE
		else
		{
			viewport.width = document.getElementsByTagName('body')[0].clientWidth,
			viewport.height = document.getElementsByTagName('body')[0].clientHeight
		}
		
		return viewport;
	}
}
if (!window.removeFromArray)
{
	function removeFromArray(array, value)
	{
		var i = 0;
		
		while (i < array.length && array[i] != value)
			i++;
			
		if (i < array.length)
			array.splice(i, 1);
	}
}
if (!window.arrayContains)
{
	function arrayContains(array, value)
	{
		for (var i = 0; i < array.length; i++)
			if (array[i] == value)
				return true;
				
		return false;
	}
}
document.getElementsByClassName = function(className, parentElement) {
  if (Prototype.BrowserFeatures.XPath) {
    var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]";
    return document._getElementsByXPath(q, parentElement);
  } else {
    var children = ($(parentElement) || document.body).getElementsByTagName('*');
    var elements = [], child;
    for (var i = 0, length = children.length; i < length; i++) {
      child = children[i];
      if (Element.hasClassName(child, className))
        elements.push(Element.extend(child));
    }
    return elements;
  }
};