/* functions for calculating windows top & left position */
function getTop() {
  if (window.screenX) return window.screenY;
  if (window.screenTop) return window.screenTop;
  return 0;
}
function getLeft() {
  if (window.screenY) return window.screenX;
  if (window.screenLeft) return window.screenLeft;
  return 0;
}

/* specific pop-up functions for licensee info */
function popUpTeacher(id) {
	if (id == null || trim(id) == '') return;
    var top = getTop() + 50;
    var left = getLeft() + 100;
    details = 'dependent,toolbar=no,directories=no,resizable=yes,height=300,width=500,top=' + top + ',left=' + left;
    w = window.open('/components/InstructorPopup.html?instructorId=' + id, 'teacher_' + id.replace('-','_'), details);
    w.focus();
}
function popUpLocation(id) {
	if (id == null || trim(id) == '') return;
    var top = getTop() + 50;
    var left = getLeft() + 100;
    details = 'dependent,toolbar=no,directories=no,resizable=yes,height=300,width=500,top=' + top + ',left=' + left;
    w = window.open('/components/LocationPopup.html?locationId=' + id, 'location_' + id.replace('-','_'), details);
    w.focus();
}
function popUpEvent(id) {
	if (id == null || trim(id) == '') return;
    var top = getTop() + 150;
    var left = getLeft() + 250;
    details = 'dependent,toolbar=no,directories=no,resizable=yes,height=400,width=400,top=' + top + ',left=' + left;
    w = window.open('/events/Event.html?eventId=' + id, 'anevent_' + id.replace('-','_'), details);
}
function popUpDayAndTime(id) {
	if (id == null || trim(id) == '') return;
    var top = getTop() + 100;
    var left = getLeft() + 150;
    details = 'dependent,toolbar=no,directories=no,resizable=yes,height=160,width=420,top=' + top + ',left=' + left;
    w = window.open('/components/DayAndTimePopup.html?courseId=' + id, 'daytime_' + id.replace('-','_'), details);
    w.focus();
}
function popUpPrice(id) {
	if (id == null || trim(id) == '') return;
    var top = getTop() + 50;
    var left = getLeft() + 100;
    details = 'dependent,toolbar=no,directories=no,resizable=yes,height=350,width=550,top=' + top + ',left=' + left;
    w = window.open('/components/PricePopup.html?courseId=' + id, 'price_' + id.replace('-','_'), details);
    w.focus();
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

/* generic pop-up window function */
function openWindow(link, height, width) {
 openWindowAt(link, height, width, 25, 25);
}
function openWindowAt(link, height, width, x, y) {
 openWindowAt(link, height, width, x, y, 'no');
}
function openPrintWindowAt(link, height, width, x, y) {
 openWindowAt(link, height, width, x, y, 'yes');
}
function openWindowAt(link, height, width, x, y, menubar) {
 var t = getTop() + x, l = getLeft() + y;
 var winname = 'uniquePopup' + (new Date()).getTime();
 var options = 'menubar=' + menubar + ',scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',top=' + t + ',left=' + l;
 w = window.open(link, winname, options);
 w.focus();
}
