// RightClick utility/cross-browser functions
// (c) 2001-2007 www.webarchitects.nl

if (typeof(Array.prototype.indexOf) != 'function') {
	Array.prototype.append = function(a) {
		var a2 = this;
		for (var i = 0; i < a.length; i++) a2.push(a[i]);
		return a2;
	}
	Array.prototype.indexOf = function(s) {
		if (s != null) s = s.toString();
		for (var i = 0; i < this.length; i++) {
			if (s == (this[i] != null ? this[i].toString() : null)) return i;
		}
		return -1;
	}
	Array.prototype.contains = function(str) {
		return (this.indexOf(str) >= 0);
	}
	Array.prototype['delete'] = function(s) {
		var n = this.indexOf(s);
		while (n >= 0) {
			this.splice(n, 1);
			n = this.indexOf(s);
		}
	}
	Array.prototype.removeDuplicates = function(bRemoveNull) {
		var aResult = new Array();
		for (var i = 0; i < this.length; i++) {
			if (bRemoveNull && this[i] == null) continue;
			if (aResult.indexOf(this[i]) == -1) aResult.push(this[i]);
		}
		return aResult;
	}
	Array.prototype.filter = function(fFilter) {
		var a = new Array();
		for (var i = 0; i < this.length; i++) {
			if (fFilter(this[i])) a.push(this[i]);
		}
		return a;
	}
	Function.prototype.andThen = function(g) {
		var f = this;
		if (typeof(g) != 'function') {
			return this;
		}
		return function() {f();g();}
	}
	Function.prototype.andThenMaybe = function(g) {
		var f = this;
		if (typeof(g) != 'function') {
			return this;
		}
		return function() {if (f()) g();}
	}
	Function.prototype.after = function(g) {
		var f = this;
		if (typeof(g) != 'function') {
			return this;
		}
		return function() {g();f();}
	}
	Function.prototype.maybeAfter = function(g) {
		var f = this;
		if (typeof(g) != 'function') {
			return this;
		}
		return function() {if (g()) f();}
	}
	String.prototype.trim = function() {
		return this.replace(/^\s+/, '').replace(/\s+$/, '');
	}
	String.prototype.ztrim = function() {
		return this.replace(/^(0+)(.+)$/, '$2');
	}
}
function toArray(o) {
	if (typeof(o) == 'Array') return o;
	if (o == null) return new Array();
	if (typeof(o) == 'object' && o.length) {
		// Collection
		var aResult = new Array();
		for (var i = 0; i < o.length; i++) {
			aResult.push(o[i]);
		}
		return aResult;
	} else if (typeof(o) == 'String') {
		return o.split(',');
	}
	return new Array();
}
function stringContainsOnly(s, sMatch) {
	return s.match('^[' + sMatch.replace('-', '\\-') + ']*$') != null;
}

function trimSpaces(s) {
	return s.trim();
}

function rcOpenWindow(sURL) {
	var bStripped = (arguments.length > 1 ? arguments[1] : true);
	var nWidth = (arguments.length > 2 ? arguments[2] : 500);
	var nHeight = (arguments.length > 3 ? arguments[3] : 400);
	var sPopupName = (arguments.length > 4 ? arguments[4] : 'rightclick_popup');
	var bAddTimestamp = (arguments.length > 5 ? arguments[5] : false);
	if (bAddTimestamp) {
		sURL += (sURL.indexOf('?') < 0 ? '?' : '&') + getTimestamp();
	}
	// Determine center of screen
	var nLeft = (screen.width - nWidth) / 2;
	var nTop = (screen.height - nHeight) / 2;
	if (bStripped) {
		var sOptions = "toolbar=0,width=" + nWidth + ",height=" + nHeight + ",top=" + nTop + ",left=" + nLeft + ",resizable";
	} else {
		var sOptions = "location=1,toolbar=1,menubar=1,status=1,width=" + nWidth + ",height=" + nHeight + ",top=" + nTop + ",left=" + nLeft + ",resizable,scrollbars=1";
	}
	var oWindow = window.open(sURL, sPopupName, sOptions);
	if (!oWindow) {
		// Popup blocker in effect?
	} else {
		oWindow.focus();
	}
}

function rcGetAttribute(o, sAttr) {
	if (o.getAttribute) return o.getAttribute(sAttr);
	return o[sAttr];
}
function rcSetAttribute(o, sAttr, vVal) {
	if (o.setAttribute) {
		o.setAttribute(sAttr, vVal);
	} else {
		o[sAttr] = vVal;
	}
	return vVal;
}
function rcAddEventListener(o, sEvent, fListener) {
	if (o.addEventListener) return o.addEventListener(sEvent, fListener, false);
	if (o.attachEvent) return o.attachEvent('on' + sEvent, fListener);
	return false;
}
function rcRemoveEventListener(o, sEvent, fListener) {
	if (o.removeEventListener) return o.removeEventListener(sEvent, fListener, false);
	if (o.detachEvent) return o.detachEvent('on' + sEvent, fListener);
	return false;
}
function rcGetEventSource(oEvent) {
	if (oEvent.target) return oEvent.target;
	if (oEvent.srcElement) return oEvent.srcElement;
	return null;
}
function rcGetEventTarget(oEvent) {
	if (oEvent.relatedTarget) return oEvent.relatedTarget;
	if (oEvent.toElement) return oEvent.toElement;
	return null;
}

