function Ajax()
{

    this.getHTTPObject = function()
    {
        var xmlhttp = false;
        if (window.ActiveXObject)
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        else if (window.XMLHttpRequest)
            xmlhttp = new XMLHttpRequest();
        return xmlhttp;
    }

    this.processReturnData = function(ajaxResponse)
    {
//        for (var i = 0; i < ajaxResponse.childNodes.length; i++)
//        {
//            switch (ajaxResponse.childNodes[i].nodeName)
//            {
//                case "update":
//                    var update    = ajaxResponse.childNodes[i];
//                    var type      = update.attributes[0].value;
//                    var field     = update.childNodes[0].firstChild.nodeValue;
//                    var attribute = update.childNodes[0].attributes[0].value;
//                    var value     = update.childNodes[1].firstChild.nodeValue;
//                    //alert(value);
//                    eval("document.getElementById('"+field+"')."+attribute+" = '"+value+"';");
//                break;
//                case "javascript":
//                    eval(ajaxResponse.childNodes[i].nodeValue);
//                break;
//            }
//        }
    }


    this.ajaxFunction = function(funct, args, typeName, typeLogo, typeId, searchFor)
    {
        var xmlhttp = this.getHTTPObject();
        xmlhttp.open("POST", funct+".php?"+args, true);
        xmlhttp.onreadystatechange = function()
        {
            if (xmlhttp.readyState == 4){
                if (xmlhttp.status == 200){

                    try
                    {
                        //alert(xmlhttp.responseXML.getElementsByTagName("ajax"));
                        var ajaxResponse = xmlhttp.responseXML.getElementsByTagName("ajax")[0];
                        for (var i = 0; i < ajaxResponse.childNodes.length; i++)
                        {
                            switch (ajaxResponse.childNodes[i].nodeName)
                            {
                                case "update":
                                    var update    = ajaxResponse.childNodes[i];
                                    var type      = update.attributes[0].value;
                                    var field     = update.childNodes[0].firstChild.nodeValue;
                                    var attribute = update.childNodes[0].attributes[0].value;
                                    var value     = update.childNodes[1].firstChild.nodeValue;
                                    eval("document.getElementById('"+field+"')."+attribute+" = '"+value+"';");
                                break;
                                case "javascript":
                                     eval(ajaxResponse.childNodes[i].firstChild.nodeValue);
                                break;
                                case "nextSearch":
                                     eval("addResultRow("+typeId+", "+ajaxResponse.childNodes[i].firstChild.nodeValue+", '"+typeLogo+"', '"+typeName+"', '"+searchFor+"');")
                                break;
                            }
                        }
                    }
                    catch(err)
                    {
                        searchOne();
                    }

                }
                else
                {
                    searchOne();
                }

            }
        }
        xmlhttp.send(null);
    }

    this.updateMyIabFunction = function(funct, args, refreshURL)
    {
        //alert(loading_div);
        var xmlhttp = this.getHTTPObject();
        xmlhttp.open("POST", funct+".php?"+args, true);
        xmlhttp.onreadystatechange = function()
        {
            if (xmlhttp.readyState == 4){
                if (xmlhttp.status == 200){
                    document.getElementById("pidy_preview").src = "my_iab_pidy_iframe.php?"+(Math.round((Math.random()*9)+1));
                }
            }
        }
        xmlhttp.send(null);
    }
}
