/*
 * Author: Vertex Logic, Inc
 * Copyright 2005, 2006, 2007 - All rights reserved
 *
 * Vertex Logic, Inc., California, USA 
 *
 * Vertex Logic grants you ("Licensee") a non-exclusive license to use
 * and modify this source and recompile it in
 * accordance with the terms of the Agreement under which this software is bought
 * and provided that (i) this copyright notice appear on all copies of the Software; 
 * (ii) Licensee does not sale the software as is or with modification without
 * the prior consent of Vertex Logic. (iii) Licensee agrees that it does not have any 
 * title or ownership of the Software.
 *
 * The program is provided "as is" without any warranty express or
 * implied, including the warranty of non-infringement and the implied
 * warranties of merchantibility and fitness for a particular purpose.
 * Vertex Logic will not be liable for any damages suffered 
 * by you as a result of using the Program. 
 * In no event will Vertex Logic be liable for any
 * special, indirect or consequential damages or lost profits even if
 * Vertex Logic have been advised of the possibility of their occurrence. 
 * Vertex Logic will not be liable for any third party claims against you.
 */
 Af.HtmlMultiSelect = Class.create();

Af.HtmlMultiSelect.prototype = {


	initialize: function(selectId, attrName) {
		this.selectId = selectId;
		this.attrName = attrName;
		this.selectElement = document.getElementById(this.selectId);
		this.dlist = null;
	},

	 setDataList: function(dlist) {
	    this.dlist = dlist;
	    if (this.dlist == null) {
	       this.dlist = new Array();
	    }
	    
	    this.selectElement.options.length = 0;
	    
	    for (var i=0; i<this.dlist.length; i++) {
	       var o = this.dlist[i];
		   var oe = document.createElement("option");
		   oe.value= "" + i;
		   oe.label = o[this.attrName];
		   oe.appendChild(document.createTextNode(oe.label));
		   this.selectElement.appendChild(oe);
	    }
	   
	 },
	 
	 
	 getSelectedObjs: function() {
	    var l = new Array();
	    if (this.dlist == null) {
	       return l;
	    }
	    for (var i=0; i<this.selectElement.options.length; i++) {
	       var option = this.selectElement.options[i];
	       if (option.selected) {
	          l.push(this.dlist[i]);
	       }
	    }
	    return l;
	 }
	 
}

