// Pricing caclulator (runs in private namespace inside an anonymous function)
(function() {
	// Declare variables
	var qty = 1;
	var minqty = 1;
	var startqty = 1;
	var qtyblock = 1;
	var PriceScriptURL = "/ajax/qtyprice.aspx";
	var popup2x1URL = "/images/pricing/popup_2x1.png";
	var popup3x1URL = "/images/pricing/popup_3x1.png";
	var popup2x2URL = "/images/pricing/popup_2x2.png";
	var popup3x2URL = "/images/pricing/popup_3x2.png";
	var popup2x1DnURL = "/images/pricing/popup_2x1_down.png";
	var popup3x1DnURL = "/images/pricing/popup_3x1_down.png";
	var popup2x2DnURL = "/images/pricing/popup_2x2_down.png";
	var popup3x2DnURL = "/images/pricing/popup_3x2_down.png";
	var imgArrowURL = "/images/pricing/qty_arrow_off.gif";
	var imgArrowRolloverURL = "/images/pricing/qty_arrow_on.gif";
	var imgArrowDnURL = "/images/pricing/qty_arrow_down_off.gif";
	var imgArrowDnRolloverURL = "/images/pricing/qty_arrow_down_on.gif";
	var imgCloseURL = "/images/pricing/qty_close_off.gif";
	var imgCloseRolloverURL = "/images/pricing/qty_close_on.gif";
	var imgProgressURL = "/images/icons/loading_wheel.gif";
	var imgNoticeURL = "/images/pricing/notice.gif";
	var txtDefaultFormLabel = "How Many?";
	var txtDefaultWideFormLabel = "How Many Copies?";
	var txtDefaultCol1Header = "Lab<br />Color";
	var txtDefaultCol2Header = "Studio<br />Color";
	var txtDefaultQtyLabel = "Total<br />Items";
	var txtDefaultUnitPriceLabel = "Avg per<br />Copy";
	var txtDefaultTotalPriceLabel = "Total";
	var txtDefaultFooterHead = "Please remember...";
	var txtDefaultFooterText = "Quantity prices are for prints of the <b>same size</b>, from the <b>same file</b>."
	var billCode1 = "";
	var billCode2 = "";
	var qtyMultiplier = null;
	var PricingTimer = null;
	
	function setupPopups(obj) {
		var formatDown = false;
		var formatWide = false;
		var formatWideDown = false;
		var formatQtyMulti = false;
		var tableImages = obj.getElementsByTagName("img");
		for (var x = 0; x < tableImages.length; x++) {
			if (tableImages[x].className == "popup-wide") formatWide = true;
			else if (tableImages[x].className == "popup-narrow-down") formatDown = true;
			else if (tableImages[x].className == "popup-wide-down") formatWideDown = true;
			if (tableImages[x].getAttribute("qtymultiplier")) formatQtyMulti = true;
			if (formatDown || formatWideDown) {
				addRollover(tableImages[x], imgArrowDnURL, imgArrowDnRolloverURL);
				addPopupClick(tableImages[x]);
			} else if (tableImages[x].className.indexOf("popup") != -1) {
				addRollover(tableImages[x], imgArrowURL, imgArrowRolloverURL);
				addPopupClick(tableImages[x]);
			}
		}
		// POPUP BOX
		// Create an object to store properties based on the popup size and orientation
		var p;
		// Set styles for the popup and background
		if (formatWideDown && formatQtyMulti) {
			// A wide-tall (3x2) popup style
			p = {"width": "201px", "height": "224px", "padding": "27px 17px 20px 23px", "bkg": popup3x2DnURL, "bkgwidth": "242px", "bkgheight": "272px"};
		} else if (formatDown && formatQtyMulti) {
			// A narrow-tall (3x1) popup style
			p = {"width": "128px", "height": "210px", "padding": "27px 17px 20px 18px", "bkg": popup3x1DnURL, "bkgwidth": "164px", "bkgheight": "256px"};
		} else if (formatWideDown) {
			// A wide-short (2x2) popup style
			p = {"width": "201px", "height": "194px", "padding": "27px 17px 20px 23px", "bkg": popup2x2DnURL, "bkgwidth": "242px", "bkgheight": "242px"};
		} else if (formatDown) {
			// A narrow-short (2x1) popup style
			p = {"width": "128px", "height": "180px", "padding": "27px 17px 20px 18px", "bkg": popup2x1DnURL, "bkgwidth": "164px", "bkgheight": "228px"};
		} else if (formatWide && formatQtyMulti) {
			// A wide-tall (3x2) popup style
			p = {"width": "201px", "height": "224px", "padding": "9px 17px 20px 39px", "bkg": popup3x2URL, "bkgwidth": "257px", "bkgheight": "255px"};
		} else if (formatWide) {
			// A wide-short (2x2) popup style
			p = {"width": "201px", "height": "194px", "padding": "9px 17px 20px 39px", "bkg": popup2x2URL, "bkgwidth": "257px", "bkgheight": "225px"};
		} else if (formatQtyMulti) {
			// A narrow-tall (3x1) popup style
			p = {"width": "128px", "height": "210px", "padding": "9px 17px 20px 34px", "bkg": popup3x1URL, "bkgwidth": "179px", "bkgheight": "241px"};
		} else {
			// A narrow-short (2x1) popup style
			p = {"width": "128px", "height": "180px", "padding": "9px 17px 20px 34px", "bkg": popup2x1URL, "bkgwidth": "179px", "bkgheight": "211px"};
		}
		// Create parent div
		var popup = document.createElement("div");
		var popupbkg = document.createElement("div");
		popup.id = "price-popup";
		popupbkg.id = "price-popupbkg";
		popup.style.width = p.width;
		popup.style.height = p.height;
		popup.style.padding = p.padding;
		(new Image()).src = p.bkg;
		if (browserName == "Microsoft Internet Explorer" && browserVer < 7) {
			popupbkg.style.whiteSpace = 'normal';
			popupbkg.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + p.bkg + '\');';
		} else popupbkg.style.cssText = 'background: url(' + p.bkg + ') center center no-repeat; white-space: normal;';
		popupbkg.style.width = p.bkgwidth;
		popupbkg.style.height = p.bkgheight;
		popupbkg.style.position = 'absolute';
		popupbkg.style.zIndex = '1000';
		popup.style.left = "0px";
		popup.style.top = "0px";
		popupbkg.style.left = "0px";
		popupbkg.style.top = "0px";
		popup.style.display = 'none';
		popupbkg.style.display = 'none';
		document.body.appendChild(popupbkg);
		popupbkg.appendChild(document.createTextNode(" "));
		document.body.appendChild(popup);
		
		// Create close box will rollover action and onclick action
		var imgClose = document.createElement("img");
		imgClose.src = imgCloseURL;
		imgClose.width = "16";
		imgClose.height = "16";
		imgClose.border = "0";
		popup.appendChild(imgClose);
		addRollover(imgClose, imgCloseURL, imgCloseRolloverURL);
		imgClose.onclick = function() { hidePopup(); }
		
		// FORM TABLE
		// Form container
		var form = document.createElement("form");
		form.id = "CalcQty";
		form.name = "CalcQty";
		form.onsubmit = function() { return false; } // Don't respond to a submit or 'enter' key
		popup.appendChild(form);
		// Table container
		var tblForm = document.createElement("table");
		tblForm.className = (formatWide || formatWideDown) ? 'form-wide' : 'form-narrow';
		tblForm.cellSpacing = 0;
		tblForm.cellPadding = 0;
		tblForm.border = 0;
		form.appendChild(tblForm);
		// table body
		var tbodyForm = document.createElement("tbody");
		tblForm.appendChild(tbodyForm);
		// Table row
		var trForm = document.createElement("tr");
		tbodyForm.appendChild(trForm);
		// Table cell, form label
		var tdFormLabel = document.createElement("td");
		tdFormLabel.id = "price-formlabel";
		trForm.appendChild(tdFormLabel);
		// Determine length of form label based on narrow/wide popup format
		if (formatWide || formatWideDown) tdFormLabel.innerHTML = txtDefaultWideFormLabel;
		else tdFormLabel.innerHTML = txtDefaultFormLabel;
		// Table cell, form field
		var tdFormField = document.createElement("td");
		trForm.appendChild(tdFormField);
		var txtField = document.createElement("input");
		txtField.setAttribute("type", "text");
		txtField.setAttribute("name", "txtQty");
		txtField.setAttribute("autocomplete", "off");
		txtField.id = "txtQty";
		txtField.value = "1";
		txtField.maxLength = 4;
		txtField.onkeyup = keyListener;
		tdFormField.appendChild(txtField);
		
		// STATUS STATEMENT
		var divStatus = document.createElement("div");
		divStatus.id = 'price-status';
		if ((formatWide || formatWideDown) && formatQtyMulti) {
			divStatus.style.padding = '18px 0px 19px 0px';
			divStatus.style.width = '201px';
			divStatus.style.height = '100px';
		} else if (formatWide || formatWideDown) {
			divStatus.style.padding = '18px 0px 19px 0px';
			divStatus.style.width = '201px';
			divStatus.style.height = '70px';
		} else if (formatQtyMulti) {
			divStatus.style.padding = '13px 0px 18px 0px';
			divStatus.style.width = '125px';
			divStatus.style.height = '76px';
		} else {
			divStatus.style.padding = '13px 0px 18px 0px';
			divStatus.style.width = '125px';
			divStatus.style.height = '46px';
		}
		popup.appendChild(divStatus);
		divStatus.style.display = '';
		// Preload progress and notice images
		(new Image()).src = imgProgressURL;
		(new Image()).src = imgNoticeURL;
		
		// PRICES TABLE
		// Div container
		var divData = document.createElement("div");
		divData.id = 'price-data';
		if (formatWide || formatWideDown) {
			divData.style.padding = '8px 0px 9px 0px';
			divData.style.width = '201px';
			if (formatQtyMulti) divData.style.height = '120px';
			else divData.style.height = '90px';
		} else {
			divData.style.padding = '8px 0px 13px 0px';
			divData.style.width = '125px';
			divData.style.height = '56px';
			if (formatQtyMulti) divData.style.height = '86px';
			else divData.style.height = '56px';
		}
		divData.style.display = 'none';
		popup.appendChild(divData);
		// Table container
		var tblPrices = document.createElement("table");
		tblPrices.setAttribute("cellspacing", "0");
		tblPrices.setAttribute("cellpadding", "0");
		tblPrices.setAttribute("border", "0");
		tblPrices.setAttribute("width", "100%");
		divData.appendChild(tblPrices);
		// table body
		var tbodyPrices = document.createElement("tbody");
		tblPrices.appendChild(tbodyPrices);
		if (formatWide || formatWideDown) {
			// Header row (wide popups only)
			var trPrices1 = document.createElement("tr");
			trPrices1.setAttribute("valign", "bottom");
			tbodyPrices.appendChild(trPrices1);
			// Table cells
			var thPricesHeader1 = document.createElement("th");
			thPricesHeader1.className = "small";
			trPrices1.appendChild(thPricesHeader1);
			thPricesHeader1.appendChild(document.createTextNode(" "));
			var thPricesHeader2 = document.createElement("th");
			thPricesHeader2.id = "price-col1head";
			thPricesHeader2.className = "small";
			trPrices1.appendChild(thPricesHeader2);
			thPricesHeader2.innerHTML = txtDefaultCol1Header;
			var thPricesHeader3 = document.createElement("th");
			thPricesHeader3.id = "price-col2head";
			thPricesHeader3.className = "small";
			trPrices1.appendChild(thPricesHeader3);
			thPricesHeader3.innerHTML = txtDefaultCol2Header;
		}
		// Quantity multiplier row (if there is one)
		if (formatQtyMulti) {
			// Unit price row
			var trPrices2 = document.createElement("tr");
			tbodyPrices.appendChild(trPrices2);
			// Table cells
			var tdPricesQty1 = document.createElement("td");
			tdPricesQty1.id = "price-qtylabel";
			tdPricesQty1.className = "small";
			trPrices2.appendChild(tdPricesQty1);
			tdPricesQty1.innerHTML = txtDefaultQtyLabel;
			var thPricesQty2 = document.createElement("th");
			thPricesQty2.id = "Col1Qty";
			trPrices2.appendChild(thPricesQty2);
			if (formatWide || formatWideDown) { // Second column is for wide popups only
				var thPricesQty3 = document.createElement("th");
				thPricesQty3.id = "Col2Qty";
				trPrices2.appendChild(thPricesQty3);
			}
		}
		// Unit price row
		var trPrices3 = document.createElement("tr");
		tbodyPrices.appendChild(trPrices3);
		// Table cells
		var tdPricesAvg1 = document.createElement("td");
		tdPricesAvg1.id = "price-unitlabel";
		tdPricesAvg1.className = "small";
		trPrices3.appendChild(tdPricesAvg1);
		tdPricesAvg1.innerHTML = txtDefaultUnitPriceLabel;
		var thPricesAvg2 = document.createElement("th");
		thPricesAvg2.id = "Col1Avg";
		trPrices3.appendChild(thPricesAvg2);
		if (formatWide || formatWideDown) { // Second column is for wide popups only
			var thPricesAvg3 = document.createElement("th");
			thPricesAvg3.id = "Col2Avg";
			trPrices3.appendChild(thPricesAvg3);
		}
		// Totals row
		var trPrices4 = document.createElement("tr");
		tbodyPrices.appendChild(trPrices4);
		// Table cells
		var tdPricesTotal1 = document.createElement("td");
		tdPricesTotal1.id = "price-totallabel";
		trPrices4.appendChild(tdPricesTotal1);
		tdPricesTotal1.innerHTML = txtDefaultTotalPriceLabel;
		var thPricesTotal2 = document.createElement("th");
		thPricesTotal2.id = "Col1Total";
		trPrices4.appendChild(thPricesTotal2);
		if (formatWide || formatWideDown) { // Second column is for wide popups only
			var thPricesTotal3 = document.createElement("th");
			thPricesTotal3.id = "Col2Total";
			trPrices4.appendChild(thPricesTotal3);
		}
		// Reminder footer
		var hFooter = document.createElement("h1");
		hFooter.id = "price-footerhead"
		popup.appendChild(hFooter);
		hFooter.innerHTML = txtDefaultFooterHead;
		var pFooter = document.createElement("p");
		pFooter.id = "price-footertext";
		popup.appendChild(pFooter);
		pFooter.innerHTML = txtDefaultFooterText;
		// Set default status text
		displayStatus(imgProgressURL, "Calculating price...");
	}
	
	// Image button rollover handler
	function addRollover(img, normalURL, rolloverURL) {
		(new Image()).src = rolloverURL;
		img.onmouseover = function() { img.src = rolloverURL; }
		img.onmouseout = function() { img.src = normalURL; }
	}
	
	// Popup on-click handler
	function addPopupClick(obj) {
		obj.onclick = function() { showPopup(obj); }
	}

	// Shows a popup window
	function showPopup(obj) {
		if (request == null) alert("Your web browser does not appear to support this feature. Please ensure you are using one of the following browsers:\n- Microsoft Internet Explorer 6.0 or higher\n- Mozilla Firefox\n- Apple Safari\n- Netscape 7.0 or higher");
		else {
			var popup_type = obj.className;
			var popup = document.getElementById("price-popup");
			var popupbkg = document.getElementById("price-popupbkg");
			var divStatus = document.getElementById("price-status");
			var divData = document.getElementById("price-data");
			var tdFormLabel = document.getElementById("price-formlabel");
			var thCol1Head = document.getElementById("price-col1head");
			var thCol2Head = document.getElementById("price-col2head");
			var tdQtyLabel = document.getElementById("price-qtylabel");
			var tdUnitLabel = document.getElementById("price-unitlabel");
			var tdTotalLabel = document.getElementById("price-totallabel");
			var pFooterHead = document.getElementById("price-footerhead");
			var pFooterText = document.getElementById("price-footertext");
			// Position popup window
			var objpos = getAnchorPosition(obj);
			var popup_left;
			var popup_top;
			if (popup_type == "popup-wide-down") {
				popup_left = parseInt(objpos.x + (obj.offsetWidth /2) - 215);
				popup_top = parseInt(objpos.y + obj.offsetHeight - 1);
			} else if (popup_type == "popup-narrow-down") {
				popup_left = parseInt(objpos.x + (obj.offsetWidth /2) - 137);
				popup_top = parseInt(objpos.y + obj.offsetHeight - 1);
			} else {
				popup_left = parseInt(objpos.x + obj.offsetWidth - 1);
				popup_top = parseInt(objpos.y + (obj.offsetHeight/2) - 37);
			}
			popup.style.left = '' + popup_left + 'px';
			popup.style.top = '' + popup_top + 'px';
			popupbkg.style.left = '' + popup_left + 'px';
			popupbkg.style.top = '' + popup_top + 'px';
			// Insert price values into popup
			billCode1 = obj.getAttribute("code1");
			billCode2 = (popup_type.indexOf("wide") != -1) ? obj.getAttribute("code2") : "";
			qtyMultiplier = (parseInt(obj.getAttribute("qtymultiplier")) > 1) ? parseInt(obj.getAttribute("qtymultiplier")) : 1;
			minqty = (parseInt(obj.getAttribute("minqty")) > 1) ? parseInt(obj.getAttribute("minqty")) : 1;
			startqty = (parseInt(obj.getAttribute("startqty")) > 1) ? parseInt(obj.getAttribute("startqty")) : 1;
			qtyblock = (parseInt(obj.getAttribute("qtyblock")) > 1) ? parseInt(obj.getAttribute("qtyblock")) : 1;
			// Insert custom text
			if (obj.getAttribute("formlabel") && tdFormLabel) tdFormLabel.innerHTML = obj.getAttribute("formlabel");
			if (obj.getAttribute("col1head") && thCol1Head) thCol1Head.innerHTML = obj.getAttribute("col1head");
			if (obj.getAttribute("col2head") && thCol2Head) thCol2Head.innerHTML = obj.getAttribute("col2head");
			if (obj.getAttribute("qtylabel") && tdQtyLabel) tdQtyLabel.innerHTML = obj.getAttribute("qtylabel");
			if (obj.getAttribute("unitlabel") && tdUnitLabel) tdUnitLabel.innerHTML = obj.getAttribute("unitlabel");
			if (obj.getAttribute("totallabel") && tdTotalLabel) tdTotalLabel.innerHTML = obj.getAttribute("totallabel");
			if (obj.getAttribute("footerhead") && pFooterHead) pFooterHead.innerHTML = obj.getAttribute("footerhead");
			if (obj.getAttribute("footertext") && pFooterText) pFooterText.innerHTML = obj.getAttribute("footertext");
			// Enable display of item
			popup.style.display = '';
			popupbkg.style.display = '';
			// Determine if the value in the quantity field is valid
			var txtQty = document.getElementById("txtQty");
			var validNum = (txtQty.value.length > 0 && !isNaN(txtQty.value) && parseInt(txtQty.value) == txtQty.value) ? true : false;
			// Determine if the value in the quantity field meets the requirements for the minimum
			var validMinQty = true;
			if (validNum && parseInt(txtQty.value) < minqty) txtQty.value = minqty;
			// Put the start quantity in the calculator field
			else if (validNum && parseInt(txtQty.value) < startqty) txtQty.value = startqty;
			// Determine if the value in the quantity field meets the quantity block requirements
			var validQtyBlock = true;
			if (validNum && qtyblock > 1 && parseInt(txtQty.value) % qtyblock > 0) txtQty.value = (minqty > qtyblock) ? minqty : qtyblock;
			// Focus the cursor on the text box and select its contents
			txtQty.focus();
			txtQty.select();
			if (validNum && validMinQty && validQtyBlock) {
				displayStatus(imgProgressURL, "Calculating price...");
				getQtyPrice();
			} else if (!validMinQty) displayStatus(imgNoticeURL, "The minimum quantity for this item is " + minqty + ".");
			else if (!validQtyBlock) displayStatus(imgNoticeURL, "This item must be ordered in blocks of " + qtyblock + ".");
			else displayStatus(imgNoticeURL, "Please enter a valid whole number quantity.");
		}
	}
	
	function keyListener() {
		var divStatus = document.getElementById("price-status");
		var divData = document.getElementById("price-data");
		var txtQty = document.getElementById("txtQty");
		if (PricingTimer != null) clearTimeout(PricingTimer);
		// Determine if the value in the quantity field is valid
		var validNum = (txtQty.value.length > 0 && !isNaN(txtQty.value) && parseInt(txtQty.value) == txtQty.value) ? true : false;
		// Determine if the value in the quantity field meets the requirements for the minimum
		var validMinQty = true;
		if (validNum && parseInt(txtQty.value) < minqty) validMinQty = false;
		// Determine if the value in the quantity field meets the quantity block requirements
		var validQtyBlock = true;
		if (validNum && qtyblock > 1 && parseInt(txtQty.value) % qtyblock > 0) validQtyBlock = false;
		if (validNum && validMinQty && validQtyBlock) {
			displayStatus(imgProgressURL, "Calculating price...");
			PricingTimer = setTimeout(getQtyPrice, 1250);
		} else if (!validMinQty) displayStatus(imgNoticeURL, "The minimum quantity for this item is " + minqty + ".");
		else if (!validQtyBlock) displayStatus(imgNoticeURL, "This item must be ordered in blocks of " + qtyblock + ".");
		else displayStatus(imgNoticeURL, "Please enter a valid whole number quantity.");
	}

	function getQtyPrice() {
		if (PricingTimer != null) clearTimeout(PricingTimer);
		if (request.readyState == 0 || request.readyState == 4) {
			var qty_field = document.getElementById("txtQty");
			var qty = parseInt(qty_field.value);
			request.open("POST", PriceScriptURL, true);
			request.onreadystatechange = showQtyPrice;
			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			request.send("c1=" + escape(billCode1) + "&c2=" + escape(billCode2) + "&q=" + escape(qty));
		} else PricingTimer = setTimeout(getQtyPrice, 0);
	}

	function showQtyPrice() {
		if (request.readyState == 4) {
			// Display prices table
			if (request.status == 200) {
				// Get the popup elements, and the first column elements
				var divStatus = document.getElementById("price-status");
				var divData = document.getElementById("price-data");
				var col1qty = document.getElementById("Col1Qty");
				var col1avg = document.getElementById("Col1Avg");
				var col1total = document.getElementById("Col1Total");
				var col2qty = document.getElementById("Col2Qty");
				var col2avg = document.getElementById("Col2Avg");
				var col2total = document.getElementById("Col2Total");
				// Get the current value of the quantity field
				var qty_field = document.getElementById("txtQty");
				var qty = parseInt(qty_field.value);
				// Get the XML response
				var xmlDoc = request.responseXML;
				var billCodes = xmlDoc.getElementsByTagName("BillingCode");
				var tmpAvg = xmlDoc.getElementsByTagName("AvgPerCopy");
				var tmpTotal = xmlDoc.getElementsByTagName("Total");
				// Replace table data with XML-received data
				if (billCodes.length == 1 && billCodes[0].firstChild.nodeValue == billCode2 && col2avg && col2total) {
					if (col1qty) replaceText(col1qty, "");
					replaceText(col1avg, "");
					replaceText(col1total, "");
					if (qtyMultiplier != null && col2qty) replaceText(col2qty, parseInt(qty * qtyMultiplier));
					else if (col2qty) replaceText(col2qty, "");
					replaceText(col2avg, "$" + tmpAvg[0].firstChild.nodeValue);
					replaceText(col2total, "$" + tmpTotal[0].firstChild.nodeValue);
				} else {
					if (qtyMultiplier != null && col1qty) replaceText(col1qty, parseInt(qty * qtyMultiplier));
					else if (col1qty) replaceText(col1qty, "");
					replaceText(col1avg, "$" + tmpAvg[0].firstChild.nodeValue);
					replaceText(col1total, "$" + tmpTotal[0].firstChild.nodeValue);
				}
				if (billCode2 != "" && tmpAvg.length > 1) {
					if (qtyMultiplier != null && col2qty) replaceText(col2qty, parseInt(qty * qtyMultiplier));
					else if (col2qty) replaceText(col2qty, "");
					replaceText(col2avg, "$" + tmpAvg[1].firstChild.nodeValue);
					replaceText(col2total, "$" + tmpTotal[1].firstChild.nodeValue);
				} else if (billCode2 == "" && col2avg && col2total) {
					if (col2qty) replaceText(col2qty, "");
					replaceText(col2avg, "");
					replaceText(col2total, "");
				}
				// Hide status message, display prices table
				divStatus.style.display = 'none';
				divData.style.display = '';
			} else {
				// Get failed status error message
				var message = "";
				message = request.statusText;
				if (message.length == 0) message = "Unspecified error " + request.status;
				// Display error message
				displayStatus(imgNoticeURL, message);
			}
		}
	}

	function displayStatus(img_url, newtext) {
		var divStatus = document.getElementById("price-status");
		var divData = document.getElementById("price-data");
		while (divStatus.firstChild != null) {
			divStatus.removeChild(divStatus.firstChild);
		}
		// Update status image
		var img = document.createElement("img");
		img.src = img_url;
		img.width = "16";
		img.height = "16";
		img.border = "0";
		divStatus.appendChild(img);
		// Update status text
		var text = document.createElement("p");
		divStatus.appendChild(text);
		text.appendChild(document.createTextNode(newtext));
		divStatus.style.display = '';
		divData.style.display = 'none';
	}

	function hidePopup() {
		var popup = document.getElementById("price-popup");
		var popupbkg = document.getElementById("price-popupbkg");
		if (popup) popup.style.display = 'none';
		if (popupbkg) popupbkg.style.display = 'none';
	}

	function getAnchorPosition(e){
		Number.prototype.NaN0 = function() { return isNaN(this)?0:this; }
		var left = 0;
		var top  = 0;
		while (e.offsetParent){
			left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
			top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
			e     = e.offsetParent;
		}
		left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
		top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
		return {x:left, y:top};
	}

	// Pricing OnLoad directive
	function doOnLoad() {
		if (document.getElementById("price")) setupPopups(document.getElementById("price"));
		if (document.getElementById("price2")) setupPopups(document.getElementById("price2"));
		if (document.getElementById("price3")) setupPopups(document.getElementById("price3"));
		if (document.getElementById("price4")) setupPopups(document.getElementById("price4"));
		if (document.getElementById("price5")) setupPopups(document.getElementById("price5"));
		if (document.getElementById("minprice")) setupPopups(document.getElementById("minprice"));
	}

	if (window.addEventListener) window.addEventListener("load", doOnLoad, false);
	else if (window.attachEvent) window.attachEvent("onload", doOnLoad);
})();
