// JavaScript Document

// cache icon images
var imgDownload1 = new Image(); 
imgDownload1.src = varDirRoot + "/images/download-1.gif";

var l_currLBButton = null;		// current lightbox icon image user clicked on to manage lightboxes

function changeLightbox(menu) {
	var url = "lightboxes?cmd=view&lightbox_id=" + menu.value;
	
	var lightboxAction = document.getElementById("lightbox_action");
	if (lightboxAction != null) url += "&lightbox_action=" + lightboxAction.value;
	
	document.location.href = url;
}

function lightboxAction(ev, item_id, item_type) {	

	item_type = item_type.toUpperCase();
	
	ev = ev || window.event;
	
	var element = ev.target || ev.srcElement;
	
	// make sure user is logged in
	var userID = document.getElementById("curr_user_id");
	if (userID == null || userID.innerHTML == "") {
		window.location.href = varWebRootSSL + "/memberLogin.jsp?showMsg=lightbox";
		return false;
	}
	
	if (element != null && element.tagName != "IMG")
		element = document.getElementById("lightbox_icon");
	
	if (varDefaultLightboxID != 0) {
		var url = "lightboxes?cmd=setimg&item_id=" + item_id;
		
		if (item_type == "CD")
			url = "lightboxes?cmd=setcd&item_id=" + item_id;
			
		// if variable varDefaultLightboxID is set then do not show popup
		// toggle item in/out of lightbox based on element's current _off state
		// _off state will contain image icon for "lightbox-1" if in a lightbox
		
		if (right(element.getAttribute("_off"), 14) == "lightbox-0.gif") {
			// add item to default lightbox
			url += "&lightbox_id=" + varDefaultLightboxID;
		} else {
			// remove item from default lightbox by omitting the url param lightbox_id
		}		
		var ajaxUpdate = new ajaxUpdateLightboxItems(element);
		ajaxUpdate.update(url);
		return;
	}
	
	var mousePos = mouseCoords(ev);
	var mouseOffset = getMouseOffset(element, ev);
		
	var popup = document.getElementById("lightbox-popup");
	
	if (popup) {
		document.getElementById("hid.lb_item_type").value = item_type;
		document.getElementById("hid.lb_item_id").value = item_id;
		clearLBSelections(true);			
		popup.style.top = (mousePos.y - mouseOffset.y) + "px";
		popup.style.left = (mousePos.x - mouseOffset.x) + "px";
		popup.style.display = "block";
				
		l_currLBButton = element;
		
		StopBubble(ev);
		document.onclick = checkClosePopUp;
		
		checkLightboxesForItems(item_type, item_id);
	}
}

function checkLightboxesForItems(item_type, item_id) {
	var url = "lightboxes?item_id=" + item_id;
	
	if (item_type == "CD")
		url += "&cmd=getcd";
	else
		url += "&cmd=getimg";
	
	// reinitialize Ajax object for Opera compatability
	if (window.ActiveXObject) {
		xmlHttpLB = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) {
		xmlHttpLB = new XMLHttpRequest();
	}
	
	xmlHttpLB.open("GET", url, true);	//3rd param: true = asynchronous; false = synchronous
	xmlHttpLB.onreadystatechange = ajxCheckLightboxesReturn;
	xmlHttpLB.send(null);
}

function ajxCheckLightboxesReturn() {
	if (xmlHttpLB.readyState != 4 || xmlHttpLB.status != 200) return true;
	
	var res = xmlHttpLB.responseXML;
	var chkLightboxes = document.getElementsByName("chk.lightbox");
			
	if (res != null) {
		var records = res.getElementsByTagName("records");
		if (records != null && records.length > 0) {
			var lightbox = records[0].getElementsByTagName("lightbox_id");
			
			for (var i = 0; i < lightbox.length; i++) {
				var lightbox_id = lightbox[i].firstChild.nodeValue;
				
				for (var j = 0; j < chkLightboxes.length; j++) {
					if (chkLightboxes[j].value == lightbox_id) {
						chkLightboxes[j].checked = true;
						break;
					}
				}
			}
		}
	}
	
	for (var i = 0; i < chkLightboxes.length; i++)
		chkLightboxes[i].disabled = false;
}

function clearLBSelections(disableAll) {
	var lightboxes = document.getElementsByName("chk.lightbox");
	for (var i = 0; i < lightboxes.length; i++) {
		lightboxes[i].checked = false;
		lightboxes[i].disabled = (disableAll == null ? false : disableAll);
	}
}

function setLBItems() {
	var itemType = document.getElementById("hid.lb_item_type").value;
	var url = "lightboxes?item_id=" + document.getElementById("hid.lb_item_id").value;
	var mode = document.getElementById("hid.mode");
	if (mode != null) mode = mode.value;
	
	if (itemType == "IMG")
		url += "&cmd=setimg";
	else
		url += "&cmd=setcd";
	
	var currLightBox = -1;
	var currLightboxName = "";
	
	if (mode != null && mode == "lightbox") {
		var lightbox_id = document.getElementById("lightbox-sel");
		currLightBox = lightbox_id.options[lightbox_id.selectedIndex].value;
		currLightboxName = lightbox_id.options[lightbox_id.selectedIndex].text;
	}
	
	var lightboxes = document.getElementsByName("chk.lightbox");
	for (var i = 0; i < lightboxes.length; i++) {
		if (lightboxes[i].checked) {
			url += "&lightbox_id=" + lightboxes[i].value;
			if (currLightBox > 0 && currLightBox == lightboxes[i].value)
				currLightBox = 0;
		}
	}
	
	if (currLightBox > 0) {
		if (itemType == "IMG") itemType = "Image";	
		else if (itemType == "EXT") type = "External";
	
		if (!confirm("Remove " + itemType + " item from " + currLightboxName + " Lightbox?")) {
			hidePopup("lightbox-popup");
			return false;
		}
		
		// if removing item from current viewing lightbox then compute the need to
		// bring in new item for position 40 when slite for current item is removed
		var currPage = document.getElementById("hid.currPage");
		var totalPage = document.getElementById("hid.totalPages");

		if (currPage && totalPage && currPage.value != totalPage.value)
			url += "&get_itm_pos=" + ((currPage.value * 40) - 1);		// perform -1 to account for MySQl offset 0 for LIMIT FUNCTION
	}
	
	var ajaxUpdate = new ajaxUpdateLightboxItems(l_currLBButton, (currLightBox > 0));
	ajaxUpdate.update(url);
	
	hidePopup("lightbox-popup");
}

