/**
 * @author jamp
 * @dependencies jquery-1.4.1.min.js
 * @dependencies form.js !important
 */

function newsletter( form ){

    /**
     * @var instance self
     **/
    var self = this;

    /**
     * @var object settings
     **/
    this.settings = {
        file: {
            send: 'ajax/newsletter.php'
        },
        container: {
            clas: '.newsletter-message-box'
        }
        
    };

    /**
     * @var string form
     **/
    this.form = form;

    /**
     * @var int error
     **/
    this.error = 0;

    /**
     * Calls itself every second and slideUp an Div element
     * after the given time
     *
     * @param string idElement
     * @param int time
     * @return void
     **/
    this.timer = function( idElement, time ){
        if( time==0 ){
            $( idElement ).stop(true, true).slideUp('fast');
        } else {
            time--;
            setTimeout('newsletter.timer(\''+idElement+'\','+time+');',1000);
        }
    };

    /**
     * Sends the form error/success code to get the message
     *
     * @param string data
     * @return void
     **/
    this.message = function( data ){

        $.ajax({
            url: self.settings.file.message,
            data: 'json='+data,
            dataType: 'json',
            type: 'post',
            success: function( html ){
                
            }
        });
    };

    /**
     * Send an activation request to the ajax file
     *
     * @param sring activation
     * @param string email
     * @return void
     **/
    this.aktivieren = function( activation, email ){
        if( activation==null ) alert( 'activation is empty.' );
        if( email==null ) alert( 'email is empty.' );

        $.ajax({
            url: self.settings.file.send,
            data: 'mode=aktivieren&aktivierung='+activation+'&email='+email,
            type: 'post',
            success: function( html ){
                if( html!='done' ){
                    $( self.settings.container.clas ).html( html ).css({ display: 'block' });
                }
            }
        });
    };

    /**
     * Sends a deactivation request to the ajax file
     *
     * @param string activation
     * @param string email
     * @return void
     */
    this.deaktivieren = function( activation, email ){
        if( activation==null ) alert( 'activation is empty.' );
        if( email==null ) alert( 'email is empty.' );

        $.ajax({
            url: self.settings.file.send,
            data: 'mode=deaktivieren&aktivierung='+activation+'&email='+email,
            type: 'post',
            success: function( html ){
                if( html!='done' ){
                    $( self.settings.container.clas ).html( html ).css({ display: 'block' });
                }
            }
        });
    };

    

}
