// CSS-Management

function isIE()	{ //	Wird die aktuelle Seite im Internet Explorer angezeigt?
	var isIE = (-1 != navigator.userAgent.indexOf('MSIE'));
	document.cookie = 'isIE=' + (isIE ? 'true' : 'false');
	return isIE;
} // function

function isWindows() { // Wird die aktuelle Seite unter Windows angezeigt?
	var isWindows = (-1 != navigator.appVersion.indexOf('Win'));
	document.cookie = 'isWindows=' + (isWindows ? 'true' : 'false');
	return isWindows;
} // function
	
function initCustomFont() {
	if (isWindows()) {
		var newCSS = document.createElement('link');
		
		newCSS.href = 'styles/windows.css';
		newCSS.rel = 'stylesheet';
		newCSS.type = 'text/css';
		
		document.body.appendChild(newCSS);
	} // if
		
	if (isIE()) {
		document.getElementById('IE').style.display = 'block';
	} // if
} // function

function initBrowserSystem() {
	isWindows();
	isIE();

	window.location = 'rf-2010/index.php';
} // function

// AJAX

var FINISHED = 4;

function initAJAX() {
	// Initiiere XMLHttp-Objekt
	if (window.XMLHttpRequest) { // IE7+, Firefox, Chrome, Opera, Safari
		xmlHTTP = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE6, IE5
		xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	} else { // alle anderen
		alert('In Ihrem Browser unterstützt leider kein AJAX.');
	} // if
	
	return xmlHTTP;
} // function

// Blog-Bearbeitung

function blogItemEdit(_id) {
	var blog = document.getElementById('blog-item-' + _id);
	
	xmlHTTP = initAJAX();

	xmlHTTP.onreadystatechange = function() {
		if (FINISHED == xmlHTTP.readyState) {
			blog.innerHTML = xmlHTTP.responseText;
			return false;
		} // if
	} // inline function
	
	xmlHTTP.open('GET', 'scripts/blogItemEdit.php?id=' + _id, true);
	xmlHTTP.send(null);
	
	return false;
} // function
	
function blogItemNew(_id) {
	var blog = document.getElementById('content');
	
	xmlHTTP = initAJAX();

	xmlHTTP.onreadystatechange = function() {
		if (FINISHED == xmlHTTP.readyState) {
			blog.innerHTML = xmlHTTP.responseText;
			return blogItemEdit(_id);
		} // if
	} // inline function
	
	xmlHTTP.open('GET', 'scripts/blogItemNew.php', true);
	xmlHTTP.send(null);
	
	return false;
} // function

function blogItemDelete(_id) {
	var blog = document.getElementById('content');

	var blogTitle = document.getElementById('blog-item-title-' + _id).value;

	if (confirm('Soll der Eintrag „' + blogTitle + '” wirklich gelöscht werden?')) {
		xmlHTTP = initAJAX();
	
		xmlHTTP.onreadystatechange = function() {
			if(FINISHED == xmlHTTP.readyState) {
				blog.innerHTML = xmlHTTP.responseText;
			} // if
		} // inline function
		
		xmlHTTP.open('GET', 'scripts/blogItemDelete.php?id=' + _id, true);
		xmlHTTP.send(null);
	} // if
	
	return false;
} // function

function blogItemCancel(_id) {
	var blog = document.getElementById('blog-item-' + _id);
	
	xmlHTTP = initAJAX();

	xmlHTTP.onreadystatechange = function() {
		if (FINISHED == xmlHTTP.readyState) {
			blog.innerHTML = xmlHTTP.responseText;
			return false;
		} // if
	} // inline function
	
	xmlHTTP.open('GET', 'scripts/blogItemShow.php?id=' + _id, true);
	xmlHTTP.send(null);
	
	return false;
} // function