function ajaxUpdateLightboxItems(eventObj, deleteNode) {			// This is the object constructor
	var that = this;														// A workaround for some javascript idiosyncrocies
	var updating = false;													// Set to true if this object is already working on a request
	this.callback = function() {}											// A post-processing call -- a stub you overwrite.
	this.update = function(url) {											// Initiates the server call.
		if (updating == true) { return false; }								// Abort if we're already processing a call.
		updating = true;												// Set the updating flag.
		var AJAX = null;												// Initialize the AJAX variable.
		if (window.XMLHttpRequest)										// Are we working with mozilla?
			AJAX = new XMLHttpRequest();									//  Yes -- this is mozilla.
		else															// Not Mozilla, must be IE
			AJAX = new ActiveXObject("Microsoft.XMLHTTP");					//  Wheee, ActiveX, how do we format c: again?

		if (AJAX == null) {												// If we couldn't initialize Ajax...
			alert("Your browser doesn't support AJAX.");						// Sorry msg.
			return false;												// Return false (WARNING - SAME AS ALREADY PROCESSING!)

		} else {
			AJAX.onreadystatechange = function() {							// When the browser has the request info..
				if (AJAX.readyState == 4 || AJAX.readyState == "complete") {	// see if the complete flag is set.
				
					var res = AJAX.responseXML;
					var xmlStatus = res.getElementsByTagName("status");

					// if return response is "success" then proceed
					if (xmlStatus != null && checkXMLResponse(xmlStatus) == 1) {
						var xmlCurrLightbox = res.getElementsByTagName("current_lightbox");
						if (xmlCurrLightbox != null && xmlCurrLightbox.length > 0)							
							setPageItemCount(xmlCurrLightbox);
						
						var xmlNextItem = res.getElementsByTagName("next_item");
						if (l_deleteNode || (xmlNextItem != null && xmlNextItem.length > 0)) {
							var item_type = xmlStatus[0].getElementsByTagName("item_type")[0].firstChild.nodeValue;
							doDeleteSlide(l_eventObj, item_type, xmlNextItem);

						} else {
							var numLightboxes = xmlStatus[0].getElementsByTagName("in_lightboxes")[0].firstChild.nodeValue;
							
							var itemType  = null;
							if (xmlStatus[0].getElementsByTagName("item_type")[0] != null)
								itemType = xmlStatus[0].getElementsByTagName("item_type")[0].firstChild.nodeValue;
							
							if (numLightboxes == 0) {
								l_eventObj.src = varDirRoot + "/images/lightbox-0.gif";
								l_eventObj.setAttribute("_on", varDirRoot + "/images/lightbox-1.gif");
								l_eventObj.setAttribute("_off", varDirRoot + "/images/lightbox-0.gif");
								l_eventObj.title = (varDefaultLightboxID != 0 ? "Add To Lightbox" : "Add To Lightboxes");
								
								if (l_eventObj.id && l_eventObj.id == "lightbox_icon") {
									var textNode = l_eventObj.nextSibling;
									if (textNode != null) {
										if (itemType != null && itemType == "CD")
											textNode.nodeValue = (varDefaultLightboxID != 0 ? "Add Photo CD To Lightbox" : "Add Photo CD To Lightboxes");
										else
											textNode.nodeValue = (varDefaultLightboxID != 0 ? "Add To Lightbox" : "Add To Lightboxes");
									}
								}
	
							} else {																
								l_eventObj.src = varDirRoot + "/images/lightbox-1.gif";
								l_eventObj.setAttribute("_on", varDirRoot + "/images/lightbox-1.gif");
								l_eventObj.setAttribute("_off", varDirRoot + "/images/lightbox-1.gif");
								
								l_eventObj.title = (varDefaultLightboxID != 0 ? "Remove From Lightbox" : "Manage In Lightboxes");
								
								if (l_eventObj.id && l_eventObj.id == "lightbox_icon") {
									var textNode = l_eventObj.nextSibling;
									if (textNode != null) {
										if (itemType != null && itemType == "CD")
											textNode.nodeValue = (varDefaultLightboxID != 0 ? "Remove Photo CD From Lightbox" : "Manage Photo CD In Lightboxes");
										else
											textNode.nodeValue = (varDefaultLightboxID != 0 ? "Remove From Lightbox" : "Manage In Lightboxes");
									}
								}
							}
						}
					}
					
					delete AJAX;										//   delete the AJAX object since it's done.
					updating = false;									//   Set the updating flag to false so we can do a new request
					that.callback();									//   Call the post-processing function.
				}													// End Ajax readystate check.
			}														// End create post-process fucntion block.

			url += "&ts=" + (new Date() * 1);								// Append date to url (so the browser doesn't cache the call)
			AJAX.open("GET", url, true);									// Open the url this object was set-up with.
			AJAX.send(null);											// Send the request.
			return true;												// Everything went a-ok.
		}															// End Ajax setup aok if/else block
	}
	
	// This area set up on constructor calls.
	var l_eventObj = eventObj;											// Remember the layer associated with this object.
	var l_deleteNode = deleteNode;
}

function ajaxUpdateRanking(eventObj) {										// This is the object constructor
	var that = this;													// A workaround for some javascript idiosyncrocies
	var updating = false;												// Set to true if this object is already working on a request
	this.callback = function() {}											// A post-processing call -- a stub you overwrite.
	this.update = function(url) {											// Initiates the server call.
		if (updating == true) { return false; }								// Abort if we're already processing a call.
		updating = true;												// Set the updating flag.
		var AJAX = null;												// Initialize the AJAX variable.
		if (window.XMLHttpRequest)										// Are we working with mozilla?
			AJAX = new XMLHttpRequest();									//  Yes -- this is mozilla.
		else															// Not Mozilla, must be IE
			AJAX = new ActiveXObject("Microsoft.XMLHTTP");					//  Wheee, ActiveX, how do we format c: again?

		if (AJAX == null) {												// If we couldn't initialize Ajax...
			alert("Your browser doesn't support AJAX.");						// Sorry msg.
			return false;												// Return false (WARNING - SAME AS ALREADY PROCESSING!)
		
		} else {
			AJAX.onreadystatechange = function() {							// When the browser has the request info..
				if (AJAX.readyState == 4 || AJAX.readyState=="complete") {		//   see if the complete flag is set.
				
					var res = AJAX.responseXML;
					var xmlStatus = res.getElementsByTagName("status");

					// if return response is "success" then proceed
					if (xmlStatus != null && checkXMLResponse(xmlStatus) == 1) {
						var rank = xmlStatus[0].getElementsByTagName("ranking")[0].firstChild.nodeValue;
		
						drawRankings(l_eventObj, rank);
					}
					
					delete AJAX;										//   delete the AJAX object since it's done.
					updating = false;									//   Set the updating flag to false so we can do a new request
					that.callback();									//   Call the post-processing function.
				}													// End Ajax readystate check.
			}														// End create post-process fucntion block.

			url += "&ts=" + (new Date() * 1);								// Append date to url (so the browser doesn't cache the call)
			AJAX.open("GET", url, true);									// Open the url this object was set-up with.
			AJAX.send(null);											// Send the request.
			return true;												// Everything went a-ok.
		}															// End Ajax setup aok if/else block
	}
	
	// This area set up on constructor calls.
	var l_eventObj = eventObj;											// Remember the layer associated with this object.
}

