/// <summary>
///  Custom Global variables
/// </summary>

var MenuHighlightedKeyword = "Highlighted";
var RightPanelImagePopupTag;
var RightPanelImagePopupDefaultImageURL;
var GlobalBrowserVariablesSet;
var Opera;
var Opera6;
var Opera7;
var InternetExplorer;
var InternetExplorer6;
var NetscapeNavigator4;
var NetscapeNavigator6;
var W3CCompliant;
var DocumentBody;
var PixelSuffix;

/// <summary>
///  These functions set global browser identification variables and include commonly used routines
///  Significant portions of this code are based on Zorn, W. (2005), "wz_tooltip.js v. 3.37", www.walterzorn.com [http://www.walterzorn.com/tooltip/tooltip_e.htm] cited below
///
///  wz_tooltip.js    v. 3.37
///  The latest version is available at http://www.walterzorn.com or http://www.devira.com or http://www.walterzorn.de
///  Copyright (c) 2002-2005 Walter Zorn. All rights reserved.
///  Created 1.12.2002 by Walter Zorn (Web: http://www.walterzorn.com)
///  Last modified: 2.12.2005
///  Cross-browser tooltips working even in Opera 5 and 6, as well as in NN 4, Gecko-Browsers, IE4+, Opera 7 and Konqueror. No onmouseouts required. Appearance of tooltips can be individually configured via commands within the onmouseovers.
///  LICENSE: LGPL
///  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
///  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
///  For more details on the GNU Lesser General Public License, see http://www.gnu.org/copyleft/lesser.html
/// </summary>

function SetGlobalBrowserVariables ()
{
	try
	{
		if (typeof(GlobalBrowserVariablesSet) == "undefined")
		{
			GlobalBrowserVariablesSet = true;
			Opera = !!(window.opera && document.getElementById);
			Opera6 = Opera && !document.defaultView;
			Opera7 = Opera && !Opera6;
			InternetExplorer = navigator.userAgent.toLowerCase().indexOf("msie") != -1 && document.all && ((document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body? document.body : null) && !Opera;
			InternetExplorer6 = InternetExplorer && parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE")+5)) >= 5.5;
			NetscapeNavigator4 = (document.layers && typeof document.classes != "undefined");
			NetscapeNavigator6 = (!Opera && document.defaultView && typeof document.defaultView.getComputedStyle != "undefined");
			W3CCompliant = !InternetExplorer && !NetscapeNavigator6 && !Opera && document.getElementById;
			DocumentBody = (((document.compatMode) && (document.compatMode != "BackCompat")) ? document.documentElement : ((document.body) ? document.body : null));
			PixelSuffix = (Opera6 || NetscapeNavigator4) ? "" : "px";
		}
	}
	catch (ExceptionObject)
	{
	}
}

function GetElement (Id)
{
	if (NetscapeNavigator4)
	{
		return((document.layers[Id] || null));
	}
	else
	{
		if (InternetExplorer)
		{
			return((document.all[Id] || null));
		}
		else
		{
			return((document.getElementById(Id) || null));
		}
	}
}

function ParseInteger (StringValue)
{
	var IntegerValue;
	IntegerValue = parseInt(StringValue);
	if (isNaN(IntegerValue))
	{
		return(0);
	}
	else
	{
		return(IntegerValue);
	}
}

function GetWidth (Tag)
{
	return(ParseInteger(NetscapeNavigator4 ? Tag.clip.width : (Tag.style.pixelWidth || Tag.offsetWidth)));
}

function GetHeight (Tag)
{
	return(ParseInteger(NetscapeNavigator4 ? Tag.clip.height : (Tag.style.pixelHeight || Tag.offsetHeight)));
}

/// <summary>
///  These functions check for the existence of the Macromedia Flash Player and publish Flash content
///  Significant portions of this code are based on the javascript code generated by Macromedia Flash Player
///  and Stearns, G. (2005), "FlashObject v1.2.3: Flash detection and embed", [http://blog.deconcept.com/flashobject/] cited below
///
///  FlashObject v1.2.3: Flash detection and embed - http://blog.deconcept.com/flashobject/
///  FlashObject is (c) 2005 Geoff Stearns and is released under the MIT License:
///  http://www.opensource.org/licenses/mit-license.php
/// </summary>

function DetectFlashPlayer (RequiredVersionMajor)
{
	try
	{
		var DetectedVersionMajor;
		if ((navigator.mimeTypes) && (navigator.mimeTypes["application\/x-shockwave-flash"]))
		{
			if (navigator.mimeTypes["application\/x-shockwave-flash"].enabledPlugin)
			{
				DetectedVersionMajor = ParseInteger(navigator.plugins["Shockwave Flash"].description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".")[0]);
			}
		}
		else if (window.ActiveXObject)
		{
			var FlashPlayer = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			DetectedVersionMajor = ParseInteger(FlashPlayer.GetVariable("$version").split(" ")[1].split(",")[0]);
		}
		return((DetectedVersionMajor > RequiredVersionMajor));
	}
	catch (ExceptionObject)
	{
	}
	return(false);
}

