/** ajax */
function setAjaxRequest(url, pars)
{
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get', 
			parameters: pars, 
			onComplete: setAjaxResponse
		});
}

function setAjaxResponse(originalRequest)
{
	//put returned XML in the textarea
	var xmldoc = originalRequest.responseXML;
	var rootNode = xmldoc.getElementsByTagName('ajax-response').item(0);
	var subNode = rootNode.firstChild;

	while (subNode != null)
	{
		if (subNode.tagName == "loginStatusResult")
		{
			processLoginStatusResult(subNode);
		}
		subNode = subNode.nextSibling;
	}
}

function processLoginStatusResult(node)
{
	if (node.firstChild.data == "1")
	{
		// save user
		$("scmsInfoBox").innerHTML = "";
		$("scmsInfoBox").style.display = "none";
		$("usRegForm").submit();
	}
	else 
	{
		// set warning message
		$("scmsInfoBox").innerHTML = "User Login bereits vergeben.";
		$("scmsInfoBox").style.display = "";
	}
}

function submitForm(type)
{
	var submit = true;
	$("usLogin").style.backgroundColor = "#FFFFFF";
	$("usFirstname").style.backgroundColor = "#FFFFFF";
	$("usLastname").style.backgroundColor = "#FFFFFF";
	$("usEmail").style.backgroundColor = "#FFFFFF";
	$("usPassword").style.backgroundColor = "#FFFFFF";
	$("usPassword2").style.backgroundColor = "#FFFFFF";
	$("usAgb").style.backgroundColor = "#FFFFFF";

	if ($("usLogin").value == '')
	{
		$("usLogin").style.backgroundColor = "#FFCC99";
		submit = false;
	}
	if ($("usFirstname").value == '')
	{
		$("usFirstname").style.backgroundColor = "#FFCC99";
		submit = false;
	}
	if ($("usLastname").value == '')
	{
		$("usLastname").style.backgroundColor = "#FFCC99";
		submit = false;
	}
	if ($("usEmail").value == '')
	{
		$("usEmail").style.backgroundColor = "#FFCC99";
		submit = false;
	}
	if ($("usPassword").value == '' || $("usPassword2").value == '' || $("usPassword").value != $("usPassword2").value)
	{
		$("usPassword").style.backgroundColor = "#FFCC99";
		$("usPassword2").style.backgroundColor = "#FFCC99";
		submit = false;
	}
	if ($("usAgb").checked != true)
	{
		$("usAgb").style.backgroundColor = "#FFCC99";
		submit = false;
	}
	if (submit)
	{
		var url = "content/userlogin/ajax/get_login_status.php";
		var pars = "?login="+$("usLogin").value;
//		alert(url + pars);
		setAjaxRequest(url, pars);
	}
}