function ajaxUpdateFlag(eventObj) {										// This is the object constructor
	var that = this;													// A workaround for some javascript idiosyncrocies
	var updating = false;												// Set to true if this object is already working on a request
	this.callback = function() {}											// A post-processing call -- a stub you overwrite.
	this.update = function(url) {											// Initiates the server call.
		if (updating == true) { return false; }								// Abort if we're already processing a call.
		updating = true;												// Set the updating flag.
		var AJAX = null;												// Initialize the AJAX variable.
		if (window.XMLHttpRequest)										// Are we working with mozilla?
			AJAX = new XMLHttpRequest();									//  Yes -- this is mozilla.
		else															// Not Mozilla, must be IE
			AJAX = new ActiveXObject("Microsoft.XMLHTTP");					//  Wheee, ActiveX, how do we format c: again?

		if (AJAX == null) {												// If we couldn't initialize Ajax...
			alert("Your browser doesn't support AJAX.");						// Sorry msg.
			return false;												// Return false (WARNING - SAME AS ALREADY PROCESSING!)
		
		} else {
			AJAX.onreadystatechange = function() {							// When the browser has the request info..
				if (AJAX.readyState == 4 || AJAX.readyState=="complete") {		//   see if the complete flag is set.
				
					var res = AJAX.responseXML;
					var xmlStatus = res.getElementsByTagName("status");

					// if return response is "success" then proceed
					if (xmlStatus != null && checkXMLResponse(xmlStatus) == 1) {
						var flag = xmlStatus[0].getElementsByTagName("flag")[0].firstChild.nodeValue;
		
						if (flag == "1")
							l_eventObj.src = varWebRoot + "/images/flag-1.gif";
						else
							l_eventObj.src = varWebRoot + "/images/flag-0.gif";
					}
					
					delete AJAX;										//   delete the AJAX object since it's done.
					updating = false;									//   Set the updating flag to false so we can do a new request
					that.callback();									//   Call the post-processing function.
				}													// End Ajax readystate check.
			}														// End create post-process fucntion block.

			url += "&ts=" + (new Date() * 1);								// Append date to url (so the browser doesn't cache the call)
			AJAX.open("GET", url, true);									// Open the url this object was set-up with.
			AJAX.send(null);											// Send the request.
			return true;												// Everything went a-ok.
		}															// End Ajax setup aok if/else block
	}
	
	// This area set up on constructor calls.
	var l_eventObj = eventObj;											// Remember the layer associated with this object.
}

function ajaxUpdateSorting(eventObj) {										// This is the object constructor
	var that = this;													// A workaround for some javascript idiosyncrocies
	var updating = false;												// Set to true if this object is already working on a request
	this.callback = function() {}											// A post-processing call -- a stub you overwrite.
	this.update = function(url, param) {											// Initiates the server call.
		if (updating == true) { return false; }								// Abort if we're already processing a call.
		updating = true;												// Set the updating flag.
		var AJAX = null;												// Initialize the AJAX variable.
		if (window.XMLHttpRequest)										// Are we working with mozilla?
			AJAX = new XMLHttpRequest();									//  Yes -- this is mozilla.
		else															// Not Mozilla, must be IE
			AJAX = new ActiveXObject("Microsoft.XMLHTTP");					//  Wheee, ActiveX, how do we format c: again?

		if (AJAX == null) {												// If we couldn't initialize Ajax...
			alert("Your browser doesn't support AJAX.");						// Sorry msg.
			return false;												// Return false (WARNING - SAME AS ALREADY PROCESSING!)
		
		} else {
			AJAX.onreadystatechange = function() {							// When the browser has the request info..
				if (AJAX.readyState == 4 || AJAX.readyState=="complete") {		//   see if the complete flag is set.
				
					var res = AJAX.responseXML;
					var xmlStatus = res.getElementsByTagName("status");

					// if return response is "success" then proceed
					if (xmlStatus != null && checkXMLResponse(xmlStatus) == 1) {
						// do nothing else
					}
					
					delete AJAX;										//   delete the AJAX object since it's done.
					updating = false;									//   Set the updating flag to false so we can do a new request
					that.callback();									//   Call the post-processing function.
				}													// End Ajax readystate check.
			}														// End create post-process fucntion block.

			param += "&ts=" + (new Date() * 1);							// Append date to url (so the browser doesn't cache the call)
			AJAX.open("POST", url, true);									// Open the url this object was set-up with.
			AJAX.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			AJAX.send(param);											// Send the request.
			return true;												// Everything went a-ok.
		}															// End Ajax setup aok if/else block
	}
	
	// This area set up on constructor calls.
	var l_eventObj = eventObj;											// Remember the layer associated with this object.
}

function ajaxUpdateMemo(eventObj, updateChat) {								// This is the object constructor
	var that = this;													// A workaround for some javascript idiosyncrocies
	var updating = false;												// Set to true if this object is already working on a request
	this.callback = function() {}											// A post-processing call -- a stub you overwrite.
	this.update = function(url, param) {									// Initiates the server call.
		if (updating == true) { return false; }								// Abort if we're already processing a call.
		updating = true;												// Set the updating flag.
		var AJAX = null;												// Initialize the AJAX variable.
		if (window.XMLHttpRequest)										// Are we working with mozilla?
			AJAX = new XMLHttpRequest();									//  Yes -- this is mozilla.
		else															// Not Mozilla, must be IE
			AJAX = new ActiveXObject("Microsoft.XMLHTTP");					//  Wheee, ActiveX, how do we format c: again?

		if (AJAX == null) {												// If we couldn't initialize Ajax...
			alert("Your browser doesn't support AJAX.");						// Sorry msg.
			return false;												// Return false (WARNING - SAME AS ALREADY PROCESSING!)
		
		} else {
			AJAX.onreadystatechange = function() {							// When the browser has the request info..
				if (AJAX.readyState == 4 || AJAX.readyState=="complete") {		//   see if the complete flag is set.
				
					var res = AJAX.responseXML;
					var xmlStatus = res.getElementsByTagName("status");

					// if return response is "success" then proceed
					if (xmlStatus != null && checkXMLResponse(xmlStatus) == 1) {
						if (l_updateChat == "true") {
							var xmlChats = res.getElementsByTagName("records");
							if (xmlChats != null && xmlChats.length > 0)
								insertChat(xmlChats);
						}
					}
					
					delete AJAX;										//   delete the AJAX object since it's done.
					updating = false;									//   Set the updating flag to false so we can do a new request
					that.callback();									//   Call the post-processing function.
				}													// End Ajax readystate check.
			}														// End create post-process fucntion block.

			param += "&ts=" + (new Date() * 1);							// Append date to url (so the browser doesn't cache the call)
			AJAX.open("POST", url, true);									// Open the url this object was set-up with.
			AJAX.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			AJAX.send(param);											// Send the request.
			return true;												// Everything went a-ok.
		}															// End Ajax setup aok if/else block
	}
	
	// This area set up on constructor calls.
	var l_eventObj = eventObj;											// Remember the layer associated with this object.
	var l_updateChat = updateChat;
}

function ajaxUpdateLightbox(eventObj) {										// This is the object constructor
	var that = this;													// A workaround for some javascript idiosyncrocies
	var updating = false;												// Set to true if this object is already working on a request
	this.callback = function() {}											// A post-processing call -- a stub you overwrite.
	this.update = function(url, param) {									// Initiates the server call.
		if (updating == true) { return false; }								// Abort if we're already processing a call.
		updating = true;												// Set the updating flag.
		var AJAX = null;												// Initialize the AJAX variable.
		if (window.XMLHttpRequest)										// Are we working with mozilla?
			AJAX = new XMLHttpRequest();									//  Yes -- this is mozilla.
		else															// Not Mozilla, must be IE
			AJAX = new ActiveXObject("Microsoft.XMLHTTP");					//  Wheee, ActiveX, how do we format c: again?

		if (AJAX == null) {												// If we couldn't initialize Ajax...
			alert("Your browser doesn't support AJAX.");						// Sorry msg.
			return false;												// Return false (WARNING - SAME AS ALREADY PROCESSING!)
		
		} else {
			AJAX.onreadystatechange = function() {							// When the browser has the request info..
				if (AJAX.readyState == 4 || AJAX.readyState=="complete") {		//   see if the complete flag is set.
				
					var res = AJAX.responseXML;
					var xmlStatus = res.getElementsByTagName("status");

					// if return response is "success" then proceed
					if (xmlStatus != null && checkXMLResponse(xmlStatus) == 1) {
						saveReturn();
					}
					
					delete AJAX;										//   delete the AJAX object since it's done.
					updating = false;									//   Set the updating flag to false so we can do a new request
					that.callback();									//   Call the post-processing function.
				}													// End Ajax readystate check.
			}														// End create post-process fucntion block.

			param += "&ts=" + (new Date() * 1);							// Append date to url (so the browser doesn't cache the call)
			AJAX.open("POST", url, true);									// Open the url this object was set-up with.
			AJAX.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			AJAX.send(param);											// Send the request.
			return true;												// Everything went a-ok.
		}															// End Ajax setup aok if/else block
	}
	
	// This area set up on constructor calls.
	var l_eventObj = eventObj;											// Remember the layer associated with this object.
}

