﻿if( ! window.addNamespace ) 
{
	window.addNamespace = function(ns) 	
	{
		var nsParts = ns.split(".");
		var root = window;

		for (var i=0;i<nsParts.length;i++) 		
		{
			if (root[nsParts[i]] == undefined) 
			{
				root[nsParts[i]] = {};
			}
			root = root[nsParts[i]];
		}
	}
}

addNamespace("Common");

// Browser related members
addNamespace("Common.Browser");

Common.Browser.isIE = document.all;

Common.Browser.isIE7 = navigator.appVersion.indexOf("MSIE 7") > -1;

// Debug
addNamespace("Common.Debug");

Common.Debug.enabled = true;
Common.Debug.trace = function(s) {}

Common.Debug.Trace = function(s, o)
{
    if (Common.Debug.enabled)
    {
        var src = "";
        try
        {
            if (o != null)
            {
                src = o.toString();
            }
            Common.Debug.TraceWindow().innerHTML += "<div style=\"border-bottom: 1px solid orange;cursor:pointer\"><textarea style=\"width:370px;height:50px;border:none\">" + s + "</textarea></div><div>" + src + "</div>";
        }
        catch(e)
        {
            window.status = "Error in trace: " + e.description;
        }
    }
}

Common.Debug._window = null;

Common.Debug.TraceWindow = function(s)
{
    if (!Common.IsDefined(Common.Debug._window))
    {
        try
        {
            Common.Debug._window = window.open("debug.htm", "debugwindow", "scrollbars=yes width=400 height=600"); 
        }
        catch(e)
        {}
        if (Common.Debug._window != null)
        {
            Common.Debug._window.document.open();// open the window document for input; 
            Common.Debug._window.document.write("<html><head><title>Debug Popup</title></head><body><div id=\"debugDiv\" style=\"font-size:8pt\">"); 
            Common.Debug._window.document.write("</body></html>"); 
            Common.Debug._window.document.close(); //closes the stream 
            Common.Debug._window = Common.Debug._window.document.getElementById("debugDiv");
        }
        else
        {
            Common.Debug._window = document.createElement("DIV");
            Common.Debug._window.style.position = "absolute";
            Common.Debug._window.style.backgroundColor = "white";
            Common.Debug._window.style.top = "0px";
            Common.Debug._window.style.left = (Common.GetClientWidth() - 200) + "px";
            Common.Debug._window.style.width = "200px";
            Common.Debug._window.style.height = "100px";
            Common.Debug._window.style.overflow = "auto";
            Common.SetOpacity(Common.Debug._window, 7);
            Common.Debug._window = document.body.appendChild(Common.Debug._window);
        }
        Common.Debug.AddToolbar();
    }
    return Common.Debug._window;
}

Common.Debug.AddToolbar = function()
{
    Common.Debug._window.innerHTML += "<input type='button' value='clear' onclick=\"parentElement.innerHTML='';\"></input>";
}

Common.Debug.ShowFormContents = function()
{
    var s = "";
    var formElements = document.forms[0].elements;
    for(var i=0;i<formElements.length;i++) 
    {
        s += formElements[i].name + ": " + formElements[i].value + "<br />";
    }
    Common.Debug.Trace(s);
}

Common.HideSelects = function()
{
    var arrCombo = document.getElementsByTagName("select");
    for (var i=0;i<arrCombo.length;i++)
    {
        arrCombo[i].style.visibility = "hidden";
    }
}

Common.ShowSelects = function()
{
    var arrCombo = document.getElementsByTagName("select");
    for (var i=0;i<arrCombo.length;i++)
    {
        arrCombo[i].style.visibility = "inherit";
    }
}

Common.StatusWin = null;

Common.SetStatus = function(s, rel)
{
    if (Common.StatusWin == null)
    {
        Common.CreateStatusWin();   
    }
    
    if (Common.StatusWin.clearTimer != null)
    {
        clearTimeout(Common.StatusWin.clearTimer);
    }
        
    if (s.length == 0)
    {
        Common.StatusWin.clearTimer = setTimeout("Common.SetHidden(Common.StatusWin)",20);
    }
    else
    {
        Common.StatusWin._innerHTML = s;
        Common.StatusWin.rel = rel;
        Common.StatusWin.timer = setTimeout("Common._SetStatus()",0);
    }
}

Common.StatusReady = function()
{
    var callbacks = false;
    if (typeof(__pendingCallbacks) != "undefined")
    {
        for (var i=0;i<__pendingCallbacks.length;i++)
        {
            var callbackObject = __pendingCallbacks[i];
            if (callbackObject && callbackObject.xmlRequest && (callbackObject.xmlRequest.readyState != 4))
            {
                callbacks = true;
                break;
            }
        }
    }
    return (!callbacks) && (Common.StatusWin == null || Common.StatusWin.style.visibility == "hidden");
}

Common.CreateStatusWin = function()
{
    Common.StatusWin = document.createElement("DIV");
    Common.StatusWin.id = "Common.StatusWin";
    Common.StatusWin.className = "statusWin";
    Common.SetHidden(Common.StatusWin);
    document.body.appendChild(Common.StatusWin);
    Common.SetOpacity(Common.StatusWin, 8);
}

Common._SetStatus = function(s)
{
    Common.StatusWin.innerHTML = Common.StatusWin._innerHTML;
    Common.SetVisible(Common.StatusWin);
    Common.MoveCenter(Common.StatusWin, Common.StatusWin.rel);
    Common.SetMaxZIndex(Common.StatusWin);
}

Common.FlashWindow = null;

Common.FlashNotify = function(text)
{
    if (!Common.IsDefined(Common.FlashWindow))
    {
        var win = document.createElement("DIV");
        win.className = "flashStatus";
        win.id = "Common.FlashWindow";
        Common.FlashWindow = document.forms[0].appendChild(win);
    }
    Common.FlashWindow.text = text;
    Common._FlashNotify()
}

Common._FlashNotify = function()
{
    Common.FlashWindow.innerHTML = Common.FlashWindow.text;
    Common.SetVisible(Common.FlashWindow);
    Common.MoveCenter(Common.FlashWindow);
    Common.SetOpacity(Common.FlashWindow, 10);
    Common.SetMaxZIndex(Common.FlashWindow);
    if (Common.StatusWin != null)
    {
        Common.SetHidden(Common.StatusWin);
    }
    setTimeout("Common.FadeOut(Common.FlashWindow)", 1000);
}