function PublishFlashContent (VersionMajor, Id, Width, Height, Movie, ScriptAccess, Quality, BackgroundColor, ShowMenu, WindowMode, Scale, FlashVariables, HTMLAlternativeTagId)
{
	var FlashContentHTML = "";
	try
	{
		SetGlobalBrowserVariables();
		if (DetectFlashPlayer(VersionMajor))
		{
			FlashContentHTML += "\<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http:\/\/fpdownload.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=" + VersionMajor + ",0,0,0\" id=\"" + Id + "\" width=\"" + Width + "\" height=\"" + Height + "\"\>\n";
			FlashContentHTML += " \<param name=\"movie\" value=\"" + Movie + "\" \/\>\n";
			FlashContentHTML += " \<param name=\"allowScriptAccess\" value=\"" + ScriptAccess + "\" \/\>\n";
			FlashContentHTML += " \<param name=\"quality\" value=\"" + Quality + "\" \/\>\n";
			FlashContentHTML += " \<param name=\"bgcolor\" value=\"" + BackgroundColor + "\" \/\>\n";
			FlashContentHTML += " \<param name=\"menu\" value=\"" + ShowMenu + "\" \/\>\n";
			FlashContentHTML += " \<param name=\"wmode\" value=\"" + WindowMode + "\" \/\>\n";
			FlashContentHTML += " \<param name=\"scale\" value=\"" + Scale + "\" \/\>\n";
			FlashContentHTML += " \<param name=\"flashvars\" value=\"" + FlashVariables + "\" \/\>\n";
			FlashContentHTML += " \<embed type=\"application\/x-shockwave-flash\" pluginspage=\"http:\/\/www.macromedia.com\/go\/getflashplayer\" id=\"" + Id + "\" name=\"" + Id + "\" width=\"" + Width + "\" height=\"" + Height + "\" src=\"" + Movie + "\" allowScriptAccess=\"" + ScriptAccess + "\" swLiveConnect=\"true\" quality=\"" + Quality + "\" bgcolor=\"" + BackgroundColor + "\" menu=\"" + ShowMenu + "\" wmode=\"" + WindowMode + "\" scale=\"" + Scale + "\" flashvars=\"" + FlashVariables + "\" \/\>\n";
			FlashContentHTML += "\<\/object\>\n";
			if (typeof(HTMLAlternativeTagId) != "undefined")
			{
				if ((HTMLAlternativeTagId != null) && (HTMLAlternativeTagId != ""))
				{
					var HTMLAlternativeTag = GetElement(HTMLAlternativeTagId);
					if (HTMLAlternativeTag != null)
					{
						HTMLAlternativeTag.innerHTML = FlashContentHTML;
					}
					else
					{
						document.write(FlashContentHTML);
					}
				}
				else
				{
					document.write(FlashContentHTML);
				}
			}
			else
			{
				document.write(FlashContentHTML);
			}
		}
	}
	catch (ExceptionObject)
	{
	}
}

