var popWin = null;
var lastMouseX;
var lastMouseY;
var isIE = navigator.appName.indexOf("Microsoft") != -1;
var isIE5 = navigator.userAgent.indexOf('MSIE 5.0') > 0;
var isOpera = navigator.userAgent.indexOf("Opera") != -1;
var isSafari = navigator.userAgent.indexOf("AppleWebKit") != -1;
var isFirefox = navigator.userAgent.indexOf( "Firefox/" ) != -1;

// Open Popup window
function popupWin(type, url)
{
	switch (type)
	{
		case "VIEW"      :	openWin(url, "T", 500, 400, 1, 0, 0); return; 
		case "IMAGE"     :	openWin(url, "T", 700, 500, 1, 0, 1); return; 
		case "EMAIL"     :	openWin(url, "C", 650, 450, 1, 0, 0); return; 
		case "TRACK"     :	openWin(url, "C", 800, 500, 1, 1, 1); return; 
		case "NOTE"      :	openWin(url, "C", 510, 300, 1, 0, 0); return; 
		case "HIST"      :	openWin(url, "C", 610, 400, 1, 0, 0); return; 
		default:	        openWin(url, "C", 500, 400, 1, 0, 0);
	}
}


// Open Popup Window
function openWin(url, pos, width, height, scrollbar, toolbar, resize)
{
	var top = 0;
	var left = 0;
	if (pos == "C")
	{
		top = ((screen.height - 100) - height) / 2;
		left = ((screen.width - 100) - width) / 2;
	}
	else if (pos == "R")
	{
		top = 0;
		left = (screen.width - width + 25);
	}
	else // Snap to Mouse Position
	{
        if (lastMouseX - width < 0) lastMouseX = width;
        if (lastMouseY + height > screen.height) lastMouseY -= (lastMouseY + height + 50) - screen.height;
        lastMouseX -= width;
        lastMouseY += 10;
        top = lastMouseY;
        left = lastMouseX;
        moreFeat = ",screenX=" + lastMouseX + ",screenY=" + lastMouseY;
	}
	var sFeatures = "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + ",scrollbars=" + scrollbar + ",toolbars=" + toolbar + ",resizable=" + resize;
	if (popWin && !popWin.closed) popWin.close();
	popWin = window.open("", "", sFeatures);
	if (url != "") popWin.location.href = url;
}

// Popup Calendar functions
function calendar(idDate, postBack)
{
	url = 'Calendar.aspx?idDate=' + idDate + '&selected=' + document.forms[0].elements[idDate].value + "&postBack=" + postBack;
	openWin(url, "S", 195, 150, 0, 0, 0); 
}

function SetDate(idDate, newDate, postBack)
{
	document.forms[0].elements[idDate].value = newDate;
	if (postBack) __doPostBack(idDate,'');
}	

function UserProfile(userid, name)
{
	url = "UserPopup.aspx?userid=" + userid + "&name=" + name;
	openWin(url, "S", 400, 150, 0, 0, 0); 
}
	
// Set Last position of mouse
function setLastPos(e) 
{
    if (isIE) e = window.event;
    lastMouseX = e.screenX;
    lastMouseY = e.screenY;
}

function initPage()
{
	window.status = "";
}

function exitPage() 
{
	if (popWin && !popWin.closed) popWin.close();
}

window.onload = initPage;
window.onunload = exitPage;
// End of Script