function OpenImage(image)
{
	var file = image.src.substring(0, image.src.lastIndexOf('.'));
	window.open(file + "Full.gif", "FullImage", "menubar=no,toolbar=no,resizable=yes");
}

function NavigateTo(newLoc)
{
	var title = document.getElementById("sectionTitle").innerHTML;
	var oldLoc = document.location.href;
	window.navigate(newLoc + "?title=" + title + "&loc=" + oldLoc);

}

function RenderBackNavigate()
{

	var param = document.location.search.substring(1);
	if (param != "")
	{
		var title = getValue("title", param);
		var oldLoc = getValue("loc", param);
		var backEl = document.getElementById("backNavigate");
		backEl.innerHTML = "<LI><a href=\"" + oldLoc + "\" title=\"return to " + title + "\">" + title + "</LI></a>";
	}
}

function getValue(param, raw)
{
	var value = raw.substring(raw.indexOf(param));
	value = value.substring(value.indexOf('=') + 1);
	if (value.indexOf('&') > 0)
		value = value.substring(0, value.indexOf('&'));
	return value.replace("%20", "&nbsp;");
}


// Returns the root path
function getPrefix()
{
	var loc = document.location.pathname.substring(document.location.pathname.lastIndexOf('/')+1);
	var prefix = "";
	if (loc != "home.htm")
		prefix = "../";
	return prefix;
}

function getCategory()
{
	var loc = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('/'));
	return loc.substring(loc.lastIndexOf('/')+1);

}

function getLocation()
{
	var loc = document.location.pathname.substring(1);
	return loc.substring(loc.indexOf('/')+1);
}


// Displays the header, which includes the purple line, logo, contact link and footer text
function RenderHeader()
{
	//WY - to dynamically get the year
	var currentDate = new Date();
	var currentYear = currentDate.getYear();

	var prefix = getPrefix();
	var headEl = document.getElementById("heading");

	// Print the logo
	if (prefix != "")
		headEl.innerHTML = "<IMG ALT=\"Go to the Portal Insight home page\" SRC=\"" + prefix + "images/Logo.gif\" style=\"z-index:4;position:absolute;top:30;cursor:hand\" onclick=\"window.location='../home.htm'\">";
	else
		headEl.innerHTML = "<IMG SRC=\"" + prefix + "images/Logo.gif\" style=\"z-index:3;position:absolute;top:30\">";

	// Print the purple line
	headEl.innerHTML += "<IMG SRC=\"" + prefix + "images/blank.gif\" style=\"z-index:-2;position:absolute;left:0;top:30\" width=\"576px\" height=\"60px\">";
	headEl.innerHTML += "<IMG SRC=\"" + prefix + "images/swirlContinue.gif\" style=\"z-index:-1;position:absolute;top:101;left:0\" height=\"60px\" width=\"80px\">";
	headEl.innerHTML += "<IMG SRC=\"" + prefix + "images/swirlSymmetrical.gif\" style=\"z-index:-1;position:absolute;top:30;left:80\">";
	headEl.innerHTML += "<IMG SRC=\"" + prefix + "images/swirlContinue.gif\" style=\"z-index:-3;position:absolute;top:30;align:right;right:0\" width=\"100%\" height=\"60px\">";

	var footEl = document.getElementById("copyRight");
	// Print the footer text
	footEl.innerHTML = "&copy;"+currentYear+" Portal Insight. All rights reserved.";
	footEl.innerHTML += " | <a href=\"#\" onclick=\"window.open('" + prefix + "legal.htm','Legal','height=200,width=400')\">Legal notice</a>";
	footEl.innerHTML += " | <a href='" + prefix + "about/sitemap.htm'\">Site map</a>";
	var category = getCategory();
	if (category == "products" || category == "portal")
	{
		footEl.innerHTML += " | <a href='" + prefix + "about/pricelist.htm?title=" + getTitle(true) + "&loc=" + prefix + getCategory() + "/" + getLocation() + "'\">Price list</a>";
	}

	// Print the contact link
	footEl.innerHTML += "<a href=\"mailto:info@portalinsight.com?subject=Web%20Site%20Inquiry\"><DIV title=\"E-mail Portal Insight\" class=\"contact\"><img src=\"" + prefix + "images/mail.gif\">Contact</DIV></a>";
}

// Displays the navigational drop-down menus
function RenderMenu(menu)
{
	buildMenu(menu);
	indicateDisplayed();
	runMenu();	
}

// Displays the site map content
function RenderMap(map)
{
	buildMenu(map);
	buildHidden(map);
}

