<!--
/*
File: new_window_v01.js
Author: Sean O'Neill (sean@marsworks.com)
Company: MARSWorks Inc.
Date: December 15, 2003
Purpose: functions to open external links in a new window
This also will work well by opening a new window in browsers with no JS or JS turned off...
In addition, each new window is given a new name so that it doesn't replace a currently
open window the user wants to keep as is...
Usage:
	call the function like this:
	<a href="http://www.somewhere.com" target="_blank" onClick="return goNewWindow(this.href);">Link Text</a>
*/

function goNewWindow(URL) {
	// check to see if they have selected not to open in a new window
	if (getCookie('OTT_Cookie_NewWindow') == "0") {
		document.location = URL;
		return false;
	}

	// get a random window name
	var newWindowName = 'OTT_Window_' + _stripChars((Math.random() + ''), '.');

	// figure out how large to make this window
	if (parseInt(navigator.appVersion) >= 4) {
		isDyn = true;
	}
	else {
		isDyn = false;
	}
	
	// set absolute defaults in case not a 4.0 or greater
	wWidth = 525;
	wHeight = 400;
	
	if (isDyn) {
		wWidth = parseInt(screen.width * .75);
		wHeight = parseInt(screen.height * .75);
	}

	if (_newWindow(URL, newWindowName, true, true, true, wHeight, wWidth, false)) {
		return false;
	}
}

// private - strips characters from a string
function _stripChars(input, invalid) {
	var newString = "";
	for (i = 0;  i < input.length; i++) {
    	myChar = input.charAt(i);
        if (invalid.indexOf(myChar) == -1)
        	newString += myChar;
	}
	return newString;
}

// private - generic function to open a new window with various properties
function _newWindow(URL, windowName, menuFlag, locationFlag, toolbarFlag,
				pHeight, pWidth, centerWindow) {
	if (parseInt(navigator.appVersion) >= 4) {
		isDyn = true;
	}
	else {
		isDyn = false;
	}

	if (pHeight != null && pWidth != null) {
		wWidth = pWidth;
		wHeight = pHeight;
	}
	else {
		// set absolute defaults in case not a 4.0 or greater
		wWidth = 525;
		wHeight = 400;
	
		// ok...figure out the screen size
	
		if (isDyn) {
			wWidth = parseInt(screen.width * .75);
			wHeight = parseInt(screen.height * .75);
		}
	}
	
	if (windowName == null)
		windowName = "popupWindow";
	
	if (menuFlag) menuFlag = 'yes'; else menuFlag = 'no';
	if (locationFlag) locationFlag = 'yes'; else locationFlag = 'no';
	if (toolbarFlag) toolbarFlag = 'yes'; else toolbarFlag = 'no';
	
	var windowFeatures = "height=" + wHeight + ",width=" + wWidth;
	windowFeatures += ",resizable=yes,toolbar=no,scrollbars=yes,menubar=";
	windowFeatures += menuFlag + ",location=" + locationFlag + ",toolbar=" + toolbarFlag;

	var windowHandle = window.open(URL, windowName, windowFeatures);
	
	if (centerWindow) {
		windowHandle.focus();
	
		if (isDyn) {
			var sWidth = screen.width;
			var sHeight = screen.height;
			
			windowHandle.moveTo(sWidth / 2 - wWidth / 2, 
								sHeight / 2 - wHeight / 2 - 35);
		}
	}

	return true;
}
// -->