﻿// JScript File
function AJAX(url)
{
    this.url = url;
    this.httpRequest = false;
    this.Init();
}

AJAX.prototype.JSON = true;
AJAX.prototype.DEBUG = false;
AJAX.prototype.Init = function()
{
    if (window.XMLHttpRequest)
	{
		this.httpRequest = new XMLHttpRequest();
	}
	if (!this.httpRequest && window.ActiveXObject)
	{
		try
		{
			this.httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e) 
		{
			try
			{
				this.httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) 
			{ 
			    this.httpRequest = false; 
            }
		}
	}
	if(this.httpRequest)
	{
	    this.initialized = true;
    }
}

AJAX.OnReadyStateChange = function(ajax)
{
    if( ajax.httpRequest.readyState == 4)
    {
        if( ajax.httpRequest.status == 200)
        {
            if( ajax.DEBUG )
            {
                alert(ajax.httpRequest.responseText);
            }
            if( ajax.JSON)
            {
                var obj = eval( "(" + ajax.httpRequest.responseText + ")" );
                ajax.callback( obj );
            }
            else
            {
                ajax.callback(ajax.httpRequest.responseText);
            }
        }
        else
        {
            ajax.callback("Error Occured");
        }
    }
}

AJAX.prototype.GetSynch = function()
{
    this.httpRequest.open("GET", this.url, false);
    this.httpRequest.send(null);
    return this.httpRequest.responseText;
}
AJAX.prototype.PostSynch = function(data)
{
    this.httpRequest.open("POST", this.url, false);
    this.httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    this.httpRequest.send(data);
    return this.httpRequest.responseText;
}

AJAX.prototype.GetASynch = function(callback)
{
    this.callback = callback;
    var me = this;
    this.httpRequest.onreadystatechange = function() {AJAX.OnReadyStateChange(me);}
    this.httpRequest.open("GET", this.url, true);
    this.httpRequest.send(null);
}

AJAX.prototype.PostASynch = function(data, callback)
{
    this.callback = callback;
    var me = this;
    this.httpRequest.onreadystatechange = function() {AJAX.OnReadyStateChange(me);}
    this.httpRequest.open("POST", this.url, true);
    this.httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    this.httpRequest.send(data);
}


function getAbsoluteLeft(node){
    var left = 0;
    while(node.tagName != "BODY")
    {
        left += node.offsetLeft;
        node = node.offsetParent;
    }
    return left;
}
function getAbsoluteTop(node){
    var top = 0;
    while(node.tagName != "BODY")
    {
        top += node.offsetTop;
        node = node.offsetParent;
    }
    return top;
}