Common.MoveCenter = function(e, rel)
{
    if (rel == null)
    {
        var sLeft = Common.ScrollLeft();
        var sTop = Common.ScrollTop();
        Common.MoveTo(e, Math.max(sLeft + (Common.GetClientWidth() / 2) - Math.max((Common.GetWidth(e), e.scrollWidth) / 2),sLeft), Math.max(sTop + (Common.GetClientHeight() / 2) - (Common.GetHeight(e) / 2),sTop));
    }
    else
    {
        var pos = Common.GetXY(rel);
        Common.MoveTo(e, Math.max(pos[0] + (Common.GetWidth(rel) / 2) - (Common.GetWidth(e) / 2),0), Math.max(pos[1] + (Common.GetHeight(rel) / 2) - (Common.GetHeight(e) / 2),0));
    }
}

Common.Box = function()
{
    this.left = 0;
    this.top = 0;
}

Common.NameValueCollection = function()
{
    this.KeyNames = new Array();
    this.KeyValues = new Array();
    
    this.GetValue = function(Key)
    {
        var i = this.GetIndex(Key);
        if (i >= 0)
        {
            return this.KeyValues[i];
        }
        return null;
    }
    
    this.SetValue = function(Key, Value)
    {
        var i = this.GetIndex(Key);
        if (i == -1)
        {
            this.KeyNames.push(Key);
            this.KeyValues.push(Value);
        }
        else
        {
            this.KeyValues[i] = Value;
        }     
    }
    
    this.GetIndex = function(Key)
    {
        for (var i=0;i<this.KeyNames.length;i++)
        {
            if (this.KeyNames[i] == Key)
            {
                return i;
            }
        }
        return -1;
    }
}

Common.GetParent = function()
{
    var element = arguments[0];
    
    if (Common.IsDefined(element.offsetParent))
    {
        return element.offsetParent;
    }
    else if(Common.IsDefined(element.parentNode))
    {
        return element.parentNode; 
    }
    else if (Common.IsDefined(element.parentElement))
    {
        return element.parentElement;
    }
    return null;
}

Common.IsDefined = function()
{
    for (var i=0;i<arguments.length;i++)
    {
        if (arguments[i] == null || typeof(arguments[i]) == 'undefined')
        {
            return false;
        }
    }
    return true;
}

Common.GetElement = function ()
{
    var e = arguments[0];

    if (!Common.IsString(e)) 
    {
        return e;
    }
    if (document.getElementById)
    {
        e = document.getElementById(e);
    }
    else if(document.all) 
    {
        e = document.all[e];
    }
    else 
    {
        e = null;
    }
    return e;
}

Common.IsNumber = function()
{
    for(var i=0; i<arguments.length; ++i)
    {
        if(parseInt(arguments[i]) != arguments[i]) 
        {
            return false;
        }
    }
    return true;
}


Common.IsString = function ()
{
    var s = arguments[0];
    for(var i=0; i<arguments.length; ++i)
    {
        if(typeof(arguments[i])!='string') 
        {
            return false;
        }
    }
    return true;
}

Common.GetCurrentStyle = function()
{
    var element = arguments[0];
    var propNm = arguments[1];
    var isInt = arguments[2];

    var s, p = 'undefined';
    var dv = document.defaultView;
    if(dv && dv.getComputedStyle)
    {
        s = dv.getComputedStyle(element,'');
        if (s) 
        {
            p = s.getPropertyValue(propNm);
        }
    }
    else if(element.currentStyle) 
    {
        var a = propNm.split('-');
        propNm = a[0];
        for (var i=1; i<a.length; ++i) 
        {
            c = a[i].charAt(0);
            propNm += a[i].replace(c, c.toUpperCase());
        }   
        p = element.currentStyle[propNm];
    }
    else 
    {
        return null;
    }
    return isInt ? (parseInt(p) || 0) : p;
}

Common.GetHeight = function()
{
    var element = arguments[0];
    var iHeight = arguments[1];
    
    if(!(element = Common.GetElement(element))) 
    {
        return 0;
    }
    if (Common.IsNumber(iHeight)) 
    {
        if (iHeight < 0) 
        {
            iHeight = 0;
        }
        else 
        {
            iHeight = Math.round(iHeight);
        }
    }
    else 
    {
        iHeight = -1;
    }
    
    var css = Common.IsDefined(element.style);
    if (element == document || element.tagName.toLowerCase() == 'html' || element.tagName.toLowerCase() == 'body') 
    {
        iHeight = Common.GetClientHeight();
    }
    else if(css && Common.IsDefined(element.offsetHeight) && Common.IsString(element.style.height)) 
    {
        if(iHeight >= 0) 
        {
            var pt=0,pb=0,bt=0,bb=0;
            if (document.compatMode == 'CSS1Compat') 
            {
                pt = Common.GetCurrentStyle(element,'padding-top',1);
                if (pt !== null) 
                {
                    pb=Common.GetCurrentStyle(element,'padding-bottom',1);
                    bt=Common.GetCurrentStyle(element,'border-top-width',1);
                    bb=Common.GetCurrentStyle(element,'border-bottom-width',1);
                }
                else if(Common.IsDefined(element.offsetHeight,element.style.height))
                {
                    element.style.height = iHeight + 'px';
                    pt = element.offsetHeight - iHeight;
                }
            }
            iHeight -= (pt+pb+bt+bb);
            if(isNaN(iHeight) || iHeight < 0) 
            {
                return;
            }
            else 
            {
                element.style.height = iHeight + 'px';
            }
        }
        iHeight = element.offsetHeight;
    }
    else if (css && Common.IsDefined(element.style.pixelHeight)) 
    {
        if (iHeight >= 0) 
        {
            element.style.pixelHeight = iHeight;
        }
        iHeight = element.style.pixelHeight;
    }
    return iHeight;
}

Common.GetWidth = function(e,w)
{   
    if  (!(e=Common.GetElement(e))) 
    {
        return 0;
    }
    
    if (Common.IsNumber(w)) 
    {
        if (w < 0) 
        {
            w = 0;
        }
        else 
        {
            w = Math.round(w);
        }
    }
    else 
    {
        w = -1;
    }
    var css = Common.IsDefined(e.style);
    if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') 
    {
        w = Common.GetClientWidth();
    }
    else if(css && Common.IsDefined(e.offsetWidth) && Common.IsString(e.style.width)) 
    {
        if (w >= 0) 
        {
            var pl=0,pr=0,bl=0,br=0;
            if (document.compatMode=='CSS1Compat') 
            {
                pl=Common.GetCurrentStyle(e,'padding-left',1);
                if (pl !== null) 
                {
                    pr=Common.GetCurrentStyle(e,'padding-right',1);
                    bl=Common.GetCurrentStyle(e,'border-left-width',1);
                    br=Common.GetCurrentStyle(e,'border-right-width',1);
                }
                else if(Common.IsDefined(e.offsetWidth,e.style.width))
                {
                    e.style.width = w + 'px';
                    pl = e.offsetWidth - w;
                }
            }
            w -= (pl+pr+bl+br);
            if (isNaN(w)||w<0) 
            {
                return;
            }
            else 
            {
                e.style.width = w + 'px';
            }
        }
        w = e.offsetWidth;
    }
    else if(css && Common.IsDefined(e.style.pixelWidth)) 
    {
        if (w >= 0) 
        {
            e.style.pixelWidth = w;
        }
        w = e.style.pixelWidth;
    }
    
    if (Common.Browser.isIE)
    {
        return w;
    }
    else
    {
        return w + 2;
    }
}

