(function($) {
    var userAgent = window.navigator.userAgent.toLowerCase();
    var version = (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1];
    $.browser.i7 = $.browser.msie && version >= 7;
})(jQuery);
Date.prototype.Format = function(format) {
    var o = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "H+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "w": "0123456".indexOf(this.getDay()),
        "S": this.getMilliseconds()
    };
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1,
          RegExp.$1.length == 1 ? o[k] :
            ("00" + o[k]).substr(("" + o[k]).length));
    }
    return format;
};
(function($){
$.fn.bgiframe = function(s) {
	// This is only for IE6
	if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
		s = $.extend({
			top     : 'auto', // auto == .currentStyle.borderTopWidth
			left    : 'auto', // auto == .currentStyle.borderLeftWidth
			width   : 'auto', // auto == offsetWidth
			height  : 'auto', // auto == offsetHeight
			opacity : true,
			src     : 'javascript:false;'
		}, s || {});
		var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
		    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
		               'style="display:block;position:absolute;z-index:-1;'+
			               (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
					       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
					       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
					       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
					       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
					'"/>';
		return this.each(function() {
			if ( $('> iframe.bgiframe', this).length == 0 )
				this.insertBefore( document.createElement(html), this.firstChild );
		});
	}
	return this;
};
})(jQuery);
//====================tree====//
function Tree(id, text, value, hasChild, isTop, EndFlag, ChildNodes) {
    this.id = id;
    this.text = text;
    this.value = value;
    this.showcheck = false;
    this.checkstate = 0;
    this.hasChildren = hasChild,
       this.isTop = isTop,
       this.isexpand = true,
       this.complete = false,
       this.EndFlag = EndFlag,
       this.ChildNodes = ChildNodes
}

/////////entity////////
eOA_rcBaseEntity = function() {
    this.ItemEntityCount = 0;
    this.TableName = "";
    this.Sort = "";
    this.Where = "";
    this.WhereValue = [];
    this.WhereValueXML = "";
    this.DataXML = "";
    this.FieldXML = "";  
    this.ItemEntityFieldXML = "";
    this.Fields = {};
    this.FieldsSet = [];
    this.ColumnsSet = [];
    this.LinkFields = {};
};
eOA_rcBaseEntity.prototype =
{
    SelectOne: function(_entity) {
        return DBReader.SelectOne(_entity);
    },
    SelectList: function(_entity) {
        return DBReader.prototype.SelectList(_entity);
    },
    Insert: function(_entity) {
        return DBReader.Insert(_entity);

    },
    Update: function(_entity) {
        return DBReader.Update(_entity);
    },
    Delete: function(_entity) {
        return DBReader.Delete(_entity);
    },
    appendEntity: function(_entity, _Action) {
        this.ItemEntityFieldXML += DBReader.resolutionItemEntityXML(_entity, this.ItemEntityCount, this.TableName, _Action);
        this.ItemEntityFieldXML += _entity.ItemEntityFieldXML;
        this.ItemEntityCount++;
    }
}
///////////////////////////
function Map() {

    this.elements = new Array();

    this.size = function() {
        return this.elements.length;
    }

    this.isEmpty = function() {
        return (this.elements.length < 1);
    }

    this.clear = function() {
        this.elements = new Array();
    }

    this.put = function(_key, _value) {
        this.remove(_key);
        this.elements.push({ key: _key, value: _value });
    }

    this.remove = function(_key) {
        try {
            for (i = 0; i < this.elements.length; i++) {
                if (this.elements[i].key == _key) {
                    this.elements.splice(i, 1);
                    return true;
                }
            }
        } catch (e) {
            return false;
        }
        return false;
    }

    this.get = function(_key) {
        try {
            for (i = 0; i < this.elements.length; i++) {
                if (this.elements[i].key == _key) { return this.elements[i].value; }
            }
        } catch (e) {
            return null;
        }
    }

    this.element = function(_index) {
        if (_index < 0 || _index >= this.elements.length) { return null; }
        return this.elements[_index];
    }

    this.containsKey = function(_key) {
        try {
            for (i = 0; i < this.elements.length; i++) {
                if (this.elements[i].key == _key) {
                    return true;
                }
            }
        } catch (e) {
            return false;
        }
        return false;
    }

    this.values = function() {
        var arr = new Array();
        for (i = 0; i < this.elements.length; i++) {
            arr.push(this.elements[i].value);
        }
        return arr;
    }

    this.keys = function() {
        var arr = new Array();
        for (i = 0; i < this.elements.length; i++) {
            arr.push(this.elements[i].key);
        }
        return arr;
    }
}
var UserTime = "";
//////////////////// jsonhelper//////////////////////////////////////////
(function($) {
    jQuery.fn.extend({
        jContains: function(value, key) {
            var retureResult = false;
            $(this).each(function(index, ele) { if (ele[key] == value) { retureResult = true; return; } });
            return retureResult;
        },
        hoverClass: function(className) {
            var _className = className || "hover";
            return this.each(function() {
                $(this).hover(function() {
                    $(this).addClass(_className);
                }, function() {
                    $(this).removeClass(_className);
                });
            });
        },
        jDelete: function() {
            var retureResult = [];
            $(this).each(function(index, ele) { if (!ele.hasChild) { retureResult.push(ele); } });
            return retureResult;
        },
        jGetArrayByValue: function(value, key) {
            var retureResult = [];
            $(this).each(function(index, ele) { if (ele[key] == value) { retureResult.push(ele); } });
            return retureResult;
        },
        jUniquelize: function(key) {
            var njson = [];
            $(this).each(function(index, ele) {
                if (!$(njson).jContains(ele[key], key)) { njson.push(ele); }
            });
            return njson;
        },
        jGetArray: function(key) {
            var retureResult = [];
            $(this).each(function(index, ele) { retureResult.push(ele[key]) });
            return retureResult;
        },
        jPrint: function(key) {
            var returnString = "";
            $(this).each(function(index, ele) { returnString += ele[key]; returnString += "\n" });
            alert(returnString);
        }



    });
    jQuery.extend({

        jIntersect: function(ojson, njson, key) {
            var returnArray = [];
            var uniqueArray = $(ojson).jUniquelize(key);
            $(uniqueArray).each(function(index, ele) {
                if ($(njson).jContains(ele[key], key)) { returnArray.push(ele); }
            })
            return returnArray;

        },
        jLtrim: function(str) {
            var pattern = new RegExp("^[\\s]+", "gi");
            return str.replace(pattern, "");
        },
        jRtrim: function(str) {
            var pattern = new RegExp("[\\s]+$", "gi");
            return str.replace(pattern, "");

        },
        jTrimAll: function(str) {
              var defaultChar = ["<P>","</P>"];
                for(var index=0;index<defaultChar.length;index++) {
                str = str.split(defaultChar[index]).join("");
            }
            var dustChar = [" ", "&nbsp;", "<", ">","\r\n"];
            str = str.replace(/<.*?>/g, "");
            for(var index=0;index<dustChar.length;index++) {
                str = str.split(dustChar[index]).join("");
            }
            return this.jRtrim(this.jLtrim(str));

        },
        jMinus: function(ojson, njson, key, unique) {
            var returnArray = [];
            var uniqueArray;
            if (unique) {
                uniqueArray == $(ojson).jUniquelize(key);
            }
            else {
                uniqueArray = $(ojson);
            }

            $(uniqueArray).each(function(index, ele) {
                if (!$(njson).jContains(ele[key], key)) { returnArray.push(ele); }
            })
            return returnArray;
        },
        jMinusExtend: function(ojson, unique) {

            var returnArray = [];
            var uniqueArray;
            if (unique) {
                uniqueArray == $(ojson).jUniquelize(key);
            }
            else {
                uniqueArray = $(ojson);
            }

            $(uniqueArray).each(function(index, ele) {
                if (ele.isTop) { returnArray.push(ele); }
            })
            return returnArray;

        },
        jMinusChild: function(ojson, key) {
            var returnArray = [];
            $(ojson).each(function(index, ele) {
                if (!$(ojson).jContains(ele.parent, key)) { returnArray.push(ele); }
            })
            return returnArray;

        },
        jUnion: function(ojson, njson, key) {
            var returnArray = ojson.concat(njson);
            return returnArray.jUniquelize(key);

        },
        jUnionExt: function(ojson, njson) {
            var returnArray = ojson.concat(njson);
            return returnArray;

        },
        jGetJsonTree: function(list, oldArray) {
            var result = [];
            $(list).each(function(index, elem) {
                var tree = new Tree();
                tree.id = elem.id;
                tree.value = elem.id;
                tree.text = elem.name;
                tree.EndFlag = elem.endflag;
                tree.isTop = true;
                tree.hasChildren = $(oldArray).jContains(tree.id, "parent");
                tree.ChildNodes = null;
                if (tree.hasChildren) {
                    var childArray = $(oldArray).jGetArrayByValue(tree.id, "parent");
                    tree.ChildNodes = $.jGetJsonTree(childArray, oldArray);
                }
                result.push(tree);
                tree = null;
            });
            return result;
        },
        jGetTree: function(table) {
            var result = [];
            var tab = [];
            UserTime += "查询数据使用时间：\r\n开始时间：" + (new Date()).toLocaleDateString() + " " + (new Date()).toLocaleTimeString() + " " + (new Date().getMilliseconds());
            result = $.jGetJsonTree($.jMinusChild(table, "id"), table);
            //$.jMinusChild(table, "id");
            UserTime += "\r\n" + "结束时间：" + (new Date()).toLocaleDateString() + " " + (new Date()).toLocaleTimeString() + " " + (new Date().getMilliseconds());
            return result;
        },
        dispose: function(obj) {
            obj = null;

        }



    });
})(jQuery);