function ajaxSetLBItemStatus(eventObj) {									// This is the object constructor
	var that = this;													// A workaround for some javascript idiosyncrocies
	var updating = false;												// Set to true if this object is already working on a request
	this.callback = function() {}											// A post-processing call -- a stub you overwrite.
	this.update = function(url, param) {									// Initiates the server call.
		if (updating == true) { return false; }								// Abort if we're already processing a call.
		updating = true;												// Set the updating flag.
		var AJAX = null;												// Initialize the AJAX variable.
		if (window.XMLHttpRequest)										// Are we working with mozilla?
			AJAX = new XMLHttpRequest();									//  Yes -- this is mozilla.
		else															// Not Mozilla, must be IE
			AJAX = new ActiveXObject("Microsoft.XMLHTTP");					//  Wheee, ActiveX, how do we format c: again?

		if (AJAX == null) {												// If we couldn't initialize Ajax...
			alert("Your browser doesn't support AJAX.");						// Sorry msg.
			return false;												// Return false (WARNING - SAME AS ALREADY PROCESSING!)
		
		} else {
			AJAX.onreadystatechange = function() {							// When the browser has the request info..
				if (AJAX.readyState == 4 || AJAX.readyState=="complete") {		//   see if the complete flag is set.
				
					var res = AJAX.responseXML;
					var xmlStatus = res.getElementsByTagName("status");

					// if return response is "success" then proceed
					if (xmlStatus != null && checkXMLResponse(xmlStatus) == 1) {
						var xmlData = res.getElementsByTagName("records");
						if (xmlData != null && xmlData.length > 0)
							setItemStatusIcons(xmlData, l_eventObj);
					}
					
					delete AJAX;										//   delete the AJAX object since it's done.
					updating = false;									//   Set the updating flag to false so we can do a new request
					that.callback();									//   Call the post-processing function.
				}													// End Ajax readystate check.
			}														// End create post-process fucntion block.

			param += "&ts=" + (new Date() * 1);							// Append date to url (so the browser doesn't cache the call)
			AJAX.open("POST", url, true);									// Open the url this object was set-up with.
			AJAX.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			AJAX.send(param);											// Send the request.
			return true;												// Everything went a-ok.
		}															// End Ajax setup aok if/else block
	}
	
	// This area set up on constructor calls.
	var l_eventObj = eventObj;											// Remember the layer associated with this object.
}

function drawRankings(rankCont, rank) {
	var numStar = 0;
	
	for (var i = 0; i < rankCont.childNodes.length; i++) {
		if (rankCont.childNodes[i].nodeName == "#text") continue;
		if (rankCont.childNodes[i].id == "img-flag") continue;
			
		numStar++;
		
		if (numStar <= rank)
			rankCont.childNodes[i].src = varDirRoot + "/images/star-1.gif";
		else
			rankCont.childNodes[i].src = varDirRoot + "/images/star-0.gif";
	}
}

function doDeleteSlide(slideElement, item_type, nextItem) {
	if (slideElement == null) return false;
	
	var classCheck = "slide"
	if (item_type == "CD") classCheck = "cd";
	
	if (slideElement.id != classCheck && slideElement.className != classCheck) {
		do {
			slideElement = slideElement.parentNode;
			if (slideElement && (slideElement.id == classCheck || slideElement.className == classCheck))
				break;
			
		} while (slideElement && slideElement.tagName != "HTML");
	}

	if (!slideElement || (slideElement.id != classCheck && slideElement.className != classCheck)) return false;

	var slideContainer = slideElement.parentNode;
	slideContainer.removeChild(slideElement);

	if (nextItem != null && nextItem.length > 0) {
		var newSlide = createSlide(nextItem);
		if (newSlide) {
			slideContainer.appendChild(newSlide);
			newSlide.setAttribute('DragObj', 0);
			
			setPositions(document.getElementById('lightbox-wrapper'));
		}
	}
}

function createSlide(itemXML) {
	var item_type = itemXML[0].getElementsByTagName("item_type")[0].firstChild.nodeValue.toLowerCase();
	
	if (item_type == "img")
		return createSlideImg(itemXML);
	else if (item_type == "cd")
		return createSlideCD(itemXML);
	else if (item_type == "ext")
		return createSlideEXT(itemXML);
}

