//------------------------------------------------------
// Page:					Viewer.js
// Author:				John Bradnam
// Created:				070812 JLB
// Copyright:			Republicorp P/L
// Purpose:				Dark Matter Viewer
// History:
// Search:				[^;{}]\n
//------------------------------------------------------

//------------------------------------------------------
// clsConfig
//------------------------------------------------------

function clsConfig() {
	this.path = "";
	this.title = "";
	this.offset = 0;
	this.pages = 0;
	this.pdf = "";
	this.size = "";
	this.view = 0;
	this.sizes = new Array();
	this.toc = new Array();
	this.mappings = new Array();
	this.stop = new Array();
	this.ftsu = new Array();
} //clsConfig

//------------------------------------------------------
// clsSize
//------------------------------------------------------

function clsSize(intWidth, intHeight) {
	this.width = intWidth;
	this.height = intHeight;
} //clsSize

//------------------------------------------------------
// clsToc
//------------------------------------------------------

function clsToc(strTitle, strPage) {
	this.title = strTitle;
	this.page = strPage;
} //clsToc

//------------------------------------------------------
// clsRssFeed
//------------------------------------------------------

function clsRssFeed(strRssFeed, intRssItems, strDivID) {
	this.feed = strRssFeed;
	this.count = intRssItems;
	this.div = strDivID;
	this.ajax = null;
	this.items = new Array();
	this.index = 0;
	this.pause = false;
	this.data = null;
} //clsRssFeed

//------------------------------------------------------
// clsRssItem
//------------------------------------------------------

function clsRssItem(strTitle, strLink, strDesc) {
	this.title = strTitle;
	this.link = strLink;
	this.desc = strDesc;
} //clsRssItem

//------------------------------------------------------
// clsWord
//------------------------------------------------------

function clsWord(strWordPages) {
	this.word = "";
	this.pages = null;
	this.message = "";
	if (strWordPages.indexOf(',') == -1)
		this.word = strWordPages;
	else {
		var aryWordPages = strWordPages.split(",");
		this.word = aryWordPages[0];
		this.pages = aryWordPages[1].split("|");
	}
} //clsToc

//------------------------------------------------------
// Initialise
//------------------------------------------------------

var ANIMATION_STEP = 80;
var ANIMATION_SPEED = 10;
var BOOKMARK_PERIOD = 2000;
var SINGLE_BUTTONS_VISIBILITY = "visible";

var intBorderMarginOneSize = 100;
var intBorderMarginTwoSize = 10;

var strProjectTitle = "";
var aryPublications = new Array();
var intCurrentPublication = -1;
var objCurrentPublication = null;
var intCurrentPage = 0;
var intCurrentView = 0;
var intCurrentStep = ANIMATION_STEP;
var intTwoSize = 2;
var intOneSize = 6;
var intA4Size = 6;
var intFullSize = 7;
var blnFullScreen = false;
var blnFullPostDrag = false;
var intDragStartX = 0;
var intDragStartY = 0;
var strSendToFriendProvider = "";
var strRssFeedProvider = "";
var strGoogleTrackerID = "";
var blnViewerInBookmark = false;
var strViewerLastBookmark = "";
var blnCanOnLoad = ((BrowserDetect.browser != "Chrome") && (BrowserDetect.browser != "Safari"));
var blnCanBookmark = ((BrowserDetect.browser != "Chrome") && (BrowserDetect.browser != "Safari"));
var intEmailPage = 0;
var intEmailMode = 0;
var intEmailPublication = -1;
var objSearchResults = null;
var intLastResizeHeight = 0;

function ViewerInitialise() {
	ViewerAddStyleSheets();
	if ((BrowserDetect.browser == "IE") && (BrowserDetect.major == 6))
		intBeautyBodyPadding = 30;
	else if (BrowserDetect.browser == "Firefox")
		intBeautyBodyPadding = 22;
	else
		intBeautyBodyPadding = 27;
	intBeautyHeadingPadding = 7;
	ControlsOnLoad();
	ViewerConfiguration();
	ViewerPublicationSet(0);
	ViewerResize();
	ViewerRestoreFromBookmark();
	ViewerSwitchView((intCurrentView != 0) ? intCurrentView : 2);
	window.onresize = function() {
		var intHeight = 768;
		if ((document.documentElement) && (document.documentElement.clientHeight))
			intHeight = document.documentElement.clientHeight;
		else if (document.body)
			intHeight = document.body.clientHeight;
		if (intHeight != intLastResizeHeight) {
			intLastResizeHeight = intHeight;
			ViewerResize();
			BeautyBarResize();
		}
	};

	var objSrn = document.getElementById("screen");
	objSrn.style.display = "";

	window.setTimeout("ViewerResize();BeautyBarResize();BeautyBarSelect('tab_contents')", (BrowserDetect.browser == "Firefox") ? 750 : 500);
} //ViewerInitialise

//------------------------------------------------------
// Stylesheets
//------------------------------------------------------

function ViewerAddStyleSheets() {
	ViewerAddStyleSheet(BrowserDetect.browser + ".css");
	ViewerAddStyleSheet(BrowserDetect.browser + BrowserDetect.major + ".css");
} //ViewerAddStyleSheets

function ViewerAddStyleSheet(strUrl) {
	var objLnk = document.createElement("LINK");
	objLnk.type = "text/css";
	objLnk.rel = "stylesheet";
	objLnk.href = strUrl;
	document.getElementsByTagName("HEAD")[0].appendChild(objLnk);
} //ViewerAddStyleSheet

//------------------------------------------------------
// Configuration
//------------------------------------------------------

function ViewerConfiguration() {
	var objAjax = new clsAjax(null, false);
	var strResult = objAjax.get("Configuration.xml");
	if (strResult != "") {
		var objXmlDoc = new clsXmlDoc(strResult);
		if (objXmlDoc.loaded) {
			strRssFeedProvider = objXmlDoc.getInnerText(objXmlDoc.getElementsByTagName(["rssfeedprovider"])[0]);
			strSendToFriendProvider = objXmlDoc.getInnerText(objXmlDoc.getElementsByTagName(["sendtofriendprovider"])[0]);
			strGoogleTrackerID = objXmlDoc.getInnerText(objXmlDoc.getElementsByTagName(["googletrackerid"])[0]);
			strProjectTitle = objXmlDoc.getInnerText(objXmlDoc.getElementsByTagName(["title"])[0]);
			document.title = strProjectTitle;
			var strCompanyLogo = objXmlDoc.getInnerText(objXmlDoc.getElementsByTagName(["companylogo"])[0]);
			document.getElementById("id_logo").src = strCompanyLogo;
			ViewerConfigurationLoadPublications(objXmlDoc);
		}
		objXmlDoc.destructor();
		objXmlDoc = null;
	}
	objAjax.destructor();
	objAjax = null;
	ViewerConfigurationLoadStopWords();
	if (strGoogleTrackerID != "") {
		var objScript = document.createElement("SCRIPT");
		objScript.type = "text/javascript";
		if (document.location.protocol == "https:")
			objScript.src = "https://ssl.google-analytics.com/ga.js";
		else
			objScript.src = "http://www.google-analytics.com/ga.js";
		document.getElementsByTagName("HEAD")[0].appendChild(objScript);
	}
} //ViewerConfiguration

function ViewerConfigurationLoadPublications(objXmlDoc) {
	var aryTag = objXmlDoc.getElementsByTagName("publication");
	var intCount = parseInt(aryTag.length);
	var intPubs = 0;
	for (var intPub = 0; intPub < intCount; intPub++) {
		aryPublications[intPubs] = null;
		var objTagPub = aryTag[intPub];
		if (!ViewerExpired(objTagPub)) {
			var objPublication = new clsConfig();
			aryPublications[intPubs] = objPublication;
			objPublication.title = objXmlDoc.getInnerText(objTagPub.getElementsByTagName(["title"])[0]);
			objPublication.path = objXmlDoc.getInnerText(objTagPub.getElementsByTagName(["folder"])[0]) + "/";
			objPublication.offset = parseInt(objXmlDoc.getInnerText(objTagPub.getElementsByTagName(["pageoffset"])[0]));
			objPublication.pdf = objXmlDoc.getInnerText(objTagPub.getElementsByTagName(["pdf"])[0]);
			objPublication.size = objXmlDoc.getInnerText(objTagPub.getElementsByTagName(["pdfsize"])[0]);
			ViewerConfigurationLoadPublicationPages(objPublication);
			intPubs = intPubs + 1;
		}
	} //for
} //ViewerConfigurationLoadPublications

function ViewerConfigurationLoadPublicationPages(objPublication) {
	objPublication.pages = 0;
	objPublication.sizes = new Array();
	var objPubAjax = new clsAjax(null, false);
	//Read config file
	var strResult = objPubAjax.get(objPublication.path + "Config.xml");
	if (strResult != "") {
		var objPubDoc = new clsXmlDoc(strResult);
		if (objPubDoc.loaded) {
			objPublication.pages = parseInt(objPubDoc.getInnerText(objPubDoc.getElementsByTagName(["pages"])[0]));
			var aryTag = objPubDoc.getElementsByTagName("size");
			var intCount = parseInt(aryTag.length);
			for (var intSize = 0; intSize < intCount; intSize++) {
				var objTagSize = aryTag[intSize];
				var intWidth = parseInt(objTagSize.getAttribute("width"));
				var intHeight = parseInt(objTagSize.getAttribute("height"));
				objPublication.sizes[intSize] = new clsSize(intWidth, intHeight);
			} //for
		}
		objPubDoc.destructor();
		objPubDoc = null;
	}
	objPubAjax.destructor();
	objPubAjax = null;
} //ViewerConfigurationLoadPublicationPages

