
function ReverseWords(sInput) {
	var	sOuput = "",
		arrReversed = sInput.split(" ").reverse();
	for (i=0; i < arrReversed.length; i++)
		{
		sOuput = sOuput + arrReversed[i];
		if (i < arrReversed.length-1)
			{
			sOuput = sOuput + " ";
			}
		}
	return sOuput;
}

function GetIDFromName(sName) {
	var nID, n_index = sName.lastIndexOf("_")+1;
	nID = 0;
	if (n_index > 0)
		{
		nID = GetInt(sName.substring(n_index, sName.length));
		}
	return nID;
}


function TrimCommonWordEndings(sWord) {
	var sOutput = $.trim(sWord);
	sOutput = TrimWordEnding(sOutput, "ies");
	sOutput = TrimWordEnding(sOutput, "es");
	sOutput = TrimWordEnding(sOutput, "s");
	sOutput = TrimWordEnding(sOutput, "e");
	sOutput = TrimWordEnding(sOutput, "y");
	sOutput = TrimWordEnding(sOutput, "ing");
	sOutput = TrimWordEnding(sOutput, "er");
	return sOutput;
}

function TrimCommonWordEndingsArray(arrWords) {
	for (var nWord = 0; nWord < arrWords.length; nWord++)
		{ arrWords[nWord] = TrimCommonWordEndings(arrWords[nWord]); }
	return arrWords;
}

function ArrayToText(arrText) {
	var sOutput = "[ ";
	for (var nIndex = 0; nIndex < arrText.length; nIndex++)
		{ sOutput += arrText[nIndex] + " | "; }
	sOutput += "]";
	return sOutput;
}

function CountArrayMatches(arr1, arr2) {
	var nMatches = 0;
	for (var nIndex1 = 0; nIndex1 < arr1.length; nIndex1++)
		{
		for (var nIndex2 = 0; nIndex2 < arr2.length; nIndex2++)
			{
			if (arr1[nIndex1] == arr2[nIndex2])
				{ nMatches++; }
			}
		}
	return nMatches;
}



function CountArrayMatchesLength(arr1, arr2) {
	var nMatchesLength = 0;
	for (var nIndex1 = 0; nIndex1 < arr1.length; nIndex1++)
		{
		for (var nIndex2 = 0; nIndex2 < arr2.length; nIndex2++)
			{
			if (arr1[nIndex1] == arr2[nIndex2])
				{ nMatchesLength += arr1[nIndex1].length; }
			}
		}
	return nMatchesLength;
}

function GetArrayMatches(arr1, arr2) {
	var sMatchingChars = "";
	for (var nIndex1 = 0; nIndex1 < arr1.length; nIndex1++)
		{
		for (var nIndex2 = 0; nIndex2 < arr2.length; nIndex2++)
			{
			if (arr1[nIndex1] == arr2[nIndex2])
				{ sMatchingChars += arr1[nIndex1]; }
			}
		}
	return sMatchingChars;
}


function SubtractArray(arrToSubtractFrom, arrToSubtract) {
	for (nItemToCheck = 0; nItemToCheck < arrToSubtractFrom.length; nItemToCheck++)
		{
		for (nItemToRemove = 0; nItemToRemove < arrToSubtract.length; nItemToRemove++)
			{
			if 	(
				(arrToSubtractFrom[nItemToCheck] == arrToSubtract[nItemToRemove]) ||
				(arrToSubtractFrom[nItemToCheck] == "")
				)
				{
				arrToSubtractFrom.splice(nItemToCheck, 1);
				nItemToCheck--;
				}
			}
		}
}


function TrimWordEnding(sWord, sEnding) {
	var sOutput = $.trim(sWord);
	if (sOutput.substring(sOutput.length-sEnding.length,sOutput.length).toLowerCase() == sEnding.toLowerCase())
		{ sOutput = sOutput.substring(0,sOutput.length-sEnding.length); }
	return sOutput;
}

//|----------------------------------
//| Forms
//|----------------------------------
function Forms_UpdateDateInput(sInputName, oForm) {
	oHiddenDate	= eval('oForm.' + sInputName);
	oHiddenDateInt	= eval('oForm.' + sInputName + '_Int');
	oMonthSelect	= eval('oForm.' + sInputName + '_Month');
	oDaySelect	= eval('oForm.' + sInputName + '_Day');
	oYearSelect	= eval('oForm.' + sInputName + '_Year');
	oHiddenDate.value = oMonthSelect.value + '/' + oDaySelect.value + '/' + oYearSelect.value;
	oHiddenDateInt.value = (oYearSelect.value * 10000) + (oMonthSelect.value * 100) + (oDaySelect.value * 1);
}


//|----------------------------------
//| Chat
//|----------------------------------
var oChatTimer, bChatWaiting = false;

