Registration = (function(aRegistrationCode,aUrl,someSettings){
	var registrationCode = aRegistrationCode;
	var url = aUrl;
	var profile = null;
	var settings = {
		cookiePrefix: 'userProfile_'
	};
	$.extend(settings,someSettings);
	
	function getRegistrationCode(){
		return registrationCode;
	}
	function getRegiCookie(){
		return GetCookie (settings.cookiePrefix + getRegistrationCode());
	}
	function isLoggedOn(){
		return getRegiCookie() != null;
	}
	function getUsername(){
		var username = (getRegiCookie().split(':'))[1];
		if(username.indexOf('|') != -1) {
			username = (username.split('|'))[0];
		}
		return username;
	}
	function getSecureCode(){
		return (getRegiCookie().split(':'))[0];
		
	}
	function getProfile(){
		if(isLoggedOn() && profile==null && RegistrationWSSoapHttpPort_getUserBySecurecode){
			profile = RegistrationWSSoapHttpPort_getUserBySecurecode(getRegistrationCode(),getSecureCode());
		}
		return profile;
	}
	function getUser(){
		var user = null;
		var profile = getProfile();
		if(profile!=null){
			user = profile.user;
		}
		return user;
	}
	function gotoRegistration(layoutUrl,method,lang){
		var seperator = '?';
		if(layoutUrl.indexOf('?') != -1) {
			seperator = '&';
		}
		var myUrl = document.location.href;
		if(myUrl.indexOf('?') != -1) {
			myUrl += "&rnd="+ new Date().getTime();			
		}else{
			myUrl += "?rnd="+ new Date().getTime();	
		}
		var regUrl = layoutUrl + seperator + 'method=' + method + '&returnUrl=' + escape(myUrl); //niet meer nodig, geeft error +'&lang='+lang;
		location.href = regUrl;
	}
	function login(){
		gotoRegistration(url,'login',null);
	}
	function logoff(){
		gotoRegistration(url,'logoff',null);
	}
	function register(){
		gotoRegistration(url,'new',null);
	}
	function change(){
		gotoRegistration(url,'change',null);
	}
	
	this.isLoggedOn = isLoggedOn;
	this.getUsername = getUsername;
	this.getUser = getUser;
	this.gotoRegistration = gotoRegistration;
	this.login = login;
	this.logoff = logoff;
	this.register = register;
	this.change = change;
	this.getSecureCode= getSecureCode;
	this.getRegistrationCode = getRegistrationCode;	
});