function blogItemSave(_id) {
	var blog = document.getElementById('content');

	var blogTitle = document.getElementById('blog-item-title-' + _id).value;
	var blogDate = document.getElementById('blog-item-date-' + _id).value;
	var blogText = document.getElementById('blog-item-text-' + _id).value;

	xmlHTTP = initAJAX();

	xmlHTTP.onreadystatechange = function() {
		if (FINISHED == xmlHTTP.readyState) {
			blog.innerHTML = xmlHTTP.responseText;
			return false;
		} // if
	} // inline function
	
	xmlHTTP.open('GET', 'scripts/blogItemSave.php?id=' + _id +
												'&title=' + escape(blogTitle) +
												'&date=' + blogDate +
												'&text=' + escape(blogText), true);
	xmlHTTP.send(null);
	
	return false;
} // function

// Kontaktformular

function checkMailForm() {
	var y = false;
	
	var form = document.getElementById('contact-form');

	var formName = document.getElementById('name');
	var formMail = document.getElementById('mail');
	var formText = document.getElementById('text');

	formName.style.border = '#666 2px solid';
	formMail.style.border = '#666 2px solid';
	formText.style.border = '#666 2px solid';

	if ('' == formText.value) {
		y = true; formText.style.border='#f60 2px solid'; formText.focus();
	} // if

	if ('' == formMail.value) {
		y = true; formMail.style.border='#f60 2px solid'; formMail.focus();
	} // if

	if ('' == formName.value) {
		y = true; formName.style.border='#f60 2px solid'; formName.focus();
	} // if
		
	if (true == y) {
		showContactError();
		return false;
	} // if

	xmlHTTP = initAJAX();

	xmlHTTP.onreadystatechange = function() {
		if (FINISHED == xmlHTTP.readyState) {
			form.innerHTML = '<p style="color:#6f0;margin-left:5px">Ihre Nachricht wurde gesendet. Vielen Dank!</p>';
			return false;
		} // if
	} // inline function
	
	xmlHTTP.open('GET', 'scripts/mailform.php?name=' + escape(formName.value) +
												'&mail=' + formMail.value +
												'&text=' + escape(formText.value), true);
	xmlHTTP.send(null);

	return false;
} // function

function showContactError() {
	var errorDiv = document.getElementById('mailform-error');

	var maxWidth = 200;		//	Maximalbreite des errorDivs
	var maxHeight = 95;		//	Maximalhöhe des errorDivs

	var leftMargin = 20;	//	Um's errorDiv richtig zu zentrieren

	var height = 550;	//isIE() ? document.documentElement.clientHeight : window.innerHeight;
	var width = isIE() ? document.documentElement.clientWidth : window.innerWidth;
	var scroll = isIE() ? document.documentElement.scrollTop : window.pageYOffset;

	errorDiv.style.left = (((width - maxWidth) / 2) - leftMargin) + 'px';
	errorDiv.style.top = (((height - maxHeight) / 2) + scroll) + 'px';
	errorDiv.style.width = maxWidth + 'px';
	errorDiv.style.height = maxHeight + 'px';

	errorDiv.style.visibility = 'visible';	
} // function
	
function hideContactError() {
	var errorDiv = document.getElementById('mailform-error');

	errorDiv.style.visibility = 'hidden';	
} // function
	
// Musik

function sortMusicList(_table, _sort)
	{
	var tbody = document.getElementById('music-list-' + _table);
	
	xmlHTTP = initAJAX();

	xmlHTTP.onreadystatechange = function()
		{
		if (FINISHED == xmlHTTP.readyState)
			{
			tbody.innerHTML = xmlHTTP.responseText;
			var count = document.getElementById(_table + '-count');
			
			xmlHTTP = initAJAX();
			
			xmlHTTP.onreadystatechange = function()
				{
				if (FINISHED == xmlHTTP.readyState)
					{
					count.innerHTML = xmlHTTP.responseText;
					return false;
					}
				}
			
			xmlHTTP.open('GET', 'scripts/musicItemListCount.php?table=' + _table + '&sort=' + _sort, true);
			xmlHTTP.send(null);
			}
		}
	
	xmlHTTP.open('GET', 'scripts/musicItemList.php?table=' + _table + '&sort=' + _sort, true);
	xmlHTTP.send(null);

	return false;
} // function
	
