function EvolverSSO(contentTargets, useOAuth) {

    var that = this;

    this.contentTargets = contentTargets;
    this.useOAuth = (useOAuth) ? true : false;

    McomSSO.prototype.constructor.apply(this, [this.contentTargets,this.useOAuth]);

    //check if user looged in ( EvoSSO cookie exists ).
    //alert( 'sso begins' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
	
    //console.group('oAuthUser');
    //console.log( this.OAuthUser );
    //console.dir( this.OAuthUser );
    //console.groupEnd();
	
    that.setFriendsportalProfileInfo();


    if( $.cookie("EvoSSO") != null ){//if EvoSSO cookie exists, login user in wp
        //alert( 'EvoSSO not null' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        //console.log( 'EvoSSO not null' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        if( $.cookie("wordpress_logged_in_") == null ){//if wp cookie does not exists, create

            var data = {
                action: 'sso_create_wp_cookie',
                ssoUserName: this.get_user_name()
            };
            ajaxurl=ssoConfig.ssoServicePath  ;

            $.post( ajaxurl, data, function( response ) {

                if( !response )
                    return false;

                obj = window.JSON.parse(response);

                var res_error = obj.error;
                var res_mess = obj.message;

                if( res_error == 1 ){//if there is an error from the server...

                    //console.log( obj.message );
                    return false;

                }
                else{
                    //console.log( obj.message );
                    return true;
                }
            })//END: post
        }//END:  no wp cookie check

        $('#SSOLoggedInFragment').show();
        $('#simplemodal-container, #simplemodal-overlay, #SSOLoggedOutFragment').hide();
        $('#ForumLoginForm').hide();
        
        
		
    }
    else{// if evosso cookie not good delete all wp cookies
        //alert( 'EvoSSO null' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        //console.log( 'EvoSSO null' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
		
        if( $.cookie("wordpress_logged_in_") != null )
            $.cookie("wordpress_logged_in_", null, {
                path: '/'
            });
        
        //FBittner: remove SsoSessionCookie as well here
        $.cookie('SsoSessionCookie', null, {
            path: '/',
            domain: ssoConfig.ssoCookieDomain
        })
        //also remove those that might have accidently be set on a subdomain
        $.cookie('SsoSessionCookie', null, {
            path: '/'
        })
    }

    /*
     * authenticates an existing EvoSSOUser with credentials
     */
    this.authenticateViaCredentials = function(ssoUserName, ssoPassword, ssoKeepLoggedIn) {
		
        //alert( 'authenticateViaCredentials overwrite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
		
        //check to see id user or pass not empty
        if( ! this.checkUserPass( ssoUserName, ssoPassword )){
            this.handle_form_error( ssoConfig.ssoLoginErrorMessage 	);
            return false;
        }

        var data = {
            action: 'sso_login_user',
            user: ssoUserName,
            pass: ssoPassword
        };
		
        //console.log( 'authenticateViaCredentials overwrite: before sso_login_user callback' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        $.modal.close();
        
        //gerold does not like the knightrider loading animation
        //modal_b = $.modal("<div><img src='/SysRes/VOLSkin/Groups/SSO/ajax-loader.gif'></div>", {
        //    minHeight:15, 
        //    minWidth: 140
        //});
        $.post( ssoConfig.ssoServicePath, data, function( response ) {

			
            if( !response ){
				
                $.modal.close();
                that.showLoginForm();
                that.handle_form_error( ssoConfig.ssoLoginCantConnectMessage );
                return false;
            }

            obj = window.JSON.parse(response);

            //console.log( obj.error );
            //console.log( obj.message );

            var res_error = obj.error;
            var res_mess = obj.message;

            //for single page comment form login
            if( (typeof comment_login_error) == 'function' )
                comment_login_error(obj);

            $.modal.close();
            if( res_error == 1 ){//if there is an error from the server show it
				
				
                that.showLoginForm();
                that.handle_form_error( res_mess );
                return obj;

            }
            else//no error from the server
            if( res_error == 0 ){//if user is autentificated, set cookie and reload
					
                //cookie for local testing
                //$.cookie( 'EvoSSO', 'h=1bb979300b03fb1063d656c2f7d8a5e9&l=misstesty2&t=bb20196185c742633da2029a8f98987a', { path : '/', domain:'.medienhaus.com' });
					
                $('#Footer #ssoImage').append( res_mess );
                //alert('bigmess');
                //$('#Footer #ssoImage img').load( that.login_user( ));
					
                $('#Footer #ssoImage img').load( function( res_mess ){
                    //console.log( 'EvoSSO' );
                    //console.log( res_mess );
                    //console.log( $.cookie('EvoSSO'));
                    that.login_user( );
                });
					
            }
            else{ //if user loggout, hide item

                this.logout();
            }

        });
		

    }//END:authenticateViaCredentials

    /*
     * public callback method to do action after authenticateViaCredentials has been called
     */
    this.onAuthenticateViaCredentials = function (data, textStatus, xmlHttpRequest) {
		
    //alert( 'onAuthenticateViaCredentials ovewrite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
    //console.log( 'onAuthenticateViaCredentials ovewrite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );


    }//END:onAuthenticateViaCredentials

    /*
     * authenticates an existing McomSSOUser with credentials and connects to a given OAuthUser
     */ 
    this.authenticateForOAuthConnection = function(ssoUserName, ssoPassword, ssoKeepLoggedIn) {
        
        //console.log( 'authenticateForOAuthConnection ovewrite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        
        if( $('#SSOUserConnect').val() == '' || ( $('#SSOPasswordConnect').val() == '' )){
            that.handle_form_error( ssoConfig.ssoLoginErrorMessage );
            return false;
        }
		
        try {
            data = {
                //action:'sso_fb_login_user',
                action:'authenticate_for_oauth_connection',
                user: ssoUserName, 
                pass: ssoPassword, 
                oauth_id: that.oAuthUser.id, 
                //facebookAppId: ssoConfig.oAuthAppId , 
                bKeepLoggedIn: ssoKeepLoggedIn,
                oauth_access_token: that.oAuthUser.token
            };
            $.post( ssoConfig.ssoServicePath, data, that.onAuthenticateForOAuthConnection, 'json' );
        }
        catch (e) {
            //console.log(e);
            //alert( 'Login failed!' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
            alert( 'Login failed!' );
        }
    }
    
    /*
     * public callback method to do action after authenticateForOAuthConnection has been called
     */
    this.onAuthenticateForOAuthConnection = function( data ) {
        
        //console.group('onAuthenticateForOAuthConnection overwrite');
        //console.log( data );
        //console.log( data.error );
		
        if ( data.error == '0' ) {
            //console.log( 'login and connection successfull, show preferences dialogue' );
            // login and connection successfull, show preferences dialogue
            // - get the local sso user if available
            //$('#SSOLoggedInFragment').append( data.message );
            
            $('#Footer #ssoImage').append( data.message );
            $('#Footer #ssoImage img').load( function( ){
                //console.log( 'EvoSSO' );
                //console.log( res_mess );
                //console.log( $.cookie('EvoSSO'));
                that.login_user( );
            });
			
            that.ssoUser = that._readSSOCookie();
            //console.log( that.ssoUser );
            
            // - show the preferences dialogue
            that.showActiveForm = that.showOAuthPreferencesForm;
            that.showActiveForm();
        }
        else {
            //handle errors
            that.handle_form_error( data.message );
        //that.handleOAuthConnectFormErrors( data.message );
        }
    //console.groupEnd();
        
    }
    

    /*
	 * logout function
	 */
    this.logout = function (){
		
        //console.group( 'logout' ); 
        //console.log(that.useOAuth);
        //console.log(that.oAuthUser);
		
		
        //alert( 'logout' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
		
        //console.log(FB.getSession());
        //if no fb session no fb logout
        if ( FB.getAuthResponse() != null){
            //alert( 'getSession' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
            if( that.oAuthUser != null ){
                //console.log( 'fb cookie deleted' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
                FB.logout();
            }
        }
				
        var data = {
            action: 'sso_logout_user'
        };

        $.post( ssoConfig.ssoServicePath, data, that.onLogout, 'json' );
		
    //console.groupEnd();
    }

    /*
	 * logout function
	 */
    this.onLogout = function( res ) {

        //alert( 'onLogout ovewrite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        //console.log( 'onLogout ovewrite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        //console.log( 'res:%o \n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName, res );
	

        if( res.error == 1 ){
            //console.log ('Could not connect to login server');
            return false;
        }
		
        //delete wp cookie
        if( $.cookie("wordpress_") != null ){
            $.cookie("wordpress_", null, {
                path: '/'
            });
        }
        if( $.cookie("wordpress_logged_in_") != null ){
            $.cookie("wordpress_logged_in_", null, {
                path: '/'
            });
        }
        
        //FBittner: remove SsoSessionCookie as well here
        $.cookie('SsoSessionCookie', null, {
            path: '/',
            domain: ssoConfig.ssoCookieDomain
        });
        //also remove those that might have accidently be set on a subdomain
        $.cookie('SsoSessionCookie', null, {
            path: '/'
        })
		
        var ar=location.host.split('.');
        var dim = location.host.split('.').length;
        ndomain = '.'+ar[dim-2]+'.'+ar[dim-1];
        //console.log( ndomain );
        $.cookie("EvoSSO", null, {
            path: '/', 
            domain:ndomain
        });
		
        //delete EvoSSO cookie
        //$('#SSOLoggedInFragment').append( res.message );
        $('#Footer #ssoImage').append( res.message );
        $('#Footer #ssoImage img').load( function( res_mess ){
            if( $.cookie("EvoSSO") != null ){
				
                //alert( 'EvoSSO cookie not null' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
                //console.group( 'onlogout' );
                //console.log( 'EvoSSO cookie not null:'+ $.cookie("EvoSSO") + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
				
                var ar=location.host.split('.');
                var dim = location.host.split('.').length;
                ndomain = '.'+ar[dim-2]+'.'+ar[dim-1];
                $.cookie("EvoSSO", null, {
                    path: '/', 
                    domain:ndomain
                });
				
            //console.groupEnd();
            }
            else{
            //console.log( 'EvoSSO cookie null:'+ $.cookie("EvoSSO") + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
            }
			
            //redirect to homepage
            //alert( 'redirect' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
            window.location = 'http://' + window.location.hostname;
        })
    }
	
  	
		
    this.onOAuthGetLoginStatus = function(response, isTriggered){
		
        //alert( 'onOAuthGetLoginStatus suprascris' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
		
        //toggle the login form as active form
			
        that.isTriggered = isTriggered;
		
        //console.dir(response.authResponse);
        //console.dir(response.authResponse.accessToken);
        //console.log(response.authResponse.accessToken);
		
        //console.group('onOAuthGetLoginStatus');
        //console.log(response);
        //connectedUserName = $(response).children("string").text();
        //console.log($(response).children("string").text());
        //console.groupEnd();
				
        switch (response.status) {  
            case 'connected':
                //user is already logged in via oAuth and has authorized our app - cool, isn' it?
                
                // ask the oAuth api and set the oAuthUser
                // @todo for future release: we might need to be able to use api's other than facebook
                if ( typeof(FB.api) !== 'undefined' ) {
                    FB.api('/me', function(response) {
						
                        //console.group('response from fb');
                        //console.dir(response);
                        //console.groupEnd();
						
                        var oAuthCookie = null;         //cookie data
                        var oAuthCookieValues = null;   //array to hold all key/value pairs read from oAuthCookie
                        var oAuthToken = null;          //token read from oAuthCookie
                        
                        /* //read the oAuthCookie to retrieve the token
                        oAuthCookie = that.getCookie('fbs_' + ssoConfig.oAuthAppId);
                        oAuthCookie = oAuthCookie.replace(/\"/g, '');
                        oAuthCookieValues = oAuthCookie.split(/\&/);
                        for (var i = 0; i < oAuthCookieValues.length; i++) {
                            var value = oAuthCookieValues[i].split(/\=/);
                            if (value[0] == 'access_token') oAuthToken 	= value[1];      
                        }
                        */
                        oAuthToken = that.getTokenFromFBCookie();
                        if (oAuthToken != null) {
						
                            //set the oAuthUser if we got everything
                            that.oAuthUser = new OAuthUser(response.id, response.name, response.first_name, response.last_name, oAuthToken);
                           
                            //console.group('that.oAuthUser');
                            //console.dir(that.oAuthUser);
                            //console.groupEnd();
                            
                            //try to login user using oauth
                            var data = {
                                //action:'sso_fb_login_user',
                                action:'check_fb_user_exists',
                                oauth_id: that.oAuthUser.id,
                                oauth_access_token: that.oAuthUser.token
                            }
                            //check the local connection via webservice
                            //we wil only do something if nobody is logged in
							
                            //console.log( $.modal( $( '#ajax-loading' )));
                            //console.log( $( '#ajax-loading' ).modal());
                            //console.log($.modal("<div><h1>SimpleModal</h1></div>"));
                            $.modal.close();
                            //gerold does not like the knightrider loading animation
                            //modal_b = $.modal("<div><img src='/SysRes/VOLSkin/Groups/SSO/ajax-loader.gif'></div>", {
                            //    minHeight:15, 
                            //    minWidth: 140
                            //});
                            //console.log( modal_b );
                            //modal_b.close();
							
							
                            if ( that.ssoUser == null || that.ssoUser.active == false ){
								
                                $.post( ssoConfig.ajaxServicePath, data, that.onOAuthCheckConnection, 'json' ) 
                                
                            }
                        }
                    });
                }
                break;
            default:
                //user is not logged in via oAuth or has not authorized our app  
                that.oAuthUser = null;
                //toggle the login form as active form
                that.showActiveForm = that.showLoginForm;
                
                break; 
        }
		        
    }
	
    /*
     * public callback method to do action after the oAuthConnection has been checked
     */
    this.onOAuthCheckConnection = function( data ) {
        
        var connectedUserName;  //the username of the local connected McomSSOUser

        //alert( 'onOAuthCheckConnection overwrite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        
        var group = 'onOAuthCheckConnection overwrite';
        //console.group(group);
        //console.log( data );
        //console.dir( data );
        //console.log( data.error );
		        
        if( data.error == '1' ){
            connectedUserName = '';
        }
        else{
            connectedUserName = data.message;
        }
		
        //data must contain a name(or '') is some form
        //connectedUserName = 'gicu';
        
        //connectedUserName = $(data).children("string").text()
        
        //console.log( connectedUserName );
        //console.dir( connectedUserName );
        //console.groupEnd();
        //either we have local connection yet or not
        
        
        if ( connectedUserName == '' ) {
        
            //we did not store any connection in our local sso for this oAuthUser
            // - so the connect form or the register form needs to be toggled as active form
            if (that.ssoUser != null && that.ssoUser.active == false) {
                // - if we have a user that recently logged out (SSOSessionCookie is there, but inactive)
                // we show a connect form
                // alert( 'we show a connect form' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
                that.showActiveForm = that.showOAuthConnectForm
            } else {
                // - otherwise we show a registration form
                //alert( 'otherwise we show a registration form' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
                that.showActiveForm = that.showOAuthRegisterForm;
            }
            
            //check form preferences on basis of what button the user clicked
            // - if user clicked a login-style button, he might already have a local user account
            //   - show the connect form
            // - if user clicked a registration style button, he might not have a local user account
            //   - show the registration form
            if (that.formPreference != null) {
                that.showActiveForm = that.formPreference;
            }
            
            
            
            
            
            //if the user is activily trigering this process, we want actual show the form
            if(that.isTriggered) {
                that.showActiveForm();
            }
            
        } else {
            //maybe our user is already logged in locally?
            if (that.ssoUser != null && that.ssoUser.active == true && that.ssoUser.userName == connectedUserName) {
            //@todo: I am not sure if that really can be the case here - do nothing for the moment
            } else {
                //let's try to log the user in locally!
                that.authenticateViaOAuthToken();                
            }
        }
        
    }
    
	
    this.registerForOAuthConnection = function(ssoUserName, ssoPassword, ssoFirstName, ssoLastName, ssoEmail, ssoMarketing, ssoTermsAndConditions) {
		
        //alert( 'submited form' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
		
        //check if everything in form is ok before submit
        if( !this.check_validation_before_submit( )){
            return false;	
        }
		
        //check if email exists in sso
        /*if( !this.check_email_exist('SSOEmailSignUp')){
			//this.onOAuthCheckConnection( 'gicu', 'success', '' );
			//this.showOAuthConnectForm();
			return false;	
		};*/
		
        data = {	
            action : 'on_register_for_oauth_connection',
            username: ssoUserName, 
            password: ssoPassword, 
            firstname: ssoFirstName, 
            lastname: ssoLastName, 
            email: ssoEmail, 
            marketing: ssoMarketing, 
            termsandconditions: ssoTermsAndConditions, 
            fbid: that.oAuthUser.id, 
            fbtoken: that.oAuthUser.token
        }
        $.post( ssoConfig.ajaxServicePath, data, this.onRegisterForOAuthConnection, 'json' );
        
    }
	
    this.onRegisterForOAuthConnection = function( data ){
		
        //alert( 'onRegisterForOAuthConnection overite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
		
        var group = 'onRegisterForOAuthConnection override';
		
        //console.group(group);
        //console.log( data );
        //console.dir( data );
        //console.log( that.OAuthUser );
        //console.groupEnd();
		
        if( data.error == 0 ){
			
            //alert( 'login user' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
            //
            that.showOAuthConnectForm();
            //SSOUserConnect
            $('#SSOUserConnect').val('kk');
        //$.modal.close();
        }
        else{
            //alert( 'error: '+ data.message + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
            //alert( 'You have been registered on the site.\nPlease check your email and validate your account' );
            //console.log( 'error: '+ data.message + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
            that.check_checkbox( 'fbRegisterNewButton',  data.message ); 
        }
		
		
    }
	
	
    
    /*
     * login an active OAuthUser user using his OAuthToken
     */
    this.authenticateViaOAuthToken = function() {
		
        //alert( 'authenticateViaOAuthToken overwrite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        //console.group(' authenticateViaOAuthToken overwrite' );
        //console.groupEnd();
		
        if (that.oAuthUser != null) {
            //try to login user using oauth
            var data = {
							
                action:'sso_fb_login_user',
                oauth_id: that.oAuthUser.id,
                oauth_access_token: that.oAuthUser.token
            }
			
            if ( that.ssoUser == null || that.ssoUser.active == false ){
				
                $.post( ssoConfig.ajaxServicePath, data, function( response ){
					
                    if( response.error == 0 ){
						
                        //alert( 'logged in via fb! (reload page)' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
                        //console.log( 'logged in via fb! (reload page)' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
					
                        //cookie for local testing
                        //$.cookie( 'EvoSSO', 'h=60b9d1831bbe056e64fe442df47ace7d&l=misstesty2&t=a39613c0ad8485f70c85a4972e7f8fd3', { path : '/', domain:'.medienhaus.com' });
							
                        $('#Footer #ssoImage').append( response.message );
                        $('#Footer #ssoImage img').load( function(res_mess){
                            //console.log( 'EvoSSO' );
                            //console.log( res_mess );
                            //console.log( $.cookie('EvoSSO'));
                            that.login_user( );
                        });
					
                    }
                    else{//check if user has validated email
						
                        alert( 'You are registered on the site.\nPlease check your email and validate your account');
                        //console.log( 'You are registered on the site. Please check your email and validate your account' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
                        location.reload();
                    }
				
                }, 'json' ); 
            }
        }
    }

    /*
     * display the login form
     */
    this.showLoginForm = function () {
        // 1. check on possible prerequisites (i.e. user needs to be logged out)
        // - assign the correct error handler
        that.handleErrors = that.handleLoginFormErrors;
        // - remove any error messages
        $('#McomSSOLoginForm .SSOFieldMessage').text('');
        $('#McomSSOLoginForm .SSOFieldMessage').hide();
        
        // @todo
        
        // 2. close all other modal windows
        $.modal.close()

        // 3. attach submit/click events on the proper elements
        // attach click event on the OAuthLoginButton
        $('#McomSSOLoginForm #OAuthLoginButton').unbind();
        $('#McomSSOLoginForm #OAuthLoginButton').click( function () {
            FB.login(function(response) {
                //call the onOAuthGetLoginStatus method as
                that.onOAuthGetLoginStatus(response, true);
            //}, {perms:'email'});
            });
        });
        // attach submit event to login form
        $('#McomSSOLoginForm').unbind();
        $('#McomSSOLoginForm').submit( function () {
            that.authenticateViaCredentials($('#SSOUser').val(), $('#SSOPassword').val(), document.getElementById('SSOKeepLoggedIn').checked);
            return false;
        });
        
        // 4. use simplemodal to display a prerendered dialog in modal window
        $('#McomSSOLoginForm').modal({
            zIndex: 5001
        });
    }
    
	
    /*
	 * checks if username is available... ajax call to sso  
	 */ 
    this.checkUsername = function ( fieldId ) {
    	
        //alert( 'checkUsername overite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        //console.log( 'checkUsername overite' + fieldId +'\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
    	
        fieldNode = $('#' + fieldId);
        msgNode = $('#' + fieldId).closest('fieldset').find('p.SSOFieldMessage');
        descNode = $('#' + fieldId).closest('fieldset').find('p.SSOFieldDescription');
        
        //console.group('checkUsername');
        //console.debug(fieldId);
        //console.debug(fieldNode.val());
        //console.groupEnd();
                
        if ( fieldNode.val().search(/[^A-Za-z0-9\_\-]/) > -1 || fieldNode.val() == '' || fieldNode.val().length < 4 || fieldNode.val().length > 32 ) {
            msgNode.text( ssoConfig.validateUsernameNotValid );
            
            msgNode.addClass('Error');
            msgNode.removeClass('Success');
            
            descNode.hide();
            msgNode.show();
            return false;
        } else {
            msgNode.text( ssoConfig.validateChecking );
            
            msgNode.removeClass('Error');
            msgNode.removeClass('Success');
            
            descNode.hide();
            msgNode.show();
            
            var response = that.check_login_exists_in_sso( fieldNode.val() );
            if ( response == '1' ) {                       
                msgNode.text( ssoConfig.validateOk );
					
                msgNode.addClass('Success');
                msgNode.removeClass('Error');
					
                descNode.hide();
                msgNode.show();
					
                return true;
            } else {                        
                msgNode.text( ssoConfig.validateUsernameNotValid );
					
                msgNode.addClass( 'Error' );
                msgNode.removeClass( 'Success' );
					
                descNode.hide();
                msgNode.show();
                //alert( 'checkUsername: return false' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );	
                return false;
            }
        /*data = {
						action:'check_login_exists_in_sso',
						'user':fieldNode.val(),
					}
            $.post( ssoConfig.ssoServicePath ,data , function(response) {
			    if ( response == '1' ) {                       
					msgNode.text( ssoConfig.validateOk );
					
					msgNode.addClass('Success');
					msgNode.removeClass('Error');
					
					descNode.hide();
					msgNode.show();
					
					return true;
			    } else {                        
					msgNode.text( ssoConfig.validateUsernameNotValid );
					
					msgNode.addClass( 'Error' );
					msgNode.removeClass( 'Success' );
					
					descNode.hide();
					msgNode.show();
					alert( 'checkUsername: return false' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );	
					return false;
			    }
		    }, 'text');*/
            
        }
    }
	
    this.check_login_exists_in_sso = function( user_id ){
        data = {
            action:'check_login_exists_in_sso',
            'user':user_id
        }
		
        return $.post( ssoConfig.ssoServicePath ,data , function(response) { 
            return response 
        })
    }
	
    /*
     * validation handler email
     */
    this.validateEmail = function (fieldId) {
        fieldNode = $('#' + fieldId);
        msgNode = $('#' + fieldId).closest('fieldset').find('p.SSOFieldMessage');
        descNode = $('#' + fieldId).closest('fieldset').find('p.SSOFieldDescription');
        
        emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        
        if (fieldNode.val().search(emailFilter) > -1) {
            msgNode.text(ssoConfig.validateOk);
            
            msgNode.addClass('Success');
            msgNode.removeClass('Error');
            
            descNode.hide();
            msgNode.show();
            return true;
        } else {
            msgNode.text( ssoConfig.validateEmailNotValid );
            
            msgNode.addClass('Error');
            msgNode.removeClass('Success');
            
            descNode.hide();
            msgNode.show();
            return false;
        }
    }
   
    /*
     * validation handler password
     */
    this.validatePassword = function (fieldId) {
        fieldNode = $('#' + fieldId);
        msgNode = $('#' + fieldId).closest('fieldset').find('p.SSOFieldMessage');
        descNode = $('#' + fieldId).closest('fieldset').find('p.SSOFieldDescription');
        
        if (fieldNode.val().replace(/ /g, "").length >= 6) {
            msgNode.text( ssoConfig.validateOk );
            
            msgNode.addClass('Success');
            msgNode.removeClass('Error');
            
            descNode.hide();
            msgNode.show();
            
            return true;
        } else {
            msgNode.text( ssoConfig.validatePasswordTooShort );
            
            msgNode.addClass('Error');
            msgNode.removeClass('Success');
            
            descNode.hide();
            msgNode.show();
            return false;
        }
    }
    
    /*
     * validation handler firstname/lastname
     */
    this.validateName = function (fieldId) {
    
        fieldNode = $('#' + fieldId);
        msgNode = $('#' + fieldId).closest('fieldset').find('p.SSOFieldMessage');
        descNode = $('#' + fieldId).closest('fieldset').find('p.SSOFieldDescription');
		
        if (fieldNode.val().replace(/ /g, "") != '') {
            msgNode.text(ssoConfig.validateOk);
            
            msgNode.addClass('Success');
            msgNode.removeClass('Error');
            
            descNode.hide();
            msgNode.show();
            return true;
        } else {
            msgNode.text(ssoConfig.validateUsernameNotValid);
            
            msgNode.addClass('Error');
            msgNode.removeClass('Success');
            
            descNode.hide();
            msgNode.show();
            return false;
        }
    }
    
    /*
	* check user and pass client side
	*/
    this.checkUserPass = function ( ssoUserName, ssoPassword ){
        if( ssoUserName=='' || ssoPassword=='' )
            //alert('user or pass empty');
            return false;
        else
            return true;

    }
    
    /*
     * read the user data from the SSOSessionCookie
     * returns a McomSSOUser or null
     */
    this._readSSOCookie = function () {

        //alert( 'readSSOCookie rewrite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        //console.log( 'readSSOCookie rewrite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        //console.log($.cookie('EvoSSO'))	;

        var ssoCookie = null;           //cookie data
        var ssoUser = null;             //McomSSOUser object to be returned

        var ssoCookieValues = null;     //array to hold all key/value pairs read from ssoCookie
        var ssoUserName = null;         //username read from ssoCookie
        var ssoPasswordHash = null;     //password hash (token) read from ssoCookie
        var ssoFullName = null;         //full name read from ssoCookie
        var ssoActive = null;           //active/inactive status read from ssoCookie
        var ssoToken = null;           //active/inactive status read from ssoCookie

        //get the sso cookie
        ssoCookie = that.getCookie('EvoSSO');
        //no cookie? let's get outa here!
        if ( ssoCookie == null ){
            return null;
        }
        else{
            ssoActive	= true;
        }

        //read the ssoCookie content into an array via split on '&'
        ssoCookieValues = ssoCookie.split(/\&/);

        //cycle through ssoCookieValues array
        for (var i = 0; i < ssoCookieValues.length; i++) {
            //create an array holding the current key/value pair via split on '='
            var value = ssoCookieValues[i].split(/\=/);
            if (value[0] == 'l') {
                ssoUserName     = value[1].replace(/ /, '\\20');
            }
            if (value[0] == 'h') {
                ssoPasswordHash = value[1] + '==';
            }
            if (value[0] == 'l')	{
                ssoFullName		= decodeURI(value[1]).replace(/\+/g,' ');
            }
            if (value[0] == 't')	{
                ssoToken		= decodeURI(value[1]).replace(/\+/g,' ');
            }
			
        /*if (value[0] == 'active') {
			    ssoActive       = (value[1] == 'True') ? true : false;
            }*/
        }

        //create new instance of McomSSOUser if the cookie states him as active and not guest
        if (ssoUserName != 'guest') {
            ssoUser = new McomSSOUser(ssoUserName, ssoPasswordHash, ssoFullName, ssoActive);
        }
        return ssoUser;
    }
	
    /*
     * read the user data from the FB cookie
     * returns a oAuthUser or null
     */
    this.getTokenFromFBCookie = function () {
		
        //alert( 'getTokenFromFBCookie' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );	
		
        //read the oAuthCookie to retrieve the token
        oAuthCookie = that.getCookie( 'fbs_' + ssoConfig.oAuthAppId );
        if( oAuthCookie == null ){
            return null;
        }
        oAuthCookie = oAuthCookie.replace(/\"/g, '');
        oAuthCookieValues = oAuthCookie.split(/\&/);
		
        for (var i = 0; i < oAuthCookieValues.length; i++) {
            var value = oAuthCookieValues[i].split(/\=/);
            if (value[0] == 'access_token') oAuthToken 	= value[1];      
        }
		
        //console.group( 'getTokenFromFBCookie' );
        //console.log( oAuthToken );
        //console.log(  );
        //console.groupEnd();
		
        return oAuthToken;
    }
    
    that.showActiveForm = that.showLoginForm;
    that.ssoUser = this._readSSOCookie();
    
}