function ViewerConfigurationInitialisePublications() {
  var objDiv = null;
  if (aryPublications.length > 1) {
    objDiv = document.getElementById("id_publications");
    var strText = "";
    strText += "<table class='publications' cellpadding='0' cellspacing='0' border='0'>";
    strText += ViewerConfigurationPublicationAddEntry(intCurrentPublication);
    for (intIndex = 0; intIndex < aryPublications.length; intIndex++) {
      if (intIndex != intCurrentPublication)
        strText += ViewerConfigurationPublicationAddEntry(intIndex);
    }
    strText += "</table>";
    objDiv.innerHTML = strText;
  }
  else {
    objDiv = document.getElementById("tab_publications");
    objDiv.style.display = "none";
    objDiv = GetNextSibling(objDiv);
    objDiv.style.display = "none";
    BeautyBarSetTabCount();
  }
} //ViewerConfigurationInitialisePublications

function ViewerConfigurationPublicationAddEntry(intPublication) {
	var strText = "";
	var strImage = aryPublications[intPublication].path + "Pages/page_1_0.jpg";
	strText += "<tr runat='server' onmouseover='TableCursorOver(this);' onmouseout='TableCursorOut(this);'";
	strText += " onclick='ViewerPublicationSet(" + intPublication + ");'";
	strText += " >";
	strText += "<td class='thumb'>";
	strText += "<img src='" + strImage + "' alt='View " + aryPublications[intPublication].title + "' />";
	strText += "</td>";
	strText += "<td class='preview'>";
	strText += (intPublication == intCurrentPublication) ? "You are currently viewing " : "Click to view ";
	strText += "<span class='title'>" + aryPublications[intPublication].title + "</span>";
	strText += "</td>";
	strText += "</tr>";
	return strText;
} //ViewerConfigurationPublicationAddEntry

function ViewerConfigurationLoadPublicationToc() {
	var objDiv = document.getElementById("id_contents");
	var strPage = "";
	var strPageText = "";
	var strPageUrl = "";
	var strText = "";
	var objPubAjax = new clsAjax(null, false);
	var strResult = objPubAjax.get(objCurrentPublication.path + "Contents.xml");
	if (strResult != "") {
		var objPubDoc = new clsXmlDoc(strResult);
		if (objPubDoc.loaded) {
			var aryTocTag = objPubDoc.getElementsByTagName("title");
			var intTocCount = parseInt(aryTocTag.length);
			if (intTocCount != 0) {
				strText += "<table class='contents' cellpadding='0' cellspacing='0' border='0'>";
				for (var intToc = 0; intToc < intTocCount; intToc++) {
					var objTagToc = aryTocTag[intToc];
					var strEntry = objPubDoc.getInnerText(objTagToc);
					strPage = objTagToc.getAttribute("page");
					if (strPage.indexOf("://") != -1) {
						strPageText = "&nbsp;";
						strPageUrl = " onclick='ViewerGoUrl(\"" + strPage + "\");'";
					}
					else {
						strPageText = strPage;
						strPageUrl = " onclick='ViewerGoLog(\"" + strPage + "\");'";
					}
					strText += "<tr runat='server' onmouseover='TableCursorOver(this);' onmouseout='TableCursorOut(this);'";
					strText += strPageUrl;
					strText += " >";
					strText += "<td class='title'>" + strEntry + "</td>";
					strText += "<td class='page'>" + strPageText + "</td>";
					strText += "</tr>";
				} //for
				strText += "</table>";
			}
		}
		objPubDoc.destructor();
		objPubDoc = null;
	}
	objPubAjax.destructor();
	objPubAjax = null;
	objDiv.innerHTML = strText;
} //ViewerConfigurationLoadPublicationToc

function ViewerConfigurationLoadPublicationMapping() {
  var objPublication = objCurrentPublication;
  var objPubAjax = new clsAjax(null, false);
  var strResult = objPubAjax.get(objPublication.path + "PageLabels.xml");
  if (strResult != "") {
    var objPubDoc = new clsXmlDoc(strResult);
    if (objPubDoc.loaded) {
      var aryMapTag = objPubDoc.getElementsByTagName("pagelabel");
      var intMapCount = parseInt(aryMapTag.length);
      for (var intMap = 0; intMap < intMapCount; intMap++)
        objPublication.mappings[intMap] = objPubDoc.getInnerText(aryMapTag[intMap]);
    }
    objPubDoc.destructor();
    objPubDoc = null;
  }
  objPubAjax.destructor();
  objPubAjax = null;
} //ViewerConfigurationLoadPublicationMapping

function ViewerConfigurationLoadStopWords() {
	for (var intPub = 0; intPub < aryPublications.length; intPub++) {
		var objPublication = aryPublications[intPub];
		if (objPublication != null) {
			var objPubAjax = new clsAjax(null, false);
			//Read stop word file
			var strResult = objPubAjax.get(objPublication.path + "Index/Stop.xml");
			if (strResult != "") {
				var objPubDoc = new clsXmlDoc(strResult);
				if (objPubDoc.loaded) {
					var aryIndexTag = objPubDoc.getElementsByTagName("index");
					var intIndexCount = parseInt(aryIndexTag.length);
					for (var intIndex = 0; intIndex < intIndexCount; intIndex++) {
						var objTagIndex = aryIndexTag[intIndex];
						var strEntry = objPubDoc.getInnerText(objTagIndex);
						if (strEntry != "")
							objPublication.stop[intIndex] = strEntry.split("|");
					} //for
				}
				objPubDoc.destructor();
				objPubDoc = null;
			}
			objPubAjax.destructor();
			objPubAjax = null;
		}
	} //for
} //ViewerConfigurationLoadStopWords

function ViewerExpired(objTag) {
  blnExpired = false;
  var strExpires = objTag.getAttribute('expires');
  if ((strExpires != null) && (strExpires != "")) {
    var aryElements = strExpires.split('-');
    var objExpire = new Date();
    objExpire.setFullYear(aryElements[0]);
    objExpire.setMonth(aryElements[1] - 1);
    objExpire.setDate(aryElements[2]);
    var objToday = new Date();
    blnExpired = (objToday > objExpire);
  }
  var strGroup = objTag.getAttribute('group');
  if ((strGroup != null) && (strGroup != "")) {
    var strUrl = document.location.href;
    var intToken = strUrl.indexOf("&" + strGroup + "=");
    if (intToken == -1)
      intToken = strUrl.indexOf("?" + strGroup + "=");
    if (intToken == -1)
      intToken = strUrl.indexOf("#" + strGroup + "=");
    if (intToken != -1) {
      intToken = intToken + strGroup.length + 2;
      if (strUrl.substr(intToken, 5) == "false")
        blnExpired = true;
      else if (strUrl.substr(intToken, 4) == "true")
        blnExpired = false;
    }
  }
  return blnExpired;
} //ViewerPanelExpired

//------------------------------------------------------
// Publication
//------------------------------------------------------

function ViewerPublicationSet(intPublication) {
	if (intPublication != intCurrentPublication) {
		intCurrentPublication = intPublication;
		objCurrentPublication = aryPublications[intCurrentPublication];
		intTwoSize = 2;
		intOneSize = 6;
		intFullSize = objCurrentPublication.sizes.length - 1;
		intA4Size = objCurrentPublication.sizes.length - 2;
		ViewerConfigurationInitialisePublications();
		ViewerConfigurationLoadPublicationToc();
		ViewerConfigurationLoadPublicationMapping();
		ViewerSetPage((intCurrentView == 1) ? 1 : 0);
		ViewerResize();
	}
} //ViewerPublicationSet

//------------------------------------------------------
// Tab bar
//------------------------------------------------------

function ViewerContents() {
} //ViewerContents

function ViewerSearch(strSearchTerm) {
	if ((typeof (strSearchTerm) == "string") && (strSearchTerm != "")) {
		var objEdt = document.getElementById("input_find");
		WatermarkSetValue(objEdt, strSearchTerm);
		ViewerSearchGetResults(strSearchTerm);
	}
	window.setTimeout("ViewerSearchFocus()", 1);
} //ViewerSearch

function ViewerPrint() {
} //ViewerPrint

function ViewerShare() {
} //ViewerShare

function ViewerPublications() {
} //ViewerPublications

//------------------------------------------------------
// Toolbar
//------------------------------------------------------

function ViewerFirst() {
	if (intCurrentView != 0)
		ViewerGoPhy(1);
	return false;
}  //ViewerFirst

function ViewerPrev() {
	if (intCurrentView == 0)
		;
	else if ((intCurrentView == 1) && (intCurrentPage > 1))
		ViewerGoPhy(intCurrentPage - 1);
	else if ((intCurrentView == 2) && (intCurrentPage > 0)) {
		var strPath = objCurrentPublication.path;
		var intTwoPageWidth = objCurrentPublication.sizes[intTwoSize].width;
		var objLeft = document.getElementById("id_imgleft");
		var objRight = document.getElementById("id_imgright");
		var objMapLeft = document.getElementById("id_mapleft");
		var objMapRight = document.getElementById("id_mapright");
		var objUnderLeft = document.getElementById("id_underleft");
		var objUnderRight = document.getElementById("id_underright");
		var objTurnLeft = document.getElementById("id_turnleft");
		objRight.style.width = "0px";
		objRight.style.left = intTwoPageWidth + "px";
		objLeft.src = strPath + "Pages/page_" + (intCurrentPage) + "_" + intTwoSize + ".jpg";
		objRight.src = strPath + "Pages/page_" + (intCurrentPage - 1) + "_" + intTwoSize + ".jpg";
		objUnderLeft.src = strPath + "Pages/page_" + (intCurrentPage - 2) + "_" + intTwoSize + ".jpg";
		objUnderRight.src = strPath + "Pages/page_" + (intCurrentPage + 1) + "_" + intTwoSize + ".jpg";
		objUnderLeft.style.visibility = ((intCurrentPage - 2) > 0) ? "visible" : "hidden";
		objMapLeft.style.display = "none";
		objMapRight.style.display = "none";
		objTurnLeft.style.visibility = "hidden";
		ViewerAnimate(intCurrentPage, 0, intTwoPageWidth, intCurrentStep, -intCurrentStep, 0);
	}
	return false;
}  //ViewerPrev

