/***********************************************************************************
 * Class: CWindow
 * Dependencies: none
 * Description:
 *   Window popup functions
 *
 ***********************************************************************************/

	// Window class
	function CWindow() {}
	
	// Win popup
	CWindow.open = function(url, width, height, features, name, win) {
		if(!win)
			win = window;
		// Default width and height
		if(!width)
			width = 400;
		if(!height)
			height = 110;
		if(!name && url.indexOf(".") > 0)
			name = url.substring(0, url.indexOf(".")).replace(/[ \/\\\(\)_]/g, "");
		
		var winl = CWindow.getCentreOfLine(screen.width, width);
		var wint = CWindow.getCentreOfLine(screen.height, height);
		
		// Append startup left and top values
		//url += (url.indexOf("?") > 0 ? "&" : "?") + "_win_defleft=" + winl + "&_win_deftop=" + wint;
		
		var popupWin = window.open(url, name,"height=" + height + ",width=" + width + ",left="+winl+",top="+wint+",screenX="+winl+",screenY="+wint + (features ? "," + features : ""));
		popupWin.focus();
		if(popupWin.opener == null)
			popupWin.opener = win;
		return popupWin;
	}

	// Centre a line on a line
	CWindow.getCentreOfLine = function(line1, line2, noNegNumbers) {
		return (CWindow.validateNum(line1) - CWindow.validateNum(line2)) / 2;
	}
	
	// Validate a number (default to 0)
	CWindow.validateNum = function(num) {
		if(num == null || num == "")
			return 0;
		if(isNaN(num)) {
			num = (num + "").replace(/px/ig, "");
			if(isNaN(num))
				return 0;
		}
		return parseFloat(num);
	}