rnd.today = new Date ();
rnd.seed = rnd.today.getTime ();
level = 100;
var lastdatestart = '';
var lastdateend = '';
var lastdateexpire = '';
var lastdatecheck = '';
var lastcolorstart = '';
var lastcolorend = '';
var lastcolorexpire = '';
var lastcolorcheck = '';
var browser = new Browser ();
var dragObj = new Object ();

var addEvent = function (element, type, eventHandle) {
	if (element == null || element == undefined) {
		return;
	}
    if (element.addEventListener) {
		element.addEventListener (type, eventHandle, false);
	}
	else if (element.attachEvent) {
		element.attachEvent ('on' + type, eventHandle);
    }
};

function Browser() {
	var ua, s, i;
	this.isIE = false;
	this.isNS = false;
	this.version = null;
	ua = navigator.userAgent;
	s = "MSIE";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isIE = true;
		return;
	}
	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		return;
	}
	this.version = parseFloat(ua.substr(i + s.length));
}

// Draggable div code courtesy of http://www.brainjar.com/
// Global object to hold drag information
function dragStart (event, id) {
	var element;
	var x, y;
	// If an element id was given, find it. Otherwise use the element being clicked on.
	if (id) {
		dragObj.elementNode = document.getElementById (id);
	}
	else {
		if (browser.isIE) {
			dragObj.elementNode = window.event.srcElement;
		}
		if (browser.isNS) {
			dragObj.elementNode = event.target;
		}
		// If this is a text node, use its parent element.
		if (dragObj.elementNode.nodeType == 3) {
			dragObj.elementNode = dragObj.elementNode.parentNode;
		}
	}
	// Get cursor position with respect to the page.
	if (browser.isIE) {
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
	if (browser.isNS) {
		x = event.clientX + window.scrollX;
		y = event.clientY + window.scrollY;
	}
	// Save starting positions of cursor and element.
	dragObj.cursorStartX = x;
	dragObj.cursorStartY = y;
	dragObj.elementStartLeft = parseInt (dragObj.elementNode.style.left, 10);
	dragObj.elementStartTop = parseInt (dragObj.elementNode.style.top, 10);
	if (isNaN (dragObj.elementStartLeft)) {
		dragObj.elementStartLeft = 0;
	}
	if (isNaN (dragObj.elementStartTop)) {
		dragObj.elementStartTop = 0;
	}
	// Capture mousemove and mouseup events on the page.
	if (browser.isIE) {
		document.attachEvent ("onmousemove", dragGo);
		document.attachEvent ("onmouseup", dragStop);
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	if (browser.isNS) {
		document.addEventListener ("mousemove", dragGo, true);
		document.addEventListener ("mouseup", dragStop, true);
		event.preventDefault ();
	}
}

function dragGo (event) {
	var x, y;
	// Get cursor position with respect to the page.
	if (browser.isIE) {
		x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
	if (browser.isNS) {
		x = event.clientX + window.scrollX;
		y = event.clientY + window.scrollY;
	}
	// Move drag element by the same amount the cursor has moved.
	var newleft = (dragObj.elementStartLeft + x - dragObj.cursorStartX);
	var newtop = (dragObj.elementStartTop + y - dragObj.cursorStartY);
	
	// Check if moved out of usable area in window to left, right, or top -- if so bring back
	var windowWidth = getWorkingWidth ();
	var podWidth = dragObj.elementNode.offsetWidth;
	if (newleft + podWidth > windowWidth - 5) {
		newleft = windowWidth - podWidth - 5;
	}
	else if (newleft < 5) {
		newleft = 5;	
	}
	if (newtop < 5) {
		newtop = 5;
	}
	dragObj.elementNode.style.left = newleft + "px";
	dragObj.elementNode.style.top = newtop + "px";
	if (browser.isIE) {
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
	if (browser.isNS) {
		event.preventDefault ();
	}
	// Update ccokie to save new position
	var newposition = newleft + ',' + newtop;
	var podID = dragObj.elementNode.id;
	var cookieName = 'ODEIM-options-' + podID;
	updatePCLCookie (cookieName, newposition, '/cgi-bin', document.domain);	
}

function dragStop (event) {
	// Stop capturing mousemove and mouseup events.
	if (browser.isIE) {
		document.detachEvent ("onmousemove", dragGo);
		document.detachEvent ("onmouseup", dragStop);
	}
	if (browser.isNS) {
		document.removeEventListener ("mousemove", dragGo, true);
		document.removeEventListener ("mouseup", dragStop, true);
	}
}

function rnd () {
	rnd.seed = (rnd.seed * 9301 + 49297) % 233280;
	return rnd.seed / (233280.0);
}

function rand (number) {
	return Math.ceil (rnd () * number);
}

function setIdProperty (id, property, value) {
	if (document.getElementById || document.all) {
		var place = document.getElementById ? document.getElementById (id) : document.all[id];
		place.style.backgroundPosition = value;
	}
}

function shiftDivBackground (id, left, top, previousLeft, previousTop, minimumLeft, minimumTop, stepLeft, stepTop, stepNumber, stepDelay, count) {
	if (count <= (stepNumber * 2)) {
		if (previousLeft > left) {
			if ((left - stepLeft) < minimumLeft) {
				currentLeft = left + stepLeft;
			}
			else {
				currentLeft = left - stepLeft;
			}
		}
		else {
			if ((left + stepLeft) < 0) {
				currentLeft = left + stepLeft;
			}
			else {
				currentLeft = left - stepLeft;
			}
		}
		if (previousTop > top) {
			if ((top - stepTop) < minimumTop) {
				currentTop = top + stepTop;
			}
			else {
				currentTop = top - stepTop;
			}
		}
		else {
			if ((top + stepTop) < 0) {
				currentTop = top + stepTop;
			}
			else {
				currentTop = top - stepTop;
			}
		}
		previousLeft = left;
		previousTop = top;
		setIdProperty (id, "backgroundPosition", left + "px " + top + "px");
		count ++;
		setTimeout ("shiftDivBackground ('" + id + "', " + currentLeft + ", " + currentTop + ", " + previousLeft + ", " + previousTop + ", " + minimumLeft + ", " + minimumTop + ", " + stepLeft + ", " + stepTop + ", " + stepNumber + ", " + stepDelay + ", " + count + ")", stepDelay);
	}
}

function setupShift (id, imageLength, imageHeight, viewportLength, viewportHeight, stepNumber, stepDelay, picURL) {
	var startLeft = rand (imageLength - viewportLength) * -1;
	var startTop = rand (imageHeight - viewportHeight) * -1;
	var minimuLeft = (imageLength - viewportLength) * -1;
	var minimumTop = (imageHeight - viewportHeight) * -1;
	var stepTop = Math.round (((imageHeight - viewportHeight) / stepNumber) * 100) / 100;
	var stepLeft = Math.round (((imageLength - viewportLength) / stepNumber) * 100) / 100;
	count = 1;
	document.write ('<style type="text/css">');
	document.write ('#' + id + ' {');
	document.write ('	width: ' + viewportLength + 'px;');
	document.write ('	height: ' + viewportHeight + 'px;');
	document.write ('	background-position: 0px 0px;');
	document.write ('	background-image: url(' + picURL + ');');
	document.write ('	background-repeat: no-repeat;');
	document.write ('	z-index: 10;');
	document.write ('}');
	document.write ('</style>');
	shiftDivBackground (id, startLeft, startTop, 0, 0, minimuLeft, minimumTop, stepLeft, stepTop, stepNumber, stepDelay, count);
}

function getPick () {
	var argv = getPick.arguments;
	var argc = argv.length;
	var picPath = argv [0];
	var index = rand ((argc - 1));
	var pick = argv [index];
	var picURL = picPath + pick;
	return picURL;
}

function openWindow (windowname, width, height) {
	var windowTitle = windowname.replace (/\s/g, "_");
	if (document.layers) {
    	temp = "screenx=25,screeny=25,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars,resizable=yes,copyhistory=yes,width=" + width + ",height=" + height;
	}
	else {
    	temp = "left=25,top=25,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars,resizable=yes,copyhistory=yes,width=" + width + ",height=" + height;
	}
	window.open ("", windowTitle, temp);
}

function createWindow (contentURL, windowname, width, height) {
	var windowTitle = windowname.replace (/\s/g, "_");
	if (document.layers) {
    	temp = "screenx=25,screeny=25,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars,resizable=yes,copyhistory=yes,width=" + width + ",height=" + height;
	}
	else {
    	temp = "left=25,top=25,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars,resizable=yes,copyhistory=yes,width=" + width + ",height=" + height;
	}
	window.open (contentURL, windowTitle, temp);
}

function checkFormFields (mandatoryFields, confirm, nextScriptString) {
	var formIndex = 0;
	var countCheck = 0;
	var checkObject;
	do {
		formIndex += (countCheck == 0) ? 0 : 1;
		checkObject = (document.forms [formIndex]) ? document.forms [formIndex].elements [mandatoryFields[1][0]] : 'undefined';
		countCheck ++;
	} while ((typeof checkObject == 'undefined') && (countCheck < 10));
	var msg = '';
	if (countCheck == 10 || checkObject == 'undefined') {
		alert ('Cannot check form inputs...\nunsafe to continue');
		return false;
	}
	for (var i = 0; i < mandatoryFields.length; i++) {
		var d = document.forms [formIndex];
		var formObject = d.elements[mandatoryFields[i][0]];
		if (formObject.type == "hidden") {
			if ((formObject.value == '') || ((mandatoryFields[i][0] == "purchaseAmount") && (formObject.value == 0))) {
				msg += mandatoryFields[i][1] + ' not supplied\n';
			}
		}
		else if ((formObject.value == '') || (formObject.value == "None") || (formObject.value == "00/00/0000") || 
		(formObject.value == "Please select")) {
			msg += mandatoryFields[i][1] + ' not supplied\n';
		}
		else if (formObject.type == "checkbox") {
			if (formObject.checked == 0) {
				msg += mandatoryFields[i][1] + ' not checked\n';
			}
		}
		else if ((formObject.type != "select-one") && (formObject.type != "select-multiple") && (formObject.type != "text") && 
		(formObject.type != "textarea") && (formObject.type != "password") && (formObject.type != "file")) {
			var buttonsChecked = 0;
			for (var j = 0; j < formObject.length; j++) {
				if (formObject[j].checked) {
					buttonsChecked++;
				}
			}
			if (buttonsChecked == 0) {
				msg += mandatoryFields[i][1] + ' not selected\n';
			}
		}
		if ((mandatoryFields[i][0].indexOf('email') > -1) || (mandatoryFields[i][0].indexOf('Email') > -1)) {
			if (!(validEmail (formObject.value))) {
				msg += mandatoryFields[i][1] + ' appears to be an invalid address\n';
			}
		}
	}
	if (msg) {
		alert (msg + '\n...please correct and try again\n');
		return false;
	}	
	if (confirm == 0) {
		return true;
	}
	else {
		return confirmFormSubmit (nextScriptString);
	}
}

function validEmail (address) {
	var at = address.indexOf('@');
	var dot = address.indexOf('.');
	if (at == -1) return false;
	if (at != address.lastIndexOf('@')) return false;
	if (dot == -1) return false;
	if (dot == (address.length - 1)) return false;
	if (address.lastIndexOf('.') == (address.length - 1)) return false;
	return true;
}

function confirmRecordDelete (object, identifier) {
	var msg = 'You are about to delete:\n\n\t' + object + ' ' + identifier;
	msg += '\n\nYou cannot undo this deletion.';
	msg += '\n\nOnly select \'OK\' if you wish to continue.';
	msg += ' If you do not wish to continue then select \'Cancel\'.';
	var proceed = confirm(msg);
	if (proceed) {
		return true;
	}
	else {	
		return false;
	}
}

function confirmFormSubmit (nextScriptString) {
	var msg = 'You have now chosen to submit the information on this form.';
	msg += '\n\nOnly select \'OK\' if you are sure you wish to proceed.';
	msg += ' Otherwise you should select \'Cancel\' to continue editing the information.';
	var proceed = confirm (msg);
	if (proceed) {
		if (nextScriptString != "") {
			return eval (nextScriptString);
		}
		else {
			return true;
		}
	}
	else {	
		return false;
	}
}

function insertInLayer (layerID, layerContent) {
	if (document.getElementById || document.all) {
		var place = document.getElementById ? document.getElementById (layerID) : document.all[layerID];
		if (place && typeof place.innerHTML != "undefined") {
			place.innerHTML = layerContent;
		}
	}
}

function resetListing (hashID) {
	var address = window.opener.location.href;
	var temp = new Array();
	temp = address.split ('#');
	address = temp [0] + '#' + hashID;
	window.opener.location.href = address;
	window.opener.focus();
	return true;
}

function showDateSelected (container, month, year, date) {
	var qmonth = (month < 10) ? '0' + month.toString() : month.toString();
	var qdate = (date < 10) ? '0' + date.toString() : date.toString();
	if (document.getElementById || document.all) {
		var place = document.getElementById ? document.getElementById (container) : document.all[container];
		if (place && typeof place.innerHTML != "undefined") {
			var selected = year.toString() + '-' + qmonth + '-' + qdate;
			var content = '<input type="hidden" id="inner' + container + '" name="' + container + '" value="' + selected + '">';
			content += '&nbsp;' + selected;
			place.innerHTML = content;
		}
	}
}

function updateDateSelected (container, month, year, date) {
	var qmonth = (month < 10) ? '0' + month.toString() : month.toString();
	var qdate = (date < 10) ? '0' + date.toString() : date.toString();
	if (document.getElementById || document.all) {
		var place;
		place = document.getElementById ? document.getElementById (container) : document.all[container];
		if (place && typeof place.innerHTML != "undefined") {
			var selected = year.toString() + '-' + qmonth + '-' + qdate;
			var content = '<input type="hidden" id="inner' + container + '" name="' + container + '" value="' + selected + '">';
			content += '&nbsp;' + selected;
			place.innerHTML = content;
		}
	}
}

function updateContent (container, content) {
	if (document.getElementById || document.all) {
		var place = document.getElementById ? document.getElementById (container) : document.all[container];
		if (place && typeof place.innerHTML != "undefined") {
			place.innerHTML = content;
		}
	}
}

function checkTextLength (object, characters) {
	if (object.value.length > characters) {
		var msg = "You must reduce the length of the supplied text to ";
		msg += characters;
		msg += " or less characters";
		alert (msg);
		object.focus ();
		object.select ();
	}
}

function refreshBookingForm (container, picker, picture) {
	// location.hash = '#start-here';
	if (document.getElementById || document.all) {
		var source = document.getElementById ? document.getElementById (picker) : document.all[picker];
		var frame = document.getElementById ? document.getElementById (picture) : document.all[picture];
		var id = source.selectedIndex;
		var content = bookingfacts[id];
		var place = document.getElementById ? document.getElementById (container) : document.all[container];
		if (place && typeof place.innerHTML != "undefined") {
			place.innerHTML = content;
		}
		frame.src = bookingpictures[id];
	}
}

function checksame (first, second, label) {
	var d = document.forms[0];
	var msg = '';
	var firstFormObject = d.elements[first];
	var secondFormObject = d.elements[second];
	if (firstFormObject.value != secondFormObject.value) {
		msg += label;
		alert (msg + '\n...please correct and try again\n');
		return false;
	}	
	else {
		return true;
	}
}

function selectdatescript (flag, container, month, year, date) {
	var lastcell = eval ('lastdate' + flag);
	var lastcolor = eval ('lastcolor' + flag);
	if (document.getElementById (lastcell)) {
		document.getElementById (lastcell).className = lastcolor;
	};
	var cell = flag + date;
	if (flag == "start") {
		lastdatestart = cell;
		lastcolorstart = document.getElementById (cell).className;
	}
	else if (flag == "end") {
		lastdateend = cell;
		lastcolorend = document.getElementById (cell).className;
	}
	else if (flag == "check") {
		lastdatecheck = cell;
		lastcolorcheck = document.getElementById (cell).className;
	}
	document.getElementById (cell).className = 'calhighlight';
	if (container && month && year && date) {
		updateDateSelected (container, month, year, date);
		updateCostSummary ();
		updateDeposit ();
	}	
}

function newsdatescript (flag, container, month, year, date) {
	var lastcell = eval ('lastdate' + flag);
	var lastcolor = eval ('lastcolor' + flag);
	if (document.getElementById (lastcell)) {
		document.getElementById (lastcell).className = lastcolor;
	};
	var cell = flag + date;
	if (flag == "start") {
		lastdatestart = cell;
		lastcolorstart = document.getElementById (cell).className;
	}
	else if (flag == "expire") {
		lastdateexpire = cell;
		lastcolorexpire = document.getElementById (cell).className;
	}
	document.getElementById (cell).className = 'calhighlight';
	if (container && month && year && date) {
		updateDateSelected (container, month, year, date);
	}	
	return false;
}

function updateCostSummary () {
	doajax (['do__updatecostsummary', 'booStart__' + getVal ('innerbooStart'), 'booEnd__' + getVal ('innerbooEnd'), 'optionID__' + getVal ('optionID'), 'booPets__' + getVal ('booPets'), 'encID__' + getVal ('encID'), 'NO_CACHE'], ['costsummary']);
	return true;
}

function updateDeposit () {
	doajax (['do__updatedeposit', 'booStart__' + getVal ('innerbooStart'), 'booEnd__' + getVal ('innerbooEnd'), 'optionID__' + getVal ('optionID'), 'booPets__' + getVal ('booPets'), 'encID__' + getVal ('encID'), 'NO_CACHE'], ['minimumdeposit']);
	return true;
}

function checkdeposit (privilege) {
	var paid = document.booking.payConfirmed.value;
	var paying = document.booking.payAddition.value;	
	var deposit = document.booking.minimumDepositAmount.value;
	paying = paying.replace (/[^\.0-9]*/g, '');
	if ((parseFloat (paying) + parseFloat (paid)) < parseFloat (deposit)) {
		if (privilege == 1) {
			alert ('Note, minimum deposit not yet paid on this booking!');
			return true;			
		}	
		else {
			alert ('You must pay the minimum deposit amount or more\n...please correct and try again\n');
			return false;
		}
	}
	else {
		return true;
	}
}

function submitBookingForm (administrator, imagespath) {
	if (checkFormFields (mandatoryFields, '0')) {
		if (checksame ('userEmail', 'confirmEmail', 'Email address and confirmation do not match')) {
			if (checkdeposit (administrator)) {
				if (confirmBookingSubmit ()) {
					var checkMessage = '<div class="alert">Checking...<img src="' + imagespath + '/loading.gif" style="text-align: right; vertical-align: middle; padding-left: 25px;" /></div>';
					updateContent ('costsummary', checkMessage);
					doajax (['do__checkgivendates', 'booStart__' + getVal ('innerbooStart'), 'booEnd__' + getVal ('innerbooEnd'), 'optionID__' + getVal ('optionID'), 'encID__' + getVal ('encID'), 'NO_CACHE'], ['costsummary']);
					finishSubmit ();
				}
			}
		}
	}

}

function finishSubmit () {
	var placeholder = 'costsummary';
	var content = 'Dates selected';
	if (document.getElementById || document.all) {
		var place = document.getElementById ? document.getElementById (placeholder) : document.all [placeholder];
		if (place && typeof place.innerHTML != "undefined") {
			var checkingDone = ((place.innerHTML != "") && (place.innerHTML.indexOf ('Checking') == -1));
			if (checkingDone) {
				var contentPresent = place.innerHTML.indexOf (content) != -1;
				if (contentPresent) {
					document.booking.submit ();
				}
				else {
					updateContent ('booStart', '<span style="color: gray;">please reselect date</span><input id="innerbooStart" value="0000-00-00" type="hidden">'); 
					updateContent ('booEnd', '<span style="color: gray;">please reselect date</span><input id="innerbooEnd" value="0000-00-00" type="hidden">');
					updateContent ('costsummary', '<p>Both arrival and departure dates must be selected before cost can be calculated...</p>');
					updateContent ('minimumdeposit', '<input type="hidden" name="purchaseAmount" value="0"><input type="hidden" name="minimumDepositAmount" value="0">&nbsp;25% of total cost');
					doajax (['do__startcalendar', 'startcalmonth__' + getVal ('startcalmonth'), 'startcalyear__' + getVal ('startcalyear'), 'optionID__' + getVal ('optionID'), 'encID__' + getVal ('encID'), 'NO_CACHE'], ['startcalendar']);
					doajax (['do__endcalendar', 'endcalmonth__' + getVal ('endcalmonth'), 'endcalyear__' + getVal ('endcalyear'), 'optionID__' + getVal ('optionID'), 'encID__' + getVal ('encID'), 'NO_CACHE'], ['endcalendar']);
					alert ('Unfortunately your dates are not now available\n...please re-select arrival and departure dates\n');
					return false;
				}
			}
			else {
				setTimeout ("finishSubmit ()", 500);
			}	
		}
		else {
			return false;
		}
	}
	else {
		return false;
	}
}

function confirmBookingSubmit () {
	var msg = 'You have now chosen to submit the booking details on this form.';
	msg += ' The selected dates will be reserved against this booking and unavailable to other bookings.';
	msg += '\n\nOnly select \'OK\' if you are sure you wish to proceed.';
	msg += ' Otherwise you should select \'Cancel\' to continue editing or come back later!';
	var proceed = confirm (msg);
	if (proceed) {
		return true;
	}
	else {	
		return false;
	}
}

function toggledisplay (id, hardset) {
	if (document.getElementById(id)) {
		hardset = (typeof hardset == 'undefined') ? ((document.getElementById(id).style.display == 'block') ? 0 : 1) : hardset;
		document.getElementById(id).style.display = (hardset == 1) ? 'block' : 'none';
	}
}

// function toggledisplay (id) {
//		if (document.getElementById) {
//			document.getElementById(id).style.display = (document.getElementById(id).style.display == 'block') ? 'none' : 'block';
//		}
//		else if (document.all) {
//			document.all(id).style.display = (document.all(id).style.display == 'block') ? 'none' : 'block';
//		}
//	}

function swap (picPlace, changeInterval, picPoolSize, rowNumber, columnNumber, rootAddress, order, setup, id, imageType) {
	var format = (typeof imageType == 'undefined') ? "jpg" : imageType;
	var unique = id || 'pic';
	if (setup == 0) {
		document.write ('<table style="background-color: transparent; border: 0; margin: 10px auto; width: 100%;"><tr><td>');
		document.write ('<center><table style="border: 0;">');
		for (var i = 0; i < rowNumber; i++) {
			document.write ('<tr>');
			for (var j = 1; j <= columnNumber; j++) {
				var label = (i * columnNumber) + j;
				var labelOffset = ((j > picPoolSize) || (label > picPoolSize)) ? label - (Math.floor ((label - 1) / picPoolSize) * picPoolSize) : label;
				var sampler = rootAddress + labelOffset + "." + format;
				document.write ('<td><img src="' + sampler + '" alt="Thumbnail image of sample photograph" id="' + unique + label + '" name="' + unique + label + '" style="filter: RevealTrans(Transition=0)" /></td>');
			}
			document.write ('</tr>');
		}
		document.write ('</table><center>');
		document.write ('</td></tr></table>');
	}
	setup++;
	if (setup > picPoolSize) {
		setup = 1;
	}	
	var picTotal = rowNumber * columnNumber;
	var swapMethod = 10;
	var swapBoxInterval = 1;
	if (document.all) {
		userBrowser = "IE";
	}
	else if (!document.all && document.getElementById) {
		userBrowser = "OK";
	}
	else {
		userBrowser = "unsupported";
	}
	var picID = unique + picPlace;
	var selectSourceLabel = (order == "sequence") ? setup : rand (picPoolSize);
	var selectSourceName = rootAddress + selectSourceLabel + "." + format;
	if (userBrowser == "IE") {
		var p = eval ("document.all." + picID);
		p.filters.RevealTrans.Apply ();
		p.filters.RevealTrans.Transition = swapMethod;
		p.filters.RevealTrans.Duration = swapBoxInterval;
		p.src = selectSourceName;
		p.filters.RevealTrans.Play ();
	}
	else if (userBrowser == "OK") {
		var p = eval ('document.getElementById("' + picID + '")');
		p.src = selectSourceName;
	}
	else if (userBrowser == "unsupported") {
		alert ("Your browser doesn't support all features intended for this page!");
	}
	picPlace++;
	if (picPlace > picTotal) {
		picPlace = 1;
	}
	setTimeout ("swap (" + picPlace + ", " + changeInterval + ", " + picPoolSize + ", " + rowNumber + ", " + columnNumber + ", '" + rootAddress + "', '" + order + "', '" + setup + "', '" + unique + "', '" + format + "')", changeInterval);
}

function removeDiv (popupbox) {
	var boxdiv = document.getElementById (popupbox);
	if (boxdiv != null) {
		boxdiv.style.display = 'none';
		document.body.removeChild (boxdiv);
	}
}

function createNewDiv (popupbox, contents, xp, yp, width, height) {
	level = (typeof level == 'undefined') ? 10 : level + 1;
	var boxdiv = document.getElementById (popupbox);
	if (boxdiv == null) {
		boxdiv = document.createElement ('div');
		boxdiv.setAttribute ('id', popupbox);
		boxdiv.setAttribute ('class', 'popup');
		boxdiv.style.left = xp + 'px';
		boxdiv.style.top = yp + 'px';
		boxdiv.style.zIndex = level;
		if (navigator.appName.indexOf ('Microsoft Internet Explorer') == 0) {
			boxdiv.style.minHeight = height + 'px';
			boxdiv.style.minWidth = width + 'px';
		}
		else {
			boxdiv.style.height = 'auto!important';
			boxdiv.style.width = 'auto!important';
		}
		if (popupbox.indexOf ('tl-') == 0) {
			boxdiv.setAttribute ('onClick', 'this.style.display = "none";');
		}
		document.body.appendChild (boxdiv);
		boxdiv.innerHTML = contents;
	}
	else {
		boxdiv.style.display = 'block';
		boxdiv.style.zIndex = level;
	}
}

function getCoordinates (elementID) {
	var thisObject = document.getElementById (elementID);
	var positionLeft = positionTop = 0;
	if (thisObject.offsetParent) {
		do {
			positionLeft += thisObject.offsetLeft;
			positionTop += thisObject.offsetTop;
		} while (thisObject = thisObject.offsetParent);
		return [positionLeft, positionTop];
	}
}

function updatePCLCookie (cname, cvalue, path, cdomain) {
	document.cookie = cname + '=' + cvalue + ';path=' + path + ';domain=' + cdomain;
}

function getPCLCookies () {
	var cookiesHash = [];
	if (document.cookie != '') {
		var cookiesArray = document.cookie.split ('; ');
		for (var singleCookie = cookiesArray.length - 1; singleCookie >= 0; singleCookie --) {
			var cookieBits = cookiesArray [singleCookie].split ('=');
			cookiesHash [cookieBits [0]] = cookieBits [1];
		}
	}
	return cookiesHash;
}

function doPodWidth (action, podID) {
	place = document.getElementById ? document.getElementById (podID) : document.all[podID];
	if (place) {
		var desiredWidth = place.offsetWidth;
		if (action == 'set') {
			place.style.minWidth = desiredWidth + "px";
		}
		else {
			return desiredWidth;
		}
	}
	else {
		return 0;
	}
}

function checkPod (podWidth, move, podID) {
	var cookieName = 'ODEIM-options-' + podID;
	podWidth = podWidth * 1;
	var windowWidth = getWorkingWidth () * 1;
	var cookies = getPCLCookies ();
	var temp = new Array ();
	temp = cookies [cookieName].split (',');	
	var podLeft = temp [0] * 1;
	var podTop = temp [1] * 1;
	var needwidth = podLeft + podWidth;
	var gotwidth = windowWidth - 20;
	if (needwidth > gotwidth) {
		podLeft = windowWidth - podWidth - 20;
		var newposition = podLeft + ',' + podTop;
		updatePCLCookie (cookieName, newposition, '/cgi-bin', document.domain);
		if (move) {
			document.getElementById (podID).style.left = podLeft + "px";
		}
	}
}

// Thanks Alexandre: http://www.alexandre-gomes.com/?p=115
function getWorkingWidth () {  
    var ruler = document.createElement ('div');  
	ruler.style.position = "absolute";  
	ruler.style.top = "-1px";  
	ruler.style.left = "0px";  
	ruler.style.visibility = "hidden";  
	ruler.style.width = "100%";  
	ruler.style.height = "1px";  
    document.body.appendChild (ruler);  
    var w = ruler.offsetWidth;  
    document.body.removeChild (ruler);  
    return w;  
};

function getScrollBarWidth () {
	var inner = document.createElement('p');
	inner.style.width = "100%";
	inner.style.height = "200px";
	var outer = document.createElement('div');
	outer.style.position = "absolute";
	outer.style.top = "0px";
	outer.style.left = "0px";
	outer.style.visibility = "hidden";
	outer.style.width = "200px";
	outer.style.height = "150px";
	outer.style.overflow = "hidden";
	outer.appendChild (inner);
	document.body.appendChild (outer);
	var w1 = inner.offsetWidth;
	outer.style.overflow = 'scroll';
	var w2 = inner.offsetWidth;
	if (w1 == w2) w2 = outer.clientWidth;
	document.body.removeChild (outer);
	return (w1 - w2);
};

function sectionLeftEdge () {
	var sectionWidth = document.getElementById ('sectioncontainer').offsetWidth;
	// Note: offsetWidth = width + border + padding + margin
	var screenWidth = getWorkingWidth ();
	var leftEdge = parseInt ((screenWidth - sectionWidth)/2);
	return (leftEdge);
}

function verticalScrollVisible () {
	return (screen.height < document.body.offsetHeight);
}

// Thanks to http://stackoverflow.com/users/127792/coderjoe for this
function getQueryParams (webaddress) {
	//Use the window.location.search if we don't have a webaddress
	var query = webaddress || window.location.search;
	query = query.split ('?') [1]
	var pairs = query.split ('&');
	var qHash = {};
	var check = [];
	for (var i = 0; i < pairs.length; i++) {
		check = pairs [i].split ('=');
		qHash [decodeURIComponent (check[0])] = decodeURIComponent (check[1]);
	}
	return qHash;
}

function checkModifierKey (e) {
	e = (e) ? e : ((window.event) ? window.event : "");
	if (e) {
		var modifier = "";
		if (e.modifiers) {
			modifier += (e.modifiers & Event.ALT_MASK) ? 'ALT' : "";
			modifier += (e.modifiers & Event.CONTROL_MASK) ? 'CTRL' : "";
			modifier += (e.modifiers & Event.SHIFT_MASK) ? 'SHIFT' : "";
		}
		else {
			modifier += (e.altKey) ? 'ALT' : "";
			modifier += (e.ctrlKey) ? 'CTRL' : "";
			modifier += (e.shiftKey) ? 'SHIFT' : "";
		}
	}
	return (modifier);
}
