function StartCallback(ControlId,event,queryString,postData)
{
    var Context = eval( ControlId + '_Context' );
    var Url=eval(ControlId + '_Url');

    if (event != null)  
    {
        Context.LastMouseTop = event.clientY;  
        Context.LastMouseLeft = event.clientX;
    }
    else 
    {  Context.LastMouseTop = 0;  }
 
    if (queryString == null)
        queryString = '';
        
    if (Context.PostBackMode == 'GET' )
    {
        if (queryString != '')
            queryString = '&' + queryString;
        
        queryString = '__WWEVENTCALLBACK=' + Context.ControlId + queryString;
    }

    if (queryString != '')
        Url =  Url + '?' + queryString;   
        
    Context.Url = Url;
    Context.PostData = postData;

    if (Context.NavigateDelay > 0)
    {
        var Cmd = "GetServerUrl(eval('" + ControlId + "_Context'))";
        setTimeout(Cmd,Context.NavigateDelay);
    }
    else
        GetServerUrl( Context );
}
function HandleCallback(ControlId)
{
    var Context = eval(ControlId + '_Context');
    var Http = Context.Http;

    if (Http == null || Http.readyState != 4) 
        return;

    var Result = '';
    var ErrorException = null;

    Result = Http.responseText;
    if (Http.status != 200) 
        ErrorException = new CallbackExceptionObject(Http.statusText);

    Http = null;

    if (Context.EventHandlerMode == 'ShowHtmlAtMousePosition')
    {
    
        if (Context.LastMouseTop != -1)
        {
            var Panel = document.getElementById(Context.ControlId);
            Panel.innerHTML = Result;
            MovePanelToMousePosition(Context);
        }
    }
    else if (Context.EventHandlerMode == 'ShowHtmlInPanel' )
    {
            var Panel = document.getElementById(Context.ControlId);
            Panel.innerHTML = Result;
            Panel.style.display = '';
    }
    else
    {
        var FinalResult = Result;
        if (Context.EventHandlerMode == 'CallPageMethod')
        {
            if (ErrorException)    
            {
                Context.Callback(ErrorException);
                return;
            }
            FinalResult = eval( '(' + Result + ')');
         }
        Context.Callback(FinalResult);
    }
}
function MovePanelToMousePosition(Context,event)
{
    try
    {
        var Panel = document.getElementById(Context.ControlId);
        Panel.style.position = 'absolute';    
        if (event)
        {
            Context.LastMouseTop = event.clientY;  
            Context.LastMouseLeft = event.clientX;
        }
       
        var Top = 0;
        var ScrollTop = document.body.scrollTop;

        if (ScrollTop == 0)
        {
            if (window.pageYOffset)
                ScrollTop = window.pageYOffset;
            else
                ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
        }

        Top = ScrollTop + Context.LastMouseTop - 3;
        
        Panel.style.top = Top.toString() + 'px';
        Panel.style.left = (Context.LastMouseLeft - 2).toString() + 'px';
        Panel.style.display = '';
        
        if (Context.AdjustWindowPosition && document.body) 
        {
            var mainHeight = 0; 
            if( typeof( window.innerWidth ) == 'number' ) 
                mainHeight = window.innerHeight; 
            else if( document.documentElement && document.documentElement.clientHeight ) 
                mainHeight = document.documentElement.clientHeight; 
            else if( document.body && document.body.clientHeight ) 
                mainHeight = document.body.clientHeight; 

            if ( mainHeight < Panel.clientHeight ) 
                Top = ScrollTop; 
            else 
            {
                if ( mainHeight < Context.LastMouseTop + Panel.clientHeight ) 
                   Top = mainHeight - Panel.clientHeight - 10 + ScrollTop; 
            } 
            Panel.style.top = Top.toString() + "px";
        }

        if (Context.ShadowOffset != 0) 
        {
             Panel.style.width = ''; 
             Panel.style.height = '';
             var Panel2 = document.getElementById(Context.ControlId + '_Shadow');
             Panel2.style.position = 'absolute';
             Panel2.style.top = (Top + Context.ShadowOffset).toString() + 'px';
             Panel2.style.left = (Context.LastMouseLeft + Context.ShadowOffset +2).toString() + 'px';
             Panel2.style.width = Panel.offsetWidth.toString() + 'px';
             Panel2.style.height = Panel.offsetHeight.toString() + 'px';
             Panel2.style.display = '';
        }
    }
    catch( e )
    {
         window.status =  'Moving of window failed: ' +  e.message  ;
    }

}
function HidePanel(ControlId) 
{
    var Context = eval( ControlId + "_Context");
    Context.LastMouseTop = -1;
    document.getElementById(Context.ControlId).style.display = 'none';
    if (Context.ShadowOffset != 0)
        document.getElementById(Context.ControlId + '_Shadow').style.display = 'none';
}         
function ShowPanel(ControlId)
{
    var Context = eval( ControlId + "_Context");
    document.getElementById(Context.ControlId).style.display = '';
    if (Context.ShadowOffset != 0)
        document.getElementById(Context.ControlId + '_Shadow').style.display = '';
}
function CallMethod(ControlId,MethodName,Parm1,Parm2,Parm3,Parm4,Parm5,Parm6,Parm7,Parm8)
{    
    var Parameters = 'CallbackMethod=' + MethodName + '&';
   
    var ParmCount = arguments.length;
    for (var x = 2; x < ParmCount-1; x++)
    {
        Parameters = Parameters + 'Parm' + (x-1).toString() + '=' + EncodeValue(JSON.serialize(arguments[x]).toString()) + '&';
    }
    Parameters = Parameters + 'CallbackParmCount=' + (ParmCount-3).toString();

    var Context = eval(ControlId + '_Context');
    Context.Callback = arguments[ParmCount-1]; 
    Context.LastMouseTop = 0;
    
    if (Context.PostBackMode == 'GET')
        StartCallback(ControlId,null,Parameters,null,1);
    else
        StartCallback(ControlId,null,null,Parameters,1);
    
} 
function CallbackContext(Url,Callback,ControlId,
                         NavigateDelay,PostBackMode,EventHandlerMode,
                         FormName,AdjustWindowPosition,PanelShadowOffset)
{
    if (NavigateDelay == null)
        NavigateDealy = 1;

    if (PostBackMode == null)
        PostBackMode = 'GET'; // POST , POSTNoViewState

    if (EventHandlerMode == null)
        EventHandlerMode = 'ShowHtmlAtMousePosition';
    
    if (AdjustWindowPosition == null)
        AdjustWindowPosition = false;
    
    if (PanelShadowOffset == null)
        PanelShadowOffset = 0;
    
    this.ControlId = ControlId;
    this.Http = GetXmlHttp();

    this.Url = Url;
    this.NavigateDelay = NavigateDelay;
    this.PostData = null;
    this.FormName = FormName;
    this.Callback = Callback;
    this.Method = '';
    this.Async = true;
    
    this.PostBackMode = PostBackMode;
    this.EventHandlerMode = EventHandlerMode; // CallPageMethod,CallExternalUrl

    this.LastMouseLeft = 0;
    this.LastMouseTop = -1;
    this.AdjustWindowPosition = AdjustWindowPosition;
    this.ShadowOffset = PanelShadowOffset;
}
function CallbackExceptionObject(Message)
{
    this.IsCallbackError = true;
    this.Message = Message;
}
function CallbackErrorResponse(Context,Message)
{
    Context.Callback( new CallbackExceptionObject(Message) );
}
function GetXmlHttp() 
{
 	var Http = null;
	if (typeof XMLHttpRequest != "undefined") 
    {
		Http = new XMLHttpRequest();
	}
    else 
    {
		try 
        {
			Http = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) 
        {
			try 
            {
				Http = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {}
		}
	}
	return Http;
}
function GetServerUrl(Context) 
{
    if (Context == null)
        return;

    if (Context.LastMouseTop == -1)
		return;
		
    try 
    {   
        var Http = GetXmlHttp();
        if (Http == null)
        {
            CallbackErrorResponse(Context,'Unable to create XmlHttp object');
            return;
        }
        Context.Http = Http;

        if (Context.Callback)
            Http.onreadystatechange = eval(Context.ControlId + '_HandleCallback');

        if (Context.PostBackMode != 'GET')
        {
            Http.open('POST',Context.Url,Context.Async);	
            Context.Async = true;
            Http.setRequestHeader('Pragma','no-cache');
            Http.setRequestHeader('Content-type','application/x-www-form-urlencoded');

            var PostBuffer = '';
            if (Context.PostBackMode != 'POSTMethodParametersOnly')
                PostBuffer = EncodeFormVars(Context);
            else
                PostBuffer = '__WWEVENTCALLBACK=' + Context.ControlId + '&';
            
            if (Context.PostData)
                PostBuffer = PostBuffer + Context.PostData;
                    
            Http.setRequestHeader('Content-length',PostBuffer.length.toString() );
            Http.send(PostBuffer);
        }
        else 
        {
		    Http.open('GET',Context.Url,Context.Async);	
		    Context.Async = true;
            Http.setRequestHeader('Pragma','no-cache');
		    Http.send(null);
        }
    }
    catch( e )
    {
        CallbackErrorResponse(Context,"XmlHttp Error: " + e.Message);
    } 
}
function EncodeFormVars(Context) 
{
    var PostData = '__WWEVENTCALLBACK=' + Context.ControlId + '&';
    
   Form = document.forms[Context.FormName]; 
    if (Form == null)
        Form = document.forms[0];
    if (Form == null)
        return PostData;

    var count = Form.length;
    var element;

    for (var i = 0; i < count; i++) 
    {
        element = Form.elements[i];
        var tagName = element.tagName.toLowerCase();
        if (tagName == 'input') 
        {
            var type = element.type;
            
            if (Context.PostBackMode == 'POSTNoViewstate')
            {
                // *** Don't send ASP.NET gunk
                if (element.name == '__VIEWSTATE' || element.name == '__EVENTTARGET' || 
                    element.name == '__EVENTARGUMENT' || element.name == '__EVENTVALIDATION')
                    continue;
            }
            if (type == 'text' || type == 'hidden' || type == 'password' ||
               ((type == 'checkbox' || type == 'radio') && element.checked  )) 
                PostData += element.name + '=' + EncodeValue(element.value) + '&';
        }
        else if (tagName == 'select') 
        {
            if (element.options == null)
                continue;
            var selectCount = element.options.length;
            for (var j = 0; j < selectCount; j++) 
            {
                var selectChild = element.options[j];
                if (selectChild.selected) 
                    PostData += element.name + '=' + EncodeValue(selectChild.value) + '&';
            }
        }
        else if (tagName == 'textarea') 
            PostData += element.name + '=' + EncodeValue(element.value) + '&';
    }
    return PostData;
}
function EncodeValue(parameter) {
    if (encodeURIComponent) 
        return encodeURIComponent(parameter);
    return escape(parameter);
}

/*
Copyright (c) 2005 JSON.org
Modifications by Rick Strahl
----------------------------
* Added support for dates in object parser

    The global object JSON contains two methods.

    JSON.stringify(value) takes a JavaScript value and produces a JSON text.
    The value must not be cyclical.

    JSON.parse(text) takes a JSON text and produces a JavaScript value. It will
    return false if there is an error.
*/
var JSON = {
    copyright: '(c)2005 JSON.org',
    license: 'http://www.crockford.com/JSON/license.html',
/*
    Stringify a JavaScript value, producing a JSON text.
*/
    serialize: function (v) {
        var a = [];
/*
    Emit a string.
*/
        function e(s) {
            a[a.length] = s;
        }

/*
    Convert a value.
*/
        function g(x) {
            var b, c, i, l, v;

            switch (typeof x) {
            case 'string':
                e('"');
                if (/["\\\x00-\x1f]/.test(x)) {
                    l = x.length;
                    for (i = 0; i < l; i += 1) {
                        c = x.charAt(i);
                        if (c >= ' ') {
                            if (c == '\\' || c == '"') {
                                e('\\');
                            }
                            e(c);
                        } else {
                            switch (c) {
                            case '\b':
                                e('\\b');
                                break;
                            case '\f':
                                e('\\f');
                                break;
                            case '\n':
                                e('\\n');
                                break;
                            case '\r':
                                e('\\r');
                                break;
                            case '\t':
                                e('\\t');
                                break;
                            default:
                                c = c.charCodeAt();
                                e('\\u00' +
                                    Math.floor(c / 16).toString(16) +
                                    (c % 16).toString(16));
                            }
                        }
                    }
                } else {
                    e(x);
                }
                e('"');
                return;
            case 'number':
                e(isFinite(x) ? x : 'null');
                return;
            case 'object':
                if (x) {
                    // RAS: Added Date Parsing
                    if (x.toUTCString) 
                       return e('new Date(' +  x.getUTCFullYear() + ',' + x.getUTCMonth() + ',' + x.getUTCDate() + ',' + x.getUTCHours() + ',' + x.getUTCMinutes() + ',' + x.getUTCSeconds() + ',' + x.getUTCMilliseconds() + ')' );

                    if (x instanceof Array) {
                        e('[');
                        l = a.length;
                        for (i = 0; i < x.length; i += 1) {
                            v = x[i];
                            if (typeof v != 'undefined' &&
                                    typeof v != 'function') {
                                if (b) {
                                    e(',');
                                }
                                g(v);
                                b = true;
                            }
                        }
                        e(']');
                        return;
                    } else if (typeof x.valueOf == 'function') {
                        e('{');
                        l = a.length;
                        for (i in x) {
                            v = x[i];
                            if (typeof v != 'undefined' &&
                                    typeof v != 'function' &&
                                    (!v || typeof v != 'object' ||
                                    typeof v.valueOf == 'function')) {
                                if (b) {
                                    e(',');
                                }
                                g(i);
                                e(':');
                                g(v);
                                b = true;
                            }
                        }
                        return e('}');
                    }
                }
                e('null');
                return;
            case 'boolean':
                e(x);
                return;
            default:
                e('null');
                return;
            }
        }
        g(v);
        return a.join('');
    },
/*
    Parse a JSON text, producing a JavaScript value.
    It returns false if there is a syntax error.
*/
    parse: function (text) {
        try {
            return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
                    text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
                    eval('(' + text + ')');
        } catch (e) {
            return false;
        }
    }
};
