﻿function launchit(newURL, newName, newFeatures, orgName) {
  var NewWindow = window.open(newURL, newName, newFeatures);
  if (NewWindow.opener == null) NewWindow.opener = self;
  NewWindow.opener.name = orgName;
  NewWindow.focus();
  return NewWindow;
}

function popUp(mylink) { 
	if (!window.focus) return true; // Don't know what this does but .focus() does not return a value
	var href = (typeof(mylink) == 'string') ? mylink : mylink.href;
	var Width = (arguments.length > 1) ? arguments[1] : 750;
	var Height = (arguments.length > 2) ? arguments[2] : 500;
	var Name = (arguments.length > 3 && arguments[3].length > 0) ? arguments[3] : mylink.target;
	var ExtraFeatures = (arguments.length > 4 && arguments[4].length > 0) ? arguments[4] : 'resizable=1,scrollbars=1,status=1,toolbar=0,menubar=0';
	var leftPos = 5, topPos = 5;
	if (screen) {
		leftPos = (screen.width / 2) - (Width / 2);
		topPos = (screen.height / 2) - (Height / 2);
	}
	var Features = (ExtraFeatures.length > 1) ? "screenX=" + leftPos + ",left=" + leftPos + ",screenY=" + topPos + ",top=" + topPos + ",width=" + Width + ",height=" + Height + "," + ExtraFeatures : "screenX=" + leftPos + ",left=" + leftPos + ",screenY=" + topPos + ",top=" + topPos + ",width=" + Width + ",height=" + Height;
	//var Features = (ExtraFeatures.length > 1) ? "width=" + Width + ",height=" + Height + "," + ExtraFeatures : "width=" + Width + ",height=" + Height;
    //alert('DEBUG Name: ' + Name + ', Features: ' + Features + ', href: ' + href + ', orgName: ' + (window.name==''?'main':window.name));
	launchit(href, Name, Features, (window.name==''?'main':window.name));
	return false;
}