Common.GetClientHeight = function ()
{
    var h=0;
    if (document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientHeight)
    {
        h = document.documentElement.clientHeight;
    }
    else if (document.body && document.body.clientHeight)
    {
        h = document.body.clientHeight;
    }
    else if(Common.IsDefined(window.innerWidth,window.innerHeight,document.width)) 
    {
        h = window.innerHeight;
        if(document.width > window.innerWidth) 
        {
            h -= 16;
        }
    }
    return h;
}

Common.GetClientWidth = function()
{
    var w = 0;
    if (document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientWidth)
    {
        w = document.documentElement.clientWidth;
    }
    else if (document.body && document.body.clientWidth)
    {
        w = document.body.clientWidth;
    }
    else if (Common.IsDefined(window.innerWidth,window.innerHeight,document.height)) 
    {
        w = window.innerWidth;
        if (document.height>window.innerHeight) 
        {
            w-=16;
        }
    }
    return w;
}

Common.SlideElement = function (e, x, y, uTime)
{
    if (!(e = Common.GetElement(e))) 
    {
        return;
    }
    if (!e.timeout) 
    {
        e.timeout = 25;
    }
    
    e.xTarget = x; 
    e.yTarget = y; 
    e.slideTime = uTime; 
    e.stop = false;
    var pos = this.GetXY(e);
    e.yA = e.yTarget - pos[1]; 
    e.xA = e.xTarget - pos[0]; // A = distance
    if (e.slideLinear) 
    {  
        e.B = 1/e.slideTime;
    }
    else 
    {
        e.B = Math.PI / (2 * e.slideTime); // B = period
    }
    
    e.xD = pos[0];
    e.yD = pos[1];
    
    var d = new Date(); 
    e.C = d.getTime();
    if (!e.moving) 
    {
        Common._SlideTo(e);
    }
}

Common._SlideTo = function(e)
{
    if (!(e = Common.GetElement(e))) 
    {
        return;
    }
    
    var now, s, t, newY, newX;
    now = new Date();
    t = now.getTime() - e.C;
    if (e.stop) 
    { 
        e.moving = false; 
    }
    else if (t < e.slideTime) 
    {
        setTimeout("Common._SlideTo('"+e.id+"')", e.timeout);
        
        s = e.B * t;
        if (!e.slideLinear) 
        {
            s = Math.sin(s);
        }

        newX = Math.round(e.xA * s + e.xD);
        newY = Math.round(e.yA * s + e.yD);

        if (e.onmove) 
        {
            e.onmove(e, newX, newY);
        }
        Common.MoveTo(e, newX, newY);
        
        e.moving = true;
    }  
    else 
    {
        Common.MoveTo(e, e.xTarget, e.yTarget);
        if (e.onmove) 
        {
            e.onmove(e, e.xTarget, e.yTarget);
        }
        e.moving = false;
        Common.SetMaxZIndex(e);
        if (e.onslideend) 
        {
            e.onslideend(e);
        }
    }  
}

Common.MaxZIndex = 9999;

Common.SetMaxZIndex = function(e)
{
    Common.SetZIndex(e, Common.MaxZIndex);
    Common.MaxZIndex++;
}

Common.MoveTo = function (e,x,y)
{
    var pos = [];
    pos[0] = x;
    pos[1] = y;
    Common.SetXY(e,pos);
}

Common.SetZIndex = function(e,uZ)
{
    if(!(e = Common.GetElement(e))) 
    {
        return 0;
    }
    if (e.style && Common.IsDefined(e.style.zIndex)) 
    {
        if(Common.IsNumber(uZ)) 
        {
            e.style.zIndex = uZ;
        }
        uZ = parseInt(e.style.zIndex);
    }
    return uZ;
}

Common.Clip = function(e,t,r,b,l)
{
    function getClipDim(dim)
    {
        if (Common.IsNumber(dim))
        {
            return dim + "px";
        }
        return dim;
    }
    
    if (!(e = Common.GetElement(e))) 
    {
        return;
    }
    if (e.style) 
    {
        e.style.clip = 'rect('+getClipDim(t)+' '+getClipDim(r)+' '+getClipDim(b)+' '+getClipDim(l)+')';
    }
}

Common.UnClip = function(e)
{
  if (!(e = Common.GetElement(e))) 
  {
    return;
  }
  if (e.style) 
  {
    e.style.clip = 'rect(auto auto auto auto)';
  }
}

Common.ClipSlide = function(e, x, y, time, dir)
{
    e.onmove = Common._ClipSlide;
    e.onslideend = Common._ClipSlideEnd;
    e.clipD = Common.IsNumber(dir) ? dir : 2;
    Common.SlideElement(e, x, y, time);
}

Common._ClipSlide = function(e, x, y)
{
    if (Common.IsDefined(e))
    {
        var tX = e.xTarget;
        var tY = e.yTarget;
        switch (e.clipD)
        {
            //up
            case 0:
                Common.Clip(e,0,"auto",Common.GetHeight(e) - (Math.abs(tY - y)),0);
                break;
           
           //right
            case 1:
                Common.Clip(e,0,"auto","auto",(Math.abs(tX - x)));
                break;
                
           //down
            case 2:
                Common.Clip(e,(Math.abs(tY - y)),"auto","auto",0);
                break;
           
           //left
            case 3:
                Common.Clip(e,0,Common.GetWidth(e) - (Math.abs(tX - x)),"auto",0);
                break;
        }
    }
}

Common._ClipSlideEnd = function(e)
{
    Common.UnClip(e);
}

Common.ClipReveal = function(e, time)
{
    if (!(e = Common.GetElement(e))) 
    {
        return;
    }
    
    e.revealHeight = Common.GetHeight(e);
    e.revealWidth = Common.GetWidth(e);
    if (e.revealWidth == 1)
    {
        e.revealWidth = Common.GetClientWidth();
    }
    e.revealTime = time;
    Common._ClipReveal(e, 0, 0, 0, 0);
}

