
jQuery(document).ready(function() {

    jQuery('.contact_us').css('display', 'none');
    /* set global variable for boxy window */
    var contactBoxy = null;
    /* what to do when click on contact us link */   
    jQuery('.contact_us').click(function(){
        var boxy_content;
        var pathname = window.location.pathname;
        boxy_content += "<div style=\"width:300px; height:300px\"><form id=\"feedback\">";
        boxy_content += "<p>Telefon<br /><input type=\"text\" name=\"telefon\" id=\"telefon\" size=\"30\" /></p><p>E-mail <em style=\"color: red\">(povinné)</em>:<br /><input type=\"text\" name=\"your_email\" id=\"validate\" size=\"30\" /></p><p>Text <em style=\"color: red\">(povinné)</em>:<br /><textarea name=\"comment\" id=\"comment\" cols=\"34\" rows=\"5\"></textarea></p><input type=\"submit\" name=\"submit\" value=\"Odeslat dotaz\" />";
        boxy_content += "<input type=\"hidden\" name=\"lokace\" value=\"" + pathname + "\">";
        boxy_content += "</form></div>";
        contactBoxy = new Boxy(boxy_content, {
            title: "Jaký máš dotaz?",
            draggable: false,
            modal: true,
            behaviours: function(c) {
                c.find('#feedback').submit(function() {
                
                jQuery(".error25").hide();
                  var hasError = false;
                  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
           
                  var emailaddressVal = jQuery("#validate").val();
                  if(emailaddressVal == '') {
                      jQuery("#validate").after('<span class="error25">Nezapomeň vložit svůj e-mail.</span>');
                      hasError = true;
                  }
           
                  else if(!emailReg.test(emailaddressVal)) {
                      jQuery("#validate").after('<span class="error25">Prosíme, vlož platný e-mail.</span>');
                      hasError = true;
                  }
           
                  if(hasError == true) { return false; }else{
                    Boxy.get(this).setContent("<div style=\"width: 300px; height: 300px\">Odesílám...</div>");
                    // submit form by ajax using post and send 3 values: subject, your_email, comment
                    jQuery.post("js/feedback/feedback.php", { telefon: c.find("input[name='telefon']").val(), lokace: c.find("input[name='lokace']").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;    
    });
});



