// 24 Dec 2002: Modified ce_OnClickLink()and ce_ChgLinks() to respond to shift key
//					 when changing images that have an associated link.
// 15 Sep 2002: Created ce_CleanUrl()and set cookies if ce_nCanEdit = -1.
//					 Created application specific functions section.
// 14 Sep 2002: Modified ce_CanEditPage() to observe folders.
// 12 Sep 2002: Modified ce_PushRepostUrl() to conditionally use parent location.
//					 Modified ce_theToolBar() to force link to setupmenu.asp in top window.
//  2 Sep 2002: Modified ce_CanEditPage(),ce_GetThisUrl(),ce_GetThisUrlFile()
// 20 Aug 2002: Use ce_AdminURL() in toolbar construction. ce_ChgLinks() sets
//					 double click event for images with A tag parent node.
// 23 Jul 2002: Implemented webshot toolbar.
// 10 Jul 2002: Created ce_CanEditDbase(), further modified ce_OnSubmitModifyOnline().
//  1 Jul 2002: Modified ce_OnSubmitModifyOnline()

var ce_nToolBarPos		= 1; //1 top, 2, bottom
var ce_sURL					= "";
var ce_TheForm				= "ModifyOnline";
var ce_nCanEdit			= 0;
var ce_sSiteRootURL 		= "";
var ce_sConteditMethod 	= "";
var ce_sApplAdminURL 	= "/admin";

// These string assignments must match those defined in GlobVars.inc
var svnLogon				= "ceLogon"
var svnSession				= "ceSession"
var svnRepost				= "ceRepostUrls"

var svKeyID					= "ID"
var svKeyUserName			= "UserName"
var svKeyUserPages		= "UserPages"
var svKeyUserGroups		= "UserGroups"
var svKeyAdminLevel		= "AdminLevel"

var svKeyApplAdminURL	= "ApplAdminURL"
var svKeyApplDefPage		= "ApplDefPage"
var svnKeyCeMethod		= "ceMethod"
var svKeyIsapiURL			= "IsapiURL"
var svKeySiteRootURL		= "SiteRootURL"

