// CREATE XMLHTTP REQUEST
function getxmlhttp() {
	try {
	  xmlhttp = new XMLHttpRequest();
	}
	catch (e) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				return false;
			}
		}
	}
	return xmlhttp;
}

// AJAX REQUEST
function ajax(id,fullpage,page) {
	xmlhttp = getxmlhttp();
	anticache = Math.floor(Math.random() * 10000000000);
	xmlhttp.open("GET",fullpage+"&ac="+anticache);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById(id).innerHTML = xmlhttp.responseText;
			if (id == 'content1' && page != "noupdate") {
				ajax('submenu','includes/submenu.php?p='+page);	
			}
		}
	}
	xmlhttp.send(null);
}

// CHANGE CONTENT
function changeContent(page) {
	//document.getElementById('content1').innerHTML = "";
	ajax('content1','includes/content.php?p='+page,page);
	//ajax('submenu','includes/submenu.php?p='+page);
	scroll(0,0);
}

// CHANGE DIENST
function changeDienst(id) {
	ajax('content1','includes/dienst.php?id='+id,'noupdate');
	scroll(0,0);
}

// OVERLAY
function overlay(todo,id,page) {
	if (todo == 'close') {
		document.getElementById('overlay').style.display = "none";
		document.getElementById('overlaybg').style.display = "none";
		document.getElementById('overlaycontent').innerHTML = "";
		document.getElementById('overlaybg').style.height = "100%";
	} else {
		ajax('overlaycontent','includes/overlaycontent.php?page='+page+'&id='+id);
		fromtop = 260 + document.documentElement.scrollTop;
		document.getElementById('overlay').style.top = fromtop+"px";		
		document.getElementById('overlay').style.display = "block";
		document.getElementById('overlaybg').style.display = "block";
		pageHeight = getPageSize()['pageHeight'];
		document.getElementById('overlaybg').style.height = pageHeight+"px";
	}
}

/* GET PAGE SIZE */
function getPageSize() {
	var xScroll, yScroll;	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}	
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	if (yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	if (xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array();
	arrayPageSize['pageWidth'] = pageWidth;
	arrayPageSize['pageHeight'] = pageHeight;
	arrayPageSize['windowWidth'] = windowWidth;
	arrayPageSize['windowHeight'] = windowHeight;
	return arrayPageSize;
	/// pageHeight = getPageSize()['pageHeight'];
}