// Preload some images

image1 = new Image();
image1.src = "../../img/loading.gif";
image2 = new Image();
image2.src = "../../img/loadingbox.png";
image3 = new Image();
image3.src = "../../img/overlay.png";


function swapDiv(elementId) {
	obj = document.getElementById(elementId);
	if (obj.style.display == 'block') {
		obj.style.display = 'none';
	} else {
		obj.style.display = 'block';
	}
}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
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){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}



function showLinkWindow(linkText) {
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	// Overlay sichtbar machen
	var objOverlay = document.getElementById('overlay');
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';
	
	// Link dynamisch einfügen
	var link = document.createElement("p");
	link.setAttribute('id','linkContainer');
	link.style.fontWeight = 'bold';
	var linkText = document.createTextNode(linkText);
	link.appendChild(linkText);
	document.getElementById("linkWindow").insertBefore(link, document.getElementById("closeLink"));
	// Linkfenster positionieren
	document.getElementById('linkWindow').style.top = arrayPageScroll[1] + ((arrayPageSize[3]-50)/2)+'px';
	document.getElementById('linkWindow').style.left = (arrayPageSize[0]-770)/2+'px';
	// Fenster sichtbar machen
	document.getElementById('linkWindow').style.display = 'block';
}

function closeLinkWindow() {
	// Overlay verstecken
	document.getElementById('overlay').style.display = 'none';
	// linkContainer löschen
	document.getElementById('linkWindow').removeChild(document.getElementById('linkContainer'));
	// linkWindow verstecken
	document.getElementById('linkWindow').style.display = 'none';
}

function popup(src,width,height,features){
	var xwidth='width='+width;
	var xheight=',height='+height+',';
	var myfeatures=xwidth+xheight+features+',top=280,left=175';
	var myXtrawin=open(src,"myXtrawin",myfeatures);
	myXtrawin.focus();
	return false;
}

function newWindow(address, title) {
	win = window.open(address, title, "width=800,height=600,scrollbars=yes,menubar=yes,resizable=yes");
  win.focus();
}


function loadingWindow() {
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// Overlay sichtbar machen
	var objOverlay = document.getElementById('overlay');
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';
	
	document.getElementById('loadingBox').style.display = 'block';
	document.getElementById('loadingBar').style.display = 'block';	
}

function confirm_with_loading_window(message) {
	if (confirm(message)) {
		loadingWindow();
		return true;
	} else {
		return false;
	}
}

