function Image(){
 
    this.replace = function(pExistingImageID, pImageURL, wid, hei){
        var a = document.getElementById('a_' + pExistingImageID);
        a.setAttribute("href", "javascript:popitup('" + pImageURL + "')");
        
        var img = document.createElement('img');
        img.onload = function(evt){
            try {
                document.getElementById(pExistingImageID).src = this.src;
                
                if (wid < 0 || hei < 0) {
                    document.getElementById(pExistingImageID).width = this.width;
                    document.getElementById(pExistingImageID).height = this.height;
                }
                else {
                    document.getElementById(pExistingImageID).width = wid;
                    document.getElementById(pExistingImageID).height = hei;
                }
            } 
            catch (e) {
                alert(e.description);
            }
        }
        img.src = pImageURL;
        
        return true;
    }
    
    this.append = function(pElem, pImageURL, wid, hei, id, label,link_to){
        var par = document.createElement('p');
        
        par.setAttribute('title', 'img');
        var app = document.createElement('a');

		if (link_to)
                     app.setAttribute("href", "javascript:link_open('" + link_to + "')");
		else
                     app.setAttribute("href", "javascript:popitup('" + pImageURL + "')"); 
		
		app.setAttribute("id", "a_img_" + id);
        
        var img = document.createElement('img');
        img.setAttribute('id', 'img_' + id);
        img.setAttribute('title', label);
        img.setAttribute('alt', 'alt');
        img.label = label;
        img.onload = function(evt){
            par.appendChild(app);
            app.appendChild(img);        
            document.getElementById(pElem).appendChild(par);
    
            if (wid < 0 || hei < 0) {
                img.width = this.width;
                img.height = this.height;
            }
            else {
                img.width = wid;
                img.height = hei;
            }
        }
        img.src = pImageURL;
        return false;
    }
	
    
}

