var link4CurrentURL = function() {

    var fieldName = "link4currentURL";

    function checkFieldExistence() {
    
        if ( jQuery("input[name='"+fieldName+"']").length == 0) {

            var selector = jQuery("form#zamow_rozmowe_form").length > 0 ? "form#zamow_rozmowe_form" : "form";
            jQuery(selector).append("<input type='hidden' name='link4currentURL' value='' />");
        }
    }
    
    function getCurrentURL() {
        
        var url = document.location.href;
        url = escape(url);
        url = url.replace(/\+/g, "%2B");
        url = url.replace(/\//g, "%2F");
        
        return url;
    }
    
    function appendCurrentURLiFFieldEmpty() {
            
        if ( jQuery("input[name='"+fieldName+"']").val() == "") {
                jQuery("input[name='"+fieldName+"']").val(getCurrentURL());
        }            
    }    
        
    return {
        
        init: function() {
        
            checkFieldExistence();
            appendCurrentURLiFFieldEmpty();
        }
    }
}();

jQuery(document).ready(function() { link4CurrentURL.init(); });