var MenuBoxStyle={None:0,Blue:1,Gray:2};
GoControl.prototype.Load = function(t,idx) {
if(!idx)idx=[0];
t[idx[0]-1]=this;
if(31618723!=t[idx[0]++])alert(ss+'An invalid version of the script: ComponentGo.Web. Reload a page, please.');
this.callbackTimeout=t[idx[0]++];
this.postbackMode=t[idx[0]++];
this.progressTimeout=t[idx[0]++];
this.Action=t[idx[0]++];
if(typeof(this.Action)=='undefined')this.Action=this.callback;
this.Action_serialize=function(args,map){
var s="b`";
s+=go.SerializeStr(args.Name);
s+=go.SerializeStr(args.Argument);
return s;
}
this.Refreshing=t[idx[0]++];
if(typeof(this.Refreshing)=='undefined')this.Refreshing=this.callback;
this.Refreshing_serialize=function(args,map){
return "c`";
}
this.callbackFn=t[idx[0]++];
this.progressCode=go.DeserStr(t,idx[0]++);
this.clientID=go.DeserStr(t,idx[0]++);
this.uniqueID=go.DeserStr(t,idx[0]++);
return this;
}

GoControl.prototype.Serialize = function(map) {
if(!map) map=[];
var r="31618723`";
var ev="";
for (var i = 0; i<this.eventsData.length; i+=2)
    ev += this[this.eventsData[i]+"_serialize"](this.eventsData[i+1], map);
this.eventsData = [];
r+=(ev+"`");
return r;
}

MenuBoxItem.prototype.Load = function(t,idx) {
if(!idx)idx=[0];
t[idx[0]-1]=this;
return this;
}

MenuBoxItem.prototype.Serialize = function(map) {
if(!map) map=[];
return "";
}

ContextMenuBox.prototype.Load = function(t,idx) {
if(!idx)idx=[0];
t[idx[0]-1]=this;
this.GoControl_Load(t,idx);
this.appearable=t[idx[0]++]!=0;
this.Command=t[idx[0]++];
if(typeof(this.Command)=='undefined')this.Command=this.callback;
this.Command_serialize=function(args,map){
var s="d`";
s+=go.SerializeStr(args.Name);
s+=go.SerializeStr(args.Argument);
return s;
}
this.MenuActivate=t[idx[0]++];
if(typeof(this.MenuActivate)=='undefined')this.MenuActivate=null;
this.horizontal=t[idx[0]++]!=0;
var arr=[];
for(var length=t[idx[0]++]; --length>=0;) {
var obj;
var n=t[idx[0]++];
switch(n) {
case 0: {
obj=new MenuActionItem().Load(t,idx);
break; }
case 1: {
obj=new MenuSeparatorItem().Load(t,idx);
break; }
}
arr.push(obj);
}
this.items=arr;
this.linkedControlID=t[idx[0]++];
this.menuStyle=t[idx[0]++];
this.font=t[idx[0]++];
this.backColor=t[idx[0]++];
return this;
}

ContextMenuBox.prototype.Serialize = function(map) {
if(!map) map=[];
var r=this.GoControl_Serialize(map);
return r;
}

MenuBox.prototype.Load = function(t,idx) {
if(!idx)idx=[0];
t[idx[0]-1]=this;
this.ContextMenuBox_Load(t,idx);
return this;
}

MenuBox.prototype.Serialize = function(map) {
if(!map) map=[];
var r=this.ContextMenuBox_Serialize(map);
return r;
}

MenuSeparatorItem.prototype.Load = function(t,idx) {
if(!idx)idx=[0];
t[idx[0]-1]=this;
this.MenuBoxItem_Load(t,idx);
return this;
}

MenuSeparatorItem.prototype.Serialize = function(map) {
if(!map) map=[];
var r=this.MenuBoxItem_Serialize(map);
return r;
}

var PostbackMode={PostbackInAjax:0,Always:1,Custom:2};
MenuActionItem.prototype.Load = function(t,idx) {
if(!idx)idx=[0];
t[idx[0]-1]=this;
this.MenuBoxItem_Load(t,idx);
this.commandArgument=go.DeserStr(t,idx[0]++);
this.commandName=go.DeserStr(t,idx[0]++);
this.enabled=t[idx[0]++]!=0;
this.imageUrl=go.DeserStr(t,idx[0]++);
this.key=go.DeserStr(t,idx[0]++);
this.navigateUrl=go.DeserStr(t,idx[0]++);
this.onClientAction=t[idx[0]++];
var arr=[];
for(var length=t[idx[0]++]; --length>=0;) {
var obj;
var n=t[idx[0]++];
switch(n) {
case 0: {
obj=new MenuActionItem().Load(t,idx);
break; }
case 1: {
obj=new MenuSeparatorItem().Load(t,idx);
break; }
}
arr.push(obj);
}
this.subItems=arr;
this.target=go.DeserStr(t,idx[0]++);
this.text=go.DeserStr(t,idx[0]++);
return this;
}

MenuActionItem.prototype.Serialize = function(map) {
if(!map) map=[];
var r=this.MenuBoxItem_Serialize(map);
r+=(go.SerializeStr(this.commandArgument));
r+=(go.SerializeStr(this.commandName));
r+=((this.enabled)?"T`":"`");
var urls=this.imageUrl;
if(urls!=null){
var urli=urls.indexOf("|@");
urls=urli>=0 ? urls.substr(urli+2) : urls;
}
r+=(go.SerializeStr(urls));
r+=(go.SerializeStr(this.key));
var urls=this.navigateUrl;
if(urls!=null){
var urli=urls.indexOf("|@");
urls=urli>=0 ? urls.substr(urli+2) : urls;
}
r+=(go.SerializeStr(urls));
var codes=this.onClientAction;
if(codes!=null) codes=codes.toString().substr(11,codes.length-12);
r+=(go.SerializeStr(codes));
var s="`";
var arr=this.subItems;
if(arr!=null && arr.length>0) {
s=arr.length+"`";
for(var idx=0; idx<arr.length; ++idx) {
var o=arr[idx];
o=o.GetType().TypeName+"`"+o.Serialize(map);
s+=o;
}
}
r+=(s);
r+=(go.SerializeStr(this.target));
r+=(go.SerializeStr(this.text));
return r;
}


//
// Capture mouse
//
// Drag handler methods and fields:
//  CancelDragging()
//  AcceptDragging()
//  StopDragging()
//  StartDragging()
//  StartEdit()
//  Dragging()
//  Cursor - indicating a cursor appearance during dragging
//  Element - indicating an element that will be scrolled if a mouse cursor will move outside one.
//

GoGlobal.prototype.SetCapture = function(handler) {
    if (this.IsCaptured) return;

    if (!this.captureInitilized) {
        var wnd = window.document.body;
        go.Attach(this, "Window_MouseMove", wnd);
        go.Attach(this, "Window_MouseOut", wnd);
        go.Attach(this, "Window_MouseDown", wnd);
        this.captureInitilized = true;
    }

    if (typeof (handler) == "function") {
        var h = {};
        h.Dragging = handler;
        handler = h;
    }

    this.captureHandler = handler;
    this.captureReady = true;
    this.captureStarted = false;
    this.captureLastPt = null;
    this.captureScrollPt = null;
    this.IsCaptured = true;
    ++this.lockEvent;
    this.captureSelectStart = document.onselectstart;
    document.onselectstart = function() { return false; };

    go.ReleaseEdit();
    this.captureEdit = handler.StartEdit;
    if (typeof (handler.StartEdit) == "function")
        this.captureHEdit = setTimeout(go.Delegate(this, "capture_StartEdit"), 500);
    else
        this.captureHEdit = -1;

    if (handler.Element)
        this.captureHScroll = setInterval(go.Delegate(this, "capture_Scroll"), 100);
    else
        this.captureHScroll = -1;
}

GoGlobal.prototype.ReleaseCapture = function() {
    if (this.captureHandler != null && typeof (this.captureHandler.StopDragging) == "function")
        this.captureHandler.StopDragging();

    if (this.IsCaptured) {
        document.onselectstart = this.captureSelectStart;
        this.IsCaptured = false;
    }
    this.captureHandler = null;
    if (this.captureHScroll != -1) {
        clearInterval(this.captureHScroll);
        this.captureHScroll = -1;
    }
    if (typeof (this.captureCursor) != "undefined")
        document.body.style.cursor = this.captureCursor;
    if (this.lockEventControl && this.lockEventControl != null)
        this.lockEventControl.UnlockEvent();
    else if (this.lockEvent > 0)
        --this.lockEvent;
}   

GoGlobal.prototype.ReleaseEdit = function() {
    if (this.captureHEdit!=-1)
        clearTimeout(this.captureHEdit);
    this.captureHEdit = -1;
    this.captureEdit = null;
}   

GoGlobal.prototype.capture_StartEdit = function() {
    if (this.captureHEdit==-1 || this.captureEdit==null) return;
    this.captureHEdit = -1;
    this.captureEdit();
}

GoGlobal.prototype.captureScrollDelta = function(v) {
    if (v<20) return 2;
    if (v<100) return 10;
    return 20;
}

GoGlobal.prototype.capture_Scroll = function() {
    if (this.captureLastPt==null) return;
    
    var x = this.captureLastPt.X;
    var y = this.captureLastPt.Y;
    var dX = 0;
    var dY = 0;
    if (x<10) 
        dX = -this.captureScrollDelta(-x+10);
    else if (x>=this.captureHandler.Element.clientWidth-10)
        dX = this.captureScrollDelta(x-this.captureHandler.Element.clientWidth+10);
    if (y<10) 
        dY = -this.captureScrollDelta(-y+10);
    else if (y>=this.captureHandler.Element.clientHeight-10)
        dY = this.captureScrollDelta(y-this.captureHandler.Element.clientHeight+10);
        
    this.captureHandler.Element.scrollLeft += dX;
    this.captureHandler.Element.scrollTop += dY;
}