function createSlideImg(itemXML) {
	var item_type = itemXML[0].getElementsByTagName("item_type")[0].firstChild.nodeValue.toLowerCase();	
	var item_id = itemXML[0].getElementsByTagName("image_id")[0].firstChild.nodeValue;
	var lightbox_item_id = itemXML[0].getElementsByTagName("lightbox_item_id")[0].firstChild.nodeValue;
	var item_name = itemXML[0].getElementsByTagName("image_name")[0].firstChild.nodeValue;
	var status = itemXML[0].getElementsByTagName("item_status")[0].firstChild.nodeValue;
	
	var keywords = "";
	
	if (itemXML[0].getElementsByTagName("keywords")[0].firstChild != null)
		keywords = itemXML[0].getElementsByTagName("keywords")[0].firstChild.nodeValue+ "/";
		
	var slide = document.createElement("div");
	slide.setAttribute("id", "img-" + item_id);
	slide.className = "slide";
	
	var itmName = document.createElement("div");
	itmName.setAttribute("id", "lb-item-name");
	itmName.innerHTML = "Image: " + item_name.toUpperCase();
	slide.appendChild(itmName);
	
	var rmvIcon = document.createElement("img");
	rmvIcon.setAttribute("id", "lb-item-del");
	rmvIcon.setAttribute("align", "middle");
	rmvIcon.setAttribute("title", "Remove from current lightbox");
	rmvIcon.src = varDirRoot + "/images/redX.gif";
	rmvIcon.onclick = function(ev) { ev = ev || window.event; removeFromLightbox(ev, lightbox_item_id); }
	slide.appendChild(rmvIcon);
	
	var thumbNailImg = document.createElement("img");
	thumbNailImg.className = "img-thm";
	thumbNailImg.src = varDirRoot + itemXML[0].getElementsByTagName("thumb_path")[0].firstChild.nodeValue;
	
	var imgLink = document.createElement("a");
	imgLink.href = varWebRoot + "/stock-photo/" + keywords + item_name.toUpperCase() + "?lightbox_item_id=" + lightbox_item_id;
	imgLink.appendChild(thumbNailImg);
	
	var thumbNailDiv = document.createElement("div");
	thumbNailDiv.setAttribute("id", "free-img-wrapper");
	thumbNailDiv.appendChild(imgLink);
	
	slide.appendChild(thumbNailDiv);
	
	var rankings = document.createElement("div");
	rankings.setAttribute("id", "img-ranking");
	
	var flag = document.createElement("img");
	flag.src = varDirRoot + "/images/flag-0.gif"; 
	flag.setAttribute("id", "img-flag");
	flag.onclick = function(ev) { ev = ev || window.event; setFlag(ev, lightbox_item_id); }
		
	if 	(itemXML[0].getElementsByTagName("flag")[0].firstChild != null) {
		if (itemXML[0].getElementsByTagName("flag")[0].firstChild.nodeValue == "1")
			flag.src = varDirRoot + "/images/flag-1.gif"; 
	}
	
	rankings.appendChild(flag);
	
	var rank = 0;
	
	if (itemXML[0].getElementsByTagName("ranking")[0] != null)
		rank = itemXML[0].getElementsByTagName("ranking")[0].firstChild.nodeValue;
		
	for (var i = 1; i <= 5; i++) {
		var star = document.createElement("img");
		if (i <= rank)
			star.src = varDirRoot + "/images/star-1.gif";
		else
			star.src = varDirRoot + "/images/star-0.gif";
		
		star.onclick = function(ev) { ev = ev || window.event; setRanking(ev, lightbox_item_id); }
		
		rankings.appendChild(star);
	}
	
	slide.appendChild(rankings);
	
	var buttons = document.createElement("div");
	var keywords = "";
	if (itemXML[0].getElementsByTagName("keywords")[0] != null)
		keywords = itemXML[0].getElementsByTagName("keywords")[0].firstChild.nodeValue;
		
	buttons.setAttribute("id", "img-opt");
		
	if (itemXML[0].getElementsByTagName("editorial_use_only")[0] != null) {
	
		var itmRestricted = document.createElement("img");
		itmRestricted.src = varDirRoot + "/images/restricted.gif";
		itmRestricted.setAttribute("title", "Restricted Use:\nNot Model or Property Released.\nFor Editorial or Personal use only.");
		buttons.appendChild(itmRestricted);
		buttons.appendChild(document.createTextNode(" "));
	}
	
	var lbIcon = document.createElement("img");
	lbIcon.src = varDirRoot + "/images/lightbox-1.gif";
	lbIcon.setAttribute("title", "Remove from Lightbox");
	lbIcon.onclick = function(ev) { ev = ev || window.event; lightboxAction(ev, item_id, item_type); }
	buttons.appendChild(lbIcon);

	buttons.appendChild(document.createTextNode(" "));

	var itmInfo = document.createElement("img");
	itmInfo.src = varDirRoot + "/images/cart-0.gif";
	itmInfo.setAttribute("_on", varDirRoot + "/images/cart-1.gif");
	itmInfo.setAttribute("_off", varDirRoot + "/images/cart-0.gif");
	itmInfo.setAttribute("title", "Image Info & Buy");
	itmInfo.onclick = function(ev) { imageDetail("/" + keywords, item_name); }
	itmInfo.onmouseover = function(ev) { ev = ev || window.event; imgOptOver(ev); }
	itmInfo.onmouseout = function(ev) { ev = ev || window.event; imgOptOut(ev); }
	buttons.appendChild(itmInfo);
	
	buttons.appendChild(document.createTextNode(" "));
	
	var itmLock = document.createElement("img");
	if (status == "L") {
		itmLock.src = varDirRoot + "/images/lock-0.gif";
		itmLock.setAttribute("_on", varDirRoot + "/images/lock-1.gif");
		itmLock.setAttribute("_off", varDirRoot + "/images/lock-0.gif");
		itmLock.setAttribute("title", "Click to allow changes & comments");

	} else {
		itmLock.src = varDirRoot + "/images/unlock-0.gif";
		itmLock.setAttribute("_on", varDirRoot + "/images/unlock-1.gif");
		itmLock.setAttribute("_off", varDirRoot + "/images/unlock-0.gif");
		itmLock.setAttribute("title", "Click to Lock from changes & comments");			
	}

	itmLock.setAttribute("id", "lock_icon");
	itmLock.onclick = function(ev) { ev = ev || window.event; lightboxItemLock(ev, lightbox_item_id); }
	itmLock.onmouseover = function(ev) { ev = ev || window.event; imgOptOver(ev); }
	itmLock.onmouseout = function(ev) { ev = ev || window.event; imgOptOut(ev); }

	buttons.appendChild(itmLock);
	
	buttons.appendChild(document.createTextNode(" "));

	var itmMemo = document.createElement("img");
	itmMemo.src = varDirRoot + "/images/chat-0.gif";
	itmMemo.setAttribute("_off", varDirRoot + "/images/chat-0.gif");
	
	if (status == "L") {
		itmMemo.setAttribute("_on", varDirRoot + "/images/chat-0.gif");
		
	} else {
		itmMemo.setAttribute("_on", varDirRoot + "/images/chat-1.gif");
		itmMemo.setAttribute("title", "Add Memo for this item");			
	}

	itmMemo.setAttribute("id", "memo_icon");
	itmMemo.onclick = function(ev) { ev = ev || window.event; lightboxItemMemo(ev, lightbox_item_id); }
	itmMemo.onmouseover = function(ev) { ev = ev || window.event; imgOptOver(ev); }
	itmMemo.onmouseout = function(ev) { ev = ev || window.event; imgOptOut(ev); }
	
	buttons.appendChild(itmMemo);
	
	if (itemXML[0].getElementsByTagName("purchased")[0] != null) {
		buttons.appendChild(document.createTextNode(" "));
	
		var itmPurchased = document.createElement("img");
		itmPurchased.src = varDirRoot + "/images/check-1.gif";
		itmPurchased.setAttribute("title", "You have previously licensed this image");
		itmPurchased.style.cssText = "cursor:default;";
		buttons.appendChild(itmPurchased);
	}
	
	slide.appendChild(buttons);
	
	return slide;
}