EvolverSSO.prototype = McomSSO.prototype;

/*
 * return username from cookie 'evosso'
 * */
McomSSO.prototype.login_user =  function(){
							
    //alert( 'load event on sso image div' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
    //console.log( 'load event on sso image div' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
    $.modal.close();
    //Navigation.User =  Navigation._ReadUserCookie();
    //Navigation.SetSSOFragment();
    this.setFriendsportalProfileInfo();
    
    location.reload();
	
// fill user info nodes
/*$(that.contentTargets.userName).text(that.ssoUser.fullName);
	$(that.contentTargets.profileLink).attr('href', ssoConfig.ssoProfileUrlPattern.replace(/{username}/, encodeURI(that.ssoUser.userName)));
	$(that.contentTargets.profileAvatar).attr('src', that.ssoUser.avatarUrl.replace(/{size}/g, 'tiny'));

	// hide content fragment for login functionality
	$(that.contentTargets.fragmentLoggedOut).hide();
	// show content fragment for logout functionality
	$(that.contentTargets.fragmentLoggedIn).show();
	*/
}

/*
 * add error to form
 * */
McomSSO.prototype.handle_form_error = function( error ){
		
    $('p.SSOFieldMessage').text( error );
    $('p.SSOFieldMessage').addClass('Error');
    $('p.SSOFieldMessage').removeClass('Success');
    $('p.SSOFieldMessage').show();
	
    return true;
	
}