GoGlobal.prototype.Window_MouseMove = function(e) {
    if (!this.IsCaptured && this.captureHEdit==-1) return;
   
    if (this.captureHScroll!=-1) {
        var pt = e.GetPt(this.captureHandler.Element);
        var scrollPt = new GoPoint(this.captureHandler.Element.scrollLeft, this.captureHandler.Element.scrollTop);
        pt.Sub(scrollPt);
        this.captureLastPt = pt;
        if (this.captureScrollPt!=null) {
            this.capturePt.Add(this.captureScrollPt);
            this.capturePt.Sub(scrollPt);
        }
        this.captureScrollPt = scrollPt;
    }
    e.DeltaX = e.X-this.capturePt.X;
    e.DeltaY = e.Y-this.capturePt.Y;
    
    var largeMove = e.DeltaX<-1 || e.DeltaX>1 || e.DeltaY<-1 || e.DeltaY>1;
    if (largeMove && this.captureHEdit!=-1)
        go.ReleaseEdit();
    
    if (this.IsCaptured) {
        if (!this.captureStarted && !this.captureReady) {
            if (largeMove) {
                this.captureHandler.StartDragging(e);
                this.captureStarted = true;
            }
        }
        if (this.captureStarted) {
            if (typeof(this.captureHandler.Dragging)=="function") {
                var dragging = this.captureHandler.Dragging(e);
                if (typeof(dragging)!="undefined" && !dragging) {
                    if (typeof(this.captureHandler.CancelDragging)=="function")
                        this.captureHandler.CancelDragging(e);
                    this.ReleaseCapture();
                }
            }
        }
    }
}

GoGlobal.prototype.Window_MouseUp = function(e) {
    if (this.IsCaptured) {
        e.DeltaX = e.X-this.capturePt.X;
        e.DeltaY = e.Y-this.capturePt.Y;

        if (this.captureStarted && typeof(this.captureHandler.AcceptDragging)=="function")
            this.captureHandler.AcceptDragging(e);
        this.ReleaseCapture();
    }
   
    gomenu.DoMouseUp();
}

GoGlobal.prototype.Window_MouseDown = function(e) {
    if (!this.IsCaptured) return;

//    e.DeltaX = e.X-this.capturePt.X;
//    e.DeltaY = e.Y-this.capturePt.Y;
    e.DeltaX = 0;
    e.DeltaY = 0;
    
    if (this.captureReady) {
        this.capturePt = e.Pt;
        this.captureStarted = typeof(this.captureHandler.StartDragging)!="function";
        this.captureReady = false;
        this.captureCursor = document.body.style.cursor;
        if (this.captureHandler.Cursor)
            document.body.style.cursor = this.captureHandler.Cursor;
        else
            document.body.style.cursor = e.Source.style.cursor;
    }
    else {
        if (this.captureStarted) {
            if (typeof(this.captureHandler.Dragging)=="function")
                this.captureHandler.Dragging(e);
            if (typeof(this.captureHandler.CancelDragging)=="function")
                this.captureHandler.CancelDragging(e);
        }
        this.ReleaseCapture();
    }
}

GoGlobal.prototype.Window_MouseOut = function(e) {
    if (!this.IsCaptured) return;
   
    e.DeltaX = e.X-this.capturePt.X;
    e.DeltaY = e.Y-this.capturePt.Y;
    
    // 9 - #document, 1 - ELEMENT
    var away = e.ToElement!=null && e.ToElement.parentNode!=null && (e.ToElement.parentNode.nodeType==9);
    if (away) {
        if (this.captureStarted) {
            if (typeof(this.captureHandler.Dragging)=="function") {
                e.DeltaX = e.DeltaY = 0;
                this.captureHandler.Dragging(e);
            }
            if (typeof(this.captureHandler.CancelDragging)=="function")
                this.captureHandler.CancelDragging(e);
        }
        this.ReleaseCapture();
    }
}


/*
*********************************************************************
* 
*       ComponentGo! Component Library
*
*       Copyright (c) ComponentGo!
*       ALL RIGHTS RESERVED
*
*********************************************************************
*/

if (typeof(__go_types)=="undefined") __go_types = {};

function RegisterType(type, parent) { 
    var t = __go_types[type];
    if (typeof(t)=="undefined") {
        var t = new GoType(type, parent);
        __go_types[type] = t;
        
        var typeP = eval(type+".prototype");
        
        if (typeof(parent)=="string") {
            var parentP = eval(parent+".prototype");
            typeP[parent] = eval(parent); // base contructor

            for (var field in parentP) {
                if (typeP[field])
                    typeP[parent+"_"+field] = parentP[field];
                else
                    typeP[field] = parentP[field];
            }
            
            typeP.GetType = function() { return t; }
        }
    }

}

RegisterType("GoType");

function GoType(type, parent) {
    this.TypeName = type;
    this.ParentName = parent;
    return this;
}

//
// ======================================================================
//

//
// Trace & Debug
//

GoGlobal.prototype.Alert = function(ele) {
    if (ele==null)
        alert("[null]");
    else if (typeof(ele)=="undefined")
        alert("[undefined]");
    else {
        var s = ele.constructor+"";
        s = s.substring(9, s.indexOf("("));
        s = "["+s+"]\n";
        for (var i in ele)
            s += i+" ";
        alert(s);
    }
}

GoGlobal.prototype.Trace = function(s) {
    if (!this.dbgElement) {
        this.dbgElement = document.createElement("div");
        this.dbgElement.style.border = "1px solid red";
        this.dbgElement.style.fontFamily = "Arial";
        this.dbgElement.style.fontSize = "8pt";
        this.dbgElement.style.color = "red";
        this.dbgElement.style.position = "absolute";
        this.dbgElement.style.left = "0px";
        this.dbgElement.style.top = "0px";
        this.dbgElement.style.zIndex = 999;
        this.dbgElement.onclick = function() {
            go.dbgElement.innerHTML = "";
        };
        
        document.body.insertBefore(this.dbgElement, document.body.firstChild);
        this.dbgNumber = 0;
    }
    var s = ++this.dbgNumber + ": "+ go.HtmlEncode(s+"");
    if (typeof(this.traceTime)=="undefined")
        this.traceTime = 0;
    var t = new Date().getTime();
    if (t-this.traceTime>1000)
        this.dbgElement.innerHTML = s;
    else
        this.dbgElement.innerHTML += "<br>"+s;
    this.traceTime = t;
    return this.dbgNumber;
}

GoGlobal.prototype.TraceBox = function(s) {
    if (typeof(s)=="undefined") {
        if (this.traceElement.style.visibility=="hidden") {
            this.traceElement.style.visibility = "visible";
            this.traceBox.style.visibility = "hidden";
        }
        else {
            this.traceElement.style.visibility = "hidden";
            this.traceBox.style.visibility = "visible";
        }
        return;
    };
    if (!this.traceElement) {
        this.traceElement = document.createElement("div");
        this.traceElement.style.border = "1px solid green";
        this.traceElement.style.fontFamily = "Arial";
        this.traceElement.style.fontSize = "7pt";
        this.traceElement.style.backgroundColor = "white";
        this.traceElement.style.color = "green";
        this.traceElement.style.position = "absolute";
        this.traceElement.style.left = "30px";
        this.traceElement.style.top = "4px";
        this.traceElement.style.visibility = "hidden";
        this.traceElement.style.zIndex = 1000;
        
        document.body.insertBefore(this.traceElement, document.body.firstChild);

        this.traceBox = document.createElement("div");
        this.traceBox.style.border = "1px solid green";
        this.traceBox.style.fontFamily = "Arial";
        this.traceBox.style.fontSize = "7pt";
        this.traceBox.style.color = "green";
        this.traceBox.style.position = "absolute";
        this.traceBox.style.left = "30px";
        this.traceBox.style.top = "4px";
        this.traceBox.style.cursor = "hand";
        this.traceBox.innerHTML = "<a href='javascript:go.TraceBox()'>Trace Go!</a><br>";
        
        document.body.insertBefore(this.traceBox, document.body.firstChild);
    }
    this.traceElement.innerHTML = "<a href='javascript:go.TraceBox()'>Close</a><br>"+s;
}

GoGlobal.prototype.HtmlEncode = function(s) {
    if (s==null) return null;
    return s.replace(/&/gi,"&amp;").replace(/</gi,"&lt;").replace(/>/gi,"&gt;");
}

GoGlobal.prototype.HtmlDecode = function(s) {
    if (s==null) return null;
    return s.replace(/&lt;/gi, "<").replace(/&gt;/gi, ">").replace(/&amp;/gi, "&");
}

GoGlobal.prototype.HtmlAttributeEncode = function(s) {
    if (s==null) return null;
    return s.replace(/&/gi,"&amp;").replace(/</gi,"&lt;");
}

GoGlobal.prototype.HtmlAttributeDecode = function(s) {
    return s.replace(/&lt;/gi, "<").replace(/&quot;/gi, '"').replace(/&amp;/gi, "&");
}

GoGlobal.prototype.Clone = function(obj) {
    var result = {};
    for (var name in obj)
        result[name] = obj[name];
    return result;
}

//
// Serialize
//

GoGlobal.prototype.None = function() {
}

