﻿



var s2f = {

    send: function() {

        var parameters = {
            _a: 'send2friend',
            email: $('s2f_email').value,
            name: $('s2f_name').value,
            url: document.location.href,
            pagename: document.title
        };

        new Ajax.Request(
            "/mailformjax.html",
            { method: 'post',
                parameters: $H(parameters).toQueryString(),
                onIsNotLoggedIn: function(t) {
                    window.location.href = window.location.href;
                },

                onFeedback: function(t, feedbackInfo) {
                    var msg = '';

                    feedbackInfo.reason.each(function(s, index) {
                    if (s.dt == 'notEmpty_120' & s.code == 'TooShort') { msg += 'Vul een naam in<br/>' };
                    if (s.dt == 'email' & (s.code == 'TooShort' || s.code == 'InvalidPattern')) { msg += 'Voer een \'geldig\' mail adres in van je vriend<br/>' };
                    });
                    $('warningmsg').innerHTML = msg;
                    Element.hide('s2f_confirmation');
                    Element.show('s2f_errors');
                },

                onSuccess: function(t) {
                    Element.hide('s2f_errors');
                    Element.show('s2f_confirmation');
                    Element.hide('s2fbox');
                    Field.clear('s2f_email');
                    Field.clear('s2f_name');
                },

                onServerException: function(t) {
                    alert("Er is een fout opgetreden, probeer het later nog eens");
                }
            }

        );
    }

}


var Poke = { 

    sendMail: function( id, type, message ) { 
        
        this.type = type;
        
        var parameters = {
            _a: 'poke',
            type: type,
            id: id,
            photo_message: message
        };  
        
        new Ajax.Request( 
            "/studentjax.html", 
            {   method: 'post', 
                parameters: $H(parameters).toQueryString(),
                onIsNotLoggedIn : function(t)
                {
                    window.location.href = window.location.href;
                },
               onSuccess : function(t)
                {
                     Poke.showMessage( "Het bericht is verstuurd. Bedankt!" );
                },
                onServerException : function(t)
                {
                     Poke.showMessage( "Het bericht kon niet worden verstuurd. Sorry!" );
                }

            }
        );  
    },
        
    showMessage: function( message ) { 
    
         var name = 'poke_' + this.type; 
        
        Element.hide( name );
        
        var messageSpan = $( name + '_message' );
        messageSpan.innerHTML = message; 
        Element.show( messageSpan );
    }

    
}

