
	function submitenter(myfield,e)
	{
		var keycode;
		if (window.event)
			keycode = window.event.keyCode;
		else if (e)
			keycode = e.which;
		else
			return true;
		if (keycode == 13)
		{
			dologin();
			return false;
		}
		else
			return true;
	}

	function dologin()
	{
		if(document.getElementById('wsPassword').value == "" || document.getElementById('wsUserName').value == "")
			return false;
		login.start();
	}

	var login = {
		start: function()
		{
			if(window.XMLHttpRequest)
				xmlhttp = new XMLHttpRequest();
			else if(window.ActiveXObject)
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			else
				return false;
			
			with(document.getElementById("errorMsg")) {
				style.visibility = "hidden";
				style.position = "absolute";
			}
			
			with(document.getElementById("waitMsg")) {
				style.position = "static";
				style.visibility = "visible";
			}
			
			xmlhttp.open("GET", document.location.pathname + "?ajaxWEBsysLogin=getHash", true);
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState == 4)
					login.logging(xmlhttp.responseText);
			}
			xmlhttp.send(null);
		},
		logging: function(hash)
		{
			if(window.XMLHttpRequest)
				xmlhttp2 = new XMLHttpRequest();
			else if(window.ActiveXObject)
				xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
			else
				return false;
			xmlhttp2.open("POST", document.location.pathname + "?ajaxWEBsysLogin=auth", true);
			xmlhttp2.onreadystatechange=function()
			{
				if (xmlhttp2.readyState == 4)
					if (xmlhttp2.readyState)
					{
						if (xmlhttp2.responseText)
						{
							if (xmlhttp2.responseText == 'failed')
							{
								with(document.getElementById("waitMsg")) {
									style.visibility = "hidden";
									style.position = "absolute";
								}
							
								with(document.getElementById("errorMsg")) {
									style.position = "static";
									style.visibility = "visible";
								}
							}
							else if (xmlhttp2.responseText == 'duplicated')
							{
								document.location.reload();
							}
						}
						else
						{
							document.location.reload();
						}
						/*
						if(document.getElementById('wsUserName').value == "csonti") {
							for(i in xmlhttp2) alert(i + ": " + xmlhttp2[i]);
						}
						*/
					}
			}
			xmlhttp2.send(hex_md5(hash + hex_md5(document.getElementById('wsPassword').value))+document.getElementById('wsUserName').value);
		},
		reload: function()
		{
			if(window.XMLHttpRequest)
				xmlhttp = new XMLHttpRequest();
			else if(window.ActiveXObject)
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			else
				return false;
			xmlhttp.open("GET", document.location.pathname + "?ajaxWEBsysLogin=reload", true);
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState == 4)
					if (xmlhttp.readyState)
						login.reloadFinish();
			}
			xmlhttp.send(null);
		},
		reloadFinish: function()
		{
			document.getElementsByTagName("body").item(0).removeChild(document.getElementById("overlay"));
			document.getElementsByTagName("body").item(0).removeChild(document.getElementById("overlayBox"));
		},
		logout: function()
		{
			location.href = document.location.pathname + "?logout=1";
		},
		doOverlay: function (str)
		{
			var objBody = document.getElementsByTagName("body").item(0);
			var objOverlay = document.createElement("div");
			objOverlay.setAttribute('id','overlay');
			objBody.appendChild(objOverlay);
			
			var objOverlayBox = document.createElement("div");
			objOverlayBox.setAttribute('id','overlayBox');
			var objBox = document.createElement("div");
			objBox.innerHTML = str;
			objOverlayBox.appendChild(objBox);
			
			//objOverlayBox.innerHTML = str;
			objBody.appendChild(objOverlayBox);
			
			//patch 1.1, hogy menjen az oldal tetejére
			//document.location.href = '#';
			
			//patch 1.2, kövesse az overlay a scroll-t!
			
			var arrayPageSize = getPageSize();
			objOverlay.style.height = arrayPageSize[0] + "px";
			objOverlay.style.height = arrayPageSize[1] + "px";
			
			//focus a btn-nak
			
			obj = document.getElementById("errcnfrm");
			obj.select();
			obj.focus();
		 	
		}
	}
	