function ViewerGoLog(strPage) {
	var objRoman = new clsRoman();
	objRoman.pages = objCurrentPublication.pages;
	objRoman.offset = objCurrentPublication.offset;
	objRoman.mappings = objCurrentPublication.mappings;
	ViewerGoPhy(objRoman.getphysical(strPage));
	return false;
}  //ViewerGoLog

function ViewerSwitchGoPhy(intPage) {
	ViewerReturn();
	ViewerGoPhy(intPage);
	return false;
}  //ViewerSwitchGoPhy

function ViewerGoPhy(intPage) {
	var intPages = objCurrentPublication.pages;
	var intPagesNormalized = ((intPages % 2) == 0) ? intPages + 2 : intPages + 1;
	if ((intPage > 0) && (intPage <= intPages)) {
		if (intCurrentView == 1) {
			if (blnFullScreen)
				ViewerZoomOut();
			ViewerSetPage(intPage);
		}
		else if (intCurrentView == 2) {
			var intLeft = intPage & 0x0fffe;
			if ((intLeft + 2) > intPagesNormalized)
				intLeft = intPagesNormalized - 2;
			if (blnFullScreen)
				ViewerZoomOut();
			ViewerSetPage(intLeft);
		}
	}
	return false;
}  //ViewerGoPhy

function ViewerGoTo(intPage) {
	var objEdt = null;
	if (typeof(intPage) == "object") {
		objEdt = intPage.nextSibling;
		intPage = WatermarkGetValue(objEdt);
		objEdt.value = "";
		WatermarkBlur(objEdt, null);
	}
	if (intPage == "")
		alert("Click in the box and enter the page number that you wish\nto view, then click this button to view that page.");
	else {
		var objRoman = new clsRoman();
		objRoman.pages = objCurrentPublication.pages;
		objRoman.offset = objCurrentPublication.offset;
		objRoman.mappings = objCurrentPublication.mappings;
		var intPhy = objRoman.getphysical(intPage);
		if (intPhy == 0)
			alert("Page range must be between " + objRoman.getlogical(1) + " and " + objRoman.getlogical(objCurrentPublication.pages));
		else {
			if (objEdt == null)
				objEdt = document.getElementById("btn_goto");
			objEdt.value = "";
			WatermarkBlur(objEdt, null);
			ViewerGoPhy(intPhy);
		}
	}
	return true;
} //ViewerGoTo

function ViewerNext() {
	var intPages = objCurrentPublication.pages;
	var intPagesNormalized = ((intPages % 2) == 0) ? intPages + 2 : intPages + 1;
	if ((intCurrentView != 0) && ((intCurrentPage + 2) < intPagesNormalized)) {
		if (intCurrentView == 1)
			ViewerGoPhy(intCurrentPage + intCurrentView);
		else {
			var strPath = objCurrentPublication.path;
			var intTwoPageWidth = objCurrentPublication.sizes[intTwoSize].width;
			var objLeft = document.getElementById("id_imgleft");
			var objRight = document.getElementById("id_imgright");
			var objMapLeft = document.getElementById("id_mapleft");
			var objMapRight = document.getElementById("id_mapright");
			var objUnderLeft = document.getElementById("id_underleft");
			var objUnderRight = document.getElementById("id_underright");
			var objTurnRight = document.getElementById("id_turnright");
			objLeft.style.width = "0px";
			objLeft.style.left = intTwoPageWidth + "px";
			objLeft.src = strPath + "Pages/page_" + (intCurrentPage + 2) + "_" + intTwoSize + ".jpg";
			objRight.src = strPath + "Pages/page_" + (intCurrentPage + 1) + "_" + intTwoSize + ".jpg";
			objUnderLeft.src = strPath + "Pages/page_" + (intCurrentPage) + "_" + intTwoSize + ".jpg";
			objUnderRight.src = strPath + "Pages/page_" + (intCurrentPage + 3) + "_" + intTwoSize + ".jpg";
			objUnderRight.style.visibility = ((intCurrentPage + 3) <= intPages) ? "visible" : "hidden";
			objMapLeft.style.display = "none";
			objMapRight.style.display = "none";
			objTurnRight.style.visibility = "hidden";
			ViewerAnimate(intCurrentPage + 1, intTwoPageWidth, intTwoPageWidth, 0, -intCurrentStep, 0);
		}
	}
	return false;
}  //ViewerNext

function ViewerLast() {
	if (intCurrentView != 0)
		ViewerGoPhy(objCurrentPublication.pages);
	return false;
}  //ViewerLast

function ViewerGoFocus(objEdt) {
	objEdt.value = "";
}  //ViewerGoFocus

function ViewerGoBlur() {
	ViewerPageChange();
}  //ViewerGoBlur

function ViewerGoKeyDown(objEvent) {
	if (objEvent == null)
		objEvent = event;
	if ((intCurrentView != 0) && (objEvent.keyCode == 13)) {
		var objInp = (objEvent.srcElement) ? objEvent.srcElement : objEvent.currentTarget;
		var strPage = encodeURIComponent(objInp.value);
		var objRoman = new clsRoman();
		objRoman.pages = objCurrentPublication.pages;
		objRoman.offset = objCurrentPublication.offset;
		objRoman.mappings = objCurrentPublication.mappings;
		var intPage = objRoman.getphysical(strPage);
		if (intPage == 0)
			alert("Page range must be between " + objRoman.getlogical(1) + " and " + objRoman.getlogical(objRoman.pages));
		else
			ViewerGoPhy(intPage);
		objInp.select();
		objEvent.returnValue = false;
	}
}  //ViewerGoKeyDown

function ViewerPdf() {
	var strPath = objCurrentPublication.path;
	window.open(strPath + objCurrentPublication.pdf, "_blank");
} //ViewerPdf

//------------------------------------------------------
// ViewerAnimate
//------------------------------------------------------

function ViewerAnimate(intPage, intLeft, intWidth, intLeftDelta, intWidthDelta, intMode) {
	var intTwoPageWidth = objCurrentPublication.sizes[intTwoSize].width;
	var blnDone = false;
	if (((intMode == 0) && (intWidth != 0)) || ((intMode == 1) && (intWidth < intTwoPageWidth))) {
		intLeft = intLeft + intLeftDelta;
		intWidth = intWidth + intWidthDelta;
		intLeft = (intLeft < 0) ? 0 : intLeft;
		intWidth = (intWidth < 0) ? 0 : (intWidth > intTwoPageWidth) ? intTwoPageWidth : intWidth;
	}
	else {
		intMode = intMode + 1;
		if (intMode == 2) {
			blnDone = true;
			if (intLeftDelta == 0)
				ViewerGoPhy(intCurrentPage - 1);
			else
				ViewerGoPhy(intCurrentPage + intCurrentView);
		}
		else if (intLeftDelta == 0) {
			//next
			intPage = intPage + 1;
			intLeft = intTwoPageWidth;
			intWidth = 0;
			intLeftDelta = -intCurrentStep;
			intWidthDelta = intCurrentStep;
		}
		else {
			//prev
			intPage = intPage - 1;
			intLeft = intTwoPageWidth;
			intWidth = 0;
			intLeftDelta = 0;
			intWidthDelta = intCurrentStep;
		}
	}
	if (!blnDone) {
		var objImg = ((intPage % 2) == 0) ? document.getElementById("id_imgleft") : document.getElementById("id_imgright");
		var intHeight = objCurrentPublication.sizes[intTwoSize].height;
		objImg.style.left = intLeft + "px";
		objImg.style.width = intWidth + "px";
		objImg.style.height = intHeight + "px";
		window.setTimeout("ViewerAnimate(" + intPage + "," + intLeft + "," + intWidth + "," + intLeftDelta + "," + intWidthDelta + "," + intMode + ")", ANIMATION_SPEED);
	}
} //ViewerAnimate

//------------------------------------------------------
// ViewerResize
//------------------------------------------------------