function filterMusicList(_table, _filter, _value)
	{
	var tbody = document.getElementById('music-list-' + _table);

	xmlHTTP = initAJAX();

	xmlHTTP.onreadystatechange = function()
		{
		if (FINISHED == xmlHTTP.readyState)
			{
			tbody.innerHTML = xmlHTTP.responseText;

			var count = document.getElementById(_table + '-count');
			
			xmlHTTP = initAJAX();
			
			xmlHTTP.onreadystatechange = function()
				{
				if (FINISHED == xmlHTTP.readyState)
					{
					count.innerHTML = xmlHTTP.responseText;
					return false;
					}
				}
			
			xmlHTTP.open('GET', 'scripts/musicItemListCount.php?table=' + _table + '&filter=' + _filter + '&value=' + escape(_value), true);
			xmlHTTP.send(null);
			}
		}
	
	xmlHTTP.open('GET', 'scripts/musicItemList.php?table=' + _table + '&filter=' + _filter + '&value=' + escape(_value), true);
	xmlHTTP.send(null);

	return false;
} // function
	
function clearMusicFilter(_table)
	{
	xmlHTTP = initAJAX();

	xmlHTTP.onreadystatechange = function()
		{
		if (FINISHED == xmlHTTP.readyState)
			return sortMusicList(_table, null);
		}
	
	xmlHTTP.open('GET', 'scripts/clearMusicFilter.php?table=' + _table, true);
	xmlHTTP.send(null);

	return false;
} // function

function editMusicInfo(_table, _id)
	{
	var maxWidth = 765;		//	Maximalbreite des infoDivs
	var maxHeight = (_table == 'compositions' ? 925 : 995);		//	Maximalhöhe des infoDivs

	var leftMargin = 20;	//	Um's infoDiv richtig zu zentrieren
	var topMargin = 40;	//	Um's infoDiv etwas weiter oben zu positionieren

	xmlHTTP = initAJAX();

	xmlHTTP.open('GET', 'scripts/musicItemEdit.php?musicList=' + _table + '&id=' + _id, true);

	xmlHTTP.onreadystatechange = function()
		{
		if(xmlHTTP.readyState == 4)
			{
			var infoDiv = document.getElementById('info-page');
		
			var height = isIE() ? document.documentElement.clientHeight : window.innerHeight;
			var width = isIE() ? document.documentElement.clientWidth : window.innerWidth;
			var scroll = isIE() ? document.documentElement.scrollTop : window.pageYOffset;
		
			infoDiv.style.left = (((width - maxWidth) / 2) - leftMargin) + 'px';
			infoDiv.style.top = (((height - maxHeight) / 2) + scroll - topMargin) + 'px';
			infoDiv.style.width = maxWidth + 'px';
			infoDiv.style.height = maxHeight + 'px';
		
			infoDiv.innerHTML = xmlHTTP.responseText;
		
			infoDiv.style.visibility = 'visible';
			}
		}
	
	xmlHTTP.send(null);
} // function

function musicItemNew(_table, _id)
	{
	var tbody = document.getElementById('music-list-' + _table);

	xmlHTTP = initAJAX();

	xmlHTTP.onreadystatechange = function()
		{
		if (FINISHED == xmlHTTP.readyState)
			{
			tbody.innerHTML = xmlHTTP.responseText;
			return editMusicInfo(_table, _id);
			}
		}
	
	xmlHTTP.open('GET', 'scripts/musicItemNew.php?musicList=' + _table, true);
	xmlHTTP.send(null);

	return false;
} // function

function musicItemDelete(_table, _id)
	{
	if(_table == 'compositions')
		var sort = 'opus';
	else
		var sort = 'released';

	var musicTitle = document.getElementById('music-item-title').value;

	if(confirm('Soll der Eintrag „' + musicTitle + '” wirklich gelöscht werden?'))
		{
		var tbody = document.getElementById('music-list-' + _table);
	
		xmlHTTP = initAJAX();
	
		xmlHTTP.onreadystatechange = function()
			{
			if (FINISHED == xmlHTTP.readyState)
				{
				tbody.innerHTML = xmlHTTP.responseText;
				return false;
				}
			}
		
		xmlHTTP.open('GET', 'scripts/musicItemDelete.php?musicList=' + _table + '&id=' + _id, true);
		xmlHTTP.send(null);

		hideMusicInfo();
		}

	return false;
} // function

