	var request;
	var dest;

	function processStateChange()
	{
		 if (request.readyState == 4)
		 {

    	  	contentDiv = document.getElementById(dest);
     		if (request.status == 200)
			{

				response = request.responseText;

				if(dest=="registererrors")
				{
					response2=response.split("<");
					if(response2[0]=="2" || response2[0]=="3")
					{
						document.getElementById("login").style.backgroundColor=ErrorFieldColor;
						errormessage=errormessage+"<div>Такой логин уже зарегистрирован.</div>";
					}
					if(response2[0]=="1" || response2[0]=="3")
					{
						document.getElementById("companyname").style.backgroundColor=ErrorFieldColor;
						errormessage=errormessage+"<div>Такая компания уже зарегистрирована.</div>";
					}

					if(errormessage!="")
					{
						document.getElementById("registererrors").innerHTML=""
						document.getElementById("password").value="";
						document.getElementById("password2").value="";
						document.getElementById("password").style.backgroundColor=ErrorFieldColor;
						document.getElementById("password2").style.backgroundColor=ErrorFieldColor;
						//document.getElementById("error").className="savebox error-info";
						document.getElementById("registererrors").innerHTML=errormessage;
					}
					else
					{
						document.getElementById('registercompanyform').submit();
					}
				}
				else
				{
					contentDiv.innerHTML = response;
				}
    		}
			else
			{
				contentDiv.innerHTML = "Error: Status "+request.status;
    		}
  		}
	}

	function loadHTML(request_type, URL, post_data, destination)
	{

		dest = destination;
		var msxmlhttp = new Array(
				'Msxml2.XMLHTTP.5.0',
				'Msxml2.XMLHTTP.4.0',
				'Msxml2.XMLHTTP.3.0',
				'Msxml2.XMLHTTP',
				'Microsoft.XMLHTTP');

		for (var i = 0; i < msxmlhttp.length; i++)
		{
			try
			{
				request = new ActiveXObject(msxmlhttp[i]);
			}
			catch (e)
			{
				request = null;
			}
		}

		if(!request && typeof XMLHttpRequest != "undefined")
		request = new XMLHttpRequest();
		if (!request)
		alert("Could not create connection object.");

    	request.onreadystatechange = processStateChange;
    	request.open(request_type, URL, true);
		if (request_type == "POST")
		{
			request.setRequestHeader("Method", "POST " + URL + " HTTP/1.1");
			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		}

		request.send(post_data);
		delete request;
	}