function ViewerResize() {
  var intSW = 1024;
  var intSH = 768;
  if ((document.documentElement) && (document.documentElement.clientHeight)) {
    intSW = document.documentElement.clientWidth;
    intSH = document.documentElement.clientHeight;
  }
  else if (document.body) {
    intSW = document.body.clientWidth;
    intSH = document.body.clientHeight;
  }
  var intEW = intSW - 320;
  var intEH = intSH;

  //Resize black beauty bar
  var objViewer = document.getElementById("id_viewer");
  objViewer.style.height = intSH + "px";
  //BeautyBarResize();

  //Calculate the smallest two page size to fit
	var intLastTwoPageSize = intTwoSize;
	intTwoSize = 1;
	for (var intSize = objCurrentPublication.sizes.length - 1; intSize > 0; intSize--) {
	  if ((intEW > ((objCurrentPublication.sizes[intSize].width << 1) + intBorderMarginTwoSize)) &&
				(intEH > (objCurrentPublication.sizes[intSize].height + intBorderMarginTwoSize))) {
			intTwoSize = intSize;
			break;
		}
	} //for;
	intCurrentStep = (((intTwoSize) >> 1) + 1) * ANIMATION_STEP;

	//Calculate the smallest one page size to fit
	var intLastOnePageSize = intOneSize;
	intOneSize = 1;
	for (var intSize = objCurrentPublication.sizes.length - 1; intSize > 0; intSize--) {
	  if (intEW >= (objCurrentPublication.sizes[intSize].width + intBorderMarginOneSize)) {
			intOneSize = intSize;
			break;
		}
	} //for;

	if ((intLastOnePageSize != intOneSize) || (intLastTwoPageSize != intTwoSize))
		ViewerSetPage(intCurrentPage);

	var intWidth = objCurrentPublication.sizes[intTwoSize].width;

	var objScreen = document.getElementById("id_twoviewframe");
	objScreen.style.marginTop = ((intCurrentView == 1) ? 0 : ((intSH - objScreen.offsetHeight) >> 1)) + "px";

	var intHeight = intSH;
	var objMapMain = document.getElementById("id_mapview");
	var objImgMain = document.getElementById("id_imgmain");
	var objOnePage = document.getElementById("id_oneviewscroll");
	objOnePage.style.height = intHeight + "px";
	if (objImgMain.offsetWidth != 0) {
	  var intMargin = (intEW - objImgMain.offsetWidth) >> 1;
	  objMapMain.style.marginLeft = intMargin + "px";
	  objMapMain.style.height = objImgMain.offsetHeight + "px";
	  objImgMain.style.marginLeft = intMargin + "px";
	  var objTabLeft = document.getElementById("id_tableft");
	  var objTabRight = document.getElementById("id_tabright");
	  objTabLeft.style.height = intHeight + "px";
	  objTabRight.style.height = intHeight + "px";
	  objTabLeft.style.left = intMargin - 45 + "px";
	  objTabRight.style.left = intMargin + objImgMain.offsetWidth + 2 + "px";
	  objTabRight.style.visibility = SINGLE_BUTTONS_VISIBILITY;
	  objTabLeft.style.visibility = SINGLE_BUTTONS_VISIBILITY;
	}
	else if (intCurrentView == 1)
	  window.setTimeout("ViewerResize()", 500);

	if (blnFullScreen) {
		var objFull = document.getElementById("id_fullsize");
		var intW = objFull.offsetWidth;
		var intH = objFull.offsetHeight;
		var intX = objFull.offsetLeft;
		var intY = objFull.offsetTop;
		objFull.style.left = ((intW < intSW) ? (intSW - intW) >> 1 : (intX > 0) ? 0 : ((intX + intW) < intSW) ? intSW - intW : intX) + "px";
		objFull.style.top = ((intH < intSH) ? (intSH - intH) >> 1 : (intY > 0) ? 0 : ((intY + intH) < intSH) ? intSH - intH : intY) + "px";
	}
} //ViewerResize

function ViewerSwitchView(intMode) {
	var objOne = document.getElementById("btn_onepage");
	var objTwo = document.getElementById("btn_twopage");
	objOne.style.display = (intMode == 2) ? "" : "none";
	objTwo.style.display = (intMode == 1) ? "" : "none";
	objOne = document.getElementById("id_oneview");
	objTwo = document.getElementById("id_twoview");
	objOne.style.display = (intMode == 1) ? "" : "none";
	objTwo.style.display = (intMode == 2) ? "" : "none";
	intCurrentView = intMode;
	if (intCurrentPage == 0)
		intCurrentPage = 1;
	ViewerSetPage((intMode == 1) ? intCurrentPage : intCurrentPage & 0xfffe);
	ViewerResize();
	ViewerPageChange();
	return false;
} //ViewerSwitchView

function ViewerInitialiseMode() {
  var intPagesPdf = objCurrentPublication.pages;

  var objLeft = document.getElementById("id_imgleft");
  var objRight = document.getElementById("id_imgright");
  var objUnderLeft = document.getElementById("id_underleft");
  var objUnderRight = document.getElementById("id_underright");
  var objLoadLeft = document.getElementById("id_loadleft");
  var objLoadRight = document.getElementById("id_loadright");
  var objTurnLeft = document.getElementById("id_turnleft");
  var objTurnRight = document.getElementById("id_turnright");
  objLeft.style.visibility = (intCurrentPage == 0) ? "hidden" : "visible";
  objUnderLeft.style.visibility = (intCurrentPage < 2) ? "hidden" : "visible";
  objLoadLeft.style.visibility = objLeft.style.visibility;
  objRight.style.visibility = (intCurrentPage == intPagesPdf) ? "hidden" : "visible";
  objUnderRight.style.visibility = (intCurrentPage > (intPagesPdf - 2)) ? "hidden" : "visible";
  objLoadRight.style.visibility = objRight.style.visibility;

  objTurnLeft.style.visibility = objUnderLeft.style.visibility;
  objTurnRight.style.visibility = objUnderRight.style.visibility;

  objFull = document.getElementById("id_fullsize");
  objLeft = document.getElementById("id_fullleft");
  objRight = document.getElementById("id_fullright");
  objMapLeft = document.getElementById("id_fullmapleft");
  objMapRight = document.getElementById("id_fullmapright");
  var blnLeft = ((intCurrentView == 1) || (intCurrentPage != 0));
  var blnRight = ((intCurrentView == 2) && (intCurrentPage != intPagesPdf));
  objLeft.style.display = (blnLeft) ? "" : "none";
  objRight.style.display = (blnRight) ? "" : "none";
  objMapLeft.style.display = (blnLeft) ? "" : "none";
  objMapRight.style.display = (blnRight) ? "" : "none";
  if ((blnLeft) && (blnRight)) {
    objLeft.style.left = "0px";
    objRight.style.left = "1000px";
    objMapLeft.style.left = "0px";
    objMapRight.style.left = "1000px";
    objFull.style.width = "2000px";
    objFull.style.height = objLeft.offsetHeight + "px";
  }
  else if (blnLeft) {
    objLeft.style.left = "0px";
    objMapLeft.style.left = "0px";
    objFull.style.width = "1000px";
    objFull.style.height = objLeft.offsetHeight + "px";
  }
  else {
    objRight.style.left = "0px";
    objMapRight.style.left = "0px";
    objFull.style.width = "1000px";
    objFull.style.height = objRight.offsetHeight + "px";
  }
}  //ViewerInitialiseMode

//------------------------------------------------------
// ViewerSetPage
//------------------------------------------------------

