/* Не закончен класс на аяксе для загрузки изображений */

function ImageControl(oImagebox, oImageComment, oImagebut, oProvider) {
    this.provider = oProvider;
    this.imagebox = oImagebox;
    this.imagebut = oImagebut;
    this.timeoutId = null;
    this.initImage();
}

ImageControl.prototype.initImage = function () {

    var oThis = this;

    this.imagebut.onclick = function (oEvent) {
        if (!oEvent) {
            oEvent = window.event;
        }
        oThis.handleOnClick(oEvent);
    };
};


ImageControl.prototype.handleOnClick = function (oEvent /*:Event*/) {
    var oThis = this;

    clearTimeout(this.timeoutId);
        this.timeoutId = setTimeout( function () {
            oThis.provider.requestSuggestions(oThis, false);
        }, 250);
};



function UploadImage() {
    this.http = zXmlHttp.createRequest();
}

UploadImage.prototype.requestSuggestions = function (oImageControl) {
    var oHttp = this.http;

    if (oHttp.readyState != 0) {
        oHttp.abort();
    }

    var oData = {
        img: oImageControl.imagebox.value
    };

    oHttp.open("post", "/loadimg.php", true);
    oHttp.onreadystatechange = function () {
        if (oHttp.readyState == 4) {
            //evaluate the returned text JavaScript (an array)
            alert(oHttp.responseText);
            var aSuggestions = JSON.parse(oHttp.responseText);
            //provide suggestions to the control
            //oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
        }
    };
    oHttp.send(JSON.stringify(oData));
};