

if ( !instore ) var instore = {};

instore.BigEditField = function() {};
instore.BigEditField.prototype = {
    opened: false,
    oldfield: null,
    editDiv: null,
    editField: null,
    
    open: function(field, title) {  // Open with title
       this.init();
       if ( this.opened && field != this.oldfield) {
        this.close();
       }
       if ( $(field) ) {
          this.editDiv.clonePosition($(field));
          this.opened=true;
          this.oldfield=field;
          this.editDiv.show();
          this.editField.value=$(field).value;
          $('bigEdithtdTitle').update(title);
          this.editField.focus();
          //alert("open for " + field);
       }
    },
    
    close: function() { // Close
        if ( $(this.oldfield) ) {
            $(this.oldfield).value=this.editField.value;
            this.editDiv.hide();
            this.opened=false;
        }
    },

    closekey: function(event) {
        if ( event.keyCode == 27 ) { // If escape pressed, then close
            if ( $(this.oldfield) ) {
                $(this.oldfield).value=this.editField.value;
                this.editDiv.hide();
                this.opened=false;
            }
        } 
    },
    
    init: function() {     // init is run once through open
        if ( !this.editField && !this.editDiv) { 
            //alert("Init");
            this.editDiv=new Element("div");
            this.editDiv.setStyle('float: none; position: absolute; top: 3px; right: 0px');
            var editTable=new Element("table",{'class': 'application_cv', 'border': '0', 'cellpadding': '0'});            
            var thead=new Element("thead");
            var tfoot=new Element("tfoot");
            var tbody=new Element("tbody");
            var htr=new Element("tr");
            var htd=new Element("td",{'colspan':3});
            var htd1=new Element("div",{'style': 'float: left', 'id': 'bigEdithtdTitle'});
            var htd2=new Element("div",{'style': 'float: right'});
            var img=new Element("img",{'src': '/instruments/images/buttons/minimize.gif;jsessionid=D2C7517C39F9DEBBCEAAB92CB47B121D.worker3b'});
            htd2.update(img);
            htd.appendChild(htd1);
            htd.appendChild(htd2);
            
            var ftr=new Element("tr");
            var ftd=new Element("td",{'colspan':3}).update("&nbsp");
            htr.appendChild(htd);
            thead.appendChild(htr);
            ftr.appendChild(ftd);
            tfoot.appendChild(ftr);
            editTable.appendChild(thead);            
            var tr=new Element("tr",{'class': 'cv_right'});
            var tdl=new Element("td",{'width':'5%'}).update("&nbsp");
            var tdr=new Element("td",{'width':'5%'}).update("&nbsp");
            var td=new Element("td",{'width':'90%'});            

            this.editField=new Element("textarea"); 
            this.editField.cols="80";
            this.editField.rows="25";
            td.appendChild(this.editField);
            tr.appendChild(tdl);
            tr.appendChild(td);            
            tr.appendChild(tdr);
            tbody.appendChild(tr);
            editTable.appendChild(tbody);                        
            editTable.appendChild(tfoot);
            
            this.editDiv.appendChild(editTable);
            document.body.appendChild(this.editDiv);
            this.editDiv.hide();
            // Event Listeners for blur and keydown (ESC)
            Event.observe(this.editField, 'blur', this.close.bindAsEventListener(this));
            Event.observe(this.editField, 'keydown', this.closekey.bindAsEventListener(this));
        }
    }
    
    
}