/*
 * return username from cookie 'evosso'
 * */
McomSSO.prototype.get_user_name = function(){

    var cook = this.getCookie('EvoSSO');
    if (cook == null) return null;
    ssoCookieValues = cook.split(/\&/);

    for (var i = 0; i < ssoCookieValues.length; i++) {
        //create an array holding the current key/value pair via split on '='
        var value = ssoCookieValues[i].split(/\=/);
        if (value[0] == 'l') {
            ssoUserName     = value[1].replace(/ /, '\\20');
        }
    }

    return ssoUserName;
}

/*
 * check_validation_before_submit
 */
McomSSO.prototype.check_validation_before_submit = function(){

    var err = 0;
    //console.debug( 'begin: ' + err ); 
	
    if( ! this.validateEmail( 'SSOEmailSignUp' )){
        err++;
    //console.log( 'SSOEmailSignUp: ' );
    };
    //console.debug( err );
    if( ! this.validatePassword( 'SSOPasswordSignUp' )){
        err++;
    //console.log('SSOPasswordSignUp');
    };
    //console.debug( err );
    if( ! this.check_checkbox( 'SSOTermsAndConditionsSignUp', ssoConfig.ssoRegisterTACErrorMessage )){
        err++;
    //console.log( 'SSOTermsAndConditionsSignUp ');
    };
    //console.debug( err );
    if( ! this.check_checkbox( 'SSOMarketingSignUp', ssoConfig.ssoRegisterMarketingErrorMessage )){
        err++;
    //console.log('SSOMarketingSignUp');
    };
    //console.debug( err );
    /*if( !this.validateName( 'SSOUserSignUp' )){
		err++;
	};*/
    //var resp = this.checkUsername( 'SSOUserSignUp' );
    //console.log(resp);
    if( false === this.checkUsername( 'SSOUserSignUp' )){
        //console.debug( 'SSOUserSignUp' );
        err++;
		
    }	;
    //console.debug( err );
    if( err == 0 ){
        return true;
    }
    else{
        return false;
    }
}
 

