function Login(){

    me = this;    
    //input names 
    var REGISTER_NAME = '#registrationName';
    var REGISTER_EMAIL = '#registrationEmail';
    var REGISTER_PASSWORD = '#registrationPassword';    
    
    //input fields
    var r_name = null;
    var r_email = null;
    var r_password = null;  
    
    //error divs
    var email_error = $j('#emailError');
    var name_error = $j('#nameError');
    var pass_error = $j('#passwordError');
    var message_div = $j('#reg_message_div');
    var reg_div = $j('#reg_div');
    
    
    //***************************INITIALIZE VARIABLES***************************
    //**************************************************************************    
    
    me.main = function( ){        
        r_name = $j( REGISTER_NAME );
        r_email = $j( REGISTER_EMAIL );
        r_password = $j( REGISTER_PASSWORD );
        fillDefaultText();
        hideDivs();
    }

    //Default text of the fields
    var fillDefaultText = function( ){
        fusion.ui.fillDefaultText( r_name,     translated_text['full-name']);
        fusion.ui.fillDefaultText( r_email,    translated_text['your-email'] );
        fusion.ui.fillDefaultText( r_password, translated_text['password'] );
    } 
    //hide error div messages
    var hideDivs = function( ){
        email_error.hide();
        name_error.hide();
        pass_error.hide();
		message_div.hide();
    } 

    //*************************REGISTRATION FUNCTIONS***************************
    //**************************************************************************    
    /**
    *Function that controls the submit form
    */
    me.onRegistrationSubmit = function( ){        
        if( validateRegistrationOnSubmit( ) ){
            //document.submitRegistrationForm.submit()
            var params = $j('FORM#schoolBookRegister').serialize();
            goAjax( '/ajax/handle/ajax-action/signup', params, afterRegistered );
        }
        else{
            // call the utility class to create the overlay and throw the errors
        }
    }
    
	var afterRegistered = function(result){
		if(result=="false")
		{ popup('Try with another email adress!'); }
		else
		{
		    reg_div.hide();
		    message_div.show();
		}
	}
    /**
    *Function that validates the Registration form fields
    *Returns False or True
    */
    var validateRegistrationOnSubmit = function(){
        // validate registration
        var validate = [ ]; //variable for validations
        
        //**is email empty?**
        if( validate[0] = General.isEmpty(r_email)) 
            email_error.show() 
        else 
            email_error.hide();
            
        //**validate email sintax**
        if(!validate[0]){ 
            if( validate[1] = General.validateEmail(r_email.val())) 
                email_error.hide()
            else 
                email_error.show();
        }
        else
            validate[1] = false;   
        
        //**is name empty?**
        if( validate[2] = General.isEmpty(r_name))
            name_error.show()
        else
            name_error.hide();
        
        //**is password empty?**
        if( validate[3] = General.isEmpty(r_password))
            pass_error.show()
        else
            pass_error.hide();
        
        return ( !validate[0] && validate[1] && !validate[2] && !validate[3] );
    }
    
}


$j(document).ready(function(){
    Login = new Login();
    Login.main( );
});
