	var paramName;
	var	paramsTemp;
	var	markFieldsGlobal;	

	function validateUserInputMoreParams(params, param, operationName, autoCompleteFieldName) {
		validateUserInputMoreParamsSessionID(params, param, operationName, autoCompleteFieldName, '22222222-2222-22222222222222-2222-222222222222');
	}
	function validateUserInputMoreParamsSessionID(params, param, operationName, autoCompleteFieldName, sessionID) {
		validateUserInputMoreParamsSessionIDMarkFields(params, param, operationName, autoCompleteFieldName, sessionID, params);
	}	
	function validateUserInputMoreParamsSessionIDMarkFields(params, param, operationName, autoCompleteFieldName, sessionID, markFields) {
		if(sessionID == '')
			sessionID = '22222222-2222-22222222222222-2222-222222222222';	
		paramsTemp = params;
		markFieldsGlobal = markFields;		
		paramName = param;
		var target = '';
		var reqParam = '';
    	for(var i=0; i<paramsTemp.length;i++){
    		if(paramsTemp[i] == 'j_username')
    			target = document.getElementsByName(paramsTemp[i])[1];    		
    		else	
    			target = document.getElementById(paramsTemp[i]);
    		if(target)
    			reqParam += paramsTemp[i]+"="+target.value+"&";
    		else
    			reqParam += paramsTemp[i]+"="+paramsTemp[i]+"&";
    	}
    	reqParam += "operationName="+operationName+"&ms="+(new Date().getTime())+"&sessionID="+sessionID;
    	var url = "xml_validation";
		var newFunc = new Function("xml, status, autoCompleteFieldName", "validateCallback(xml, status, \'"+autoCompleteFieldName+"\')");
    	var ajax = new AJAXInteraction(url, newFunc); 
    	ajax.doPost(reqParam);
	}
	function validateParams(params, param, operationName) {
		paramsTemp = null;
		markFieldsGlobal = null;		
		paramName = param;
		params += "&operationName="+operationName+"&ms="+(new Date().getTime())+"&sessionID=22222222-2222-22222222222222-2222-222222222222";
    	var url = "xml_validation";
		var newFunc = new Function("xml, status, autoCompleteFieldName", "validateCallback(xml, status, \'\')");
    	var ajax = new AJAXInteraction(url, newFunc); 
    	ajax.doPost(params);
	}
	
	function validateUserInputParam(param, param2, operationName) {
		validateUserInputMoreParams(new Array(param), param2, operationName, param);
	}
	function validateUserInput(param, operationName) {
		validateUserInputMoreParams(new Array(param), param, operationName, param);
	}
	function getCSSErrorClass(colorDiv){
		if(colorDiv.type.indexOf('select')!=-1)
			return 'commonSelectError';
		else
			return 'commonInputError';
	}
	function getCSSClass(colorDiv){
		if(colorDiv.type.indexOf('select')!=-1)
			return 'commonSelect';
		else
			return 'commonInput'; 
	}
	
	function hasError(xml, name){
		var errors = xml.getElementsByTagName("ERROR");
	    for(var i=0; i<errors.length;i++){
			if (xml.getElementsByTagName("ERROR")[0].getAttribute('key') && xml.getElementsByTagName("ERROR")[0].getAttribute('key') == name)
				return true;
	    }
	    return false;
	}

	function setFocusToField(paramName){
		if(paramName == 'j_username')
			document.registrationForm.j_password1.focus();
		else if(paramName == 'j_nickname' || paramName == 'j_address'){
			document.registrationForm.j_address.focus();
		}
	}
	
	function validateCallback(xml, status, autoCompleteFieldName) {
		var errors = xml.getElementsByTagName("ERROR").length;

		if(markFieldsGlobal){
	    	for(var i=0; i<markFieldsGlobal.length;i++){
	    		var colorDiv;
	    		if(markFieldsGlobal[i] == 'j_username')
	    			colorDiv = document.getElementsByName(markFieldsGlobal[i])[1];    		
	    		else	
	    			colorDiv = document.getElementById(markFieldsGlobal[i]);
	    		if(colorDiv){
					var width = parseInt(colorDiv.style.width.substring(0,colorDiv.style.width.indexOf("px")));
					if (errors > 0) {
						if(width && (colorDiv.className=="commonInput" || colorDiv.className=="commonSelect"))
							colorDiv.style.width = (width)+'px';
						colorDiv.className = getCSSErrorClass(colorDiv);
					} else {
						if(width && (colorDiv.className=="commonInputError" || colorDiv.className=="commonSelectError"))
							colorDiv.style.width = (width)+'px';
						colorDiv.className = getCSSClass(colorDiv);
					}
				}
	    	}
	    }
		var mdiv = document.getElementById(paramName+"_message");
		if (errors > 0) {
			mdiv.innerHTML = xml.getElementsByTagName("ERROR")[0].firstChild.nodeValue;
			mdiv.style.display = "block";
		} else {
			mdiv.style.display = "none";
			mdiv.innerHTML = "";
		}
		var autocompletes = xml.getElementsByTagName("AUTOCOMPLETE").length;
		if((paramName == 'j_username' || paramName == 'j_nickname')){
			if (autocompletes > 0) {
				var text = '';
				//hidden div in jsp, which defines text shown before links
				var completionText = document.getElementById("autocomplete").firstChild.nodeValue;
				text+=completionText;
				//fill in autocompleteItems
				for(var i=0; i<autocompletes;i++){
					if(i>0)
						text+=', '
					var autoCompleteItem = xml.getElementsByTagName("AUTOCOMPLETE")[i].firstChild.nodeValue;
					text+='<a href="javascript:autoCompleteItem(\''+autoCompleteItem+'\',\''+autoCompleteFieldName+'\');" class=\'LinkContent\' tabindex=\'100\'>'+autoCompleteItem+'</a>';
				}
				document.getElementById("autocomplete").innerHTML = text;
				document.getElementById("autocomplete").style.display = 'block';
			} else if(errors == 0){
				mdiv.style.display = "none";
				mdiv.innerHTML = "";
				document.getElementById("autocomplete").style.display = 'none';			
			} else
				document.getElementById("autocomplete").style.display = 'none';
		}
	}
	
	function autoCompleteItem(item, fieldName){
		var pos = 0;
    	if(fieldName == 'j_username')
    		pos = 1;		
        document.getElementsByName(fieldName)[pos].value = item;
        document.getElementsByName(fieldName)[pos].text = item;
		if(fieldName == 'j_username'){
        	checkUsername();
        	document.getElementById("j_password1").focus();
        }else if(fieldName == 'j_nickname' && document.getElementById("j_address")){
        	document.getElementById("j_address").focus();
        }
		if(document.getElementsByName(fieldName)[pos]){
			var colorDiv = document.getElementsByName(fieldName)[pos];
			colorDiv.className = getCSSClass(colorDiv);
        }
        document.getElementById(fieldName+"_message").innerHTML = "";
        document.getElementById(fieldName+"_message").style.display = 'none'; 
    	if(fieldName == 'j_username')               
        	document.getElementById("autocomplete").innerHTML = "Bitte geben Sie eine andere Usernamen ein oder w&auml;hlen Sie einen unserer Vorschl&auml;ge aus: ";
        else
        	document.getElementById("autocomplete").innerHTML = "Bitte geben Sie eine andere Nickname ein oder w&auml;hlen Sie einen unserer Vorschl&auml;ge aus: ";
        document.getElementById("autocomplete").style.display = 'none';
	}