//schimba check_validation_tac si check_validation_marketing cu asta
McomSSO.prototype.check_checkbox = function( fieldId, sso_error ){
		
    fieldNode = $('#' + fieldId);
    msgNode = $('#' + fieldId).closest('fieldset').find('p.SSOFieldMessage');
    descNode = $('#' + fieldId).closest('fieldset').find('p.SSOFieldDescription');
	
    //console.debug(fieldNode.attr('checked'));
		
    if ( fieldNode.attr('checked' )) {
        msgNode.text(ssoConfig.validateOk);
            
        msgNode.addClass('Success');
        msgNode.removeClass('Error');
            
        descNode.hide();
        msgNode.show();
        return true;
    } else {
        msgNode.text( sso_error );
            
        msgNode.addClass('Error');
        msgNode.removeClass('Success');
            
        descNode.hide();
        msgNode.show();
        return false;
    }
	
}


/*
 * checks if check_email_exist is available... ajax call to sso  
 */ 
McomSSO.prototype.check_email_exist = function (fieldId) {
	
    //alert( 'check_email_exist overite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
	
    fieldNode = $('#' + fieldId);
    msgNode = $('#' + fieldId).closest('fieldset').find('p.SSOFieldMessage');
    descNode = $('#' + fieldId).closest('fieldset').find('p.SSOFieldDescription');
	
    //console.group('checkUsername');
    //console.debug(fieldId);
    //console.debug(fieldNode.val());
    //console.groupEnd();
        
    emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
    if ( fieldNode.val().search(emailFilter) < 0 ) {
		
        msgNode.text( ssoConfig.validateEmailNotValid );
		
        msgNode.addClass('Error');
        msgNode.removeClass('Success');
		
        descNode.hide();
        msgNode.show();
		
        return false;
		
    }
    else {
			
		   
        data = {
            action:'check_email_exists_in_sso',
            'user':fieldNode.val()
        }
        $.post( ssoConfig.ssoServicePath ,data , function(response) {
            if ( response == '1' ) {                       
                msgNode.text( ssoConfig.validateOk );
				
                msgNode.addClass('Success');
                msgNode.removeClass('Error');
				
                descNode.hide();
                msgNode.show();
				
                return true;
            } else {                        
                //msgNode.text( ssoConfig.validateUsernameNotValid );
                msgNode.text( 'email exists' );
				
                msgNode.addClass( 'Error' );
                msgNode.removeClass( 'Success' );
				
                descNode.hide();
                msgNode.show();
				
                return false;
            }
        }, 'text')
    }
}

