﻿// JScript File
// define the core ajax object

/*
    example of reply processor

        var req=this._ajax.getChannel()
        if (req.readyState == 4) 
        {
            if (req.status == 200) 
            {
                var status=this._ajax.getXmlVal(req.responseXML.getElementsByTagName('status'))
                if (status=="ok")
                {
                    this.show(this._currentsearch)
                }
                else
                {
                    var error=this._ajax.getXmlVal(req.responseXML.getElementsByTagName('error'))
                    error=error.replace("\\n","\n")
                    alert(error)
                }
            }
            else
            {
                alert('error\n'+req.responseText)
            }
        }
    
*/



var _ajaxcore_init=true
function ajaxCore()
{
    this._req;
    this._querystring
    this.init = function()
    {
        if (window.XMLHttpRequest)
        {
	        // If IE7, Mozilla, Safari, etc: Use native object
	        this._req = new XMLHttpRequest()
        }
        else 
        {
	        if (window.ActiveXObject)
	        {
		        // ...otherwise, use the ActiveX control for IE5.x and IE6
		        this._req = new ActiveXObject("Microsoft.XMLHTTP"); 
	        }
        }
    }
    this.putData = function(url,formData,callBackFunction)
    {
        this.init()
        this._req.onreadystatechange=callBackFunction
        this._querystring=url
        this._req.open("PUT",url+"&sid="+Math.random(),true)
        this._req.send(formData)
    }
    
    this.getData = function(url,callBackFunction)
    {
        this.init()
        this._req.onreadystatechange=callBackFunction
        this._querystring=url
        this._req.open("GET",url+"&sid="+Math.random(),true)
        this._req.send("")
    }
    this.getChannel = function()
    {
        return this._req
    }
    this.getXmlVal = function (element)
    {
        try
        {
        if (element[0].firstChild==undefined)
            return ""
        return element[0].firstChild.nodeValue
        }
        catch(e){}
        return ""
    }
}
