// An enum that holds for the event types
var EventType = 
{
	Alarm : "alarm",
	TechnicalAlarm : "technisch",
	FireAlarm : "brand",
	Exercise : "uebung",
	Youth : "jugend",
	Appointment : "termin",
	News : "news"
};

// An enum that holds for the event types
var MonthNumber2text = 
{
	0 : "Jänner",
	1 : "Februar",
	2 : "März",
	3 : "April",
	4 : "Mai",
	5 : "Juni",
	6 : "Juli",
	7 : "August",
	8 : "September",
	9 : "Oktober",
	10 : "November",
	11 : "Dezember"
};

var WeekdayNumber2text =
{
	0 : "Sonntag",
	1 : "Montag",
	2 : "Dienstag",
	3 : "Mittwoch",
	4 : "Donnerstag",
	5 : "Freitag",
	6 : "Samstag"
}


// 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;
 	}
 }


function showLoadInfo()
{
	parent.frames[0].document.getElementById('loadinfo').style.visibility = 'visible';
}
function hideLoadInfo()
{
	parent.frames[0].document.getElementById('loadinfo').style.visibility = 'hidden';
}

/**
 * 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;
	}
}



function scrollToElement(theElement)
{
  var selectedPosX = 0;
  var selectedPosY = 0;

  while(theElement != null)
  {
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }

 window.scrollTo(selectedPosX,selectedPosY);
}



// 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;
};

// Calculates the intersection of two arrays
Array.prototype.intersect = function(arr)
{
	var i;
	var newArray = new Array();
	for (i = 0; i < arr.length; i++)
	{
		if (this.contains(arr[i]))
		{
			newArray.push(arr[i]);
		}
	}
	return newArray;
};

