
jQuery(document).ready(function() {

    jQuery('#zmena-velikost').html('<a href="#" class="dotazat-se">Klikni a zjisti její dostupnost</a>.');
        
    
    
    /* set global variable for boxy window */
    var contactBoxy = null;
    /* what to do when click on contact us link */   
    jQuery('.dotazat-se').click(function(){
        var boxy_content;
        var pathname = window.location.pathname;
        boxy_content += "<div style=\"width:300px;\"><form id=\"velikost\">";
        boxy_content += "<p>Požadovaná velikost <em class=\"povinne\">(povinné)</em>:<br /><input type=\"text\" name=\"velikost\" size=\"3\" /><p>Tvůj e-mail <em class=\"povinne\">(povinné)</em>:<br /><input type=\"text\" name=\"email\" id=\"validate\" size=\"30\" /></p><p><a href=\"#\" class=\"dotaz-na-velikost\">Přidat poznámku?</a></p><p id=\"text-poznamky\" style=\"display: none\">Text <em style=\"font-size: 0.8em;\">(není nutné vyplnit)</em>:<br /><textarea name=\"comment\" id=\"comment\" cols=\"34\" rows=\"5\"></textarea></p><input type=\"submit\" name=\"submit\" value=\"Odeslat dotaz\" class=\"dotaz-submit\" />";
        boxy_content += "<input type=\"hidden\" name=\"lokace\" value=\"" + pathname + "\">";
        boxy_content += "</form></div>";
        contactBoxy = new Boxy(boxy_content, {
            title: "Rychlý dotaz na velikost",
            draggable: false,
            modal: true,
            behaviours: function(c) {
                c.find('#velikost').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/velikost/velikost.php", { velikost: c.find("input[name='velikost']").val(), lokace: c.find("input[name='lokace']").val(), email: c.find("input[name='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;
                    }
                });
            
            
            }
            
        });
        
              jQuery('.dotaz-na-velikost').click(function () {
                jQuery('#text-poznamky').show("slow");
              });

        return false;    
    });
});



