/**
 * Created by IntelliJ IDEA.
 * User: Magistr
 * Date: 06.12.2010
 * Time: 22:03:10
 * To change this template use File | Settings | File Templates.
 */
var ad_form_dialog = null;
function ad_open_form(adId)
{
    showAjaxLoadingOverlay();
    dojo.xhrPost({
        url: langPrefix+'ad/get-ad-form',
        content:{
            ad_id: adId
        },
        handle: function(html){
            hideAjaxLoadingOverlay();
            var title = html.match('<title>(.*?)</title>');
            ad_form_dialog = new dijit.Dialog({
                title: title[1],
                content: html
            });
            ad_form_dialog.show();
        }
    });
}

function ad_send_form()
{
    showAjaxLoadingOverlay();
    var ad_fields = dojo.query('.ad_field', ad_form_dialog.id);
    var data = [];
    for (var i in ad_fields) {
        if (ad_fields[i].type == 'checkbox')
            data[ad_fields[i].id] = ad_fields[i].checked?'Yes':'No';
        else
            data[ad_fields[i].id] = ad_fields[i].value;
    }
    dojo.xhrPost({
        url: langPrefix+'ad/send-ad-form',
        handleAs: 'json',
        content: data,
        handle: function(info){
            hideAjaxLoadingOverlay();
            ad_form_dialog.hide();
            setTimeout(function(){alert(info.message);}, 300);
        }
    });

}