function RCImageHandler() {
	rcAddEventListener(window, 'load', fPreload);

	function fPreload() {
		if (window.gbPreloaded) return;
		var aImages = toArray(document.getElementsByTagName('img'));
		var aInputs = toArray(document.getElementsByTagName('input')).filter(function(o) {return o.type.toLowerCase() == 'image';});
		aImages.append(aInputs);
		var nImages = aImages.length;
		for (var i = 0; i < nImages; i++) {
			var oImage = aImages[i];
			if (sSrcNormal = rcGetAttribute(oImage, 'srcNormal')) {
				new Image().src = sSrcNormal;
			} else {
				sSrcNormal = rcSetAttribute(oImage, 'srcNormal', oImage.src);
			}
			if (sSrcOver = rcGetAttribute(oImage, 'srcOver')) {
				var o = new Image(); o.src = sSrcOver;
				rcAddEventListener(oImage, 'mouseover', fMouseOver);
				rcAddEventListener(oImage, 'mouseout', fMouseOut);
			} else {
				rcSetAttribute(oImage, 'srcOver', sSrcNormal);
			}
			if (sSrcDown = rcGetAttribute(oImage, 'srcDown')) {
				var o = new Image(); o.src = sSrcDown;
				rcAddEventListener(oImage, 'mousedown', fMouseDown);
				rcAddEventListener(oImage, 'dragleave', fMouseOut);
				rcAddEventListener(oImage, 'mouseup', fMouseUp);
			}
			if (sSrcClick = rcGetAttribute(oImage, 'srcClick')) {
				var o = new Image(); o.src = sSrcClick;
				if (!sSrcDown) {
					rcSetAttribute(oImage, 'srcDown', sSrcClick);
					rcAddEventListener(oImage, 'mousedown', fMouseDown);
				}
				rcAddEventListener(oImage, 'click', fClick);
			}
		}
		window.gbPreloaded = true;
	}
	function fMouseOver(e) {
		swapImage(rcGetEventSource(e), 'srcOver');
	}
	function fMouseOut(e) {
		swapImage(rcGetEventSource(e), 'srcNormal');
	}
	function fMouseDown(e) {
		swapImage(rcGetEventSource(e), 'srcDown');
	}
	function fMouseUp(e) {
		swapImage(rcGetEventSource(e), 'srcOver');
	}
	function fClick(e) {
		var oImage = rcGetEventSource(e);
		swapImage(oImage, 'srcClick');
		rcRemoveEventListener(oImage, 'mouseover', fMouseOver);
		rcRemoveEventListener(oImage, 'mouseout', fMouseOut);
		rcRemoveEventListener(oImage, 'mousedown', fMouseDown);
		rcRemoveEventListener(oImage, 'mouseup', fMouseUp);
	}
	function swapImage(oImage, sAttribute) {
		if (sSource = rcGetAttribute(oImage, sAttribute)) oImage.src = sSource;
	}
}
new RCImageHandler();

function RCBrowser() {
	this.userAgent = navigator.userAgent.toLowerCase();
	this.isMac = navigator.appVersion.indexOf('Mac') != -1 ? 1 : 0;
	this.isOpera = this.userAgent.indexOf('opera') != -1 ? 1 : 0;
	this.isOpera7 = this.userAgent.indexOf('opera/7') != -1 || this.userAgent.indexOf('opera 7') != -1 ? 1 : 0;

	// Both Safari and Konqueror use the khtml rendering engine
	this.isSafari = (this.userAgent.indexOf('safari') != -1 || this.userAgent.indexOf('konq') != -1) ? 1 : 0;
	this.isIE = !this.isSafari && !this.isOpera && (
		this.userAgent.indexOf('msie 4') != -1
		|| this.userAgent.indexOf('msie 5') != -1
		|| this.userAgent.indexOf('msie 6') != -1
		|| this.userAgent.indexOf('msie 7') != -1);
	this.isIE4 = this.isIE && this.userAgent.indexOf('msie 4') != -1;
	this.isIE50 = this.isIE && this.userAgent.indexOf('msie 5.0') != -1;
	this.isIE55 = this.isIE && this.userAgent.indexOf('msie 5.5') != -1;
	this.isIE5 = this.isIE50 || this.isIE55;
	this.isIE6 = this.isIE && this.userAgent.indexOf('msie 6') != -1;
	this.isIE7 = this.isIE && this.userAgent.indexOf('msie 7') != -1;
	// Silly safari uses string "khtml, like gecko", so check for distinctive /
	this.isFirefox = this.userAgent.indexOf('firefox') != -1;
	this.isGecko = !this.isFirefox && this.userAgent.indexOf('gecko/') != -1;
	this.isMacIE = (this.isIE && this.isMac);
	this.isIE5up = this.isIE && !this.isIE4;
	this.isIE55up = this.isIE5up && !this.isIE50 && !this.isMacIE;
	this.isIE6up = this.isIE55up && !this.isIE55;

	this.standardsMode = (document.compatMode && document.compatMode == 'CSS1Compat');
	this.useLibrary = (this.isOpera7 || this.isSafari || this.isIE55up || this.isGecko || this.isMacIE);
	this.canTimeout = !(this.isSafari || this.isIE55up || this.isMacIE);
	this.canFade = (this.isGecko || this.isIE55up);
	this.canDrawOverSelect = (this.isOpera || this.isMac);

	// Event Variables
	this.eventTarget = this.isIE ? 'srcElement' : 'currentTarget';
	this.eventButton = this.isIE ? 'button' : 'which';
	this.eventTo = this.isIE ? 'toElement' : 'relatedTarget';
	this.stylePointer = this.isIE ? 'hand' : 'pointer';
}

