function bumpReview(rid, amt) {
	requestChange("/revbump.php", "rid="+rid+"&bump="+amt, respondBump);
}

function bumpUp(rid) {
	bumpReview(rid, 1);
}

function bumpDown(rid) {
	bumpReview(rid, -1);
}


function bumpUp10(rid) {
    var amount = prompt("Bump Up Value", "10");
	bumpReview(rid, amount);
}

function bumpDown10(rid) {
    var amount = prompt("Bump Down Value", "-10");
	bumpReview(rid, amount);
}

function respondBump() {
	genericRespond(updateBump);
}

function updateBump() {
	try {
		var rev = req.responseXML.getElementsByTagName("success")[0];
		if (rev && rev.hasAttribute("rev")) {
			var theBumpRegion = document.getElementById("bump"+rev.getAttribute("rev"));
			if (theBumpRegion) {
				if (theBumpRegion.hasChildNodes()) {
					for (var child = theBumpRegion.firstChild; child != null; child = child.nextSibling) {
						if (isBumpCount(child)) {
							updateBumpCount(child, rev.getAttribute("bump"));
						} else if (isBumpControls(child)) {
							disableBumpControls(child, rev.getAttribute("bump"));
						}
					}
				} else {
					console.log("Could not find bump region with children (should contain controls and value)");
				}
			} else {
				console.log("Could not find proper reference to bump container");
			}
		}
	} catch (m) {
		
	}
}

function isBumpCount(nd) {
	return isNodeWithClass(nd, /bumptot/);
}

function isBumpControls(nd) {
	return isNodeWithClass(nd, /bumpcont/);
}

function isNodeWithClass(nd, cls) {
	return (nd && nd.nodeType == 1 && cls.test(nd.className));
}
	
function updateBumpCount(nd, bump) {
	nd.normalize();
	var existingValue = parseInt(nd.firstChild.nodeValue);
	var newValue = ((isNaN(existingValue)) ? 0 : existingValue) + parseInt(bump);
	var sign = (newValue > 0) ? "+" : "";
	while (nd.lastChild) {
		nd.removeChild(nd.lastChild);
	}
	nd.appendChild(document.createTextNode(sign+newValue)); // this can also take into account changing the attributes
	nd.className = (newValue < 0) ? "bumptot neg" : "bumptot pos";
}

	/// this can take into account changing the class for contained images, when available
function disableBumpControls(nd, bump) {
	if (nd.hasChildNodes()) {
		bump = parseInt(bump); // make sure integer
		var anchors = nd.getElementsByTagName("a");
		for (a=0; a<anchors.length; a++) {
			var control = anchors[a];
				/// change image to reflect bump value
			var img = control.getElementsByTagName("img")[0];
			if (img) {
				if (img.hasAttribute("onmouseover")) {
					img.removeAttribute("onmouseover");
				} else if (img.onmouseover) {
					img.onmouseover = null;
				}
				if (img.hasAttribute("onmouseout")) {
					img.removeAttribute("onmouseout");
				} else if (img.onmouseout) {
					img.onmouseout = null;
				}
				if (control.className == "bumpUp" && bump > 0) {
					img.setAttribute("src", "/newlayout/images/bumpUp_off.png");
				} else if (control.className == "bumpDown" && bump < 0) {
					img.setAttribute("src", "/newlayout/images/bumpDown_off.png");
				} else { // make sure in original state
					if (control.className == "bumpUp") {
						img.setAttribute("src", "/newlayout/images/bumpUp.png");
					} else if (control.className == "bumpDown") {
						img.setAttribute("src", "/newlayout/images/bumpDown.png");
					}
				}
			}
				/// change link attributes (disable)
			control.removeAttribute("href");
			control.className = "disabled";
		}
	}
}