function ExpandChat() {
	if (bChatWaiting)
		{
		clearTimeout(oChatTimer);
		bChatWaiting = false;
		}
	$('#ChatHTMLBox').height(250);

	$('#ChatBox').css("width", "700px");


	$('#ChatFormBox').show();
	$('#ChatUsersPane').show();
	//$('#ChatToolbar').show();
	$('#ChatFormBox').show();

	$('#ChatExpandButton').hide();
	$('#ChatDeExpandButton').show();
}
function MaximizeChat() {
	if (bChatWaiting)
		{
		clearTimeout(oChatTimer);
		bChatWaiting = false;
		}
	$('#BottomDock').css("width", "100%")
					.css("height", "80%")
					.css("z-index", 9999999);

	$('#ChatBox').css("height", "100%")
				.css("width", "100%");
				
}

function PauseChat() {
	$('#ChatHTMLBox').attr("data-outputcontainer", "PausedChatOutput").removeClass("AutoScroll");
	$('#ChatPauseButton').hide();
	$('#ChatStartButton').show();
}

function StartChat() {
	$('#ChatHTMLBox').attr("data-outputcontainer", "").addClass("AutoScroll");
	$('#ChatPauseButton').show();
	$('#ChatStartButton').hide();
}

function DeExpandChat() {
	bChatWaiting = false;
	$('#ChatHTMLBox').height(0);
	$('#ChatFormBox').hide();
	//$('#ChatToolbar').hide();
	$('#ChatUsersPane').hide();
	$('#ChatFormBox').hide();

	$('#ChatDeExpandButton').hide();
	$('#ChatExpandButton').show();
}

function DeExpandChatSlow() {
	if (!bChatWaiting)
		{
		bChatWaiting = true;
		oChatTimer = setTimeout('DeExpandChat();', 1000);
		}
}

//|----------------------------------
//| Ads
//|----------------------------------
function GenerateAdBox(sTitle, sImgFile, sBody, nAdID) {
	var sAdBox =	"<DIV CLASS=\"AdBox\">";
	if (sTitle != "")
		{
		sAdBox += "<DIV CLASS=\"AdTitle\"><A HREF=\"Ads_ClickThrough.asp?AdID=" + nAdID + "\" TARGET=\"_blank\">" + sTitle + "</A></DIV>";
		}
	if (sImgFile != "")
		{
		sAdBox += "<DIV CLASS=\"AdImageBox\"><A HREF=\"Ads_ClickThrough.asp?AdID=" + nAdID + "\" TARGET=\"_blank\"><IMG CLASS=\"AdImage\" SRC=\"" + GetFullSizePath(sImgFile) + sImgFile + "\" /></A></DIV>";
		}
	if (sBody != "")
		{
		sAdBox += "<DIV CLASS=\"AdBody\"><A HREF=\"Ads_ClickThrough.asp?AdID=" + nAdID + "\" TARGET=\"_blank\">" + sBody + "</A></DIV>";
		}
	sAdBox += "</DIV>";

	return sAdBox;
}

function GenerateAdBox2(sTitle, sImgURL, sBody, nAdID) {
	var sAdBox =	"<DIV CLASS=\"AdBox\">";
	if (sTitle != "")
		{
		sAdBox += "<DIV CLASS=\"AdTitle\"><A HREF=\"Ads_ClickThrough.asp?AdID=" + nAdID + "\" TARGET=\"_blank\">" + sTitle + "</A></DIV>";
		}
	if (sImgURL != "")
		{
		sAdBox += "<DIV CLASS=\"AdImageBox\"><A HREF=\"Ads_ClickThrough.asp?AdID=" + nAdID + "\" TARGET=\"_blank\"><IMG CLASS=\"AdImage\" SRC=\"" + sImgURL + "\" /></A></DIV>";
		}
	if (sBody != "")
		{
		sAdBox += "<DIV CLASS=\"AdBody\"><A HREF=\"Ads_ClickThrough.asp?AdID=" + nAdID + "\" TARGET=\"_blank\">" + sBody + "</A></DIV>";
		}
	sAdBox += "</DIV>";

	return sAdBox;
}

//|----------------------------------
//| DHTML
//|----------------------------------
function SetupTextAreaLimit(oTextArea) {
	oTextArea.keyup(
		function(event)
			{
			nCharLimit = $(this).attr("title").split(" ")[1];
			if ($(this).val().length > nCharLimit)
				{ $(this).val($(this).val().substring(0,nCharLimit)); }
			sStatusBoxID = $(this).attr("data-StatusBoxID");
			if (sStatusBoxID)
				{
				if (sStatusBoxID.length > 0)
					{
					$("#" + sStatusBoxID).html( " (" + (nCharLimit - $(this).val().length) + "/" + nCharLimit + ")");
					}
				}
			}
		);
}

function HandleModalLink(oLink) {
	var sSourceURL = GetStr(oLink.attr("data-ModalSourceURL"));
	var sSkipURL = GetStr(oLink.attr("data-ModalSkipURL"));
	if (sSkipURL == "") { sSkipURL = GetStr(oLink.attr("HREF")); }
	if (sSourceURL == "") { return; }
	nWidth = GetInt(oLink.attr("data-ModalWidth"));
	if (nWidth <= 0) { nWidth = 600; }
	ModalPopup(sSourceURL, sSkipURL, nWidth);
}