/*----------------------------------------------------*/
(function($) {
    $.ui = $.ui || {};
    var top = window, cover, doc, dragDiv, ZIndex, dcount = 0;
    while (top.parent != top)
        top = top.parent;
    doc = top.document;
    function getsrc() {
        if ($.browser.msie) {
            return ($.browser.i7 ? '' : "javascript:''");
        }
        else
            return 'javascript:void(0);';
    };
    function getZIndex() {
        if (!ZIndex) ZIndex = 999;
        
        return ++ZIndex;
    };
    function reSizeHdl() {
        //var rel = J.root(doc);
        var rel = $.boxModel ? doc.documentElement : doc.body;
        $(cover).css({
            width: Math.max(rel.scrollWidth, rel.clientWidth || 0) - 1 + 'px',
            height: Math.max(rel.scrollHeight, rel.clientHeight || 0) - 1 + 'px'
        });
    };
    $.fn.fixie6png = function() {
        var els = $('*', this), iebg, bgIMG;

        for (var i = 0, l = els.length; i < l; i++) {
            bgIMG = $(els[i]).css('backgroundImage');
            if (bgIMG.indexOf('.png') !== -1) {
                iebg = bgIMG.replace(/url\(|"|\)/g, '');
                els[i].style.backgroundImage = 'none';
                els[i].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
            }
        }
    };

    $.ui.getScrollSize = function($) {
        $ = $ || window;
        if ('pageXOffset' in $) {
            return {
                x: $.pageXOffset || 0,
                y: $.pageYOffset || 0
            };
        }
        else {
            // var doc = J.root($.document);
            var doc = $.boxModel ? $.document.documentElement : $.document.body;
            return {
                x: doc.scrollLeft || 0,
                y: doc.scrollTop || 0
            };
        }
    };

    $.ui.getClientSize = function($) {
        $ = $ || window;
        //var doc = J.root($.document);
        var doc = $.boxModel ? $.document.documentElement : $.document.body;

        return {
            w: doc.clientWidth || 0,
            h: doc.clientHeight || 0
        }
    };

    function cleanDiv() {
        $(dragDiv).remove();
        dragDiv = null;

        if (cover) {
            $(cover).remove();
            cover = null;
        }
    };

    $.fn.dialog = function(opts) {
        var dialog = false;

        if (this[0])
            dialog = new $.ui.dialog(opts, this[0]);

        return dialog;
    };

    $.ui.dialog = function(opts, elem) {
        var self = this, r = this.opt =
	$.extend({
	    height: 300,
	    width: 400,
	    id: 'lhgdlgId',
	    event: 'click',
	    isclick:true,
	    link: false,
	    btns: true,
	    fixed: false,
	    drag: true,
	    resize: false,
	    top: 'center',
	    left: 'center',
	    title: 'lhgdialog',
	    regDragWindow: []
	}, opts || {});

        if (r.SetTopWindow) {
            top = r.SetTopWindow;
            doc = top.document;
        }

        if (dcount === 0) {
            if ($.browser.msie && !$.browser.i7) {
                try {
                    doc.execCommand('BackgroundImageCache', false, true);
                } catch (e) { }
            }
            dcount += 1;
        }

        iframe = $.browser.msie && !$.browser.i7 ? '<iframe hideFocus="true" ' +
	    'frameborder="0" src="' + getsrc() + '" style="position:absolute;' +
		'z-index:-1;width:100%;height:100%;top:0px;left:0px;filter:' +
		'progid:DXImageTransform.Microsoft.Alpha(opacity=0)"><\/iframe>' : '';
        //注意
        if (!dragDiv) {
            //dragDiv = $('<div id="lhgdig_cDiv" style="position:absolute;top:0px;left:0px;border:1px solid #000;background-color:#999;display:none;"></div>', doc)
            dragDiv = $("<div/>").addClass("lhgdig_cDiv_class").attr("id", "lhgdig_cDiv").hide()
			.appendTo('body').bind('contextmenu', function(ev) { ev.preventDefault(); })[0];
        }

        this.SetIFramePage = function() {
            var innerDoc, text;
            if (r.html) {
                if (typeof r.html === 'string')
                    innerDoc = '<div id="lhgdig_inbox" class="lhgdig_inbox" style="display:none">' + r.html + '</div>';
                else
                    innerDoc = '<div id="lhgdig_inbox" class="lhgdig_inbox" style="display:none"></div>';
            }
            else if (r.page) {
                innerDoc = ['<iframe frameborder="0" src="', r.page, '" scrolling="auto" ',
				'id="lhgfrm" style="display:none;width:100%;height:100%;"><\/iframe>'].join('');
            }
            
            text = [
			'<div id="', r.id, '" class="lhgdig" style="width:', r.width, 'px;height:', r.height, 'px;">',
				'<table border="0" cellspacing="0" cellpadding="0">',
				'<tr>',
					'<td class="lhgdig_leftTop"></td>',
					'<td id="lhgdig_drag" class="lhgdig_top">',
						'<div class="lhgdig_title"><span id="lhgdig_icon" class="lhgdig_icon"></span>', r.title, '</div>',
						'<div id="lhgdig_xbtn" class="lhgdig_xbtn"></div>',
					'</td>',
					'<td class="lhgdig_rightTop"></td>',
				'</tr>',
				'<tr>',
					'<td class="lhgdig_left" id="lhgdigLeft"></td>',
					'<td>',
						'<table border="0" cellspacing="0" cellpadding="0">',
						'<tr>',
							'<td id="lhgdig_content" class="lhgdig_content">',
								innerDoc, '<div id="throbber" class="lhgdig_throbber"><span id="lhgdig_load">loading...</span></div>',
							'</td>',
						'</tr>',
						r.btns ? '<tr><td id="lhgdig_btns" class="lhgdig_btns"><div id="lhgdig_bDiv" class="lhgdig_bDiv"></div></td></tr>' : '',
						'</table>',
					'</td>',
					'<td class="lhgdig_right"></td>',
				'</tr>',
				'<tr>',
					'<td class="lhgdig_leftBottom"></td>',
					'<td class="lhgdig_bottom"></td>',
					'<td id="lhgdig_drop" class="lhgdig_rightBottom"></td>',
				'</tr>',
				'</table>', iframe,
			'</div>'
		].join('');
            return text;
        };

        this.ShowDialog = function() {
            if ($('#' + r.id, doc[0])[0])
                return;

            if (r.cover)
                this.ShowCover();

            var fixpos = r.fixed && (!$.browser.msie || $.browser.i7) ? 'fixed' : 'absolute',

		html = this.SetIFramePage();

            this.dlg = $(html, doc).css({
                position: fixpos, zIndex: getZIndex()
            }).appendTo(doc.body)[0];
            this.iPos(this.dlg, r.top, r.left, r.fixed);

            this.setDialog(this.dlg);

            if (r.drag)
                this.initDrag($('#lhgdig_drag', this.dlg)[0]);

            if (r.resize)
                this.initSize($('#lhgdig_drop', this.dlg)[0]);

            if ($.browser.msie && !$.browser.i7) {
                var ie6PngRepair = $('html', doc).css('ie6PngRepair') === 'true' ? true : false;
                if (ie6PngRepair) $(this.dlg).fixie6png();
            }

            this.lhgDigxW = $('#lhgdigLeft', this.dlg)[0].offsetWidth * 2;

            this.reContentSize(this.dlg);

            if (r.html && r.cusfn) r.cusfn();

            if (r.html) {
                $('#throbber', this.dlg).css('display', 'none');
                $('#lhgdig_inbox', this.dlg)[0].style.display = 'inline-block';
            }
        };

        this.iPos = function(dig, tp, lt, fix) {
            var cS = $.ui.getClientSize(top),
		    sS = $.ui.getScrollSize(top),
			dW = dig.offsetWidth,
			dH = dig.offsetHeight, x, y;

            if (fix) {
                if ($.browser.msie && !$.browser.i7) {
                    $('html', doc).addClass('lhgdig_ie6_fixed');
                    $('<div class="lhgdig_warp"></div>', doc).appendTo(doc.body).append(dig).css('zIndex', getZIndex());
                }

                lx = 0;
                rx = cS.w - dW;
                cx = (rx - 20) / 2;

                ty = 0;
                by = cS.h - dH;
                cy = (by - 20) / 2;
            }
            else {
                lx = sS.x;
                cx = sS.x + (cS.w - dW - 20) / 2;
                rx = sS.x + cS.w - dW;

                ty = sS.y;
                cy = sS.y + (cS.h - dH - 20) / 2;
                by = sS.y + cS.h - dH;
            }

            switch (lt) {
                case 'center':
                    x = cx;
                    break;
                case 'left':
                    x = lx;
                    break;
                case 'right':
                    x = rx;
                    break;
                default:
                    if (fix) lt = lt - sS.x;
                    x = lt; break;
            }

            switch (tp) {
                case 'center':
                    y = cy;
                    break;
                case 'top':
                    y = ty;
                    break;
                case 'bottom':
                    y = by;
                    break;
                default:
                    if (fix) tp = tp - sS.y;
                    y = tp; break;
            }

            $(dig).css({ top: y + 'px', left: x + 'px' });
        };

        this.setDialog = function(dlg) {
            this.win = window;
            this.top = top;
            $(dlg).bind('contextmenu', function(ev) {
                ev.preventDefault();
            }).bind('mousedown', self.setIndex);

            $('#lhgdig_xbtn', dlg).hover(function() {
                $(this).addClass('lhgdig_xbtnover');
            }, function() {
                $(this).removeClass('lhgdig_xbtnover');
            }).click(self.cancel);

            if (r.html && r.html.nodeType)
                $('#lhgdig_inbox', dlg).append(r.html);

            this.regWindow = [window];

            if (r.regDragWindow.length > 0)
                this.regWindow.push(r.regDragWindow);

            if (top != window)
                this.regWindow.push(top);

            if (r.page) {
                this.infrm = $('#lhgfrm', dlg)[0];

                if (!r.link) {
                    this.inwin = this.infrm.contentWindow;
                    this.infrm.dg = this;
                }

                $(this.infrm).bind('load', function() {
                    if (!self.opt.link) {
                        var indw = $.browser.msie ?
					    this.contentWindow.document : this.contentWindow;
                        $(indw).bind('mousedown', self.setIndex);
                        self.regWindow.push(this.contentWindow);
                    }

                    $('#throbber', self.dlg)[0].style.display = 'none';
                    this.style.display = 'block';
                });
            }
        };

        this.reContentSize = function(dig) {
            var tH = $('#lhgdig_drag', dig)[0].offsetHeight,
		    bH = $('#lhgdig_drop', dig)[0].offsetHeight,
			xW = this.lhgDigxW,
			nH = r.btns ? $('#lhgdig_btns', dig)[0].offsetHeight : 0,
			iW = parseInt(dig.style.width, 10) - xW,
			iH = parseInt(dig.style.height, 10) - tH - bH - nH;

            $('#lhgdig_content', dig).css({
                width: iW + 'px', height: iH + 'px'
            });

            if (r.html) {
                $('#lhgdig_inbox', dig).css({
                    width: iW + 'px', height: iH + 'px'
                });
            }

            this.SetLoadLeft();
        };

        this.reDialogSize = function(width, height) {
            $(this.dlg).css({
                'width': width + 'px', 'height': height + 'px'
            });

            this.reContentSize(this.dlg);
        };

        this.initDrag = function(elem) {
            var lacoor, maxX, maxY, curpos, regw = this.regWindow, cS, sS;

            function moveHandler(ev) {
                var curcoor = { x: ev.screenX, y: ev.screenY };
                curpos =
		    {
		        x: curpos.x + (curcoor.x - lacoor.x),
		        y: curpos.y + (curcoor.y - lacoor.y)
		    };
                lacoor = curcoor;

                if (r.rang) {
                    if (curpos.x < sS.x) curpos.x = sS.x;
                    if (curpos.y < sS.y) curpos.y = sS.y;
                    if (curpos.x > maxX) curpos.x = maxX;
                    if (curpos.y > maxY) curpos.y = maxY;
                }

                $(dragDiv).css({ left: curpos.x + 'px', top: curpos.y + 'px' });
            };

            function upHandler(ev) {
                for (var i = 0, l = regw.length; i < l; i++) {
                    $(regw[i].document).unbind('mousemove', moveHandler);
                    $(regw[i].document).unbind('mouseup', upHandler);
                }

                if ($.browser.msie)
                    dragDiv.releaseCapture();

                dragDiv.style.display = 'none'; lacoor = null; elem = null;

                if (self.opt.fixed)
                    $(self.dlg).css({ left: curpos.x - sS.x + 'px', top: curpos.y - sS.y + 'px' });
                else
                    $(self.dlg).css({ left: curpos.x + 'px', top: curpos.y + 'px' });
            };

            $(elem).bind('mousedown', function(ev) {
                if (ev.target.id === 'lhgdig_xbtn') return;

                cS = $.ui.getClientSize(top);
                sS = $.ui.getScrollSize(top);

                var lt = self.dlg.offsetLeft,
			    tp = self.dlg.offsetTop,
			    dW = self.dlg.clientWidth,
			    dH = self.dlg.clientHeight;

                curpos = self.opt.fixed ?
			    { x: lt + sS.x, y: tp + sS.y} : { x: lt, y: tp };

                lacoor = { x: ev.screenX, y: ev.screenY };

                maxX = self.opt.fixed ? cS.w - dW : cS.w + sS.x - dW;
                maxY = self.opt.fixed ? cS.h - dH : cS.h + sS.y - dH;

                $(dragDiv).css({
                    width: dW - 2 + 'px', height: dH - 2 + 'px', left: curpos.x + 'px',
                    top: curpos.y + 'px', zIndex: parseInt(ZIndex, 10) + 2, display: ''
                });

                for (var i = 0, l = regw.length; i < l; i++) {
                    $(regw[i].document).bind('mousemove', moveHandler);
                    $(regw[i].document).bind('mouseup', upHandler);
                }

                ev.preventDefault();

                if ($.browser.msie) dragDiv.setCapture();
            });
        };

        this.initSize = function(elem) {
            var lacoor, dH, dW, curpos, regw = this.regWindow, dialog, cS, sS;

            function moveHandler(ev) {
                var curcoor = { x: ev.screenX, y: ev.screenY };
                dialog = {
                    w: curcoor.x - lacoor.x,
                    h: curcoor.y - lacoor.y
                };

                if (dialog.w < 200) dialog.w = 200;
                if (dialog.h < 100) dialog.h = 100;

                $(dragDiv).css({
                    width: dialog.w + 'px', height: dialog.h + 'px',
                    top: curpos.y + 'px', left: curpos.x + 'px'
                });
            };

            function upHandler(ev) {
                for (var i = 0, l = regw.length; i < l; i++) {
                    $(regw[i].document).unbind('mousemove', moveHandler);
                    $(regw[i].document).unbind('mouseup', upHandler);
                }

                if ($.browser.msie)
                    dragDiv.releaseCapture();

                self.reDialogSize(dialog.w, dialog.h);
                dragDiv.style.display = 'none'; lacoor = null; elem = null;
            };

            $(elem).bind('mousedown', function(ev) {
                dW = self.dlg.clientWidth;
                dH = self.dlg.clientHeight;

                dialog = { w: dW, h: dH };

                cS = $.ui.getClientSize(top);
                sS = $.ui.getScrollSize(top);

                var lt = self.dlg.offsetLeft,
			    tp = self.dlg.offsetTop;

                curpos = self.opt.fixed ?
			    { x: lt + sS.x, y: tp + sS.y} : { x: lt, y: tp };

                lacoor = { x: ev.screenX - dW, y: ev.screenY - dH };

                $(dragDiv).css({
                    width: dW - 2 + 'px', height: dH - 2 + 'px', left: curpos.x + 'px',
                    top: curpos.y + 'px', zIndex: parseInt(ZIndex, 10) + 2, display: ''
                });

                for (var i = 0, l = regw.length; i < l; i++) {
                    $(regw[i].document).bind('mousemove', moveHandler);
                    $(regw[i].document).bind('mouseup', upHandler);
                }

                ev.preventDefault();

                if ($.browser.msie) dragDiv.setCapture();
            });
        };

        this.setIndex = function(ev) {
            if (self.opt.fixed && $.browser.msie && !$.browser.i7) {
                $(self.dlg).parent()[0].style.zIndex = parseInt(ZIndex, 10) + 1;
                ZIndex = parseInt($(self.dlg).parent()[0].style.zIndex, 10);
            }
            else {
                self.dlg.style.zIndex = parseInt(ZIndex, 10) + 1;
                ZIndex = parseInt(self.dlg.style.zIndex, 10);
            }

            ev.stopPropagation();
        };

        this.SetLoadLeft = function() {
            var loadL = ($('#lhgdig_content', this.dlg)[0].offsetWidth -
		    $('#lhgdig_load', this.dlg)[0].offsetWidth) / 2;

            $('#lhgdig_load', this.dlg)[0].style.left = loadL + 'px';
        };

        this.addBtn = function(id, txt, fn) {
            if ($('#' + id, this.dlg)[0])
                $('#' + id, this.dlg).html('<em>' + txt + '</em>').click(fn);
            else {
                var html = '<a id="' + id + '" class="lhgdig_button" href="javascript:void(0)" hidefocus="true"><em>' + txt + '</em></a>',

		    btn = $(html, doc).click(fn)[0];
                $('#lhgdig_bDiv', this.dlg).append(btn);
            }
        };

        this.removeBtn = function(id) {
            if ($('#' + id, this.dlg)[0])
                $('#' + id, this.dlg).remove();
        };

        this.reload = function(win, url) {
            win = win || window;
            self.cancel();

            win.location.href = url ? url : win.location.href;
        };

        this.ShowCover = function() {
            if (!cover) {
                var html = ['<div style="position:absolute;top:0px;left:0px;',
					'background-color:#fff;">', iframe, '</div>'].join('');

                cover = $(html, doc).css('opacity', 0.5).appendTo(doc.body)[0];
            }
              
            //$(top).bind('resize', reSizeHdl);
            reSizeHdl();
            $(cover).css({ display: '', zIndex: getZIndex() });
        };

        this.cancel = function() {
            var frm = $('#lhgfrm', self.dlg)[0];
            if (frm) {
                if (!self.opt.link)
                    $(frm.contentWindow).unbind('load');
                frm.src = getsrc(); frm = null;
            }

            self.regWindow = [];
            if (self.opt.fixed && $.browser.msie && !$.browser.i7) {
                $('html', doc).removeClass('lhgdig_ie6_fixed');
                $(self.dlg).parent().remove();
            }
            else
            {
                $(self.dlg).hide();
                self.dlg=null;
                CollectGarbage();
            }  //引起input状态为只读,原为$(self.dlg).remove();可改为$(self.dlg).hide();,但每个弹出框必须设置唯一ID
            if (cover) {
                if (self.opt.parent && self.opt.parent.opt.cover) {
                    var Index = self.opt.parent.dlg.style.zIndex;
                    cover.style.zIndex = parseInt(Index, 10) - 1;
                }
                else
                    cover.style.display = 'none';
            }
        };

        this.cleanDialog = function() {
            if (self.dlg) {
                var frm = $('#lhgfrm', self.dlg)[0];
                if (frm) {
                    if (!self.opt.link)
                        $(frm.contentWindow).unbind('load');
                    frm.src = getsrc(); frm = null;
                }

                if (self.opt.fixed && $.browser.msie && !$.browser.i7) {
                    $('html', doc).removeClass('lhgdig_ie6_fixed');
                    $(self.dlg).parent().remove();
                }
                else
                    $(self.dlg).remove(); self.dlg = null;
            }
        };
        $(window).bind('unload', this.cleanDialog);
        if (elem)
        {    if(r.isclick)
             {
                $(elem).bind(r.event, function() { self.ShowDialog(); });
             }
             else
             {
                self.ShowDialog();
             }
       }
    };

    $(window).bind('unload', cleanDiv);

})(jQuery);

/////////////扩展//////////////////////////////////////////

(function($) {
    var _alert = window.alert,
	_name = 'darren-dialog_';
    // 警告
    // @param {String} 消息内容
    // @return {Object} 对话框操控接口
    var _alertOption = { id: _name + "Alert", title: '操作提示',
        width: 250,
        height: 150,
        cover: true,
        resize: false,
        btns: true,
        html: "",
        cusfn: null
    }
    function GetAlertHtml(type, content) {
        var template = "<table class=\"aui_content_table\">" +
				"<tr><td><div class=\"aui_icon art_" + type + "\"></div></td>" +
				     "<td class=\"aui_td_content\" ><div class=\"aui_content_wrap\"><div class=\"aui_content\">" + content + "</div></div></td>" +
				"</tr></table>";
        return template;
    }
    $.fn.alert = function(type, content) {
        if (typeof content !== 'string') {
            _alert(content);
            return;
        }
        else {
            _alertOption.id="_fnAlert"+new Date().getMilliseconds()+parseInt(10*Math.random());
            _alertOption.cusfn = function() { myDlgAlert.addBtn('dlgBtnSure', '确定', function() { myDlgAlert.cancel();  }); }
            _alertOption.html = GetAlertHtml(type, content);
            var myDlgAlert = new $.ui.dialog(_alertOption);
            myDlgAlert.ShowDialog();
           
        }
    };
    $.fn.confirm = function(content, callback) {
        _alertOption.id="_confirm"+new Date().getMilliseconds()+parseInt(10*Math.random());
        _alertOption.title = "确认操作";
        _alertOption.html = GetAlertHtml("confirm", content);
        _alertOption.cusfn = function() {
            myDlgConfirm.addBtn('dlgConfirmBtnSure', '确定', function() { myDlgConfirm.cancel(); callback.call(this); });
            myDlgConfirm.addBtn('dlgConfirmBtnCancel', '取消', function() { myDlgConfirm.cancel(); });
        };
        myDlgConfirm = new $.ui.dialog(_alertOption);
        myDlgConfirm.ShowDialog();
    };
    $.alert = function(content) {
        return $.fn.alert("alert", content);
    };

})(jQuery);
//===================== 颜色选择器====================
(function($) {
_name = 'darren-myColor-dialog_';
    $.fn.myColor = function(o) {
        var options = $.extend({
            page: '../common/color.html',
            selectedchange: false
        }, o);
        var myColorSelector = new $.ui.dialog({ id: _name + "colorselector", title: '颜色选择',
            width: 225,
            height: 290,
            cover: true,
            resize: false,
            btns: true,
            page: options.page
        });
         myColorSelector.ShowDialog();

    };

})(jQuery);
// ==============辅助信息选择===============
(function($) {
    $.ui = $.ui || {};
    $.fn.addtionInfo = function(opts) {
        var addtionInfo = false;
        if (this[0])
            addtionInfo = new $.ui.addtionInfo(opts, this[0]);
        return addtionInfo;
    }
    $.ui.addtionInfo = function(o, ele) {
        var options = $.extend({
            selectedchange: false,
            picker: '<img class="dropIcon" align="middle" src="s.gif" />',
            title: '辅助信息选择',
            width: 300,//((dialogLayout.schedule.selectAddtionItem.width)+(dialogLayout.schedule.selectAddtionType.width)),
            height: 200,//(dialogLayout.schedule.selectAddtionType.height+20),
            url: '../schedules/dataTree.htm',
            clickEvent: false,
            customFunction: false,
            setValue: false
        }, o);
        var target = this;
        var me = $(ele);
        var wrapper = $(ele).wrap("<div/>").parent().addClass("myui-form-div-dropdown");
        var picker = $("<div />").appendTo(wrapper).addClass("addtiondropicon").css("left", me.width());
        var left = $(ele).offset().left;
        var top = $(ele).offset().top;
        var uniquename = 'darren-addtionInfo-dialog_';
        $(picker).click(function() {
            if (options.customFunction && $.isFunction(options.customFunction)) {
                options.customFunction.call(this, wrapper);
            }
            else {
                var myAddtionInfoSelector = new $.ui.dialog({ id: uniquename + "addtionselector", title: options.title,
                    width: options.width,
                    height: options.height,
                    cover: true,
                    resize: false,
                    btns: true,
                    page: options.url
                });
                myAddtionInfoSelector.ShowDialog();
                myAddtionInfoSelector.addBtn('myColorSelectorBtnSure', '确定', function() {
                    var item = myAddtionInfoSelector.inwin.setValue();
                    if(item!=undefined)
                    {
                        if (options.setValue) {
                            $(ele).val(item.attr("Name")).attr("vid", item.attr("ID"));
                        }
                        else {
                            $(ele).val(item[1]).attr("vid", item[0]).attr("flag", item[2]);
                        }
                    }
                    myAddtionInfoSelector.cancel();
                });
            }
            if (options.clickEvent && $.isFunction(options.clickEvent)) {
                options.clickEvent.call(this, me);
            }
        });

    };




})(jQuery);
//////////////////////////////loadmask////////////
//-------------end
(function($) {

    /**
    * Displays loading mask over selected element(s). Accepts both single and multiple selectors.
    *
    * @param label Text message that will be displayed on top of the mask besides a spinner (optional). 
    * 				If not provided only mask will be displayed without a label or a spinner.  	
    * @param delay Delay in milliseconds before element is masked (optional). If unmask() is called 
    *              before the delay times out, no mask is displayed. This can be used to prevent unnecessary 
    *              mask display for quick processes.   	
    */
    $.fn.mask = function(label, delay, isScroll) {
        $(this).each(function() {
            if (delay !== undefined && delay > 0) {
                var element = $(this);
                element.data("_mask_timeout", setTimeout(function() { $.maskElement(element, label, isScroll) }, delay));
            } else {
                $.maskElement($(this), label, isScroll);
            }
        });
    };

    /**
    * Removes mask from the element(s). Accepts both single and multiple selectors.
    */
    $.fn.unmask = function() {

      if($(this).attr("tagName").toUpperCase()=="BODY")
      {  
         var element=$(document);
         if (element.find("body").data("_mask_timeout") !== undefined) {
            clearTimeout(element.find("body").data("_mask_timeout"));
            element.find("body").removeData("_mask_timeout");
        }
        element.find(".loadmask-msg,.loadmask").remove();
        element.removeClass("masked");
        element.removeClass("masked-relative");
      }
      else
      {
         $(this).each(function(index,ele) {
            $.unmaskElement($(ele));
         });
      
      }
       
    };

    /**
    * Checks if a single element is masked. Returns false if mask is delayed or not displayed. 
    */
    $.fn.isMasked = function() {
        return this.hasClass("masked");
    };

    $.maskElement = function(element, label, isScroll) {
        //if this element has delayed mask scheduled then remove it and display the new one
        if (element.data("_mask_timeout") !== undefined) {
            clearTimeout(element.data("_mask_timeout"));
            element.removeData("_mask_timeout");
        }

        if (element.isMasked()) {
            $.unmaskElement(element);
        }

        if (element.css("position") == "static") {
            element.addClass("masked-relative");
        }

        element.addClass("masked");

        var maskDiv = $('<div class="loadmask"></div>');

        //auto height fix for IE
        if (navigator.userAgent.toLowerCase().indexOf("msie") > -1) {
            
            maskDiv.height(element.height() + parseInt(element.css("padding-top")) + parseInt(element.css("padding-bottom")));
            maskDiv.width(element.width() + parseInt(element.css("padding-left")) + parseInt(element.css("padding-right")));
        }

        //fix for z-index bug with selects in IE6
        if (navigator.userAgent.toLowerCase().indexOf("msie 6") > -1) {
            //alert("ie6")
            //element.find("select").css("disabled","disabled");
           $(maskDiv).bgiframe();
        }

        element.append(maskDiv);

        if (label !== undefined) {
            var maskMsgDiv = $('<div class="loadmask-msg" style="display:none;"></div>');
            maskMsgDiv.append('<div>' + label + '</div>');
            element.append(maskMsgDiv);

            //calculate center position
            maskMsgDiv.css("top", Math.round(element.height() / 2 - (maskMsgDiv.height() - parseInt(maskMsgDiv.css("padding-top")) - parseInt(maskMsgDiv.css("padding-bottom"))) / 2) + "px");
            maskMsgDiv.css("left", Math.round(element.width() / 2 - (maskMsgDiv.width() - parseInt(maskMsgDiv.css("padding-left")) - parseInt(maskMsgDiv.css("padding-right"))) / 2) + "px");
            if (isScroll) {

                if ($(document.documentElement).height() < $(element).height()) {
                    maskMsgDiv.css("top", Math.round($(document.documentElement).height() / 2 - (maskMsgDiv.height() - parseInt(maskMsgDiv.css("padding-top")) - parseInt(maskMsgDiv.css("padding-bottom"))) / 2) + "px");
                }
                ///maskMsgDiv.css("top", $(document).scrollTop())
            }
            maskMsgDiv.show();
        }

    };

    $.unmaskElement = function(element) {
       
        //if this element has delayed mask scheduled then remove it
        if (element.data("_mask_timeout") !== undefined) {
            clearTimeout(element.data("_mask_timeout"));
            element.removeData("_mask_timeout");
        }

        element.find(".loadmask-msg,.loadmask").remove();
        element.removeClass("masked");
        element.removeClass("masked-relative");
        //element.find("select").css("disabled","");
    };

})(jQuery);
//////////////////timepicker///////////////////////
(function($) {
    jQuery.fn.timepicker = function(o) {
        var options = $.extend({
            defaultValue: false,
            disenableSecond: true
        }, o);
        this.each(function() {
            // get the ID and value of the current element
            var i = this.id;
            // the options we need to generate
            var hrs = new Array();
            for (var p = 0; p < 24; p++) { hrs.push(format(p)) }
            var mins = new Array();
            for (var j = 0; j < 60; j++) { mins.push(format(j)) }
            var ap = new Array();
            for (var h = 0; h < 60; h++) { ap.push(format(h)) }
            // default to the current time

            var d = new Date();
            var h = format(d.getHours());
            var m = format(d.getMinutes());
            var p = format(d.getSeconds());
            if (options.defaultValue) {
                h = options.defaultValue.substring(11, 19).split(":")[0];
                m = options.defaultValue.substring(11, 19).split(":")[1];
                p = options.defaultValue.substring(11, 19).split(":")[2];
            }
            if (options.disenableSecond) {
                p = format("00");
            }
            var v = h + ':' + m + ':' + p;
            $("#" + i).attr("val", v);
            function format(n)//格式化数字为两位字符表示
            {
                var m = new String();
                var tmp = new String(n);
                if (n < 10 && tmp.length < 2) {
                    m = "0" + n;
                }
                else {
                    m = n;
                }

                return m;

            }
            // build the new DOM objects
            var output = '';
            output += '<select id="h_' + i + '" class="h timepicker" style="vertical-align:middle;">';
            for (var hh = 0; hh < hrs.length; hh++) {

                output += '<option value="' + hrs[hh] + '"';
                if (hrs[hh] == h) output += ' selected';
                output += '>' + hrs[hh] + '</option>';
            }
            output += '</select>时';

            output += '<select id="m_' + i + '" class="m timepicker" style="vertical-align:middle;">';
            for (var j = 0; j < mins.length; j++) {
                output += '<option value="' + mins[j] + '"';
                if (mins[j] == m) output += ' selected';
                output += '>' + mins[j] + '</option>';
            }
            output += '</select>分';

            output += '<select id="p_' + i + '" class="p timepicker" style="vertical-align:middle;">';
            if (!options.disenableSecond) {
                for (var pp = 0; pp < mins.length; pp++) {
                    output += '<option value="' + ap[pp] + '"';
                    if (ap[pp] == p) output += ' selected';
                    output += '>' + ap[pp] + '</option>';
                }
            }
            else {
                output += '<option selected value="00">00</option>';
              
            }
            output += '</select>秒';


            // hide original input and append new replacement inputs
            //var wrapper = $(this).wrap("<div/>").parent().addClass("myui-form-div-datepicker");
            // var wrap = $(this).attr('type', 'hidden').wrap("<div/>");
            $(this).append(output);


        });

        $('select.timepicker').change(function() {
            var i = this.id.substr(2);
            var h = $('#h_' + i).val();
            var m = $('#m_' + i).val();
            var p = $('#p_' + i).val();
            var v = h + ':' + m + ':' + p;
            $("#" + i).attr("val", v);

        });
        return this;
    };
})(jQuery);
//=============editortable=============
(function($) {
    $.ui = $.ui || {};
    $.fn.editortable = function(opts) {
        var myeditortable = false;

        if (this[0])
            myeditortable = new $.ui.editortable(opts, this[0]);

        return myeditortable;
    };
    $.ui.editortable = function(option, ele) {
        var cofig = $.extend(
         {
             items: [],
             data: null,
             width: 400,
             height: 400,
             formposition: 0,
             addRow: true,
             addWord: '添加行',
             clearWord: '清空',
             clear: true,
             selectRow: true,
             selectWord: '选择行',
             selectEvent: null,
             deleteEvent: null,
             delRow: true,
             showDelRow: true,
             template: null,
             rails: true,
             storeDel: "",
             showHeader: true,
             noShowCheckbox: true,
             inputandselectEvent: false,
             inputandselectListEvent:false,
             addRowHandler:false,
             saveData:false,
             saveDataWord:'保存'
         }, option);
        //--------defined id----------//
        var tableID = "myeditor" + $(ele).attr("id");
        var containerID = "myContainerID" + $(ele).attr("id");
        var toolbarID = "myToolbarID" + $(ele).attr("id");
        var addbtnID = "myaddBtnID" + $(ele).attr("id");
        var selectbtnID = "myselectBtnID" + $(ele).attr("id");
        var clearbtnID = "myclearBtnID" + $(ele).attr("id");
        var savebtnID="mysaveBtnID"+$(ele).attr("id");
        //add container
        $(ele).html("<div id=\"" + containerID + "\" class=\"div-editor-container\"></div>");
        //add toolbar
        $("#" + containerID).width(cofig.width);
        $("#" + containerID).prepend("<div class=\"div-editor-toolbar\" id=\"" + toolbarID + "\"></div>");
        //render header
        var rowtemplate = "";
        RenderHeaderAndmakeRowTemplate();
        //initial
        InitializeRow();
        //bind delete event
        showDelRow();

        // Allow to add rows
        //判断是自定义事件还是默认
        if (cofig.addRow) {

            $("#" + toolbarID).append("<a id=\"" + addbtnID + "\" class=\"div-editor-tool-btn\" href=\"javascript:void(0);\"><span class=\"Add\" title=\"" + cofig.addWord + "\">" + cofig.addWord + "</span></a>");
            $("#" + addbtnID).click(function() {
                if(cofig.addRowHandler && $.isFunction(cofig.addRowHandler))
                {
                    cofig.addRowHandler.call(this);
                }
                else
                {
                    addRow(null, true);
                }
                return false;
            });
        }
        //判断是自定义事件还是默认
        if (cofig.selectRow) {
            $("#" + toolbarID).append("<a id=\"" + selectbtnID + "\" class=\"div-editor-tool-btn\" href=\"javascript:void(0);\"><span class=\"Selected\" title=\"" + cofig.selectWord + "\">" + cofig.selectWord + "</span></a>");
            $("#" + selectbtnID).click(function() {
                if (cofig.selectEvent && $.isFunction(cofig.selectEvent)) {
                    cofig.selectEvent.call($(this));

                }
                return false;
            });
        }
        //判断是清空
        if (cofig.clear) {
            $("#" + toolbarID).append("<a id=\"" + clearbtnID + "\" class=\"div-editor-tool-btn\" href=\"javascript:void(0);\"><span class=\"Clear\" title=\"" + cofig.clearWord + "\">" + cofig.clearWord + "</span></a>");
            $("#" + clearbtnID).click(function() {
                clear();
                return false;
            });
        }
        //判断是否保存
        if(cofig.saveData)
        {
            $("#" + toolbarID).append("<a id=\"" + savebtnID + "\" class=\"div-editor-tool-btn\" href=\"javascript:void(0);\"><span class=\"Save\" title=\"" + cofig.saveDataWord + "\">" + cofig.saveDataWord + "</span></a>");
            $("#" + savebtnID).click(function() {
                if(cofig.saveData && $.isFunction(cofig.saveData))
                {
                    cofig.saveData.call(this);//提供接口给外面
                }
                return false;
            });
        }
        if (cofig.delRow) {

            //allow to delete at row end
            if (cofig.showDelRow) {
                $("#" + tableID).find('tr:first').each(function(index, elem) {
                    $(elem).append("<th class=\"div-th-delete\">删除</th>");
                });

            }

        }

        // Allow to delete rows
        function showDelRow() {
            $("#" + tableID).find('a.div-row-delete').live("click", function() {
                DeleteRow($(this).parents('tr').eq(0),true);
                return true;

            });
        }
        function RenderHeaderAndmakeRowTemplate() {
            var header = [];
            var template = [];

            header.push("<div class=\"clear\"></div><div class=\"div-table-container\">");
            header.push("<table class=\"div-editor-table\" id=\"" + tableID + "\" ><thead><tr class=\"disableedit\">");
            template.push("<tr>");
            for (var i = 0, l = cofig.items.length; i < l; i++) {
                var item = cofig.items[i];

                if (item.type != "inputHidden") {
                    header.push("<th class=\"" + item.thClass + "\" col=\"" + item.thName + "\">" + item.colName + "</th>");
                }
                if (item.type != "inputHidden") {
                    if (item.align) {

                        template.push("<td align=" + item.align + ">");
                    }
                    else {
                        template.push("<td>");

                    }
                    template.push(makeTemplate(item.type, item.colID, item.colClass, "",item.width,true));
                    template.push("</td>")
                }
                else {
                    template.push("<span style='display:none'/>");
                    template.push(makeTemplate(item.type, item.colID, item.colClass, "",item.width,true));
                    template.push("</span>");
                }

            }
            header.push("</tr></thead><table></div>");
            template.push("</tr>");
            rowtemplate = template.join("");
            cofig.template = rowtemplate;
            $("#" + containerID).append(header.join(""));
            //是否显示标题
            if (!cofig.showHeader) {
                $("#" + tableID).find('tr:first').hide()

            }
            if (cofig.noShowCheckbox) {
                $("#" + tableID + " tr th:first-child").hide();

            }
            header = null;
            template = null;
        }
        function makeTemplate(tempType, name, cssClass, value,thWidth,flag) {
            
            switch (tempType) {
                case "sltinput":
                    if (flag) {
                        return "<input id=\""+name+"\" name=\"" + name + "\" attrType=\"sltinput\"   type=\"text\" value=\"" + value + "\" class=\"" + cssClass + "\"  style='width:"+thWidth+"' />";
                    }
                    else {
                        return "<input id=\""+name+"\" name=\"" + name + "\"  readonly = \"readonly\" attrType=\"sltinput\"  type=\"text\" value=\"" + value + "\" class=\"" + cssClass + "\"  style='width:"+thWidth+"' />";
                    }

                    break;
                case "sltinputEdit":
                        return "<input name=\"" + name + "\" attrType=\"sltinputEdit\" maxlength=\"9\"   type=\"text\" value=\"" + value + "\" class=\"" + cssClass + "\"  style='width:"+thWidth+"' />";
                    break;
                case "sltinputRemark":
                        return "<input name=\"" + name + "\" attrType=\"sltinputRemark\"  type=\"text\" value=\"" + value + "\" class=\"" + cssClass + "\" style='width:"+thWidth+"' />";
                    break;
                case "sltchk":
                    return "<input name=\"" + name + "\"  attrType=\"sltchk\" type=\"checkbox\" class=\"" + cssClass + "\" />";
                    break;
                case "sltonlychk":
                    if (value == 1) {
                        return "<input name=\"" + name + "\"  attrType=\"sltonlychk\"  checked=\"checked\" type=\"checkbox\" class=\"" + cssClass + "\" />";
                    }
                    else {

                        return "<input name=\"" + name + "\"  attrType=\"sltonlychk\" type=\"checkbox\" class=\"" + cssClass + "\" />";
                    }
                    break;
                case "sltDate":
                    return "<input id=\"" + name + "\"  readonly = \"readonly\" attrType=\"sltDate\" name=\"" + name + "\" value=\"" + value + "\" type=\"text\" class=\"" + cssClass + "\"  style='width:"+thWidth+"' />";
                    break;
                case "inputHidden":
                    return "<input name=\"" + name + "\" attrType=\"inputHidden\"  type=\"hidden\" value=\"" + value + "\" class=\"" + cssClass + "\" />";
                    break;
                case "sltinandsel":
                    return "<input id=\"" + name + "\"  attrType=\"sltinandsel\" name=\"" + name + "\" value=\"" + value + "\" type=\"text\" class=\"" + cssClass + "\"/>";
                    break;
                default:
                    return "<input name=\"" + name + "\" attrType=\"sltinput\" type=\"text\" value=\"" + value + "\" class=\"" + cssClass + "\" />";
                    break;
            }
        }
        function InitializeRow() {
            var rows = cofig.data;
            if (rows != null && rows.length > 0) {
                for (var i = 0; i < rows.length; i++) {

                    addRow(rows[i], false)
                }
            }
        }

        /**
        * Function that allows o add new rows
        */
        function addRow(obj, flag) {
            //var tr = rowtemplate;
            var tr = cofig.template;
            cofig.formposition++;
            var cols = [];
            cols.push("<tr>");

            if ($(tr).find("input").length > 0) {
                $(tr).find("input").each(function(index, elem) {
                    // Change the name of the fields
                    var newName = '';
                    if (cofig.formposition !== '') {
                        newName = elem.name.replace(/\[[0-9]+\]/i, '[' + cofig.formposition + ']');
                    }
                    else {
                        cofig.formposition = $("#" + tableID + " tr").length - 1;
                        newName = elem.name;
                    }
                    newName = newName.replace(/[^\w]/gi, "_");
                    var colindex = "colindex" + index;
                    var objvalue = (obj == null ? "" : obj[colindex]);
                    if (elem.attrType != "inputHidden") {
                        //alert($(this).parent().attr("align"))
                        cols.push("<td style='text-align:" + $(this).parent().attr("align") + "'>");
                        if (elem.attrType == "sltchk") {
                            if (flag) {
                                cols.push("<input name=\"div-edit-checkbox\" checked=\"true\" rowIndex=\"" + cofig.formposition + "\" rowNO=\"" + cofig.formposition + "\" value=\"" + objvalue + "\"  attrType=\"sltchk\" type=\"checkbox\" class=\"" + elem.className + "\" />");
                            }
                            else {
                                cols.push("<input name=\"div-edit-checkbox\" checked=\"true\"  checked=\"true\" rowIndex=\"" + cofig.formposition + "\" rowNO=\"" + cofig.formposition + "\" value=\"" + objvalue + "\"  attrType=\"sltchk\" type=\"checkbox\" class=\"" + elem.className + "\" />");
                            }
                        }
                        else {
                            cols.push(makeTemplate(elem.attrType, newName, elem.className, objvalue,elem.style.width,flag));

                        }
                        cols.push("</td>");
                    }
                    //隐藏字段
                    else {
                        cols.push("<span style='display:none;'>");
                        cols.push(makeTemplate(elem.attrType, newName, elem.className, objvalue,elem.style.width,flag))
                        cols.push("</span>");
                    }
                });
                if (cofig.delRow && cofig.showDelRow) {
                    cols.push("<td class=\"div-td-delete\"><a href=\"#\" class=\"div-row-delete\"><span class=\"Delete\">&nbsp;</span></a></td>");
                }

                cols.push("</tr>");


            }
            $("#" + tableID).prepend(cols.join(""));

            cols = null;
            //allow datepicker
            $(":text[class='div-input-date']", $("#" + tableID + " tr:not(.disableedit):first")).each(function(index, elem) {

                if (elem.attrType == "sltDate") {
                    var dateWidth=125;
                    var userTime=true;
                    if(elem.style.width!="")
                    {
                        dateWidth=elem.style.width;
                        userTime=false;
                    }
                    $(elem).datepicker({ width: dateWidth ,isUserTime:userTime});
                }
            });
            //allow focus
            $(":text[class='div-input-text']", $("#" + tableID + " tr:not(.disableedit):first")).each(function(index, elem) {

                if (!$(this).attr("readonly")) {
                    $(this).focus();
                    return false;
                }
            });

            //allow selectandinput
            $(":text[class='div-inputandselect-text']", $("#" + tableID + " tr:not(.disableedit):first")).each(function(index, elem) {

                if (cofig.inputandselectEvent && $.isFunction(cofig.inputandselectEvent)) {

                    cofig.inputandselectEvent.call(this, elem);
                }

            });
            //allow selectandinputList
            $(":text[class='div-inputandselectList-text']", $("#" + tableID + " tr:not(.disableedit):first")).each(function(index, elem) {

                if (cofig.inputandselectEvent && $.isFunction(cofig.inputandselectEvent)) {

                    cofig.inputandselectEvent.call(this, elem);
                }

            });
            //allow selectandinputList
            $(":text[class='div-inputandselectListArray-text']", $("#" + tableID + " tr:not(.disableedit):first")).each(function(index, elem) {

                if (cofig.inputandselectListEvent && $.isFunction(cofig.inputandselectListEvent)) {

                    cofig.inputandselectListEvent.call(this, elem);
                }

            });
            if (cofig.noShowCheckbox) {
                $("#" + tableID + " tr th:first-child").hide();
                $("#" + tableID + " tr td:first-child").hide();
            }

        }
        //Allow to delete row
        function DeleteRow(elem,isClearData) {
            if (cofig.rails) {
                var checkbox = $(elem).find("input[name='div-edit-checkbox']:first");
                if ($(checkbox).val() !== "") {
                    cofig.storeDel += $(checkbox).val() + ",";
                }
            }
            $(elem).remove();
            // alert(cofig.storeDel);
            //rownumber initialize
            var rowno = 0;
            $("#" + tableID).find("input[name='div-edit-checkbox']").each(function(index, elem) {
                rowno++;
                $(elem).attr("rowNO", rowno)
            })
            cofig.formposition = rowno;
            if (cofig.deleteEvent && $.isFunction(cofig.deleteEvent)) {
                var value = $(elem).find("input[name='div-edit-checkbox']:first").val();
                cofig.deleteEvent.call(this, value,isClearData);
            }
            //alert(cofig.formposition);
        }
        //isClearData判断是否删除数据
        function clear(isClearData) {
            $("tr:not(.disableedit)", "#" + tableID).each(function() {
                DeleteRow($(this),isClearData);
            });
        };
        function hidecolumn(Index) {
            $("#" + tableID).find("tr").find("th:eq(" + Index + ")").each(function() { $(this).hide(); });
            $("#" + tableID).find("tr").find("td:eq(" + Index + ")").each(function() { $(this).hide(); });
        };
        function showcolumn(Index) {
            $("#" + tableID).find("tr").find("th:eq(" + Index + ")").each(function() { $(this).show(); });
            $("#" + tableID).find("tr").find("td:eq(" + Index + ")").each(function() { $(this).show(); });
        };
        /////----------API--------------------//////
        //获取选中的行编号
        this.GetSelectedRow = function(type) {
            var table = $("#" + tableID);
            var returnVal = [];
            $(table).find("input[name='div-edit-checkbox'][disabled='true']").each(function(index, elem) {
                returnVal.push($(elem).val());
            })
            return returnVal;
        };
        this.Clear = function() {
            clear();
        };
        this.HideColumn = function(index) {
            hidecolumn(index);
        };
        this.ShowColumn = function(index) {
            showcolumn(index);
        };
        this.CheckExist = function(itemArray) {
            var table = $("#" + tableID);
            var returnVal = false;
            $(table).find("input[name='div-edit-checkbox']").each(function(index, elem) {
                if ($(elem).val() == itemArray["colindex0"]) { returnVal = true; return; }
            })
            return returnVal;
        };
        this.GetRow = function(itemArray) {
            var table = $("#" + tableID);
            var returnVal = null;
            $(table).find("input[name='div-edit-checkbox']").each(function(index, elem) {
                if ($(elem).val() == itemArray["colindex0"]) { returnVal = $(this).parents('tr').eq(0); return; }
            })
            return returnVal;
        };
        this.GetTable = function(table) {
            var table = $("#" + tableID);
            return table;
        };
        //添加行
        this.customAddRow = function(itemArray,flag,IsNoCheck) {
            if(flag=="" || flag==undefined)
            {
                flag=false;
            }
            if(IsNoCheck=="" || IsNoCheck==undefined)
            {
                for (var i = 0; i < itemArray.length; i++) {
                    if (!this.CheckExist(itemArray[i])) {
                        addRow(itemArray[i], flag);
                    }
                }
            }
            else
            {
                for (var i = 0; i < itemArray.length; i++) {
                    addRow(itemArray[i], flag);
                }
            }
        },
        //删除行
        this.customDeleteRow = function(itemArray) {
            for (var i = 0; i < itemArray.length; i++) {
                if (this.GetRow(itemArray[i]) != null) {
                    DeleteRow(this.GetRow(itemArray[i]));
                }

            }
        }

    }
})(jQuery);
//=========================Checkbox=======================
(function($) {
    $.fn.ikecheckbox = function(option, method) {
        var config = $.extend({
            defaultCls: 'zogo-form-checkbox',
            hoverCls: 'zogo-form-checkbox-hover',
            checkedCls: 'zogo-form-checkbox-checked',
            clickEvent: null
        }, option);
        if (method == 'check') {
            return this.each(function() {
                $(this).attr('checked', 'checked');
                $(this).next().addClass(config.checkedCls);
            });
        };
        if (method == 'uncheck') {
            return this.each(function() {
                $(this).removeAttr('checked');
                $(this).next().removeClass(config.checkedCls);
            });
        };
        if (method == 'disable') {
            return this.each(function() {
                $(this).attr('disabled', 'disabled');
                $(this).next().css('opacity', .3)
						  .unbind('click')
						  .unbind('mouseover')
						  .unbind('mouseout');
            });
        };
        if (method == 'enable') {
            return this.each(function() {
                var target = $(this);
                var item = target.next();
                target.removeAttr('disabled');
                item.css('opacity', 1)
				.bind('click', { target: target, item: item }, _click)
				.bind('mouseover', { item: item }, _mouseover)
				.bind('mouseout', { item: item }, _mouseout);
            });
        };
        if (method == 'click') {
            return this.each(function() {
                _click({ data: { target: $(this), item: $(this).next()} });
            });
        };
        return this.each(function() {
            var target = $(this);
            var text = $(this).next();
            var item =
			$('<span />').insertAfter(this)
						 .addClass(config.defaultCls)
						 .attr("title", $(this).attr("title"))
						 .html(text.html());
            target.hide();
            text.remove();

            item.bind('click', { target: target, item: item }, _click)
				.bind('mouseover', { item: item }, _mouseover)
				.bind('mouseout', { item: item }, _mouseout);

            if (target.attr('disabled')) { $(this).d_checkbox('disable'); }
            if (target.attr('checked')) { $(this).d_checkbox('check'); }
        });
        function _click(event) {
            var _target = event.data.target;
            var _item = event.data.item;
            _target.attr('checked', !_target.attr('checked'));
            _item.toggleClass(config.checkedCls);
            //提供向外的接口
            if (config.clickEvent && $.isFunction(config.clickEvent)) {
                config.clickEvent.call(this, _target);
            }

        }
        function _mouseover(event) {
            event.data.item.addClass(config.hoverCls);
        }
        function _mouseout(event) {
            event.data.item.removeClass(config.hoverCls);
        }

    }

})(jQuery);
//====================Radio========================
(function($) {
    $.fn.ikeradio = function(option, method) {

        var config = $.extend({
            defaultCls: 'zogo-form-radio',
            hoverCls: 'zogo-form-radio-hover',
            checkedCls: 'zogo-form-radio-checked',
            clickEvent: null
        }, option);
        if (method == 'disable') {
            return this.each(function() {
                $(this).attr('disabled', 'disabled');
                $(this).next().css('opacity', .3)
						  .unbind('click')
						  .unbind('mouseover')
						  .unbind('mouseout');
            });
        };

        if (method == 'enable') {
            return this.each(function() {
                var target = $(this);
                var item = target.next();
                target.removeAttr('disabled');
                item.css('opacity', 1)
				.bind('click', { target: target, item: item }, _click)
				.bind('mouseover', { item: item }, _mouseover)
				.bind('mouseout', { item: item }, _mouseout);
            });
        };

        if (method == 'click') {
            return this.each(function() {
                _click({ data: { target: $(this), item: $(this).next()} });
            });
        };

        return this.each(function(i) {
            var target = $(this);
            var text = $(this).next();
            var item = $('<span />').insertAfter(this)
									.addClass(config.defaultCls)
									.addClass(target.attr('checked') ? config.checkedCls : '')
									.html(text.html());
            target.hide();
            text.remove();

            item.bind('click', { target: target, item: item }, _click)
				.bind('mouseover', { item: item }, _mouseover)
				.bind('mouseout', { item: item }, _mouseout);
            if (target.attr('disabled')) { $(this).d_checkbox('disable'); }
        });
        function _click(event) {
            var _target = event.data.target;
            var _item = event.data.item;
            _target.attr('checked',true);
            $(":radio[name='" + _target.attr('name') + "']").next().removeClass(config.checkedCls);
            _item.toggleClass(config.checkedCls);
            //提供向外的接口
            if (config.clickEvent && $.isFunction(config.clickEvent)) 
            {
                config.clickEvent.call(this, _target);
            }
        }
        function _mouseover(event) {
            event.data.item.addClass(config.hoverCls);
        }

        function _mouseout(event) {
            event.data.item.removeClass(config.hoverCls);
        }

    }
})(jQuery);





