/*	
 Copyright 2013 Adobe Systems Incorporated.  All rights reserved. 

Purpose- 
This file has the implementation of for Dreamweaver side utility functions which are exposed to TableHud extension.
*/

/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, maxerr: 50 */
/*global GenericLiveEditBridger,TableHudBridger */

TableHudBridger.prototype = new GenericLiveEditBridger();
TableHudBridger.prototype.constructor = TableHudBridger;
TableHudBridger.prototype.baseClass = GenericLiveEditBridger.prototype.constructor;

function TableHudBridger(documentDOM) {
    'use strict';
    this.setDocumentDOM(documentDOM);
}

/*
function:setInlineStyle
Arguments:argObj
Description: 
    Sets the inline CSS style, for the given element, property & value.

*/
TableHudBridger.prototype.setInlineStyle = function (argObj) {
    'use strict';
    if (argObj && argObj.dwID && argObj.prop && argObj.value) {
        var elem = this.getElementByDWId(argObj.dwID);
        if (elem) {
            //set the above mentioned property
            elem[argObj.prop] = argObj.value;
        }
    }
};

TableHudBridger.prototype.selectTable = function (argObj) {
    'use strict';
    if (argObj && argObj.dwID) {
        var elem = this.getElementByDWId(argObj.dwID);
        if (elem && this.m_documentDOM) {
            this.m_documentDOM.setSelectedNode(elem);
        }
    }
};

TableHudBridger.prototype.deleteRowOrColumn = function (argObj) {
    'use strict';
    if (argObj && this.m_documentDOM) {
        this.m_documentDOM.deleteTableRowColumn();
    }
};

TableHudBridger.prototype.getTableInfo = function (argObj) {
    'use strict';
    if (argObj && argObj.callback) {
        if (this.m_documentDOM) {
            var ret = this.m_documentDOM.getTableInfo();
            if (ret) {
                argObj.callback(ret);
            }
        }
    }
};

TableHudBridger.prototype.selectTableCells = function (argObj) {
    'use strict';
    if (argObj && argObj.dwID && argObj.cellArray) {
        var elem = this.getElementByDWId(argObj.dwID);
        if (elem && this.m_documentDOM) {
			this.m_documentDOM.setSelectedNode(elem);
            var cells = [];
            var index = 0;
            for (index = 0; index < argObj.cellArray.length; ++index) {
                cells.push(argObj.cellArray[index]);
            }
            
            this.m_documentDOM.selectTableCells(elem, cells);
        }
    }
};