function musicItemSave(_table, _id)
	{
	if(_table == 'compositions')
		var sort = 'opus';
	else
		var sort = 'released';

	var musicOpus = musicNo = musicReleased = musicComposer = musicFilename = '';

	if(_table == 'compositions')
		{
		musicOpus = '&opus=' + document.getElementById('music-item-opus').value;
		musicNo = '&no=' + document.getElementById('music-item-no').value;
		}
	else
		{
		musicReleased = '&released=' + document.getElementById('music-item-released').value;
		musicComposer = '&composer=' + document.getElementById('music-item-composer').value;
		musicFilename = '&filename=' + document.getElementById('music-item-filename').value;
		}
	
	var musicTitle = document.getElementById('music-item-title').value;
	var musicCast = document.getElementById('music-item-cast').value;
	var musicInstrumentation = document.getElementById('music-item-instrumentation').value;
	var musicGenre = document.getElementById('music-item-genre').value;
	var musicDifficulty = document.getElementById('music-item-difficulty').value;
	var musicPublisher = document.getElementById('music-item-publisher').value;
	var musicOrderNumber = document.getElementById('music-item-order_number').value;
	var musicLink = document.getElementById('music-item-link').value;
	var musicInfo =  document.getElementById('music-item-info').value;

	var tbody = document.getElementById('music-list-' + _table);

	xmlHTTP = initAJAX();

	xmlHTTP.onreadystatechange = function()
		{
		if (FINISHED == xmlHTTP.readyState)
			{
			tbody.innerHTML = xmlHTTP.responseText;
			return false;
			}
		}

	xmlHTTP.open('GET', 'scripts/musicItemSave.php?musicList=' + _table +
															'&id=' + _id +
															'&title=' + escape(musicTitle) +
															'&cast=' + escape(musicCast) +
															'&instrumentation=' + escape(musicInstrumentation) +
															'&genre=' + escape(musicGenre) +
															'&difficulty=' + musicDifficulty +
															'&publisher=' + escape(musicPublisher) +
															'&order_number=' + musicOrderNumber +
															'&link=' + escape(musicLink) +
															'&info=' + escape(musicInfo) +
															musicOpus + musicNo + musicReleased + musicComposer + musicFilename
															, true);
//'&text=' + escape(formText.value)
	xmlHTTP.send(null);

	hideMusicInfo();

	return false;
} // function

function showMusicInfo(_table, _id)
	{
	var maxWidth = 875;		//	Maximalbreite des infoDivs
	var maxHeight = 885;	//	Maximalhöhe des infoDivs

	var leftMargin = 20;	//	Um's infoDiv richtig zu zentrieren
	var topMargin = 100;	//	Um's infoDiv etwas weiter oben zu positionieren

	xmlHTTP = initAJAX();

	xmlHTTP.open('GET', 'scripts/musicItemInfo.php?musicList=' + _table + '&id=' + _id, true);

	xmlHTTP.onreadystatechange = function()
		{
		if(xmlHTTP.readyState == 4)
			{
			var infoDiv = document.getElementById('info-page');
		
			var height = isIE() ? document.documentElement.clientHeight : window.innerHeight;
			var width = isIE() ? document.documentElement.clientWidth : window.innerWidth;
			var scroll = isIE() ? document.documentElement.scrollTop : window.pageYOffset;
		
			infoDiv.style.left = (((width - maxWidth) / 2) - leftMargin) + 'px';
			infoDiv.style.top = (((height - maxHeight) / 2) + scroll - topMargin) + 'px';
			infoDiv.style.width = maxWidth + 'px';
			infoDiv.style.height = maxHeight + 'px';
		
			infoDiv.innerHTML = xmlHTTP.responseText;
		
			infoDiv.style.visibility = 'visible';	
			}
		}
	
	xmlHTTP.send(null);
} // function

