/**********************************************************************
Copyright (c)2007 by Graphical Dynamics, Inc. all rights reserved.

General events & functions.

 Date   Who Changes
------- --- -----------------------------------------------------------
11oct07 jlp Created.
17oct07     
**********************************************************************/

// AutoIntern...
g_oAINavInfo = 
	{
	logo		: "<img src='/images/ai-logo.gif' width=80 height=62>",
	dispName	: "AutoIntern",
	downloadURL	: "/autointern/download.html?auto=../pub/autointern21.zip",
	menuItems	: new Array
		(
		["Business Process Automation",	   "index.html"],
		["QuickBooks automation",		   "qb-automation.html"],
		["Automating<br>maintenance tasks", "why-crash.html"],
		["VBS/JS/WIL scripting",		   "vbs-automation.html"],
		["Screenshots",					   "screenshots.html"],
		["What's new in AutoIntern 2.1",   "whatsnew.html"],
		["Download AutoIntern",			   "download.html"],
		["Purchase AutoIntern",			   "pricing.html"]
		)
	};

// ClockMan95...
g_oCMNavInfo =
	{
	logo		: "<img src='/images/clock95logo.gif' width=72 height=75>",
	dispName	: "ClockMan95",
	downloadURL	: "/clockman95/download.html?auto=../pub/cm95-10.zip",
	menuItems	: new Array
		(
		["ClockMan95 vs. AutoIntern",	   "index.html"],
		["Download ClockMan95",			   "download.html"],
		["Purchase ClockMan95",			   "pricing.html"]
		)
	};

// Company info...
g_oGDINavInfo =
	{
	logo		: "<img src='/images/gdi-logo100.gif' width=113 height=100>",
	dispName	: "Graphical Dynamics, Inc.",
	downloadURL	: "",
	menuItems	: new Array
		(
		["Contact us",					   "index.html"],
		["Copyrights",					   "copyright.html"],
		["Privacy",						   "privacy.html"]
		)
	};

g_oPopup = null; // For popup screenshots


/**********************************************************************
LNavOnLoad (sProduct, sMenuItem);

Fills out the left navigation menu with links. The menuitem that the
calling page represents is not a link.

Parameters:
sProduct			"AI" or "CM95" - specifies which menuitem array to use.
sMenuItem			The menuitem text for this page.
**********************************************************************/
function LNavOnLoad (p_sProduct, p_sLeftNavItemText)
	{
	var oLeftNav	  = null; // <div id="LeftNav">
	var oInfo		  = null;
	var nMenuItem;
	var aMenuItem;
	
	
	switch (p_sProduct)
		{
		case "AI":   oInfo = g_oAINavInfo;  break;
		case "CM95": oInfo = g_oCMNavInfo;  break;
		case "GDI":  oInfo = g_oGDINavInfo; break;
		}
		
	oLeftNav = document.getElementById ("LeftNav");
	if (oLeftNav)
		{// This page has a left-navigation menu. Build the menu & insert it
		//  into the LeftNav div...
		sLeftNavText  = "<table width='100%' cellspacing=0 cellpadding=0><tr><td>\n";
		sLeftNavText += "<p align='center'>" + oInfo.logo + "\n";
		sLeftNavText += "<table cellpadding='2'>\n";
		for (nMenuItem=0; nMenuItem<oInfo.menuItems.length; nMenuItem++)
			{
			aMenuItem = oInfo.menuItems[nMenuItem];
			if (aMenuItem[0]==p_sLeftNavItemText)
				{sLeftNavText += "<tr><td class='LNavThisItem'>" + aMenuItem[0] + "</td>\n";
				}
			else
				{sLeftNavText += "<tr><td class='LNavOtherItem' onclick='LNavTDOnClick(" + '"' + aMenuItem[1] + '"' + ")'>" 
							   + "<a href='" + aMenuItem[1] + "'>" + aMenuItem[0] + "</a></td>\n";
				}
			sLeftNavText += "<tr><td class='LNavBlankRow'></td>\n";
			}
		
		sLeftNavText += "</table>\n";
		
		if (oInfo.downloadURL != "")
			{sLeftNavText += "<p align='center'><a href='" + oInfo.downloadURL + "'><img src='/images/btn-download.gif' width='100' height='33' border=0></a>\n";
			}
		
		// Firefox-friendly right margin. Otherwise FF 2.0 would add margin only 
		// after initially allocating space for the div & the mainbody to its right...
		sLeftNavText += "<td class='LNavMarginR'>&nbsp;</table'>\n";
		
		oLeftNav.innerHTML = sLeftNavText;
		}
	
	return;
	}


/**********************************************************************
LNavTDOnClick (sURL);

Makes sure that the whole table cell is clickable as a link, not just
the text inside the <a> link.
**********************************************************************/
function LNavTDOnClick (p_sURL)
	{
	location.href =  p_sURL;
	
	return;
	}


/**********************************************************************
PopupPix (sPixName);

Pops up a window for viewing a screenshot. The pix are listed in the
"screenshot-popup.html" file.
**********************************************************************/
function PopupPix (p_sName)
	{
	oPix = new Image();
	oPix.src = "screenshots/"+p_sName+".jpg";
	g_oPopup = window.open ("screenshot-popup.html?theimage="+p_sName, "aiscreenshot", "width="+(oPix.width+20)+", height="+(oPix.height+100));
	g_oPopup.focus();
	}

	
/**********************************************************************
AutoDL ();

If ?auto=fileurl is defined in this document's url, then download fileurl.
**********************************************************************/
function AutoDL ()
	{
	var sQuery;
	var aQPairs;
	var n;
	var aQPair;
	
	
	sQuery = location.search.slice(1); // The query string minus the leading "?"
	aQPairs = sQuery.split("&");
	for (n=0; n<aQPairs.length; n++)
		{
		aQPair = aQPairs[n].split("=");
		if (aQPair[0]=="auto")
			{
			location.href = aQPair[1];
			return;
			}
		}
	
	return;
	}


/**********************************************************************
BuildPrevNextButtons (sPrevURL, sPrevText, sNextURL, sNextText);

Write out the HTML for a [Prev] [Next] button pair. If sPrevURL or
sNextURL are blank, those parts of the line will be blank.
**********************************************************************/
function BuildPrevNextButtons (p_sPrevURL, p_sPrevText, p_sNextURL, p_sNextText)
	{
	// Force text to stay on one line...
	p_sPrevText.replace (" ", "&nbsp;");
	p_sNextText.replace (" ", "&nbsp;");
	
	document.writeln ("<p align='center'><table width='100%'><tr>");
	document.writeln ("<td width='50%' align='right'>");
	if (p_sPrevURL)
		{document.write ("<span class='small'><b><a href='" + p_sPrevURL + "'>" + p_sPrevText + "&nbsp;<img src='/images/btn-prev.gif' width='100' height='33' border=0 align='top'></a></b></span>");
		}
	else
		{document.write ("&nbsp;");
		}
	
	document.writeln ("<td width='50%' align='left'>");
	if (p_sNextURL)
		{document.writeln ("<span class='small'><b><a href='" + p_sNextURL + "'><img src='/images/btn-next.gif' width='100' height='33' border=0 align='top'>&nbsp;" + p_sNextText + "</a></b></span>")
		}
	else
		{document.write ("&nbsp;");
		}
	document.writeln ("</table>");
	}
	