function ViewerSetPage(intPage) {
	intCurrentPage = intPage;
	var intFullSizeWidth = objCurrentPublication.sizes[intFullSize].width;
	var intFullSizeHeight = objCurrentPublication.sizes[intFullSize].height;
	var strPath = objCurrentPublication.path;

	var objMain = document.getElementById("id_imgmain");
	var objMapMain = document.getElementById("id_mapmain");
	var objImgLoad = document.getElementById("id_loadmain");
	var intOnePageWidth = objCurrentPublication.sizes[intOneSize].width;
	var intOnePageHeight = objCurrentPublication.sizes[intOneSize].height;
	objMain.style.width = intOnePageWidth + "px";
	objMain.style.height = intOnePageHeight + "px";
	objMapMain.style.width = intOnePageWidth + "px";
	objMapMain.style.height = intOnePageHeight + "px";
	objImgLoad.style.width = intOnePageWidth + "px";
	objImgLoad.style.height = intOnePageHeight + "px";

	var objTwoView = document.getElementById("id_twoviewframe");
	var objLeft = document.getElementById("id_imgleft");
	var objRight = document.getElementById("id_imgright");
	var objMapLeft = document.getElementById("id_mapleft");
	var objMapRight = document.getElementById("id_mapright");
	var objUnderLeft = document.getElementById("id_underleft");
	var objUnderRight = document.getElementById("id_underright");
	var objLoadLeft = document.getElementById("id_loadleft");
	var objLoadRight = document.getElementById("id_loadright");
	var intTwoPageWidth = objCurrentPublication.sizes[intTwoSize].width;
	var intTwoPageHeight = objCurrentPublication.sizes[intTwoSize].height;

	objTwoView.style.width = (intTwoPageWidth << 1) + "px";
	objTwoView.style.height = intTwoPageHeight + "px";
	objLeft.style.width = intTwoPageWidth + "px";
	objLeft.style.height = intTwoPageHeight + "px";
	objLeft.style.left = "0px";
	objRight.style.width = intTwoPageWidth + "px";
	objRight.style.left = intTwoPageWidth + "px";
	objRight.style.height = intTwoPageHeight + "px";
	objMapLeft.style.width = intTwoPageWidth + "px";
	objMapLeft.style.height = intTwoPageHeight + "px";
	objMapLeft.style.left = "0px";
	objMapRight.style.width = intTwoPageWidth + "px";
	objMapRight.style.left = intTwoPageWidth + "px";
	objMapRight.style.height = intTwoPageHeight + "px";
	objUnderLeft.style.width = intTwoPageWidth + "px";
	objUnderLeft.style.height = intTwoPageHeight + "px";
	objUnderLeft.style.left = "0px";
	objUnderRight.style.width = intTwoPageWidth + "px";
	objUnderRight.style.left = intTwoPageWidth + "px";
	objUnderRight.style.height = intTwoPageHeight + "px";
	objLoadLeft.style.width = intTwoPageWidth + "px";
	objLoadLeft.style.height = intTwoPageHeight + "px";
	objLoadLeft.style.left = "0px";
	objLoadRight.style.width = intTwoPageWidth + "px";
	objLoadRight.style.left = intTwoPageWidth + "px";
	objLoadRight.style.height = intTwoPageHeight + "px";

	var strLoad = (blnCanOnLoad) ? "" : "none";
	var strMain = (blnCanOnLoad) ? "none" : "";
	objImgLoad.style.display = strLoad;
	objMain.style.display = strMain;
	objMapMain.style.display = strMain;
	objLoadLeft.style.display = strLoad;
	objLeft.style.display = strMain;
	objMapLeft.style.display = strMain;
	objLoadRight.style.display = strLoad;
	objRight.style.display = strMain;
	objMapRight.style.display = strMain;

	var intPagesPdf = objCurrentPublication.pages;
	if ((intCurrentPage > 0) && (intCurrentPage <= intPagesPdf)) {
	  objMain.src = strPath + "Pages/page_" + intCurrentPage + "_" + intOneSize + ".jpg";
	  objLeft.src = strPath + "Pages/page_" + intCurrentPage + "_" + intTwoSize + ".jpg";
	}
	if ((intCurrentPage + 1) <= intPagesPdf)
	  objRight.src = strPath + "Pages/page_" + (intCurrentPage + 1) + "_" + intTwoSize + ".jpg";
	if ((intCurrentPage - 2) > 0)
	  objUnderLeft.src = strPath + "Pages/page_" + (intCurrentPage - 2) + "_" + intTwoSize + ".jpg";
	if ((intCurrentPage + 3) <= intPagesPdf)
	  objUnderRight.src = strPath + "Pages/page_" + (intCurrentPage + 3) + "_" + intTwoSize + ".jpg";
	if ((intCurrentPage > 0) && (intCurrentPage <= intPagesPdf)) {
	  ViewerLoadMaps(objMapMain, intCurrentPage, intOnePageWidth / intFullSizeWidth, intOnePageHeight / intFullSizeHeight);
	  ViewerLoadMaps(objMapLeft, intCurrentPage, intTwoPageWidth / intFullSizeWidth, intTwoPageHeight / intFullSizeHeight);
	}
	if ((intCurrentPage + 1) <= intPagesPdf)
	  ViewerLoadMaps(objMapRight, intCurrentPage + 1, intTwoPageWidth / intFullSizeWidth, intTwoPageHeight / intFullSizeHeight);

	objLeft = document.getElementById("id_fullleft");
	objRight = document.getElementById("id_fullright");
	objMapLeft = document.getElementById("id_fullmapleft");
	objMapRight = document.getElementById("id_fullmapright");
	if ((intCurrentPage > 0) && (intCurrentPage <= intPagesPdf))
	  objLeft.src = strPath + "Pages/page_" + intCurrentPage + "_" + intFullSize + ".jpg";
	if ((intCurrentPage + 1) <= intPagesPdf)
	  objRight.src = strPath + "Pages/page_" + (intCurrentPage + 1) + "_" + intFullSize + ".jpg";
	if ((intCurrentPage > 0) && (intCurrentPage <= intPagesPdf))
	  ViewerLoadMaps(objMapLeft, intCurrentPage, 1, 1);
	if ((intCurrentPage + 1) <= intPagesPdf)
	  ViewerLoadMaps(objMapRight, intCurrentPage + 1, 1, 1);

	ViewerInitialiseMode();
	ViewerPageChange();
}  //ViewerSetPage

function ViewerOnImageLoad(intType) {
  switch (intType) {
    case 0:
      document.getElementById("id_loadmain").style.display = "none";
      document.getElementById("id_imgmain").style.display = "";
      document.getElementById("id_mapmain").style.display = "";
      break;

    case 1:
      document.getElementById("id_loadleft").style.display = "none";
      document.getElementById("id_imgleft").style.display = "";
      document.getElementById("id_mapleft").style.display = "";
      break;

    case 2:
      document.getElementById("id_loadright").style.display = "none";
      document.getElementById("id_imgright").style.display = "";
      document.getElementById("id_mapright").style.display = "";
      break;
  } //switch
} //ViewerOnImageLoad

function ViewerLoadMaps(objMap, intMapPage, dblScaleX, dblScaleY) {
  var strHTML = "";
  var intLeft = 0;
  var intRight = 0;
  var intTop = 0;
  var intBottom = 0;
  var intPage = "";
  var strUrl = "";
  var objPubAjax = new clsAjax(null, false);
  var strResult = objPubAjax.get(objCurrentPublication.path + "Pages/page_" + intMapPage + ".xml");
  if (strResult != "") {
    var objPubDoc = new clsXmlDoc(strResult);
    if (objPubDoc.loaded) {
      //<link left="39" top="1200" right="271" bottom="1229" page="0" url="http://www.fostersgroup.com" />
      var aryLinkTag = objPubDoc.getElementsByTagName("link");
      var intLinkCount = parseInt(aryLinkTag.length);
      if (intLinkCount != 0) {
        var objRoman = new clsRoman();
        objRoman.pages = objCurrentPublication.pages;
        objRoman.offset = objCurrentPublication.offset;
        objRoman.mappings = objCurrentPublication.mappings;
        for (var intLink = 0; intLink < intLinkCount; intLink++) {
          var objTagLink = aryLinkTag[intLink];
          intLeft = Math.round(parseFloat(objTagLink.getAttribute("left")) * dblScaleX);
          intTop = Math.round(parseFloat(objTagLink.getAttribute("top")) * dblScaleY);
          intRight = Math.round(parseFloat(objTagLink.getAttribute("right")) * dblScaleX);
          intBottom = Math.round(parseFloat(objTagLink.getAttribute("bottom")) * dblScaleY);
          intPage = parseInt(objTagLink.getAttribute("page"));
          strUrl = objTagLink.getAttribute("url");
          strHTML += "<a class='maplink' style='left:" + intLeft + "px;top:" + intTop + "px;";
          strHTML += " width:" + (intRight - intLeft) + "px;height:" + (intBottom - intTop) + "px;'";
          strHTML += " page='" + intPage + "'";
          if (strUrl == "") {
            strHTML += " onclick='return ViewerGoPhy(" + intPage + ");'";
            strHTML += " href='Page." + objRoman.getlogical(intPage) + "'";
            strHTML += " title='View page " + objRoman.getlogical(intPage) + "'";
          }
          else if (strUrl.substr(0, 7) == "mailto:") {
            strHTML += " href='" + strUrl + "'";
            strHTML += " title='Send email to " + strUrl.substr(7) + "'";
          }
          else {
            strHTML += " href='" + strUrl + "' target='_blank'";
            strHTML += " title='View " + strUrl + "'";
          }
          strHTML += "></a>";

        } //for
      }
    }
    objPubDoc.destructor();
    objPubDoc = null;
  }
  objPubAjax.destructor();
  objPubAjax = null;
  objMap.innerHTML = strHTML;
} //ViewerLoadMaps

function ViewerPageChange() {
	var objRoman = new clsRoman();
	objRoman.pages = objCurrentPublication.pages;
	objRoman.offset = objCurrentPublication.offset;
	objRoman.mappings = objCurrentPublication.mappings;
	if (intCurrentView == 1)
		strPage = objRoman.getlogical(intCurrentPage);
	else if (intCurrentPage == 0)
		strPage = objRoman.getlogical(1);
	else if (intCurrentPage >= objRoman.pages)
		strPage = objRoman.getlogical(intCurrentPage);
	else
		strPage = objRoman.getlogical(intCurrentPage) + " - " + objRoman.getlogical(intCurrentPage + 1);
	strPage += " of " + (objRoman.pages - objRoman.offset);
	WatermarkSetEmptyText("btn_goto", strPage);
	if (intCurrentView != 0)
		ViewerSaveForBookmark(intCurrentPage, intCurrentPublication, objCurrentPublication.title, strPage);
	ViewerEmailPageChange(intCurrentPage);
	ViewerPrintPageChange(intCurrentPage);
	ViewerBackgroundPrintPageChange(intCurrentPage);
	ViewerTrackPageChange(intCurrentPage);
}  //ViewerPageChange

//------------------------------------------------------
// Page turn
//------------------------------------------------------

function ViewerTurnOver(objDiv) {
	window.setTimeout("ViewerTurnAnimate('" + objDiv.id + "',1,6)", 1);
} //ViewerTurnOver

function ViewerTurnOut(objDiv) {
	window.setTimeout("ViewerTurnAnimate('" + objDiv.id + "',-1,6)", 1);
} //ViewerTurnOut

function ViewerTurnAnimate(strId, intDirection, intFrames) {
	var objDiv = document.getElementById(strId);
	var intFrame = parseInt(objDiv.getAttribute("frame"));
	if (((intFrame != 0) && (intDirection == -1)) || ((intFrame < intFrames) && (intDirection == 1))) {
		intFrame = intFrame + intDirection;
		objDiv.setAttribute("frame", intFrame);
		objDiv.style.backgroundPosition = (-(intFrame - 1) * 37) + "px bottom";
		window.setTimeout("ViewerTurnAnimate('" + objDiv.id + "'," + intDirection + ",6)", (intDirection == 1) ? 1 : 50);
	}
} //ViewerTurnAnimate

//------------------------------------------------------
// Zoom in / out
//------------------------------------------------------