function ChangeObjectVisibility(objectId, newVisibility) {
	var styleObject = GetStyleObject(objectId);
	if (styleObject) {
		styleObject.display = newVisibility;
		return true;
	} else {
		return false;
	}
}

function MaximizeElement(oElement) {
	oElement.css({left: '0', top: '0'});
	oElement.css("width",  $(document).width()  + "px");
	oElement.css("height", $(document).height() + "px");
}

function CenterAtTop(oElement) {
	CenterOnScreen(oElement);
	var nTopOfObject = parseInt(oElement.css("top").replace(/[^\.\-0-9]/g,""));
	var nTopOfViewport = $(window).scrollTop();
	if (nTopOfObject < (nTopOfViewport + 40))
		{ oElement.css("top", nTopOfViewport + 10); }
}

function CenterOnScreen(oElement) {
    oElement.css("position","absolute");
    oElement.css("top", ( $(window).height() - oElement.height() ) / 2+$(window).scrollTop() + "px");
    oElement.css("left", ( $(window).width() - oElement.width() ) / 2+$(window).scrollLeft() + "px");
}

function GetStyleObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	}
	else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
	}
	else if (document.layers && document.layers[objectId]) {
		return document.layers[objectId];
	} else {
		return false;
	}
}

function GetObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId);
	}
	else if (document.all && document.all(objectId)) {
		return document.all(objectId);
	}
	else if (document.layers && document.layers[objectId]) {
		return document.layers[objectId];
	} else {
		return false;
	}
}

function PopupObject(event,sObjectID) {
	{
	var iebody = (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
	var nDSOCLeft = document.all? iebody.scrollLeft : pageXOffset;
	var nDSOCTop = document.all? iebody.scrollTop : pageYOffset;
	var nEventX = (event.pageX)?event.pageX:window.event.x+nDSOCLeft;
	var nEventY = (event.pageY)?event.pageY:window.event.y+nDSOCTop;

	$("#" + sObjectID)
		.css("top",  nEventY + "px")
		.css("left", nEventX + "px")
		.show();
	}
	return false;
}

function MoveObjectTo(sObjectID,x,y) {
	var oObjectStyle = GetStyleObject(sObjectID);
	var oObject = GetObject(sObjectID);
	oObjectStyle.left = x + 'px';
	oObjectStyle.top = y + 'px';
}

function AjaxLoadingMessageWithSkipLink(sSkipToURL) {
	var sOutput = "<DIV CLASS=\"SectionBox\"><BR><BR><DIV CLASS=\"Centered\"><IMG SRC=\"Images/LoadingIcon.gif\" CLASS=\"Icon\"> " +
				"Loading, please wait...</DIV><BR><DIV CLASS=\"ButtonPanel Centered\">" +
				"<A HREF=\"javascript:void(0);\" onClick=\"HideAllPopups();\"><IMG SRC=\"Images/Icons/Silk/cross.png\" CLASS=\"Icon\"> Cancel</A>";
	if (sSkipToURL != "")
		{ sOutput = sOutput + "<A HREF=\"" + sSkipToURL + "\" ><IMG SRC=\"Images/Icons/Silk/arrow_right.png\" CLASS=\"Icon\"> Skip This Preview</A>"; }
	sOutput = sOutput + "</DIV><BR><BR></DIV>";
	return sOutput;
}

function AjaxLoadingMessage() {
	return "<IMG SRC=\"Images/LoadingIcon.gif\" CLASS=\"Icon\"> Loading...";
}

function AjaxSavingMessage() {
	return "<IMG SRC=\"Images/LoadingIcon.gif\" CLASS=\"Icon\"> Saving...";
}


function FixDisplayNameURL(sDisplayName) {
	var sOutput = FixFileName(sDisplayName).replace("_", "");
	return sOutput;
}

function ShowThumbNailPopup(event, sLinkURL, sThmFileURL, nThmWidth, nThmHeight) {
	bHidingThumbNailPopup = false;
	if (sPopupThmFileURL != sThmFileURL)
		{
		oThumbNailPopupDiv = GetObject("ThumbNailPopup");
		oThumbNailPopupDivStyle = GetStyleObject("ThumbNailPopup");
		oThumbNailPopupDivStyle.width = nThmWidth + "px";
		oThumbNailPopupDivStyle.height = nThmHeight + "px";
		oThumbNailPopupDiv.innerHTML = '<A HREF="' + sLinkURL + '" onMouseOver="bHidingThumbNailPopup = false;" onMouseOut="HideThumbNailPopup();"><IMG SRC="' + sThmFileURL + '" WIDTH="' + nThmWidth + '" HEIGHT="' + nThmHeight + '" ALIGN="CENTER" BORDER="2" HSPACE="0" VSPACE="0"></A>"';
		sPopupThmFileURL = sThmFileURL;
		PopupObject(event,"ThumbNailPopup");
		}
}



function HideAllPopups() {
	HideTopModalPopup();
	HideThumbNailPopup();
	$(".PopupMask").hide();
}

function HideThumbNailPopup() {
	bHidingThumbNailPopup = true;
	setTimeout("if (bHidingThumbNailPopup) { ChangeObjectVisibility('ThumbNailPopup', 'none'); bHidingThumbNailPopup = false; sPopupThmFileURL = ''; }",100);
}

//|----------------------------------
//| Form Handling
//|----------------------------------
function CheckTextArea(oTextArea, nMaxLength, sCharsLeftDiv) {
	if (oTextArea.value.length > nMaxLength)
		{
		oTextArea.value = oTextArea.value.substring(0,nMaxLength);
		alert('You have reached the maximum character limit.');
		}
	var CharsLeft = GetObject(sCharsLeftDiv);
	if (CharsLeft)
		{ CharsLeft.innerHTML = '(' + nMaxLength + ' characters maximum. ' + (nMaxLength-oTextArea.value.length) + ' characters left.'; }
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

//|----------------------------------
//| Location Handling
//|----------------------------------
function GetAnchor() {
	var	sAnchorName = "",
		nPoundPos   = window.location.href.lastIndexOf("#");
	if (nPoundPos > 10)
		{ sAnchorName = window.location.href.substring(nPoundPos+1, window.location.href.length); }
	return sAnchorName;
}

function SetAnchor(sAnchorName) {
	var sBaseURL = window.location.href;
	nPoundPos = sBaseURL.lastIndexOf("#");
	if (nPoundPos > 10)
		{ sBaseURL = sBaseURL.substring(0, nPoundPos); }
	window.location.href = sBaseURL + "#" + sAnchorName;
}

//|----------------------------------
//| Window Handling
//|----------------------------------
function WindowReload(returnVal) {
  window.document.reload();
}

function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight;

	return window.undefined;
}

function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth;
	if (document.body) return document.body.clientWidth;
}