/*var Products = new Array(8);
Products[0] = new Array("0","File&nbsp;Manager","products/fileManager.htm","$7,500");
Products[1] = new Array("14","Learning&nbsp;Manager","products/learningManager.htm","from $12,500");
Products[2] = new Array("1","Usage&nbsp;Monitor","products/usageMonitor.htm","$6,000");
Products[3] = new Array("2","Issue&nbsp;Manager","products/issueManager.htm","$9,500");
Products[4] = new Array("3","ESS&nbsp;Workspace","products/corporateDirectory.htm","$6,000");
Products[5] = new Array("4","Team&nbsp;Tracker","products/teamTracker.htm","$8,000");
Products[6] = new Array("5","Asset&nbsp;Scheduler","products/assetScheduler.htm","$9,500");
Products[7] = new Array("6","Dashboard&nbsp;Manager","products/dashboardManager.htm","$9,500");
var Tools = new Array(7);
Tools[0] = new Array("7","Workflow&nbsp;Engine","portal/workflowEngine.htm","$4,500");
Tools[1] = new Array("8","Directory&nbsp;Browser","portal/directoryBrowser.htm","$2,500");
Tools[2] = new Array("9","Directory&nbsp;Manager","portal/directoryManager.htm","$4,500");
Tools[3] = new Array("10","Community&nbsp;Navigator","portal/communityNavigator.htm","$2,000");
Tools[4] = new Array("11","Announcement&nbsp;Builder","portal/easyAnnouncements.htm","$4,500");
Tools[5] = new Array("12","Excel&nbsp;Manager","portal/excelManager.htm","$1,500");
Tools[6] = new Array("13","World&nbsp;Clocks","portal/worldClocks.htm","$1,500");
*/
var Products = new Array(5);
Products[0] = new Array("1","Dashboard&nbsp;Manager","products/dashboardManager.htm","$9,500");
Products[1] = new Array("6","Help&nbsp;Desk&nbsp;Central","products/helpDeskCentral.htm","$9,500");
//Products[1] = new Array("1","Usage&nbsp;Monitor","products/usageMonitor.htm","$6,000");
Products[2] = new Array("0","Asset&nbsp;Scheduler","products/assetScheduler.htm","$9,500");
Products[3] = new Array("4","ESS&nbsp;Workspace","products/essWorkspace.htm","$7,500");
Products[4] = new Array("8","Learning&nbsp;Manager","products/learningManager.htm","$19,500")

var Tools = new Array(7);
Tools[0] = new Array("10","Usage&nbsp;Monitor","products/usageMonitor.htm","$6,000");
Tools[1] = new Array("3","Directory&nbsp;Manager","portal/directoryManager.htm","$5,000");
Tools[2] = new Array("2","Directory&nbsp;Browser","portal/directoryBrowser.htm","$3,000");
//Tools[1] = new Array("7","Community&nbsp;Navigator","portal/communityNavigator.htm","$2,000");
Tools[3] = new Array("5","File&nbsp;Manager","products/fileManager.htm","$7,500");
Tools[4] = new Array("9","Photo&nbsp;Manager","portal/photoManager.htm","$5,000");
Tools[5] = new Array("7","Issue&nbsp;Management&nbsp;Toolkit","products/issueManager.htm","$9,500");
Tools[6] = new Array("11","Workflow&nbsp;Engine","portal/workflowEngine.htm","$5,000");
//Tools[4] = new Array("10","World&nbsp;Clocks","portal/worldClocks.htm","$1,500");


function RenderPrices(list)
{
	var listEl = document.getElementById(list);

	buildApps(true, listEl.firstChild, Products.concat(Tools));

}

function sortNumber(a,b)
{
	return a[0] - b[0];
}

function buildApps(showPrice, menuEl, appArr)
{

	var prefix = getPrefix();
	var arr = appArr;
	if (showPrice)
		arr = appArr.sort(sortNumber);

	for (var i=0; i<appArr.length; i++)
	{
		if (showPrice)
		{
			var tr = menuEl.appendChild(document.createElement("<TR>"));
			var td = tr.appendChild(document.createElement("<TD>"));
			td.innerHTML += "&nbsp;<img src=\"../images/productBullet.gif\">&nbsp;&nbsp;<a href=\"" + prefix + appArr[i][2] + "\">" + appArr[i][1] + "</a>";
			td = tr.appendChild(document.createElement("<TD class=\"tableTick\">"));
			td.innerHTML += appArr[i][3];
		}
		else
			menuEl.innerHTML += "	<li><a href=\"" + prefix + appArr[i][2] + "\">" + appArr[i][1] + "</a></li>";
	}


}




