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 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 1 or -1
    		//alert(bump);
    		var anchors = nd.getElementsByTagName("a");
    	   	/*
    	    var controltodisable = anchors[1];
    	    var controltoenabled = anchors[0];
    		if (bump > 0)
    		{
    		  controltodisable = anchors[0];
    		  controltoenabled = anchors[1];
    		}
    				/// change image to reflect bump value
    			var img = controltodisable.getElementsByTagName("img")[0];
    			if (img) {
    			//	alert(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 (bump > 0) {
    					img.setAttribute("src", "/images/bumpUp_off.png");
    				} else  {
    					img.setAttribute("src", "/images/bumpDown_off.png");
    				} 
    			}
    				/// change link attributes (disable)
    			controltodisable.removeAttribute("href");
    			controltodisable.className = "disabled";

*/


    	
    		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", "/images/bumpUp_off.png");
    				} else if (control.className == "bumpDown" && bump < 0) {
    					img.setAttribute("src", "/images/bumpDown_off.png");
    				} else { // make sure in original state
    					if (control.className == "bumpUp") {
    						img.setAttribute("src", "/images/bumpUp.png");
    					} else if (control.className == "bumpDown") {
    						img.setAttribute("src", "/images/bumpDown.png");
    					}
    				}
    			}
    				/// change link attributes (disable)
    			control.removeAttribute("href");
    			control.className = "disabled";
    		}
    		
    	}
    }