﻿var DDXCommon = {
    CheckAll: function(srcName, tarName) {
        if ($('input[name=' + srcName + ']').attr('checked')) {
            $('input[name=' + tarName + ']').attr('checked', 'checked');
        } else {
            $('input[name=' + tarName + ']').removeAttr('checked');
        }
    },
    GetCheckItemCount: function(tarName) {
        var items = 0;
        $('input[name=' + tarName + ']').each(function() {
            if ($(this).attr('checked')) {
                items++;
            }
        });
        return items;
    },
    GetCheckItemValues: function(tarName) {
        var items = new Array();
        $('input[name=' + tarName + ']').each(function() {
            if ($(this).attr('checked')) {
                items[items.length] = $(this).val();
            }
        });
        return items;
    },
    ShowRequestedMsg: function(xml, tarLocation) {
        var state = parseInt($('state', xml).text());
        $('#requestMsg').attr('class', 'complete').empty().append($('result', xml).text());
        if (state == 1) {
            setTimeout(function() {
                if (tarLocation) {
                    window.location = tarLocation;
                }
            }, 800);
        }
        setTimeout(function() {
            $('#requestMsg').attr('class', 'hide');
        }, 2000);
    },
    ShowMsg: function(msg, tarLocation) {
        $('#requestMsg').attr('class', 'complete').empty().append(msg);
        if (tarLocation) {
            setTimeout(function() {
                window.location = tarLocation;
            }, 1000);
        } else {
            setTimeout(function() {
                $('#requestMsg').attr('class', 'hide');
            }, 2000);
        }
    },
    WinResize: function(frameid, minHeight) {
        var h = $(document).height();
        if (minHeight) {
            if (eval(h < minHeight)) {
                h = minHeight;
            }
        }
        var pw = window.parent;
        if (pw) {
            var frame = pw.document.getElementById(frameid);
            if (frame) {
                $(frame).trigger('load');
                frame.height = h + 'px';
            }
        }
    },
    SetFrameHeight: function(obj) {
        var win = obj;
        if (document.getElementById) {
            if (win && !window.opera) {
                var h = 0;
                if (win.contentDocument && win.contentDocument.body.offsetHeight) {
                    h = win.contentDocument.body.offsetHeight;
                } else if (win.Document && win.Document.body.scrollHeight) {
                    h = win.Document.body.scrollHeight;
                }
                win.height = h + 'px';
            }
        }
    }
};
