// Load a number of images into the browswer cache. So they can be accessed quickly.
// @input 1: an array of filenames of images
// @return: the number of images
function preloadImages(imageArray)
{
	for (i = 0; i < imageArray.length; i++)
	{
		var img = new Image();
		img.src = imageArray[i];
	}
	return imageArray.length;
}



// Checks whether the current frame is the top-frame. If true, redirection to provided URL.
function checkTopFrame(url)
 {
 	if (top == self)
 	{
 		self.location.href = url;
 	}
 }



/**
 * Returns the number of days of a distinct month in a specific year
 * @param int month
 * @param int year
 * @return int number of days
 */
function getDaysPerMonth(year, month)
{
	date = new Date(year, (month + 1), 0);
	return date.getDate();
}



// Read the width of the current window or frame respectively
function getWindowWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		return document.documentElement.clientWidth;
	}
	else if	(document.body && document.body.clientWidth)
	{
		return document.body.clientWidth;
	}
	else
	{
		return 0;
	}
}



// Read the height of the current window or frame respectively
function getWindowHeight()
{
	if (window.innerHeight)
	{
		return window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		return document.documentElement.clientHeight;
	}
	else if	(document.body && document.body.clientHeight)
	{
		return document.body.clientHeight;
	}
	else
	{
		return 0;
	}
}



// Signifies whether an array contains a specific object.
Array.prototype.contains = function(obj)
{
	var i, listed = false;
	for (i = 0; i < this.length; i++)
	{
		if (this[i] === obj)
		{
			listed = true;
			break;
		}
	}
	return listed;
};
