/* variabler */
var move = false;/* sets if div tags shut follow then page is scrolled*/
var positionFixed = false; /* sets if div tags shut maintain its margin from the top.can be true or false only works if move is true only works in firefox 2 og ei7 or later versions*/
var positionStart = 10; /* sets the div tags margin from the top.Is only used if positionFixed is false*/
var mainDiv = "page_master";
var mainDivMargin = 20; 
var floatDiv = "popup";
var floatDivCenter = false;
var backgroundDiv = "popback"; /* the Id of the floating div tag */ 
var floatDivHeight = "";
var floatDivWidth = "";
var windowWidth = "";
var windowHeight = "";
var mainDivHeight = ""; 
var mainDivWidth = "";
var mainavailWidth = "";
var mainavailHeignt = "";
var mainBodyHeight = "";
var mainBodyWidth = "";
var floatDivWidth = "";
var floatDivHeight= "";
var floatDivHeight = "";
var floatDivLeft="";
/* variabler slut */

/* browser check funktion */
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

/* browser check funktion slut */







var userBrowser = BrowserDetect.browser + " " + BrowserDetect.version;
window.onscroll = document.documentElement.onscroll = doOnScroll;
window.onresize = reSize;
doOnScroll();

function browserCheck(){
	
	if(userBrowser != "Explorer 6"){
	//alert("ikke ie")
	}
	else{
	document.getElementById(floatDiv).style.position = "absolute";
	//alert("ie")
	}
pageSize()
}


function reSize(){

pageSize()

floatDivWidth = document.getElementById(floatDiv).offsetWidth;
floatDivHeight= document.getElementById(floatDiv).offsetHeight;


floatDivLeft = parseInt((mainBodyWidth - floatDivWidth)/2);

if(floatDivLeft < 0)
floatDivLeft = "0px";

document.getElementById(floatDiv).style.left = floatDivLeft + "px";

if (floatDivCenter == true){
floatDivHeight = parseInt((mainBodyHeight - floatDivHeight)/2);

if(floatDivHeight < 0)
floatDivHeight = "0px";

document.getElementById(floatDiv).style.top = floatDivHeight + "px";
positionStart = floatDivHeight + "px";
}

if(mainDivHeight < windowHeight)
mainDivHeight = windowHeight;


if(floatDivHeight > mainDivHeight){
	document.getElementById(backgroundDiv).style.height = floatDivHeight + positionStart + "px";
	document.getElementById(backgroundDiv).style.width = mainBodyWidth + "px";
	document.getElementById(mainDiv).style.height = floatDivHeight + "px";
	}
else{	
document.getElementById(backgroundDiv).style.height = mainDivHeight + "px";
document.getElementById(backgroundDiv).style.width = mainBodyWidth + "px";
}
}

function view(url, containerid){
   
    var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
	page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
	try {
	page_request = new ActiveXObject("Msxml2.XMLHTTP")
	} 
	catch (e){
	try{
	page_request = new ActiveXObject("Microsoft.XMLHTTP")
	}
	catch (e){}
	}
	}
	else
	return false
	page_request.onreadystatechange=function(){
	loadpage(page_request, containerid)
	}
	page_request.open('GET', url, true)
	page_request.send(null)
	
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
persistclose = 0;
show();
}

function show(){
//alert("hej");
pageSize()

if (move != true){
var newOffset = document.documentElement.scrollTop || document.body.scrollTop;

document.getElementById(floatDiv).style.top =  10 + newOffset + "px";

}

floatDivWidth = document.getElementById(floatDiv).offsetWidth;
floatDivHeight= document.getElementById(floatDiv).offsetHeight;

floatDivLeft = parseInt((mainBodyWidth - floatDivWidth)/2);

if(floatDivLeft < 0)
floatDivLeft = "0px";

document.getElementById(floatDiv).style.left = floatDivLeft + "px";

if (floatDivCenter == true){
floatDivHeight = parseInt((mainBodyHeight - floatDivHeight)/2);

if (move != true){

floatDivHeight = floatDivHeight + newOffset;

}

if(floatDivHeight < 0)
floatDivHeight = "0px";

document.getElementById(floatDiv).style.top = floatDivHeight + "px";
positionStart = floatDivHeight + "px";
}


if(floatDivHeight < windowHeight)
floatDivHeight = windowHeight;


if(floatDivHeight > mainDivHeight){
	document.getElementById(backgroundDiv).style.height = floatDivHeight + positionStart + "px";
	document.getElementById(backgroundDiv).style.width = mainBodyWidth + "px";
	document.getElementById(mainDiv).style.height = floatDivHeight + "px";
	}
else{	
document.getElementById(backgroundDiv).style.height = mainDivHeight + "px";
document.getElementById(backgroundDiv).style.width = mainBodyWidth + "px";
}
	


document.getElementById(floatDiv).style.visibility = "visible";
document.getElementById(backgroundDiv).style.visibility = "visible";

}

function hide(){

document.getElementById(floatDiv).style.visibility = "hidden";
document.getElementById(backgroundDiv).style.visibility = "hidden";

}
function pageSize(){

			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}


			if (typeof(window.innerWidth) == 'number') {
				windowWidth = window.innerWidth;
			}
			else {
				if (document.documentElement && document.documentElement.clientWidth) {
					windowWidth = document.documentElement.clientWidth;
				}
				else {
					if (document.body && document.body.clientWidth) {
						windowWidth = document.body.clientWidth;
					}
				}
			}


windowWidth = windowWidth;
windowHeight = windowHeight;

mainDivHeight = document.getElementById(mainDiv).offsetHeight + mainDivMargin; 
mainDivWidth = document.getElementById(mainDiv).offsetWidth;

mainavailWidth = screen.availWidth;
mainavailHeignt = screen.availHeight;

mainBodyHeight = document.getElementsByTagName('body')[0].clientHeight;
mainBodyWidth = document.getElementsByTagName('body')[0].clientWidth;

/*
windowHeight er browser winduets højde + evt horisontal scrollbar men - topbar

windowWidth er browser winduets bredde + evt vertikal scrollbar

mainavailWidth Hovedet div'ens bredde

mainavailWidth Hovedet div'ens højde (angiver den total længte af siden)

mainavailWidth angiver højden af hele browser vinduet + topbar

mainavailHeignt angiver bredden af hele browser vinduet + scrollbar

mainBodyHeight angiver højden af browser vinduets "indholds område"  -scroll - topbar 

mainBodyWidth angiver bredde af browser vinduets "indholds område"  -scroll - topbar 
*/

//alert(windowHeight + " " + windowWidth + " " + mainDivHeight + " " + mainDivWidth + " " + mainavailHeignt + " " + mainavailWidth + " " +mainBodyHeight + " " + mainBodyWidth);
}
function doOnScroll() {
    
	
	var header = document.getElementById(floatDiv);
	if (!header) return;
	
	var currentOffset = document.documentElement.scrollTop || document.body.scrollTop; // body for Safari
	var startPos = positionStart;
	var desiredOffset = startPos - currentOffset;
	if (desiredOffset < 10)
		desiredOffset = 0;
	if (desiredOffset != parseInt(header.style.top)) 
	
	
	if(userBrowser != "Explorer 6"){
		
		if (positionFixed == false)
		header.style.top = desiredOffset + 'px';
		
		if (move != true){
		header.style.position = "absolute";
		}
		}
		else{
		if (move == true){
		header.style.position = "absolute";
		header.style.top = desiredOffset + currentOffset + 'px';
		}
		}
		
	
	
	 
   //alert(currentOffset);
}