function createSlideCD(itemXML) {
	var item_type = itemXML[0].getElementsByTagName("item_type")[0].firstChild.nodeValue.toLowerCase();	
	var item_id = itemXML[0].getElementsByTagName("cd_id")[0].firstChild.nodeValue;
	var lightbox_item_id = itemXML[0].getElementsByTagName("lightbox_item_id")[0].firstChild.nodeValue;
	var item_name = itemXML[0].getElementsByTagName("cd_name")[0].firstChild.nodeValue;
	var cd_name_url = itemXML[0].getElementsByTagName("cd_name_url")[0].firstChild.nodeValue;
	var category_url = itemXML[0].getElementsByTagName("category_url")[0].firstChild.nodeValue;
	var status = itemXML[0].getElementsByTagName("item_status")[0].firstChild.nodeValue;
	
	//	strTemp.append("<img id=\"img-flag\" src=\"" + dirRoot + "/images/flag-1.gif\" onClick=\"setFlag(event, " +  rset.getInt("lightbox_item_id") + ")\">");

	var slide = document.createElement("div");
	slide.setAttribute("id", "cd-" + item_id);
	slide.className = "cd";
	
	var itmName = document.createElement("div");
	itmName.setAttribute("id", "lb-item-name");
	itmName.innerHTML = "CD: " + item_name;
	slide.appendChild(itmName);
	
	var rmvIcon = document.createElement("img");
	rmvIcon.setAttribute("id", "lb-item-del");
	rmvIcon.setAttribute("align", "middle");
	rmvIcon.setAttribute("title", "Remove from current lightbox");
	rmvIcon.src = varDirRoot + "/images/redX.gif";
	rmvIcon.onclick = function(ev) { ev = ev || window.event; removeFromLightbox(ev, lightbox_item_id); }
	slide.appendChild(rmvIcon);
	
	var cdCover = document.createElement("img");
	cdCover.setAttribute("id", "cd-cover");
	cdCover.src = varDirRoot + itemXML[0].getElementsByTagName("cover_image")[0].firstChild.nodeValue;
	
	var imgLink = document.createElement("a");
	imgLink.href = varWebRoot + "/stock-photo-cd/" + category_url + "/" + cd_name_url + "/" + item_id + "/1/stock-photos.html";
	imgLink.appendChild(cdCover);
	
	var cdWrapper = document.createElement("div");
	cdWrapper.setAttribute("id", "cd-wrapper");
	cdWrapper.appendChild(imgLink);
	
	var imgCount = document.createElement("div");
	imgCount.setAttribute("id", "img-count");
	imgCount.innerHTML = itemXML[0].getElementsByTagName("num_images")[0].firstChild.nodeValue + " Images";
	
	cdWrapper.appendChild(imgCount);
	
	var rankings = document.createElement("div");
	rankings.setAttribute("id", "img-ranking");
	
	var flag = document.createElement("img");
	flag.src = varDirRoot + "/images/flag-0.gif"; 
	flag.setAttribute("id", "img-flag");
	flag.onclick = function(ev) { ev = ev || window.event; setFlag(ev, lightbox_item_id); }
		
	if 	(itemXML[0].getElementsByTagName("flag")[0].firstChild != null) {
		if (itemXML[0].getElementsByTagName("flag")[0].firstChild.nodeValue == "1")
			flag.src = varDirRoot + "/images/flag-1.gif"; 
	}
	
	rankings.appendChild(flag);
		
	var rank = 0;
	
	if (itemXML[0].getElementsByTagName("ranking")[0] != null)
		rank = itemXML[0].getElementsByTagName("ranking")[0].firstChild.nodeValue;
		
	for (var i = 1; i <= 5; i++) {
		var star = document.createElement("img");
		if (i <= rank)
			star.src = varDirRoot + "/images/star-1.gif";
		else
			star.src = varDirRoot + "/images/star-0.gif";
		
		star.onclick = function(ev) { ev = ev || window.event; setRanking(ev, lightbox_item_id); }
		
		rankings.appendChild(star);
	}

	cdWrapper.appendChild(rankings);

	slide.appendChild(cdWrapper);

	var buttons = document.createElement("div");
	buttons.setAttribute("id", "img-opt");

	var lbIcon = document.createElement("img");
	lbIcon.src = varDirRoot + "/images/lightbox-1.gif";
	lbIcon.setAttribute("title", "Remove from Lightbox");
	lbIcon.onclick = function(ev) { ev = ev || window.event; lightboxAction(ev, item_id, item_type); }
	buttons.appendChild(lbIcon);

	buttons.appendChild(document.createTextNode(" "));
	
	var itmInfo = document.createElement("img");
	itmInfo.src = varDirRoot + "/images/cart-0.gif";
	itmInfo.setAttribute("_on", varDirRoot + "/images/cart-1.gif");
	itmInfo.setAttribute("_off", varDirRoot + "/images/cart-0.gif");
	itmInfo.setAttribute("title", "View Images on this CD");
	itmInfo.onclick = function(ev) { viewCDImages(item_id); }
	itmInfo.onmouseover = function(ev) { ev = ev || window.event; imgOptOver(ev); }
	itmInfo.onmouseout = function(ev) { ev = ev || window.event; imgOptOut(ev); }
	buttons.appendChild(itmInfo);
	
	buttons.appendChild(document.createTextNode(" "));
	
	var itmLock = document.createElement("img");	
	if (status == "L") {
		itmLock.src = varDirRoot + "/images/lock-0.gif";
		itmLock.setAttribute("_on", varDirRoot + "/images/lock-1.gif");
		itmLock.setAttribute("_off", varDirRoot + "/images/lock-0.gif");
		itmLock.setAttribute("title", "Click to allow changes & comments");

	} else {
		itmLock.src = varDirRoot + "/images/unlock-0.gif";
		itmLock.setAttribute("_on", varDirRoot + "/images/unlock-1.gif");
		itmLock.setAttribute("_off", varDirRoot + "/images/unlock-0.gif");
		itmLock.setAttribute("title", "Click to Lock from changes & comments");			
	}

	itmLock.setAttribute("id", "lock_icon");
	itmLock.onclick = function(ev) { ev = ev || window.event; lightboxItemLock(ev, lightbox_item_id); }
	itmLock.onmouseover = function(ev) { ev = ev || window.event; imgOptOver(ev); }
	itmLock.onmouseout = function(ev) { ev = ev || window.event; imgOptOut(ev); }
	buttons.appendChild(itmLock);
	
	buttons.appendChild(document.createTextNode(" "));

	var itmMemo = document.createElement("img");
	itmMemo.src = varDirRoot + "/images/chat-0.gif";
	itmMemo.setAttribute("_off", varDirRoot + "/images/chat-0.gif");
	
	if (status == "L") {
		itmMemo.setAttribute("_on", varDirRoot + "/images/chat-0.gif");
		
	} else {
		itmMemo.setAttribute("_on", varDirRoot + "/images/chat-1.gif");
		itmMemo.setAttribute("title", "Add Memo for this item");			
	}

	itmMemo.setAttribute("id", "memo_icon");
	itmMemo.onclick = function(ev) { ev = ev || window.event; lightboxItemMemo(ev, lightbox_item_id); }
	itmMemo.onmouseover = function(ev) { ev = ev || window.event; imgOptOver(ev); }
	itmMemo.onmouseout = function(ev) { ev = ev || window.event; imgOptOut(ev); }
	buttons.appendChild(itmMemo);
	
	slide.appendChild(buttons);
	
	return slide;
}