var goRCBrowser = new RCBrowser();

/* rcPopup library to show dynamic Iframe */

var gsRCPopupId = 'goRCPopupIframe';
var gnRCPopupPagePadding = 10;

// rcShowPopup is now replaced by rcShowPopup2 (Safari-compatible)

function rcShowPopup(sUrl, nWidth, nHeight) {
	var bPassedPosition = false;
	var oPosition = new Object();
	oPosition.x = 10;
	oPosition.y = 10;

	if (arguments.length == 6 || arguments.length == 4) {
		// Event passed as last argument
		var oEvent = arguments[arguments.length - 1];
	} else {
		var oEvent = window.event;
	}
	if (arguments.length >= 5) {
		// Position passed
		return rcShowPopup2(oEvent, sUrl, nWidth, nHeight, arguments[3], arguments[4]);
	} else {
		// No position passed
		return rcShowPopup2(oEvent, sUrl, nWidth, nHeight);
	}
	return false;
}

// rcShowPopup2 is a cross-browser dynamic IFRAME popup
// The x and y coordinates are optional, if left out the event
// determines the position (click)

function rcShowPopup2(oEvent, sUrl, nWidth, nHeight, nX, nY) {
	var oPosition;

	if (arguments.length == 2) {
		// Hidden popup! Don't do anything with w/h/x/y
	} else if (arguments.length == 6) {
		oPosition = new Object();
		oPosition.x = nX;
		oPosition.y = nY;
	} else {
		oPosition = rcGetEventPosition(oEvent);
		oPosition = rcCorrectOverlap(nWidth, nHeight, oPosition, gnRCPopupPagePadding);
	}

	var bSetUrl = false;
	var o = rcGetPopup(gsRCPopupId);
	if (o == null) {
		bSetUrl = rcCreatePopup(gsRCPopupId, sUrl);
		o = rcGetPopup(gsRCPopupId);
	} else {
		rcSetPopupUrl(o, 'about:blank');
	}
	if (typeof(oPosition) != 'undefined') {
		rcPositionPopup(o, nWidth, nHeight, oPosition.x, oPosition.y);
		document.onmouseup = rcHidePopup;
	}
	if (!bSetUrl) {
		rcSetPopupUrl(o, sUrl);
		if (goRCBrowser.isSafari) {
			window.setTimeout("rcVerifyPopupUrl('" + sUrl + "')", 1000);
		}
	}

	return false;
}

function rcVerifyPopupUrl(sUrl) {
	// Safari bug workaround
	var o = rcGetPopup(gsRCPopupId);
	if (o && rcGetPopupUrl(o) != sUrl) {
		rcSetPopupUrl(sUrl);
	}
}

function rcCorrectOverlap(nWidth, nHeight, oPos, nPagePadding) {
	var oDoc, nPageHeight, nPageWidth, nPageOffsetY, nPageOffsetX;
	var nX = oPos.x, nY = oPos.y;

	if (goRCBrowser.standardsMode && (goRCBrowser.isIE || goRCBrowser.isGecko)) {
		oDoc = window.document.documentElement;
	} else {
		oDoc = window.document.body;
	}

	if (goRCBrowser.isIE) {
		nPageWidth = oDoc.clientWidth;
		nPageHeight = oDoc.clientHeight;
		nPageOffsetX = oDoc.scrollLeft;
		nPageOffsetY = oDoc.scrollTop;
	} else {
		nPageWidth = oDoc.clientWidth;
		nPageHeight = (goRCBrowser.isSafari ? window.innerHeight : oDoc.clientHeight);
		nPageOffsetX = window.pageXOffset;
		nPageOffsetY = window.pageYOffset;
	}

	nX = nX - (nWidth / 2);
	nY = nY - (nHeight / 2);

	nX = Math.max(nX, nPageOffsetX + nPagePadding);
	nX = Math.min(nX, nPageOffsetX + nPageWidth - nWidth - nPagePadding);
	nX = Math.max(nX, 0);

	nY = Math.max(nY, nPageOffsetY + nPagePadding);
	nY = Math.min(nY, nPageOffsetY + nPageHeight - nHeight - nPagePadding);
	nY = Math.max(nY, 0);

	oPos.x = nX;
	oPos.y = nY;
	return oPos;
}

function rcGetPopup(sId) {
	var o = null;
	if (goRCBrowser.isIE4) {
		o = document.all[sId];
	} else if (false && goRCBrowser.isMacIE) {
		o = document.frames[sId];
	} else {
		o = document.getElementById(sId);
	}
	return o;
}

