//
// $Id: CMSActions.js,v 1.1.1.1 2010/02/26 08:30:04 steve Exp $
//
var CMSActions = function() {

    this.deleteSection = function(elem, type) {

        var self = this

        var id = $(elem).attr('id').split('_')
        id = id[1]

        var pageId = $('#currentPageId').val()

        $.ajax({
                  type:     'POST',
                  url:      AJAXURL,
                  data:     'Action=deleteContent&SectionId=' + id +
                                                '&PageId=' + pageId +
                                                '&Type=' + type,
                  dataType: 'json',
                  timeout:  40000,
            error:
                function() {
                    return false;
                },
            success:
                function(data) {
                    if (data.Error) {
                        alert(data.Message)
                    } else {
                        alert('Content Updated')
                    }
                    location.reload()
                }
        })
    }

    this.move = function(elem, direction, type) {

        var id = $(elem).attr('id').split('_')
        id = id[1]

        var pageId = $('#currentPageId').val()

        $.ajax({
                  type:     'POST',
                  url:      AJAXURL,
                  data:     'Action=moveContent&SectionId=' + id +
                                              '&PageId=' + pageId +
                                              '&Direction=' + direction +
                                              '&Type=' + type,
                  dataType: 'json',
                  timeout:  40000,
            error:
                function() {
                    return false;
                },
            success:
                function(data) {
                    if (data.Error) {
                        alert(data.Message)
                    } else {
                        alert('Content Updated')
                    }
                    location.reload()
                }
        })
    }
    
    this.showAddSection = function(elem, where, type) {

        var self = this

        var id = $(elem).attr('id').split('_')
        var editor = 'newSection_' + type + '_' + id[1]
        var title  = 'newSectionTitle_' + type + '_' + id[1]

        $('#' + title).html(where)

        var left   = $(elem).offset().left
        var top    = $(elem).offset().top

        $('#' + editor).css('top', top + 'px')
        $('#' + editor).css('left', left + 'px')
        $('#' + editor).fadeIn()
    }
    
    this.reloadPage = function(elem) {
    
        $('#contentChanged').css('top', $(elem).offset().top + 'px')
        $('#contentChanged').css('left', $(elem).offset().left + 'px')
        $(elem).hide()
        $('#contentChanged').fadeIn()
        location.replace(location.href)
    }
}

