function configSearchForm(id){
    $.getJSON(
        '/accounts/type/'+id,
        function(data)
        {
            if (data.error == false){
                switch (data.type) {
                    case 'T':
                        $('#optfilter_profiledate').show();
                        $('#optfilter_following_less').show();
                        $('#optfilter_following_more').show();
                        $('#optfilter_followers_less').show();
                        $('#optfilter_followers_more').show();
                        $('#optfilter_followingratio_less').show();
                        $('#optfilter_followingratio_more').show();
                        $('#optfilter_statusescount').show();
                        $('#optsearch_updates').show();
                        break;
                    case 'G':
                        $('#optfilter_profiledate').hide();
                        $('#optfilter_following_less').hide();
                        $('#optfilter_following_more').hide();
                        $('#optfilter_followers_less').hide();
                        $('#optfilter_followers_more').hide();
                        $('#optfilter_followingratio_less').hide();
                        $('#optfilter_followingratio_more').hide();
                        $('#optfilter_statusescount').hide();
                        $('#optsearch_updates').hide();
                        break;
                    case 'N':
                        $('#optfilter_profiledate').hide();
                        $('#optfilter_following_less').hide();
                        $('#optfilter_following_more').hide();
                        $('#optfilter_followers_less').hide();
                        $('#optfilter_followers_more').hide();
                        $('#optfilter_followingratio_less').hide();
                        $('#optfilter_followingratio_more').hide();
                        $('#optfilter_statusescount').hide();
                        $('#optsearch_updates').hide();
                        break;
                }
            }
        }
    );
}

function doSGAction(postto, hideelem, errorelem, busydiv){
    if (busydiv != ''){
        $(busydiv).show();
    }
    $.getJSON(
        postto,
        function(data)
        {
            if (busydiv != ''){
                $(busydiv).hide();
            }
            if (data.error == true){
                $(errorelem).html(data.msg);
                $(errorelem).show();
            } else {
                if (data.credits != ''){
                    $('#creditbalance').html(data.credits);
                }
                $(hideelem).hide();
            }
        }
    );
}

function doFollow(postto, hideelem, errorelem, busydiv){
    if (busydiv != ''){
        $(busydiv).show();
    }
    $.getJSON(
        postto,
        function(data)
        {
            if (busydiv != ''){
                $(busydiv).hide();
            }
            if (data.error == true){
                $(errorelem).html(data.msg);
                $(errorelem).show();
            } else {
                if (data.credits != ''){
                    $('#creditbalance').html(data.credits);
                }
                $(hideelem).hide();
            }
        }
    );
}

function doSGFollow(postto, hideelem, errorelem, busydiv){
    if (busydiv != ''){
        $(busydiv).show();
    }
    $.getJSON(
        postto,
        function(data)
        {
            if (busydiv != ''){
                $(busydiv).hide();
            }
            if (data.error == true){
                $(errorelem).html(data.msg);
                $(errorelem).show();
            } else {
                if (data.credits != ''){
                    $('#creditbalance').html(data.credits);
                }
                $(hideelem).hide();
            }
        }
    );
}

function doUnFollow(postto, hideelem, hideelem2, errorelem, busydiv){
    if (busydiv != ''){
        $(busydiv).show();
    }
    $.getJSON(
        postto,
        function(data)
        {
            if (busydiv != ''){
                $(busydiv).hide();
            }
            if (data.error == true){
                $(errorelem).html(data.msg);
                $(errorelem).show();
            } else {
                if (data.credits != ''){
                    $('#creditbalance').html(data.credits);
                }
                $(hideelem).hide();
                if (hideelem2 != ''){
                    $(hideelem2).hide();
                }
            }
        }
    );
}

function createSGNoteForm(matchid, updatediv, elemvalue){
    content = '<form id="addnoteform_'+matchid+'" method="post" action="/socialgraph/addnote/'+matchid+'" accept-charset="utf-8"><div style="display:none;"><input type="hidden" name="_method" value="POST" /></div><input name="data[Socialgraph][graph_note]" type="text" style="display: inline; width: 400px;" value="'+elemvalue+'" /> <span class="symlink" onclick="postAjaxdiv($(this).parents(\'form\'), \'/socialgraph/addnote/'+matchid+'\', \''+updatediv+'\', \'\'); return false;">save</span><input name="submith" style="display: none;" type="submit" /></form>';
    $(updatediv).html(content);
}

function createNoteForm(matchid, updatediv, elemvalue){
    content = '<form id="addnoteform_'+matchid+'" method="post" action="/search/addnote/'+matchid+'" accept-charset="utf-8"><div style="display:none;"><input type="hidden" name="_method" value="POST" /></div><input name="data[Match][graph_note]" type="text" style="display: inline; width: 400px;" value="'+elemvalue+'" /> <span class="symlink" onclick="postAjaxdiv($(this).parents(\'form\'), \'/search/addnote/'+matchid+'\', \'#graphnote_'+matchid+'\', \'\'); return false;">save</span><input name="submith" style="display: none;" type="submit" /></form>';
    $(updatediv).html(content);
}

function postAjaxvalue(formobj, postto, updateto, busydiv) {
    var formData = $(formobj).serialize();
    if (busydiv != ''){
        $(busydiv).show();
    }
    $.ajax({
        type: 'POST',
        url: postto,
        data: formData,
        dataType: 'html',
        success: function(data){
            if (busydiv != ''){
                $(busydiv).hide();
            }
            $(updateto).val(data);
        }
    });
}

function postAjaxdiv(formobj, postto, updateto, busydiv) {
    var formData = $(formobj).serialize();
    if (busydiv != ''){
        $(busydiv).show();
    }
    $.ajax({
        type: 'POST',
        url: postto,
        data: formData,
        dataType: 'html',
        success: function(data){
            if (busydiv != ''){
                $(busydiv).hide();
            }
            if (updateto != ''){
                $(updateto).html(data);
            }
        }
    });
}

function getAjaxdiv(postto, updateto, busydiv) {
    if (busydiv != ''){
        $(busydiv).show();
    }
    $.ajax({
        type: 'GET',
        url: postto,
        dataType: 'html',
        success: function(data){
            if (busydiv != ''){
                $(busydiv).hide();
            }
            $(updateto).html(data);
            $(updateto).show();
        }
    });
}

function getAjax(postto, busydiv) {
    if (busydiv != ''){
        $(busydiv).show();
    }
    $.ajax({
        type: 'GET',
        url: postto,
        dataType: 'html',
        success: function(data){
            if (busydiv != ''){
                $(busydiv).hide();
            }
        }
    });
}

function HideTweet(tan,un,tn,i) {
    var postto = '/users/hidetweet/?u='+un+'&t='+tn;
    $.ajax({
        type: 'GET',
        url: postto,
        dataType: 'html',
        success: function(data){
            document.getElementById(tan).deleteRow(i);
        }
    });

}

function manageMenu(action,item) {
    if (action == 'h'){
        getAjax('/users/setmenu?action=hide&section='+item, '#updimg')
        $('#mbhide'+item).show('fast');
        $('#mbshow'+item).hide('fast');
    } else {
        getAjax('/users/setmenu?action=show&section='+item, '#updimg')
        $('#mbshow'+item).show('fast');
        $('#mbhide'+item).hide('fast');
    }
}

function hideAnnouncement() {
    getAjax('/users/hideannouncement', '')
    $('#sysannounce').hide('fast');
}

