
	function dologin()
	{
		login.start();
	}

	var login = {
		start: 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=getHash", true);
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState == 4)
					if (xmlhttp.readyState)
						login.logging(xmlhttp.responseText);
			}
			xmlhttp.send(null);
		},
		logging: function(hash)
		{
			if(window.XMLHttpRequest)
				xmlhttp = new XMLHttpRequest();
			else if(window.ActiveXObject)
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			else
				return false;
			xmlhttp.open("POST", document.location.pathname + "?ajaxWEBsysLogin=auth", true);
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState == 4)
					if (xmlhttp.readyState)
					{
						if (xmlhttp.responseText)
						{
							if (xmlhttp.responseText == 'failed')
							{
								//login.doOverlay('<strong>A bejelentkezés nem sikerült!</strong><br /><br />Rossz név és/vagy jelszó!<br /><br /><input type="button" class="graybutton" value="OK" onclick="location.reload();" />');
								
								var ovhtml = '<table class="block strip" style="border:solid 1px #fff;">';
								ovhtml += '<tr>';
								ovhtml += '	<td class="blockhead norepeat" colspan="2">';
								ovhtml += '		<table class="blocktitle" align="center">';
								ovhtml += '		<tr>';
								ovhtml += '			<td class="btl"></td>';
								ovhtml += '			<td class="bterr">Bejelentkezés nem sikerült</td>';
								ovhtml += '			<td class="btr"></td>';
								ovhtml += '		</tr>';
								ovhtml += '		</table>';
								ovhtml += '	</td>';
								ovhtml += '</tr>';
								ovhtml += '<tr>';
								ovhtml += '	<td class="blockconterr">Ön rossz felhasználónevet és/vagy jelszót adott meg.<br/><br/><input type="button" class="graybutton" value="OK" id="errcnfrm" onclick="location.reload();" /></td>';
								ovhtml += '</tr>';
								ovhtml += '</table>';
								
								login.doOverlay(ovhtml);
								
							}
							else if (xmlhttp.responseText == 'duplicated')
							{
								//login.doOverlay('<strong>Ilyen nevű felhasználó már van bejelentkezve a rendszerbe!</strong><br /><br />(Amennyiben a kijelentkezés pont használata nélkül hagyta el a rendszert utoljára, úgy elképzelhető, hogy az Ön bejelentkezése maradt beragadva a rendszerbe.<br /><br />Ha nem erről van szó akkor, felhasználónevét mások is használják, amennyiben ezt problémának találja, kérem változtassa meg a belépési jelszavát!<br /><br /><input type="button" class="button" value="OK" onclick="location.reload();"/>');
								location.reload();
							}
						}
						else
						{
							location.reload();
						}
					}
			}
			xmlhttp.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();
		 	
		}
	}
	
