//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++ Filename......: popup-lib.js
//++ Author........: Melvyn Sopacua
//++ Type..........: JavaScript Library
//++ Purpose.......: Making popup windows easy
//++ Version.......: 1.0
//++ Version Date..: May 13th, 2000
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

/*Usage:

This library can be used in 2 different ways:
[1] By calling the fnPopup function
[2] By creating a popUp object specifically

@[1]_Calling_the_fnPopup_function__________________________
The fnPopup function contains 4 templates for windows, with
specific heights, features and screen alignments. You can
modify these, by looking at the comments.
If you're farmiliar with JavaScript, you may add your own,
by adding another case statement.

Syntax:
objReference = fnPopup(url, window_target_name, template_type)

@[2]_Creating_a_popUp_object_______________________________
You may also create a popup object yourself. Remember to
always call the setFeatures method.
Default values for the popup object, are:
width: 640
height: 480
center: true (centers popup on screen)
top: 0
left: 0

Syntax:
objReference = new popUp(width, height, center?, screen_position_top, screen_position_left);
objReference.setFeatures(directories, locationbar, menubar, resizable, scrollbars, statusbar, titlebar, toolbar, hotkeys);
window.open(url, window_target_name, objReference.featString);


Regarding the setFeatures method:
0 or not specified = false
1 = true

Exception is the scrollbar:
0 = false
1 = true
2 = auto
not specified = not mentioned (equals 'auto' in most browsers).
*/

/*
Copyright:
Feel free to use/modify this script, but do not modify
this copyright section or the file information at the top.

If you have any questions, email:
mshtml@nyvlem.mine.nu

*/

var scrWidth = parseInt(screen.width);
var scrHeight = parseInt(screen.height);

function popUp(width, height, center, top, left) {
	this.center = center || true;
	this.top = top || 0;
	this.left = left || 0;
	this.width = width || 640;
	this.height = height || 480;
	this.featString = new String();
	this.checkDimensions = checkDimensions;
	this.centerPosition = centerPosition;
	this.setFeatures = setFeatures;
	this.defined = new Boolean(1);
	this.checkDimensions();
	if(this.center == true) {
		this.centerPosition();
	}
}

function checkDimensions() {
	if(this.defined) {
		if(this.width >= screen.availWidth) {
			this.width = 0.9 * screen.availWidth;
		}
	
		if(this.height >= screen.availHeight) {
			this.height = 0.9 * screen.availHeight;
		}
	} else {
		//failsafe in case object creation interferes with asynchronous execution.
		setTimeout("checkDimensions()", 100);
	}
}

function checkOM() {
	if(navigator.appName.indexOf("Microsoft") == -1) {
		return true;
	} else {
		return false;
	}
}

function centerPosition() {
	//center popup
	this.left = parseInt((scrWidth - this.width) / 2);
	this.top = parseInt((scrHeight - this.height) / 2);
}

function setFeatures(dir, loc, menu, rsize, scrll, stat, ttle, tool, hkeys) {
	this.featString += (dir) ? "directories=yes," : "directories=no,";
	this.featString += (loc) ? "location=yes," : "location=no,";
	this.featString += (menu) ? "menubar=yes," : "menubar=no,";
	this.featString += (rsize) ? "resizable=yes," : "resizable=no,";
	
	if(typeof(scrll) != 'undefined') {
		switch (scrll) {
			case 0 :
				this.featString += "scrollbars=0,";
				break;
			case 1 :
				this.featString += "scrollbars=1,";
				break;
			case 2 :
				this.featString += "scrollbars=2,";
				break;
		}
	}
	
	this.featString += (stat) ? "status=yes," : "status=no,";
	this.featString += (ttle) ? "titlebar=yes," : "titlebar=no,";
	this.featString += (tool) ? "toolbar=yes," : "toolbar=no,";
	this.featString += (hkeys) ? "hotkeys=yes," : "hotkeys=no,";
	this.featString += (checkOM()) ? "outerWidth=" + this.width +  ",outerHeight=" + this.height + ",screenX=" + this.left + ",screenY=" + this.top : "width=" + this.width + ",height=" + this.height + ",left=" + this.left + ",top=" + this.top;
}

function fnPopup(strUrl, strTarget, strType) {
	switch (strType) {
		case 'xmp' :
			//width, height, top, left, center
			popupXmp = new popUp(550, 400);
			//dir, loc, menu, rsize, scrll, stat, ttle, tool, hkeys
			popupXmp.setFeatures(0,0,0,1,1,1,1,0,0);
			//result: 550x400, centered, resizable, scrollable, statusbar and titlebar.
			return window.open(strUrl, strTarget, popupXmp.featString);
		case 'xmple' :
			//width, height, top, left, center
			popupXmple = new popUp(550, 400);
			//dir, loc, menu, rsize, scrll, stat, ttle, tool, hkeys
			popupXmple.setFeatures(0,0,0,1,1,1,1,0,0);
			//result: 550x400, centered, resizable, scrollable, statusbar and titlebar.
			return window.open(strUrl, strTarget, popupXmple.featString);
		case 'tutor' :
			popupTutor = new popUp();
			popupTutor.setFeatures(0,0,0,1,0,1,1,1,0);
			//result: default dimensions, centered, resizable, statusbar, titlebar, toolbar
			return window.open(strUrl, strTarget, popupTutor.featString);
		case 'msgBoard' :
			popupMsgBoard = new popUp(640,480);
			popupMsgBoard.setFeatures(0,0,0,1,2,1,1,0,0);
			//result: 640x480, centered, resizable, scrollable, statusbar and titlebar
			return window.open(strUrl, strTarget, popupMsgBoard.featString);
		case 'info' :
			popupInfo = new popUp(100,100,false);
			popupInfo.setFeatures();
			//result: 100x100, upper left corner, completely blank.
			return window.open(strUrl, strTarget, popupInfo.featString);
		case 'cbond' :
			popupBlond = new popUp(780,350)
			popupBlond.setFeatures(0,0,0,1,2,0,0,0,0);
			return window.open(strUrl, strTarget, popupBlond.featString);
		case 'msdimitri' :
			popupMS = new popUp(600,422)
			popupMS.setFeatures(0,0,0,1,2,0,0,0,0);
			return window.open(strUrl, strTarget, popupMS.featString);
		case 'euro' :
			popupEuro = new popUp(600,383);
			popupEuro.setFeatures(0,0,0,1,2,0,0,0,0);
			return window.open(strUrl, strTarget, popupEuro.featString);
		case 'wwreactie' :
			popupReactie = new popUp(400,441)
			popupReactie.setFeatures(0,0,0,1,2,1,1,0,0);
			return window.open(strUrl, strTarget, popupReactie.featString);
		case 'wwprint' :
			popupPrint = new popUp(675,578)
			popupPrint.setFeatures(0,0,0,1,2,1,1,0,0);
			return window.open(strUrl, strTarget, popupPrint.featString);
		case 'wwemail' :
			popupEmail = new popUp(400,420)
			popupEmail.setFeatures(0,0,0,1,2,1,1,0,0);
			return window.open(strUrl, strTarget, popupEmail.featString);
	}
}

