/* <![CDATA[ */
/*
#####################################################################
Author: TSO
Description: "Lite" version of pop up/under script
Version: 0.90
#####################################################################
*/

/*
=======================================
Define functions and variables
=======================================
*/

/* getCookie() -- Get a cookie */
function getCookie(name)
{
	var pos = document.cookie.indexOf(name+"=");
	if (pos<0) return null;
	var endpos = document.cookie.indexOf(";",pos);
	if (endpos<0) endpos=document.cookie.length;
	var cstr = document.cookie.substring(pos+name.length+1,endpos);
	return unescape(cstr);
}

/* setCookie() -- Sets a cookie */
function setCookie(name, value, expire)
{
	var expDate = new Date();
	if (expire) { expDate.setTime(expDate.getTime() + expire); }
	var expStr = (expire) ? "; expires=" + expDate.toGMTString() : "";
	document.cookie = name + "=" + escape(value) + expStr;
}

/* Maximize window */
function maximize()
{
	self.moveTo(0,0);
	self.resizeTo(screen.availWidth,screen.availHeight);
}

/* isOpen() -- Check to see if popup is open */
function isOpen() { return (popWindow && popWindow.open && !popWindow.closed); }

/* stayUnder() -- Put popup under */
function stayUnder() { if (isOpen()) { popWindow.blur(); } self.focus(); }

/* popCalc() -- Calculate window properties */
function popCalc()
{
	/* Set flag */
	noCalc = false;

	/* Convert width and height to values */
	if (isNaN(popWidth))
	{
		var widthStr = String(popWidth);
		var widthInt = parseInt(widthStr);
		popWidth = (isNaN(widthInt)) ? maxWidth : ((widthInt >= 100 || widthInt < 0) ? maxWidth : Math.round(maxWidth * widthInt / 100));
	}
	if (isNaN(popHeight))
	{
		var heightStr = String(popHeight);
		var heightInt = parseInt(heightStr);
		popHeight = (isNaN(heightInt)) ? maxHeight : ((heightInt >= 100 || heightInt < 0) ? maxHeight : Math.round(maxHeight * heightInt / 100));
	}
	popAttrib = "width=" + popWidth + ",height=" + popHeight;

	/* Calculate positions */
	if (isNaN(popAlign))
	{
		popAttrib += ",left=";
		popAttrib += (popAlign == "center") ? ((maxWidth - popWidth)/2) : ((popAlign == "right") ? (maxWidth - popWidth) : 0);
	}
	else
	{
		popAttrib += (popWidth >= maxWidth) ? ("left=0,width=" + maxWidth) : (",left=" + popAlign + ",width=" + popWidth);
	}
	if (isNaN(popValign))
	{
		popAttrib += ",top=";
		popAttrib += (popValign == "middle") ? ((maxHeight - popHeight)/2) : ((popAlign == "bottom") ? (maxHeight - popHeight) : 0);
	}
	else
	{
		popAttrib += (popHeight >= maxHeight) ? ("top=0,height=" + maxHeight) : (",top=" + popValign + ",height=" + popHeight);
	}

	/* Check flag for no attributes */
	if (noAttrib) { return; }

	/* Add attributes */
	popAttrib += ((directories) ? ",directories=yes" : ",directories=no")
	+ ((win_location) ? ",location=yes" : ",location=no")
	+ ((menubar) ? ",menubar=yes" : ",menubar=no")
	+ ((resizable) ? ",resizable=yes" : ",resizable=no")
	+ ((scrollbars) ? ",scrollbars=yes" : ",scrollbars=no")
	+ ((status) ? ",status=yes" : ",status=no")
	+ ((toolbar) ? ",toolbar=yes" : ",toolbar=no")
	+ attribs;
}

/* Main popup function */
function pop()
{
	if (!exit) return;
	if (popPeriod > 0 && getCookie(popName) != null) return;

	/* Calculate attributes */
	if (noCalc) { popCalc(); }

	/* Do popup */
	if (!isOpen()) { popWindow = window.open(popUrl,popName,popAttrib); }
	if (popPeriod > 0) { setCookie(popName,1,popPeriod*1000); }
	if (popUnder) { stayUnder(); }
}

/* Popup window */
var popWindow = null;

/* Maximum dimensions of popup */
var maxWidth = screen.availWidth - 12;
var maxHeight = screen.availHeight - 144;

/* Popup attributes */
var popAttrib = "";

/* Flag for attributes calculation */
var noCalc = true;

/*
=======================================
Set popup attributes below
=======================================
*/


/* Name of popup (note: can also use "_blank" for new windows) */
var popName = "popup";

/* Popup URL */
var popUrl = "popup.htm";

/* Popup dimensions (either values or a percentage, ie "80%") */
var popWidth = maxWidth;
var popHeight = maxHeight;

/* Popunder flag */
var popUnder = false;

/* Horizontal position (left, center, right, or an offset value; default = center) */
var popAlign = "center";

/* Vertical position (top, middle, bottom, or an offset value; default = middle) */
var popValign = "middle";

/* Window attributes */
var directories = false;
var win_location = false;
var menubar = false;
var resizable = false;
var scrollbars = false;
var status = false;
var toolbar = false;

/* For other window attributes */
var attribs = "";

/* Flag for no attributes (overrides the above attributes) */
var noAttrib = false;

var popPeriod = 0;

/* Flag you can set for no popup */
var exit = true;

/* ]]> */

