var winStack = [];

function openPopup(dest,name,height,width) {
	var winExist = null;

	width = width + 10;
	height = height + 10;

	// find out if the window exists
	for (var i=0;i<winStack.length;i++) {
		if (winStack[i].name == name) winExist = i;
	}
		
	// if the window does exist, check if it is still open	
	if (winExist!=null) {
	 	if (winStack[winExist].win&&!winStack[winExist].win.closed) {
			//the window has been used, and it is still open
			winStack[winExist].win.location = dest;
			winStack[winExist].win.resizeTo(width,height+50)
			winStack[winExist].win.focus();

		} else {
			// the window has existed but is now closed so create a new window but assign it to the variable it used last time
			winStack[winExist].win = window.open(dest,name,'height='+ height +',width='+ width +',toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
			winStack[winExist].name = name;
			winStack[winExist].win.focus();
		}
	} else {
		
		// the window has never existed, so make a new entry in the stack
		var winIndex = winStack.length-1;
		winStack[winIndex] = {win:null,name:null }
		winStack[winIndex].win = window.open(dest,name,'height='+ height +',width='+ width +',toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
		winStack[winIndex].name = name;
		winStack[winIndex].win.focus();
	}
}
function openPopupImage(dest,height,width) {
	width = width + 10;
	height = height + 10;
	hest = window.open(dest,'o','height='+ height +',width='+ width +',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=ýes');
        hest.focus();
        return false;
}
function FlytVaerdiId(value) {	
	if(window.opener == undefined) return false;
	alert(value);
}
function elementCheck(id) {
        if(document.getElementById(id)) 
                return true;
        else
                return false;
}
function TopChange(oldid,newid) {
	var toppunkt = [
		'generelt',
		'front'
	];

	for (var i=0;i<toppunkt.length;i++) {
		if(elementCheck(toppunkt[i])) 
			document.getElementById(toppunkt[i]).src='/webadmin/images/fane_'+toppunkt[i]+'_off.gif';
	}

	if(elementCheck(newid)) 
		document.getElementById(newid).src='/webadmin/images/fane_'+newid+'_on.gif';
		
	location.href='/admin/popup_image_browser/'+newid+'/';
}
function TopHighlight(id) {
	if(elementCheck(id)) 
		document.getElementById(id).src='/webadmin/images/fane_'+id+'_on.gif';
}
