/*requires jquery-1.3.2.min.js*/

var HAS_FOCUS = "";

$(initFocusSettings);
document.onkeypress = disableEnterKey;


function initFocusSettings() {
	if (document.getElementsByTagName) {
		for (i=0; (input = document.getElementsByTagName("INPUT")[i]); i++) {
			if (input.type == "text" || input.type == "password") {
				input.onfocus = function() { HAS_FOCUS = this.id; }
				input.onblur = function() { HAS_FOCUS = ""; }
			}
		}
		
		for (i=0; (TA = document.getElementsByTagName("TEXTAREA")[i]); i++) {
			TA.onfocus = function() { HAS_FOCUS = "textarea"; }
			TA.onblur = function() { HAS_FOCUS = ""; }
		}
	}
}

function disableEnterKey(e) {
	if (document.getElementById) {
		var key;
		if (typeof e == "undefined") e = window.event;
		if (window.event) key = e.keyCode;
		else if (e.which) key = e.which;
		
		if (HAS_FOCUS != "textarea") {
			if (key == 13) {
			
				if (window.event) window.event.keyCode = 0;
				else if (e.which) e.stopPropagation();
				
				// determine which form to post
				switch (HAS_FOCUS) {
					case "Bottom1_LeftColumn1_SearchTextBox":
						var button = document.getElementById("Bottom1_LeftColumn1_SearchImageButton");
						button.click();
						break;
					case "UsernameTextBox":
					case "PasswordTextBox":
						var button = document.getElementById("LoginImageButton");
						button.click();
						break;
					case "EmailTextBox":
						var button = document.getElementById("SendImageButton");
						button.click();
						break;
					default:
				}
			}
		}
	}
}