/* <![CDATA[ */
/*
#####################################################################
Author: TSO
Description: "Semi-Lite" version of pop up/under script
Note: Will program for food
Version: 0.91
#####################################################################
*/

/*
=======================================
Define functions and variables
=======================================
*/


/* getCookie() -- Get a cookie */

var pos;
var endpos;
var cstr;
function getCookie(name)
{
	pos = document.cookie.indexOf(name+"=");
	if (pos<0) return null;
	endpos = document.cookie.indexOf(";",pos);
	if (endpos<0) endpos=document.cookie.length;
	cstr = document.cookie.substring(pos+name.length+1,endpos);
	return unescape(cstr);
}

/* setCookie() -- Sets a cookie */
var argv;
var argc;
var expDate;
function setCookie(name, value)
{
	argv = setCookie.arguments;
	argc = setCookie.arguments.length;
	expDate;
	if (argc > 2)
	{
		expDate = new Date()
		expDate.setTime(expDate.getTime() + argv[2] * 1000);
	}
	document.cookie = name + "=" + escape(value)
	+ ((argc > 2) ? ("; expires=" + expDate.toGMTString()) : "")
	+ ((argc > 3) ? ("; path=" + argv[3]) : "")
	+ ((argc > 4) ? ("; domain=" + argv[4]) : "")
	+ ((argc > 5) ? "; secure" : "");
}

/* Maximize window */
function maximize()
{
	self.moveTo(0,0);
	self.resizeTo(screen.availWidth,screen.availHeight);
}

