$.fn.includeForm = function(url, callback) {
    var obj = null;
    var u = '';
    if (url.split('?').length == 2) u = url + '&rnd=' + new Date().getTime();
    else u = url + '?rnd=' + new Date().getTime();

    var e = function() {
        form = obj.find('form');
        form.submit(function() {
            $.post(u, form.serialize(), v);
            return false;
        }); 

        try{
            // Init form calendars
            obj.find('.init-calendar').each(function(i){
                new tcal({
                    'controlname':this.id, 
                    'place':this.parentNode, 
                    'lang':'ru'
                });

            });

            // Init form calendar intervals 
            obj.find('.init-calendar-interval').each(function(i){
                for(j=0; j<2; ++j){
                    e = f_getElement(this.id + '['+j+']');
                    new tcal({
                        'controlname':e.id, 
                        'place':e.parentNode, 
                        'lang':'ru',
                        'intervalpair':[
                            this.id + '[0]',
                            this.id + '[1]'
                        ],
                        'intervalupdatecont' : this.id
                    });
                }
            });
            
        }catch(ex){}
    }

    var v = function(text, status, xhr) {
        if (status == 'success'){
            text = text.split('<!--includeForm-->');
            if (text.length == 3) {
                obj.html(text[1]);
                e();
                if (callback && typeof callback == "function")
                    callback(obj);
            }
            else alert('<!--includeForm--> missing');
        }
    }

    obj = $(this);
    $.get(u, null, v);
}