function GetRandomInt(nMin, nMax) {
	return GetInt(((nMax+1-nMin) * Math.random()) + nMin);
}


function LaunchLink(sLink) {
	this.open(Unscramble(sLink), "Win" + Math.floor(Math.random()*10000), "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,status=yes");
}

function BrowseToLink(sLink) {
	var sUnscrambled = Unscramble(sLink);
	window.status = "~" + sUnscrambled;
	window.location.href = sUnscrambled;
	window.status = "-" + window.location;
}

//|----------------------------------
//| AJAX
//|----------------------------------
function ModalPopup(sSourceURL, sSkipURL, nWidth) {
	//| Hide all tooltips
	$(".qtip").hide();

	var	nMaskZIndex  = nTopPopupZIndex + 1,
		nPopupZIndex = nTopPopupZIndex + 2;

	nTopPopupZIndex = nPopupZIndex;
	nWidth = GetInt(nWidth)
	if (nWidth <= 0) { nWidth = "auto" }

	var oPopupMask = $("<div>")
					.appendTo("body")
					.attr("ID", "PopupMask_" + nMaskZIndex)
					.addClass("PopupMask")
					.css("z-index", nMaskZIndex)
					.click(function() { HideTopModalPopup(); });

	MaximizeElement(oPopupMask);
	oPopupMask.show();

	var oPopupContainer = $("<div>")
			.appendTo("body")
			.attr("ID", "PopupBox_" + nPopupZIndex)
			.addClass("PopupBox")
			.addClass("HiddenPopup")
			.css("z-index", nPopupZIndex)
			.show()
			.width(nWidth)
			.height("auto");

	CenterAtTop(oPopupContainer);
	oPopupContainer.html(AjaxLoadingMessageWithSkipLink(sSkipURL))
	CenterAtTop(oPopupContainer);

	$.get(sSourceURL, "",
		function(data, sStatus)
		{
		oPopupContainer.html(data);
		CenterAtTop(oPopupContainer);
		MaximizeElement(oPopupMask);
		} );
}

function HandleAjaxForm(oForm) {
	var oOutputBox, sFormData;
	sFormData = oForm.serialize()
	oOutputBox = $("#" + oForm.attr("data-ajaxoutput"));
	if (oOutputBox)
		{
		var	bValidated = true,
			sErrorIfEmpty = "";

		if (GetStr(oOutputBox.attr("data-NoLoadingMessage")) == "")
			{ oOutputBox.html(AjaxLoadingMessage()); }

		oForm.children("[data-ErrorIfEmpty]").each(
			function () {
				if ($(this).val() == "")
					{
					sErrorIfEmpty = GetStr(oForm.attr("data-ErrorIfEmpty"));
					if ((sErrorIfEmpty != "") && (sErrorIfEmpty != "silent"))
						{ alert(sErrorIfEmpty); }
					bValidated = false;
					}
			})
		if (bValidated)
			{
			if (oForm.attr("method").toUpperCase() == "POST")
				{

				$.post(oForm.attr("action"), sFormData,
					function(data, sStatus){
						if (GetStr(oForm.attr("data-AppendToTarget")) == "")
							{ oOutputBox.html(data); }
						else
							{ oOutputBox.append(data); }

						if (oOutputBox.hasClass("AutoScroll"))
							{ oOutputBox.scrollTop(oOutputBox.attr('scrollHeight')); }
						} );
				}
			else
				{
				$.get(oForm.attr("action"), sFormData,
					function(data, sStatus)
						{
						if (GetStr(oForm.attr("data-AppendToTarget")) == "")
							{ oOutputBox.html(data); }
						else
							{ oOutputBox.append(data); }
						if (oOutputBox.hasClass("AutoScroll"))
							{ oOutputBox.scrollTop(oOutputBox.attr('scrollHeight')); }
						} );
				}
			if (GetStr(oForm.attr("data-ResetOnSubmit")) != "")
				{ oForm[0].reset(); }
			}
		}
}


