function ImageUploader(div, options)
{
    this.resetfunctions = function()
    {
        this.onError = function(){};
        this.onComplete = function(){};

    }

    this.upload = function() {
        uploadDir=this.input.value;
        var self = this;

        this.filename = uploadDir.substr(uploadDir.lastIndexOf('\\')+1);

        this.form.submit();
        this.description.disable();
        this.input.disable();
        //this.span.deleteChild(this.input);
        //this.span.appendChild(this.progress);

        var t_img = document.createElement('img');
        t_img.setAttribute('src' , this.options.image);
        t_img.setAttribute('alt', "Loading....");
        widthto('280', t_img);
        heightto('13', t_img);
        this.img_span.appendChild(t_img);
        this.images.push(t_img);

        this.timer = new Timer();
        this.timer.interval(1000);
        this.timer.addCallback(function(){self.traceUpload(self);});
        this.timer.addCallback(function(){self.timeOut(self);}, 25);
        this.timer.start();
    }

    this.handleResponse = function(a) {
        var response=a.response;
        if(response.indexOf(this.filename) != -1)
        {
            //d.src = "/images/tmp/mini-"+this.filename;
            //d.width = 100;
            //d.height= 100;
            this.images[this.images.length-1].setAttribute('src', this.options.server+response);
            this.images[this.images.length-1].setAttribute('alt', this.options.server+response);
            widthto('100', this.images[this.images.length-1]);
            heightto('100', this.images[this.images.length-1]);
            this.Success = true;
            this.timer.stop();
            this.onComplete('File Uploaded: '+ this.filename);
            if(this.options.multiple)
            {
                this.description.enable();
            }
        }else if(response.indexOf("Error") != -1)
        {
            this.images[this.images.length-1].alt = response;
            this.images[this.images.length-1].src = '';
            this.success = true;
            this.timer.stop();
            this.onError("Error: "+response);
        }
    }

    this.isMultiple = function(val)
    {
        this.options.multiple = val;
        if(val == true){
            this.description.enable();
        } else {
            if(this.images.length > 0){
                this.description.disable();
            } else {
                this.description.enable();
            }
        }
    };

    this.traceUpload = function (self) {
            var a = new sack();
            a.requestFile = this.options.uploadHndler+'?filename='+self.filename;
            a.setVar('uploader', 'true');
            a.setVar('PropertyID', this.options.ID);
            a.setVar('filename', self.filename);
            a.onCompletion = function(){self.handleResponse(a);};
            a.onError = function(msg){self.timeOut();self.onError(msg);};
            a.onFail = function(msg){self.timeOut();self.onError(msg);};
            a.runAJAX();
    }

    this.timeOut = function(self)
    {
        if(self){
            self = self
        } else {
            self = this;
        }
        if(!this.Success)
        {
            this.img_span.innerHTML="Upload Timed Out.";
            //this.img_span.innerHTML="";
        }
        self.timer.stop();
        if(self.options.multiple)
        {
            self.input.enable();
        }
    }
    /* Private Functions -----------------------------------------------------------------------------*/
    //MoveDiv(x,y) - moves the calenderDiv to the correct.
    var self = this;
    if (typeof(Timer) == "undefined"){
        Navigator.loadJavaScript("java/timer.js", "")
    }

    this.div = div;
    this.images = new Array();

    this.options = options;
    this.id = random(0, 100);
    this.form = document.createElement('form');
    this.form.action = this.options.uploadHndler;
    this.form.enctype = "multipart/form-data";
    this.form.target="iframeImage"+this.id;
    this.form.method="post";
    this.form.id="Image"+this.id;
    this.form.className ="";
    this.form.innerHTML = "<label>"+this.options.header+"</label>";
    this.input = document.createElement('input');
    this.input.setAttribute("type",  "file");
    this.input.setAttribute('name' , "Image");
    Element.extend(this.input);
    this.input.disable();

    this.description = document.createElement('input');
    this.description.setAttribute("type",  "textarea");
    this.description.setAttribute('name' , "Description");
    Element.extend(this.input);
    addEvent(this.description, "keyup", function(){ if(this.value != ''){self.input.enable();} else {self.input.disable();} });

    var pid = document.createElement('input');
    pid.type = "Hidden";
    pid.value = this.options.ID;
    pid.name = "PropertyID";
    this.span =  document.createElement('div');
    this.img_span =  document.createElement('span');
    this.div.appendChild(this.span);

    this.span.appendChild(this.img_span);
    this.span.appendChild(this.form);

    this.form.innerHTML = this.form.innerHTML+"</br>Picture Description: ";
    this.form.appendChild(this.description);
    this.form.appendChild(pid);
    this.form.appendChild(this.input);


    this.iframe = document.createElement('iframe');
    Element.extend(this.iframe);
    this.iframe.hide();

    this.iframe.src=this.options.uploadHndler;
    this.iframe.name="iframeImage"+this.id;

    this.form.appendChild(this.iframe);

    addEvent(this.input, 'change', function(){self.upload();});
    this.resetfunctions();

}