// Builds the top two level site areas
function buildMenu(menu)
{

	var section = document.location.pathname.substring(0,document.location.pathname.lastIndexOf('/'));
	section = section.substring(section.lastIndexOf('/')+1);

	var prefix = getPrefix();

	var menuEl = document.getElementById(menu);
	// Builds the top level site areas
	if (section == "about")
		menuEl.innerHTML += "<li><a id=\"displayed\">About Us</a><ul id=\"aboutMenu" + menu + "\"></ul></li>";
	else
		menuEl.innerHTML += "<li><a>About Us</a><ul id=\"aboutMenu" + menu + "\"></ul></li>";

	if (section == "products")
		menuEl.innerHTML += "<li><a id=\"displayed\">Products</a><ul id=\"productMenu" + menu + "\"></ul></li>";
	else
		menuEl.innerHTML += "<li><a>Products</a><ul id=\"productMenu" + menu + "\"></ul></li>";

	if (section == "portal")
		menuEl.innerHTML += "<li><a id=\"displayed\">Portal&nbsp;Tools</a><ul id=\"portalMenu" + menu + "\"></ul></li>";
	else
		menuEl.innerHTML += "<li><a>Portal&nbsp;Tools</a><ul id=\"portalMenu" + menu + "\"></ul></li>";

	if (section == "services")
		menuEl.innerHTML += "<li><a id=\"displayed\">Services</a><ul id=\"servicesMenu" + menu + "\"></ul></li>";
	else
		menuEl.innerHTML += "<li><a>Services</a><ul id=\"servicesMenu" + menu + "\"></ul></li>";
	
	if (prefix != "")
		menuEl.innerHTML += "<li><a style=\"cursor:auto\" href=\"../home.htm\">Home</a><ul id=\"homeMenu" + menu + "\"></ul></li>";
	else
		menuEl.innerHTML += "<li><a style=\"cursor:auto\" href=\"about/contact.htm\">Contact Us</a></li>";

	// Builds second level site areas
	menuEl = document.getElementById("aboutMenu" + menu + "");
//	menuEl.innerHTML += "	<li><a href=\"" + prefix + "about/experts.htm\">The&nbsp;Enterprise&nbsp;Web&nbsp;Experts</a></li>";
	menuEl.innerHTML += "	<li><a href=\"" + prefix + "about/news.htm\">News</a></li>";
	menuEl.innerHTML += "	<li><a href=\"" + prefix + "about/corporate.htm\">Corporate&nbsp;Overview</a></li>";
//	menuEl.innerHTML += "	<li><a href=\"" + prefix + "about/management.htm\">Management</a></li>";
	menuEl.innerHTML += "	<li><a href=\"" + prefix + "about/contact.htm\">Contact Us</a></li>";
	menuEl.innerHTML += "	<li><a href=\"" + prefix + "about/careers.htm\">Careers</a></li>";

	// Pull these functions out, because we want to use it for the pricelist
	buildApps(false, document.getElementById("productMenu" + menu + ""), Products);
	buildApps(false, document.getElementById("portalMenu" + menu + ""), Tools);

	
	menuEl = document.getElementById("servicesMenu" + menu + "");
	menuEl.innerHTML += "	<li><a href=\"" + prefix + "services/development.htm\">Custom&nbsp;Development</a></li>";
	if (menu != 'menu')
		menuEl.innerHTML += "	<li><a href=\"" + prefix + "services/consulting.htm\">Consulting</a><ul id=\"consultingMenu\"></ul></li>";
	else
		menuEl.innerHTML += "	<li><a href=\"" + prefix + "services/consulting.htm\">Consulting</a></li>";
	menuEl.innerHTML += "	<li><a href=\"" + prefix + "services/support.htm\">Support</a></li>";
	if (menu != 'menu')
		menuEl.innerHTML += "	<li><a href=\"" + prefix + "services/training.htm\">Training</a><ul  id=\"trainingMenu\"></ul></li>";
	else
		menuEl.innerHTML += "	<li><a href=\"" + prefix + "services/training.htm\">Training</a></li>";
}