function showPopWin(sSourceURL, nWidth, height, sTitle, returnFunc, showCloseBox) {
	ModalPopup(sSourceURL, "", nWidth)
}

function HideTopModalPopup() {
	if (nTopPopupZIndex <= 1300) { return; }
	var nMaskZIndex  = nTopPopupZIndex - 1;
	$("#PopupBox_" + nTopPopupZIndex).remove();
	$("#PopupMask_" + nMaskZIndex).remove();
	nTopPopupZIndex = nTopPopupZIndex - 2;
}

function SetupTooltip(oTargetElement) {
	var	sPos_Target = GetStr(oTargetElement.attr("data-TT_Pos_Target")),
		sPos_Tooltip = GetStr(oTargetElement.attr("data-TT_Pos_Tooltip")),
		bShow_Ready = (GetStr(oTargetElement.attr("data-TT_Show_Ready")) != ""),
		sShow_Target = GetStr(oTargetElement.attr("data-TT_Show_Target")),
		sShow_EffectType = GetStr(oTargetElement.attr("data-TT_Show_EffectType")),
		nShow_EffectLength = GetInt(oTargetElement.attr("data-TT_Show_EffectLength")),
		nShow_Delay = GetInt(oTargetElement.attr("data-TT_Show_Delay")),
		nStyle_Width = GetInt(oTargetElement.attr("data-TT_Style_Width")),
		sStyle_Tip = GetStr(oTargetElement.attr("data-TT_Style_Tip")),
		sStyle_Name = GetStr(oTargetElement.attr("data-TT_Style_Name")),
		//| Required attributes
		sContent_Title = GetStr(oTargetElement.attr("data-TT_Content_Title")),
		sContent_URL = GetStr(oTargetElement.attr("data-TT_Content_URL")),
		oTarget = oTargetElement;

	if (sPos_Target == "") { sPos_Target = "bottomMiddle" }
	if (sPos_Tooltip == "") { sPos_Tooltip = "topMiddle" }
	if (sShow_EffectType == "") { sShow_EffectType = "fade" }
	if (sStyle_Tip == "") { sStyle_Tip = "topLeft" }
	if (sShow_Target != "") { oTarget = $(sShow_Target) }
	if (sStyle_Name == "") { sStyle_Name = "green" }
	if (!(nStyle_Width > 0)) { nStyle_Width = 500 }
	if (!(nShow_EffectLength > 0)) { nShow_EffectLength = 500 }
	if (!(nShow_Delay > 0)) { nShow_Delay = 500 }

	oTargetElement.qtip({
					content: {
						title: { text: sContent_Title, button: '<img src=images/icons/silk/cross.png>' },
						url: sContent_URL
						},
					position: { corner: { target: sPos_Target, tooltip: sPos_Tooltip } },

					show: {
						delay: nShow_Delay,
						ready : bShow_Ready,
						when: { target: oTarget },
						effect:	{
								type: sShow_EffectType,
								length : nShow_EffectLength
								}
						},

					hide: {
						when: '',
						fixed: true,
						effect: { length : 500 }
						},

					style: {
						padding: 20,
						tip: sStyle_Tip,
						width: nStyle_Width,
						name: sStyle_Name,
						border: { width: 2, radius: 5 }
						}
					});
}

function OutputLinkToContainer(oLinkElement)
	{
	var sConfirmMessage = GetStr(oLinkElement.attr("data-confirm")),
		sOutputContainer = GetStr(oLinkElement.attr("data-outputcontainer")),
		sGetURL = GetStr(oLinkElement.attr("data-ajaxgeturl")),
		sRemove = GetStr(oLinkElement.attr("data-removelink")),
		sGetParams = GetStr(oLinkElement.attr("data-ajaxgetparams"));

	if (sGetURL == "") { sGetURL = GetStr(oLinkElement.attr("HREF")) }
	if (sGetURL == "") { return false; }			//| Quit if No URL
	if (sOutputContainer == "") { return false; }	//| Quit if No Output Container
	if (sConfirmMessage != "") { if (!confirm(sConfirmMessage)) { return false; } } //| Quit if user cancels

	oOutputBox = $("#" + sOutputContainer);
	if (sRemove != "") { oLinkElement.remove(); }

	var bAppend = (GetStr(oLinkElement.attr("data-AppendToTarget")) != "");
	var bPrepend = (GetStr(oLinkElement.attr("data-PrependToTarget")) != "");

	URLToElement2(sGetURL, oOutputBox, sGetParams, bAppend, bPrepend);
	}

function URLToElement(sURL, oOutputBox, sGetParams) {
	URLToElement2(sURL, oOutputBox, sGetParams, false);
}