function createSlideEXT(itemXML) {
	var item_type = itemXML[0].getElementsByTagName("item_type")[0].firstChild.nodeValue.toLowerCase();	
	var item_id = itemXML[0].getElementsByTagName("lightbox_item_id")[0].firstChild.nodeValue;
	var item_name = itemXML[0].getElementsByTagName("external_name")[0].firstChild.nodeValue;
	var external_page = itemXML[0].getElementsByTagName("external_page_url")[0].firstChild.nodeValue;
	var status = itemXML[0].getElementsByTagName("item_status")[0].firstChild.nodeValue;
	
	var slide = document.createElement("div");
	slide.setAttribute("id", "ext-" + item_id);
	slide.className = "slide";
	
	var itmName = document.createElement("div");
	itmName.setAttribute("id", "lb-item-name");
	itmName.innerHTML = "Name: " + item_name;
	slide.appendChild(itmName);
	
	var rmvIcon = document.createElement("img");
	rmvIcon.setAttribute("id", "lb-item-del");
	rmvIcon.setAttribute("align", "middle");
	rmvIcon.setAttribute("title", "Remove from current lightbox");
	rmvIcon.src = varDirRoot + "/images/redX.gif";
	rmvIcon.onclick = function(ev) { ev = ev || window.event; removeFromLightbox(ev, item_id); }
	slide.appendChild(rmvIcon);
	
	var thumbNailImg = document.createElement("img");
	thumbNailImg.className = "img-thm";

	if (itemXML[0].getElementsByTagName("external_thumb_url")[0].firstChild == null) {
		thumbNailImg.src = varDirRoot + "/images/ext-item.gif";
		thumbNailImg.style.border = "0px";
		
	} else
		thumbNailImg.src = itemXML[0].getElementsByTagName("external_thumb_url")[0].firstChild.nodeValue;
	
	thumbNailImg.style.width = "110px";
	thumbNailImg.style.height = "110px";
	
	var imgLink = document.createElement("a");
	imgLink.href = external_page
	imgLink.setAttribute("target", "_blank");
	imgLink.appendChild(thumbNailImg);
	
	var thumbNailDiv = document.createElement("div");
	thumbNailDiv.setAttribute("id", "free-img-wrapper");
	thumbNailDiv.appendChild(imgLink);
	
	slide.appendChild(thumbNailDiv);
	
	var rankings = document.createElement("div");
	rankings.setAttribute("id", "img-ranking");
	
	var flag = document.createElement("img");
	flag.src = varDirRoot + "/images/flag-0.gif"; 
	flag.setAttribute("id", "img-flag");
	flag.onclick = function(ev) { ev = ev || window.event; setFlag(ev, item_id); }
		
	if 	(itemXML[0].getElementsByTagName("flag")[0].firstChild != null) {
		if (itemXML[0].getElementsByTagName("flag")[0].firstChild.nodeValue == "1")
			flag.src = varDirRoot + "/images/flag-1.gif"; 
	}
	
	rankings.appendChild(flag);
	
	var rank = 0;
	
	if (itemXML[0].getElementsByTagName("ranking")[0] != null)
		rank = itemXML[0].getElementsByTagName("ranking")[0].firstChild.nodeValue;
		
	for (var i = 1; i <= 5; i++) {
		var star = document.createElement("img");
		if (i <= rank)
			star.src = varDirRoot + "/images/star-1.gif";
		else
			star.src = varDirRoot + "/images/star-0.gif";
		
		star.onclick = function(ev) { ev = ev || window.event; setRanking(ev, item_id); }
		
		rankings.appendChild(star);
	}

	slide.appendChild(rankings);

	var buttons = document.createElement("div");
	buttons.setAttribute("id", "img-opt");

	var itmLock = document.createElement("img");
	if (status == "L") {
		itmLock.src = varDirRoot + "/images/lock-0.gif";
		itmLock.setAttribute("_on", varDirRoot + "/images/lock-1.gif");
		itmLock.setAttribute("_off", varDirRoot + "/images/lock-0.gif");
		itmLock.setAttribute("title", "Click to allow changes & comments");

	} else {
		itmLock.src = varDirRoot + "/images/unlock-0.gif";
		itmLock.setAttribute("_on", varDirRoot + "/images/unlock-1.gif");
		itmLock.setAttribute("_off", varDirRoot + "/images/unlock-0.gif");
		itmLock.setAttribute("title", "Click to Lock from changes & comments");			
	}

	itmLock.setAttribute("id", "lock_icon");
	itmLock.onclick = function(ev) { ev = ev || window.event; lightboxItemLock(ev, item_id); }
	itmLock.onmouseover = function(ev) { ev = ev || window.event; imgOptOver(ev); }
	itmLock.onmouseout = function(ev) { ev = ev || window.event; imgOptOut(ev); }
	buttons.appendChild(itmLock);
	
	buttons.appendChild(document.createTextNode(" "));

	var itmMemo = document.createElement("img");
	itmMemo.src = varDirRoot + "/images/chat-0.gif";
	itmMemo.setAttribute("_off", varDirRoot + "/images/chat-0.gif");
	
	if (status == "L") {
		itmMemo.setAttribute("_on", varDirRoot + "/images/chat-0.gif");
		
	} else {
		itmMemo.setAttribute("_on", varDirRoot + "/images/chat-1.gif");
		itmMemo.setAttribute("title", "Add Memo for this item");			
	}

	itmMemo.setAttribute("id", "memo_icon");
	itmMemo.onclick = function(ev) { ev = ev || window.event; lightboxItemMemo(ev, item_id); }
	itmMemo.onmouseover = function(ev) { ev = ev || window.event; imgOptOver(ev); }
	itmMemo.onmouseout = function(ev) { ev = ev || window.event; imgOptOut(ev); }
	buttons.appendChild(itmMemo);

	slide.appendChild(buttons);
	
	return slide;
}

function setPageItemCount(xmlData) {
	var mode = document.getElementById("hid.mode");
	if (mode == null || mode.value != "lightbox") return false;
	
	var totalRows = xmlData[0].getElementsByTagName("num_items")[0].firstChild.nodeValue;
	if (xmlData[0].getElementsByTagName("num_items")[0] != null)
		document.getElementById("hid.totalRowCount").value = totalRows;
		
	var currPage = document.getElementById("hid.currPage").value;
	
	var start = ((currPage - 1) * 40) + 1;
	var end = start + 39;
	if (end > totalRows) end = totalRows;
	
	var display = document.getElementById("display-counter");
	display.innerHTML = "Displaying Items " + start + " to " + end + " of " + totalRows;
	
	var pagingBar = document.getElementById("paging2");
	var firstPage = null;
	var lastPage = null;
	
	for (var j = 0; j < pagingBar.childNodes.length; j++) {
		if (pagingBar.childNodes[j].nodeName == "A") {
			var pageNum = pagingBar.childNodes[j];
			if (firstPage == null) firstPage = pageNum;
			lastPage = pageNum;
		}
	}

	var totalPages = Math.ceil(totalRows / 40);
	
	if (totalPages < lastPage.innerHTML) {
		pagingBar.removeChild(lastPage);
		lastPage = null;
		
		if (firstPage.innerHTML > "1") {
			var newPage = document.createElement("a");
			newPage.innerHTML = firstPage.innerHTML - 1;
			newPage.onclick = function(ev) { gotoPage((firstPage.innerHTML - 1)); }
			
			firstPage.parentNode.insertBefore(newPage, firstPage);			
		}
	}

	// see if current page is still present
	var currPageFound = false;
	for (var j = 0; j < pagingBar.childNodes.length; j++) {
		if (pagingBar.childNodes[j].nodeName == "A") {
			var id = pagingBar.childNodes[j].getAttribute("id");
			if (id != null && id == "curr-page") {
				currPageFound = true;
				break;
			}
		}
	}
	
	if (!currPageFound)
		window.location.href = "lightboxes?hid.mode=lightbox&cmd=gotoPage&pageNum=" + totalPages;

	return currPageFound;
}

function saveMemo() {
	var memo = trim(document.getElementById("txt.lb_memo").value);
	
	if (memo.length > 500) {
		alert("Memo is too long.\n\nMaximum length is 500 chars.");
		document.getElementById("txt.lb_memo").focus();
		return false;
	}
	
	hidePopup("memo-popup");
	
	if (memo == "") return false;
	
	var lightbox_item_id = document.getElementById("hid.lightbox_item_id").value;
	var update_chat = document.getElementById("hid.update_chat").value;
	
	var url = "cmd=setmemo&lightbox_item_id=" + lightbox_item_id + "&memo=" + escape(memo);
		
	var ajaxLBMemo = new ajaxUpdateMemo(this, update_chat);
	ajaxLBMemo.update("lightboxes", url)
		
}

function lightboxItemMemo(ev, lightbox_item_id, updateChat) {	
	ev = ev || window.event;
	
	var element = ev.target || ev.srcElement;
	
	if (element == null) return false;
	
	if (right(element.src, 10) == "chat-0.gif") {
		alert("Item has been locked.\n\nNo additional comments are allowed.");
		return false;
	}
	
	var mousePos = mouseCoords(ev);
	var mouseOffset = getMouseOffset(element, ev);
		
	var popup = document.getElementById("memo-popup");
	
	if (popup) {
		document.getElementById("hid.lightbox_item_id").value = lightbox_item_id;		
		document.getElementById("txt.lb_memo").value = "";
		document.getElementById("hid.update_chat").value = (updateChat == null ? "" : updateChat);
		popup.style.top = (mousePos.y - mouseOffset.y) + "px";
		popup.style.left = (mousePos.x - mouseOffset.x) + "px";
		popup.style.display = "block";

		document.getElementById("txt.lb_memo").focus();
		
		l_currLBButton = element;
		
		StopBubble(ev);
		document.onclick = checkClosePopUp;
	}
}

