var debugMode = "activity"

//activity    or      datasource      or      visibility
    //"if debugMode variable not undefined then you can see log in your browser console ";

function CreateGroupLogger(groupName) {
    console.group(groupName);
}

function GroupEndLogger(groupName) {
    console.groupEnd(groupName);
}

function TraceLogger(trace) {
    console.log(trace);
}

function ElementActivityLogger(raiser, destinationElement, toState)
{
    return;
    if (typeof debugMode == 'undefined' || debugMode.toLowerCase() != 'activity')
        return;

    var raiserID = GetElementID(raiser);
    var destinationElementID = GetElementID(destinationElement)

    CreateGroupLogger("Change Activity Requirements from " + raiserID + " on " + destinationElementID);
    var logTable = [];
    logTable.push(new NewRowActivityLogger(raiser, destinationElement, toState, raiserID, destinationElementID));
    console.table(logTable);

    function NewRowActivityLogger(raiser, destinationElements, toState, raiserID, destinationElementID) {
        this.raiserElement = raiser;
        this.destinationElements = destinationElements;
        this.toState = toState;
        this.raiserID = raiserID;
        this.destinationElementID = destinationElementID;
    } 
}


function ShowElementLogger(raiser, destinationElement, toState) {
    if (typeof debugMode == 'undefined' || debugMode.toLowerCase() != 'visibility')
        return;

    var raiserID = GetElementID(raiser);
    var destinationElementID = GetElementID(destinationElement)
    CreateGroupLogger("Change visibility Requirements from " + raiserID + " on " + destinationElementID);

    var logTable = [];
    logTable.push(new NewRowVisibilityLogger(raiser, destinationElement, toState, raiserID, destinationElementID));
    console.table(logTable);
    GroupEndLogger("Change visibility Requirements from " + raiserID + " on " + destinationElementID);

    function NewRowVisibilityLogger(raiser, destinationElements, toState, raiserID, destinationElementID) {
        this.raiserElement = raiser;
        this.destinationElements = destinationElements;
        this.toState = toState;
        this.raiserID = raiserID;
        this.destinationElementID = destinationElementID;
    }
}



function ShowDataSourcesLogger(raiser, eventsName) {
    if (typeof debugMode == 'undefined' || debugMode.toLowerCase() != 'datasource')
        return;

    CreateGroupLogger("Call ExecFormDatasources. Caller: " + raiser);

    var logTable = [];


    $.each(eventsName.split(","), function (index, dsName) {
            logTable.push(new NewRowDataSourceLogger(dsName));
            //$($(controller).attr(dsName).select).parent().find('.k-i-arrow-s').addClass('k-loading');
    });
    console.table(logTable);
    GroupEndLogger("Call ExecFormDatasources. Caller: " + raiser);

    function NewRowDataSourceLogger(dsName) {
        this.dsName = dsName;
    }
}


function GetElementID(input) {
    try {
        if ($(input).is('input.k-textbox,a,textarea.k-textbox,input.tzTimePicker')) {
            return input.id || input[0].id || input.innerText;
        }

        if ($(input).is('button.btn.btn-default.btn-xs')) {
            return input.id || input[0].parentElement.id;
        }
        if ($(input).is('button.tbsButton')) {
            return input.id || input[0].id;
        }

        else if ($(input).is("input[type='checkbox'],input[type='radio']")) {
            return input.id || input[0].id;

        }
        else if ($(input).is("ul.tzCheckListBox")) {
            return input.id || input[0].id;

        }
        else if ($(input).parent().parent().is('.k-datepicker')) {
            return input.id || input[0].id;

        }
        else if ($(input).is('div.tzLookup')) {
            return input.id || input[0].id;

        }
        else if ($(input).hasClass('tzGridView')) {
            return input.id || input[0].id;

        }
        else if ($(input).is('fieldset')) {
            return input.id || input[0].id;
        }
        else if ($(input).is('div')) {

            return input.id || input[0].id;

        }
        else if ($(input).is('select')) {
            return input.id || input[0].id;
        }
        else if ($(input).is('legend')) {
            return input.parentElement.id;


        }
        else if (input.context == document) {
            return input.selector;
        }
    } catch (e) {
        return '---No Id---'
    }



}