//Letzte Aenderungen: 28. November 2001
//AAB Schweiz, ITCS, Joerg Pasch

var windowPopup = null;
//einfache version

//this is the main general popup function. It is called by all other more
//specific functions below.
function openPopup() {

	//default values as hash object
	var hParams = new Array();
	hParams["url"] = "about:blank";
	hParams["target"] = "newwindow";
	hParams["toolbar"] = "no";
	hParams["location"] = "no";
	hParams["directories"] = "no";
	hParams["status"] = "no";
	hParams["menubar"] = "no";
	hParams["scrollbars"] = "no";
	hParams["resizable"] = "no";
	hParams["center"] = "no";
	hParams["width"] = "100";
	hParams["height"] = "300";
	hParams["left"] = "15";
	hParams["top"] = "15";


	//first we have to see, what arguments we've been given
	//if there were no arguments, then exit without action
	//if (openPopup.arguments.length==0) return;

	var splitRegExp = /=/;
	var sNameValue;
	var aNameValue;

	
	for (var i = 0; i < openPopup.arguments.length; i++){
		sNameValue = openPopup.arguments[i];
		sNameValue = sNameValue.replace(/=/, "|");
		aNameValue = sNameValue.split("|");
		
		//the first item - if existing - is the key
		//if its a known param, overwrite default
		if (aNameValue[0] && hParams[aNameValue[0]]) {
			if(aNameValue[1]) {
				hParams[aNameValue[0]] = aNameValue[1];
				//alert("key: " + aNameValue[0] + " value:" + hParams[aNameValue[0]]);
			}
		}
	}
	
	//if popup must be centered then calculate the positions
	if ((hParams.center) && (hParams.center == "yes")) {
		fCenter = true;
	} else {
		hParams["center"] = "no";
		fCenter = false;
	}	
	if ((document.all || document.layers) && fCenter) {
		var screenWidth = screen.availWidth;
   		var screenHeight = screen.availHeight;
		hParams["left"] = (screenWidth - hParams.width)/2
		hParams["top"] = (screenHeight - hParams.height)/2;
	}
	
	//now we have all info needed to build the param string for window.open
	sParams =  "width="   + hParams.width;
	sParams += ",height=" + hParams.height; 
	sParams += ",left="   + hParams.left;
	sParams += ",top="    + hParams.top;
	sParams += ",directories=" + hParams.directories;
	sParams += ",toolbar=" + hParams.toolbar;
	sParams += ",menubar=" + hParams.menubar;
	sParams += ",location=" + hParams.location;
	sParams += ",status=" + hParams.status;
	sParams += ",resizable=" + hParams.resizable;
	sParams += ",scrollbars=" + hParams.scrollbars;

	
	//if (windowPopup && !windowPopup.closed){
	//	newWidth = parseInt(hParams.width) + 15;
	//	newHeight = parseInt(hParams.height) + 25;
	//	windowPopup.resizeTo(newWidth, newHeight);
	//	windowPopup.location.href = hParams.url;
	//}
	//else{
		windowPopup = window.open(hParams.url, hParams.target, sParams);
	//}

	if (windowPopup.opener == null) windowPopup.opener = self;
	if (window.focus) {windowPopup.focus()}

}


//This function opens the news articles from Information & Library Centre pages
function openPopupIRCArticle(sURL) {
	openPopup("url="+sURL,"target=IRCAABNieuws","center=yes","width=660","height=475","resizable=yes", "scrollbars=yes");
}

function openPopupIRCConcurrentenNieuws(sURL) {
	openPopup("url="+sURL,"target=IRCConcurrentenNieuws","center=yes","width=660","height=475","resizable=yes", "scrollbars=yes");
	//document.location.reload();
}

function openPopupIRCConcurrentenRapport(sURL) {
	openPopup("url="+sURL,"target=IRCConcurrentenRapport","center=yes","width=660","height=475","resizable=yes", "scrollbars=yes", "toolbar=yes");
	//document.location.reload();
}


function setOpenerLocation(sTargetURL, fCloseSelf) {
	if (window.opener) {
		window.opener.location.href = sTargetURL;
		if (fCloseSelf) self.close();
	} else {
		window.location.href = sTargetURL;
	}
}


function reloadOpenerLocation(fCloseSelf) {
	if (window.opener) {
		window.opener.location.reload();
		if (fCloseSelf) self.close();
	} else {
		
	}
}



function changeState(a_pageLink, a_windowName)
{
	var href, windowWidth, windowHeight;
	if (! window.focus)
	{
		return true;
	}

	if (typeof(a_pageLink) == 'string')
	{
		href=a_pageLink;
	}
	else
	{
		href=a_pageLink.href;
	}

	window.open(href, a_windowName, 'width=400, height=200, scrollbars=yes');
	 
	return false;
}

function showProperties(a_pageLink, a_windowName, popupwidth, popupheight)
{
	var href, windowWidth, windowHeight;
	if (! window.focus)
	{
		return true;
	}

	if (typeof(a_pageLink) == 'string')
	{
		href=a_pageLink;
	}
	else
	{
		href=a_pageLink.href;
	}

	window.open(href, a_windowName, 'width='+popupwidth+', height='+popupheight+', scrollbars=yes');
	 
	return false;
}

function refreshCaller()
{
	if (window.opener) {
		window.opener.location.reload();
	}

	window.close();
}