// read the SSOSessionCookie and place some info above the navigation
McomSSO.prototype.setFriendsportalProfileInfo = function() {
    var ssoCookie = this.getCookie('EvoSSO');
    var profileCookie = this.getCookie('SsoSessionCookie');
    var strUserName = "";
    var strFullName = "";
    
    if (ssoCookie== null || profileCookie == null){
        $('#SSOLoggedOutFragment').show();
        $('#SSOLoggedInFragment').hide();
        return; // do nothing, quit		
    }
    else{
        var cookieVals = profileCookie.split(/\&/);	
            
        for (var i = 0; i < cookieVals.length; i++) {
            var Val = cookieVals[i].split(/\=/);
            //alert("cookie: " + CookieVals[i]);

            if (Val[0] == 'username') strUserName = (""+Val[1]).replace(/ /, "\\20");
            if (strUserName != "guest") {
                if (Val[0] == 'fullname') strFullName = decodeURI(""+Val[1]).replace(/\+/g,' ');
            }
        }
            
        if ( strUserName != "" ) {
            $.modal.close();
            $('#SSOLoggedOutFragment').hide();
            $('#SSOLoggedInFragment').show();
            //console.log( 'this user: ' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
				
            // modify the UserIconProfile stuff
            $('#UserIconProfileImage').attr("src", ssoConfig.ssoAvatarUrlPattern.replace(/{username}/, encodeURI(strUserName)));
            $('#UserIconProfileImage').attr("src", $('#UserIconProfileImage').attr("src").replace(/{size}/, 'tiny'));
            $('#UserIconProfileLink').attr("href", ssoConfig.ssoProfileUrlPattern.replace(/{username}/, encodeURI(strUserName)));
				
            // modify the UserProfileData stuff
            $('#UserProfileDataName').html((strFullName != null && strFullName != '') ? strFullName : strUserName);
            $('#UserProfileLink').attr("href", ssoConfig.ssoProfileUrlPattern.replace(/{username}/, encodeURI(strUserName)));

           
					
        } else {
			
            $('#SSOLoggedOutFragment').show();
            $('#SSOLoggedInFragment').hide();
        }
    }
} 