function rcCreatePopup(sId, sUrl) {
	var o = null;
	if (goRCBrowser.isIE4 || (goRCBrowser.isIE5 && !goRCBrowser.isMac)) {
		// IE4/IE5 PC does not allow dynamic creation
		// and manipulation of an iframe object.
		sHTML = '<IFRAME id="' + sId + '" style="'
			+ 'border: 1px solid black;'
			+ 'display: none;'
			+ 'position: absolute;'
			+ 'left: 0px;'
			+ 'top: 0px;'
			+ 'width: 0px;'
			+ 'height: 0px;'
			+ 'z-index: 32767;'
			+ 'background-color: white;'
			+ '" border="0" frameborder="0" scrolling="no" src="' + sUrl + '"></IFRAME>';
		document.body.innerHTML += sHTML;
	} else {
		// Create dynamically using neat DOM
		var oTemp = document.createElement('IFRAME');
		oTemp.setAttribute('id', sId);
		oTemp.setAttribute('src', sUrl);
		oTemp.setAttribute('scrolling', 'no');
		oTemp.border = '0';
		oTemp.frameborder = '0';
		oTemp.frameBorder = '0';
		oTemp.style.position = 'absolute';
		oTemp.style.border = '1px solid black';
		oTemp.style.display = 'none';
		oTemp.style.left = '0px';
		oTemp.style.top = '0px';
		oTemp.style.width = '0px';
		oTemp.style.height = '0px';
		oTemp.style.zIndex = 32767;
		oTemp.style.backgroundColor = 'white';
		document.body.appendChild(oTemp);
		if (goRCBrowser.isIE5 && goRCBrowser.isMac) {
			// Mac IE5 needs to set the src again.
			return false;
		}
	}
	// The URL of the iframe has been set.
	return true;
}

function rcPositionPopup(o, nWidth, nHeight, nLeft, nTop) {
	// Show the popup at the specified position
	o.style.left = nLeft + 'px';
	o.style.top = nTop + 'px';
	o.style.width = nWidth + 'px';
	o.style.height = nHeight + 'px';
	o.style.display = 'block';
	o.style.visibility = 'visible';
	o.style.filter = "progid:DXImageTransform.Microsoft.Shadow(color='#666666', Direction=135, Strength=4)";
}

function rcGetPopupUrl(o) {
	if (o.contentDocument) {
		// NS6
		return o.contentDocument.location.href;
	} else if (o.contentWindow) {
		// IE5.5 and IE6
		return o.contentWindow.document.location.href;
	}
	return o.src;
}

function rcSetPopupUrl(o, sUrl) {
	// Set the popup's URL
	if (o.contentDocument) {
		// NS6
		return o.contentDocument.location.replace(sUrl);
	} else if (o.contentWindow) {
		// IE5.5 and IE6
		return o.contentWindow.document.location.replace(sUrl);
	}
	o.src = sUrl;
}

function rcHidePopup() {
	// Do we need to jump through to another page? If so, the URL is passed
	// as an argument.
	// Take either 2nd or 1st argument. If there's two arguments, the first
	// may be (Safari's) event object.
	var sUrl = (arguments.length > 1 ? arguments[1] : (arguments.length > 0 ? arguments[0] : null));
	var o = rcGetPopup(gsRCPopupId);

	if (typeof(sUrl) == 'string') {
		// Hide popup/relocate to URL
		if (o != null) {
			// Safari/Mac bug workaround: new iframe on reloaded page
			// always seems to show the last url of the iframe before reload.
			rcSetPopupUrl(o, 'about:blank');
		}
		window.location.href = sUrl;
	} else if (o != null) {
		o.style.visibility = 'hidden';
		o.style.display = 'none';
		rcSetPopupUrl(o, 'about:blank');
	}
	document.onmouseup = null;
	return false;
}

function rcAlert(sMessage) {
	if (typeof(rcCustomAlert) == 'function') {
		return rcCustomAlert(sMessage);
	} else {
		alert(sMessage);
	}
}

function rcConfirm(sQuestion) {
	if (typeof(rcCustomConfirm) == 'function') {
		return rcCustomConfirm(sQuestion);
	} else {
		return confirm(sQuestion);
	}
}

// formatFloat takes a locale-specific string as input,
// and returns a valid float according to that (or another) locale.
// The output locale can be passed as a second parameter.
// The input locale can be passed as a third parameter; if omitted, the output locale is assumed.

function formatCharacters(sLocale) {
	if (sLocale.toUpperCase() == 'NL') {
		return new Array('.', ',');
	}
	return new Array(',', '.');
}

// Example: formatFloat('347878') returns an array with two elements: '347878.00' and '347,878.00'
// Example: formatFloat('1293.22', 'NL') returns an array with two elements: '1293.22' and '1.293,22'
// Example: formatFloat('1.293,22', 'NL', 'NL') returns: '1293.22' and '1.293,22'.

