var bugRiddenCrashPronePieceOfJunk = (
	navigator.userAgent.indexOf('MSIE 5') != -1
	&&
	navigator.userAgent.indexOf('Mac') != -1
);

var W3CDOM = (!bugRiddenCrashPronePieceOfJunk && 
	document.getElementsByTagName && document.createElement);

if ((top != self.parent) && !self.disabled)
	top.location.href = '/index.html';

if (top.navi && top.navi.setNav) top.navi.setNav(location.href,'currentPage');
top.setNav = location.href;


window.onload = initialize;

/* Why no window.onload = function () {} ? Because NN3 doesn't support the function
	constructor and gives an error message. This site must be accessible to NN3 */

function initialize () {	
/* Hide nifty stuff from old browsers */

	if (W3CDOM)
	{

/* Go through all links. If any has a type="popup" write the popup function into its onclick
   Any external link gets a target='ppk'. 
   Any link with a hreflang attribute gets an extra note with its value.   
   */
	var langspan = document.createElement('span');
	langspan.className = 'smaller lang';


/* Add breadcrumb of current page to logo frame */
	if (top.logo && top.logo.addBreadCrumb)
		top.logo.addBreadCrumb(document.title,location.href);

/* Add IE version to page title */
	var browser = '';
	if (document.all)
	{
		detect = navigator.userAgent.toLowerCase();
		if (checkItLocal('msie')) 
		{
			browser = "IE "
			browser += detect.substr(placeOfDetect + thestring.length,3);
			document.title = document.title;
		}
	}
	}
}

window.onunload = remove;

function remove () {
	if (top.navi && top.navi.setNav) top.navi.setNav(location.href,'');
	top.setNav = '';
	if (self.exit) self.exit();
}

// Table of Contents



var TOCstate = 'none';

function showhideTOC()
{
	TOCstate = (TOCstate == 'none') ? 'block' : 'none';
	document.getElementById('toc').lastChild.style.display = TOCstate;
	
}


function checkItLocal(string)
{
	placeOfDetect = detect.indexOf(string) + 1;
	thestring = string;
	return placeOfDetect;
}