/*
 * MainNavigationBar
 */ 

/* FBittner: this should not be in here
 * 
//method to authenticate user
MainNavigationBar.prototype.SSOAuthenticateUser = function(strUserName, strPassword, boolKeepLoggedIn, errorMessageContainer, boolReloadPage, funcSuccessCallback) {
    var NavBar = this;
     
    if (typeof errorMessageContainer != "undefined") {
        MainNavigationCommon.strErrorMsgContainer = errorMessageContainer;
    }
    else {
        MainNavigationCommon.strErrorMsgContainer = "SSOMessages";
    }

    if (typeof boolReloadPage != "undefined") {
        MainNavigationCommon.boolReloadPage = boolReloadPage;
    }
    else {
        MainNavigationCommon.boolReloadPage = true;
    }

    if (typeof funcSuccessCallback != "undefined") {
        MainNavigationCommon.funcSuccessCallback = funcSuccessCallback;
    }
    else {
        MainNavigationCommon.funcSuccessCallback = function() { };
    }

    try {
		
		//alert( 'MainNavigationCommon rewrite: ' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
		//console.log( 'MainNavigationCommon : ' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
        //$.get(MainNavigationCommon.strSNPEServicePath + MainNavigationCommon.strSSOWebServiceAuthMethod, { user: strUserName, pass: strPassword, bKeepLoggedIn: boolKeepLoggedIn }, NavBar._SSOAuthenticateUserCallback, "xml");
    }
    catch (e) {
        //alert("Login ist fehlgeschlagen.");  	
    }

}
*/