/// <summary>
///  These functions handle events generated by an Input Text box
/// </summary>

function InputTextOnFocusHandler (InputTag, DefaultText)
{
	try
	{
		if (InputTag.value == DefaultText)
		{
			InputTag.value = "";
		}
	}
	catch (ExceptionObject)
	{
	}
}

function InputTextOnBlurHandler (InputTag, DefaultText)
{
	try
	{
		if (InputTag.value == "")
		{
			InputTag.value = DefaultText;
		}
	}
	catch (ExceptionObject)
	{
	}
}

/// <summary>
///  This function redirects on an event generated by a Select box
/// </summary>

function SelectOnChangeRedirect (SelectTag)
{
	try
	{
		if (SelectTag.value != "")
		{
			window.location.href = SelectTag.value;
		}
	}
	catch (ExceptionObject)
	{
	}
}

/// <summary>
///  This function opens a centered popup
/// </summary>

function Popup (URL, Width, Height, Scrollable, Resizable)
{
	try
	{
		var Popup=null;
		Popup = window.open(URL, "Popup", "width = " + Width + ", height = " + Height + ", top = " + ((screen.height - Height) / 2) + ", left = " + ((screen.width - Width) / 2) + ", resizable = " + (Resizable ? "yes" : "no") + ", scrollbars = " + (Scrollable ? "yes" : "no") + ", status = no");	
		Popup.onload = function(){self.focus()};
	}
	catch (ExceptionObject)
	{
		alert("Your browser or a piece of software installed on your\ncomputer appears to be blocking popups on this page.\n\nPlease enable popups and refresh this page to continue.");
	}
}

function Popup2(URL, Width, Height, Scrollable, Resizable)
{
	top.Popup=window.open('', "Popup", "width = " + Width + ", height = " + Height + ", top = " + ((screen.height - Height) / 2) + ", left = " + ((screen.width - Width) / 2) + ", resizable = " + (Resizable ? "yes" : "no") + ", scrollbars = " + (Scrollable ? "yes" : "no") + ", status = no");
	top.Popup.document.open("text/html","replace");
	top.Popup.document.writeln(
	 '<html><head><title>Popup 1.0</title></head>'
	+'<body onLoad="self.focus()" style="margin:0;padding:0;">'
	+'<iframe src="'+URL+'" width="100%" height="100%"></iframe>'
	+'</body></html>'
	);
	top.Popup.document.close();
	return false;
}

function PopupImage(URL, Width, Height, Scrollable, Resizable)
{
	top.Popup=window.open('', "Popup", "width = " + Width + ", height = " + Height + ", top = " + ((screen.height - Height) / 2) + ", left = " + ((screen.width - Width) / 2) + ", resizable = " + (Resizable ? "yes" : "no") + ", scrollbars = " + (Scrollable ? "yes" : "no") + ", status = no");
	top.Popup.document.open("text/html","replace");
	top.Popup.document.writeln(
	 '<html><head><title>Popup 1.0</title></head>'
	+'<body onLoad="self.focus()" style="margin:0;padding:0;">'
	+'<img src="'+URL+'" alt=""></img>'
	+'</body></html>'
	);
	top.Popup.document.close();
	return false;
}

/// <summary>
///  These functions enable drop-down menus
///  Significant portions of this code are based on Koivisto, J. (2004), "KOIVI Nearly Pure CSS Drop-down Menus", KOIVI [http://koivi.com/css-menus/] cited below
///
///  KOIVI Nearly Pure CSS Drop-down Menus (C) 2004 Justin Koivisto
///  Version 3.0
///  Last Modified: 4/27/2005
///  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
///  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
///  You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
///  For more details on the GNU Lesser General Public License, see http://www.gnu.org/copyleft/lesser.html
/// </summary>

