/*
 * $Id: popup.js,v 1.2 2008/05/30 20:43:46 mripplin Exp $
 *
 * +------+   Copyright 2008, ICx Transportation Group
 * | ICx  |                   All Rights Reserved
 * +------+----------------------------------------------------------
 * This file is property of ICx Transportation Group.  Any unauthorized use or
 * duplication of this file, or removal of the header, constitutes
 * theft of intellectual property.
 *
 * This file contains functions to open the interactive map window, and
 * to open links from within popup windows.  It also contains utility
 * functions used in various places on the traffic site.
 *
 * TODO: Move non-popup-related functions to other files.
 */

/**
 * Open the interactive map.
 */
function openMap() {
	return openMapWindow("");
}

/**
 * Open the map with the driving times tool active.
 */
function openDrivingTimes() {
	return openMapWindow("drivingtimes=1");
}

/**
 * Open the map in a new browser window.
 * @param querystring	String to be appended to the query portion of the map URL.
 */
 
function openMapWindow(querystring) {
	var params = "left=0,top=0,screenX=0,screenY=0,toolbars=0,resizable=1";
	if (screen.availWidth >= 800) {
		params += ",width=790,height=550";
	}
	var mapwin = window.open("traffic_map.asp?" + querystring, "mapwin", params);
	mapwin.focus();
	return false;
}

/**
 * Find all links with target="_blank" or target="parent" and make them open in
 * the parent window instead of a new window.  Links with target="_blank" should
 * also close the current window.
 */
function makeParentLinks() {
	for (var i=0; i < document.links.length; i++) {
		link = document.links[i];
		if (link.target == "_blank")
			link.onclick = parentLink;
		else if (link.target == "parent")
			link.onclick = parentLink2;
	}
}

/**
 * If possible, open this link in the window that opened this frameset.
 * CLOSE this window afterwards.
 */
function parentLink() {
	if (parent.opener && !parent.opener.closed) {
		parent.opener.location = this.href;
		parent.opener.focus();
		parent.close();
		return false;
	}
	else return true;
}

/**
 * If possible, open this link in the window that opened this frameset.
 * DON'T close this window afterwards.
 */
function parentLink2() {
	if (parent.opener && !parent.opener.closed) {
		parent.opener.location = this.href;
		parent.opener.focus();
		return false;
	}
	else return true;
}



