var isNetscape = (navigator.appName=="Netscape");
var isExplorer = (navigator.appName=="Microsoft Internet Explorer");
var browserVer = parseInt(navigator.appVersion);
var subWindows = null;

/** 
* Shows an ulr in the opener window, closes de window if told so
*
* Example call: onClick="return showUrlOpener('/una/url/de/una/pagina.html',true);"
**/ 
function showUrlOpener(theUrl,doCloseWindow){
	if (window.opener != null && !window.opener.closed){
		window.opener.location = theUrl;
	}
	
	// Close window if told so
	if (doCloseWindow){
		window.close();
	}
	
	return false;
}										// showUrlOpener

/** 
* Finds a window in the subWindow array
*
**/ 
function findWindow(windowName){
	if (typeof(subWindows[windowName])=="undefined" && subWindows[windowName]!=null){
		return null;
	}else{
		return subWindows[windowName];
	}
}

/** 
* Remove a window in the subWindow array
*
**/ 
function removeWindow(windowName){
	var theWin;
	
	if (typeof(subWindows[windowName])=="undefined" && subWindows[windowName]!=null){
		return null;
	}else{
		subWindows[windowName] = null;
	}
}

/** 
* Adds a window into the subWindow array
*
**/ 
function addWindow(theWin,windowName){
	subWindows[windowName] = theWin;
}

/** 
* Opens a window, if its already open it will focus that window
*
**/ 
function openWin(windowName,URL,width,height,windowfeatures){
	var theWin;
	var topPos,leftPos;
	
	// if array of subWindows not created create one
	if (subWindows == null){
		subWindows = new Array();
	}
	
	// If Netscape add 20 px to height
	windowfeatures ="width="+width+",height="+height+","+windowfeatures;
	if (isNetscape){
		height = height + 20;
	}else{
			leftPos = (screen.availWidth-width)/ 2;
			topPos = (screen.availHeight-height)/ 2;
			windowfeatures ="top="+topPos+",left="+leftPos+","+windowfeatures;
	}

	//alert("windowfeatures="+windowfeatures);

	theWin = findWindow(windowName);
	if (theWin == null){
		theWin=window.open(URL,windowName,windowfeatures);
		addWindow(theWin,windowName);
	}else{
		if (theWin.closed){
			removeWindow(windowName)
			theWin=window.open(URL,windowName,windowfeatures);
			addWindow(theWin,windowName);
		}else{
			theWin.location=URL;
			theWin.focus();
		}
	}
	
	return false;
}