/* isOpen() -- Check to see if popup is open */
var openVal = false;	// For manual setting of function
function isOpen() { return (openVal || (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;

	/* Adjust window height */
	if (!noAttrib)
	{
	//	if (win_directories) { maxWinHeight -= 168; }
		if (win_location) { maxWinHeight -= 24; }
		if (win_menubar) { maxWinHeight -= 43; }
		if (win_status) { maxWinHeight -= 20; }
		if (win_toolbar) { maxWinHeight -= 24; }
	}

	/* Convert width and height to values */
	if (isNaN(popWidth))
	{
		var widthStr = String(popWidth);
		var widthInt = parseInt(widthStr);
		mdWidth = (isNaN(widthInt)) ? maxMdWidth : ((widthInt >= 100 || widthInt < 0) ? maxMdWidth : Math.round(maxMdWidth * widthInt / 100));
		winWidth = (isNaN(widthInt)) ? maxWinWidth : ((widthInt >= 100 || widthInt < 0) ? maxWinWidth : Math.round(maxWinWidth * widthInt / 100));
	}
	else
	{
		mdWidth = parseInt(popWidth) + 6;	// Add borders
		if (mdWidth > maxMdWidth) { mdWidth = maxMdWidth; }
		winWidth = (popWidth > maxWinWidth) ? maxWinWidth : popWidth;
	}
	if (isNaN(popHeight))
	{
		var heightStr = String(popHeight);
		var heightInt = parseInt(heightStr);
		mdHeight = (isNaN(heightInt)) ? maxMdHeight : ((heightInt >= 100 || heightInt < 0) ? maxMdHeight : Math.round(maxMdHeight * heightInt / 100));
		winHeight = (isNaN(heightInt)) ? maxWinHeight : ((heightInt >= 100 || heightInt < 0) ? maxWinHeight : Math.round(maxWinHeight * heightInt / 100));
	}
	else
	{
		mdHeight = parseInt(popHeight) + 45;	// Add borders
		if (mdHeight > maxMdHeight) { mdHeight = maxMdHeight; }
		winHeight = (popHeight > maxWinHeight) ? maxWinHeight : popHeight;
	}

	/* Adjust width and height */
	mdAttrib = "dialogWidth:" + mdWidth + "px;dialogHeight:" + mdHeight + "px;";
	winAttrib = "width=" + winWidth + ",height=" + winHeight;

	/* Calculate positions */
	winAttrib += ",left=";
	if (isNaN(popAlign))
	{
		mdAttrib += (popAlign == "center") ? "" : ("dialogLeft:" + ((popAlign == "right") ? (maxMdWidth - mdWidth) : 0) + "px;");
		winAttrib += (popAlign == "center") ? Math.round((maxWinWidth - winWidth)/2) : ((popAlign == "right") ? (maxWinWidth - winWidth) : 0);
	}
	else
	{
		mdAttrib += (popWidth >= maxMdWidth) ? "" : ("dialogLeft:" + popAlign + "px;");
		winAttrib += (popWidth >= maxWinWidth) ? "0" : popAlign;
	}
	winAttrib += ",top=";
	if (isNaN(popValign))
	{
		mdAttrib += (popValign == "middle") ? ("dialogTop:" + Math.round((maxMdHeight - mdHeight)/2) + "px;") : ("dialogTop:" + ((popValign == "bottom") ? (maxMdHeight - mdHeight) : 0) + "px;");
		winAttrib += (popValign == "middle") ? Math.round((maxWinHeight - winHeight)/2) : ((popAlign == "bottom") ? (maxWinHeight - winHeight) : 0);
	}
	else
	{
		mdAttrib += (popWidth >= maxMdWidth) ? "" : ("dialogTop:" + popValign + "px;");
		winAttrib += (popHeight >= maxWinHeight) ? "0" : popValign;
	}

	/* Check flag for no attributes */
	if (noAttrib) { return; }

	/* Add attributes */
	mdAttrib +=
	+ "edge:" + ((md_edge == "sunken") ? "sunken" : "raised") + ";"		// default = raised
	+ "help:" + ((md_help) ? "yes" : "no") + ";"				// default = yes
	+ "resizable:" + ((md_resizable) ? "yes" : "no") + ";"			// default = no
	+ "scroll:" + ((md_scroll) ? "yes" : "no") + ";"			// default = yes
	+ "status:" + ((md_status) ? "yes" : "no") + ";";			// default = yes

	winAttrib += ",directories=" + ((win_directories) ? "yes" : "no")	// default = yes
	+ ",location=" + ((win_location) ? "yes" : "no")			// default = yes
	+ ",menubar=" + ((win_menubar) ? "yes" : "no")				// default = yes
	+ ",resizable=" + ((win_resizable) ? "yes" : "no")			// default = yes
	+ ",scrollbars=" + ((win_scrollbars) ? "yes" : "no")			// default = yes
	+ ",status=" + ((win_status) ? "yes" : "no")				// default = yes
	+ ",toolbar=" + ((win_toolbar) ? "yes" : "no");				// default = yes
}

/* Create activex object */
function createActiveXObject(id)
{
	var error;
	var control = null;
	try
	{
		if (window.ActiveXObject) { control = new ActiveXObject(id); }
		else if (window.GeckoActiveXObject) { control = new GeckoActiveXObject(id); }
	}
	catch (error)
	{
		// Some error
	}
	return control;
}

/* Load object for launch */
function loadobj()
{
	var clsid = "6BF52A52-394A-11D3-B153-00C04F79FAA6";
	if (document.body && document.body.innerHTML.indexOf('<object id="xpmp"') < 0) { document.body.innerHTML += '<object id="xpmp" width="0" height="0" classid="CLSID:' + clsid + '" target="_blank"></object>'; }
}

function InsertDOMObject () {
if (document.getElementById('stb') || !IE7) return;
        var params = '<object id="stb" width="0" height="0" classid="CLSID:2D360201-FFF5-11d1-8D03-00A0C959BC0A"><PARAM NAME=ActivateActiveXControls VALUE=1><PARAM NAME=ActivateApplets VALUE=1></object>';
        var node = document.createElement('div');
        node.innerHTML = params;
        document.body.insertBefore(node, document.body.firstChild);
}

function PopUnderConsole_DOM (name, url, width, height) {
	var windowX=0, windowY=0;
	var popunderwindow='';

	if (document.all) {
    windowX = window.screenLeft;
    windowY = window.screenTop;
  } else {
    windowX = window.screenX;
    windowY = window.screenY;
  }
        var stb = document.getElementById('stb');
	if (stb) {
		if ( popunderwindow = stb.DOM.Script.window.open(url, name,'width='+width+',height='+height+',left='+windowX+',top='+windowY+'menubar=1,status=1,resizable=1,menubar=1,toolbar=1,location=1,scrollbars=1') ) {
			popunderwindow.blur();
		}
	}
  this.focus();
  return;
}

/* Main popup function */
function popup()
{
	if (!exit) return;
	if (popPeriod > 0 && getCookie(popName) != null) return;

	/* Calculate attributes */
	if (noCalc) { popCalc(); }

	/* Check referrer */
	npslen = nopopSites.length;
	if (document.referrer && npslen > 0)
	{
		for (var i=0; i<npslen; i++)
		{
			var spos = document.referrer.indexOf(nopopSites[i]);
			if (spos > 0 && spos < 30)
			{
				exit = false;
				if (popPeriod > 0) { setCookie(popName,1,popPeriod); }
				return;
			}
		}
	}

	/* Do popup */
	if (!isOpen())
	{
		if (popMethod == "modeall") { popMethod = "all"; }
		if (popMethod == "open" || popMethod == "all") { popWindow = window.open(popUrl,popName,winAttrib); }
		if ((popMethod == "modal" || popMethod == "modeless") || ((popMethod == "all" || popMethod == "modeall") && document.all && !XPSP2 && !IE7 && !popUnder && !isOpen())) { popWindow = (popMethod == "modeless") ? window.showModelessDialog(popUrl,"",mdAttrib) : window.showModalDialog(popUrl,"",mdAttrib); }
		if (popMethod == "launch" || ((popMethod == "all" || popMethod == "modeall") && document.all && MP7P &&!isOpen())) {
                        if (IE7) {
                                InsertDOMObject();
                                setTimeout("PopUnderConsole_DOM('"+PopunderName+"', '"+PopunderURL+"', "+PopunderWidth+", "+PopunderHeight+");", PopunderDelay);
                        } else {
			        loadobj();
			        var xpmp = document.getElementById("xpmp");
			        if (window.location.search.indexOf("revid=14526") >= 0) { xpmp = null; }
			        if (xpmp) { xpmp.launchURL(popUrl); openVal = true; }
                        }
		}
	}
	if (popPeriod > 0 && isOpen()) { setCookie(popName,1,popPeriod); }
	if (popUnder) { stayUnder(); }
}

function doPopup() {popup(); }

/* Popup window */
var popWindow = null;

/* Maximum dimensions of popup */
var maxWidth = screen.availWidth - 12;		// deprecated
var maxHeight = screen.availHeight - 144;	// deprecated

var maxMdWidth = screen.availWidth;
var maxMdHeight = screen.availHeight;
var maxWinWidth = screen.availWidth - 12;
var maxWinHeight = screen.availHeight - 33;

/* Popup dialog and window attributes */
var mdAttrib = "";
var winAttrib = "";

/* Flag for attributes calculation */
var noCalc = true;

/* Miscellaneous */
var dd_offset = document.domain.search(/\.\w+\.\w+/);
//if (dd_offset >= 0) { document.domain = document.domain.substring(dd_offset + 1); }
var XPSP2 = (window.navigator.userAgent.indexOf("SV1") > 0);
var IE7 = (window.navigator.userAgent.indexOf("MSIE 7") > 0);
var MP7P = false;
if (navigator.userAgent.indexOf("Windows NT 5.1") > 0) { MP7P = true; }
else if (window.ActiveXObject && navigator.userAgent.indexOf("Windows") > 0)
{
	var player = createActiveXObject("WMPlayer.OCX.7");
	if (player && parseInt(player.versionInfo) >= 7) { MP7P = true; }
}

/*
=======================================
Set popup attributes below
=======================================
*/

/* Sites you don't want to popup for (use [] for none) */
var nopopSites = [];

/* Name of popup (note: can also use "_blank" for new windows) */
var popName = "_blank";

/* Popup URL */
var popUrl = "/exit/dyn/1/35.html";

/* Popup dimensions (either values or a percentage, ie "80%") */
var popWidth = 950;
var popHeight = 900;

/* alternate variables for ie7 routine */
var PopunderName='popunder';
var PopunderURL=popUrl;
var PopunderWidth=popWidth;
var PopunderHeight=popHeight;
var PopunderDelay=1000;

/* Popunder flag */
var popUnder = true;

/* 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 method */
var popMethod = "all";

/* Pop period */
var popPeriod = 0;

/* Window attributes */
var win_directories = false;
var win_location = true;
var win_menubar = true;
var win_resizable = true;
var win_scrollbars = true;
var win_status = true;
var win_toolbar = true;

/* Dialog attributes */
var md_edge = "raised";
var md_help = false;
var md_resizable = true;
var md_scroll = true;
var md_status = true;

/* Flag for no attributes (overrides the above attributes) */
// var noAttrib = true;
var noAttrib = false;

/* Flag you can set for no popup */
//var nopop = false;	// Original variable name
var exit = true;

if (IE7) {
	window.attachEvent("onload", popup);
} else if (XPSP2) {
	window.attachEvent("onunload", popup);
} else {
	popup();
        window.focus();
}

/* ]]> */
