
function OpenTargetBlank(strUrl, strWinName)
{
	window.open(strUrl, strWinName);
	return false;
}

// OpenWin('page-edit-library.html','w2', 380, Math.ceil(screen.height - 76), 1, 1, parseInt(screen.width - (380 + 12)), 0);
function OpenWin(theURL, winName, wWidth, wHeight, withScrollbars, withResizeable, horzPos, vertPos, boolSetCookie)
{
	winHandle = '';
	vAdjustment = -50;
	if (horzPos == "" && vertPos == "")
	{
		if (screen)
		{
			horzPos = Math.ceil((screen.width - wWidth)/2);
			vertPos = Math.ceil((screen.height - wHeight)/2) + vAdjustment;
		}
		else
		{
			horzPos = 0;
			vertPos = 0;
		}
	}
	winChild = window.open(theURL, winName,'toolbar=no,location=no,scrollbars='+withScrollbars+',resizable='+withResizeable+',width='+wWidth+',height='+wHeight+', left='+horzPos+', top='+vertPos+'');
	setTimeout("winChild.focus()", 500);
	if (boolSetCookie) SetCookie("childWinUrl", theURL, 24);
	return false;
}

//
// 1, Used for manage the "on" state on menus
// 2. You can set the variable "strOverrideUrl" in the master_template.html through PHP
// ...or allow it to locate the url itself
// 3. Remember to set class="" on the anchor tags so that it's available to be reset
//
function ManageCss(strObName, strNewClassName, strOverrideUrl, obClassTranslate)
{
	var blnParseEntireStyle = true;
	if (navigator.userAgent.indexOf("Firefox") != -1) blnParseEntireStyle = false;
	else if (navigator.userAgent.indexOf("Opera") != -1) blnParseEntireStyle = false;

	var objMenu = document.getElementById(strObName);
	if(objMenu != null)
	{
		var strCurrUri = window.location.pathname.toLowerCase().replace("/", "");

		// Add the search string for this project
		strCurrUri += location.search

		// Check for parent menu to override
		// ...set in head of master_template.html
		if (strOverrideUrl != "" && strOverrideUrl != undefined && strOverrideUrl != null)
		{
			if (strOverrideUrl != strCurrUri) strCurrUri = strOverrideUrl;
		}

		// Special case for index page
		if (strCurrUri == "") strCurrUri = "index.html";

		var arrA = objMenu.getElementsByTagName("a");
		var strAnchorHref = null;
		for(var i=0; i< arrA.length;i++)
		{
			strAnchorHref = arrA[i]["href"].toLowerCase().replace("//", "").replace("/", "").replace(location.hostname, "").replace(location.protocol, "");
			strAnchorHref = strAnchorHref.replace(":10080", "").replace(location.hash, ""); // .replace(location.search, "");
			// strAnchorHref = strAnchorHref.replace("#", "");

			// alert(strCurrUri+":"+strAnchorHref);
			if (strCurrUri.indexOf(strAnchorHref) != -1) // Opera returns 0 instead of -1
			{
				// THIS IS IF A CLASS IS ALREADY SET FOR A DROPDOWN MENU
				// ... SUCH AS AN DOWN ARROW OR RIGHT ARROW
				// THERE WILL BE A SPECIAL CASE
				if (obClassTranslate != undefined)
				{
					for (var key in obClassTranslate)
					{
						if (arrA[i]["className"] == key)
						{
							strNewClassName = obClassTranslate[key];
							break;
						}
						else if (arrA[i]["class"] == key)
						{
							strNewClassName = obClassTranslate[key];
							break;
						}
					}
				}

				arrA[i]["className"] = strNewClassName; // For IE
				arrA[i]["class"] = strNewClassName; // For non-IE
				arrA[i].setAttribute("class", strNewClassName);
				// alert(document.styleSheets[2].rules.item(3).style.getAttribute('color'));
				// alert(arrA[i]["className"]["border"]);
				// arrA[i].href = "javascript:void(0);";
				// alert(strNewClassName);
				// alert(blnParseEntireStyle);

				objStyle = GetCssObjectByRuleName(strNewClassName);

				// This works fine in IE and Safari but not FireFox
				if (blnParseEntireStyle)
				{
					var str = "CSS RULES:\n";
					if (objStyle)
					{
						var str = "";
						for (key in objStyle)
						{
							str +=key+":"+objStyle[key]+";"; // For testing
							if (objStyle[key])
								arrA[i]["style"][key] = objStyle[key];
						}

					}
					// alert(str); // For testing
				}

				else
				{
					try
					{
						arrA[i]["style"]["color"] = objStyle["color"];
						arrA[i]["style"]["fontWeight"] = objStyle["fontWeight"];
						arrA[i]["style"]["background"] = objStyle["background"];
						arrA[i]["style"]["border"] = objStyle["border"];
						arrA[i]["style"]["borderTop"] = objStyle["borderTop"];
						arrA[i]["style"]["borderRight"] = objStyle["borderRight"];
						arrA[i]["style"]["borderBottom"] = objStyle["borderBottom"];
						arrA[i]["style"]["borderLeft"] = objStyle["borderLeft"];
						arrA[i]["style"]["backgroundColor"] = objStyle["backgroundColor"];
					}
					catch(err)
					{
						// alert(err.description);
					}
				}
			}
		}
	}
}

