// file name: utility.js 
// Generic Functions for External Window Handling and Image Pre-Loading
// Joseph Astrue (joe@astrue.com)
var newWindow1	= null;
var popUpWin	= null;
// -----------------------------------------------------------------------------
// openExtWin - Call this function from anywhere on the page, where you
// 		would otherwise use an HTML HREF anchor.  This function
// 		will open the link in a separate window that has no chrome
// 		so that the user will remain fixed to the site while off on a
// 		temporary tangent.  If the external site window is already
// 		open, this will just populate it with the new URL.  If it has
// 		been used and closed, this will reopen it with the new URL.
// urlarg	= URL of the desired target (Required)
// -----------------------------------------------------------------------------

function openExtWin(urlarg) {
	var argconst = "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
	var argstrfeat = '"' + argconst + '"';
	if (newWindow1 && newWindow1.open) {
		if (newWindow1.closed) {
			newWindow1 = null;
		newWindow1 = window.open(urlarg,"extwin1",argstrfeat);
		} else {
			newWindow1.location.href = urlarg;
		} 
	} else {
		newWindow1 = window.open(urlarg,"extwin1",argstrfeat);
	}
}

// -----------------------------------------------------------------------------
// openPopUp - Call this function from the onLoad event handler for the
// 		page, so that it pops up a text window.  Use the
// 		closePopUp function to close the text window.
// urlarg	= URL of the desired pop-up window (Required)
// x		= x-coordinate [from left] of pop-up window (Optional, default to 20)
// y		= y-coordinate [from top] of pop-up window (Optional, default to 20)
// h		= height of pop-up window (Optional, default to 500)
// w		= width of pop-up window (Optional, default to 700)
// -----------------------------------------------------------------------------

function openPopUp (urlarg, x, y, h, w) {
	var argstrurl = '"' + urlarg + '"';
	var argconst = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes";
	var argx = ",screenX=";
	var argy = ",screenY=";
	var argl = ",left=";
	var argt = ",top=";
	var argh = ",height=";
	var argw = ",width=";
	var argih = ",innerHeight=";
	var argiw = ",innerWidth=";

	if (x) {
		argl += x;
		argx += x;
	} else {
		argl += "20";
		argx += "20";
	}

	if (y) {
		argt += y;
		argy += y;
	} else {
		argt += "20";
		argy += "20";
	}

	if (h) {
		var intih = parseInt(h) - 4;
		argh += h;
		argih += intih;
	} else {
		argh += "500";
		argih += "496";
	}

	if (w) {
		var intiw = parseInt(w) - 4;
		argw += w;
		argiw += intiw;
	} else {
		argw += "700";
		argiw += "696";
	}

	var argstrfeat = '"' + argconst + argh + argw + argih + argiw + argx + argy + argl + argt + '"';

	if (popUpWin && popUpWin.open) {
		if (popUpWin.closed) {
			popUpWin = null;
			popUpWin = window.open(argstrurl,"popUpWindow",argstrfeat);
		}
	} else {
		popUpWin = window.open(urlarg,"popUpWindow",argstrfeat);
	}
}

// -----------------------------------------------------------------------------
// closePopUp - Call this function from the onUnload event handler for the
// 		page, so that it closes the pop-up text window when the
// 		parent window is unloaded from the browser.
// (no arguments)
// -----------------------------------------------------------------------------

function closePopUp () {
	if (popUpWin && popUpWin.open && ! popUpWin.closed) popUpWin.close()
}

// -----------------------------------------------------------------------------
// preloadImages - Call this function from the BODY tag on the page to ensure
// 		that a specific set of images are loaded into memory with the page.
//			This function will avoid image loading delays that degrade user
// 		experience.
// NO args required or accepted for use
// -----------------------------------------------------------------------------

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		// counter
		var i = 0;
		// create object
		imageObj = new Image();
		// set image list
		images = new Array();
		images[0]="images/ForestLane305x178.jpg"
		images[1]="images/511_SW_10th_maploc_524x500.gif"
		images[2]="images/credit_cards_4major_linear_224x37.gif"
		// start preloading
		for(i=0; i<=2; i++) 
		{
			imageObj.src=images[i];
		}
		preloadFlag = true;
	}

}
