﻿
function loadRecordsToEdit(idTable, IDBlock) {
    ncService.loadRecordsToEdit(idTable, loadRecordsToEditSuccess, loadRecordsToEditFailure, IDBlock);

}

function loadRecordsToEditSuccess(args, userContext) {
    buttonsMode($("#block" + userContext), 2);
    //$("#block" + userContext).find(".divBody").css({ "width": "600px" });
    $("#block" + userContext).find(".divBody").html(args);
    //$("#block" + userContext).css({ "border": "5px solid black", "float":"left" });
    $("#block" + userContext).find(".divBody").css({ "width": "auto" });
    //document.getElementById("txtColName").focus();
}



function loadRecordsToEditFailure(args, userContext) {
    document.getElementById("block" + userContext).innerHTML = args._message;
    //document.getElementById("txtColName").focus();
}

function functionRecordAdd(idParent, idTable) {
    var str = '';
    $('#' + idParent).find('.recordInputs').each(function() {
        str += $(this).attr('name') + '=' + $(this).val() + '&'
    });
    ncService.addRecord(str, idTable, RecordSuccess);
}
function funRecordSave(idParent, idRecord) {
    var str = '';
    $('#' + idParent).find('.recordInputs').each(function() {
        str += $(this).attr('name') + '=' + $(this).val() + '&'
    });
    ncService.dynTabRecordSave(str, idRecord, RecordSuccess);
}
function funRecordDelete(idRecord) {
    var check = confirm('Are you sure that you want to delete this record, this data will be lost?')
    if (check == true) {
        var check2 = confirm('Sure sure?')
        if (check2 == true) {
            ncService.funRecordDelete(idRecord, RecordSuccess);
        }
    }
}

function RecordSuccess(result) {
    var refreshMsg = "<font color=green>Saved. <a href='javascript:window.location.href=window.location.href;'>Refresh</a> screen to see the result.</font>";
    $("#divTableRecords").html(result + "<br />" + refreshMsg);
}
function createFunctionSuccess(result) {
    $("#block41").find(".divBody").html(result);
    repaintBlock(41);
    $("#block41").show();
}
function createFunction(sFunction) {
    loadContent(17, 40);
    ncService.createFunction(sFunction, createFunctionSuccess);
}