//function for the feedback form

$(function() {
    /* set global variable for boxy window */
    var contactBoxy = null;
    /* what to do when click on contact us link */
    $('.contact_us').click(function(){
        var boxy_content;
        boxy_content += "<div style=\"width:300px; height:300px \">";
        boxy_content += " <form action='feedback' id=\"feedbacked\">";
        boxy_content += "    <p>Send us an email or have a look at our ";
        boxy_content += "    <a target='_blank' href='http://sourceforge.net/apps/phpbb/easyrec/'>forum<a/>.";
        boxy_content += "    <br/>Subject<br/>";
        boxy_content += "    <input type=\"text\" name=\"subject\" id=\"subject\" size=\"41\" />";
        boxy_content += "    </p><p>Your name and/or email<br />";
        boxy_content += "    <input type=\"text\" name=\"email\" size=\"41\" /></p>";
        boxy_content += "    <p>Comment<br /><textarea name=\"comment\" id=\"comment\" cols=\"31\" rows=\"4\"></textarea></p>";
        boxy_content += "    <a href='#' onclick='javascript:document.forms[\"feedbacked\"].submit();'>send<a/>";
        boxy_content += "</form></div>";
        contactBoxy = new Boxy(boxy_content, {
            title: "Send feedback",
            draggable: false,
            modal:true,
            behaviours: function(c) {
                c.find('#feedbacked').submit(function() {
                    Boxy.get(this).setContent("<div style=\"width: 300px; height: 300px\">Sending...</div>");
                    // submit form by ajax using post and send 3 values: subject, your_email, comment
                    $.post("suggest.php", { subject: c.find("input[name='subject']").val(), your_email: c.find("input[name='your_email']").val(), comment: c.find("#comment").val()},
                    function(data){
                        /*set boxy content to data from ajax call back*/
                        contactBoxy.setContent("<div style=\"width: 300px; height: 300px\">"+data+"</div>");
                    });
                    return false;
                });
            }
        });
        return false;
    });
});
