
function getElementById(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6 
		return document.getElementById(id);
	} else {
		if (document.layers) { // Netscape 4 
			return document.layers[id];
		} else { // IE 4 
			return document.all[id];
		}
	}
}
function eraseElement(id, clearHtml) {
	var element = getElementById(id);
	element.style.display = "none";
	if (clearHtml) {
		element.innerHTML = "";
	}
}
function inlineElement(id, html) {
	var element = getElementById(id);
	element.style.display = "inline";
	if (html) {
		element.innerHTML = html;
	}
}
function hideElement(id, clearHtml) {
	var element = getElementById(id);
	element.style.visibility = "hidden";
	if (clearHtml) {
		element.innerHTML = "";
	}
}
function showElement(id, html) {
	var element = getElementById(id);
	element.style.visibility = "visible";
	if (html) {
		element.innerHTML = html;
	}
}
function urldecode(encoded) {
	   // Replace + with ' '
	   // Replace %xx with equivalent character
	   // Put [ERROR] in output if %xx is invalid.
	var HEXCHARS = "0123456789ABCDEFabcdef";
	var plaintext = "";
	var i = 0;
	while (i < encoded.length) {
		var ch = encoded.charAt(i);
		if (ch == "+") {
			plaintext += " ";
			i++;
		} else {
			if (ch == "%") {
				if (i < (encoded.length - 2) && HEXCHARS.indexOf(encoded.charAt(i + 1)) != -1 && HEXCHARS.indexOf(encoded.charAt(i + 2)) != -1) {
					plaintext += unescape(encoded.substr(i, 3));
					i += 3;
				} else {
					alert("Bad escape combination near ..." + encoded.substr(i));
					plaintext += "%[ERROR]";
					i++;
				}
			} else {
				plaintext += ch;
				i++;
			}
		}
	} // while
	return plaintext;
}

function checkEnter(e,theFunction){ //e is event object passed from function invocation
	var characterCode; // literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4s which property
	}
	else {
		e = event;
		characterCode = e.keyCode; //character code is contained in IEs keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		return theFunction(); 
	}
	else{
		return true; 
	}
}

function addHiddenToForm(theForm,name,value) {
	if (theForm.elements[name] == undefined) {
		var el = document.createElement("input");
		el.type = "hidden";
		el.name = name;
		el.id = name;
		el.value = value;
		theForm.appendChild(el);
		if (theForm.normalize) {theForm.normalize();}
	}
}

function mouseOutRateImg(img) {
	img.src = "images/rateMealButton.gif";
}

function mouseOverRateImg(img) {
	img.src = "images/rateMealButtonHover.gif";
}