function URLToElement2(sURL, oOutputBox, sGetParams, bAppend, bPrepend) {
	if (GetStr(oOutputBox.attr("data-LoadDisabled")) == "")
		{
		$.get(sURL, sGetParams,
			function(data, sStatus){
				if (bPrepend)
					{ oOutputBox.prepend(data); }
				else if (bAppend)
					{ oOutputBox.append(data); }
				else
					{
					if (GetStr(oOutputBox.attr("data-NoLoadingMessage")) == "")
						{ oOutputBox.html(AjaxLoadingMessage()); }
					oOutputBox.html(data);
					}

				if (oOutputBox.hasClass("AutoScroll"))
					{ oOutputBox.scrollTop(oOutputBox.attr('scrollHeight')); }
				} );
		}
}

function UpdateElementContent(sElementID) {
	var sOutputContainer = "",
		oOutputBox,
		oElement = $("#" + sElementID);

	sOutputContainer = GetStr(oElement.attr("data-outputcontainer"));
	if (sOutputContainer == "")
		{ oOutputBox = $("#" + sElementID); }
	else
		{ oOutputBox = $("#" + sOutputContainer); }

	URLToElement(oElement.attr("data-content_url").replace("$$rand$$", GetRandomInt(10000, 99999)), oOutputBox, "");
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try
		{ xmlHttp=new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari
	catch (e)
		{
		try
			{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } // Internet Explorer
		catch (e)
			{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
		}
	return xmlHttp;
}

function TransformToOutput(sTemplateContainerID, sDataURL, sOutputContainerID) {
	$.get(sDataURL,
		function(sDataSet)
			{
			$("#" + sOutputContainerID)
				.html(
					TransformTemplate
						(
						$("#" + sTemplateContainerID).html(),
						sDataSet
						)
					);
			}
		);
}

function TransformTemplate(sTemplate, sSlimData) {
	return TransformTemplateAdv(sTemplate, sSlimData, ".-$$", "$$-.");
}
function TransformTemplateAdv(sTemplate, sSlimData, sIdentifierPrefix, sIdentifierSuffix) {
	var sOutput;
	sOutput = "";
	sRowSeparator = sSlimData.substring(0,1);
	sColumnSeparator = sSlimData.substring(1,2);
	debug("data = " + sSlimData);
	arrRows = sSlimData.substring(2,sSlimData.length).split(sRowSeparator);
	if (arrRows.length > 1)
		{
		arrColumnNames = arrRows[0].split(sColumnSeparator);
		for (nRowIndex = 1; nRowIndex < arrRows.length; nRowIndex++)
			{
			sSection = sTemplate;
			sRowData = arrRows[nRowIndex];
			arrRowData = sRowData.split(sColumnSeparator);
			for (nColumnIndex = 0; nColumnIndex < arrColumnNames.length; nColumnIndex++)
				{
				sColumnName = arrColumnNames[nColumnIndex];
				sIdentifier = sIdentifierPrefix + sColumnName.toLowerCase() + sIdentifierSuffix;
				while ( sSection.indexOf(sIdentifier) >= 0 )
					{ sSection = sSection.replace(sIdentifier, arrRowData[nColumnIndex]); }
				}

				if (!((sSection.indexOf(sIdentifierPrefix) >= 0) || (sSection.indexOf(sIdentifierSuffix) >= 0)))
					{ sOutput = sOutput + sSection; }
				else
					{ debug("BAD SECTION: " + sSection ); }

			}
		}
	return sOutput;
}


//|--------------------------------
//| String Test
//|--------------------------------

function StartsWith(sStringToCheck, sStartsWithString) {
	if	(
		LCase(Left(GetStr(sStringToCheck), Len(GetStr(sStartsWithString)))) == LCase(GetStr(sStartsWithString))
		&& Len(GetStr(sStartsWithString)) > 0
		)
		{ return true; }
	else
		{ return false; }
}

function EndsWith(sStringToCheck, sEndsWithString) {
	if	(
		LCase(Right(GetStr(sStringToCheck), Len(GetStr(sEndsWithString)))) == LCase(GetStr(sEndsWithString))
		&& Len(GetStr(sEndsWithString)) > 0
		)
		{ return true; }
	else
		{ return false; }
}


//|----------------------------------
//| String Formatting
//|----------------------------------

function Len(str) {
	return str.length;
}

function LCase(str) {
	return str.toLowerCase();
}

function UCase(str) {
	return str.toUpperCase();
}

function LimitLength(sInput, nMaxLength) {
	var sOutput = "";
	//sOutput = Trim(sInput);
	sOutput = GetStr(sInput);
	if (sOutput.length > nMaxLength)
		{
		if (nMaxLength > 3)
			{ sOutput = Trim(sOutput.substring(0, nMaxLength - 3)) + "..."; }
		else
			{ sOutput = Trim(sOutput.substring(0, nMaxLength)); }
		}
	return sOutput;
}

function URLEncode(str) {
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}

function URLDecode(str) {
	str = str.replace('+', ' ');
	str = unescape(str);
	return str;
}


function FilterString_ValidCharsOnly(sInput, sValidChars) {
	var sChar, sOutput;
	sOutput = "";
	for (nChar = 0; nChar < sInput.length; nChar++)
		{
		sChar = sInput.charAt(nChar);
		if (sValidChars.indexOf(sChar) >= 0)
			{sOutput = sOutput + sChar;}
		}
	return sOutput;
}

function FilterString_ValidCharsOnly_WithGapChar(sInput, sValidChars, sGapChar) {
	var sChar, sOutput;
	sOutput = "";
	for (nChar = 0; nChar < sInput.length; nChar++)
		{
		sChar = sInput.charAt(nChar);
		if (sValidChars.indexOf(sChar) >= 0)
			{sOutput = sOutput + sChar;}
		else
			{sOutput = sOutput + sGapChar;}
		}

	while (sOutput.indexOf(sGapChar + sGapChar) >= 0)
		{ sOutput = ReplaceAll(sOutput, sGapChar + sGapChar, sGapChar); }
	return sOutput;
}

function ReplaceAll(sStringToSearch, sStringToFind, sReplaceWith) {
	var sOutput;
	sOutput = sStringToSearch.replace(eval("/" + sStringToFind + "/gi"), sReplaceWith);
	return( sOutput );
}

function PadString(sStringToPad, nLength, sPadChars, bPadOnLeft) {
	var sOutput = "";
	sOutput = sStringToPad;
	while (sOutput.length < nLength)
		{
		if (bPadOnLeft)
			{ sOutput = sPadChars + sOutput; }
		else
			{ sOutput = sOutput + sPadChars; }
		}
	return sOutput;
}

function USW(sScrambled) {
	document.write(Unscramble(sScrambled));
}

function Unscramble(sScrambled) {
	var sUnscrambled = "";
	for (var i=0; i<sScrambled.length; i++) {
		nAsc = sScrambled.charCodeAt(i) - 128;
		if (nAsc < 0) {nAsc = nAsc + 256};
		sUnscrambled = sUnscrambled + String.fromCharCode(nAsc);
	}
	return sUnscrambled;
}

function FormatCurrency(nInput) {
	var nAmount = parseFloat(nInput);
	var minus = '';
	if (isNaN(nAmount)) { nAmount = 0.00; }
	if (nAmount < 0) { minus = '-'; }
	nAmount = Math.abs(nAmount);
	nAmount = parseInt((nAmount + .005) * 100);
	nAmount = nAmount / 100;
	sOutput = new String(nAmount);
	if(sOutput.indexOf('.') < 0) { sOutput += '.00'; }
	if(sOutput.indexOf('.') == (sOutput.length - 2)) { sOutput += '0'; }
	sOutput = minus + '$' + sOutput;
	return sOutput;
}

function FormatCurrency2(nInput) {
	var nAmount = parseFloat(nInput);
	var minus = '';
	if (isNaN(nAmount)) { nAmount = 0.00; }
	if (nAmount < 0) { minus = '-'; }
	nAmount = Math.abs(nAmount);
	nAmount = parseInt((nAmount + .005) * 100);
	nAmount = nAmount / 100;
	sOutput = new String(nAmount);
	if(sOutput.indexOf('.') < 0) { sOutput += '.00'; }
	if(sOutput.indexOf('.') == (sOutput.length - 2)) { sOutput += '0'; }
	sOutput = minus + sOutput;
	return sOutput;
}

function WriteEmailLink(sScrambledEmail) {
	document.write("<A HREF='mailto:" + Unscramble(sScrambledEmail) + "'>" + Unscramble(sScrambledEmail) + "</A>");
}

function FixFileName(sFileName) {
	var sOutput, sValidChars;
	sValidChars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-."
	sOutput = ReplaceAll(sFileName, "&", "and");
	sOutput = FilterString_ValidCharsOnly_WithGapChar(sOutput, sValidChars, "_");
	while (sOutput.indexOf("--") >= 0) { sOutput = ReplaceAll(sOutput, "--", "-"); }
	while (sOutput.indexOf("..") >= 0) { sOutput = ReplaceAll(sOutput, "..", "."); }
	return sOutput;
}

function EscapeHTML(sInput) {
	var sOutput = "";
	sOutput = sInput.toString();
	sOutput = ReplaceAll(sOutput,  "&", "&#38;");
	sOutput = ReplaceAll(sOutput,  "<", "&#60;");
	sOutput = ReplaceAll(sOutput,  ">", "&#62;");
	sOutput = ReplaceAll(sOutput, "\"", "&#34;");
	sOutput = ReplaceAll(sOutput,  "'", "&#39;");

	return sOutput;
}

function GetFullSizePath(sImgFile) {
	var sOutput = "";
	nImgID = GetImageID(sImgFile);
	sThousand = (Math.floor(nImgID/1000)*1000).toString();
	sOutput = sFullSizePath + PadString(sThousand, 9, "0", true) + "/";
	return sOutput;
}

function GetThumbNailPath(sThmFile) {
	var sOutput = "";
	nThmID = GetImageID(sThmFile);
	sThousand = (Math.floor(nThmID/1000)*1000).toString();
	sOutput = sThumbNailPath + PadString(sThousand, 9, "0", true) + "/";
	return sOutput;
}

function GetImageID(sImageFile) {
	var nImageID = 0;
	n_Pos = sImageFile.indexOf("_");
	if ( n_Pos >= 4 )
		{
		if ((sImageFile.substring(0,3).toLowerCase() == "thm") || (sImageFile.substring(0,3).toLowerCase() == "img"))
			{ nImageID = GetInt(sImageFile.substring(3, n_Pos)); }
		}
	return nImageID;
}

//|----------------------------------
//| String Trimming
//|--------------------------------
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function Trim(sInput) {
	var sOutput, sCharactersToTrim;
	sCharactersToTrim = " 	"
	sOutput = TrimChars(sInput, sCharactersToTrim);
	return sOutput;
}

function TrimChars(sInput, sCharactersToTrim) {
	var sOutput;
	sOutput = TrimCharsRight(TrimCharsLeft(sInput, sCharactersToTrim), sCharactersToTrim);
	return sOutput;
}

function TrimCharsLeft(sInput, sCharactersToTrim) {
	var sOutput;
	sOutput = "";
	if (sInput.length > 0)
		{
		sOutput = GetStr(sInput);
		while (sCharactersToTrim.indexOf(sOutput.substring(0,1)) >= 0)
			{ alert(sOutput); sOutput = sOutput.substring(1); }
		}
	return sOutput;
}

function TrimCharsRight(sInput, sCharactersToTrim) {
	var sOutput;
	sOutput = "";
	if (sInput.length > 0)
		{
		sOutput = GetStr(sInput);
		while (sCharactersToTrim.indexOf(sOutput.substring(sOutput.length-2,sOutput.length-1)) >= 0)
			{ sOutput = sOutput.substring(0,sOutput.length-2); }
		}
	return sOutput;
}

function TrimString(sInput, sStringToTrim) {
	var sOutput;
	sOutput = TrimStringRight(TrimStringLeft(sInput, sStringToTrim), sStringToTrim);
	return sOutput;
}

function TrimStringLeft(sInput, sStringToTrim) {
	var sOutput;
	sOutput = GetStr(sInput);

	while ( sOutput.substring(0,sStringToTrim.length).toLowerCase() == sStringToTrim.toLowerCase() )
		{ sOutput = sOutput.substring(sStringToTrim.length); }

	return sOutput;
}

function TrimStringRight(sInput, sStringToTrim) {
	var sOutput;
	sOutput = GetStr(sInput);

	while ( sOutput.substring(sOutput.length-sStringToTrim.length-1,sOutput.length-1).toLowerCase() == sStringToTrim.toLowerCase() )
		{ sOutput = sOutput.substring(0, sOutput.length-sStringToTrim.length-1); }

	return sOutput;
}

//|---------------------------------------------------------------------------
//| Type Conversion
//|---------------------------------------------------------------------------
function GetNumeric(vInput) {
	var nOutput = 0;
	if (!isNaN(vInput))
		{
		try { nOutput = parseFloat(vInput); }
		catch (e) { nOutput = 0; }
		}
	return nOutput;
}

function GetStr(vInput) {
	var sOutput = "";
	try { sOutput = vInput.toString(); }
	catch (e) { sOutput = ""; }
	return sOutput;
}

function GetInt(vInput) {
	var nOutput = 0;
	if (!isNaN(vInput))
		{
		try { nOutput = parseInt(vInput); }
		catch (e) { nOutput = 0; }
		}
	return nOutput;
}

function GetBit(vInput) {
	var nOutput;
	nOutput = GetInt(vInput);
	if (nOutput > 0) { nOutput = 1; }
	return nOutput;
}

//|---------------------------------------------------------------------------
//| Numeric & Math
//|---------------------------------------------------------------------------
function GreaterOf(nInput1, nInput2) {
	if (GetNumeric(nInput1) > GetNumeric(nInput2))
		{ return nInput1; }
	else
		{ return nInput2; }
}

function LesserOf(nInput1, nInput2) {
	if (GetNumeric(nInput1) < GetNumeric(nInput2))
		{ return nInput1; }
	else
		{ return nInput2; }
}

function LimitTo(nInput, nMin, nMax) {
	return LesserOf(GreaterOf(nInput, nMin), nMax);
}

//|----------------------------------
//| Utility
//|----------------------------------
function debug(sOutput) {
	$("#DebugOutput").html($("#DebugOutput").html() + "<BR><BR>" + sOutput);
}

function kp(e) {
	var kC  = (window.event)?event.keyCode:e.keyCode;
	var Esc = (window.event)?27:e.DOM_VK_ESCAPE;
	if(kC==Esc)
		{ HideTopModalPopup(); }
}
//|----------------------------------
//| Global Page Init
//|----------------------------------

bCenteringPopup = false;
bHidingThumbNailPopup = false;
bHidingGalleryPagePopup = false;
bHidingImagePagePopup = false;
sPopupThmFileURL = "";
nGalleryPopupID = 0;
nImagePopupID = 0;

nTopPopupZIndex = 1300;