Common._ClipReveal = function(e,t,r,b,l)
{
    if (!(e = Common.GetElement(e))) 
    {
        return;
    }
    Common.Clip(e, t, r, b, l);    
    Common.SetVisible(e);
    if (r <= e.revealWidth || b <= e.revealHeight)
    {
        setTimeout("Common._ClipReveal('"+e.id+"', " + 0 + ", " + (r + 10) + ", " + (b + 10) + ", " + 0 + ")", e.revealTime);
    }
}

Common.GetParentByClass = function(e, className)
{
    if (e != null && Common.IsDefined(e))
    {
        if (Common.HasClass(e, className))
        {
            return e;
        }
        else
        {
            return Common.GetParentByClass(e.parentNode, className);
        }
    }
    else
    {
        return null;
    }
}

Common.HasClass = function(e, className)
{
    return e.className && e.className.match(new RegExp("\\b"+className+"\\b"));
}

Common.GetParentByTag = function(e, tagName)
{
    if (e != null && Common.IsDefined(e))
    {
        if (Common.IsDefined(e.tagName) && e.tagName == tagName)
        {
            return e;
        }
        else
        {
            return Common.GetParentByTag(e.parentNode, tagName);
        }
    }
    else
    {
        return null;
    }
}

Common.GetChildByTag = function(e, tagName)
{
    if (e != null && Common.IsDefined(e))
    {
        if (Common.IsDefined(e.tagName) && e.tagName == tagName)
        {
            return e;
        }
        else
        {
            if (e.childNodes)
            {
                for (var i=0;i<e.childNodes.length;i++)
                {
                    var child = Common.GetChildByTag(e.childNodes(i), tagName);
                    if (child != null)
                    {
                        return child;
                    }
                }
            }
        }
    }
    return null;
}

Common.CallbackError = function(message, context)
{
    try
    {
        Common.SetStatus("");
        var messageArray = String(message).split(";");
        if(messageArray[0] == "login")
        {
            alert("Your session has expired.\nYou are being redirected to the login page.");
            Common.SetStatus("redirecting to login page...");
            window.location = messageArray[1];            
            return;
        }
        
        var pop = window.open("callbackerror.html", "callbackerror", "scrollbars=yes width=800 height=600"); 
        pop.document.open();// open the window document for input;
        pop.window.srcDoc = document; 
        message = Common.HtmlDecode(message);
        var idx = message.indexOf("</HTML>");
        if (idx > 0)
        {
            message = message.substr(0, idx + 7);
        }
        pop.document.write(message); 
        pop.document.close(); //closes the stream
     }
     catch(e)
     {       
        Common.HandleError("Callback error: " + message);
     }  
}

Common.LoadState = function() 
{
    //var deserialized = ClientType_StringToObject(response);
    var deserialized = JSON.parse(arguments[0]);
    for(var i = 0; i < deserialized.length; i++) 
    {
        var stateAtom = deserialized[i];
        //var formField = document.forms[0][stateAtom.name];
        var formField = Common.GetElement(stateAtom.name);
        if (formField) 
        {
            formField.value = stateAtom.value;
        }
    }
}

Common._OriginalViewstate = "";

Common.ClearViewstate = function()
{
//    if (Common.IsDefined(__theFormPostData))
//    {
//        Common._OriginalViewstate = __theFormPostData;
//        __theFormPostData = "";
//    }
}

Common.RestoreViewstate = function()
{
//    if (Common.IsDefined(__theFormPostData))
//    {
//        __theFormPostData = Common._OriginalViewstate;
//    } 
}
        
Common.GetState = function() 
{
    var state = new Array();
    
    //add flag
    state[state.length] = {name: "callbackstate", value: new Date()};
    
    var formElements = document.forms[0].elements;
    for(var i = 0; i < formElements.length; i++) 
    {
        var formE = formElements[i];
        //ignore elements that start with "__"
        if ((typeof(formE.name) != "undefined" && formE.name.substr(0,2) != "__") && typeof(formE.value) != "undefined")
        {
            var stateAtom = {name: formE.name, value: formE.value};
            if (formE.type == "checkbox" && !formE.checked)
            {
                stateAtom.value = "";
            }
            if (stateAtom.value.length > 0)
            {
                state[state.length] = stateAtom;
            }
        }
    }
    
    return JSON.stringify(state);
}

Common.InnerText = function(e, txt)
{
    if (!(e = Common.GetElement(e))) 
    {
        return null;
    }
    
    if (e.innerText)
    {
        if (txt)
        {
            e.innerText = txt;
        }
        return e.innerText;
    }
    if (e.textContent)
    {
        if (txt)
        {
            e.textContent = txt;
        }
        return e.textContent;
    }
    return null;
}

Common.PreventDefault = function(e)
{
    if (e && e.preventDefault) 
    {
        e.preventDefault();
    }
    else if (window.event) 
    {
        window.event.returnValue = false;
    }
}

Common.StopPropagation = function(e)
{
    if (e && e.stopPropagation) 
    {
        e.stopPropagation();
    }
    else if (window.event)
    {
        window.event.cancelBubble = true;
    }
}

Common.EventObject = function(evt)
{
    var e = evt || window.event;
    if (!e) 
    {
        return;
    }
    if (e.type) 
    {
        this.type = e.type;
    }
    if (e.target) 
    {
        this.target = e.target;
    }
    else if (e.srcElement) 
    {
        this.target = e.srcElement;
    }

    if (e.relatedTarget) 
    {
        this.relatedTarget = e.relatedTarget;
    }
    else if (e.type == 'mouseover' && e.fromElement) 
    {
        this.relatedTarget = e.fromElement;
    }
    else if (e.type == 'mouseout') 
    {
        this.relatedTarget = e.toElement;
    }

    if(Common.IsDefined(e.pageX,e.pageY)) 
    { 
        this.pageX = e.pageX; 
        this.pageY = e.pageY; 
    }
    else if (Common.IsDefined(e.clientX,e.clientY)) 
    { 
        this.pageX = e.clientX + Common.ScrollLeft(); 
        this.pageY = e.clientY + Common.ScrollTop(); 
    }

    if (Common.IsDefined(e.offsetX,e.offsetY)) 
    {
        this.offsetX = e.offsetX;
        this.offsetY = e.offsetY;
    }
    else if (Common.IsDefined(e.layerX,e.layerY)) 
    {
        this.offsetX = e.layerX;
        this.offsetY = e.layerY;
    }
    else 
    {
        var pos = Common.GetXY(this.target);
        this.offsetX = this.pageX - pos[0];
        this.offsetY = this.pageY - pos[1];
    }

    if (e.keyCode) 
    { 
        this.keyCode = e.keyCode; 
    }
    else if (Common.IsDefined(e.which) && e.type.indexOf('key')!=-1) 
    { 
        this.keyCode = e.which; 
    }

    this.shiftKey = e.shiftKey;
    this.ctrlKey = e.ctrlKey;
    this.altKey = e.altKey;
}