/* FBittner: this should not be in here
 * 
MainNavigationBar.prototype._ReadUserCookie = function () {
		
	//alert( '_ReadUserCookie rewrite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
	

	//console.log( $.modal( $( '#ajax-loading' )));
	//console.log( $( '#ajax-loading' ).modal());
	
	//console.log( '_ReadUserCookie rewrite' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
	//console.log($.cookie('EvoSSO'))	;
			
	var NavBar = this;
	var strUserName;
	var strPasswordHash;
	var strFullName;
	var strActive;
	var User = null;
	var SSOCookie = null;
			
	//get the cookie
	try{
		SSOCookie = NavBar._GetCookie("EvoSSO");
			
	}
	catch(e) {
		//alert( 'error: ' + e.description + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
		//console.log( 'error: ' + e.description + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
		
	}
	//if (!SSOCookie) alert("No Cookie...");
	
	if (SSOCookie == null){
		//console.log( '_ReadUserCookie rewrite: ssocookie null: ' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
		return null;		
	}
	else{
		//console.log( '_ReadUserCookie rewrite: ssocookie NOT null: ' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
		strActive = 'True';				 
	}
			
	var CookieVals = SSOCookie.split(/\&/);		
			
	for (var i = 0; i < CookieVals.length; i++) {
		var Val = CookieVals[i].split(/\=/);
		//alert("cookie: " + CookieVals[i]);
		
		if (Val[0] == 'l') 			strUserName 	= (""+Val[1]).replace(/ /, "\\20");
		if (strUserName != "guest") {
			if (Val[0] == 'h') 	strPasswordHash = (""+Val[1]) + "==";
			if (Val[0] == 'active') 		strActive 		= ""+Val[1];
			if (Val[0] == 'l')		strFullName		= decodeURI(""+Val[1]).replace(/\+/g,' ');
		}
	}
	//console.group('cookie');
		//console.log( SSOCookie );
		//console.log( strUserName );
		//console.log( strPasswordHash );
		//console.log( strFullName );
	//console.groupEnd();
	
	//alert("Active: " + strActive);
	
	if (strActive == "True") {
		User = new PortalUser(strUserName, strPasswordHash, strFullName);
	}
	//console.debug( User);
	
	return User;
}
*/