function ViewerZoomIn(objEvent) {
	if (objEvent == null)
		objEvent = window.event;
	if ((!blnFullScreen) && (intCurrentView != 0)) {
		blnFullScreen = true;
		intDragStartX = objEvent.clientX;
		intDragStartY = objEvent.clientY;
		var objFull = document.getElementById("id_fullsize");
		var objLeft = document.getElementById("id_fullleft");
		var objRight = document.getElementById("id_fullright");
		objFull.style.height = ((objLeft.style.display != "none") ? objLeft.offsetHeight : objRight.offsetHeight) + "px";
		var objPage = (intCurrentView == 1) ? document.getElementById("id_oneview") : document.getElementById("id_twoview");
		var objRect = ViewerCalcRect(objPage);
		var intLeft = intDragStartX - Math.floor(((intDragStartX - objRect.left) * objFull.offsetWidth) / objPage.offsetWidth);
		var intTop = intDragStartY - Math.floor(((intDragStartY - objRect.top) * objFull.offsetHeight) / objPage.offsetHeight);
		objFull.style.left = intLeft + "px";
		objFull.style.top = intTop + "px";

		var objMain = document.getElementById("id_viewer");
		objMain.style.display = "none";
		ViewerResize();

		var objTooltip = document.getElementById("id_fulltooltip");
		objTooltip.style.left = (intDragStartX - objFull.offsetLeft) + "px";
		objTooltip.style.top = (intDragStartY - objFull.offsetTop) + "px";
	}
	return false;
}  //ViewerZoomIn

function ViewerZoomOut(objEvent) {
	if (objEvent == null)
		objEvent = event;
	if (blnFullScreen) {
		if (blnFullPostDrag)
			blnFullPostDrag = false;
		else {
			blnFullScreen = false;
			var objFull = document.getElementById("id_fullsize");
			objFull.style.left = "-2000px";
			objFull.style.top = "-2000px";
			var objMain = document.getElementById("id_viewer");
			objMain.style.display = "";
			ViewerResize();
	  }
	}
}  //zoomout

function ViewerZoomTooltipClose(objEvent) {
  if (objEvent == null)
    objEvent = event;
  var objTooltip = document.getElementById("id_fulltooltip");
  objTooltip.style.display = "none";
  objEvent.cancelBubble = true;
  objEvent.returnValue = false;
  try { objEvent.preventDefault(); } catch (e) { }
  return false;
} //ViewerZoomTooltipClose

function ViewerZoomDragStart(objEvent) {
	if (objEvent == null)
		objEvent = event;
	if (blnFullScreen) {
		intDragStartX = objEvent.clientX;
		intDragStartY = objEvent.clientY;
		document.body.style.cursor = "move";
		document.onmousemove = function(objEvent) { ViewerZoomDragMove(objEvent); };
		document.onmouseup = function(objEvent) { ViewerZoomDragEnd(objEvent); };
		document.body.onselectstart = function() { return false; };
		try { document.body.setCapture(true); } catch (e) { }
		objEvent.cancelBubble = true;
		objEvent.returnValue = false;
		try { objEvent.preventDefault(); } catch (e) { }
	}
	return false;
}  //ViewerZoomDragStart

function ViewerZoomDragMove(objEvent) {
	if (objEvent == null)
		objEvent = event;
	if (blnFullScreen) {
		var intX = intDragStartX - objEvent.clientX;
		var intY = intDragStartY - objEvent.clientY;
		if ((intX != 0) || (intY != 0)) {
			var objFull = document.getElementById("id_fullsize");
			objFull.style.left = (objFull.offsetLeft - intX) + "px";
			objFull.style.top = (objFull.offsetTop - intY) + "px";
			ViewerResize();
			intDragStartX = objEvent.clientX;
			intDragStartY = objEvent.clientY;
			blnFullPostDrag = true;
		}
	}
}  //ViewerZoomDragMove

function ViewerZoomWheel(objEvent) {
	if (objEvent == null)
		objEvent = event;
	if (blnFullScreen) {
		var intDelta = 0;
		if (objEvent.wheelDelta) { // IE/Opera.
			intDelta = objEvent.wheelDelta / 120;
			// In Opera 9, delta differs in sign as compared to IE.
			if (window.opera)
				intDelta = -intDelta;
		}
		else if (objEvent.detail) { /** Mozilla case. */
			//In Mozilla, sign of delta is different than in IE.
			//Also, delta is multiple of 3.
			intDelta = -objEvent.detail / 3;
		}
		//If delta is nonzero, handle it.
		// Basically, delta is now positive if wheel was scrolled up,
		// and negative, if wheel was scrolled down.
		if (intDelta != 0) {
			var objFull = document.getElementById("id_fullsize");
			objFull.style.top = (objFull.offsetTop - (intDelta * 30)) + "px";
			ViewerResize();
		}
		// Prevent default actions caused by mouse wheel.
		// That might be ugly, but we handle scrolls somehow anyway, so don't bother here..
		if (objEvent.preventDefault)
			objEvent.preventDefault();
		objEvent.returnValue = false;
	}
}  //ViewerZoomWheel

function ViewerZoomDragEnd(objEvent) {
	if (objEvent == null)
		objEvent = event;
	if (blnFullScreen) {
		try { document.body.releaseCapture(true); } catch (e) { };
		document.body.style.cursor = "";
		ViewerZoomDragMove(objEvent);
		document.onmousemove = null;
		document.onmouseup = null;
		document.body.onselectstart = null;
	}
	return false;
}  //ViewerZoomDragEnd

function ViewerCalcRect(objDiv) {
	var objRect = new clsRect();
	objRect.top = 0;
	objRect.left = 2;
	objPar = objDiv.parentNode;
	while ((objPar != null) && (objPar != document.body)) {
		//if ((objPar.tagName == "DIV") && (objPar.style.position == "relative")) {
		objRect.left += objPar.offsetLeft;
		objRect.top += objPar.offsetTop;
		//}
		objPar = objPar.parentNode;
	}
	objRect.right = objRect.left + objDiv.offsetWidth;
	objRect.bottom = objRect.bottom + objDiv.offsetHeight;
	return objRect;
}  //ViewerCalcRect

//------------------------------------------------------
// Search
//------------------------------------------------------

function ViewerSearchBegin() {
  var objEdt = document.getElementById("input_find");
  ViewerSearchGetResults(WatermarkGetValue(objEdt));
} //ViewerSearchBegin

function ViewerSearchFocus() {
	var objEdt = document.getElementById("input_find");
	objEdt.select();
	objEdt.focus();
} //ViewerSearchFocus

function ViewerSearchGetResults(strSearchTerm) {
	objSearchResults = null;
	var aryWordPages = null;
	var objWord = null;
	var strTerm = strSearchTerm.toLowerCase();
	if (strTerm != "") {
		if (intCurrentPublication == -1) {
			objSearchResults = new clsWord(strSearchTerm);
			objSearchResults.message = "Please open a publication first.";
		}
		else if (strTerm.indexOf(' ') != -1) {
			objSearchResults = new clsWord(strSearchTerm);
			objSearchResults.message = "Please limit your searches to single words only";
		}
		else if (ViewerInStopWordList(strTerm)) {
			objSearchResults = new clsWord(strSearchTerm);
			objSearchResults.message = "The word <span>" + encodeURIComponent(strTerm) + "</span> hasn't been indexed and therefore cannot be searched for.";
		}
		else {
			objSearchResults = new clsWord(strSearchTerm);
			objSearchResults.message = "The word <span>" + encodeURIComponent(strTerm) + "</span> was not found in <span>" + objCurrentPublication.title + "</span>";
			var blnFound = false;
			var intFtsuIndex = ViewerGetFtsuIndex(strTerm);
			if (objCurrentPublication.ftsu[intFtsuIndex] == null) {
				//Read ftsu file
				var objPubAjax = new clsAjax(null, false);
				var strResult = objPubAjax.get(objCurrentPublication.path + "Index/Ftsu_" + intFtsuIndex + ".xml");
				if (strResult != "") {
					var objPubDoc = new clsXmlDoc(strResult);
					if (objPubDoc.loaded) {
						var objTagIndex = objPubDoc.getElementsByTagName("index")[0];
						var strEntry = objPubDoc.getInnerText(objTagIndex);
						if (strEntry != "") {
							aryWordPages = strEntry.split("^");
							objCurrentPublication.ftsu[intFtsuIndex] = new Array();
							for (var intKey = 0; intKey < aryWordPages.length; intKey++)
								objCurrentPublication.ftsu[intFtsuIndex][intKey] = new clsWord(aryWordPages[intKey]);
						}
					}
					objPubDoc.destructor();
					objPubDoc = null;
				}
				objPubAjax.destructor();
				objPubAjax = null;
			}
			var aryWordList = objCurrentPublication.ftsu[intFtsuIndex];
			if (aryWordList != null) {
				var intBottom = 0;
				var intTop = aryWordList.length;
				var intSeek = -1;
				var intMiddle = 0;
				while (intSeek != intMiddle) {
					intMiddle = intSeek;
					intSeek = (intBottom + intTop) >> 1;
					objWord = aryWordList[intSeek];
					if (strTerm < objWord.word)
						intTop = intSeek;
					else if (strTerm > objWord.word)
						intBottom = intSeek;
					else {
						objSearchResults = objWord;
						break;
					}
				} //while
			}
		}
	}
	//Test if we found something
	if (objSearchResults != null)
		ViewerResults();
	return false;
} //ViewerSearchGetResults