function formatFloat(s) {
	var sOutputLocale = (arguments.length > 1 ? arguments[1] : 'EN').toString().toUpperCase();
	var sInputLocale = (arguments.length > 2 ? arguments[2] : 'EN').toString().toUpperCase();

	var aInputChars = formatCharacters(sInputLocale);
	var aOutputChars = formatCharacters(sOutputLocale);

	s = s.toString();

	// 1. Remove all thousand-separators
	var oThousandsExp = new RegExp('[' + aInputChars[0] + ']', 'g');
	s = s.replace(oThousandsExp, '');

	// 2. Get all numbers, optionally followed by decimal point and X decimals
	var oDecimalExp = new RegExp('([-]){0,1}[0-9]*([' + aInputChars[1] + '][0-9]*){0,1}', '');
	var oResult = s.match(oDecimalExp);

	// 3. If the string cannot be matched (empty or non numeric), set to zero
	s = (oResult == null ? '0' : oResult[0]);

	// 4. Determine decimal point location and add it if not present
	var nLoc = s.indexOf(aInputChars[1]);
	if (nLoc == -1) {
		s += '.00';
	} else {
		sStart = (nLoc > 0 ? s.substring(0, nLoc) : '');
		sEnd = (nLoc < s.length - 1 ? s.substring(nLoc + 1, s.length) : '');
		s = sStart + '.' + sEnd + '00'.substring(0, 2 - sEnd.length);
	}
	s = Math.round(parseFloat(s) * 100) / 100;
	s = s.toString();
	var nLoc = s.indexOf('.');
	if (nLoc == -1) {
		s += '.00';
	} else {
		sStart = (nLoc > 0 ? s.substring(0, nLoc) : '');
		sEnd = (nLoc < s.length - 1 ? s.substring(nLoc + 1, s.length) : '');
		s = sStart + '.' + sEnd + '00'.substring(0, 2 - sEnd.length);
	}

	// 5. Remove leading zeroes
	s = s.replace(/^[0]*/, '');

	// 6. Add zero if string starts with decimal point.
	var nLoc = s.indexOf('.');
	if (nLoc == 0) {
		nLoc++;
		s = '0' + s;
	}

	// 7. Set DB value in 'real' input
	var sValue = s;

	// 8. Replace decimal with output locale's decimal
	s = s.replace(/[.]/, aOutputChars[1]);

	// 9. Insert thousand separators
	for (var i = nLoc - 3; i > (s.substring(0,1) == '-' ? 1 : 0); i -= 3) {
		s = s.substring(0, i) + aOutputChars[0] + s.substring(i, s.length);
	}

	return new Array(sValue, s);
}

var goRCImageClick = null;

function rcPrepareImage(oImage) {
	var o = null;
	if (oImage.src1) {
		o = oImage.img1 = new Image();
		o.src = oImage.src1;
	}
	if (oImage.src2) {
		o = oImage.img2 = new Image();
		o.src = oImage.src2;
	}
	if (oImage.src3) {
		o = oImage.img3 = new Image();
		o.src = oImage.src3;
	}
}

function rcOverImage(oImage) {
	if (oImage != goRCImageClick) {
		oImage.src = oImage.src2;
	}
}

function rcOutImage(oImage) {
	if (oImage != goRCImageClick) {
		oImage.src = oImage.src1;
	}
}

function rcClickImage(oImage) {
	if (goRCImageClick != null && goRCImageClick.src1) {
		goRCImageClick.src = goRCImageClick.src1;
	}
	oImage.src = (oImage.src3 ? oImage.src3 : oImage.src2);
	goRCImageClick = oImage;
}

function rcGetEventPosition(oEvent) {
	var oPos = new Object();
	oPos.x = 0;
	oPos.y = 0;
	if (!oEvent) {
		return oPos;
	}
	if (goRCBrowser.isIE) {
		var oDoc = (goRCBrowser.standardsMode ? document.documentElement : document.body);
		if (oDoc) {
			oPos.x = oEvent.clientX + oDoc.scrollLeft;
			oPos.y = oEvent.clientY + oDoc.scrollTop;
		}
	} else {
		oPos.x = oEvent.pageX;
		oPos.y = oEvent.pageY;
	}
	return oPos;
}

function rcStatus(s) {
	window.status = s;
}

function rcVerifyFrameset(sId, nFramesetId, nFrameCount) {
	function getBaseWindow() {
		var oWindow = window;
		while (true) {
			if (typeof(oWindow.gnFramesetId) != 'undefined') {
				return oWindow;
			}
			if (oWindow.parent == oWindow || oWindow.parent == null) {
				return null;
			}
			oWindow = oWindow.parent;
		}
	}
	function getFrameURL(sId) {
		// Rewrite sId to contain placeholders.
		if (location.search != '') {
			var aPlaceholders = new Array('product_id','text_id','property_id','image_id');
			var aURLParameters = location.search.split('&');
			var aURLPlaceholders = new Array();
			for (var i = 0; i < aURLParameters.length; i++) {
				if (aPlaceholders.contains(aURLParameters[i].split('=')[0])) {
					aURLPlaceholders.push(aURLParameters[i]);
				}
			}
			if (aURLPlaceholders.length > 0) {
				sId = sId + '/' + aURLPlaceholders.join('/');
			}
		}
		return sId;
	}
	var sBaseURL = (arguments.length > 3 ? arguments[3] : '');
	oBaseWindow = getBaseWindow();
	if (oBaseWindow == null) {
		top.location.href = sBaseURL + 'rightclick.cfm?id=' + nFramesetId + '&rc_frame_' + nFrameCount + '=' + getFrameURL(sId);
		return false;
	}
	// We've got oBaseWindow, a valid RC frameset
	if (oBaseWindow.gnFramesetId != nFramesetId) {
		if (history.length > oBaseWindow.gnFramesetHistory) {
			// Client has gone back in history. Push history beyond JS relocate.
			history.go(-1);
			return true;
		}
		// Relocate to correct frameset
		oBaseWindow.location.href = sBaseURL + 'rightclick.cfm?id=' + nFramesetId + '&rc_frame_' + nFrameCount + '=' + getFrameURL(sId);
		return false;
	}
	oBaseWindow.gnFramesetHistory++;
	return true;
}
function dbl(n) {return (n < 10 ? '0' : '') + n;}

