var lastMouseX;
var lastMouseY;
var curPopupWindow = null;

function setLastMousePosition(e) {
	if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
	lastMouseX = e.screenX;
	lastMouseY = e.screenY;
}

function openWindow(url) {
	var popupWin = window.open(url, 'newWin',  'status,scrollbars,resizable,menubar,toolbar,dependent,width=770,height=550,left=50,top=50');
	popupWin.focus();
}

function openPopup(url, name, pWidth, pHeight, features, snapToLastMousePosition) {
	openPopupFocus(url, name, pWidth, pHeight, features, snapToLastMousePosition, true);
}

function openPopupFocus(url, name, pWidth, pHeight, features, snapToLastMousePosition, closeOnLoseFocus) {
	closePopup();

	if (snapToLastMousePosition) {
		if (lastMouseX - pWidth < 0) {
			lastMouseX = pWidth;
		}
		if (lastMouseY + pHeight > screen.height) {
			lastMouseY -= (lastMouseY + pHeight + 50) - screen.height;
		}
		lastMouseX -= pWidth;
		lastMouseY += 10;
		features += "screenX=" + lastMouseX + ",left=" + lastMouseX + "screenY=" + lastMouseY + ",top=" + lastMouseY;
	}

	if (closeOnLoseFocus) {
		curPopupWindow = window.open(url, name, features, false);
		curPopupWindow.focus();
	} else {
		win = window.open(url, name, features, false);
		win.focus();
	}
}

function closePopup() {
	if (curPopupWindow != null) {
       
		if (!curPopupWindow.closed)
			curPopupWindow.close();
		
		curPopupWindow = null;
	}
}

function openLookup(baseURL, tbl, frm, fld_id, fld_txt, param) {
	var str = baseURL + "/lookup/lookup.cfm?tbl=" + tbl + "&frm=" + frm + "&fld_id=" + fld_id + "&fld_txt=" + fld_txt;

	if (param == undefined) param = '';
	
	str += '&param=' + param;
	
	openPopup(str, "lookup", 430, 300, "width=430,height=300,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
}

function openCombo(baseURL, frm, fld, evt) {
	var str = baseURL + "/lookup/combo.cfm?frm=" + frm + "&fld=" + fld + "&evt=" + evt;
	
	openPopup(str, "combo", 300, 200, "width=300,height=200,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
}

function showDate(baseURL, fld, frm) {
	var str = baseURL + "/lookup/cal.cfm?frm=" + frm + "&fld=" + fld;
	if (eval("document." + frm + "." + fld).value.length > 0)
		str = str + "&cdate=" + eval("document." + frm + "." + fld).value;
	
		openPopup(str, "calwin", 170, 190, "width=170,height=190,toolbar=no,status=no,directories=no,menubar=no,resizable=no,scrollable=no", true);
}

/*function ptWin() {
	var photoWin = window.open('/providence/phototour/index.cfm', 'photoWin',  'status=no,scrollbars=no,resizable=no,menubar=no,toolbar=no,dependent,width=760,height=440,left=50,top=50');
		photoWin.focus();
}*/

function ptWin(location) {
	var URL;
	if (location.length == 0) {
		URL = '/slo07/phototour/index.cfm';
	} else {
		URL = location;
	}
	var photoWin = window.open(URL, 'photoWin',  'status=no,scrollbars=no,resizable=no,menubar=no,toolbar=no,dependent,width=760,height=520,left=50,top=50');
		photoWin.focus();
}