//method to set the SSO state display (user logged-in or not etc..)

/* FBittner: this should not be in here
 *
MainNavigationBar.prototype.SetSSOFragment = function () {
	
	var NavBar				= this;
	
	//console.log( 'SetSSOFragment overwrite: ' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
	
	//do only if login-stuff should be visible
	
	if ( this.boolShowLogin) {
			//console.log( 'before this user: ' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
			//console.log(this.User);
			
			//check if user is logged in...
			if ( this.User ) {
				$.modal.close();
				$('#SSOLoggedOutFragment').hide();
				$('#SSOLoggedInFragment').show();
				//console.log( 'this user: ' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
				
				// modify the UserIconProfile stuff
					$('#UserIconProfileImage').attr("src", MainNavigationCommon.strAvatarUrl.replace(/###username###/, encodeURI(this.User.strUserName)));
					$('#UserIconProfileLink').attr("href", this.strProfileUrl.replace(/###username###/, encodeURI(this.User.strUserName)));
				
				// modify the UserProfileData stuff
					$('#UserProfileDataName').html((this.User.strFullName != null && this.User.strFullName != '') ? this.User.strFullName : this.User.strUserName);
					$('#UserProfileLink').attr("href", this.strProfileUrl.replace(/###username###/, encodeURI(this.User.strUserName)));

				// set the logout action
					if (this.strLogoutUrl) {
						$('#SSOLogoutLink').attr("href", this.strLogoutUrl);
					} else {
						$('#SSOLogoutLink').click(function() {
						

								return false;
							});
					}
					
			} else {
			
				$('#SSOLoggedOutFragment').show();
				$('#SSOLoggedInFragment').hide();


				ssoLoginLink = $("a.SSOLoginLink");
				
				if (this.strOverrideLoginUrl == null) {
					ssoLoginLink.click(function() { return false; });
					ssoLoginLink.attr("href", "#");
				} else {
					ssoLoginLink.unbind("click");
					ssoLoginLink.attr("href", this.strOverrideLoginUrl);
				}
				
				// only use the formaction if there is one defined via the override method
				// - otherwise we use a onclickevent which tries to login the user via a call
				//	 to the SNPEWebservice.

					//var formLogin = document.getElementById("SSOLoginForm");
					$(document).ready( function(){
						//console.info('ver1');
						var formLogin = document.getElementById("McomSSOLoginForm");
						//console.log( 'formLogin: %o',   formLogin );
						//console.log( 'strFormAction: %o',  this.strFormAction );
						//console.log( this.strFormAction );
						//console.log( 'SSOLoginForm: this.User==null' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
						
						if ( this.strFormAction ) {
							
							formLogin.action = this.strFormAction; 
							formLogin.onsubmit = function () {};
						} else {
							
							//console.log( 'formLogin.onsubmit: this.User==null' + '\n line: ' +  (new Error).lineNumber + ' \n file:' + ( new Error).fileName );
									
							formLogin.onsubmit = function () { 
								NavBar.SSOAuthenticateUser(document.getElementById("SSOUser").value, document.getElementById("SSOPassword").value, document.getElementById("SSOKeepLoggedIn").checked); 
								return false; 
							}; 
							
						}
					})
				
			}
	}
	//do only if login-stuff should not be visible
	else {
		
		$('#SSOLoggedOutFragment').hide();
		$('#SSOLoggedInFragment').hide();
			
	}
};
*/

