/** 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 = "<br />User Login bereits vergeben.";
		$("scmsInfoBox").style.display = "";
	}
}

function submitForm(type)
{
	var submit = true;
	var textValueArray = new Array("usLogin", "usLogin", "usFirstname", "usLastname", "usEmail", "usPassword", "usPassword2", "usZipCode", "usCity", "usBirthday");
	
	for (var i = 0; i < textValueArray.length; ++i) 
	{
		$(textValueArray[i]).style.backgroundColor = "#c0c0c0";
	}

	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 ($("usZipCode").value == '')
	{
		$("usZipCode").style.backgroundColor = "#FFCC99";
		submit = false;
	}
	if ($("usCity").value == '')
	{
		$("usCity").style.backgroundColor = "#FFCC99";
		submit = false;
	}
	if ($("usBirthday").value == '')
	{
		$("usBirthday").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);
	}
}

