var ajax = {
    sendmail: function(data) {
        ajaxQuery('sendmail', data, function(data) {
            if (data.status == 'error') document.getElementById('form_message').innerHTML = '<span style="color:#900;">' + data.html + '</span>';
            else {
                document.getElementById('form_message').innerHTML = '<span style="color:#090;">' + data.html + '</span>';
                setTimeout('refreshPage()',2000);
            }
        });
    }
}


function reQuery(func){setTimeout(func,1000);}
function refreshPage(){window.location.href=window.location.href.replace(/#.*$/,'');}
function ajaxQuery(query,params,callback) {
    if (typeof(query)=='undefined') return false;
    params['rnd'] = Math.random();
    $.getJSON('/ajax/'+query+'/',params,function(data){
        if (data==null || data.status=='waiting'){reQuery(function(){ajaxQuery(params,callback)}); return false;}
        if (typeof(callback)=='function'){callback(data);}
    });
}