function ViewerInStopWordList(strWord) {
	var blnFound = false;
	var objPub = objCurrentPublication;
	var intStopIndex = ViewerGetFtsuIndex(strWord);
	var aryWrds = objPub.stop[intStopIndex];
	if (aryWrds != null) {
		var intBottom = 0;
		var intTop = aryWrds.length;
		var intSeek = -1;
		var intMiddle = 0;
		while (intSeek != intMiddle) {
			intMiddle = intSeek;
			intSeek = (intBottom + intTop) >> 1;
			if (strWord < aryWrds[intSeek])
				intTop = intSeek;
			else if (strWord > aryWrds[intSeek])
				intBottom = intSeek;
			else {
				blnFound = true;
				break;
			}
		} //while
	}
	return blnFound;
} //ViewerInStopWordList

function ViewerGetFtsuIndex(strWord) {
	var intIndex;
	var intFirst = strWord.toUpperCase().charCodeAt(0);
	if (intFirst < 65)
		intIndex = 0;
	else if (intFirst > 90)
		intIndex = 27;
	else
		intIndex = intFirst - 64;
	return intIndex;
} //ViewerGetFtsuIndex

//------------------------------------------------------
// Results
//------------------------------------------------------

function ViewerResults() {
	if (objSearchResults != null) {
		var strLinks;
		var strText = "&nbsp;";
		if (objSearchResults.pages == null)
			strText = objSearchResults.message;
		else {
			var objRoman = new clsRoman();
			objRoman.pages = objCurrentPublication.pages;
			objRoman.offset = objCurrentPublication.offset;
			objRoman.mappings = objCurrentPublication.mappings;
			strText += "<table class='resultpage' cellpadding='0' cellspacing='0' border='0'>";
			for (var intRelPage = 0; intRelPage < objSearchResults.pages.length; intRelPage++) {
				var intPage = objSearchResults.pages[intRelPage];
				strText += '<tr onmouseover="TableCursorOver(this);" onmouseout="TableCursorOut(this);" onclick="ViewerGoPhy(' + intPage + ');" >';
				strText += '<td class="thumb">';
				strText += '<img src="' + objCurrentPublication.path + 'Pages/page_' + intPage + '_0.jpg"';
				strText += ' width="' + objCurrentPublication.sizes[0].width + '" height="' + objCurrentPublication.sizes[0].height + '" alt="" />';
				strText += '</td>';
				strText += '<td class="preview">';
				strText += '<p class="page">Page ' + objRoman.getlogical(intPage) + '</p>';
				strText += '<p>' + ViewerGetPageText(intPage) + '</p>';
				strText += '</td>';
				strText += '</tr>';
			} //for
			strText += "</table>";
		}
		var objDiv = document.getElementById("id_results");
		objDiv.innerHTML = strText;
	}
	return false;
} //ViewerResults

function ViewerGetPageText(intPage) {
	var strText = "";

	var strPageText = "";
	var objPubAjax = new clsAjax(null, false);
	var strResult = objPubAjax.get(objCurrentPublication.path + "Index/Page_" + intPage + ".xml");
	if (strResult != "") {
		var objPubDoc = new clsXmlDoc(strResult);
		if (objPubDoc.loaded)
			strPageText = objPubDoc.getInnerText(objPubDoc.getElementsByTagName("index")[0]);
		objPubDoc.destructor();
		objPubDoc = null;
	}
	objPubAjax.destructor();
	objPubAjax = null;

	var strReg = eval("/" + objSearchResults.word + "/i");
	var intPreviewLimit = 120;
	var intFirst = strPageText.search(strReg) - (intPreviewLimit >> 1);
	if (intFirst < 0)
		intFirst = 0;
	var intLast = intFirst + intPreviewLimit;
	if (intLast > strPageText.length) {
		intLast = strPageText.length;
		intFirst = (intLast > intPreviewLimit) ? intLast - intPreviewLimit : 0;
	}
	while ((intFirst > 0) && (strPageText.charAt(intFirst - 1) != ' '))
		intFirst--;
	while ((intLast < strPageText.length) && (strPageText.charAt(intLast) != ' '))
		intLast++;
	
	var strPrefix = (intFirst != 0) ? "..." : "";
	var strPostfix = (intLast != strPageText.length) ? "..." : "";
	strPageText = strPageText.substr(intFirst, intLast - intFirst);

	strReg = eval("/(" + encodeURIComponent(objSearchResults.word) + ")/gi");
	strText += "<p>" + strPrefix + strPageText.replace(strReg, "<span>$1</span>") + strPostfix + "</p>";

	return strText;
} //ViewerGetPageText

//------------------------------------------------------
// Passive Email screen
//------------------------------------------------------

function ViewerEmailPageChange(intCurrentPage) {
	var strPublicationPath = objCurrentPublication.path;
	var intPagesPdf = objCurrentPublication.pages;
	if (intCurrentView != 0) {
		objLeft = document.getElementById("id_email_left");
		if (objLeft != null) {
			objRight = document.getElementById("id_email_right");
			objLeft.src = strPublicationPath + "Pages/page_" + intCurrentPage + "_1.jpg";
			objRight.src = strPublicationPath + "Pages/page_" + (intCurrentPage + 1) + "_1.jpg";
			objLeft.style.visibility = ((intCurrentView != 0) && (intCurrentPage > 0)) ? "visible" : "hidden";
			objRight.style.visibility = ((intCurrentView == 2) && (intCurrentPage < intPagesPdf)) ? "visible" : "hidden";
		}
	}
	intEmailPage = intCurrentPage;
	intEmailMode = intCurrentView;
	intEmailPublication = intCurrentPublication;
	ViewerEmailSetSpaceLeft();
} //ViewerEmailPageChange

function ViewerEmailKeyPress(objEvent) {
	var blnAllow = true;
	if (objEvent == null)
		objEvent = event;
	//window.status = "Key: " + objEvent.keyCode;
	intSpace = ViewerEmailSetSpaceLeft();
	if (intSpace <= 0) {
		objEvent.cancelBubble = true;
		blnAllow = false;
	}
	return blnAllow;
} //functon

function ViewerEmailSetSpaceLeft() {
	var strUrl = ViewerEmailMailUrl();
	var intSpace = 1000 - strUrl.length;
	var objMail = document.getElementById("id_email_space");
	if (objMail != null)
		objMail.innerHTML = intSpace;
	return intSpace;
} //ViewerEmailSetSpaceLeft

function ViewerEmailSend() {
	var objAdr = document.getElementById("id_email_friend");
	var objMsg = document.getElementById("id_email_message");
	var strError = ViewerValidateEmail(objAdr.value);
	if ((strError == "") && (objMsg.value == "")) {
		strError = "What message would you like to convey to your friend?";
		objMsg.focus();
	}
	if (strError != "")
		alert(strError);
	else {
		var strUrl = ViewerEmailMailUrl();
		window.open(strUrl,"_self");
	}
} //ViewerEmailSend

function ViewerEmailMailUrl() {
	var strUrl = "";
	var objAdr = document.getElementById("id_email_friend");
  var objMsg = document.getElementById("id_email_message");
  if ((objAdr != null) && (objMsg != null)) {
  	var strShareRoot = document.location.href;
  	var intSlash = strShareRoot.lastIndexOf("/");
  	var strWebRoot = strShareRoot.substr(0, intSlash);
  	var strLink = "";
  	if (intEmailPublication == -1)
  		strLink += strWebRoot + "/default.htm#p=" + intEmailPage + "&v=" + intEmailMode;
  	else
  		strLink += strWebRoot + "/default.htm#p=" + intEmailPage + "&c=" + intEmailPublication + "&v=" + intEmailMode;
  	strUrl = "mailto:" + objAdr.value;
  	strUrl += "?subject=" + escape(strProjectTitle);
  	strUrl += "&body=" + escape(objMsg.value) + "%0D%0A%0D%0A" + escape(strLink);
  }
	return strUrl;
} //ViewerEmailMailUrl

function ViewerValidateEmail(strMail) {
	var strError = "";
	if (strMail == "")
		strError = "Please specify the email address\nof the friend that you wish to\nsend a link to this page";
	else {
		var objEmailFilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
		if (!objEmailFilter.test(strMail))
			strError = strMail + " is incorrectly formatted for a email address";
	}
	return strError;
} //ViewerValidateEmail

//------------------------------------------------------
// Page printing
//------------------------------------------------------

function ViewerBackgroundPrintPageChange() {
	if (intCurrentView != 0) {
		var intLeft = intCurrentPage;
		var intRight = ((intCurrentView == 2) && (intCurrentPage < objCurrentPublication.pages)) ? intCurrentPage + 1 : intCurrentPage;
		intLeft = (intLeft == 0) ? intRight : intLeft;
		ViewerBackgroundPrintSetPages(intLeft, intRight, objCurrentPublication.path);
	}
} //ViewerBackgroundPrintPageChange

function ViewerBackgroundPrintSetPages(intFrom, intTo, strPubPath) {
	objDiv = document.getElementById("printer");
	while (objDiv.firstChild != null)
		objDiv.removeChild(objDiv.firstChild);
	for (var intPage = intFrom; intPage <= intTo; intPage++) {
		var objImg = document.createElement("IMG");
		objImg.src = strPubPath + "Pages/page_" + intPage + "_" + intA4Size + ".jpg";
		objImg.alt = objImg.src;
		objImg.className = (intPage == intTo) ? "" : "followed";
		objDiv.appendChild(objImg);
	} //for
} //ViewerBackgroundPrintSetPages

//------------------------------------------------------
// Print
//------------------------------------------------------