function ce_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function ce_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=ce_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function ce_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=ce_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function ce_swapImage() { //v3.0
  var i,j=0,x,a=ce_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=ce_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ce_Prm(sName, sValue, bStart) {
	var s = (bStart) ? "?" : "&";
	return (s + sName + "=" + sValue.toString());
}
function ce_StrTokIdx(str, sDelim, nIndex) {
	str = new String(str);
	var sOut = null, nIdx1, nIdx2 = 0, nIdx3 = 0;
	var nLenTok = sDelim.length;
	for(var i = 0; nIdx2 >= 0 && i <= nIndex; ++i)
		{
		nIdx1 = nIdx3;
		nIdx2 = str.indexOf(sDelim, nIdx1);
		nIdx3 = nIdx2 + nLenTok;
		}
	if((i - 1) == nIndex)
		{
		if(nIdx2 == -1)
			sOut = str.substr(nIdx1);
		else
			sOut = str.substring(nIdx1,nIdx2);
		}
	return sOut;
}
function ce_getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function ce_GetCookieKeyVal (str, key) {
	var s,s1,i;
	var i = parseInt(key);
	if(isNaN(i))
		{
		key = key.toString();
		key = key.toLowerCase();
		for(i = 0; (s = ce_StrTokIdx(str,"&",i)) && i < 100; ++i)
			{
			s1 = ce_StrTokIdx(s,"=",0);
			if(s1 && s1.toLowerCase() == key)
				return ce_StrTokIdx(s,"=",1);
			}
		return null;
		}
	else
		return ce_StrTokIdx(str,"&",i);
}
function ce_GetCookie (name, key) {
	if(name)
		{
		var arg = name + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		while (i < clen)
			{
			var j = i + alen;
			if (document.cookie.substring(i, j) == arg)
				{
				var sVal = ce_getCookieVal (j);
				if(key && sVal.indexOf("=") >= 0) // Has keys
					sVal = ce_GetCookieKeyVal(sVal,key);
				return sVal;
				}
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break; 
			}
		return null;
		}
	else
		return document.cookie;
}

function ce_SetCookie (name,value,expires,path,domain,secure) {

	var n = parseInt(expires);
	if(! isNaN(n))
		{
		expires = new Date ();
		expires.setTime(expires.getTime() + (n * 3600 * 1000)); // n hrs from now 
		}

	if(! (path))
		path = "/";
	else if(path == "")
		path = null;

	document.cookie = name + "=" + escape (value.toString()) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

/* Functions to trim strings (fn_Common.js) */
function ce_Ltrim(s, c) {
	var c1 = (c) ? c : " ";
	var len = c1.length;
	for(i = 0; i < s.length; ++i)
		if(s.substr(i,len) != c1)
			break;
	return s.substr(i);
}

function ce_Rtrim(s, c) {
	var c1 = (c) ? c : " ";
	var len = c1.length;
	for(i = s.length - 1; i >= 0; --i)
		if(s.substr(i,len) != c1)
			break;
	return s.substr(0,i + 1);
}

function ce_Trim(s, c) {
	return ce_Ltrim(ce_Rtrim(s, c), c);
}

function ce_AdminURL(sFile) { //v3.0
	return ce_Rtrim(ce_sApplAdminURL.toString(),"/") + "/" + ce_Ltrim(sFile,"/");
}
	
function ce_BuildModuleURL(sModule) {
	return ce_AdminURL(sModule);
}

function ce_DocumentURL() { //v3.0
	var sUrl = document.location.href;
	if(sUrl.length > 0 && sUrl.charAt(sUrl.length - 1) == "/")
		{
		var coll = document.forms(ce_TheForm);
		if(coll.length > 0)
			{
			if(coll(0).Url)
				sUrl = coll(0).Url.value;
			else if(coll.Url)
				sUrl = coll.Url.value;
			}
		}
	return sUrl;
}

function ce_FmtUrlEditLink(Mode, Location, href, sName, sTarg, Index) { //v3.0
	var sPage = Location.toString();
	var sFrame = window.location;
	sFrame = sFrame.toString();
	return ce_AdminURL("EditHyperLink.asp") + ce_Prm("edit",Mode,true) + ce_Prm("page",sPage) + ce_Prm("href",href) + ce_Prm("Name",escape(sName)) + ce_Prm("target",sTarg) + ce_Prm("index",Index) + ce_Prm("frame",sFrame);
}

function ce_FmtUrlEditImage(Mode, Location, href, Index) { //v3.0
	var sPage = Location.toString();
	var sFrame = window.location;
	sFrame = sFrame.toString();
	return ce_AdminURL("EditImageLink.asp") + ce_Prm("edit",Mode,true) + ce_Prm("page",sPage) + ce_Prm("index",Index) + ce_Prm("href",href) + ce_Prm("frame",sFrame);
}

function ce_FmtUrlContentUpload(Location, href) { //v3.0
	var sPage = Location.toString();
	var sFrame = window.location;
	sFrame = sFrame.toString();
	return ce_AdminURL("UploadContent.asp") + ce_Prm("page",sPage,true) + ce_Prm("href",href) + ce_Prm("frame",sFrame);
}

function ce_StrCmp(sRef, sCmp) {
	var s1 = sRef.toString();
	var s2 = sCmp.toString();
	s1 = s1.toLowerCase();
	s2 = s2.toLowerCase();
	return (s1 == s2.substr(0,s1.length));
}

function ce_ScriptedElement(oEl) {
	var sId = oEl.id;
	return (ce_StrCmp("clientadded",sId) || ce_StrCmp("serveradded",sId));
}

function ce_OnClickLink() { //v3.0
	var Idx = -1, sThisInnerText = this.innerText, sThisHref = this.href;
	var oHL;
	
	if (window.event.shiftKey)	// Added 24/12/2002
		{
		//window.event.cancelBubble = true;
		window.event.returnValue = false;
		return; 
		}

	//alert(sThisHref + "\nNo of hyperlinks=" + document.links.length);
	for(var i = 0, n = 0; i < document.links.length; ++i)
		{
		oHL = document.links[i];
		if(oHL.sourceIndex == this.sourceIndex)
			{
			Idx = n;
			break;
			}
		if(! ce_ScriptedElement(oHL))
			{
			if(oHL.innerText == sThisInnerText && oHL.href == sThisHref)
				n++;
			}
		}
	
	var s = sThisHref.toString();
	if(s.length == 0)
		{
		s = this.title;
		s = s.toString();
		i = s.indexOf("http:");
		if(i > 0)
			s = s.substr(i);
			
		i = s.indexOf(" ");
		if(i > 0)
			s = s.substring(0,i);
		}
	sThisHref = s;
	ce_PushRepostUrl();
	window.location = ce_FmtUrlEditLink(0, ce_DocumentURL(), sThisHref, sThisInnerText, this.target, Idx);
	return false;
}

function ce_OnClickImage() { //v3.0
	var Idx = -1, sThisHref = this.href;
	sThisHref = sThisHref.toString();
	for(var i = 0, n = 0; i < document.images.length; ++i)
		{
		oImg = document.images[i];
		if(oImg.sourceIndex == this.sourceIndex)
			{
			Idx = n;
			break;
			}
		if(! ce_ScriptedElement(oImg))
			{
			if(oImg.href == sThisHref)
				n++;
			}
		}
	ce_PushRepostUrl();
	window.location = ce_FmtUrlEditImage(0, ce_DocumentURL(), sThisHref, Idx);
	return false;
}

function ce_OnClickContentUpload(sHref) { //v3.0
	sHref = sHref.toString();
	window.location = ce_FmtUrlContentUpload(window.parent.location, sHref);
	return false;
}

// 10 Jul 2002: Modified form identify method again!!
//  1 Jul 2002: Modified form identify method
// Called by ModifyOnline form submit button	to set the value of the hidden input 
// object named IDX to the index number of the form in the collection of forms.
function ce_OnSubmitModifyOnline(theFormElement) { //v3.0
	var nIndex = -1;
	var nRet = nIndex;
	var coll = document.forms;
	if(coll != null && coll.length != null)
		{
		for(var i = 0; i < coll.length; ++i)
			{
			if(coll.item(i).name == ce_TheForm)
				{
				nIndex++;	//Increment the counter for the required form
				var collel = coll[i].elements;
				if(collel)
					{
					// Check if form element is part of form collection.
					var nStartIdx = collel[0].sourceIndex - 10; // Relaxes check
					var nEndIdx = collel[collel.length - 1].sourceIndex + 10; // Relaxes check
					if(theFormElement.sourceIndex >= nStartIdx && theFormElement.sourceIndex <= nEndIdx)
						{
						// The form is specified in collection by index counter nIndex
						// Now set the value of form element IDX to nIndex
						for(var n = 0; n < collel.length; ++n)
							{
							if(collel[n].name.toUpperCase() == "IDX")
								{
								collel[n].value = nIndex.toString();
								//alert(collel[n].name + "=" + collel[n].value);
								//return true;
								break;
								}
							}
						nRet = nIndex;
						}
					}
				}
			}
		}
	return nRet;
}

function ce_ChgLinks(theCheckBox, bChecked) { //v3.0
	if(theCheckBox)
		{
		var i,e,curs,title;
		var nSectOrd = ce_GetSectionOrdinal(theCheckBox);
		var nStartSourceIndex = ce_GetSourceIndex("ceStartMark", nSectOrd);
		var nEndSourceIndex   = ce_GetSourceIndex("ceEndMark",   nSectOrd);
		var sKey = ce_GetThisUrlFile() + nSectOrd.toString();
		//alert("sKey=" + sKey + ", nSectOrd=" + nSectOrd + ", nStartSourceIndex=" + nStartSourceIndex + ", nEndSourceIndex=" + nEndSourceIndex);
		if(bChecked == null)
			{
			bChecked = parseInt(ce_GetCookie(sKey));	// Get checked status from cookie
			bChecked = isNaN(bChecked) || bChecked == 0 ? false : true;
			theCheckBox.checked = bChecked;
			}
		else
			ce_SetCookie(sKey, bChecked ? 1 : 0);		// Save checked status to cookie

		for(i = 0; i < document.images.length; ++i)
			{
			var oImg = document.images[i];
			if(oImg.name && (oImg.name == "ce_toolbar" || oImg.name == "help"))
				continue;
			if(oImg.sourceIndex > nStartSourceIndex && oImg.sourceIndex < nEndSourceIndex)
				{
				if(bChecked)
					{
					oImg.onclicksave = new Object(oImg.onclick);
					oImg.ondblclicksave = new Object(oImg.ondblclick);
					oImg.cursorsave = new String(oImg.style.cursor);
					oImg.titlesave = new String(oImg.title);
					if(! ce_ScriptedElement(oImg))
						{
						oImg.style.cursor = "hand";
						if(oImg.parentNode.tagName == "A")
							{
							oImg.title = "Click to change link URL\r\nShift + click to change image";
							oImg.onclick = ce_OnClickImage;	// Added 24/12/2002, changed title attribute
							oImg.ondblclick = ce_OnClickImage;
							}
						else
							{
							oImg.title = "Click to change image";
							oImg.onclick = ce_OnClickImage;
							}
						}
					else
						{
						oImg.style.cursor = "not-allowed";
						oImg.title = "Dynamically generated";
						}
					}
				else
					{
					if(oImg.ondblclicksave)
						oImg.ondblclick = oImg.ondblclicksave;
					if(oImg.onclicksave)
						oImg.onclick = oImg.onclicksave;
					if(oImg.cursorsave)
						oImg.style.cursor = oImg.cursorsave;
					if(oImg.titlesave)
						oImg.title = oImg.titlesave;
					}
				}
			}

		for(i = 0; i < document.links.length; ++i)
			{
			var oLink = document.links[i];
			if(oLink.sourceIndex > nStartSourceIndex && oLink.sourceIndex < nEndSourceIndex)
				{
				if(bChecked)
					{
					oLink.onclicksave = new Object(oLink.onclick);
					oLink.cursorsave = new String(oLink.style.cursor);
					oLink.titlesave = new String(oLink.title);
					if(! ce_ScriptedElement(oLink))
						{
						oLink.onclick = ce_OnClickLink;
						oLink.title = "Click to change link URL";
						}
					else
						{
						oLink.style.cursor = "not-allowed";
						oLink.title = "Dynamically generated";
						}
					}
				else
					{
					if(oLink.onclicksave)
						oLink.onclick = oLink.onclicksave;
					if(oLink.cursorsave)
						oLink.style.cursor = oLink.cursorsave;
					if(oLink.titlesave)
						oLink.title = oLink.titlesave;
					}
				}
			}
		}
}

function ce_ChgLinksOnClick(theCheckBox) { //v3.0
	ce_ChgLinks(theCheckBox, theCheckBox.checked)
}

function ce_GetSectionOrdinal(theFormElement) { //v3.0
	var nRet = -1;
	var nIndex = -1;
	var coll = document.forms;
	if(coll != null && coll.length != null)
		{
		for(var i = 0; i < coll.length; ++i)
			{
			if(coll.item(i).name == ce_TheForm)
				{
				nIndex++;	//Increment the counter for the required form
				var collel = coll[i].elements;
				// Determine which form in the collection of forms, that the form element
				// passed in is inside.
				for(var n = 0; n < collel.length; ++n)
					if(theFormElement.sourceIndex == collel[n].sourceIndex)
						break;
				if(n < collel.length)
					{
					nRet = nIndex;
					break;
					}
				}
			}
		}
	return nRet;
}

function ce_GetSourceIndex(TagName, nOrdinal) { //v3.0
	var a = document.all.item(TagName);
	if (a != null)
		{
		if(a.length != null)
			{
			if(nOrdinal >= 0 && nOrdinal < a.length)
				return a(nOrdinal).sourceIndex;
			}
		else if(nOrdinal == 0)
			return a.sourceIndex;
		}

	return -1;
}

function ce_GetFormElement(nOrdinal, TagName) { //v3.0
	var coll = document.forms;
	if(coll != null && coll.length != null)
		{
		var nIndex = -1;
		var nIdxColl;
		for(var i = 0; i < coll.length; ++i)
			{
			if(coll.item(i).name == ce_TheForm)
				{
				nIndex++;	//Increment the counter for the required form
				nIdxColl = i;
				if(nOrdinal == nIndex)
					break;
				}
			}
		if(nOrdinal == nIndex || (nIndex >= 0 && nOrdinal < 0))
			{
			var collel = coll[nIdxColl].elements;
			if(collel != null && collel.length != null)
				{
				var sStr = TagName;
				sStr = sStr.toUpperCase();
				for(var n = 0; n < collel.length; ++n)
					{
					if(collel[n].name.toUpperCase() == sStr)
						{
						return collel[n];
						}
					}
				}
			}
		}
	return null;
}

// Created (15/9/2002)
function ce_CleanUrl(sPageUrl) {
	var sURL = sPageUrl!=null ? sPageUrl.toString() : document.location.href;
	var i = sURL.indexOf("//");
	if(i >= 0)
		sURL = sURL.substr(i);
	sURL = unescape(sURL);
	return sURL
}

// Calls ce_CleanUrl (15/9/2002)
// Added optional page URL parameter (2/9/2002)
function ce_GetThisUrl(sPageUrl) {
	var sURL = ce_CleanUrl(sPageUrl);
	if(sURL.length > 0 && sURL.charAt(sURL.length - 1) == "/")
		sURL = ce_CleanUrl(ce_GetCookie(svnSession, svKeyApplDefPage));
	return sURL
}

// Added optional page URL parameter (2/9/2002)
function ce_GetThisUrlFile(sPageUrl) {
	var sUrl = ce_GetThisUrl(sPageUrl);
	var i = sUrl.lastIndexOf("/");
	return (i >= 0) ? sUrl.substr(i + 1) : sUrl;
}

// Calls ce_CleanUrl (15/9/2002)
// Observes folders (14/9/2002)
// Added optional page URL parameter (2/9/2002)
function ce_CanEditPage(sPageUrl) {
	var nRet = 0;
	var nVal = ce_GetUserRights();
	if(nVal < 0)
		nRet = 1;
	else if(nVal > 0)
		{
		nRet = -1;
		var sPage = (sPageUrl!=null)?ce_CleanUrl(sPageUrl):ce_GetThisUrl(sPageUrl);
		var sSiteRootURL = ce_GetCookie(svnSession, svKeySiteRootURL);
		if(sSiteRootURL)
			{
			sPage = ce_Ltrim(sPage.substr(sSiteRootURL.length),"/");
			sPage = sPage.toLowerCase();
			var sUserPages = ce_GetUserPages();
			var s;
			for(var i = 0; nRet != 1 && (s = ce_StrTokIdx(sUserPages, ",", i)) && i < 1000; ++i)
				{
				s = s.toLowerCase();
				if(s == "<all>" || s == "*" || s == sPage)
					nRet = 1;
				else if(s == "./" && sPage.indexOf("/") < 0) // Page in root folder
					nRet = 1;
				else
					{
					if(s.charAt(s.length - 1) == "/" && s == sPage.substr(0, s.length))
						nRet = 1;	// Page is in folder
					}
				}
			}
		}
	return nRet;
}

function ce_CanEditDbase() {
	var nRet = 0;
	var nVal = ce_GetUserRights();
	if(nVal < 0)
		nRet = 1;
	else if(nVal > 0)
		{
		nRet = -1;
		var sCountry;
		try {
			sCountry = GetCountry();
		}
		catch(e) {
			sCountry = null;
		}
		if(sCountry)
			{
			var sUserGroups = ce_GetUserGroups();
			var s1,s2,s3;
			for(var i = 0; nRet != 1 && (s1 = ce_StrTokIdx(sUserGroups, ",", i)) && i < 200; ++i)
				{
				s1 = s1.toUpperCase()
				if(s1 == "<ALL>" )
					nRet = 1;
				else
					{
					s2 = ce_StrTokIdx(s1, "_", 0);
					s3 = ce_StrTokIdx(s1, "_", 1);
					if(s2 != null && s2 == "DB" && s3 != null && s3 == sCountry)
						nRet = 1;
					}
				}
			}
		}
	return nRet;
}

// These functions are called if content edit statements have been inserted into page
function ce_OnHelp() {
	window.open(ce_BuildModuleURL("webshot.chm"));
	return false;
}

function ce_WriteTlbarButton(sAction, sValue, sTitle, sName) {
	document.write("<td>");
	document.write("<input type=button value='" + sValue + "'");
	if(sName)
		document.write("id='" + sName + "' name='" + sName + "'");
	document.write(" style='cursor:hand'");
	document.write(" onclick='return " + sAction + "'");
	document.write(" title='" + sTitle + "'>");
	document.write("</td>");
	return true;
}

function ce_WriteTlbarImage(sAction, sIcon, sAlt, sName) {
	document.write("<input type=image src='" + ce_AdminURL("Images/" + sIcon) + "'");
	if(sName)
		document.write("id='" + sName + "' name='" + sName + "'");
	document.write(" style='cursor:hand' width='78' height='34'");
	document.write(" onclick='return " + sAction + "'");
	document.write(" alt='" + sAlt + "'>");
	return true;
}

function ce_WriteTlbarChkBox(sAction, sValue, sTitle, sName) {
	document.write("<table border='0' cellpadding='0' cellspacing='0'>"
		+ "<tr>"
		+ "<td><img src='" + ce_AdminURL("images/wsb_changelink.gif") + "' width='114' height='16'></td>"
		+ "</tr>"
		+ "<tr>"
		+ "<td>"
		+ "<table border='1' cellpadding='2' bordercolor='E49432' cellspacing='3' bgcolor='E49432'>"
		+ "<tr>"
		+ "<td bgcolor='#FFFFFF' align='left' width='100%'>"
		+ "<span class='text_small'> </span>"
		+ "<table border='0' cellpadding='2'>"
		+ "<tr>"
		+ "<td>"
		+ "<input type='checkbox'");
	if(sName)
		document.write("id='" + sName + "' name='" + sName + "'");
	document.write(" style='cursor:hand'");
	document.write(" onclick='" + sAction + "'");
	document.write(" title='" + sTitle + "'>");
	document.write("</td>"
		+ "<td><span class='text_small'>CHECK BOX, THEN CLICK<br>IMAGE/LINK TO CHANGE</span></td>"
		+ "</tr>"
		+ "</table>"
		+ "</td>"
		+ "</tr>"
		+ "</table>"
		+ "</td>"
		+ "</tr>"
		+ "</table>");
	return true;
}

function ce_WriteTlbarValue(sName, sValue) {
	document.write("<input type=hidden name='" + sName + "' value='" + sValue + "'>");
}
	
function ce_theToolBar(sID) {
	if(ce_nCanEdit == -1 || ce_nCanEdit == 1)
		{
		document.write("<link rel='stylesheet' href='" + ce_AdminURL("webshot.css") + "' type='text/css'>");
		if(ce_nToolBarPos != 1)
			ce_theToolBarExt(sID);
		document.write(
		"<table width='90%' border='5' cellspacing='0' cellpadding='0' align='center' bgcolor='#FFFFFF' bordercolor='E49432'>"
		+ "<tr>"
		+ "<td colspan='2' height='20'>"
		+ "<table width='100%' cellspacing='3' cellpadding='0' height='20' align='center' bgcolor='#FFFFFF'>"
		+ "<tr>"
		+ "<td bgcolor='#FFFFFF' valign='bottom' width='17%'>"
		+ "<div align='left'><a target=_top id='clientAdded' href='" + ce_AdminURL("setupmenu.asp") + "' onclick='ce_PushRepostUrl(1)' title='Go to Webshot setup menu page'><img style='border-style:none' src='" + ce_AdminURL("images/powered%20by%20webshot.gif") + "' width='84' height='42'></a></div>"
		+ "</td>"
		+ "<td bgcolor='#FFFFFF' width='57%'>"
		+ "<div align='left'><font face='Verdana' color='#0000ff' class='text_big_heading'>CONTENT EDITOR</font></div>"
		+ "</td>"
		+ "<td bgcolor='#FFFFFF' width='26%'>"

		+ "<div align='right'>"
		+ "<a target=_top id='clientAdded' href='" + ce_AdminURL("setupmenu.asp") + "' onclick='ce_PushRepostUrl(1)' title='Go to Webshot setup menu page' onMouseOut='ce_swapImgRestore()' onMouseOver='" + 'ce_swapImage("setupmenu","","' + ce_AdminURL("images/wsb_setup_on.gif") + '",1)' + "'>"
		+ "<img name='setupmenu' border='0' src='" + ce_AdminURL("images/wsb_setup.gif") + "' height='20' align='absmiddle'></a>"
		+ "<a id='clientAdded' href='" + ce_AdminURL("webshot.chm") + "' title='Opens Webshot online help in new window' target='_blank' onMouseOut='ce_swapImgRestore()' onMouseOver='" + 'ce_swapImage("help","","' + ce_AdminURL("images/wsb_help_on.gif") + '",1)' + "'>"
		+ "<img name='help' border='0' src='" + ce_AdminURL("images/wsb_help.gif") + "' height='20' align='absmiddle'></a>"
		+ "</div>"

		+ "</td>"
		+ "</tr>"
		+ "</table>"
		+ "</td>"
		+ "</tr>"
		+ "<tr>"
		+ "<td colspan='2'>"
		+ "<table width='100%' cellspacing='0' cellpadding='00' align='center' bgcolor='#FFFFFF'>"
		+ "<tr valign='top'>"
		+ "<td colspan='2'>"
		+ "<div align='left'></div>"
		+ "<table border='0' cellspacing='0' cellpadding='10' align='center' width='95%'>"
		+ "<tr>"
		+ "<td align='left' width='26%'>");
		
		if(ce_nCanEdit == -1)
			document.write("<STRONG><FONT color=red face=Verdana size=2>Sorry! You do not have access rights to edit this page</FONT></STRONG>");
		else
			{
			document.write("<form name='" + ce_TheForm + "' method='get' action='" + ce_BuildModuleURL("EditContent.asp") + "'>");
			ce_WriteTlbarValue("Url",ce_sURL);
			ce_WriteTlbarValue("Repost",ce_sURL);
			ce_WriteTlbarValue("Idx",0);
			ce_WriteTlbarValue("Root",ce_sSiteRootURL);
			ce_WriteTlbarValue("Method",ce_sConteditMethod);
			if(ce_nCanEdit == 1)
				ce_WriteTlbarImage("ce_OnClickTlbar1(this)", "wsb_editcontent.gif", "Enables this page content to be modified online");
			document.write("</td><td>");
			if(ce_nCanEdit == 1)
				ce_WriteTlbarChkBox("ce_ChgLinksOnClick(this)", "Change hyperlinks and images", "When checked, clicking on link navigates to the link edit page. Also allows image to be changed by clicking on image", "EditLink");
			document.write("</td><td>");
			document.write("</form>");

			var frm = document.frames;
			for (var i=0; i < frm.length; i++)
				frm(i).scrolling = "auto";
			}

		document.write("</td>"
		+ "</tr>"
		+ "</table>"
		+ "</td>"
		+ "</tr>"
		+ "</table>"
		+ "</td>"
		+ "</tr>"
		+ "</table>");
		if(ce_nToolBarPos == 1)
			ce_theToolBarExt(sID);
		}
}
	
function ce_theToolBarExt(sID) {
	if(ce_nCanEdit == -1 || ce_nCanEdit == 1)
		document.write("<div id='" + sID + "'></div>");
}

function ce_StartMarker() {
	var sID = "ceStartMark";
	if(ce_nToolBarPos == 1)
		ce_theToolBar(sID)
	else
		ce_theToolBarExt(sID)
}
	
function ce_EndMarker() {
	var sID = "ceEndMark";
	if(ce_nToolBarPos == 1)
		ce_theToolBarExt(sID)
	else
		ce_theToolBar(sID)
	if(ce_nCanEdit == 1)
		ce_ChgLinks(ce_GetFormElement(-1,"EditLink"));
}

// Toolbar item onclick functions
function ce_OnClickTlbar1(theFormElement) {
	var iIdx = ce_OnSubmitModifyOnline(theFormElement.parentNode);
	if(iIdx >= 0)
		{
		ce_PushRepostUrl(); //this url
		window.location = ce_BuildModuleURL("EditContent.asp") + ce_Prm("url",ce_sURL,true) + ce_Prm("Repost",ce_sURL) + ce_Prm("Idx",iIdx) + ce_Prm("Root", ce_sSiteRootURL) + ce_Prm("Method", ce_sConteditMethod);
		}
	return false;
}

function ce_PushRepostUrl(sUrl) {
	if(sUrl==null || sUrl.toString() == "0")
		sUrl = window.location.href;
	else if(sUrl.toString() == "1")
		sUrl = window.parent.location.href;
	var sRepostUrls = ce_GetCookie(svnRepost);
	if(sRepostUrls && sRepostUrls.length > 0)
		sRepostUrls = sUrl + "," + sRepostUrls;
	else
		sRepostUrls = sUrl;
	ce_SetCookie(svnRepost, sRepostUrls);
}

function ce_PopRepostUrl(nNumPop) {
	if(nNumPop==null)
		nNumPop = 1;
	var sUrl = null;
	var sRepostUrls = ce_GetCookie(svnRepost);
	if(sRepostUrls)
		{
		var i,s1,s2="";
		if(nNumPop < 0)
			sUrl = sRepostUrls;
		else
			{
			sUrl = "";
			for(i = 0; (s1 = ce_StrTokIdx(sRepostUrls,",",i)) && i < 100; ++i)
				{
				if(i < nNumPop)
					{
					if(sUrl.length > 0)
						sUrl += ",";
					sUrl += s1;
					}
				else
					{
					if(s2.length > 0)
						s2 += ",";
					s2 += s1;
					}
				}
			}
		ce_SetCookie(svnRepost, s2);
		}
	return sUrl;
}

function ce_ReadRepostUrl() {
	var sUrl = null;
	var sRepostUrls = ce_GetCookie(svnRepost);
	if(sRepostUrls)
		sUrl = ce_StrTokIdx(sRepostUrls,",",0);
	return sUrl;
}

function ce_GetUserName() {
	var s = ce_GetCookie(svnLogon,svKeyUserName);
	return (s!=null)?s:"";
}

function ce_GetPwd() {
	var s = ce_GetCookie(svnLogon,"UserPwd");
	return (s!=null)?s:"";
}

function ce_GetUserGroups() {
	var s = ce_GetCookie(svnLogon, svKeyUserGroups);
	return (s!=null)?s:"";
}

function ce_GetUserPages() {
	var s = ce_GetCookie(svnLogon, svKeyUserPages);
	return (s!=null)?s:"";
}

function ce_GetUserRights() {
	var n = parseInt(ce_GetCookie(svnLogon, svKeyAdminLevel));
	return (!isNaN(n))?n:0;
}

function ce_Initialize() {
	ce_nCanEdit = ce_CanEditPage();
	if(ce_nCanEdit == 1 || ce_nCanEdit == -1)
		{
		ce_sSiteRootURL = ce_GetCookie(svnSession, svKeySiteRootURL);
		ce_sConteditMethod = ce_GetCookie(svnSession, svnKeyCeMethod);
		ce_sApplAdminURL = ce_GetCookie(svnSession, svKeyApplAdminURL);
		if(ce_sApplAdminURL==null || ce_sApplAdminURL.length == 0)
			ce_sApplAdminURL = "/admin";
		ce_sURL = ce_GetThisUrl();
		}
}

// Add application specific functions here
// End application specific functions

// Initialize content edit environment
ce_Initialize();