GoGlobal.prototype.SerializeObj = function(s) {
    if (s==null) return "`";
    if (typeof(s)=="string") return "!"+s.replace(/~/g, "~0").replace(/`/g, "~1").replace(/</g, "~2")+"`";
    return s.toString()+"`";
}

GoGlobal.prototype.SerializeStr = function(s) {
    if (s==null) return "!(NU#LL$%`";
    var ss = s.replace(/~/g, "~0").replace(/`/g, "~1").replace(/</g, "~2")+"`";
    return ss;
}

GoGlobal.prototype.DeserStr = function(t, idx) {
    var v = t[idx];
    if (typeof(v)!="number") return v;
    if (v==0) return null;
    return t[v];
}

GoGlobal.prototype.AddDivWidth = function(ele, width, height) {
    var div = document.createElement("DIV");
    div.style.width = width+"px";
    if (typeof(height)!="undefined") {
        if (height<0) height = 0;
        div.style.overflow = "hidden";
        div.style.height = height+"px";
    }
    ele.appendChild(div);
    return div;
}

GoGlobal.prototype.ClientX = function(e) {
    var x = 0;
    while (e!=null) {
        x += e.offsetLeft-e.scrollLeft;
        e = e.offsetParent;
    }
    return x;
}

GoGlobal.prototype.ClientY = function(e) {
    var y = 0;
   
    if (!this.IsOpera) {
        var ee = e;
        while (e!=null) {
            y += e.offsetTop;
            e = e.offsetParent;
        }
        while (typeof(ee.scrollTop)!="undefined") {
            y -= ee.scrollTop;
            ee = ee.parentNode;
        }
    }
    else {
        var ee = e; 
        var enext = ee;
        while (ee!=null) {
            if (ee==enext) {
                enext = enext.offsetParent;
                y += ee.offsetTop;
            }
            ee = ee.parentElement;
        }
    }
    return y;
}

GoGlobal.prototype.Attr = function(ele, name, value) {
    if (typeof(value)=="undefined") {
        if (typeof(ele.attributes[name])=="undefined") return null;
        return ele.attributes[name].value;
    }
    else {
        var attr = ele.attributes[name];
        if (typeof(attr)=="undefined") {
            attr = document.createAttribute(name);
            ele.attributes.setNamedItem(attr);
        }
        attr.value = value;
    } 
}



GoGlobal.prototype.IfIE = function(s1, s2) {
    return this.IsIE ? s1 : s2;
}

GoGlobal.prototype.IfIE8 = function(s1, s2) {
    return this.IsIE8 ? s1 : s2;
}

GoGlobal.prototype.IfOperaIE = function(s0, s1, s2) {
    if (this.IsOpera) return s0;
    return this.IsIE ? s1 : s2;
}

GoGlobal.prototype.IfBrw = function(def, ie7, opera, safari) {
    if (this.IsSafari) {
        if (typeof(safari)=="undefined")
            return def;
        return safari;
    }
    if (this.IsOpera) {
        if (typeof(opera)=="undefined")
            return def;
        return opera;
    }
    return this.IsIE7 ? ie7 : def;
}

GoGlobal.prototype.InitializeElement = function(goc, ele, styleInfo, onlyEvents) {
    var idx = (typeof(styleInfo)=="undefined" || styleInfo==null || styleInfo=="")
        ? -2 : styleInfo.indexOf('`');
    if (idx<-1) return;
    var s = idx<0 ? styleInfo : styleInfo.substr(0, idx);
    if (!onlyEvents) {
        // Opera doesn't support for cssText
        if (typeof(ele.style.cssText)!="undefined")
            ele.style.cssText = s;
        else {
            var t = s.split(";");
            for (var i = t.length; --i>=0;) {
                var j = t[i].indexOf(":");
                if (j>=0) {
                    var ss = t[i].substr(0, j);
                    var k = ss.indexOf("-");
                    if (k>=0)
                        ss = ss.substr(0, k)+ss.substr(k+1, 1).toUpperCase()+ss.substr(k+2);
                    ele.style[ss] = t[i].substr(j+1);
                }
            }
        }
    }

    if (idx>=0 && idx<styleInfo.length-1) {
        ++idx;
        while (idx<styleInfo.length) {
            var i = styleInfo.indexOf("=\"", idx);
            if (i<0) break;
            var j = styleInfo.indexOf('"', i+2);
            if (j<0) break;
            s = styleInfo.substring(i+2, j);
            if (styleInfo.substr(idx, 2)=="on") {
                s = go.HtmlAttributeDecode(s);
                goc.attachEvent(ele, styleInfo.substring(idx+2, i), new Function("event", s));
            }
            else
                ele[styleInfo.substring(idx, i)] = s;
            idx = j+2;
        }
    }
}

GoGlobal.prototype.MakeElement = function(tag, attrs, styles, styleInfo) {
    var idx = (typeof(styleInfo)=="undefined" || styleInfo==null || styleInfo=="")
        ? -2 : styleInfo.indexOf('`');
    var html = "<"+tag;
    if (attrs!=null)
        html += " "+attrs;
    if (idx>=0 && idx<styleInfo.length-1)
        html += " "+styleInfo.substr(idx+1);
    if (styles!=null || idx>0 || idx==-1) {
        html += " style=\"";
        if (styles!=null) {
            html += styles;
            if (idx>0 || idx==-1)
                html += ";";
        }
        if (idx>0)
            html += styleInfo.substr(0, idx);
        else if (idx==-1)
            html += styleInfo;
        html += '"';
    }
    html += ">";
    return html;
}

//
// String
//

GoGlobal.prototype.ConcatStr = function(s1, s2, link) {
    if (s1==s2) return s1;
    if (s1==null || s1=="") return s2;
    if (s2==null || s2=="") return s1;
    return s1+link+s2;
}

GoGlobal.prototype.GetParam = function(s, index) {
    var i = -1;
    var ok = true;
    while (--index>=0 && ok) {
        i = s.indexOf(",", i+1);
        ok = i>=0;
    }
    if (!ok) i = s.length; else ++i;
    var j = s.indexOf(",", i);
    if (j<0) j = s.length;
    return s.substring(i, j)
}

GoGlobal.prototype.GetStr = function(ele, number) {
    var s = document.getElementById(ele.id+"_state").value;
    if (typeof(number)=="undefined")
        return s;
    var i = -1;
    var ok = true;
    while (--number>=0 && ok) {
        i = s.indexOf("~", i+1);
        ok = i>=0;
    }
    if (!ok) i = s.length; else ++i;
    var j = s.indexOf("~", i);
    if (j<0) j = s.length;
    return s.substring(i, j);
}

GoGlobal.prototype.GetInt = function(ele, number) {
    return parseInt(this.GetStr(ele, number));
}

GoGlobal.prototype.SetState = function(ele, value, number) {
    ele = document.getElementById(ele.id+"_state");
    if (typeof(number)=="undefined")
        ele.value = value;
    else {
        var s = ele.value;
        var i = -1;
        var ok = true;
        while (--number>=0 && ok) {
            i = s.indexOf("~", i+1);
            ok = i>=0;
        }
        if (!ok) i = s.length; else ++i;
            var j = s.indexOf("~", i);
        if (j<0) j = s.length;
        
        ele.value = s.substring(0, i)+value+s.substring(j, s.length);
    }
}

GoGlobal.prototype.FindArr = function(arr, element) {
    if (element==null) return "-";
    for (var i = arr.length; --i>=0;)
        if (arr[i]==element)
            return i;
    return "";
}

//
// Date & time
//

GoGlobal.prototype.SystemAMPM = function() {
    var s = new Date(2000, 1, 1, 16, 0).toLocaleString(); 
    return s.toLowerCase().indexOf("pm")>=0;
}

GoGlobal.prototype.GetHourName = function(h, ampm) {
    if (typeof(ampm)=="undefined") ampm = this.SystemAMPM();

	var hour = Math.floor(h);
	var mins = "";
	if (hour!=h) {
	    mins = Math.round((h-hour)*60);
	    mins = "<sup>"+(mins<10 ? "0" : "")+mins+"</sup>";
	}
	hour = hour % 24;
	if (!ampm) return hour+mins;
	if (mins=="")
		mins = hour<12 ? "<sup>am</sup>" : "<sup>pm</sup>";
	if (hour==0) hour = 12;
	else if (hour>12) hour -= 12;
	return hour+mins;
}

GoGlobal.prototype.DateToStr = function(dt) {
    return (dt.getMonth()+1)+"/"+dt.getDate()+"/"+dt.getFullYear()+" "+dt.getHours()+":"+dt.getMinutes();
}

GoGlobal.prototype.IsLastDayMonth = function(dt) {
    var dt2 = new Date(dt.getTime()+1000*60*60*24);
    return dt2.getUTCMonth()!=dt.getUTCMonth();
}

GoGlobal.prototype.AddMonths = function(dt, column, n) {
    if (typeof(dt)=="number") dt = new Date(dt);
	var c = Math.floor(column);
	var n12 = 12/n;
	var ym = n12*dt.getFullYear()+Math.floor(dt.getMonth()/n)+c;
	dt = Date.UTC(Math.floor(ym/n12), ym%n12*n, 1);
	if (c!=column) {
	    ++ym;
    	var dt2 = Date.UTC(Math.floor(ym/n12), ym%n12*n, 1);
    	var t = (column-c) * (dt2-dt);
    	dt += Math.floor(t);
	}
	return new Date(dt);
}

//
// Metrix Px
//

GoGlobal.prototype.AddPx = function(x, y) {
    if (typeof(x)=="string") {
        if (x.substr(x.length-2, 2)=="px") x = x.substr(0, x.length-2);
        x = parseInt(x);
    }
    if (typeof(y)=="string") {
        if (y.substr(y.length-2, 2)=="px") y = y.substr(0, y.length-2);
        y = parseInt(y);
    }
    var v = x+y;
    return v+"px";
}

GoGlobal.prototype.SubPx = function(x, y) {
    if (typeof(x)=="string") {
        if (x.substr(x.length-2, 2)=="px") x = x.substr(0, x.length-2);
        x = parseInt(x);
    }
    if (typeof(y)=="string") {
        if (y.substr(y.length-2, 2)=="px") y = y.substr(0, y.length-2);
        y = parseInt(y);
    }
    var v = x-y;
    return v+"px";
}

GoGlobal.prototype.ComparePx = function(x, y) {
    if (typeof(x)=="string") {
        if (x.substr(x.length-2, 2)=="px") x = x.substr(0, x.length-2);
        x = parseInt(x);
    }
    if (typeof(y)=="string") {
        if (y.substr(y.length-2, 2)=="px") y = y.substr(0, y.length-2);
        y = parseInt(y);
    }
    return x-y;
}

GoGlobal.prototype.GetLineWidth = function(line) {
    var i = line.indexOf(" ");
    if (i>=0) {
        var s = line.substring(0, i);
        if (s.length>2)
            return parseInt(line.substr(0, s.length-2));
    }
    throw new GoError(GoError_InvalidArgument);
}

GoGlobal.prototype.GetPx = function(width) {
    var type = typeof(width);
    if (type=="undefined" || width==null) return 0;
    if (type=="string") {
        if (width=="") return 0;
        if (width.substr(width.length-2, 2)=="px") width = width.substr(0, width.length-2);
        width = parseInt(width);
        if (isNaN(width)) return 1;
    }
    return width;
}

GoGlobal.prototype.MulUnit = function(x, n) {
    if (n==1) return x;
    var j = x.length;
    for (var i = 0; i<j; ++i) {
        var ch = x.charAt(i);
        if (!('0'<=ch && ch<='9' || ch=='.' || ch=='-')) { j = i; break; }
    }
    return x.substring(0, j)*n+x.substring(j);
}

//
// Delegates & events
//

GoGlobal.prototype.Delegate = function(obj, methodName) {
    return function() {
		return obj[methodName]();
	};
}

GoGlobal.prototype.Attach = function(obj, method, element, name) {
    var idx = method.indexOf('_');
    
    if (typeof(element)=="undefined")
        element = obj[method.substring(0, idx)];
    else if (typeof(element)=="string")
        element = document.getElementById(element);
        
    if (typeof(name)=="undefined") {
        if (idx<0)
            throw new GoError(GoError_InvalidArgument, "go.Attach: name "+method+" does not contain event name.");
        name = method.substr(idx+1).toLowerCase();
    }
    else if (name.substr(0, 2)=='on')
        name = name.substr(2);
        
    var handler = function(e) {
		var r = obj[method](new GoEvent(e, element));
		if (typeof(r)!='undefined') return r;
	};

    this.attachEvent(element, name, handler);
}

GoGlobal.prototype.attachEvent = function(element, name, handler) {
	if (element.attachEvent) {
		// MS registration model
		this.attachEvent = function(element, name, handler) { 
		    name = "on"+name;
		    element.attachEvent(name, handler); 
		};
	} 
	else if (element.addEventListener) {
		// NN (W4C) regisration model
		this.attachEvent = function(element, name, handler) { element.addEventListener(name, handler, false); };
	} 
	else {
		// old regisration model as fall-back
		this.attachEvent = function(element, name, handler) { element[name] = handler; };
	}
	this.attachEvent(element, name, handler);
}

GoGlobal.prototype.afterCallback = function() {
    for (var i = go.goControls.length; --i>=0;) {
        var e = document.getElementById(go.goControls[i]);
        if (typeof(e)!="undefined" && e!=null) {
            var attr = e.attributes["go_script"];
            if (typeof(attr)!="undefined" && attr!=null && attr.value!="") {
                eval(attr.value);
                attr.value = "";
            }
        }
    }
}

GoGlobal.prototype.addGoControl = function(name) {
    if (this.goControls==null) {
        this.goControls = [];
        if (typeof(Sys)!="undefined" && typeof(Sys.WebForms)!="undefined" && typeof(Sys.WebForms.PageRequestManager)!="undefined")
            Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(this.afterCallback);
    }
    
    for (var i = this.goControls.length; --i>=0;)
        if (this.goControls[i]==name)
            return;

    this.goControls.push(name);
}

GoGlobal.prototype.initScrollSizes = function() {
    var e = document.createElement("div");
    e.style.overflow = "scroll";
    e.style.position = "absolute";
    e.style.left = "-200px";
    e.style.top = "-200px";
    e.style.width = "100px";
    e.style.top = "100px";
    document.body.insertBefore(e, document.body.firstChild);
    this.ScrollWidth = e.offsetWidth - e.clientWidth;
    this.ScrollHeight = e.offsetHeight - e.clientHeight;
    if (this.IsIE8) {
        --this.ScrollHeight;
        this.ScrollWidth = this.ScrollHeight;
    }
    document.body.removeChild(e);
}

RegisterType("GoGlobal");

function GoGlobal() {   
    this.captureInitilized = false;
    this.captureEdit = null;
    this.IsCaptured = false;

    var agent = window.navigator.userAgent;
    this.IsSafari = agent.indexOf("Safari/")>=0;
    this.IsFirefox = agent.indexOf("Firefox/") >= 0;
    this.IsIE = agent.indexOf("MSIE") >= 0;
    if (typeof (ForceIE7Mode) == "undefined" || !ForceIE7Mode)
        this.IsIE8 = agent.indexOf("MSIE 8") >= 0 || agent.indexOf("MSIE 9") >= 0 || agent.indexOf("MSIE 10") >= 0;
    else
        this.IsIE8 = false;
    this.IsIE7 = this.IsIE && !this.IsIE8;
    this.IsNetscape = !this.IsIE && agent.indexOf("Netscape/")>=0;
    this.IsOpera = agent.indexOf("Opera") >= 0;
    this.IsChrome = agent.indexOf("Chrome") >= 0;
    this.lockEvent = 0;
    this.lockEventControl = null;
    this.goControls = null;
    this.initScrollSizes();
    
    this.Attach(this, "Window_MouseUp", window.document.body);
   
    return this;
}

if (typeof(go)=="undefined")
    go = new GoGlobal();

//
// ======================================================================
//

var GoError_InvalidOperation = 1;
var GoError_InvalidArgument = 2;
var GoError_IndexOutOfRange = 3;

GoError.prototype.GetDescription = function() {
    return this.description;
}

GoError.prototype.GetNumber = function() {
    return this.number;
}

RegisterType("GoError");

function GoError(number, description) {
    if (typeof(number)=="undefined")
        number = GoError_InvalidOperation;
    else if (typeof(number)=="string") {
        description = number;
        number = GoError_InvalidOperation;
    }
    
    this.number = number;
    if (typeof(description)=="undefined") {
        switch (number) {
            case GoError_InvalidArgument: this.description = "Invalid argument"; break;
            case GoError_IndexOutOfRange: this.description = "Index out of range"; break;
            default: this.description = "Invalid operation"; break;
        }
    }
    else
        this.description = description;
    return this;
}

//
// ======================================================================
//

GoPoint.prototype.calculateDistance = function(ele) {
    var offsetParent = ele;
    this.X += ele.scrollLeft;
    this.Y += ele.scrollTop;
    for (var e = ele; e != null; ) {
        if (offsetParent == e) {
            this.X -= e.offsetLeft;
            this.Y -= e.offsetTop;
            try {
                offsetParent = e.offsetParent;
            }
            catch (e) {
                offsetParent = null;
            }
        }
        if (e.tagName == "HTML") break;
        if (go.IsIE7) {
            this.X -= e.clientLeft;
            this.Y -= e.clientTop;
        }
        else if (go.IsFirefox) {
            this.X -= go.GetPx(e.style.borderLeftWidth);
            this.Y -= go.GetPx(e.style.borderTopWidth);
        }
        e = e.parentNode;
        if (e != null) {
            this.X += e.scrollLeft;
            this.Y += e.scrollTop;
        }
    }
}

GoPoint.prototype.toString = function() {
    return this.X+", "+this.Y;
}

GoPoint.prototype.Add = function(pt) {
    this.X += pt.X;
    this.Y += pt.Y;
}

GoPoint.prototype.Sub = function(pt) {
    this.X -= pt.X;
    this.Y -= pt.Y;
}

RegisterType("GoPoint");

function GoPoint(x, y) {
    if (typeof(x)=="undefined")
        this.X = this.Y = 0;
    else if (typeof(y) == "undefined") {
        this.X = this.Y = 0;
        this.calculateDistance(x);
        this.X = -this.X;
        this.Y = -this.Y;
    }
    else {
        this.X = x;
        this.Y = y;
    }
    return this;
}

//
// ======================================================================
//

GoEvent.prototype.CancelBubble = function() {
   this.e.cancelBubble = true;
}

GoEvent.prototype.SourceX = function() {
   return go.ClientX(this.Source);
}

GoEvent.prototype.SourceY = function() {
   return go.ClientY(this.Source);
}

GoEvent.prototype.SenderPt = function() {
    var pt;
    if (go.IsIE7)
        pt = new GoPoint(this.e.clientX-2, this.e.clientY-2);
    else
        pt = new GoPoint(this.e.clientX, this.e.clientY);
    pt.calculateDistance(this.Sender);
    return pt;
}

GoEvent.prototype.GetPt = function(ele) {
    var pt;
    if (go.IsIE7)
        pt = new GoPoint(this.e.clientX-2, this.e.clientY-2);
    else
        pt = new GoPoint(this.e.clientX, this.e.clientY);
    pt.calculateDistance(ele);
    return pt;
}

GoEvent.prototype.IsRightPressed = function() {
	if (this.e.which) return this.e.which == 3;
	return this.e.button == 2;
}

RegisterType("GoEvent");

function GoEvent(e, sender) {
    if (!e) 
        this.e = window.event;
    else
        this.e = e;
    this.X = this.e.clientX;
    this.Y = this.e.clientY;
    this.Pt = new GoPoint(this.X, this.Y);
    if (typeof(this.e.srcElement)=="undefined") {
        this.Source = this.e.target;
        if (this.e.relatedTarget!=null)
            this.ToElement = this.e.relatedTarget;
        else
            this.ToElement = this.e.currentTarget;
    }
    else {
        this.Source = this.e.srcElement;
        if (this.Source==null)
            this.Source = this.e.fromElement;
        this.ToElement = this.e.toElement;
    }
    this.Sender = sender;
    this.KeyCode = this.e.keyCode;
    this.DeltaX = this.DeltaY = -1000000;
    return this;
}

/*
*********************************************************************
* 
*       ComponentGo! Component Library
*
*       Copyright (c) ComponentGo!
*       ALL RIGHTS RESERVED
*
*********************************************************************
*/

RegionInfo.prototype.IsEmpty = function() {
    return this.data=="";
}

RegionInfo.prototype.EmitElement = function(html, tag, attrs, styles) {
    html.push("<"+tag);
    if (typeof(attrs)!="undefined" && attrs!=null)
        html.push(attrs);

    if (this.data=="") {
        if (typeof(styles)!="undefined" && styles!=null) {
            html.push("style=\"");
            html.push(styles);
            html.push("\"");
        }
    }
    else {
        var idx = this.data.indexOf('<');
        var idx2 = this.data.lastIndexOf('<', this.data.length-2);

        if (idx2-idx-1>0)
            html.push(this.data.substr(idx+1, idx2-idx-1));
          
        if (styles!=null || idx>0) {
            html.push("style=\"");
            if (styles!=null) {
                html.push(styles);
                if (idx>0)
                    html.push(";");
            }
            if (idx>0)
                html.push(this.data.substr(0, idx));
            html.push("\"");
        }
    }
    
    html.push(">");
}

RegionInfo.prototype.InitElement = function(control, element) {
    if (typeof(this.initMethod)=="undefined")
        this.initMethod = this.CompileInitializeElement();
    this.initMethod(control, element);
}

RegionInfo.prototype.CompileInitializeElement = function() {
    if (this.data=="")
        return function(control, element) {};
        
    var js = "";
    var idx = this.data.indexOf('<');
    var idx2 = this.data.lastIndexOf('<');

    if (idx>0) {
        var s = this.data.substr(0, idx);
        var t = s.split(";");
        for (var i = t.length; --i>=0;) {
            var j = t[i].indexOf(":");
            if (j>=0) {
                var ss = t[i].substr(0, j);
                var k = ss.indexOf("-");
                if (k>=0)
                    ss = ss.substr(0, k)+ss.substr(k+1, 1).toUpperCase()+ss.substr(k+2);
                js += "e.style."+ss+"=\""+t[i].substr(j+1)+"\";";
            }
        }
    }

    if (idx2-idx-1>0) {
        ++idx;
        while (idx<idx2) {
            var i = this.data.indexOf("=\"", idx);
            if (i<0) break;
            var j = this.data.indexOf('"', i+2);
            if (j<0) break;
            s = this.data.substring(i+2, j);
            if (this.data.substr(idx, 2)=="on") {
                s = go.HtmlAttributeDecode(s);
                js += "goc.attachEvent(e,\""+this.data.substring(idx+2, i)+"\",function(event){"+s+"});";
            }
            else {
                var name = this.data.substring(idx, i);
                if (name=="class") name = "className";
                js += "e."+name+"=\""+s+"\";";
            }
            idx = j+2;
        }
    }

    return new Function("goc", "e", js);
}

RegionInfo.prototype.get_TextAlign = function() {
    if (this.data=="") return null;
    var i = this.data.indexOf("text-align:");
    if (i<0) return null;
    var j = this.data.indexOf(";", i);
    return this.data.substring(i+11, j);
}

RegionInfo.prototype.get_BackgroundColor = function() {
    if (this.data=="") return null;
    var i = this.data.indexOf("background-color:");
    if (i<0) return null;
    var j = this.data.indexOf(";", i);
    return this.data.substring(i+11, j);
}

RegionInfo.prototype.Serial = function() { 
    return go.SerializeStr(this.data==null ? this.initMethod.toString() : this.data);
}


RegisterType("RegionInfo");

function RegionInfo(data) {
    if (typeof(data)=="undefined" || data==null || data=="") {
        this.data = "";
        this.initMethod = function(control, element) {};
    }
    else if (typeof(data)=="function") {
        this.data = null;
        this.initMethod = data;
    }
    else
        this.data = data;
}

var RegionInfo_Empty = new RegionInfo(null);


/*
*********************************************************************
* 
*       ComponentGo! Component Library
*
*       Copyright (c) ComponentGo!
*       ALL RIGHTS RESERVED
*
*********************************************************************
*/

//
// Events
//

GoControl.prototype.Refresh = function() {
    this.InvokeEvent("Refreshing");
}

GoControl.prototype.DoAction = function(name, argument) {
    this.InvokeNewEvent("Action", { Name: name, Argument: argument });
}

GoControl.prototype.callback = function(temp) {
    if (!this.removeCancelled()) return;
    if (this.postbackMode == PostbackMode.Always) {
        this.postback(temp);
        return;
    }
    if (go.lockEvent > 0) {
        if (this.lockEventState == 0)
            this.lockEventState = 1;
        go.lockEventControl = this;
    }
    else {
        var ele = document.getElementById(this.clientID + "_state");
        if (ele)
            ele.value = this.Serialize();

        //
        // Forces initializing internal variables for MS callback library
        //
        __theFormPostData = "";
        __theFormPostCollection = [];
        WebForm_InitCallback();

        this.LockEvent();
        go.duringPostback = true;
        this.callbackFn("");

        this.addProgress();

        if (this.callbackTimeout > 0) {
            var This = this;
            setTimeout(function() {
                if (go.duringPostback) {
                    go.duringPostback = false;
                    if (This.progressDiv) {
                        This.mainElement.removeChild(This.progressDiv);
                        This.progressDiv = null;
                    }
                    This.UnlockEvent();
                }
            },
                this.callbackTimeout);
        }
    }
}

GoControl.prototype.postback = function(temp) {
    if (!this.removeCancelled()) return;
    if (go.lockEvent > 0) {
        this.lockEventState = 2;
        go.lockEventControl = this;
    }
    else {
        this.LockEvent();
        go.duringPostback = true;
        this.addProgress();
        __doPostBack(this.uniqueID, "");
    }
}

GoControl.prototype.addProgress = function() {
    this.progressDiv = null;
    if (this.progressTimeout < 0) return;

    if (this.progressTimeout == 0) this.progressTimeout = 1;

    var This = this;
    setTimeout(function() {
        if (!go.duringPostback) return;
        This.progressDiv = document.createElement("DIV");
        This.progressDiv.style.position = "absolute";
        This.progressDiv.style.left = "0px";
        This.progressDiv.style.top = "0px";
        This.progressDiv.style.width = This.mainElement.offsetWidth + "px";
        This.progressDiv.style.height = This.mainElement.offsetHeight + "px";
        This.progressDiv.style.zIndex = 10000;
        var img = This.progressCode;
        if (img != null && img.substr(0, 1) != "!")
            This.progressDiv.innerHTML = img;
        else {
            if (img != null)
                img = img.substr(1);
            else
                img = '/Reserved.Go.axd?a=.&n=_Properties.Progress.gif&t=3.1.6.18723';
            This.progressDiv.style.backgroundColor = "white";
            This.progressDiv.style.backgroundPosition = "center center";
            This.progressDiv.style.backgroundRepeat = "no-repeat";
            This.progressDiv.style.backgroundImage = "url(" + img + ")";
            This.progressDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
            This.progressDiv.style["opacity"] = 0.5;
            This.progressDiv.style["-moz-opacity"] = 0.5;
        }
        This.mainElement.appendChild(This.progressDiv);
    }, this.progressTimeout);
}

GoControl.prototype.removeCancelled = function() {
    for (var i = this.eventsData.length - 1; i >= 0; i -= 2) {
        var args = this.eventsData[i];
        if (typeof (args) != "undefined" && typeof (args.Cancel) != "undefined" && args.Cancel)
            this.eventsData.splice(i-1, 2);
    }

    return this.eventsData.length>0;
}

GoControl.prototype.mouseE = function(name, action, cb) {
    this.InvokeNewEvent(name, { Action: action });
    var This = this;
    setTimeout(function() {
        if (cb)
            This.callback();
        else
            This.postback();
    }, 1);
}

GoControl.prototype.response = function(args, cx) {
    eval(args);
    go.duringPostback = false;
}

GoControl.prototype.InvokeEvent = function(name, args) {
    for (var i = this.eventsData.length-2; i>=0; i -= 2) {
        if (this.eventsData[i]==name) {
            this.eventsData.splice(i, 2);
            break;
        }
    }

    this.InvokeNewEvent(name, args)
}

GoControl.prototype.InvokeNewEvent = function(name, args) {
    if (!args || typeof(args.Cancel)=="undefined" || !args.Cancel) {
        this.eventsData.push(name);
        this.eventsData.push(args);
    }
    this.InvokeClientEvent(name, args);
}

GoControl.prototype.InvokeClientEvent = function(name, args) {
    if (this[name]!=null) {
        this.__eee = this[name];
        this.__eee(args);
    }
}

GoControl.prototype.LockEvent = function() {
    ++go.lockEvent;
}

GoControl.prototype.UnlockEvent = function() {
    if (--go.lockEvent<=0) {
        go.lockEvent = 0;
        if (this.lockEventState!=0) {
            var i = this.lockEventState;
            this.lockEventState = 0;
            go.lockEventControl = null;            
            if (i==1)
                this.callback();
            else if (i==2)
                this.postback();
        }
    } 
}

//
// Initialize
//

//
// Method is called only after callback.
//
GoControl.prototype.AfterSerializing = function() {
}

GoControl.prototype.OnCommit = function() {
    var ele = document.getElementById(this.clientID + "_state");
    if (ele)
        ele.value = this.Serialize();
}

GoControl.prototype.Attach = GoGlobal.prototype.Attach;

GoControl.prototype.attachEvent = function(element, name, handler) {
	if (element.attachEvent) {
		// MS registration model
		this.attachEvent = function(element, name, handler) { 
		    name = "on"+name;
            this.attached.push(element);
            this.attached.push(name);
            this.attached.push(handler);
		    element.attachEvent(name, handler); 
		};
	} 
	else if (element.addEventListener) {
		// NN (W4C) regisration model
		this.attachEvent = function(element, name, handler) { element.addEventListener(name, handler, false); };
	} 
	else {
		// old regisration model as fall-back
		this.attachEvent = function(element, name, handler) { element[name] = handler; };
	}
	this.attachEvent(element, name, handler);
}

GoControl.prototype.detachEvents = function() {
    if (this.attached.length>0) {
        for (var i = 0; i<this.attached.length; i += 3)
            this.attached[i].detachEvent(this.attached[i+1], this.attached[i+2]);
        this.attached = [];
    }
}

//
// Method is called only after load page into browser.
//
GoControl.prototype.Loaded = function(isCallback) {
    if (this.progressDiv) {
        this.mainElement.removeChild(this.progressDiv);
        this.progressDiv = null;
    }
    go.duringPostback = false;
    this.detachEvents();
    if (!isCallback) {
        this.mainElement = document.getElementById(this.clientID);
        if (typeof (this.clientID) != "undefined" && this.clientID != null)
            go.addGoControl(this.clientID);
        this.AfterSerializing();
    }

    if (this.mainElement != null) {
        this.saveElementWidth = this.mainElement.clientWidth;
        this.saveElementHeight = this.mainElement.clientHeight;
        this.Attach(this, "main_Resize", this.mainElement);

        if (this.mainElement.offsetWidth > 1 && this.mainElement.offsetHeight > 1 && this.Render == go.None)
            this.Render = this.__Render;
        this.Render();

        if (!isCallback) {
            if (go.IsIE) {
                if (this.RenderOnResize)
                    go.Attach(this, "mainElement_Resize", this.mainElement);
            }
            else {
                var This = this;
                setInterval(function() {
                if (This.mainElement.clientHeight>100)
                    if (This.saveElementWidth != This.mainElement.clientWidth || This.saveElementHeight != This.mainElement.clientHeight) {
                        This.saveElementWidth = This.mainElement.clientWidth;
                        This.saveElementHeight = This.mainElement.clientHeight;
                        if (This.RenderOnResize) {
                            This.detachEvents();
                            This.Render();
                        }
                        else
                            This.main_Resize(null);
                    }
                }, 1000);
            }
        }
    }
    this.UnlockEvent();
}

GoControl.prototype.RenderControl = function(mainElement) {
}

GoControl.prototype.mainElement_Resize = function(e) {
    if (this.Render == this.__Render) {
        if (this.saveElementWidth != this.mainElement.clientWidth || this.saveElementHeight != this.mainElement.clientHeight) {
            this.detachEvents();
            this.Render();
            this.saveElementWidth = this.mainElement.clientWidth;
            this.saveElementHeight = this.mainElement.clientHeight;
        }
    }
}

GoControl.prototype.main_Resize = function(e) {
    if (this.mainElement.offsetWidth > 1 && this.mainElement.offsetHeight > 1) {
        if (this.Render == go.None) {
            this.Render = this.__Render;
            this.Render();
        }
    }
    else
        this.Render = go.None;
        
    if (this.Render == this.__Render)
        this.ResizeControl();
}

GoControl.prototype.ResizeControl = function() {
}

GoControl.prototype.IsRenderingPossible = function() {
    return this.Render!=go.None;
}

GoControl.prototype.RenderInternal = function() {
    if (go.IsIE && this.RenderDoubleBuffer) {
        if (this.mainElement.style.position=="" || this.mainElement.style.position=="static") {
            this.mainElement.style.position = "relative";
            this.mainElement.style.left = "0px";
            this.mainElement.style.top = "0px";
        }

        var div = document.createElement("DIV");
        div.style.position = "absolute";
        div.style.left = "0px";
        div.style.top = "0px";
        div.style.zIndex = -1;
        this.mainElement.appendChild(div);
        this.RenderControl(div);

        if (typeof(this.renderDiv)!="undefined")
            this.mainElement.removeChild(this.renderDiv);
        this.renderDiv = div;
        div.style.zIndex = 0;
    }
    else
        this.RenderControl(this.mainElement);
}

GoControl.prototype.__Render = function() {
    if (typeof (GOTEST) != "undefined") {
        this.Render = function() { };
        this.RenderInternal();
        this.Render = this.__Render;
    }
    else {
        try {
            this.Render = function() { };
            this.RenderInternal();
        }
        finally {
            this.Render = this.__Render;
        }
    }
}

GoControl.prototype.get_CallbackTimeout = function() {
    return this.callbackTimeout;
}

GoControl.prototype.get_MainElement = function() {
    return this.mainElement;
}

RegisterType("GoControl");

function GoControl() {
    this.mainElement = null;
    this.lockEventState = 0;
    this.attached = [];
    this.eventsData = [];
    this.Render = go.None;
    this.RenderOnResize = false;
    this.RenderDoubleBuffer = false;
}

/*
*********************************************************************
* 
*       ComponentGo! Component Library
*
*       Copyright (c) ComponentGo!
*       ALL RIGHTS RESERVED
*
*********************************************************************
*/

ContextMenuBox.prototype.Clear = function() {
    this.items = [];
    this.rebuild();
}

ContextMenuBox.prototype.AddItem = function(name) {
    var it = new MenuActionItem();
    it.text = name;
    it.parent = this;
    it.enabled = true;
    it.commandName = "";
    it.commandArgument = "";
    this.items.push(it);
    this.rebuild();
    return it;
}

ContextMenuBox.prototype.AddSeparator = function() {
    var it = new MenuSeparatorItem();
    it.text = "-";
    it.parent = this;
    this.items.push(it);
    this.rebuild();
}

ContextMenuBox.prototype.SetEnabled = function(v) {
    this.set_Enabled(v);
}

ContextMenuBox.prototype.Show = function(x, y, parent) {
    var args = { Cancel: false };
    this.InvokeClientEvent("MenuActivate", args);
    if (args.Cancel) return;

    if (this.mainElement==null) {
        this.mainElement = document.createElement("TABLE");
        if (typeof(parent)!="undefined")
            this.InitStyleParent(parent);
        this.StartAppearTimer(20);
        document.body.appendChild(this.mainElement);
        this.mainElement.insertRow(0).insertCell(0);
        this.mainElement.style.border = this.BorderColor+" 1px solid";
        this.mainElement.style.width = "auto";
        if (this.menuStyle!=MenuBoxStyle.None) {
            var img = document.getElementById("go_menu24box_"+(this.menuStyle==MenuBoxStyle.Blue ? "Blue" : "Gray"));
            this.mainElement.style.backgroundImage = "url("+img.src+")";
            this.mainElement.style.backgroundRepeat = "repeat-y";
            this.mainElement.style.backgroundColor = "white";
        }
        this.mainElement.cellPadding = 0;

    }
    else
        this.StartAppearTimer(20);

    var td = this.mainElement.rows[0].cells[0];
    if (td.innerHTML.indexOf('<')<0)
        td.innerHTML = this.RenderMenu();

    if (typeof(x)!="undefined") {
        if (typeof(x)=="string")
            x = document.getElementById(x);
        if (typeof(x)!="number") {
            var pt = new GoPoint(x.offsetWidth/2, x.offsetHeight/2);
            pt.calculateDistance(document.body);
            var pt2 = new GoPoint(0, 0);
            pt2.calculateDistance(x);
            pt.Sub(pt2);
            x = pt.X; y = pt.Y;
        }
        this.mainElement.style.left = x+"px";
        this.mainElement.style.top = y+"px";
        this.mainElement.style.position = "absolute";
        this.mainElement.style.zIndex = 32000;
    }
    
    if (!this.Permanent && typeof(x)=="number") {
        x += document.body.offsetLeft;
        y += document.body.offsetTop;
        var screenW = document.documentElement.offsetWidth-5;
        var screenH = document.documentElement.offsetHeight-5;
        if (x+this.mainElement.offsetWidth-document.documentElement.scrollLeft>screenW) 
            x -= this.mainElement.offsetWidth;
        if (x<document.documentElement.scrollLeft) 
            x = document.documentElement.scrollLeft;
        if (y+this.mainElement.offsetHeight-document.documentElement.scrollTop>screenH) 
            y -= this.mainElement.offsetHeight;
        if (y<document.documentElement.scrollTop) 
            y = document.documentElement.scrollTop;
        this.mainElement.style.left = x+"px";
        this.mainElement.style.top = y+"px";
    }

    gomenu.eatCapture = this;
    setTimeout(function() {  gomenu.eatCapture = null; }, 300);
        
    this.mainElement.style.visibility = "visible";
    this.Visible = true;
    gomenu.captured.push(this);
    this.AssignMain();
    this.attachEvents();
}

ContextMenuBox.prototype.rebuild = function() {
    if (this.mainElement!=null) {
        var td = this.mainElement.rows[0].cells[0];
        td.innerHTML = "";
        this.table = null;
    }
}

ContextMenuBox.prototype.attachEvents = function() {
    if (this.wasEventAttached) return;
    this.wasEventAttached = true;
    this.Attach(this, "ContextMenu_MouseOut", this.mainElement);
    this.Attach(this, "ContextMenu_MouseMove", this.mainElement);
    this.Attach(this, "ContextMenu_Click", this.mainElement);
    this.Attach(this, "ContextMenu_Click", this.mainElement, "oncontextmenu");
}

ContextMenuBox.prototype.ShowForEvent = function(e, t) {
    this.Linked_ContextMenu(new GoEvent(e, t));
}

ContextMenuBox.prototype.Hide = function() {
    if (!this.Permanent) {
        if (this.Visible) {
            this.Visible = false;
            for (var i = this.items.length; --i>=0;)
                this.items[i].Hide();
            if (this.get_Appearable())
                this.StartAppearTimer(-50);
            else
                this.mainElement.style.visibility = "hidden";
        }
    }
    this.SetSelect(-1, true);
}

ContextMenuBox.prototype.Linked_ContextMenu = function(e) {
    e.CancelBubble();

    var pt = e.GetPt(document.body);
    this.Show(pt.X, pt.Y);

    // It prevent show standard context menu in FireFox
    if (e.e.preventDefault)
        e.e.preventDefault(); 
        
    go.ReleaseCapture();
    go.ReleaseEdit();

    return false;
}

ContextMenuBox.prototype.StartAppearTimer = function(delta) {
    if (this.get_Appearable()) {
        this.appearDelta = delta;
        if (this.appearTimer==null) {
            this.Appear_Timer();
            this.appearTimer = setInterval(this.appearDelegate, 30);
        }
    }
}

ContextMenuBox.prototype.Appear_Timer = function() {
    this.appearOpaque += this.appearDelta;
    if (this.appearOpaque>=100) {
        this.appearOpaque = 100;
        this.mainElement.style.filter = "";
    }
    else if (this.appearOpaque<=0) {
        this.appearOpaque = 0;
        this.mainElement.style.filter = "";
        this.mainElement.style.visibility = "hidden";
    }
    else {
        this.mainElement.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity="+this.appearOpaque+",Style=0)";
        return;
    }
    clearInterval(this.appearTimer);
    this.appearTimer = null; 
}

ContextMenuBox.prototype.AssignMain = function() {
    this.mainElement.Obj = this;
    if (this.mainElement.rows.length>0 && this.table==null) {
        this.table = this.mainElement.rows[0].cells[0].getElementsByTagName("TABLE")[0];
        if (this.table!=null)
            this.SetSelect(-1, true);
    }
}

ContextMenuBox.prototype.RenderMenu = function() {
    var html = [];
    html.push("<table style=\"cursor: default;");
    if (this.font!=null)
        html.push(this.font);
    html.push("\" border=0 cellpadding=3 cellspacing=0>");
    if (this.horizontal) {
        html.push("<tr>");
        for (var i = 0; i<this.items.length; ++i)
            this.items[i].RenderItemH(html);
        html.push("</tr>");
    }
    else {
        for (var i = 0; i<this.items.length; ++i)
            this.items[i].RenderItem(html);
    }
    html.push("</table>");
    return html.join(" ");
}

ContextMenuBox.prototype.RenderItem = function(html) {
    html.push("<tr>");
    if (this.text!="-") {
        html.push("<td");
        var img = this.get_ImageUrl();
        if (typeof(img)!="undefined" && img!=null)
            html.push("style=\"background-image: url("+img+"); background-repeat: no-repeat; background-position: 2px center;\"");
        html.push("><div style=\"width:20px;\"></div></td><td><nobr>");
        html.push(this.text);
        html.push("</nobr></td><td>");
        if (this.key!=null)
            html.push(this.key);
        html.push("&nbsp;</td><td>");
        if (this.items.length>0)
            html.push("<img src=/Reserved.Go.axd?a=P&n=arr&p=rt|4|7|black&t=3.1.6.18723>");
        else
            html.push("&nbsp;");
        html.push("</td>");
    }
    else {
        html.push("<td><div style=\"width:20px; height:1px; overflow: hidden;\"></div></td>");
        html.push("<td colspan=3><div style=\"height:1px; overflow: hidden; background-color: lightgrey;\"></div></td>");
    }
    html.push("</tr>");
}

ContextMenuBox.prototype.RenderItemH = function(html) {
    html.push("<td><nobr>&nbsp;"+this.text+"&nbsp;</nobr></td>");
}

ContextMenuBox.prototype.ContextMenu_MouseMove = function(e) {
    var tr = e.Source;
    var s = this.horizontal ? "TD" : "TR";
    while (tr!=null && tr.tagName!=s) tr = tr.parentNode;
    if (tr==null) return;

    this.SetSelect(this.FindIndex(tr), false);
}

ContextMenuBox.prototype.Delayed = function() {
    this.delayedHandle = -1;
    if (!this.Visible) return;

    var isVisible = false;        
    for (var i = this.items.length; --i>=0;)
        if (this.items[i].Visible)
            isVisible = true;
            
    for (var i = this.items.length; --i>=0;) {
        var it = this.items[i];
        if (it.Visible && i!=this.SelectedIndex)
            it.Hide();
        else if (this.Visible && (isVisible || !this.Permanent) 
            && !it.Visible && i==this.SelectedIndex && it.items.length>0)
            it.Click(this, i, null);
    } 
}

ContextMenuBox.prototype.ContextMenu_MouseOut = function(e) {
    if (e.ToElement!=null && e.ToElement.tagName=="TABLE") {
        for (var i = this.items.length; --i>=0;)
            if (this.items[i].Visible)
                return;
        this.SetSelect(-1, false);
    }
}

ContextMenuBox.prototype.FindIndex = function(ele) {
    if (this.horizontal) {
        while (ele!=null && ele.tagName!="TD") ele = ele.parentNode;
        if (ele!=null) 
            for (var i = this.items.length; --i>=0; )
                if (this.items[i].enabled && this.table.rows[0].cells[i]==ele)
                    return i;
    }
    else {
        while (ele!=null && ele.tagName!="TR") ele = ele.parentNode;
        if (ele!=null) 
            for (var i = this.items.length; --i>=0; )
                if (this.items[i].enabled && this.table.rows[i]==ele)
                    return i;
    }
    return -1;
}

ContextMenuBox.prototype.ContextMenu_Click = function(e) {
    var i = this.FindIndex(e.Source);
    if (i>=0)
        this.items[i].Click(this, i, e);
    return false;
}

ContextMenuBox.prototype.Click = function(sender, i, e) {
    if (this.items.length==0) {
        gomenu.captureOff();
        
        if (this.navigateUrl!=null) {
            var s = this.get_Target();
            if (s==null || s=="")
                s = "_self";
            window.open(this.get_NavigateUrl(), s);
        }
        
        else if (this.onClientAction!=null)
            this.onClientAction();
            
        else 
            this.InvokeCommand();
    }
    else {
        if (this.Visible)
            this.Hide();
        else {
            var x = 0;
            var y = 0;
            if (typeof(sender)=="object" && sender.ClassName=="MenuBox") {
                if (sender.horizontal) {
                    var td = sender.table.rows[0].cells[i];
                    var pt = new GoPoint(0, td.clientHeight + 1);
                    pt.calculateDistance(document.body);
                    var pt2 = new GoPoint(0, 0);
                    pt2.calculateDistance(td);
                    pt.Sub(pt2);
                    x = pt.X; y = pt.Y;
                }
                else {
                    var tr = sender.table.rows[i];
                    var pt = go.IsIE8 ? new GoPoint(tr.offsetWidth + 2, 0) : new GoPoint(tr.clientWidth + 2, 0);
                    pt.calculateDistance(document.body);
                    var pt2 = new GoPoint(0, 0);
                    pt2.calculateDistance(tr);
                    pt.Sub(pt2);
                    x = pt.X; y = pt.Y;
                }
            }
            this.Show(x, y, sender);
        }
        sender.SetSelect(sender.SelectedIndex, true);
    }
}

ContextMenuBox.prototype.SetSelect = function(selidx, force) {
    if (selidx>=0 && !force) {
        if (this.parent!=null) {
            for (var i = this.parent.items.length; --i>=0;) {
                if (this.parent.items[i]==this) {
                    this.parent.SetSelect(i, false);
                    break;
                } 
            }
        }
    }
        
    if (!force && selidx==this.SelectedIndex) return;
    
    if (this.delayedHandle!=-1)
        clearTimeout(this.delayedHandle);
    if (this.Visible) {
        var time = 1;
        if (!this.horizontal && selidx>=0) {
            var items = this.items[selidx].items;
            if (items && items!=null && items.length>0)
                time = 100;
            else
                time = 500;
        }
        this.delayedHandle = setTimeout(go.Delegate(this, "Delayed"), time);
    }
    else
        this.delayedHandle = -1;
    
    if (this.text=="-" || this.items.length==0 || this.table==null) return;

    this.SelectedIndex = selidx;
    if (this.horizontal) {
        var subVisible = false;
        var cells = this.table.rows[0].cells;
        for (var j = 0; j<this.items.length; ++j) 
            if (this.items[j].Visible)
                subVisible = true;
        for (var j = 0; j<cells.length; ++j) {
            var tc = cells[j];
            var border;
            if (j==selidx) {
                this.SelectedIndex = j;
                if (subVisible) {
                    tc.style.backgroundColor = this.SelBk2Color;
                    border = this.SelFrame2Color+" 1px solid";
                }
                else {
                    tc.style.backgroundColor = this.SelBkColor;
                    border = this.SelFrameColor+" 1px solid";
                }
            }
            else {
                border = this.FrameColor+" 1px solid";
                tc.style.backgroundColor = "";
            }
            if (!this.items[j].enabled)
                tc.style.color = "silver";
            tc.style.borderLeft = border;
            tc.style.borderRight = border;
            tc.style.borderTop = border;
            tc.style.borderBottom = border;
        }
    }
    else {
        for (var i = 0; i<this.table.rows.length; ++i) {
            var tr = this.table.rows[i];
            if (tr.cells.length>2) {
                var nobr = tr.cells[1].getElementsByTagName("nobr")[0];
                if (nobr!=null && nobr.innerHTML!=this.items[i].text)
                    nobr.innerHTML = this.items[i].text;
                for (var j = 0; j<tr.cells.length; ++j) {
                    var tc = tr.cells[j];
                    var border;
                    if (i==selidx) {
                        this.SelectedIndex = i;
                        borderM = this.SelFrameColor+" 1px solid";
                        border = this.SelFrameColor+" 1px solid";
                        tc.style.backgroundColor = this.SelBkColor;
                    }
                    else {
                        borderM = this.MarginColor+" 1px solid";
                        border = "white 1px solid";
                        tc.style.backgroundColor = "";
                    }
                    if (j==0)
                        tc.style.borderLeft = borderM;
                    if (j==3)
                        tc.style.borderRight = border;
                    if (i!=selidx && j==0) border = "";
                    if (!this.items[i].enabled && (j==1 || j==2))
                        tc.style.color = "silver";
                    else
                        tc.style.color = "";
                    tc.style.borderTop = border;
                    tc.style.borderBottom = border;
                }
            }
        }
    }
}




ContextMenuBox.prototype.attachItems = function() {
    if (typeof(this.subItems)!="undefined") this.items = this.subItems;
    if (typeof(this.items)=="undefined") 
        this.items = [];
    else {
        for (var i = this.items.length; --i>=0;) {
            this.items[i].parent = this;
            this.items[i].attachItems();
        }
    }
}

ContextMenuBox.prototype.InitStyleParent = function(parent) {
    this.menuStyle = parent.menuStyle;
    this.appearable = parent.appearable;
    this.backColor = parent.backColor;
    this.font = parent.font;

    this.mainElement.style.fontFamily = parent.mainElement.style.fontFamily;
    this.mainElement.style.fontSize = parent.mainElement.style.fontSize;
    this.BorderColor = parent.BorderColor;
    this.BkColor = parent.BkColor;
    this.MarginColor = parent.MarginColor;
    this.FrameColor = parent.FrameColor;
    this.SelBkColor = parent.SelBkColor;
    this.SelBk2Color = parent.SelBk2Color;
    this.SelFrameColor = parent.SelFrameColor;
    this.SelFrame2Color = parent.SelFrame2Color;
}

ContextMenuBox.prototype.Loaded = function(isCallback) {
    this.wasEventAttached = false;
    this.rebuild();
    this.GoControl_Loaded(isCallback);
    if (!isCallback) {
        this.Permanent = this.mainElement!=null;
		switch (this.menuStyle) {
			case MenuBoxStyle.Blue:
                this.BorderColor = "navy";
                this.MarginColor = "#cbddf6";
                this.FrameColor = this.backColor;
                this.SelBkColor = "#ffeec2";
                this.SelBk2Color = "#deebfd";
                this.SelFrameColor = "#000080";
                this.SelFrame2Color = "#000080";
				break;
			case MenuBoxStyle.Gray:
                this.BorderColor = "gray";
                this.MarginColor = "#fefefb";
                this.FrameColor = this.backColor;
                this.SelBkColor = "#ccccff";
                this.SelBk2Color = "white";
                this.SelFrameColor = "#0000cc";
                this.SelFrame2Color = "gray";
				break;
			default:
                this.BorderColor = "gray";
                this.MarginColor = "#fefefb";
                this.FrameColor = "white";
                this.SelBkColor = "#ccccff";
                this.SelBk2Color = "white";
                this.SelFrameColor = "#0000cc";
                this.SelFrame2Color = "gray";
				break;
		}
		if (this.linkedControlID!=null)
            this.Attach(this, "Linked_ContextMenu", this.linkedControlID);
    }
    this.attachItems();
}

//
// Properties
//

ContextMenuBox.prototype.get_Appearable = function() {
    return this.appearable && go.IsIE;
}

ContextMenuBox.prototype.get_MenuStyle = function() {
    return this.menuStyle;
}

ContextMenuBox.prototype.get_Horizontal = function() {
    return this.horizontal;
}

ContextMenuBox.prototype.get_Items = function() {
    return this.items;
}

RegisterType("ContextMenuBox", "GoControl");

function ContextMenuBox() {
    this.GoControl();
    //
    // Public properties
    //
    this.Visible = false;
    //
    // Private properties
    //
    this.ClassName = "MenuBox";
    this.table = null;
    this.parent = null;
    this.delayedHandle = -1;
    this.SelectedIndex = -1;
    this.appearDelegate = go.Delegate(this, "Appear_Timer");
    this.appearTimer = null;
    this.appearOpaque = 0;
    this.appearDelta = 0;
    this.wasEventAttached = false;
    return this;
}

//
// MenuBox
//

MenuBox.prototype.Loaded = function(isCallback) {
    this.ContextMenuBox_Loaded(isCallback);
    if (!isCallback) {
        if (this.Permanent)
            this.AssignMain();
        this.Show();
    }
}

RegisterType("MenuBox", "ContextMenuBox");

function MenuBox() {
    this.ContextMenuBox();
    return this;
}





MenuBoxItem.prototype.get_Menu = function() {
    var menu = this; 
    while (menu.parent!=null)
        menu = menu.parent;
    return menu;
}

RegisterType("MenuBoxItem", "ContextMenuBox");

function MenuBoxItem() {
    this.ContextMenuBox();
    return this;
}

//
// MenuActionItem
//

MenuActionItem.prototype.get_SubItems = function() {
    return this.subItems;
}

MenuActionItem.prototype.get_Text = function() {
    return this.text;
}

MenuActionItem.prototype.set_Text = function(v) {
    if (this.text==v) return;
    this.text = v;
    if (this.parent!=null && this.parent.Visible)
        this.parent.SetSelect(this.parent.SelectedIndex, true);
    else
        this.parent.rebuild();
}

MenuActionItem.prototype.get_Key = function() {
    return this.key;
}

MenuActionItem.prototype.set_Key = function(v) {
    if (this.key==v) return;
    this.key = v;
    if (this.parent!=null)
        this.parent.SetSelect(this.parent.SelectedIndex, true);
}

MenuActionItem.prototype.get_Enabled = function() {
    return this.enabled;
}

MenuActionItem.prototype.set_Enabled = function(v) {
    if (this.enabled==v) return;
    this.enabled = v;
    if (this.parent!=null && this.parent.Visible)
        this.parent.SetSelect(this.parent.SelectedIndex, true);
    else
        this.parent.rebuild();
}

MenuActionItem.prototype.get_ImageUrl = function() {
    if (this.imageUrl==null) return null;
    var i = this.imageUrl.indexOf("|@");
    return i>=0 ? this.imageUrl.substr(0, i) : this.imageUrl;
}

MenuActionItem.prototype.set_ImageUrl = function(v) {
    this.imageUrl = v;
    if (this.parent!=null)
        this.parent.rebuild();
}

MenuActionItem.prototype.get_NavigateUrl = function() {
    if (this.navigateUrl==null) return null;
    var i = this.navigateUrl.indexOf("|@");
    return i>=0 ? this.navigateUrl.substr(0, i) : this.navigateUrl;
}

MenuActionItem.prototype.set_NavigateUrl = function(v) {
    this.navigateUrl = v;
}

MenuActionItem.prototype.get_Target = function() {
    return this.target;
}

MenuActionItem.prototype.set_Target = function(v) {
    this.target = v;
}

MenuActionItem.prototype.get_CommandName = function() {
    return this.commandName;
}

MenuActionItem.prototype.set_CommandName = function(v) {
    this.commandName = v;
}

MenuActionItem.prototype.get_CommandArgument = function() {
    return this.commandArgument;
}

MenuActionItem.prototype.set_CommandArgument = function(v) {
    this.commandArgument = v;
}

MenuActionItem.prototype.InvokeCommand = function() {
    this.get_Menu().InvokeNewEvent("Command", {
        Name: this.get_CommandName(), 
        Argument: this.get_CommandArgument(),
        Cancel: false});
}

RegisterType("MenuActionItem", "MenuBoxItem");

function MenuActionItem() {
    this.MenuBoxItem();
    this.items = [];
    return this;
}

RegisterType("MenuSeparatorItem", "MenuBoxItem");

function MenuSeparatorItem() {
    this.MenuBoxItem();
    this.text = "-";
    return this;
}













//
// =====================================================================
//

//
// Gets object supported daily calendar functionallity for specified
// tag (element parameter).
//
MenuBoxClass_Ctor.prototype.Get = function(element) {
    if (element.ClassName=="MenuBox")
        return element;

    if (typeof(element)=="string")
        element = document.getElementById(element);
    if (typeof(element.className)=="undefined") 
        return null;
    while (typeof(element.Obj)=="undefined" || element.Obj.ClassName!="MenuBox") {
        element = element.parentNode;
        if (typeof(element.className)=="undefined") return null;
    }
    return element.Obj;
}

MenuBoxClass_Ctor.prototype.checkEat = function(m) {
    if (m==this.eatCapture) return true;
    if (m.text!="-")
        for (var i = m.items.length; --i>=0;)
            if (this.checkEat(m.items[i]))
                return true;
    return false;
}

MenuBoxClass_Ctor.prototype.captureOff = function() {
    for (var i = this.current.length; --i>=0; )
        if (!this.checkEat(this.current[i]) && this.current[i].mainElement.parentNode!=null)
            this.current[i].Hide();
    var old = this.captured;
    this.captured = [];
    for (var i = 0; i<old.length; ++i)
        if (old[i].Visible && old[i].mainElement.parentNode!=null)
            this.captured.push(old[i]);
    this.eatCapture = null;
}

MenuBoxClass_Ctor.prototype.DoMouseUp = function() {
    setTimeout(function() {  
        gomenu.current = [];
        for (var i = 0; i<gomenu.captured.length; ++i)
            gomenu.current.push(gomenu.captured[i]);
        gomenu.captureOff();
    }, 100);
} 

function MenuBoxClass_Ctor() {
    this.ClassName = "MenuBoxClass";
    this.captured = [];
    this.current = this.captured;
    this.eatCapture = null;
    return this;
}

if (typeof(gomenu)=="undefined")
    gomenu = new MenuBoxClass_Ctor();