function rcGetTimestamp(bExtended) {
	var dNow = new Date();
	var d = (bExtended ? '-' : '');
	var dt = (bExtended ? ' ' : '');
	var t = (bExtended ? ':' : '');
	return dNow.getYear()
		+ d + dbl(dNow.getMonth() + 1)
		+ d + dbl(dNow.getDate())
		+ dt + dbl(dNow.getHours())
		+ t + dbl(dNow.getMinutes())
		+ t + dbl(dNow.getMilliseconds());
}

function RCCookie() {
	this.set = RCCookie_set;
	this.setField = RCCookie_setField;
	this.get = RCCookie_get;
	this.getField = RCCookie_getField;
	this['delete'] = RCCookie_delete;
	this.deleteField = RCCookie_deleteField;
	this.deleteExcept = RCCookie_deleteExcept;
	this.deleteLike = RCCookie_deleteLike;

	function RCCookie_set(sName, vValue) {
		var nNrDays = (arguments.length > 2 ? arguments[2] : 0);
		var sPath = (arguments.length > 3 ? arguments[3] : getFirstDirectoryFromURL(location.href));
		var sDomain = (arguments.length > 4 ? arguments[4] : getDomainFromURL(location.href));
		var dExpiryDate = null;
		if (nNrDays != 0) {
			dExpiryDate = new Date();
			dExpiryDate.setTime(dExpiryDate.getTime() + (nNrDays * 60 * 60 * 24 * 1000));
		}
		var sCookie = sName.toUpperCase() + '=' + escape(vValue)
			+ (dExpiryDate != null ? '; expires=' + dExpiryDate.toGMTString() : '')
			+ '; path=/' + sPath;
		document.cookie = sCookie;
	}

	function RCCookie_setField(sCookieName, sFieldName, vFieldValue) {
		// Get cookie
		var sCookieValue = this.get(sCookieName);

		// Check if field already in cookie?
		sFieldName = sFieldName.toLowerCase();
		var sFieldValue = escape(vFieldValue);
		var bFoundField = false;
		if (sCookieValue != '') {
			// See if field already contained in cookie
			var aCookieFields = sCookieValue.split(';');
			sCookieValue = '';
			for (var i = 0; i < aCookieFields.length; i++) {
				var aCookieField = aCookieFields[i].split('=');
				var sCookieFieldName = aCookieField[0].toLowerCase();
				var sCookieFieldValue = (aCookieField.length > 1 ? aCookieField[1] : '');
				if (sCookieFieldName == sFieldName) {
					sCookieFieldValue = sFieldValue;
					bFoundField = true;
				}
				sCookieValue += (sCookieValue == '' ? '' : ';') + sCookieFieldName + '=' + sCookieFieldValue;
			}
		}
		// Empty? Set to single-element list
		if (!bFoundField) {
			sCookieValue += (sCookieValue == '' ? '' : ';') + sFieldName + '=' + sFieldValue;
		}

		// Set cookie. Duplicate arguments array, remove unwanted argument
		// field name, replace field value with new cookie value.

		var aArguments = new Array();
		for (var i = 0; i < arguments.length; i++) {
			if (i != 1) {
				aArguments.push(arguments[i]);
			}
		}
		aArguments[1] = sCookieValue;

		// Call set method with dynamic argument array
		var sEval = '';
		for (var i = 0; i < aArguments.length; i++) {
			sEval += (i > 0 ? ',' : '') + 'aArguments[' + i + ']';
		}
		eval('this.set(' + sEval + ')');
	}

	function RCCookie_getField(sCookieName, sFieldName) {
		// Get cookie
		var sCookieValue = this.get(sCookieName);

		// Check if field already in cookie?
		sFieldName = sFieldName.toLowerCase();
		var bFoundField = false;
		if (sCookieValue != '') {
			// See if field already contained in cookie
			var aCookieFields = sCookieValue.split(';');
			for (var i = 0; i < aCookieFields.length; i++) {
				var aCookieField = aCookieFields[i].split('=');
				var sCookieFieldName = aCookieField[0].toLowerCase();
				if (sCookieFieldName == sFieldName) {
					return unescape(aCookieField.length > 1 ? aCookieField[1] : '');
				}
			}
		}
		return null;
	}

	function RCCookie_deleteField(sCookieName, sFieldName) {
		// Get cookie
		var sCookieValue = this.get(sCookieName);

		if (sCookieValue == '') {
			// OK!
			return true;
		}

		// Check if field in cookie
		var bFoundField = false;
		if (sCookieValue != '') {
			// See if field already contained in cookie
			var aCookieFields = sCookieValue.split(';');
			var sCookieValue = '';
			for (var i = 0; i < aCookieFields.length; i++) {
				var aCookieField = aCookieFields[i].split('=');
				var sCookieFieldName = aCookieField[0].toLowerCase();
				if (sCookieFieldName != sFieldName) {
					var sCookieFieldValue = (aCookieField.length > 1 ? aCookieField[1] : '');
					sCookieValue += (sCookieValue == '' ? '' : ';') + sCookieFieldName + '=' + sCookieFieldValue;
				}
			}
		}
		if (sCookieValue == '') {
			// Delete entirely
			this['delete'](sCookieName);
		} else {
			// Set remainder
			this.set(sCookieName, sCookieValue);
		}
		return true;
	}

	function RCCookie_get(sName) {
		var sName = sName.toUpperCase();
		var sCookie = document.cookie;
		var aCookies = sCookie.split('; ');
		for (var n = 0; n < aCookies.length; n++) {
			var aCookie = aCookies[n].split('=');
			if (aCookie[0].toUpperCase() == sName) {
				if (aCookie.length > 1) {
					return unescape(aCookie[1]);
				} else {
					return '';
				}
			}
		}
		return '';
	}

	function RCCookie_delete() {
		var sName = (arguments.length > 0 ? arguments[0] : null);
		if (sName == null) {
			// Delete all
			var aCookies = top.document.cookie.split(';')
			for (var n = 0; n < aCookies.length; n++) {
				aCookie = aCookies[n].split('=');
				var sDeleteName = aCookie[0];
				if (sDeleteName.substring(0,1) == ' ') sDeleteName = sDeleteName.substring(1, sDeleteName.length);
				this['delete'](sDeleteName);
			}
			return;
		}
		this.set(sName, '', -1);
	}

	function RCCookie_deleteExcept() {
		var aCookies = document.cookie.split(';');
		for (var n = 0; n < aCookies.length; n++) {
			var aCookie = aCookies[n].split('=');
			var sDeleteName = aCookie[0];
			if (sDeleteName.substring(0,1) == ' ') sDeleteName = sDeleteName.substring(1, sDeleteName.length);
			var bSkip = false;
			for (var i = 0; i < arguments.length; i++) {
				if (sDeleteName.toUpperCase() == arguments[i].toUpperCase()) {
					bSkip = true;
					break;
				}
			}
			if (!bSkip) {
				this['delete'](sDeleteName);
			}
		}
		return;
	}

	function RCCookie_deleteLike(sPrefix) {
		sPrefix = sPrefix.toUpperCase()
		var aCookies = document.cookie.split(';');
		for (var n = 0; n < aCookies.length; n++) {
			var aCookie = aCookies[n].split('=');
			var sDeleteName = aCookie[0];
			if (sDeleteName.substring(0,1) == ' ') sDeleteName = sDeleteName.substring(1, sDeleteName.length);
			bSkip = (sDeleteName.substring(0, sPrefix.length).toUpperCase() != sPrefix);
			if (!bSkip) {
				for (var i = 1; i < arguments.length; i++) {
					if (sDeleteName.toUpperCase() == arguments[i].toUpperCase()) {
						bSkip = true;
						break;
					}
				}
				if (!bSkip) {
					this['delete'](sDeleteName);
				}
			}
		}
		return;
	}
}