function ShowMenu (MenuNodeTag)
{
	try
	{
		if (InternetExplorer)
		{
			if (MenuNodeTag.MenuChildNodeGroupTag)
			{
				MenuNodeTag.MenuChildNodeGroupTag.style.display = "block";
			}
		}
	}
	catch (ExceptionObject)
	{
	}
}

function HideMenu (MenuNodeTag)
{
	try
	{
		if (InternetExplorer)
		{
			if (MenuNodeTag.MenuChildNodeGroupTag)
			{
				MenuNodeTag.MenuChildNodeGroupTag.style.display = "none";
			}
		}
	}
	catch (ExceptionObject)
	{
	}
}

function InitializeMenu (MenuRootNodeGroupTagId)
{
	try
	{
		SetGlobalBrowserVariables();
		if (document.getElementById(MenuRootNodeGroupTagId))
		{
			var MenuRootNodeGroupTag = document.getElementById(MenuRootNodeGroupTagId);
			var MenuNodeTag = MenuRootNodeGroupTag.getElementsByTagName("LI");
			for (var i = 0; i < MenuNodeTag.length; i++)
			{
				var MenuChildNodeGroupTag = MenuNodeTag[i].getElementsByTagName("UL");
				if (MenuChildNodeGroupTag.length > 0)
				{
					MenuNodeTag[i].MenuChildNodeGroupTag = MenuChildNodeGroupTag[0];
				}
				MenuNodeTag[i].onmouseover = new Function("ShowMenu(this);");
				MenuNodeTag[i].onmouseout = new Function("HideMenu(this);");
			}
		}
	}
	catch (ExceptionObject)
	{
	}
}

/// <summary>
///  These function parses the DOM and assigns CSS selectors for IE
/// </summary>

function AssignClassNameSuffix (Tag, ClassNameSuffix)
{
	try
	{
		if (typeof(Tag.className) == "undefined")
		{
			Tag.className = " " + ClassNameSuffix;
		}
		else
		{
			Tag.className = Tag.className + " " + ClassNameSuffix;
		}
	}
	catch (ExceptionObject)
	{
	}
}

function AssignCSSSelectors ()
{
	try
	{
		SetGlobalBrowserVariables();
		if (InternetExplorer)
		{
			var ListTag = document.getElementsByTagName("UL");
			var ListFirstChildTag = null;
			var ListLastChildTag = null;
			var ListItemTag = null;
			for (var i = 0; i < ListTag.length; i++)
			{
				ListFirstChildTag = null;
				ListLastChildTag = null;
				if (ListTag[i].hasChildNodes)
				{
					ListItemTag = ListTag[i].childNodes;
					for (var j = 0; j < ListItemTag.length; j++)
					{
						if (ListItemTag[j].tagName.toLowerCase() == "li")
						{
							if (ListFirstChildTag == null)
							{
								ListFirstChildTag = ListItemTag[j];
							}
							ListLastChildTag = ListItemTag[j];
						}
					}
				}
				if (ListFirstChildTag != null)
				{
					AssignClassNameSuffix(ListFirstChildTag, "FirstChild");
					if (ListFirstChildTag != ListLastChildTag)
					{
						AssignClassNameSuffix(ListLastChildTag, "LastChild");
					}
				}
			}
		}
	assignIsNode("Navigation1"); //Remove this when not in use
	}
	catch (ExceptionObject)
	{
	}
}


/// <summary>
///  This function parses the DOM and assigns CSS selectors ['sfhover'] for LI tags on non-standard browsers.
///  Adapted from the orginal suckerfish javascript code from www.htmldog.com
/// </summary>

function sfHover(IdToHover)
{
	try
	{
		if(InternetExplorer)
		{
			for (var j=0; j<IdToHover.length; j++)
			{
				var sfEls = document.getElementById(IdToHover[j]).getElementsByTagName("LI");
				for (var i=0; i<sfEls.length; i++) {
					sfEls[i].onmouseover=function() {
						this.className+=" sfhover";
					}
					sfEls[i].onmouseout=function() {
						this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
					}
				}
			}
		}
	}
	catch (ExceptionObject)
	{
	}
}