function ViewerPrintRange() {
	var strPublicationPath = objCurrentPublication.path;
	var strPublicationTitle = objCurrentPublication.title;
	var intPagesPdf = objCurrentPublication.pages;
	var objRoman = new clsRoman();
	objRoman.pages = intPagesPdf;
	objRoman.offset = objCurrentPublication.offset;
	objRoman.mappings = objCurrentPublication.mappings;
	var strError = "Page range must be between " + objRoman.getlogical(1) + " and " + objRoman.getlogical(intPagesPdf);
	var objFrom = document.getElementById("id_print_from");
	var strFrom = encodeURIComponent(objFrom.value);
	var intFrom = objRoman.getphysical(strFrom);
	var objTo = document.getElementById("id_print_to");
	var strTo = encodeURIComponent(objTo.value);
	var intTo = objRoman.getphysical(strTo);
	if (intFrom == 0) {
		alert(strError);
		objFrom.focus();
	}
	else if (intTo == 0) {
		alert(strError);
		objTo.focus();
	}
	else if (intFrom > intTo) {
		alert("The first page in the range must come before the last page in the range.");
		objFrom.focus();
	}
	else if ((document.all) && (window.top == window)) {
		ViewerBackgroundPrintSetPages(intFrom, intTo, strPublicationPath);
		var objPrn = document.getElementById("tbl_print");
		var objCan = document.getElementById("tbl_cancel");
		objPrn.style.display = "none";
		objCan.style.display = "";
		strOldTitle = document.title;
		var strPage = (intFrom == intTo) ? " - Page " + strFrom : " - Pages " + strFrom + " to " + strTo;
		document.title = strPublicationTitle + strPage;
		window.onafterprint = function() { ViewerPrintCancel(); };
		window.setTimeout("ViewerPrintBegin()", 1000);
	}
	else {
		var intW = 200;
		var intH = 70;
		var intX = (screen.availWidth - intW) >> 1;
		var intY = (screen.availHeight - intH) >> 1;
		var objWindow = window.open(
			"print.htm?c=" + intCurrentPublication + "&f=" + intFrom + "&l=" + intTo + "&pf=" + strFrom + "&pl=" + strTo +
			"&p=" + encodeURI(strPublicationPath) + "&t=" + encodeURI(strPublicationTitle),
			"_print",
			"left=" + intX + ",top=" + intY + ",screenX=0,screenY=0,scrollbars=0,status=no,width=" + intW + ",height=" + intH
			);
		objWindow.focus();
	}
} //ViewerPrintRange

function ViewerPrintBegin() {
	window.print();
} //ViewerPrintBegin

function ViewerPrintCancel() {
	document.title = strOldTitle;
	window.onafterprint = null;
	ViewerPrintPageChange();
	ViewerBackgroundPrintPageChange();
	var objPrn = document.getElementById("tbl_print");
	var objCan = document.getElementById("tbl_cancel");
	objPrn.style.display = "";
	objCan.style.display = "none";
} //ViewerPrintCancel()

function ViewerPrintPageChange() {
	if (intCurrentView != 0) {
		var intPagesPdf = objCurrentPublication.pages;
		var intLeft = intCurrentPage;
		var intRight = ((intCurrentView == 2) && (intCurrentPage < intPagesPdf)) ? intCurrentPage + 1 : intCurrentPage;
		intLeft = (intLeft == 0) ? intRight : intLeft;
		var objRoman = new clsRoman();
		objRoman.pages = intPagesPdf;
		objRoman.offset = objCurrentPublication.offset;
		objRoman.mappings = objCurrentPublication.mappings;
		var objFrom = document.getElementById("id_print_from");
		objFrom.value = objRoman.getlogical(intLeft);
		var objTo = document.getElementById("id_print_to");
		objTo.value = objRoman.getlogical(intRight);
	}
} //ViewerPrintPageChange

function ViewerPrintOnLoad() {
	ControlsOnLoad();
	var intFrom = 0;
	var intTo = 0;
	var strFrom = "";
	var strTo = "";
	var strPubPath = "";
	var strTitle = "";
	var strUrl = document.location.href;
	var intParam = strUrl.indexOf("?");
	if (intParam != -1) {
		var aryParam = strUrl.substr(intParam + 1).split("&");
		var aryItem = null;
		for (var intIndex = 0; intIndex < aryParam.length; intIndex++) {
			aryItem = aryParam[intIndex].split("=");
			switch (aryItem[0]) {
				case "c": intCurrentPublication = parseInt(aryItem[1]); break;
				case "f": intFrom = parseInt(aryItem[1]); break;
				case "l": intTo = parseInt(aryItem[1]); break;
				case "pf": strFrom = aryItem[1]; break;
				case "pl": strTo = aryItem[1]; break;
				case "p": strPubPath = decodeURI(aryItem[1]); break;
				case "t": strTitle = decodeURI(aryItem[1]); break;
			} //switch
		} //for
		document.title = strTitle + ((intFrom == intTo) ? " - Page " + strFrom : " - Pages " + strFrom + " to " + strTo);
		ViewerBackgroundPrintSetPages(intFrom, intTo, strPubPath);
		window.print();
		var objBtn = document.getElementById("id_close");
		objBtn.onclick = function() { window.close(); };
		window.close();
		setTimeout("try { window.close(); } catch(e) {}", 1000);
	}
} //ViewerPrintOnLoad

//------------------------------------------------------
// Bookmark functions
//------------------------------------------------------

function ViewerSaveForBookmark(intPage, intPublication, strPub, strPage) {
	blnViewerInBookmark = true;
	//document.title = strPub + " - Page " + strPage;
	var strUrl = document.location.href;
	var strToken = "#p=" + intPage + "&c=" + intPublication + "&v=" + intCurrentView;
	var intToken = strUrl.indexOf("#");
	if (intToken == -1)
		strViewerLastBookmark = strUrl + strToken;
	else
		strViewerLastBookmark = strUrl.substr(0, intToken) + strToken;
	document.location.href = strViewerLastBookmark;
	window.setTimeout("ViewerCheckForBookmark()", BOOKMARK_PERIOD);
	blnViewerInBookmark = false;
} //ViewerSaveForBookmark

function ViewerCheckForBookmark() {
	if (!blnViewerInBookmark) {
		if (strViewerLastBookmark != document.location.href)
			ViewerRestoreFromBookmark();
		else
			window.setTimeout("ViewerCheckForBookmark()", BOOKMARK_PERIOD);
	}
} //ViewerCheckForBookmark

function ViewerRestoreFromBookmark() {
	var strUrl = document.location.href;
	var intToken = strUrl.indexOf("#p=");
	if (intToken != -1) {
		var strPage = strUrl.substr(intToken + 3);
		intToken = strPage.indexOf("&c=");
		if (intToken != -1) {
			var intPage = parseInt(strPage.substr(0, intToken));
			strPage = strPage.substr(intToken + 3);
			intToken = strPage.indexOf("&v=");
			if (intToken != -1) {
				var intPub = parseInt(strPage.substr(0, intToken));
				if ((intPub != intCurrentPublication) && (intPub < aryPublications.length))
					ViewerPublicationSet(intPub);
				var intViewMode = parseInt(strPage.substr(intToken + 3));
				if ((intViewMode != intCurrentView) && ((intViewMode == 1) || (intViewMode == 2)))
					ViewerSwitchView(intViewMode);
				if (intPage != intCurrentPage)
					ViewerGoPhy(intPage);
				window.setTimeout("ViewerResize()", 500);
			}
		}
	}
} //ViewerRestoreFromBookmark

function ViewerBookmarkSite(strTitle, strUrl) {
	var strError = "";
	try {
		if (window.sidebar) // firefox
			window.sidebar.addPanel(strTitle, strUrl, "");
		else if ((window.opera) && (window.print)) { // opera
			var objAnc = document.createElement('A');
			objAnc.setAttribute('href', strUrl);
			objAnc.setAttribute('title', strTitle);
			objAnc.setAttribute('rel', 'sidebar');
			objAnc.click();
		}
		else if (document.all) // ie
			window.external.AddFavorite(strUrl, strTitle);
	}
	catch (e) {
		strError = e.description;
	}
	return strError;
} //ViewerBookmarkSite

//------------------------------------------------------
// Tracking
//------------------------------------------------------

function ViewerTrackPageChange(intCurrentPage) {
	if ((typeof (_gat) != "undefined") && (intCurrentView != 0)) {
		var strPublicationPath = objCurrentPublication.path;
		var strPublicationTitle = objCurrentPublication.title;
		var intPagesPdf = objCurrentPublication.pages;
		var intLeft = intCurrentPage;
		var intRight = ((intCurrentView == 2) && (intCurrentPage < intPagesPdf)) ? intCurrentPage + 1 : 0;
		var objRoman = new clsRoman();
		objRoman.pages = intPagesPdf;
		objRoman.offset = objCurrentPublication.offset;
		objRoman.mappings = objCurrentPublication.mappings;
		var objTracker = _gat._getTracker(strGoogleTrackerID);
		if (intLeft != 0)
			objTracker._trackPageview("/" + strPublicationTitle + "/Page " + objRoman.getlogical(intLeft));
		if (intRight != 0)
			objTracker._trackPageview("/" + strPublicationTitle + "/Page " + objRoman.getlogical(intRight));
	}
} //ViewerTrackPageChange

function ViewerTrackEvent(strEventName) {
	if (typeof (_gat) != "undefined") {
		var objTracker = _gat._getTracker(strGoogleTrackerID);
		objTracker._trackPageview("/" + objCurrentPublication.title + "/" + strEventName);
	}
} //ViewerTrackEvent