// Builds lower level site areas
function buildHidden(map)
{
	var prefix = getPrefix();
	
	var mapEl = document.getElementById("consultingMenu");
	mapEl.innerHTML = "	<li><a href=\"" + prefix + "services/healthCheck.htm\">Portal Health Check Overview</a></li>";
	mapEl.innerHTML += "	<li><a href=\"" + prefix + "services/healthCheckTasks.htm\">Health Check Tasks and Deliverables</a></li>";

	mapEl = document.getElementById("trainingMenu");
	mapEl.innerHTML = "	<li><a href=\"" + prefix + "services/announcement.htm\">Plumtree Training Announcement</a></li>";
	mapEl.innerHTML += "	<li><a href=\"" + prefix + "services/introductionToPortals.htm\">Introduction to Portals</a></li>";
	mapEl.innerHTML += "	<li><a href=\"" + prefix + "services/gettingStartedWithAPortal.htm\">Getting Started With A Portal</a></li>";
	mapEl.innerHTML += "	<li><a href=\"" + prefix + "services/portalFoundations.htm\">Managing Your Portal Deployment</a></li>";
	mapEl.innerHTML += "	<li><a href=\"" + prefix + "services/portalFoundations.htm\">Portal Foundations</a></li>";
	mapEl.innerHTML += "	<li><a href=\"" + prefix + "services/portalArchitecture.htm\">Portal Architecture and Administration</a></li>";
	mapEl.innerHTML += "	<li><a href=\"" + prefix + "services/portletDevelopment.htm\">Portlet Development</a></li>";
	mapEl.innerHTML += "	<li><a href=\"" + prefix + "services/contentAdmin.htm\">Content Administration</a></li>";
	mapEl.innerHTML += "	<li><a href=\"" + prefix + "services/collaborationServer.htm\">Collaboration Server</a></li>";

	mapEl = document.getElementById("homeMenu" + map + "");
	mapEl.innerHTML = "	<li><a href=\"#\" onclick=\"window.open('" + prefix + "legal.htm','Legal','height=200,width=400')\">Legal notice</a></li>";
	mapEl.innerHTML += "	<li><a href=\"" + prefix + "about/sitemap.htm\">Site map</a></li>";
	mapEl.innerHTML += "	<li><a href=\"" + prefix + "about/pricelist.htm\">Price list</a></li>";
	mapEl.innerHTML += "	<li><a href=\"#\" onclick=\"window.open('" + prefix + "catalog/productCatalog.pdf')\">Product catalog</a></li>";
}

// Indicates the displayed top level area
function indicateDisplayed()
{
	var loc = document.location.pathname.substring(document.location.pathname.lastIndexOf('/')+1);
	if (document.getElementById("displayed") && loc != "sitemap.htm")
	{
			var dispEl = document.getElementById("displayed");
			dispEl.innerHTML = "<span class='displayed'>[</span> " + dispEl.innerHTML + " <span class='displayed'>]</span>";
	}

}

function hideDisplay()
{
	if (currentMenu && currentMenu.getElementsByTagName("UL")[0])
	{
		currentMenu.getElementsByTagName("UL")[0].style.display = 'none';
		currentMenu = null;
	}
}

var currentMenu = null;
var currentTimer = null;
function runMenu()
{
	var menuEls = document.getElementById("menu").getElementsByTagName("LI");
	for (var i = 0; i < menuEls.length; i++)
	{
		menuEls[i].onmouseover = function() {
			hideDisplay();
			clearTimeout(currentTimer);
			if (this.getElementsByTagName("UL")[0])
				this.getElementsByTagName("UL")[0].style.display = 'block';
			currentMenu = this;
		}
	}
	var menuTd = document.getElementById("menu").parentNode;
	menuTd.onmouseout = function() {
			currentTimer = setTimeout(hideDisplay, 500);
	}
}

// Prints the "arrange a demo" link
function printFooter(online)
{
	var title = getTitle();
	var footer = getPrice(title) + "</DIV><UL class='goNavigate'>";
	if (online)
	{
		footer += "<LI><P>To view an online demonstration of " + title + ", ";
		footer += "<a href='../demos/" + title.replace(" ","").replace(" ","") + ".htm' target='_blank'>click here</a>.</P></LI>";
	}
	else
	{
		footer += "<LI><P>To learn more about " + title + ", ";
		footer += "<a href='mailto:sales@portalinsight.com?subject=Information%20Request%20-%20" + getTitle(true);
		footer += "&body=Please%20contact%20me%20with%20more%20details%20about%20" + getTitle(true) + ".'>click&nbsp;here</a>.</P></LI>";

	}
	footer += "<LI><P>To download a comprehensive product catalog, <a href='../catalog/productCatalog.pdf' target='_blank'>click here</a>.</P></LI>";
	footer += "<LI><P>To enquire further or purchase " + title + ", ";
	footer += "<a href='mailto:sales@portalinsight.com?subject=" + getTitle(true) + "%20Enquiry'>click here</a>.</P></LI></UL>";

	document.write(footer);
}

function printDemo(margin)
{
	if (!margin)
	{
		margin = "-60 0 20 -30";
	}
	document.write("<a href='../demos/" + getTitle().replace(" ","").replace(" ","") + ".htm' target='_blank'><IMG SRC='../images/demo.gif' style='margin:" + margin + "'></a>");
}

function getPrice(title)
{
	title = title.replace(" ","&nbsp;").replace(" ","&nbsp;");
	var list = Products.concat(Tools);
	for (var i=0; i<list.length; i++)
	{
		if (list[i][1] == title)
			return list[i][3];
	}
	return "";
}
// Returns the title of the product or portal tool
function getTitle(forURL)
{
	if (document.getElementById("sectionTitle"))
	{
		if (forURL)
			return document.getElementById("sectionTitle").innerHTML.replace(" ","%20");
		else
			return document.getElementById("sectionTitle").innerHTML;
	}
	return "";
}