var goRCCookie = new RCCookie();

function getDomainFromURL(sURL) {
	return getURLSegment(sURL, true);
}

function getFirstDirectoryFromURL(sURL) {
	return getURLSegment(sURL, false);
}

function getURLSegment(sURL, bDomain) {
	if (sURL.indexOf('http://') == 0) {
		sURL = sURL.substring(7, sURL.length);
	} else if (sURL.indexOf('https://') == 0) {
		sURL = sURL.substring(8, sURL.length);
	}
	nLoc = sURL.indexOf('/');
	if (nLoc == -1) {
		return (bDomain ? sURL : '');
	}
	if (bDomain) {
		return sURL.substring(0, nLoc);
	}
	sURL = sURL.substring(nLoc + 1, sURL.length);
	nLoc = sURL.indexOf('/');
	if (nLoc > 0) {
		sURL = sURL.substring(0, nLoc);
	} else {
		sURL = '';
	}
	return sURL;
}
function getElementLeft(o, b) {
	if (o == null) return 0;
	if (o.tagName == 'BODY' || o.tagName == 'HTML') return 0;
	var nLeft = o.offsetLeft - (b && o.scrollLeft ? o.scrollLeft : 0);
	return nLeft + getElementLeft(o.offsetParent, true);
}
function getElementTop(o, b) {
	if (o == null) return 0;
	if (o.tagName == 'BODY' || o.tagName == 'HTML') return 0;
	var nTop = o.offsetTop - (b && o.scrollTop ? o.scrollTop : 0);
	return nTop + getElementTop(o.offsetParent, true);
}
function cancelEvent(e) {
	if (!e) e = event;
	if (!e) return false;
	event.returnValue = false;
	event.cancelBubble = true;
	return false;
}
function handleEvent(e) {
	if (!e) e = event;
	if (!e) return false;
	event.returnValue = true;
	event.cancelBubble = true;
	return true;
}
// Keep the following code synchronized with interaction.js
function AjaxRequest(sUrl, oArguments) {
	this.sUrl = sUrl;
	this.fOnReady = (oArguments.onready || null);
	this.fOnError = (oArguments.onerror || null);
	this.oForm = (oArguments.form || null);
	this.bAsynchronous = (oArguments.async || true);
	this.sMethod = (oArguments.method || 'GET').toUpperCase();
	this.sParameters = '';

	this.receiveResult = function (sResult) {
		if (this.oRequest.readyState == 4) {
			if (this.oRequest.status == 200) {
				var oJSON = null;
				try {
					var sJSON = this.oRequest.getResponseHeader('X-JSON');
					oJSON = JSON.toObject(sJSON);
				} catch(e) {
				}
				if (this.fOnReady == null) return;
				this.fOnReady(this.oRequest, oJSON);
			} else {
				if (this.fOnError != null) {
					try {
						this.fOnError(this.oRequest, this.sUrl);
					} catch(ex) {
						alert(ex.description + ',' + ex.message + ',' + ex.name + ',' + ex.number);
					}
				}
			}
		}
	}
	var oMe = this;

	if (window.XMLHttpRequest) {
		this.oRequest = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		this.oRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (this.oRequest) {
		this.oRequest.onreadystatechange = function(sResult) {oMe.receiveResult();}
		if (this.sMethod == 'GET') {
			this.oRequest.open('GET', sUrl, this.bAsynchronous);
			this.oRequest.send(null);
		} else if (this.sMethod == 'POST') {
			// Post form
			if (this.oForm != null) {
				this.sParameters = AjaxRequest.serializeForm(this.oForm);
			}
			this.oRequest.open('POST', sUrl, this.bAsynchronous);
			this.oRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.oRequest.setRequestHeader("Content-length", this.sParameters.length);
			this.oRequest.setRequestHeader("Connection", "close");
			this.oRequest.send(this.sParameters);
		} else {
			throw('Unsupported method ' + this.sMethod);
		}
	}
}
AjaxRequest.serializeForm = function(oForm) {
	var aParameter = new Array();
	var sParameter = '';

	for (var i = 0; i < oForm.elements.length; i++) {
		sParameter = AjaxRequest.serializeElement(oForm.elements[i]);
		if (sParameter) {
			aParameter.push(sParameter);
		}
	}
	return aParameter.join('&');
}
AjaxRequest.serializeElement = function(oElement) {
	var sName = encodeURIComponent(oElement.name);

	switch (oElement.tagName.toLowerCase()) {
		case 'input' :
			var sInputType = oElement.type.toLowerCase();
			if (sInputType == 'text' || sInputType == 'hidden' || sInputType == 'password' || sInputType == 'submit') {
				return sName + '=' + encodeURIComponent(oElement.value);
			} else if (sInputType == 'checkbox' || sInputType == 'radio') {
				if (oElement.checked) {
					return sName + '=' + encodeURIComponent(oElement.value);
				}
			}
			break;
		case 'select' :
			if (oElement.type == 'select-one') {
				if (oElement.selectedIndex >= 0) {
					return sName + '=' + encodeURIComponent(oElement.options[oElement.selectedIndex].value);
				} else {
					return sName + '='
				}
			} else {
				var aSelected = new Array();
				for (var i = 0; i < oElement.length; i++) {
				  if (oElement.options[i].selected) {
					aSelected.push(oElement.options[i].value);
				  }
				}
				return sName + '=' + encodeURIComponent(aSelected.join('&'));
			}
			break;
		case 'textarea' :
			return sName + '=' + encodeURIComponent(oElement.value);
			break;
	}
}
AjaxRequest.defaultErrorHandler = function(o) {
	oWin = window.open('about:blank');
	oWin.document.write(o.responseText);
}
var JSON = {
	toObject: function(sJSON) {
		sJSON = sJSON.trim();
		try {
			return eval('(' + sJSON + ')');
		} catch(e) {
			return null;
		}
	}
}
// End keep the following code synchronized with interaction.js
function glue(sSeparator) {
	var aResult = [];
	for (var i = 1; i < arguments.length; i++) {
		if (arguments[i] != null) aResult.push(arguments[i].toString().trim());
	}
	return aResult.join(sSeparator);
}
function writeFlash(sUrl, nWidth, nHeight) {
	var s = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + nWidth + '" height="' + nHeight + '" id="pr" align="middle">';
	s += '<param name="allowScriptAccess" value="sameDomain" />';
	s += '<param name="movie" value="' + sUrl + '" />';
	s += '<param name="quality" value="high" />';
	s += '<param name="menu" value="false" />';
	s += '<param name="wmode" value="transparent" />';
	s += '<embed src="' + sUrl + '" quality="high" bgcolor="#fff" width="' + nWidth + '" height="' + nHeight + '" name="pr" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	s += '</object>';
	document.write(s);
}
var Util = {
	addClass: function(oElement, sClass) {
		if (!Util.hasClass(oElement, sClass)) {
			oElement.className = glue(' ', oElement.className, sClass);
		}
	}, deleteClass: function(oElement, sClass) {
		var aClasses = oElement.className.split(' ');
		aClasses['delete'](sClass);
		oElement.className = aClasses.join(' ');
	}, hasClass: function(oElement, sClass) {
		return oElement.className.split(' ').indexOf(sClass) >= 0;
	}
}