//
// Looks through all style sheet for a particular rule name
//
function GetCssObjectByRuleName(strCssRuleName)
{
	var cssRules;
	var objStyle;

	if (document.all) cssRules = "rules";
	else if (document.getElementById) cssRules = "cssRules";

	// alert(document.styleSheets.length);
	for (var i = 0; i < document.styleSheets.length; i++)
	{
		try
		{
			for (var j = 0; j < document.styleSheets[i][cssRules].length; j++)
			{
				try
				{
					if (document.styleSheets[i][cssRules][j].selectorText.replace(".", "") == strCssRuleName)
					{
						var objStyle = document.styleSheets[i][cssRules][j].style;
					}
				}
				catch(err) { }
			}
		}
		catch(err) { }
	}

	return objStyle;
}

function ConfirmVerifyDelete(strInfo, strPleaseConfirmText, strOkToDelete)
{
	var strUsr = strPleaseConfirmText;
	strUsr += "\n\n";
	strUsr += strOkToDelete;
	strUsr += ": ";
	strUsr += "\n\n";
	strUsr += strInfo
	return confirm(strUsr);
}

// var objWidth = new Object();
// objWidth["stringValue"] = "mystring";

//
// Creates an editable row
// Implementation:
// Ensure the table is nested inside a form tag and
// ...each td tag has a width setting
// The edit field must have an id of 'updateurl'
// The delete field must have an id of 'deleteurl'
// arg 1: The name/id of the form
// arg 2: The name/id of the database id
// arg 3: The id value of this particularly row
// arg 4: csv list of fields needing text area
// arg 5: the number of rows needed for the text field
//
var blnEdit = false;
function EditRow(strIdFieldName, intIdValue, csvTextAreaList, intTextAreaRows, strRequiredQueryStringItem)
{
	if (blnEdit)
	{
		alert(_TXT1); // Another row already being edited
		return false;
	}
	else
	{
		blnEdit = true;
	}

	// Create array of the fields needing text areas, otherwise defauts to normal text field
	arrTextAreaList = csvTextAreaList.split(",");

	// Get the row
	var objRow = document.getElementById(intIdValue);
	var rowId = null;

	// Get cells from the row
	if (objRow)
	{
		var objCell = objRow.getElementsByTagName("td");
		var strOutput = "";

		for(var i = 0; i < objCell.length; i++)
		{
			var arrTmp = objCell[i]["id"].split("-");
			var strFieldName = arrTmp[0];

			// Sort out the columns
			if (strFieldName == null || strFieldName == "")
			{
				// If it finds a html comment - remove it
				// ...especially useful for adding hidden fields to enable row update
				objCell[i].innerHTML = objCell[i].innerHTML.replace(/<!--(.*)-->/gi, "$1");
				// alert(objCell[i].innerHTML);
				continue;
			}
			else if(strFieldName == strIdFieldName) // The hidden non-editable field with the row id
			{
				objCell[i].innerHTML = objCell[i].innerHTML+' <input type="hidden" name="'+strFieldName+'" value="'+objCell[i].innerHTML+'" />';
			}
			else if(strFieldName == "deleteurl") // The delete cell, converted to a cancel button
			{
				objCell[i].innerHTML = '<a href="'+location.pathname+'?'+strRequiredQueryStringItem+'">'+_TXT2+'</a>'; // Cancel
				// objCell[i].innerHTML = '<a href="'+location.pathname+location.search+'">'+_TXT2+'</a>';
			}
			else if(strFieldName == "updateurl") // The edit cell, converted to save button
			{
				objCell[i].innerHTML = '<input type="submit" value="'+_TXT3+'" style="width:'+(objCell[i].width-6)+'px;margin:0;cursor:pointer" />'; // Save
			}
			else if (InArray(strFieldName, arrTextAreaList)) // an editable field. uses text area
			{
				if (intTextAreaRows == undefined) intTextAreaRows = 3;
				objCell[i].innerHTML = '<textarea name="'+strFieldName+'" rows="'+intTextAreaRows+'" style="width:'+(objCell[i].width-8)+'px;">'+objCell[i].innerHTML+'</textarea>';
			}
			else // an editable field
			{
				var objCellChild = objCell[i].getElementsByTagName("Select");
				if (objCellChild.length > 0) objCellChild[0].disabled = false; // Only concerned with first element
				else objCell[i].innerHTML = '<input type="text" name="'+strFieldName+'" value="'+objCell[i].innerHTML+'" style="width:'+(objCell[i].width-8)+'px;" />';
			}
		}

		// For debugging
		// alert(strOutput);
	}
	return false;
}