function assignIsNode(IdToAssign)
{
	var rootNode = document.getElementById(IdToAssign).getElementsByTagName("LI");
	for(var i=0;i<rootNode.length;i++)
	{
		if(rootNode[i].getElementsByTagName("UL").length>0)
		{
			rootNode[i].className += rootNode[i].className.indexOf("IsNode")<0 ? " IsNode" :"";
		}
	}
}

///<summary>
///This function will parse through the document and collect all elements
///with a specified class name. As adapted from www.snook.ca
///</summary>

function getElementsByClassName(node, classname)
{
	try
	{
		var a = [];
		var re = new RegExp('\\b' + classname + '\\b');
		var els = node.getElementsByTagName("*");
		for(var i=0,j=els.length; i<j; i++)
		if(re.test(els[i].className))a.push(els[i]);
		return a;
	}
	catch (ExceptionObject)
	{
	}
}

///<summary>
///This function will parse through Navigation1 node and add an image (bullet)
///dynamically to dropdown menu LIs, a work around for IE bug on hover flickering
///</summary>

function cssHoverImage(nodeId,imgSrc)
{
	try
	{
		if(document.all && document.getElementById)
		{
			var imgArrow = new Image();
			imgArrow.src = imgSrc;
			var navRoot = document.getElementById(nodeId);
			var arrULs = navRoot.getElementsByTagName("UL");
			var arrLIs = null;
			var anchor = null;
			for(var i=0;i<arrULs.length;i++)
			{
				arrLIs = arrULs[i].getElementsByTagName("LI");
				for(var j=0;j<arrLIs.length;j++)
				{
					anchor = arrLIs[j].getElementsByTagName("A");
					var temp01 = anchor[0].innerHTML;
					anchor[0].innerHTML="<img style='position:absolute;left:15px;top:8px;margin:0;padding:0;display:block;border:0;width:5px;height:5px;' src='"+ imgArrow.src +"' alt='' />" + temp01;
				}
			}
		}
	}
	catch (ExceptionObject)
	{
	}
}

///<summary>
///This function will pop up dubal global map
///with parameters passed into it
///</summary>
function displayMap(map)
{
	var mapId = map;
	if(mapId!="")
	{
		Popup('Map.aspx?id='+mapId+'',650,430,0,0);
	}
}

function displayMapInner(map)
{
	var mapId = map;
	if(mapId!="")
	{
		Popup('../Map.aspx?id='+mapId+'',650,430,0,0);
	}
}

/// <summary>
///  Functions used to Assign W3C Compatible Links
///  Portions of this code are based on Kokoska, T. (2003), "Proper way to append to a links onclick handler", thelist [http://lists.evolt.org/archive/Week-of-Mon-20031124/151971.html]
/// </summary>
function AppendOnClickFunction (AnchorTag, Commands)
{
	try
	{
		if (typeof(AnchorTag.onclick) == "function")
		{
			AnchorTag.OnClickFunction = AnchorTag.onclick;
			AnchorTag.onclick = new Function("event", ("this.OnClickFunction();" + Commands));
		}
		else
		{
			AnchorTag.onclick = new Function(Commands);
		}
	}
catch (ExceptionObject)
	{
	}
}

//New Added by Muhammad.M.Baqir for opening the PDF doc in new window
function AssignLinks ()
{
	try
	{
		var LinkTag = document.getElementsByTagName("A");
		
		for (var i = 0; i < LinkTag.length; i++)
		{
			//if (LinkTag[i].href.indexOf("#") == (LinkTag[i].href.length - 1))
			//{
			//	AppendOnClickFunction(LinkTag[i], "return(false);");
			//}
			//else 
			if ((typeof(LinkTag[i].rel) != "undefined") && (LinkTag[i].rel.toLowerCase() == "external"))
			{
				AppendOnClickFunction(LinkTag[i], "Popup2(this.href,825,600,0,1); return false;");
			}
		}
	}
	catch (ExceptionObject)
	{
	}
}

