// Copyright MAH Designs
// http://www.mahDesigns.com/

function PopUp(url, winName, winWidth, winHeight, winCenter, winStyle) {
	var xPos = 0;
	var yPos = 0;
	if (window.screen && winCenter) {
    	var aw = screen.availWidth - 10;
    	var ah = screen.availHeight - 30;

		if (winWidth) {
			if (winWidth > aw) winWidth = aw;
    		xPos = (aw - winWidth) / 2;
		}
		
		if (winHeight) {
			if (winHeight > ah) winHeight = ah;
	    	yPos = (ah - winHeight) / 2;
		}
		
		if (xPos < 0) xPos = 0;
		if (yPos < 0) yPos = 0;
	}
	else {
		xPos = 50;
		yPos = 10;
	}
	var winAttributes = new Array();
	if (winWidth) {
		var atrWidth = 'width='+winWidth+',innerWidth='+winWidth;
		winAttributes.push(atrWidth);
	}
	if (winHeight) {
		var atrHeight = 'height='+winHeight+',innerHeight='+winHeight;
		winAttributes.push(atrHeight);
	}
	if (xPos) {
		var winLeft = 'left='+xPos+',screenX='+xPos;
		winAttributes.push(winLeft);
	}
	if (yPos) {
		var winRight = 'top='+yPos+',screenY='+yPos;
		winAttributes.push(winRight);
	}
	winAttributes.push('resizable=1','copyhistory=0');
	if (winStyle == 'popup') {
		winAttributes.push('menubar=0','toolbar=0','location=0','directories=0','status=0','scrollbars=0');
	}
	else {
		winAttributes.push('menubar','toolbar','location','directories','status','scrollbars');
	} 
	var winFeatures = winAttributes.join(',');
	var popWin = window.open(url,winName,winFeatures);
	if (popWin && popWin.open && !popWin.closed) {
		//insures that the window gets refreshed properly 
		//if it wasn't closed between uses
		if (winWidth && winHeight) {
			popWin.resizeTo(winWidth, winHeight);
		}
		if (xPos && yPos) {
			popWin.moveTo(xPos, yPos);
		}
		popWin.focus();
	}
}