function hideMusicInfo()
	{
	var infoDiv = document.getElementById('info-page');
	
	infoDiv.style.visibility = 'hidden';
	infoDiv.innerHTML = null;
	
	return false;
} // function
	
function musicCheckKey(_event, _table, _id)
	{
	if(_event.keyCode == 13/*Return oder Enter*/)
		return musicItemSave(_table, _id);		
	
	return _event.keyCode;
} // function

// Equipment

function showEquipDiv(_id)
	{
	document.cookie = 'equip-menu=' + _id;
	
	document.getElementById('equip-empty').style.display = 'none';
	
	var ul = document.getElementById('equip-menu-ul');
	
	var menuItemsId = new Array('office', 'instruments', 'music', 'organization', 'coding');
	var menuItemsCaption = new Array('B&uuml;ro', 'Instrumente', 'Musik', 'Organisation', 'Programmierung');
	
	var ulHTML = '';
	var tempDiv = '';
	var currentDiv = '';

	for(var i = 0; i < menuItemsId.length; i++)
		{
		if(_id == menuItemsId[i])
			{
			ulHTML += '<li class="active">' + menuItemsCaption[i] + '</li>';

			currentDiv = document.getElementById('equip-' + menuItemsId[i]);

			currentDiv.innerHTML = ''; /*'<p id="wait-please">Unterseite <em>' + menuItemsCaption[i] + '</em> wird gelanden&hellip;</p>';*/
			currentDiv.style.display = 'block';
			}
		else
			{
			ulHTML += '<li><a href="" onClick="return showEquipDiv(\'' + menuItemsId[i] + '\');">' + menuItemsCaption[i] + '</a></li>';

			tempDiv = document.getElementById('equip-' + menuItemsId[i]);
	
			tempDiv.style.display = 'none';
			tempDiv.innerHTML = '';
			}
		}

	ul.innerHTML = ulHTML;
	
	xmlHTTP = initAJAX();

	xmlHTTP.open('GET', 'scripts/loadTemplate.php?template=equip-' + _id, true);

	xmlHTTP.onreadystatechange = function()
		{
		if(xmlHTTP.readyState == 4)
			{
			currentDiv.innerHTML = xmlHTTP.responseText;
			return false;
			}
		}
	
	xmlHTTP.send(null);
} // function

// Sprachen

function toggleLanguage(_id)
	{
	var div = document.getElementById(_id);

	if(div.style.display == 'block')
		div.style.display = 'none';
	else
		div.style.display = 'block';
	
	return false;
} // function

function showLangDiv(_id)
	{
	document.cookie = 'lang-menu=' + _id;

	document.getElementById('lang-empty').style.display = 'none';

	var ul = document.getElementById('lang-menu-ul');
	
	var menuItemsId = new Array('german', 'english', 'french-italian', 'slavonic', 'baanvi', 'nade', 'luomi');
	var menuItemsCaption = new Array('deutsch', 'englisch', 'romanisch', 'slawisch', 'baanvi', 'nad&euml;', 'lu&rsquo;omi');
	
	var ulHTML = '';
	var tempDiv = '';
	var currentDiv = '';
	
	for(var i = 0; i < menuItemsId.length; i++)
		{
		if(_id == menuItemsId[i])
			{
			ulHTML += '<li class="active">' + menuItemsCaption[i] + '</li>';
			
			currentDiv = document.getElementById('lang-' + menuItemsId[i]);

			currentDiv.innerHTML = ''; /*'<p id="wait-please">Sprachseite zu <em>' + menuItemsCaption[i] + '</em> wird gelanden&hellip;</p>';*/
			currentDiv.style.display = 'block';
			}
		else
			{
			ulHTML += '<li><a href="" onClick="return showLangDiv(\'' + menuItemsId[i] + '\');">' + menuItemsCaption[i] + '</a></li>';
			
			tempDiv = document.getElementById('lang-' + menuItemsId[i]);
			
			tempDiv.style.display = 'none';
			tempDiv.innerHTML = '';
			}
		}

	ul.innerHTML = ulHTML;

	xmlHTTP = initAJAX();

	xmlHTTP.open('GET', 'scripts/loadTemplate.php?template=lang-' + _id, true);

	xmlHTTP.onreadystatechange = function()
		{
		if(xmlHTTP.readyState == 4)
			{
			currentDiv.innerHTML = xmlHTTP.responseText;
			return false;
			}
		}
	
	xmlHTTP.send(null);
} // function