Common.ScrollLeft = function(e, bWin)
{
    var offset=0;
    if (!Common.IsDefined(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') 
    {
        var w = window;
        if (bWin && e) 
        {
            w = e;
        }
        if (w.document.documentElement && w.document.documentElement.scrollLeft) 
        {
            offset=w.document.documentElement.scrollLeft;
        }
        else if (w.document.body && Common.IsDefined(w.document.body.scrollLeft)) 
        {
            offset=w.document.body.scrollLeft;
        }
    }
    else 
    {
        e = Common.GetElement(e);
        if (e && Common.IsNumber(e.scrollLeft)) 
        {
            offset = e.scrollLeft;
        }
    }
    return offset;
}

Common.ScrollTop = function(e, bWin)
{
    var offset=0;
    if (! Common.IsDefined(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') 
    {
        var w = window;
        if (bWin && e) 
        {
            w = e;
        }
        if (w.document.documentElement && w.document.documentElement.scrollTop) 
        {
            offset = w.document.documentElement.scrollTop;
        }
        else if (w.document.body &&  Common.IsDefined(w.document.body.scrollTop)) 
        {
            offset=w.document.body.scrollTop;
        }
    }
    else 
    {
        e = Common.GetElement(e);
        if (e && Common.IsNumber(e.scrollTop)) 
        {
            offset = e.scrollTop;
        }
    }
    return offset;
}
                                                   
Common.AddEventListener = function(e,eT,eL,cap)
{
    if(!(e = Common.GetElement(e)))
    {
        return;
    }
    eT = eT.toLowerCase();
    var eh = 'e.on' + eT + '=eL';
    if (e.addEventListener) 
    {
        e.addEventListener(eT, eL, cap);
    }
    else if(e.attachEvent) 
    {
        e.attachEvent('on' + eT,eL);
    }
    else 
    {
        eval(eh);
    }
}

Common.RemoveEventListener = function(e,eT,eL,cap)
{
    if(!(e=Common.GetElement(e))) 
    {
        return;
    }
    eT = eT.toLowerCase();
    var eh = 'e.on' + eT + '=null';
    if(e.removeEventListener) 
    {
        e.removeEventListener(eT, eL, cap);
    }
    else if(e.detachEvent) 
    {
        e.detachEvent('on' + eT, eL);
    }
    else 
    {
        eval(eh);
    }
}

Common.SetOpacity = function(e, op)
{
    e.style.opacity = op/10;
    e.style.filter = 'Alpha(opacity=' + op*10 + ')';
}

Common.FadeIn = function(e, i, oncomplete, speed)
{
    e = Common.GetElement(e);
    if (!e._isFading)
    {
        if (typeof(oncomplete) == 'function')
        {
            e._onfadecomplete = oncomplete;
        }
        else
        {
            e._onfadecomplete = null;
        }
        
        if (!speed)
        {
            speed = 10;
        }
        
        e._isFading = true;
        Common._FadeIn(e,i,speed);
    }
}

Common.FadeOut = function(e)
{
    e = Common.GetElement(e);
    if (!e._isFading)
    {
        e._isFading = true;
        Common.SetVisible(e);
        Common._FadeOut(e,10);
    }
}

Common._FadeIn = function(e, i, speed)
{
    e = Common.GetElement(e);
    Common.SetOpacity(e, i);
    Common.SetVisible(e);
    if (i == 10)
    {
        e._isFading = false;
        if (e._onfadecomplete)
        {
            e._onfadecomplete(e);
        }
        return;
    }
    else
    {
        i++;
        window.setTimeout("Common._FadeIn('" + e.id + "'," + i + "," + speed + ")", speed);
    }
}

Common._FadeOut = function(e, i)
{
    e = Common.GetElement(e);
    Common.SetOpacity(e, i);
    if (i < 1)
    {
        e._isFading = false;
        Common.SetHidden(e);
        return;
    }
    else
    {
        i--;
        window.setTimeout("Common._FadeOut('" + e.id + "'," + i + ")", 100);
    }
}

Common.ConfirmDelete = function(s)
{
    if (s == null)
    {
        s = "Are you sure you want to delete this item?";
    }
    return window.confirm(s);
}

Common.HandleError = function()
{
    Common.SetStatus("");
    var oError = arguments[0];
    
    alert(Common.IsString(oError) ? oError : oError.Message);  
}

Common.SetFocus = function(e)
{
    e = Common.GetElement(e);
    if (Common.IsDefined(e) && !e.disabled)
    {
        try
        {
            e.focus();
        }
        catch(e)
        {}
    }
}

Common.TrimString = function(s)
{
    return s.replace(/^\s*|\s*$/g,"");
}

Common.MarkChanged = function()
{
    if (Common.IsDefined(Common.Changes))
    {
        Common.Changes.MarkChanged();
    }
}

Common.SkipChanges = function()
{
    if (Common.IsDefined(Common.Changes))
    {
        //skip changes prompt
        Common.Changes.SkipCheck = true;
    }
}

Common.DetermineCallback = function(cb, u, i)
{
    if (cb)
    {
        return u;
    }
    else
    {
        return i;
    }
}

Common.HtmlDecode = function(s)
{
	var div = document.createElement('div');
	div.innerHTML = Common.StripTags(s);
	
	var f = new Function("e","var text='';for(var i=0;i<e.childNodes.length;i++){text+=e.childNodes[i].nodeValue;}return text;");
	
	return div.childNodes[0] ? (div.childNodes.length > 1 ? f(div) : div.childNodes[0].nodeValue) : '';
}

Common.HtmlEncode = function(s)
{
	var div = document.createElement('div');
	var text = document.createTextNode(s);
	div.appendChild(text);
	return div.innerHTML;
}

Common.StripTags = function(s)
{
    return s.replace(/<\/?[^>]+>/gi, '');
}

Common.SetCookie = function(name, value, expire, path)
{
    document.cookie = name + "=" + escape(value) + ((!expire) ? "" : ("; expires=" + expire.toGMTString())) + "; path=" + ((!path) ? "/" : path);
}

Common.EraseCookie = function(name, path)
{
    if (Common.GetCookie(name)) 
    {
        document.cookie = name + "=" + "; path=" + ((!path) ? "/" : path) + "; expires=" + new Date(0).toGMTString();
    }
}

Common.GetCookie = function(name)
{
    var value=null, search=name+"=";
    if (document.cookie.length > 0) 
    {
        var offset = document.cookie.indexOf(search);
        if (offset != -1) 
        {
            offset += search.length;
            var end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            value = unescape(document.cookie.substring(offset, end));
        }
    }
    return value;
}

Common._FocusControl = null;

Common.FocusControl = function (focusControlID)
{
    //use existing method
    Common.SetFocus(focusControlID);
}

Common.GetBoundingClientRect = function(e)
{
    try
    {
        document.recalc();
        return e.getBoundingClientRect();
    }
    catch(ex)
    {
        return new Common.Box();
    } 
}

Common.GetXY = function(e) 
{
    var parentNode = null;
    var pos = [];
    var box;
            
    if (e.getBoundingClientRect) 
    { // IE
        window.status = "";
        box = Common.GetBoundingClientRect(e);

        var doc = document;

        var scrollTop = Math.max(doc.documentElement.scrollTop, doc.body.scrollTop);
        var scrollLeft = Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft);
               
        return [box.left + scrollLeft, box.top + scrollTop];
    }
    else 
    { // non-IE
        pos = [e.offsetLeft, e.offsetTop];
        parentNode = e.offsetParent;
        if (parentNode != e) 
	    {
	        while (parentNode) 
	        {
	            pos[0] += parentNode.offsetLeft;
		        pos[1] += parentNode.offsetTop;
		        parentNode = parentNode.offsetParent;
	        }
	    }
    }
            
    if (e.parentNode) 
    { 
	    parentNode = e.parentNode; 
    }
    else 
    { 
	    parentNode = null; 
    }
      
    while (parentNode && parentNode.tagName.toUpperCase() != 'BODY' && parentNode.tagName.toUpperCase() != 'HTML') 
    { 
        // account for any scrolled ancestors
	    pos[0] -= parentNode.scrollLeft;
	    pos[1] -= parentNode.scrollTop;
      
	    if (parentNode.parentNode) 
        { 
	        parentNode = parentNode.parentNode; 
	    } 
	    else 
	    { 
	        parentNode = null; 
	    }
    }
    return pos;
}

Common.SetXY = function(e, pos, noRetry) 
{
    var style_pos = this.GetStyle(e, 'position');
    if (style_pos == 'static') 
    { 
        // default to relative
        this.SetStyle(e, 'position', 'relative');
        style_pos = 'relative';
    }
        
    var pageXY = this.GetXY(e);
    if (pageXY === false) 
    { 
        // has to be part of doc to have pageXY
        return false; 
    }
        
    var delta = [ // assuming pixels; if not we will have to retry
       parseInt( this.GetStyle(e, 'left'), 10 ),
       parseInt( this.GetStyle(e, 'top'), 10 )
    ];
     
    if ( isNaN(delta[0]) ) 
    {
        // in case of 'auto'
        delta[0] = (style_pos == 'relative') ? 0 : e.offsetLeft;
    } 
    if ( isNaN(delta[1]) ) 
    { 
        // in case of 'auto'
        delta[1] = (style_pos == 'relative') ? 0 : e.offsetTop;
    } 
  
    if (pos[0] !== null) 
    { 
        e.style.left = pos[0] - pageXY[0] + delta[0] + 'px'; 
    }
    if (pos[1] !== null) 
    {
        e.style.top = pos[1] - pageXY[1] + delta[1] + 'px'; 
    }
  
    var newXY = this.GetXY(e);
  
    // if retry is true, try one more time if we miss 
    if (!noRetry && (newXY[0] != pos[0] || newXY[1] != pos[1]) ) 
    {
        this.SetXY(e, pos, true);
    }
            
}

Common.GetStyle = function(e, p)
{
    var value = null;
    var dv = document.defaultView;
            
    if (!Common.property_cache[p]) 
    {
       Common.CacheProperty(p);
    }
            
    var camel = Common.property_cache[p]['camel'];
    var hyphen = Common.property_cache[p]['hyphen'];

    if (p == 'opacity' && e.filters) 
    {
        // IE opacity
        value = 1;
        try 
        {
            value = e.filters.item('DXImageTransform.Microsoft.Alpha').opacity / 100;
        } 
        catch(ex) 
        {
            try 
            {
                value = e.filters.item('alpha').opacity / 100;
            } 
            catch(ex) {}
        }
    } 
    else if (e.style[camel]) 
    { 
        // camelCase for valid styles
        value = e.style[camel];
    }
    else if (Common.Browser.isIE && e.currentStyle && e.currentStyle[camel]) 
    { 
        // camelCase for currentStyle; isIE to workaround broken Opera 9 currentStyle
        value = e.currentStyle[camel];
    }
    else if ( dv && dv.getComputedStyle ) 
    { 
        // hyphen-case for computedStyle
        var computed = dv.getComputedStyle(e, '');
               
        if (computed && computed.getPropertyValue(hyphen)) 
        {
            value = computed.getPropertyValue(hyphen);
        }
    }
      
    return value;
}

Common.SetStyle = function(e, p, val) 
{
    if (!Common.property_cache[p]) 
    {
        Common.CacheProperty(p);
    }
         
    var camel = Common.property_cache[p]['camel'];
         
    switch(p) 
    {
        case 'opacity' :
            if (Common.Browser.isIE && typeof(e.style.filter) == 'string') 
            { 
                // in case not appended
                e.style.filter = 'alpha(opacity=' + val * 100 + ')';
             
                if (!e.currentStyle || !e.currentStyle.hasLayout) 
                {
                    e.style.zoom = 1; // when no layout or cant tell
                }
            } 
            else 
            {
                e.style.opacity = val;
                e.style['-moz-opacity'] = val;
                e.style['-khtml-opacity'] = val;
            }

            break;
            
        default :
            e.style[camel] = val;
    }  
}
         
Common.ToCamel = function(p) 
{
    var convert = function(prop) 
    {
        var test = /(-[a-z])/i.exec(prop);
        return prop.replace(RegExp.$1, RegExp.$1.substr(1).toUpperCase());
    };

    while(p.indexOf('-') > -1) 
    {
        p = convert(p);
    }

    return p;
}
   
Common.ToHyphen = function(p) 
{
    if (p.indexOf('-') > -1) 
    { 
        // assume hyphen
        return p;
    }

    var c = '';
    var len = p.length;
    for (var i = 0;i < len; ++i) 
    {
        if (p.charAt(i) == p.charAt(i).toUpperCase()) 
        {
            c = c + '-' + p.charAt(i).toLowerCase();
        } 
        else 
        {
            c = c + p.charAt(i);
        }
    }

    return c;
}

Common.property_cache = {};
   
Common.CacheProperty = function(p) 
{
    Common.property_cache[p] = {
         camel: Common.ToCamel(p),
         hyphen: Common.ToHyphen(p)
      };
}

Common.IsAlphabetic = function(c)
{
    return (c != null) && c.match(/^[a-zA-Z]+$/);
}

Common.IsAlphaNumeric = function(c)
{
    return (c != null) && c.match(/^[a-zA-Z0-9]+$/);
}

Common.IsNumeric = function(c)
{
    var re = /[\D]/g;
    return !(re.test(c));
}

Common.UpdateHiddenField = function(id, s)
{
    Common.UpdateField(id,s);
}

Common.UpdateField = function(id, s)
{
    var e = Common.GetElement(id);
    if (Common.IsDefined(e))
    {
        e.value = s;
    }
}

Common.RefreshControls = function(ctrlList)
{
    if (ctrlList != null && ctrlList.length > 0)
    {
        try
        {
            Common._RefreshList = ctrlList;
            for (var idx=0;idx<ctrlList.length;idx++)
            {
                Common.SetStatus("Refreshing...");
                setTimeout("Common._RefreshControl(" + idx + ")",0);
            }
        }
        catch(e)
        {
            Common.SetStatus("");
            throw e;
        }
    }
}

Common._RefreshList = null;

Common._RefreshControl = function(idx)
{
    var ctrl = Common._RefreshList[idx];
    if (ctrl.ClientMethod != null && ctrl.ClientMethod.length > 0)
    {
        eval(ctrl.ClientMethod + "(ctrl.ClientID,ctrl.Html)");
    }
    else
    {
        Common.SetInnerHTML(ctrl.ClientID, ctrl.Html);
        Common.SetStatus("");
    }
}

Common.SetInnerHTML = function(e, html)
{
    e = Common.GetElement(e);
    if (Common.IsDefined(e) && html != null)
    {
        e.innerHTML = html;
    }
}

Common.ReplaceElement = function(e, html)
{
    e = Common.GetElement(e);
    if (Common.IsDefined(e))
    {
        if (e.parentNode.childNodes.length > 1)
        {
            var div = document.createElement("DIV");
            div.innerHTML = html;
            e.parentElement.insertBefore(div, e);
            e.parentElement.removeChild(e);
        }
        else
        {
            e.parentNode.innerHTML = html;
        }    
    }
}

Common.IsArray = function(o)
{
    return (o && (typeof o == 'object') && o.constructor == Array);
}

Common.SetNavTrail = function(id, key, loc, title, cookieFld, eID)
{
    if (Common.IsDefined(eID) && eID.length > 0)
    {
        var target = Common.GetElement(eID);
        if (Common.IsDefined(target))
        {
            title = String(title).replace("{0}", target.value);   
        }
    }
    
    var currentCookie = "";
    if (cookieFld.length > 0)
    {
        var eCookie = Common.GetElement(cookieFld);
        if (eCookie != null)
        {
            currentCookie = eCookie.value;
        }
        else
        {
            return;
        }
    }
    else
    {
        //root link - clear all others
        Common.GetElement("navTrailLinks").innerHTML = "";
    }
    
    if (currentCookie != null && currentCookie.length > 0)
    {
        currentCookie += "|!|";
    }
    else
    {
        currentCookie = "";
    }
    
    currentCookie += loc + "$|$" + title;
    
    Common.SetCookie(key, currentCookie);
    
    if (title.length == 0)
    {
        title = document.title;
    }
    Common.GetElement(id).innerHTML = title;
}

Common.HasPoint = function(e,x,y,t,r,b,l)
{
    if (!Common.IsNumeric(t))
    {
        t=r=b=l=0;
    }
    else if (!Common.IsNumeric(r))
    {
        r=b=l=t;
    }
    else if (!Common.IsNumeric(b))
    {
        l=r; b=t;
    }
    var pos = Common.GetXY(e);
    var eX = pos[0], eY = pos[1];
    return (x >= eX + l && x <= eX + Common.GetWidth(e) - r &&
          y >= eY + t && y <= eY + Common.GetHeight(e) - b );
}

Common.ChildWindows = new Array();

Common.OpenWindow = function(url, nm, f, r, p, def, eT)
{
    var newWin = null;
    var idx = -1;
    for (var i = 0;i<Common.ChildWindows.length;i++)
    {
        if (Common.ChildWindows[i] != null && Common.ChildWindows[i].name == nm)
        {
            newWin = Common.ChildWindows[i];
            idx = i;
            break;
        }
    }
    
    if (!Common.IsDefined(newWin) || newWin.closed)
    {
        newWin = Common._OpenWindow(def, nm, f, r);
        
        if (newWin != null && idx == -1)
        {
            Common.ChildWindows[Common.ChildWindows.length - 1]  = newWin;
        }
    }
    
    if (newWin != null)
    {
        Common._OpenWindowLocation(newWin, url, p, eT);
        newWin.focus();
    }
}

Common._OpenWindow = function(url, nm, f, r)
{
    var win = window.open(url,nm,f,r);
        
    if (win == null)
    {
        Common.HandleError("Unable to open a new window.\n\nThis is most likely due to a pop up blocker.\n\nPlease add this site to your list of trusted sites.");
    }
    
    return win;
}

Common._OpenWindowLocation = function(win,url,p,eT)
{
    if (p)
    {
        //post to window
        var firstForm = document.forms[0];
        var origTarget = firstForm.target;
        var origAction = firstForm.action;
        var origVSName = Common.GetElement("__VIEWSTATE").name;
        try
        {
            firstForm.target = win.name;
            firstForm.action = url;
            
            if (firstForm.action.length > 0)
            {
                Common.GetElement("__VIEWSTATE").name = "NOVIEWSTATE";
            }
            
            if (typeof(__doPostBack) == "function")
            {
                __doPostBack(eT,"");
            }
            else
            {
                firstForm.submit();
            }
        }
        finally
        {
            firstForm.action = origAction;
            firstForm.target = origTarget;
            Common.GetElement("__VIEWSTATE").name = origVSName;
            firstForm.__EVENTTARGET.value = "";
        }
    }
    else
    {
        win.location.href = url;
    }
}

Common.IsVisible = function(e)
{
    return Common.IsDefined(e) && (e.style.display != "none" && e.style.visibility != "hidden");
}

Common.SetVisible = function(e)
{
    if (Common.IsDefined(e))
    {
        if (Common.IsDefined(e.prevDisplay))
        {
            e.style.display = e.prevDisplay;
        }
        else
        {
            e.style.display = "inline";
        }
        e.style.visibility = "inherit";
    }
}

Common.SetHidden = function(e)
{
    if (Common.IsDefined(e))
    {
        if (e.style.display != "none")
        {
            e.prevDisplay = e.style.display;
        }
        e.style.display = "none";
        e.style.visibility = "hidden";
    }
}

Common.LoadScriptBlock = function(s, parent)
{
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.text = s;
    try
    {
        if (parent)
        {
            parent.appendChild(script);
        }
        else
        {
            document.body.appendChild(script);
        }
    }
    catch(e)
    {
        Common.HandleError("There was an error loading a script block.");
        //Common.Debug.Trace(s);
    }
}

Common.DragManager = {e:null, mm:false};

Common.DragEnable = function(id, dStart, dDrag, dEnd, dObj)
{
    var ele = Common.GetElement(id);
    ele.CanDrag = true;
    ele.eDragStart = dStart;
    ele.eDragging = dDrag;
    ele.eDragEnd = dEnd;
    ele.eObj = dObj;
    Common.AddEventListener(ele, 'mousedown', Common._dragMD, false);
    
    if (!Common.DragManager.mm) 
    {
        Common.DragManager.mm = true;
        Common.AddEventListener(document, 'mousemove', Common._dragMM, false);
    }
}

Common.DropEnable = function(id,cb)
{
    var e = Common.GetElement(id);
    if (e) 
    {
        e.xODp = cb;
        if (!Common.DragManager.drops) 
        {
            Common.DragManager.drops = new Array();
        }
        Common.DragManager.drops[Common.DragManager.drops.length] = e;
        if (!Common.DragManager.omu) 
        {
            Common.DragManager.omu = Common._dragMU;
            Common._dragMU = _fWin._dragMU2;
        }
    }
}

Common._dragMU2 = function(e)
{
    var i, z, hz = 0, he = null;
    e = new Common.EventObject(e);
    for (i = 0; i < Common.DragManager.drops.length; ++i) 
    {
        if (Common.HasPoint(Common.DragManager.drops[i], e.pageX, e.pageY)) 
        {
            z = Common.DragManager.drops[i].style.zIndex || 0;
            if (z >= hz) 
            {
                hz = z;
                he = Common.DragManager.drops[i];
            } 
        }
    }
  
    var ele = Common.DragManager.ele;
    Common.DragManager.omu(e); // dragEnd event
    if (he && he.xODp) 
    {
        he.xODp(ele, e.pageX, e.pageY); // drop event
    }
}

Common._dragMD = function(e)
{
    var evt = new Common.EventObject(e);
    var ele = evt.target;
    while(ele && !ele.CanDrag) 
    {
        ele = Common.GetParent(ele);
    }
    if (ele) 
    {
        Common.PreventDefault(e);
        ele.xDPX = evt.pageX;
        ele.xDPY = evt.pageY;
        Common.DragManager.e = ele;
        Common.AddEventListener(document, 'mouseup', Common._dragMU, false);
        if (ele.eDragStart) 
        {
            ele.eDragStart(ele, evt.pageX, evt.pageY);
        }
    }
}

Common._dragMM = function(e)
{
    var evt = new Common.EventObject(e);
    if (Common.DragManager.e) 
    {
        Common.PreventDefault(e);
        var ele = Common.DragManager.e;
        var dx = evt.pageX - ele.xDPX;
        var dy = evt.pageY - ele.xDPY;
        ele.xDPX = evt.pageX;
        ele.xDPY = evt.pageY;
        if (ele.eDragging) 
        {
            ele.eDragging(ele, dx, dy);
        }
        else 
        {
            var pos = Common.GetXY(e);
            Common.MoveTo(ele, pos[0](ele) + dx, pos[1](ele) + dy);
        }
    }  
}

Common._dragMU = function(e)
{
    if (Common.DragManager.e) 
    {
        Common.PreventDefault(e);
        Common.RemoveEventListener(document, 'mouseup', Common._dragMU, false);
        if (Common.DragManager.e.eDragEnd) 
        {
              var evt = new Common.EventObject(e);
              Common.DragManager.e.eDragEnd(Common.DragManager.e, evt.pageX, evt.pageY);
        }
        Common.DragManager.e = null;
    }  
}

Common.GetCSSRule = function(ruleName, deleteFlag) 
{               
    ruleName=ruleName.toLowerCase();                       
    
    if (document.styleSheets) 
    {                            
        for (var i=0; i<document.styleSheets.length; i++) 
        { 
            var styleSheet=document.styleSheets[i];
            var ii=0;                                        
            var cssRule=false;
            do 
            {
                if (styleSheet.cssRules) 
                {
                    cssRule = styleSheet.cssRules[ii];
                } 
                else 
                {
                    cssRule = styleSheet.rules[ii];
                }
                if (cssRule)  
                {
                    if (cssRule.selectorText.toLowerCase()==ruleName) 
                    {
                        if (deleteFlag=='delete') 
                        {
                            if (styleSheet.cssRules) 
                            {
                                styleSheet.deleteRule(ii);
                            } 
                            else 
                            {
                                styleSheet.removeRule(ii);
                            }
                            return true;
                        } 
                        else 
                        {
                            return cssRule;
                        }
                    }
                }
                ii++;
            } 
            while (cssRule)
        }
    }
    return false;                                          
}                                                         
    
Common.KillCSSRule = function(ruleName) 
{
    return Common.GetCSSRule(ruleName,'delete');
}
    
Common.AddCSSRule = function(ruleName, styleSheet) 
{
    if (document.styleSheets) 
    {
        if (!Common.GetCSSRule(ruleName)) 
        {
            if (!styleSheet)
            {
                styleSheet = document.styleSheets[0];
            }
            if (styleSheet.addRule) 
            {
                styleSheet.addRule(ruleName, null,0);
            } 
            else 
            {
                styleSheet.insertRule(ruleName+' { }', 0);
            }
        }
    }
    return Common.GetCSSRule(ruleName);
}

Common.BaseID = function(id)
{
    var sec = id.split('_');
    return sec[sec.length - 1];
}

Common.MoveIntoView = function(e)
{
    e = Common.GetElement(e);
    var iClientHeight = Common.GetClientHeight();
    var iClientWidth = Common.GetClientWidth();
    var iScrollTop = Common.ScrollTop();
    var iScrollLeft = Common.ScrollLeft();
    
    var iHeight = Common.GetHeight(e);
    var iWidth = e.firstChild ? Common.GetWidth(e.firstChild) : Common.GetWidth(e);
    
    var pos = Common.GetXY(e);
    
    var bMove = false;
    
    //right edge
    if (pos[0] + iWidth > iClientWidth + iScrollLeft)
    {
        pos[0] = Math.max(pos[0] - ((pos[0] + iWidth) - (iClientWidth + iScrollLeft)), 1);
        bMove = true;
    }
    
    //bottom
    //this calculation seems to be off by 18 - horizontal scroll bar?
    if ((pos[1] + iHeight + 18) > (iClientHeight + iScrollTop))
    {
        pos[1] = Math.max(pos[1] - ((pos[1] + iHeight) - (iClientHeight + iScrollTop)), 1);
        bMove = true;
    }
    
    if (bMove)
    {
        Common.SlideElement(e, pos[0], pos[1], 20);
    }
}