var book_details = function() {
    return {
        init : function(){
            //Book Email Code
            $("[name=email_book]").submit(function(){return false;});
            $("#email_send").click(function(){
                    //Check To For An Email Address
                    email_to = $("#email_to").val(); 
                    if(!(Validate_Email_Address(email_to))){alert("Please provide and email address.");}
                    else{
                        //Get Values From The Book Page
                        title = $("#title").val();
                        series = $("#series").val();
                        id = $("#id").val();
                        link = $("#email_url_link").val();
                        
                        //Create The Message Body
                        body = "The Book, "+title+", has been suggested to you.\n\nGo to the following URL to view this book's details.\n\n"+link;
                        
                        //Mail Out the Message
                        $("#email_div").hide();
                        mailto = email_to+"?subject="+escape(title)+"&body="+escape(body);
                        document.location.href = "mailto:"+mailto;
                    }
                });

            //Book Information Request Code
            $('[name=info_request_email]').submit(function(){return false;});
            $('#info_request_email_send').click(function(){
                    form_error = false;
                    //Validate Form
                    if($('[name=info_request_email_fname]').val() == ""){form_error = true;}
                    if($('[name=info_request_email_lname]').val() == ""){form_error = true;}
                    if(!(Validate_Email_Address($('[name=info_request_email_to]').val()))){form_error = true;}
                    if(form_error == false){
                       form_data = $('[name=info_request_email]').serialize();
                       id = $('[name=id]').val(); 
                       $.getJSON(id+"/send_info_request/", form_data, function(data){
                                if(data.success == true){
                                    $('#info_request_email_div').hide();
                                    alert("Request Sent!");
                                    }
                            });
                        }
                    else{
                        alert("Please complete the Information Request Form.");
                    }
                });

            //Show/Hide Email Book Form
            $('#email_link').click(function(){
                $('#email_to').val("");
                $('#email_div').show();
            });
            $('#email_hide_link').click(function(){
                $('#email_div').hide();
            });
            //Show/Hide Request Book Information
            $('#info_request_email_link').click(function(){
                $('[name=info_request_email_to]').val("");
                $('[name=info_request_email_fname]').val("");
                $('[name=info_request_email_lname]').val("");
                $('#info_request_email_div').show();
            });
        $('#info_request_email_hide_link').click(function(){
                $('#info_request_email_div').hide(); 
            });
            
        }
    }
}();
$(book_details.init);
 
