﻿//Author: Đỗ Lâm Thiên
//Date Create: 2007/11/22
//Last Upldate: 2007/11/22
//Note: *** AjaxRequest ***

function XL_NHAP_XUAT() {
    //Hàm cập nhật thông tin
    // - idUpdate: Điều khiển cần cập nhật    
    // - urlRequest: Đường dẫn lấy thông tin từ Server
    // - functionName: Hàm sẽ thi hành sau khi nhận kết quả
    this.UpdateInfo = function(idUpdate, urlRequest, functionName) {
        var target = document.getElementById(idUpdate);
        var Noi_dung_cu = target.innerHTML;
        AjaxRequest.get(
            {
                'url': urlRequest
                , 'onLoading': function(req) { }
                , 'onSuccess': function(req) {
                    var returnValue = req.responseText;

                    if (target != null)
                        if (Noi_dung_cu != returnValue)
                        target.innerHTML = returnValue;

                    if (functionName != null && functionName != '')
                        eval(functionName);
                }
            }
        );
        window.status = '';
    };

    this.UpdateSrc = function(idUpdate, urlRequest, functionName) {
        var target = document.getElementById(idUpdate);
        AjaxRequest.get(
            {
                'url': urlRequest
                , 'onLoading': function(req) { }
                , 'onSuccess': function(req) {
                    var returnValue = req.responseText;

                    if (target != null)
                        target.src = returnValue;

                    if (functionName != null && functionName != '')
                        eval(functionName);
                }
            }
        );
        window.status = '';
    };
    //Hàm cập nhật thông tin
    // - FCK_control: Điều khiển FCK cần cập nhật    
    // - urlRequest: Đường dẫn lấy thông tin từ Server
    // - functionName: Hàm sẽ thi hành sau khi nhận kết quả
    this.UpdateInfoFCK = function(FCK_control, urlRequest, functionName) {
        AjaxRequest.get(
            {
                'url': urlRequest
                , 'onLoading': function(req) { }
                , 'onSuccess': function(req) {
                    FCK_control.FCK.SetHTML(req.responseText);

                    if (functionName != null && functionName != '')
                        eval(functionName);
                }
            }
        );
        window.status = '';
    };

    this.GetInfo = function(urlRequest, functionName) {
        AjaxRequest.get(
            {
                'url': urlRequest
                , 'onLoading': function(req) { }
                , 'onSuccess': function(req) {
                    var returnValue = req.responseText;

                    if (functionName != null && functionName != '') {
                        //Tiền xử lý
                        functionName = preExecFunctions(functionName, returnValue);
                        ExecFunctions(functionName);
                    }
                }
            }
        );
        window.status = '';
    };

    preExecFunctions = function(functionNames, returnValue) {
        functionNames = functionNames.replace("[RET_VALUE]", returnValue);
        return functionNames;
    };

    ExecFunctions = function(functionNames) {
        eval(functionNames);
    };
}
