LandingPage = function(landing_type)
{
    that = this;
    that.landing_page_type = landing_type;
    that.isGFC = false ;                    //Know if it comes from Google Connect
    that.login_username = $j('#username');
    that.login_password = $j('#password');
    that.school_id      = $j('#school_id');
    that.district_id    = $j('#district_id');
    that.inst_name      = $j('#inst_name');
    that.login_go2url   = $j('#go2url');
    that.login_language = $j('#language');
    that.login_error    = $j('#error');

    var LOGIN_CODE_REQUIRED_ID = '#facebox div.code-verification-status > div.required';
    //--------------------------------
    // Ids to get the DOM elements from the Sign Up Form
    var 
    USERNAME_ID           = '#facebox .username',
    USER_TYPE_ID          = '#facebox .user-type',
    TEACHER_INPUTS_ID     = '#facebox .teacher',
    STUDENT_INPUTS_ID     = '#facebox .student',
    USERNAME_CHECKING_ID  = '#facebox div.username-status > div.checking',
    USERNAME_REQUIRED_ID  = '#facebox div.username-status > div.required',
    USERNAME_INVALID_ID   = '#facebox div.username-status > div.invalid',
    USERNAME_TAKEN_ID     = '#facebox div.username-status > div.taken',
    USERNAME_MSGS_ID      = '#facebox div.username-status > *',
    USERNAME_AVAILABLE_ID = '#facebox div.username-status > div.available',
    SIGNUP_BTN_ID         = '#facebox input.sign-up',
    LOADING_ID            = '#facebox img.go-loading',
    FNAME_ID              = '#facebox .first-name',
    FNAME_REQUIRED_ID     = '#facebox div.first-name-required',
    LNAME_ID              = '#facebox .last-name',
    LNAME_REQUIRED_ID     = '#facebox div.last-name-required',
    EMAIL_ID              = '#facebox .email',
    EMAIL_REQUIRED_ID     = '#facebox div.email-status > div.required',
    EMAIL_CHECKING_ID     = '#facebox div.email-status > div.checking',
    EMAIL_TAKEN_ID        = '#facebox div.email-status > div.taken',
    EMAIL_INVALID_ID      = '#facebox div.email-status > div.invalid',
    EMAIL_AVAILABLE_ID       = '#facebox div.email-status > div.available',
    EMAIL_MSGS_ID         = '#facebox div.email-status > *',
    PASSWORD_ID           = '#facebox .password',
    PASSWORD_REQUIRED_ID  = '#facebox div.password-required',
    CODE_ID               = '#facebox .group-code',
    CODE_MSGS_ID          = '#facebox div.group-code-status > *',
    CODE_REQUIRED_ID      = '#facebox div.group-code-status > div.required',
    CODE_INVALID_ID       = '#facebox div.group-code-status > div.invalid',
    CODE_CHECKING_ID      = '#facebox div.group-code-status > div.checking',
    CODE_VALID_ID         = '#facebox div.group-code-status > div.valid',

    SCHOOL_CODE_ID               = '#facebox .school-code',
    SCHOOL_CODE_MSGS_ID          = '#facebox div.school-code-status > *',
    SCHOOL_CODE_REQUIRED_ID      = '#facebox div.school-code-status > div.required',
    SCHOOL_CODE_INVALID_ID       = '#facebox div.school-code-status > div.invalid',
    SCHOOL_CODE_CHECKING_ID      = '#facebox div.school-code-status > div.checking',
    SCHOOL_CODE_VALID_ID         = '#facebox div.school-code-status > div.valid',
    
    ERRORS_ID             = '#facebox input.error',
    SIGNUP_FORM_ID        = '#facebox form.da-signup-form',
    GFC_SIGNUP_FORM_ID    = '#facebox form.gfc-signup-form', 
    AN_ERROR              = '#facebox div.an-error',
    FP_EMAIL_ID           = '#facebox .email',
    FP_ERRORS_ID          = '#facebox div.msgs-container > *',
    GOOGLE_BTN_ID         = '#facebox .go-google-signup',
    STUDENT               = 'STUDENT',
    TEACHER               = 'TEACHER',
    SLOW_CLIENT_LOADING_ID = '#slow-client-loading',
    USERNAME_MIN_LENGTH = 3;

    //--------------------------------
    // This variable is used to store the last entered 
    // username to see if an avaibility ajax call is needed
    this.last_username = '';

    this.init = function()
    {
        //--------------------------------
        // load the onclick functions of the "sign-up" links
        $j('.signup .teacher').bind('click', { type: TEACHER }, this.showSignUp );
        $j('.signup .student').bind('click', { type: STUDENT }, this.showSignUp );

        //--------------------------------
        // load the onclick function of the "forgot-password" link
        $j('#form_login>.pwd>a').bind('click', this.showForgotPassword);

        //--------------------------------
        // load the onclick function of the "Google Sign Up" button
        $j('#google-signup').bind('click', this.showGoogleSignUp);

        //--------------------------------
        // Check if the user has cookies enabled in their system
        this.check4cookies();

    };

    this.showGoogleSignUp = function(e)
    {
        $j.facebox( {div:'#google-signup-tpl', title: translated_text['google-sign-up']} );
        $j(GOOGLE_BTN_ID).bind('click', that.googleSignUp);
    };

    this.googleSignUp = function(e)
    {

        $j(LOADING_ID).show();
        $j(GOOGLE_BTN_ID).hide();

        var email_obj = $j( EMAIL_ID );
        var email = email_obj.val();

        //-------------------------
        // Hide all the errors on the form
        $j( ERRORS_ID ).removeClass('error');
        $j(  AN_ERROR ).hide();
        $j( FP_ERRORS_ID ).hide();
        $j( PASSWORD_REQUIRED_ID ).hide();

        if( email == '' )
        {
            email_obj.addClass('error');
            $j( EMAIL_REQUIRED_ID ).show();
        }
        else if( email.search( EMAIL_REGEX ) == -1 )
        {
            email_obj.addClass( 'error' );
            $j( EMAIL_INVALID_ID ).show();
        }

        var password_obj = $j( PASSWORD_ID );
        var password = password_obj.val();

        if( password == '' )
        {
            password_obj.addClass( 'error' );
            $j( PASSWORD_REQUIRED_ID ).show();
        }


        if( $j( ERRORS_ID ).length == 0 )
        {
            goAjax('/index/ajax-google-sign-up', {'email' : email, 'password' : password}, that.afterGoogleSignUp);
        }
        else
        {
            $j(LOADING_ID).hide();
            $j(GOOGLE_BTN_ID).show();
        }

    };

    this.afterGoogleSignUp = function(xresponse)
    {
        var response = eval('(' + xresponse + ')');
        if( !response['status'] )
        {
            $j(LOADING_ID).hide();
            $j(GOOGLE_BTN_ID).show();
            $j(AN_ERROR).show();
        }
        else if ( response['login'] )
        {
            document.location = '/home';
        }
        else
        {
            that.isGFC = true;
            var 
            email = response['email'],
            signTitle = $j( '.sign-up' ).val();
            
            $j.facebox( {div:'#gfc-sign-up-form', title: signTitle} );

            $j( STUDENT_INPUTS_ID ).show();
            $j( TEACHER_INPUTS_ID ).hide();

            var student_btn_j = $j('#facebox .gfc-student')
                .bind('click', { type: STUDENT }, function(e)
                    {
                        that.toogleGFCInputs(e);
                        student_btn_j.prior_img = 'http://images.edmodo.com/images/backgrounds/btns/button_Student_on.png';
                    } 
                )
                .hover(function()
                    {
                        student_btn_j.prior_img = student_btn_j.attr('src');
                    
                        student_btn_j
                            .attr('src', 
                            'http://images.edmodo.com/images/backgrounds/btns/button_Student_on.png');
                    },
                    function()
                    {
                        student_btn_j.attr( 'src', student_btn_j.prior_img );
                    }
                )
            ,
            teacher_btn_j = $j('#facebox .gfc-teacher')
                .bind('click', { type: TEACHER }, function(e)
                    {
                        that.toogleGFCInputs(e);
                        teacher_btn_j.prior_img = 'http://images.edmodo.com/images/backgrounds/btns/button_Teacher_on.png';
                    } 
                )
                .hover(function()
                    {
                        teacher_btn_j.prior_img = teacher_btn_j.attr('src');
                    
                        teacher_btn_j
                            .attr('src', 
                            'http://images.edmodo.com/images/backgrounds/btns/button_Teacher_on.png');
                    },
                    function()
                    {
                        teacher_btn_j.attr( 'src', teacher_btn_j.prior_img );
                    }
                )
            ;
            
            $j( EMAIL_ID ).val(email);            
        }
    };

    this.showForgotPassword = function(e)
    {
        $j.facebox( {div:'#forgot-password-form', title: e.target.title} );
        $j('#facebox input.send-fp').bind('click', that.checkFPemail);
        $j( FP_EMAIL_ID ).bind('blur', {key : 'email'}, function(e){inputOnBlur(this, e.data.key);});
        $j( FP_EMAIL_ID ).bind('focus', {key : 'email'}, function(e){inputOnFocus(this, e.data.key);});
    }

   /**
    * Checks the "Forgot Password" form's email address
    */
    this.checkFPemail = function()
    {
        var email_obj = $j( FP_EMAIL_ID );
        var email = email_obj.val();

        //-------------------------
        // Hide all the errors on the form
        $j( FP_ERRORS_ID ).hide();
        $j(  AN_ERROR ).hide();

        //-------------------------
        // Hide all the errors on the form
        if( email == translated_text['email'] )
        {
            email_obj.addClass('error');
            $j('#facebox .required').show();
        }
        else if( email.search( EMAIL_REGEX ) == -1 )
        {
            email_obj.addClass('error');
            $j('#facebox .invalid').show();
        }
        else
        {
            $j('#facebox .checking').show();
            goAjax('/index/ajax-forgot-password', {'email' : email}, that.afterForgotPassword);
        }

    };

    this.afterForgotPassword = function( xhresponse )
    {
        var response = eval( '(' + xhresponse + ')' );
        if ( response['status'] )
        {
            // display success message
            $j.facebox.close();
            $j('#fp-success').show();
        }
        else
        {
            $j( FP_ERRORS_ID ).hide();
            $j('#facebox .doesnt-exist').show();
        }
    }

   /**
    * Shows or hides some of the fields of the form, depending
    * if the user is signing up as a student or as a teacher
    * @param object e The event object
    */
    this.showSignUp = function(e)
    {
        var type = e.data.type;

        $j.facebox( {div:'#sign-up-form', title: e.target.title} );

        //-------------------------------------
        // Hide/Show inputs depending on the user type signing up
        if( type == TEACHER )
        {
            $j( STUDENT_INPUTS_ID ).hide();
            $j( TEACHER_INPUTS_ID ).show();

            if($j( SCHOOL_CODE_ID ).length){
                // Give focus to the school code field if it exists
                $j( SCHOOL_CODE_ID ).trigger('focus');
            }else{
                // Give focus to the username field
                $j( USERNAME_ID ).trigger('focus');
            }
        }
        else
        {
            $j( TEACHER_INPUTS_ID ).hide();
            $j( STUDENT_INPUTS_ID ).show();

            //-------------------------------------
            // Give focus to the Group Code field
            $j( CODE_ID ).trigger('focus');
        }

        //-------------------------------------
        // Set the proper user type on the hidden form's value
        $j( USER_TYPE_ID ).val( type );

        //-------------------------------------
        // Bind the 'onblur' event of the username field to check for the username avaibility
        $j( USERNAME_ID ).bind( 'blur', that.usernameExists );

        //-------------------------------------
        // Bind the 'click' event to the "Sign Up" button
        //_jq( SIGNUP_BTN_ID ).bind('click', that.validateFields);


    };

   /**
    * Checks if the username typed in by the user is already taken
    */
    this.usernameExists = function(e)
    {
        var username = e.target.value;

        if( username != this.last_username )
        {
            $j( USERNAME_MSGS_ID ).hide();
            $j( USERNAME_ID ).removeClass('error');

            if(username.length > USERNAME_MIN_LENGTH)
            {
                if(username.search( USERNAME_REGEX ) != -1)
                {
                    $j( USERNAME_CHECKING_ID ).show();

                    //-------------------------------------
                    // Hide the "Sign Up" button
                    that.toggleSignUpBtn(false);

                    that.checkInDB({username : username}, false);
                }
                else
                {
                    $j( USERNAME_INVALID_ID ).show();
                    $j( USERNAME_ID ).addClass('error');
                }
            }
            else if(username.length > 0)
            {
                $j( USERNAME_REQUIRED_ID ).show();
                $j( USERNAME_ID ).addClass('error');
            }

            //-------------------------------------
            // Save the last typed username
            this.last_username = username;
        }
    };

   /**
    * Shows/hides the Sign Up Button and shows Loading gif
    * @param bool show Tells whether to show the button or hide it
    */
    this.toggleSignUpBtn = function(show)
    {
        if(show)
        {
            //-------------------------------------
            // Show the "Sign Up" button and
            // hide the Loading gif
            $j(SIGNUP_BTN_ID).show();
            $j(LOADING_ID).hide();
        }
        else
        {
            //-------------------------------------
            // Hide the "Sign Up" button and
            // show the Loading gif
            $j(SIGNUP_BTN_ID).hide();
            $j(LOADING_ID).show();
        }
    };


   /**
    * Validates the form fields and registers the user
    */
    this.validateFields = function(){

        var type = $j( USER_TYPE_ID ).val( type );

        //-------------------------------------
        // Creates a list of inputs to validate 
        // and their corresponding "required" error
        var fields = new Array();
        
        if(that.isGFC != true)
        {
            fields[PASSWORD_ID] = {
                'require-msg' : PASSWORD_REQUIRED_ID,
                'min-length'  : 4
            };
            fields[USERNAME_ID] = {
                'require-msg' : USERNAME_REQUIRED_ID,
                'msgs'        : USERNAME_MSGS_ID,
                'min-length'  : USERNAME_MIN_LENGTH
            };
        }
        fields[FNAME_ID] = {
            'require-msg' : FNAME_REQUIRED_ID,
            'min-length'  : 1
        };
        fields[LNAME_ID] = {
            'require-msg' : LNAME_REQUIRED_ID,
            'min-length'  : 1
        };

        //---------------------
        // Hide the email errors, regardless of the type
        $j( EMAIL_ID ).removeClass('error');
        $j( EMAIL_MSGS_ID ).hide();

        if( type == TEACHER )
        {
            fields[EMAIL_ID] = {
                'require-msg' : EMAIL_REQUIRED_ID,
                'msgs'        : EMAIL_MSGS_ID,
                'min-length'  : 1
            };
            if(that.landing_page_type == 'INSTITUTIONAL'){
                fields[SCHOOL_CODE_ID] = {
                    'require-msg' : SCHOOL_CODE_REQUIRED_ID,
                    'msgs'        : SCHOOL_CODE_MSGS_ID,
                    'min-length'  : 1
                };
            }
        }
        else
        {
            fields[CODE_ID] = {
                'require-msg' : CODE_REQUIRED_ID,
                'msgs'        : CODE_MSGS_ID,
                'min-length'  : 1
            };
        }

        //-------------------------------------
        // Iterate on the fields list validating it's
        // contents and displaying the error if necessary
        for( var i in fields )
        {
            if( $j( i ).val().length < fields[i]['min-length'] )
            {
                if( typeof fields[i]['msgs'] != 'undefined' )
                {
                    $j( fields[i]['msgs'] ).hide();
                }
                $j( fields[i]['require-msg'] ).show();
                $j( i ).addClass('error');
            }
            else
            {
                $j( fields[i]['require-msg'] ).hide();
                $j( i ).removeClass('error');
            }
        }

        //-------------------------------------
        // Check the email and the code 
        // group values agains the DB
        var values2check = {};

        var email = $j( EMAIL_ID ).val();
        var group_code = $j( CODE_ID ).val();
        var school_code = that.landing_page_type == 'INSTITUTIONAL' ? $j( SCHOOL_CODE_ID ).val() : '';
        var username = $j( USERNAME_ID ).val();

        if( email != '' )
        {
            if( email.search( EMAIL_REGEX ) != -1 )
            {
                //-------------------------------------
                // Add the email to the checklist
                values2check['email'] = email;

                $j( EMAIL_MSGS_ID ).hide();
                $j( EMAIL_ID ).removeClass('error');

                //-------------------------------------
                // Show the "checking" label
                $j( EMAIL_CHECKING_ID ).show();
            }
            else
            {
                $j( EMAIL_ID ).addClass('error');
                $j( EMAIL_INVALID_ID ).show();
            }
        }

        if( type == STUDENT && group_code != '' )
        {
            //-------------------------------------
            // Add the code group to the checklist
            values2check['group-code'] = group_code;

            $j( CODE_MSGS_ID ).hide();
            $j( CODE_ID ).removeClass('error');

            //-------------------------------------
            // Show the "checking" label
            $j( CODE_CHECKING_ID ).show();
        }

        if ( type == TEACHER && school_code != '')
        {
            //-------------------------------------
            // Add the school code to the checklist
            values2check['school-code'] = school_code;

            $j( SCHOOL_CODE_MSGS_ID ).hide();
            $j( SCHOOL_CODE_ID ).removeClass('error');

            //-------------------------------------
            // Show the "checking" label
            $j( SCHOOL_CODE_CHECKING_ID ).show();
        }

        if ( that.isGFC != true && username.length > USERNAME_MIN_LENGTH )
        {
            if( username.search( USERNAME_REGEX ) != -1 )
            {
                //-------------------------------------
                // Add the code group to the checklist
                values2check['username'] = username;

                $j( USERNAME_MSGS_ID ).hide();
                $j( USERNAME_ID ).removeClass('error');

                //-------------------------------------
                // Show the "checking" label
                $j( USERNAME_CHECKING_ID ).show();
            }
            else
            {
                $j( USERNAME_ID ).addClass('error');
                $j( USERNAME_INVALID_ID ).show();
            }
        }


        if( count(values2check) > 0 )
        {
            //-------------------------------------
            // Hide the "Sign Up" button
            that.toggleSignUpBtn(false);

            that.checkInDB( values2check, true );
        }

    };

    this.checkInDB = function( params, sign_up )
    {
        // Sends the sign up flag to the server so it can be echoed back
        params['sign-up'] = sign_up;

        if(that.landing_page_type == 'INSTITUTIONAL'){
            params['school_id'] = that.school_id.val();
            params['district_id'] = that.district_id.val();
        }
        goAjax( '/index/ajax-check-in-db', params, that.afterCheckInDB);
    };

    this.afterCheckInDB = function( xresponse )
    {
        var response = eval('(' + xresponse + ')');

        var fields2check = new Array();

        fields2check['email'] = {
            'field'         : EMAIL_ID,
            'msgs'          : EMAIL_MSGS_ID,
            'invalid-msg'   : EMAIL_TAKEN_ID,
            'valid-msg'     : EMAIL_AVAILABLE_ID,
            'success'       : false
        };

        fields2check['username'] = {
            'field'         : USERNAME_ID,
            'msgs'          : USERNAME_MSGS_ID,
            'invalid-msg'   : USERNAME_TAKEN_ID,
            'valid-msg'     : USERNAME_AVAILABLE_ID,
            'success'       : false
        };

        fields2check['group-code'] = {
            'field'         : CODE_ID,
            'msgs'          : CODE_MSGS_ID,
            'invalid-msg'   : CODE_INVALID_ID,
            'valid-msg'     : CODE_VALID_ID,
            'success'       : true
        };

        var type = $j( USER_TYPE_ID ).val();
        if(that.landing_page_type == 'INSTITUTIONAL' && type == TEACHER){
            fields2check['school-code'] = {
                'field'         : SCHOOL_CODE_ID,
                'msgs'          : SCHOOL_CODE_MSGS_ID,
                'invalid-msg'   : SCHOOL_CODE_INVALID_ID,
                'valid-msg'     : SCHOOL_CODE_VALID_ID,
                'success'       : true
            };

            if(typeof response['school_id'] != 'undefined'){
                //if the school code check was successful, set the school_id
                that.school_id.val(response['school_id']);
            }
        }

        for( var i in fields2check)
        {
            if( typeof response[i] != 'undefined' )
            {
                //-----------------------------------
                // clear all messages and errors
                $j( fields2check[i]['msgs'] ).hide();
                $j( fields2check[i]['field'] ).removeClass('error');

                //-----------------------------------
                // If the server response is what's expected,
                // display the success message :)
                if( response[i] == fields2check[i]['success'] )
                {
                    $j( fields2check[i]['field'] ).removeClass('error');
                    $j( fields2check[i]['valid-msg'] ).show();
                }

                //-----------------------------------
                // Otherwise, display an error message :(
                else
                {
                    $j( fields2check[i]['field'] ).addClass('error');
                    $j( fields2check[i]['invalid-msg'] ).show();
                }
            }
        }

        if( response['sign-up'] == 'true' )
        {
            that.signUp();
        }
        else
        {
            //-------------------------------------
            // Hide the "Sign Up" button
            that.toggleSignUpBtn(true);
        }
    };

    this.signUp = function()
    {
        if( $j( ERRORS_ID ).length == 0 )
        {
            if(that.isGFC != true)
                var params = $j( SIGNUP_FORM_ID ).serialize();
            else 
                var params = $j( GFC_SIGNUP_FORM_ID ).serialize();
            
            if(that.landing_page_type == 'INSTITUTIONAL'){
                params += '&school_id=' + that.school_id.val() + '&district_id=' + that.district_id.val();
            }

            //alert("YAY");
               goAjax('/index/ajax-sign-up', params, that.afterSignUp);
        }
        else
        {
            //-------------------------------------
            // Show the "Sign Up" button
            that.toggleSignUpBtn(true);
        }
    };

    this.afterSignUp = function( xresponse )
    {

        response = eval('(' + xresponse + ')');

        if( response['result'] )
        {
            document.location = '/home';
        }
        else
        {
            $j( AN_ERROR ).show();
            //-------------------------------------
            // Show the "Sign Up" button
            that.toggleSignUpBtn(true);
        }

    };

    this.checkIfVerifySchoolCode = function(){
        var params = {
            'username'    : that.login_username.val(),
            'password'    : that.login_password.val(),
            'school_id'   : that.school_id.val(),
            'district_id' : that.district_id.val(),
            'inst_name'   : that.inst_name.val()
        };
        goAjax('/institutional/check-if-verify', params, that.afterCheckIfVerify);
        //return false to stop form submittal
        return false;
    };

    this.afterCheckIfVerify = function(xhresponse){
        var response = eval( '(' + xhresponse + ')' );
        //alert('ver: '+ response['must_verify_code'] +', login_res: '+ response['login_result'] +', user_associated_to_school: '+response['user_associated_to_school']);

        var go2url = that.login_go2url.val();
        var language = that.login_language.val();
        if(language != '' && go2url.indexOf('?language=') == -1){
            go2url += '?language=' + language;
        }

        if(response['must_verify_code']){
            if(typeof response['school_id'] != 'undefined'){
                //Set the school_id
                that.school_id.val(response['school_id']);
            }

            //show code validation popup
            that.showCodeValidationPopup(go2url);
            
        }else if(response['login_result'] == 1){
            //go to the homepage or wherever the user wanted
            document.location = go2url;
        }else{
            //show login error
            that.login_error.children('span').text(translated_text['error' + response['login_result']]);
            that.login_error.show();
        }
    };

    this.showCodeValidationPopup = function(go2url){
        $j(SLOW_CLIENT_LOADING_ID).hide();
        $j.facebox( {div:'#code-verification', title: translated_text['verify-school-code']} );
        var code_input = $j('#facebox input.code-verification-input');

        $j('#facebox input.send-code').click(function(){
            var school_code = code_input.val();
            if(school_code.replace(/ /g, '') != '' && school_code != translated_text['school-code-no-colon']){
                that.sendCodeForVerification(school_code, go2url);   
            }else{
                $j( LOGIN_CODE_REQUIRED_ID ).show();
            }
        });
        code_input.bind('blur', {key : 'school-code-no-colon'}, function(e){inputOnBlur(this, e.data.key);});
        code_input.bind('focus', {key : 'school-code-no-colon'}, function(e){inputOnFocus(this, e.data.key);});
    };

    this.sendCodeForVerification = function(school_code, go2url){
        var params = {
            'school_code'        : school_code,
            'username'    : that.login_username.val(),
            'password'    : that.login_password.val(),
            'school_id'   : that.school_id.val(),
            'district_id' : that.district_id.val(),
            'go2url' : go2url
        };
        var url = '/institutional';

        var myForm = document.createElement("form");
        myForm.method = "post" ;
        myForm.action = url;
        for (var k in params) {
            var myInput = document.createElement("input") ;
            myInput.setAttribute("name", k) ;
            myInput.setAttribute("value", params[k]);
            myForm.appendChild(myInput) ;
        }
        document.body.appendChild(myForm);
        myForm.submit();
        document.body.removeChild(myForm);
    };
  
    this.toogleGFCInputs = function ( e )
    {
        $j( FNAME_REQUIRED_ID ).hide();
        $j( LNAME_REQUIRED_ID ).hide();
        $j( CODE_MSGS_ID ).hide();
                
        var type = e.data.type;
        $j( USER_TYPE_ID ).val( type );
        
        if( type == TEACHER)
        {
            $j('#facebox .gfc-student').attr('src', 'http://images.edmodo.com/images/backgrounds/btns/button_Student_off.png');
            $j('#facebox .gfc-teacher').attr('src', 'http://images.edmodo.com/images/backgrounds/btns/button_Teacher_on.png');                              
        	$j('#facebox .gfc-teacher').blur();
            $j( STUDENT_INPUTS_ID ).hide();
            $j( TEACHER_INPUTS_ID ).show();  
        }
        else
         {
            $j('#facebox .gfc-student').attr('src', 'http://images.edmodo.com/images/backgrounds/btns/button_Student_on.png');
            $j('#facebox .gfc-teacher').attr('src', 'http://images.edmodo.com/images/backgrounds/btns/button_Teacher_off.png');                              
         	$j('#facebox .gfc-student').blur();
            $j( STUDENT_INPUTS_ID ).show();
            $j( TEACHER_INPUTS_ID ).hide();
         }       
    } ;

    this.check4cookies = function()
    {
        /*
        var tmpcookie = new Date();
        chkcookie = (tmpcookie.getTime() + '');
        document.cookie = "chkcookie=" + chkcookie + "; path=/";

        if (document.cookie.indexOf(chkcookie,0) < 0)
        {
            $j('#allow-cookies').show();
        }
        */
        var cookieEnabled = navigator.cookieEnabled ? true : false;

        //if not IE4+ nor NS6+
        if(typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)
        { 
            document.cookie = "testcookie";
            cookieEnabled = document.cookie.indexOf("testcookie") != -1 ? true : false;
        }

        if (!cookieEnabled)
        {
            $j('#allow-cookies-error').show();
        }

    };

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // NEW LANDING PAGE STUFF
    
    var
    i=0,
    
    _Tab = Tab,
    
    _FaceBox = $j.facebox,
    
    _translated_text = translated_text,
    
    _landing_jq = $j( '#landing' ),
    
    _feature_links_jq = $j( '.features a' ),
    
    _feature_index = 0,
    
    _feature_index_str = 'ind',
    
    _tour_tmp_jq = $j( '#tour_video' ),
    
    _feature_templates_jq = $j( '#feature_tmps' ).children(),
    
    _marketing_tabs = [],
    _benefits_btn_jq = _landing_jq.find( '.col2 .tab.n1' ),
    _benefits_tab_jq = _landing_jq.find( '.benefits' ),
    
    _features_btn_jq = _landing_jq.find( '.col2 .tab.n2' ),
    _features_tab_jq = _landing_jq.find( '.features' );
    
    _marketing_tabs.push(
        new _Tab( _benefits_btn_jq, _marketing_tabs, _benefits_tab_jq ),
        new _Tab( _features_btn_jq, _marketing_tabs, _features_tab_jq )
    );
    _marketing_tabs[0].select();
    
    _landing_jq.find( '.tour.btn' ).click(function(){
        _FaceBox( _tour_tmp_jq.clone().show() );
        _FaceBox.setTitle( _translated_text.tour );
    });
    
    
    function showFeature( _index )
    {
        var _feature_jq = $j(_feature_templates_jq[ _index ]).clone();
    
        _FaceBox( _feature_jq );
        
        _FaceBox.setTitle( _translated_text[ 'edmodo-features' ] );
        
        $j( '#facebox .next' ).click(function(){ showNextFeature() });
        $j( '#facebox .prev' ).click(function(){ showPrevFeature() });
        
        _feature_index = _index;
    }
    
    function showNextFeature()
    {
        _feature_index++;
        showFeature( _feature_index );
    }
    
    function showPrevFeature()
    {
        _feature_index--;
        showFeature( _feature_index );
    }
    
    function onClickFeatureLink()
    {
        showFeature( $j(this).data(_feature_index_str) );
    }
    
    /*_feature_links_jq.each(function()
    {
        $j( this )
        .data( _feature_index_str, i )
        .click( onClickFeatureLink );
        
        i++;
    });*/
}