function getElementsByTagNames(list,obj)
{
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++)
	{
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++)
		{
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (testNode != null)
	if (testNode.sourceIndex)
	{
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition)
	{
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}

// push and shift for IE5

function Array_push() {
	var A_p = 0
	for (A_p = 0; A_p < arguments.length; A_p++) {
		this[this.length] = arguments[A_p]
	}
	return this.length
}

if (typeof Array.prototype.push == "undefined") {
	Array.prototype.push = Array_push
}

function Array_shift() {
	var A_s = 0
	var response = this[0]
	for (A_s = 0; A_s < this.length-1; A_s++) {
		this[A_s] = this[A_s + 1]
	}
	this.length--
	return response
}

if (typeof Array.prototype.shift == "undefined") {
	Array.prototype.shift = Array_shift
}


function disable(disableIt)
{
	if (disableIt)
	{
		document.inputform.user_building.selectedIndex = 0;
		document.inputform.user_flat.selectedIndex = 0;
		document.inputform.user_hide_address[1].checked = true;
	}
	document.inputform.user_building.disabled = disableIt;
	document.inputform.user_flat.disabled = disableIt;
	document.inputform.user_hide_address[0].disabled = disableIt;
	document.inputform.user_hide_address[1].disabled = disableIt;
}

var store = new Array();

store[0] = new Array(
	'',''
);

//98
store[98] = new Array(
	'1','1',
	'2','2',
	'3','3',
	'4','4',
	'5','5',
	'6','6',
	'7','7',
	'8','8',
	'9','9',
	'10','10'
);

//100
store[100] = new Array(
	'1','1',
	'2','2',
	'3','3',
	'4','4',
	'5','5',
	'6','6',
	'7','7',
	'8','8',
	'9','9',
	'10','10',
	'11','11',
	'12','12',
	'13','13',
	'14','14',
	'15','15',
	'16','16',
	'17','17',
	'18','18',
	'19','19',
	'20','20',
	'21','21',
	'22','22',
	'23','23',
	'24','24',
	'25','25'
);

// 102
store[102] = new Array(
	'1','1',
	'2','2',
	'3','3',
	'4','4',
	'5','5',
	'6','6',
	'7','7',
	'8','8',
	'9','9',
	'10','10',
	'11','11',
	'12','12',
	'13','13',
	'14','14',
	'15','15',
	'16','16',
	'17','17',
	'18','18',
	'19','19',
	'20','20',
	'21','21',
	'22','22',
	'23','23',
	'24','24',
	'25','25',
	'26','26',
	'27','27',
	'28','28',
	'29','29',
	'30','30',
	'31','31',
	'32','32',
	'33','33',
	'34','34',
	'35','35',
	'36','36',
	'37','37',
	'38','38'
);

// 104
store[104] = new Array(
	'1','1',
	'2','2',
	'3','3',
	'4','4',
	'5','5',
	'6','6',
	'7','7',
	'8','8',
	'9','9',
	'10','10',
	'11','11',
	'12','12',
	'13','13',
	'14','14',
	'15','15',
	'16','16',
	'17','17',
	'18','18',
	'19','19',
	'20','20',
	'21','21',
	'22','22',
	'23','23',
	'24','24',
	'25','25',
	'26','26',
	'27','27',
	'28','28',
	'29','29',
	'30','30',
	'31','31',
	'32','32',
	'33','33',
	'34','34',
	'35','35',
	'36','36',
	'37','37',
	'38','38',
	'39','39',
	'40','40',
	'41','41',
	'42','42',
	'43','43',
	'44','44',
	'45','45'
);

// 106
store[106] = new Array(
	'1','1',
	'2','2',
	'3','3',
	'4','4',
	'5','5',
	'6','6',
	'7','7',
	'8','8',
	'9','9',
	'10','10',
	'11','11',
	'12','12',
	'13','13',
	'14','14',
	'15','15',
	'16','16',
	'17','17',
	'18','18',
	'19','19',
	'20','20',
	'21','21',
	'22','22',
	'23','23',
	'24','24',
	'24a','24a',
	'25','25',
	'26','26',
	'27','27',
	'28','28',
	'29','29',
	'30','30',
	'31','31',
	'32','32',
	'33','33',
	'34','34',
	'35','35',
	'36','36',
	'37','37',
	'38','38',
	'39','39',
	'40','40',
	'41','41',
	'42','42',
	'43','43',
	'44','44',
	'45','45'
);

function populate()
{
	var box = document.inputform.user_building;
	var number = box.options[box.selectedIndex].value;
	if (!number) return;
	var list = store[number];
	var box2 = document.inputform.user_flat;
	box2.options.length = 0;
	for(i=0;i<list.length;i+=2)
	{
		box2.options[i/2] = new Option(list[i],list[i+1]);
	}
}


function StatsTabs() {
	this.settings = new Array();
};

StatsTabs.prototype.init = function(settings) {
	this.settings = settings;
};

StatsTabs.prototype.getParam = function(name, default_value) {
	var value = null;

	value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];

	// Fix bool values
	if (value == "true" || value == "false")
		return (value == "true");

	return value;
};

StatsTabs.prototype.displayTab = function(tab_id, panel_id) {
	var panelElm = document.getElementById(panel_id);
	var panelContainerElm = panelElm ? panelElm.parentNode : null;
	var tabElm = document.getElementById(tab_id);
	var tabContainerElm = tabElm ? tabElm.parentNode : null;
	var selectionClass = this.getParam('selection_class', 'current');

	if (tabElm && tabContainerElm) {
		var nodes = tabContainerElm.childNodes;

		// Hide all other tabs
		for (var i=0; i<nodes.length; i++) {
			if (nodes[i].nodeName == "LI")
				nodes[i].className = '';
		}

		// Show selected tab
		tabElm.className = 'current';
	}

	if (panelElm && panelContainerElm) {
		var nodes = panelContainerElm.childNodes;

		// Hide all other panels
		for (var i=0; i<nodes.length; i++) {
			if (nodes[i].nodeName == "DIV")
				nodes[i].className = 'panel';
		}

		// Show selected panel
		panelElm.className = 'current';
	}
};

StatsTabs.prototype.getAnchor = function() {
	var pos, url = document.location.href;

	if ((pos = url.lastIndexOf('#')) != -1)
		return url.substring(pos + 1);

	return "";
};

// Global instance
var StatsTabs = new StatsTabs();