// Typical usage
// var messages = new makeArray(COMMA SEPARATED LIST AS ARGUMENTS HERE);
function CsvToArray()
{
	arrTmp = new Array();
	for (var i = 0; i < CsvToArray.arguments.length; i++)
		arrTmp[i] = CsvToArray.arguments[i];
	return arrTmp;
}

function InArray(strSource, arrTarget)
{
	if (strSource == "") return false;
	else if (arrTarget.length == 0) return false;

	for (var i = 0; i < arrTarget.length; i++)
	{
		if (arrTarget[i] == undefined) continue;
	  	else if (arrTarget[i] == strSource) return true;
	}
	return false;
}

function ShowHideObj(linkObj, objId, strShowText, strHideText)
{
	var objItem = document.getElementById(objId);

	if (objItem.style.display == "none")
	{
		objItem.style.display = "block";
		linkObj.innerHTML = strHideText;
	}
	else
	{
		objItem.style.display = "none";
		linkObj.innerHTML = strShowText;
	}

	return false;
}

function GoTo(strLocation)
{
	location.href = strLocation;
	return false;
}

function AddSlashes(str)
{
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}

function StripSlashes(str)
{
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

//
// Typical Usage
//
/*
var page = new PageQuery(location.search);
var myValue = page.getValue("a");
if (myValue == "-1") myValue = "history.html";
*/
function PageQuery(q)
{
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q)
	{
		for(var i=0; i < this.q.split("&").length; i++)
		{
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s)
	{
		for(var j=0; j < this.keyValuePairs.length; j++)
		{
			if(this.keyValuePairs[j].split("=")[0] == s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return -1;
	}
	this.getParameters = function()
	{
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++)
		{
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
     this.getLength = function() { return this.keyValuePairs.length; }
}

function ClosePanel()
{
	if (!objDiv) return;

	objDiv["style"]["overflow"] = "hidden";

	if (objDiv["style"]["height"] == "")
	{
		objDiv["style"]["height"] = objDiv["offsetHeight"]+"px";
		setTimeout("ClosePanel()", intRate);
	}
	else if (parseInt(objDiv["style"]["height"]) <= 0)
	{
		objDiv["style"]["display"] = "none";
		if (objLink) objLink["style"]["display"] = "block"; // Shows text link
		return;
	}
	else if (parseInt(objDiv["style"]["height"]) > 0)
	{
		var intNewHeight = parseInt(objDiv["style"]["height"]) - 1;

		if (intNewHeight == 0) objDiv["style"]["height"] = "0";
		else objDiv["style"]["height"] = intNewHeight+"px";

		if (intMargin > 0)
		{
			intMargin -= 1;
			objDiv["style"]["margin"] = intMargin+"px 10px "+intMargin+"px 10px";
			setTimeout("ClosePanel()", intRate);
		}

		else
		{
			/*
			var currTop = 0;
			var currRight = objDiv["offsetHeight"];
			var currBottom = intNewHeight;
			var currLeft = 0;
			objDiv["style"]["clip"] = "rect("+currTop+"px, "+currRight+"px, "+currBottom+"px, "+currLeft+"px)";
			*/
			if (intRate > 0)intRate -= (parseInt(intRate/2));
			setTimeout("ClosePanel()", intRate);
		}
	}
}

function ToggleDiv(objLink, strDivName, strSwitchText, strDivMargin)
{
	var objDiv = document.getElementById(strDivName);
	if (objDiv)
	{
		// Currently hidden - begin opening
		if (objDiv["style"]["display"] == "none")
		{
			if (navigator.userAgent.indexOf("MSIE") != -1) objDiv["style"]["display"] = "inline";
			else objDiv["style"]["display"] = "table";

			if (objHshLinkText[strDivName] == undefined) objHshLinkText[strDivName] = objLink["innerHTML"];
			objLink["innerHTML"] = strSwitchText;

			// If div has been hidden
			// if (intDivHeight != "undefined" && intDivHeight != 0) objDiv["style"]["height"] = intDivHeight+"px";

			// If div has been hidden
			objDiv["style"]["margin"] = strDivMargin;
		}

		// Currently open - begin hidding
		else
		{
			objDiv["style"]["display"] = "none";
			objLink["innerHTML"] = objHshLinkText[strDivName];
		}
	}
	return false;
}

//
// Converts a div into an editable div for IE or text area for others
// saving needs to be managed separately
// arg1: The id of the editable div
// arg2: The content to add to the div
// arg3: For non-IE the colour of text
//
function MakeEditable(strTargetDivName, strContent, strTextColour)
{
	// Integrity
	if (strTargetDivName == "")
	{
		alert("Javascript funtion 'MakeEditable' requires arg1");
		return;
	}

	if (strTextColour == "" || strTextColour == undefined) strTextColour = "#039";

	var objTargetDiv = document.getElementById(strTargetDivName);
	objTargetDiv["innerHTML"] = strContent;

	// This is IE
	if (navigator.userAgent.indexOf("MSIE") != -1)
	{
		objTargetDiv.setAttribute("contentEditable", true);
		document.execCommand("LiveResize", true, true);
		document.execCommand("2D-Position", true, true);
		document.execCommand("MultipleSelection", true, true);
		document.oncontextmenu = new Function("return false;");
	}

	// This is not IE
	else
	{
		ToggleEditMode(strTargetDivName);
	}
}

//
// This only works in IE
// arg1: The name of the object in question
// arg2: Optional text colour....defaults to #039
// arg3: Optional obj if text switching required
// arg3: Optional text to div
// arg4: Optional text to textarea
//
function ToggleEditMode(strTargetName, strTextColour, objLink, strLinkWysiwygText, strLinkCodeText)
{
	if (strTextColour == "" || strTextColour == undefined) strTextColour = "#039";

	// Get the object
	var objTarget = document.getElementById(strTargetName);

	if (objTarget["tagName"].toLowerCase() == "div")
	{
		// Link text
		if (objLink) objLink["innerHTML"] = strLinkWysiwygText;

		// Save original content
		var strSavedContent = objTarget["innerHTML"];

		// Get the parent
		var objParent = objTarget["parentNode"];

		// Capture style from div before replacement
		var strOriginalClassName = objTarget["className"];
		var intOriginalWidth = objTarget["offsetWidth"];
		var intOriginalHeight = objTarget["offsetHeight"];

		// Create new node
		var objTextArea = document.createElement("textarea");
		objTextArea["value"] = strSavedContent;

		// Set attibutes
		objTextArea.setAttribute("id", strTargetName);
		objTextArea.setAttribute("rows", "10");
		objTextArea.setAttribute("className", strOriginalClassName);

		// Add some textarea styles
		// changes to width are padding x2 and 1px border x2
		if (intOriginalHeight < 122) intOriginalHeight = 122;
		objTextArea["style"]["width"] = (intOriginalWidth-22)+"px";
		objTextArea["style"]["height"] = (intOriginalHeight-22)+"px";
		objTextArea["style"]["padding"] = "10px";
		objTextArea["style"]["color"] = strTextColour;
		objTextArea["style"]["fontFamily"] = "Lucida console";
		objTextArea["style"]["fontSize"] = "11px";

		// For non IE browsers
		if (navigator.userAgent.indexOf("MSIE") == -1)
		{
			objTextArea["style"]["marginLeft"] = "10px";
			objTextArea["style"]["width"] = (parseInt(objTextArea["style"]["width"]) - 2) + "px";
		}

		// Replace old for new
		objParent.replaceChild(objTextArea, objTarget);
	}

	else if (objTarget["tagName"].toLowerCase() == "textarea")
	{
		// Link text
		if (objLink) objLink["innerHTML"] = strLinkCodeText;

		// Not IE - this won't work
		if (navigator.userAgent.indexOf("MSIE") == -1)
		{
			alert("Please switch to IE to use WYSIWYG editor option");
			return false;
		}

		// Save original content
		var strSavedContent = objTarget["value"];

		// Get the parent
		var objParent = objTarget["parentNode"];

		// Capture style from div before replacement
		var strOriginalClassName = objTarget["className"];
		var intOriginalWidth = objTarget["offsetWidth"];
		var intOriginalHeight = objTarget["offsetHeight"];

		// Create new node
		var objNewDiv = document.createElement("div");
		objNewDiv["innerHTML"] = strSavedContent;

		// Set attibutes
		objNewDiv.setAttribute("contentEditable", true);
		objNewDiv.setAttribute("id", strTargetName);
		objNewDiv.setAttribute("className", strOriginalClassName);
		objNewDiv["style"]["height"] = intOriginalHeight+"px";

		// Replace old for new
		objParent.replaceChild(objNewDiv, objTarget);
	}
	return false;
}

//
// arg1: the obj pointer to the master checkbox
// arg2: the name of the form where all checkboxes are situated
//
function ToggleAll(objMasterCheckBox, strFormName)
{
	// Get the form obj
	var objFrm = document.getElementById(strFormName);
	var arrChk = document.getElementsByTagName("input");

	for(var i = 0; i < arrChk.length; i++)
	{
		if (arrChk[i]["type"] != "checkbox") continue;

		if (objMasterCheckBox["checked"])
		{
			arrChk[i]["checked"] = true;
		}
		else
		{
			arrChk[i]["checked"] = false;
		}
	}
	return true;
}

//
// DATE MANIPULATION
//
function DaysInFebruary(intYear)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((intYear % 4 == 0) && ( (!(intYear % 100 == 0)) || (intYear % 400 == 0))) ? 29 : 28 );
}

//
// arg1: a unique id
// arg2: URL to display
// arg3: popup width
// arg4: popup height
// arg5: topbar win title
//
function ShowPopup(strWinId, strUrl, intIfrWidth, intIfrHeight, strTopBarTitle, intLeftPos, intTopPos)
{
	// http://www.codeproject.com/KB/aspnet/JsOOP1.aspx
	var objPopup = new ClassPopup();

	// Basic properties
	var objPopupProperties = new Object;
	if (intLeftPos) objPopupProperties["intLeftPos"] = intLeftPos;
	if (intTopPos) objPopupProperties["intTopPos"] = intTopPos;
	objPopupProperties["strWinId"] = strWinId;
	objPopupProperties["strUrl"] = strUrl;
	objPopupProperties["intIfrWidth"] = intIfrWidth;
	objPopupProperties["intIfrHeight"] = intIfrHeight;
	objPopupProperties["strTopBarTitle"] = strTopBarTitle;
	objPopupProperties["intMasterDivOpacity"] = 75; // Overall percentage opacity of greyed out background
	objPopupProperties["hexMasterDivBgColour"] = "#456";
	objPopupProperties["strTopBarinnerHTML"] = '<img src="/local/common/images/winTopClose.gif" style="float:right;" alt="Close" /><div style="float:right;margin:5px 3px 0 0;cursor:pointer;color:#666;text-decoration: none;">CLOSE</div>';
	objPopupProperties["hexTopBarAnchorColor"] = "#fff";
	objPopup.SetProperties(objPopupProperties);

	// These are standard css styles
	// Names are appropriate for javascript
	var objTopBarStyle = new Object;
	objTopBarStyle["height"] = 26;
	objTopBarStyle["background"] = "#888 url('/local/common/images/winTopBg.jpg') repeat-x";
	objTopBarStyle["padding"] = "4px 0 0 7px";
	objTopBarStyle["margin"] = "0";
	objTopBarStyle["color"] = "#666";
	objTopBarStyle["fontWeight"] = "bold";
	objTopBarStyle["fontSize"] = "13px";
	objPopup.SetTopBarCss(objTopBarStyle);

	objPopup.BuildWindow();
	return false;
}

function ClassPopup()
{
	//
	// PRIVATE PROPERTIES only available from within the class
	// ...must have var prefix
	//
	var intCounter = 0;
	var _zIndex = 100;
	var objCentreDiv = null;
	var _hshTopBarCss = new Object;
	var _hshProperties = new Object;

	// Public setter arg needs to be a hash
	this["SetProperties"] = _SetProperties;
	this["SetTopBarCss"] = _SetTopBarCss;
	this["BuildWindow"] = _BuildWindow;
	this["_CreateElement"]  = _CreateElement;
	this["_GetWindowHeight"] = _GetWindowHeight;
	this["_GetWindowWidth"] = _GetWindowWidth;
	this["_intRightMarginWidth"] = 16;
	// this["_Tween"] = _Tween;

	// Constants
	this["intWinWidth"] = GetWindowWidth();
	this["intWinHeight"] = GetWindowHeight();
	var arrScrollXY = GetScrollXY();
	this["intWinScrollX"] = arrScrollXY[0];
	this["intWinScrollY"] = arrScrollXY[1];

	// INITIALISATION
	// - without this appears to causes a problem post
	// - ie8!
	this["_zIndex"] = _zIndex;

	function _BuildWindow()
	{
		// System check
		/*
		for (key in _hshProperties)
		{
			alert(_hshProperties[key]);
		}
		*/
		var strContainerDivId = _hshProperties["strWinId"]+"_contDiv";
		var strCentreDivId = _hshProperties["strWinId"]+"_centDiv";
		var strControlDivId = _hshProperties["strWinId"]+"_ctrDiv";
		var strContainerIfrId = _hshProperties["strWinId"]+"_contIfr";

		// These are used mainly for closing the window
		var objMasterDiv = document.getElementById(strContainerDivId); // test whether it has already been created
		var objCenterDiv = document.getElementById(strCentreDivId); // test whether it has already been created
		var objContainerIfrId = document.getElementById(strContainerIfrId);

		// Doesn't already exist
		if (objMasterDiv == null)
		{
			// Create reference to common "body" across doctypes
			var standardbody = (document.compatMode=="CSS1Compat")?document.documentElement:document.body;
			// standardbody["style"]["overflow"] = "hidden";

			if (navigator.userAgent.indexOf("IE") != -1)
			{
				standardbody["style"]["overflow"] = "hidden";
			}

			else
			{
				standardbody["style"]["overflowY"] = "hidden";
			}

			// Hide the scroll bar
			var intBodyMarginRight = (standardbody["style"]["marginRight"] != "")?parseInt(standardbody["style"]["marginRight"]):0;
			standardbody["style"]["marginRight"] = intBodyMarginRight+this["_intRightMarginWidth"]+"px";

			// Create master div container
			var objMasterDiv = this._CreateElement
			(
				"div",
				strContainerDivId,
				this["intWinScrollX"],
				this["intWinScrollY"],
				this["intWinWidth"],
				this["intWinHeight"],
				_hshProperties["hexMasterDivBgColour"],
				this["_zIndex"]++,
				_hshProperties["intMasterDivOpacity"]
			);
			document.body.appendChild(objMasterDiv);

			// Create central div
			// All other objects are created inside this div
			var intVerticalAdjustment = 30;

			if (_hshProperties["intLeftPos"]) var intLeftPos = parseInt(_hshProperties["intLeftPos"])+"px";
			else
			{
				var intLeftPos = parseInt((this["intWinWidth"]/2) - (_hshProperties["intIfrWidth"]/2))+this["intWinScrollX"]+"px";
			}

			if (_hshProperties["intTopPos"]) var intTopPos = parseInt(_hshProperties["intTopPos"])+"px";
			else
			{
				var intTopPos = parseInt((this["intWinHeight"]/2) - (_hshProperties["intIfrHeight"]/2)
						- (_hshTopBarCss["height"]*2)+_hshTopBarCss["height"]+intVerticalAdjustment)+this["intWinScrollY"]+"px";
			}

			objCentreDiv = this._CreateElement
			(
				"div",
				strCentreDivId,
				intLeftPos,
				intTopPos,
				10, // _hshProperties["intIfrWidth"],
				10, // _hshProperties["intIfrHeight"],
				"#333", // _hshProperties["hexMasterDivBgColour"],
				this["_zIndex"]++,
				100
			);
			objCentreDiv["style"]["overflow"] = "hidden";
			document.body.appendChild(objCentreDiv);

			// Create top control area
			var objCtrDiv = this._CreateElement
			(
				"div",
				strControlDivId,
				0,
				0,
				_hshProperties["intIfrWidth"],
				_hshTopBarCss["height"],
				_hshTopBarCss["background"],
				this["_zIndex"]++,
				100
			);
			objCentreDiv.appendChild(objCtrDiv);

			// Create close link
			var objLink = document.createElement("a");
			objLink.setAttribute("href", "javascript:void(0);");
			var strWinId = _hshProperties["strWinId"];
			if (navigator.userAgent.indexOf("MSIE") != -1) objLink.onclick = function() {ShowPopup(strWinId)};
			else objLink.setAttribute("onclick", "return ShowPopup('"+strWinId+"');"); // For other browsers
			objLink["innerHTML"] = _hshProperties["strTopBarinnerHTML"];
			objLink["style"]["color"] = _hshProperties["hexTopBarAnchorColor"];
			objCtrDiv.appendChild(objLink);

			// Create box title
			if (_hshProperties["strTopBarTitle"] != undefined)
			{
				var objDiv = document.createElement("div");
				// objDiv["style"]["width"] = parseInt(_hshProperties["intIfrWidth"]/2)+"px";
				objDiv["style"]["height"] = _hshTopBarCss["height"]+"px";
				objDiv["style"]["textAlign"] = "left";
				objDiv["style"]["margin"] = _hshTopBarCss["margin"];
				objDiv["style"]["padding"] = _hshTopBarCss["padding"];
				objDiv["style"]["color"] = _hshTopBarCss["color"];
				objDiv["style"]["fontWeight"] = _hshTopBarCss["fontWeight"];
				objDiv["style"]["fontSize"] = _hshTopBarCss["fontSize"];

				objDiv["innerHTML"] = _hshProperties["strTopBarTitle"];
				objCtrDiv.appendChild(objDiv);
			}

			var objNewIfr = this._CreateElement
			(
				"iframe",
				strContainerIfrId,
				0,
				_hshTopBarCss["height"],
				_hshProperties["intIfrWidth"],
				_hshProperties["intIfrHeight"],
				"#fff",
				this["_zIndex"]++,
				100
			);
			objNewIfr.setAttribute("name", strContainerIfrId);
			objNewIfr.setAttribute("src", _hshProperties["strUrl"]);
			objNewIfr.setAttribute("scrolling", "auto");
			objNewIfr.setAttribute("frameborder", "0");
			objCentreDiv.appendChild(objNewIfr);

			_Tween();

			return false;
		}

		else // Switch display
		{
			// Get the body object
			// ... for IE6
			var standardbody = (document.compatMode=="CSS1Compat")?document.documentElement:document.body;

			// Reveal the scroll bar
			if (navigator.userAgent.indexOf("IE") != -1)
			{
				standardbody["style"]["overflow"] = "auto";
			}

			else
			{
				standardbody["style"]["overflowY"] = "scroll";
				// standardbody["style"]["overflowX"] = "scroll";
			}

			// Adjust right margin
			var intBodyMarginRight = (standardbody["style"]["marginRight"] != "")?parseInt(standardbody["style"]["marginRight"]):0;
			standardbody["style"]["marginRight"] = intBodyMarginRight - this["_intRightMarginWidth"]+"px";

			// Close and remove
			objContainerIfrId["src"] = ""; // Take out the iframe - causes problem with ie8
			document.body.removeChild(objCenterDiv);
			document.body.removeChild(objMasterDiv);

			return false;
		}
	}

	function _Tween()
	{
		if (objCentreDiv["offsetWidth"] < _hshProperties["intIfrWidth"])
		{
			// To avoid making width too great
			var intCurrWidth = 0;
			if ((objCentreDiv["offsetWidth"]+50) > _hshProperties["intIfrWidth"]) intCurrWidth = _hshProperties["intIfrWidth"];
			else intCurrWidth = parseInt(objCentreDiv["offsetWidth"]+50)

			// Make the width change
			objCentreDiv["style"]["width"] = intCurrWidth+"px";

			setTimeout(_Tween, 10);
		}

		else if (objCentreDiv["offsetHeight"] < parseInt(_hshTopBarCss["height"]+_hshProperties["intIfrHeight"]))
		{
			var intChange = 20;
			var intCurrHeight = 0;

			// Ease out tween
			var intCurrDiff = _hshProperties["intIfrHeight"] - (objCentreDiv["offsetHeight"]+intChange);
			if (intCurrDiff < 100 && intCounter < intChange)
			{
				intChange = intChange - intCounter;
				intCounter++;
			}

			// To avoid making height too great
			if ((objCentreDiv["offsetHeight"]+intChange) > _hshProperties["intIfrHeight"]) intCurrHeight = _hshProperties["intIfrHeight"];
			else intCurrHeight = parseInt(objCentreDiv["offsetHeight"]+intChange)

			// Make the height change
			objCentreDiv["style"]["height"] = intCurrHeight+"px";
			setTimeout(_Tween, 10);
		}

		else // Fall through - a final correction
		{
			objCentreDiv["style"]["height"] = parseInt(_hshTopBarCss["height"]+_hshProperties["intIfrHeight"])+"px";
			objCentreDiv["style"]["width"] = _hshProperties["intIfrWidth"]+"px";
			intCounter = 0;
		}
	}

	function _SetProperties(hshProperties)
	{
		_hshProperties = hshProperties;
	}

	function _SetTopBarCss(hshTopBarCss)
	{
		_hshTopBarCss = hshTopBarCss;
	}

	function _CreateElement(strElementType, strId, intLeft, intTop, intWidth, intHeight, strBackground, intZindex, intBackgroundOpacity)
	{
		var objPointer = document.createElement(strElementType);
		objPointer.setAttribute("id", strId);

		// Set these for all
		// Both following lines may be reset if necessary using the returned object
		objPointer["style"]["position"] = "absolute";
		objPointer["style"]["display"] = "block";

		// Style elements
		if (intLeft > 0) objPointer["style"]["left"] = intLeft+"px";
		else objPointer["style"]["left"] = intLeft;

		if (intTop > 0) objPointer["style"]["top"] = intTop+"px";
		else objPointer["style"]["top"] = intTop;

		objPointer["style"]["width"] = intWidth+"px";
		objPointer["style"]["height"] = intHeight+"px";
		objPointer["style"]["background"] = strBackground;
		objPointer["style"]["zIndex"] = intZindex;

		if (intBackgroundOpacity != 100)
		{
			objPointer["style"]["filter"] = "alpha(opacity="+intBackgroundOpacity+") Shadow(Color=#00FF00, Direction=225)";
			objPointer["style"]["-moz-opacity"] = "."+intBackgroundOpacity;
			objPointer["style"]["opacity"] = "."+intBackgroundOpacity;
			objPointer["style"]["-khtml-opacity"] = "0."+intBackgroundOpacity;
		}
		return objPointer;
	}

	function _GetWindowHeight()
	{
		var intHeight = 0;
		if( typeof( window.innerWidth) == "number")
		{
			intHeight = window.innerHeight;
		}

		else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
		{
			intHeight = document.documentElement.clientHeight;
		}

		else if(document.body && (document.body.clientWidth || document.body.clientHeight))
		{
			intHeight = document.body.clientHeight;
		}
		return intHeight;
	}

	function _GetWindowWidth()
	{
		var intWidth = 0;
		if( typeof( window.innerWidth) == "number")
		{
			intWidth = window.innerWidth;
		}

		else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
		{
			intWidth = document.documentElement.clientWidth;
		}

		else if(document.body && (document.body.clientWidth || document.body.clientHeight))
		{
			intWidth = document.body.clientWidth;
		}
		return intWidth;
	}

	//
	// OmniWeb 4.2-, NetFront 3.3- and Clue browser do not provide any way to do this.
	// Safari and OmniWeb 4.5+ have bugs that do not affect this script+, which return -8 if the scrolling is 0,
	// but get all other scrolling offsets correct. However, as they correctly provide window.pageXOffset/pageYOffset,
	// this function will not have any problems.
	//
	function GetScrollXY()
	{
		var scrOfX = 0, scrOfY = 0;

		//Netscape compliant
		if( typeof( window.pageYOffset ) == 'number' )
		{
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		}

		//DOM compliant
		else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
		{
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		}

		//IE6 standards compliant mode
		else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
		{
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return [scrOfX, scrOfY];
	}

	return false;
}

function DropDownGoTo(strName, selObj, strQueryAdditions)
{
	var strDestination = location.pathname + "?"+strName+"="+selObj.options[selObj.selectedIndex].value + strQueryAdditions;
	location.href = strDestination.substr(1); // Remove forward slash
}
