﻿this.Base = new function()
{
    this.addEvent = function(objElement, strEvent, objExpression, blnCaptureEvent)
    {
        blnCaptureEvent = blnCaptureEvent || false;

        this.removeEvent(objElement, strEvent, objExpression, blnCaptureEvent);

        if (window.addEventListener)
            objElement.addEventListener(strEvent, objExpression, blnCaptureEvent);
        else
            objElement.attachEvent('on' + strEvent, objExpression);
    }

    this.removeEvent = function(objElement, strEvent, objExpression, blnCaptureEvent)
    {
        if (window.removeEventListener)
            objElement.removeEventListener(strEvent, objExpression, blnCaptureEvent);
        else
            objElement.detachEvent('on' + strEvent, objExpression);
    }
}

this.Ajax = new function()
{
    this.xmlHttpRequest = function(strXmlSource, objCallBack)
    {
        var objXmlHttp = null;

        if (window.XMLHttpRequest)
            objXmlHttp = new XMLHttpRequest();
        else if (window.ActiveXObject)
            objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        else
            alert('Your browser does not support AJAX.');

        objXmlHttp.onreadystatechange = function()
        {
            checkRequestData(objXmlHttp, objCallBack);
        }

        objXmlHttp.open('GET', strXmlSource, true)
        objXmlHttp.send(null);
    }

    function checkRequestData(objXmlHttp, objCallBack)
    {
        if (objXmlHttp.readyState == 4)
        {
            if (objXmlHttp.status == 200)
            {
                if (objXmlHttp.responseText != "")
                {
                    var objErrorNode = objXmlHttp.responseXML.getElementsByTagName("error");

                    if (objErrorNode.length > 0)
                    {
                        alert(objErrorNode[0].firstChild.nodeValue);
                    }
                }

                if (objCallBack)
                    objCallBack(objXmlHttp);
            }
            else
                alert("XmlHttpRequest failed. Request status: " + objXmlHttp.status + " " + objXmlHttp.statusText);
        }
    }
}
