﻿
EAT.Contact = function(){

    var main = function(){
    
        /* Private */
        
        /* Properties */
        
        var cmp = null;
        
        
        /* Methods */
        
        var init = function(){
        
                        // List restaurant form
            $('#listRestaurantForm .sendMessage').click(function() {


                var name = $('#listRestaurantForm #txt_name').val();
                var restaurantName = $('#listRestaurantForm #txt_restaurantName').val();
                var email = $('#listRestaurantForm #txt_email').val();
                var phone = $('#listRestaurantForm #txt_phone').val();
                var message = $('#listRestaurantForm #txt_message').val();
                var errors = "";
                if (name == "") {
                    errors += "Please enter your name<br />";
                }
                if (restaurantName == "") {
                    errors += "Please enter your restaurant name<br />";
                }
                if (email == "") {
                    errors += "Please enter your email address<br />";
                }
                if (phone == "") {
                    errors += "Please enter your phone number<br />";
                }
                if (message == "") {
                    errors += "Please enter a message<br />";
                }
                if (errors != "") {
                    $('#contactErrors').html(errors);
                    return false;
                }
                $('#contactErrors').html('');
                TVI.ajax({
                    url: '/handlers/app.aspx/contactUs',
                    data: '{ \"d\": { ' +
                            '\"name\": \"' + name + '\", ' +
                            '\"restaurantName\": \"' + restaurantName + '\", ' +
                            '\"surname\": \"' + name + '\", ' +
                            '\"email\": \"' + email + '\", ' +
                            '\"telephone\": \"' + phone + '\", ' +
                            '\"message\": \"' + message + '\" ' +
                            '} }',
                    success: function(d) {

                        $('#contactErrors').html('Your message has been sent');

                    },
                    failure: function(d) {
                        $('#contactErrors').html(d.errors[0].message);
                    }

                });


                return false;
            });
        
        };
        
        
        /* Public */
        
        return {
        
            /* Properties */
        
            test: 'test',
            
        
            /* Methods */
        
            init: function(){
            
                /* Constructor */
                
                cmp = this;
            
                //wait for jQuery to load and initialise object
                $(init);
            
            },
            
            test: function(){
            
                /* Test function  */
            
                // Code goes here
            
            }
        
        }
    
    };
    
    var m = new main();
    m.init();
    
    return m;

}();