// Literatur

function toggleBook(_id)
	{
	var div = document.getElementById(_id);

	if(div.style.display == 'block')
		div.style.display = 'none';
	else
		div.style.display = 'block';
	
	return false;
} // function

function showBookDiv(_id)
	{
	document.cookie = 'book-menu=' + _id;

	document.getElementById('book-empty').style.display = 'none';

	var ul = document.getElementById('book-menu-ul');
	
	var menuItemsId = new Array('obin', 'music', 'snow');
	var menuItemsCaption = new Array('Obin', 'Musik verstehen', 'Spuren im Schnee');
	
	var ulHTML = '';
	var tempDiv = '';
	var currentDiv = '';
	
	for(var i = 0; i < menuItemsId.length; i++)
		{
		if(_id == menuItemsId[i])
			{
			ulHTML += '<li class="active">' + menuItemsCaption[i] + '</li>';
			
			currentDiv = document.getElementById('book-' + menuItemsId[i]);

			currentDiv.innerHTML = ''; /*'<p id="wait-please">Literaturseite zu <em>' + menuItemsCaption[i] + '</em> wird gelanden&hellip;</p>';*/
			currentDiv.style.display = 'block';
			}
		else
			{
			ulHTML += '<li><a href="" onClick="return showBookDiv(\'' + menuItemsId[i] + '\');">' + menuItemsCaption[i] + '</a></li>';
			
			tempDiv = document.getElementById('book-' + menuItemsId[i]);
			
			tempDiv.style.display = 'none';
			tempDiv.innerHTML = '';
			}
		}

	ul.innerHTML = ulHTML;

	xmlHTTP = initAJAX();

	xmlHTTP.open('GET', 'scripts/loadTemplate.php?template=book-' + _id, true);

	xmlHTTP.onreadystatechange = function()
		{
		if(xmlHTTP.readyState == 4)
			{
			currentDiv.innerHTML = xmlHTTP.responseText;
			return false;
			}
		}
	
	xmlHTTP.send(null);
} // function

// Equipment

function showSibelius()
	{
	document.cookie = 'equip-menu=' + 'music';
	
	return true;
} // function
	
// Cookie löschen (Equipment)

function killCookies()
	{
	document.cookie = 'equip-menu' + '=null;expires=Thu, 01-Jan-1970 00:00:01 GMT';
	document.cookie = 'lang-menu' + '=null;expires=Thu, 01-Jan-1970 00:00:01 GMT';
	document.cookie = 'book-menu' + '=null;expires=Thu, 01-Jan-1970 00:00:01 GMT';

	/*document.cookie = 'not-IE' + '=null;expires=Thu, 01-Jan-1970 00:00:01 GMT';*/
} // function
	
// DropDown Menu

var timeOut	= 0;
var closeTimer	= 0;
var ddMenuItem	= 0;

function menuOpen(_id)
	{	
	menuCancelCloseTime();

	if(ddMenuItem)
		ddMenuItem.style.visibility = 'hidden';

	ddMenuItem = document.getElementById(_id);
	ddMenuItem.style.visibility = 'visible';
} // function

function menuClose()
	{
	if(ddMenuItem)
		ddMenuItem.style.visibility = 'hidden';
} // function

function menuCloseTime()
	{
	closeTimer = window.setTimeout(menuClose, timeOut);
} // function

function menuCancelCloseTime()
	{
	if(closeTimer)
		{
		window.clearTimeout(closeTimer);
		closeTimer = null;
		}
} // function