function insertChat(chatXML) {
	var chats = chatXML[0].getElementsByTagName("record");
	
	for (var i = 0; i < chats.length; i++) {
		var memo = chats[i].getElementsByTagName("memo")[0].firstChild.nodeValue;	
		var posted = chats[i].getElementsByTagName("create_ts")[0].firstChild.nodeValue;
		var posted_by_owner = chats[i].getElementsByTagName("posted_by_owner")[0].firstChild.nodeValue;
		
		var TBODY = document.createElement("tbody");
			
		var TR = document.createElement("tr");
		
		var TD = document.createElement("td");
		
		if (posted_by_owner != 0)
			TD.setAttribute("id", "chat1");
		else
			TD.setAttribute("id", "chat2");
					
		TR.appendChild(TD);
		TBODY.appendChild(TR);
		
		var TR2 = document.createElement("tr");
				
		var TD2 = document.createElement("td");
		
		if (posted_by_owner != 0)
			TD2.setAttribute("id", "chat1-body");
		else
			TD2.setAttribute("id", "chat2-body");
					
		var PRE = document.createElement("pre");
		PRE.setAttribute("id", "chat-text");
		PRE.innerHTML = memo;
		
		TD2.appendChild(PRE);
		TD2.appendChild(document.createTextNode("Posted: " + posted));
		TR2.appendChild(TD2);
		TBODY.appendChild(TR2);
		
		var bubble = document.createElement("table");
		bubble.appendChild(TBODY);
		bubble.setAttribute("cellspacing", "0");
		bubble.setAttribute("cellpadding", "0");
		bubble.setAttribute("id", "tbl-chat");
		
		if (posted_by_owner == 0)
			bubble.style.marginLeft = "238px";
			
		var conversation = document.getElementById("lb-conversation");
		
		var recentChat = conversation.firstChild;
		if (recentChat != null)
			recentChat.parentNode.insertBefore(bubble, recentChat);
		else {
			conversation.appendChild(bubble);
		}
			
	}
}

function lightboxItemLock(ev, lightbox_item_id) {	
	ev = ev || window.event;
	
	var element = ev.target || ev.srcElement;
		
	if (element == null) return false;
	
	var url = "cmd=setitemstatus&lightbox_item_id=" + lightbox_item_id;
	
	if (right(element.src, 11) == "/lock-0.gif" || right(element.src, 11) == "/lock-1.gif") 
		url += "&status=A";		// reopen by setting to Active
	else
		url += "&status=L";		// lock by setting to Locked
	
	var ajaxLBItemStatus = new ajaxSetLBItemStatus(element);
	ajaxLBItemStatus.update("lightboxes", url)
}

function setItemStatusIcons(xmlData, icon) {
	var itemStatus = xmlData[0].getElementsByTagName("record");
	
	if (itemStatus.length == 0) return false;
	if (icon == null) return false;
	
	var memo = null;
	
	var container = icon.parentNode;
	for (var i = 0; i < container.childNodes.length; i++) {
		if (container.childNodes[i].id == "memo_icon") {
			memo = container.childNodes[i];
			break;
		}
	}
	    
	if (itemStatus[0].getElementsByTagName("status")[0].firstChild.nodeValue == "L") {
		icon.src = varWebRoot + "/images/lock-1.gif";
		icon.setAttribute("_on", varWebRoot + "/images/lock-1.gif");
		icon.setAttribute("_off", varWebRoot + "/images/lock-0.gif");
		
		icon.setAttribute("title", "Click to allow changes & comments");
		
		if (memo != null) {
			memo.src = varWebRoot + "/images/chat-0.gif";
			memo.setAttribute("_on", varWebRoot + "/images/chat-0.gif");
			memo.setAttribute("_off", varWebRoot + "/images/chat-0.gif");
			memo.setAttribute("title", "");
		}
		
	} else {
		icon.src = varWebRoot + "/images/unlock-1.gif";
		icon.setAttribute("_on", varWebRoot + "/images/unlock-1.gif");
		icon.setAttribute("_off", varWebRoot + "/images/unlock-0.gif");
		icon.setAttribute("title", "Click to Lock from changes & comments");
		
		if (memo != null) {
			memo.src = varWebRoot + "/images/chat-0.gif";
			memo.setAttribute("_on", varWebRoot + "/images/chat-1.gif");
			memo.setAttribute("_off", varWebRoot + "/images/chat-0.gif");
			memo.setAttribute("title", "Click to Add/Respond");
		}
	}
}

function clearLBItems() {
	var lbType = document.getElementById("lightbox_type");
	if (lbType == null) return false;
		
	if (lbType.value == "IMG") {
		if (!confirm("Delete all Image items from current lightbox?\n\nThis will delete all rankings, memos and history for all Image items.\n\nThis action cannot be undone.")) return false;
	} else if (lbType.value == "CD") {
		if (!confirm("Delete all CD items from current lightbox?\n\nThis will delete all rankings, memos and history for all CD items.\n\nThis action cannot be undone.")) return false;
	} else if (lbType.value == "EXT") {
		if (!confirm("Delete all External items from current lightbox?\n\nThis will delete all rankings, memos and history for External image items.\n\nThis action cannot be undone.")) return false;
	} else
		return false;
			
	var url = "cmd=clear&item_type=" + lbType.value;
	
	var ajaxLightbox = new ajaxUpdateLightbox(document.getElementById("paging2"));
	ajaxLightbox.update("lightboxes", url);
}

function addEXT() {
	document.location.href = varWebRoot + "/lightboxAddExt.jsp";
}

function setRanking(ev, lightbox_item_id) {
	var currentRanking = 0;
	var newRanking = 0;
	var numStar = 0;
	
	ev = ev || window.event;
	var star = ev.target || ev.srcElement;
	
	var rankings = star.parentNode;
	var slide = rankings.parentNode;
			
	while (slide && slide.tagName != "HTML" && !(slide.className == "cd" || slide.className == "slide")) {
		slide = slide.parentNode;
	}
	
	for (var i = 0; i < rankings.childNodes.length; i++) {
		if (rankings.childNodes[i].nodeName == "#text") continue;
		if (rankings.childNodes[i].id == "img-flag") continue;
		
		numStar++;
		if (rankings.childNodes[i] == star) newRanking = numStar;
		
		if (right(rankings.childNodes[i].src, 10) == "star-1.gif") 
			currentRanking++;
	}
	
	var itemProp = slide.id.split("-");
	
	var url = "lightboxes?cmd=setrank&lightbox_item_id=" + lightbox_item_id;
	
	if (currentRanking == newRanking)
		url += "&ranking=0";
	else
		url += "&ranking=" + newRanking;
	
	var ajaxRanking = new ajaxUpdateRanking(rankings);
	ajaxRanking.update(url);
}

function setFlag(ev, lightbox_item_id) {
	ev = ev || window.event;
	var flag = ev.target || ev.srcElement;
		
	var url = "lightboxes?cmd=setflag&lightbox_item_id=" + lightbox_item_id;
	
	if (right(flag.src, 10) == "flag-1.gif")
		url += "&flag=0";
	else
		url += "&flag=1";
		
	var ajaxFlag = new ajaxUpdateFlag(flag);
	ajaxFlag.update(url);	
}