function ChooseFrom_ChooseFromSource(name) {
	__chooseFroms[name].ChooseFromSource();	
}

function ChooseFrom_ChooseFromDest(name) {
	__chooseFroms[name].ChooseFromDest();
}

function ChooseFrom_Source() {
	curObj=eval("document.forms['"+this.form+"']."+this.name+"_source");
	for (i=0; i<curObj.length; i++) {
		if (curObj[i].selected) {
			this.source_options[curObj[i].value].bChosen=true;
			this.dest_options[curObj[i].value].bChosen=false;
		}
	}
	this.genForm();
	
	curObj=eval("document.forms['"+this.form+"']."+this.name);
	curObj.value=this.GetChosenOption();
}

function ChooseFrom_Dest() {
	curObj=eval("document.forms['"+this.form+"']."+this.name+"_dest");
	for (i=0; i<curObj.length; i++) {
		if (curObj[i].selected) {
			this.dest_options[curObj[i].value].bChosen=true;
			this.source_options[curObj[i].value].bChosen=false;
		}
	}
	this.genForm();


	curObj=eval("document.forms['"+this.form+"']."+this.name);
	curObj.value=this.GetChosenOption();
}

function ChooseFrom_GetChosenOption() {
	chosen="";
	for (i in this.dest_options) {
		if (this.dest_options[i].bChosen) continue;
		chosen+=this.dest_options[i].value+"###";
	}
	if (chosen.length > 0) {
		chosen=chosen.substring(0, chosen.length-3);
	}
	return chosen;
}

function ChooseFrom_InitSourceOptions(options) {
	this.source_options=new Array();
	for (i in options) {
		this.source_options[i]=new Object();
		this.source_options[i].value=i;
		this.source_options[i].prompt=options[i];
		this.source_options[i].bChosen=false;
	} 

	this.dest_options=new Array();
	for (i in options) {
		this.dest_options[i]=new Object();
		this.dest_options[i].value=i;
		this.dest_options[i].prompt=options[i];
		this.dest_options[i].bChosen=true;
	} 
}

function ChooseFrom_GenForm() {
	// source select
	src_select="<select name=\""+this.name+"_source\" multiple size=\""+this.size+"\" style=\""+this.style+"\">";
	for (i in this.source_options) {
		if (this.source_options[i].bChosen) continue;
		src_select+="<option value=\""+this.source_options[i].value+"\">"+this.source_options[i].prompt+"</option>";
	}
	src_select+="</select>";
	
	// select buttons
	select_btns ="<input type=\"button\" value=\" >> \" onclick=\"javascript:ChooseFrom_ChooseFromSource('"+this.name+"')\">";
	select_btns+="<br><br>";
	select_btns+="<input type=\"button\" value=\" << \" onclick=\"javascript:ChooseFrom_ChooseFromDest('"+this.name+"')\">";
	
	// dest select
	dest_select="<select name=\""+this.name+"_dest\" multiple size=\""+this.size+"\" style=\""+this.style+"\">";
	for (i in this.dest_options) {
		if (this.dest_options[i].bChosen) continue;
		dest_select+="<option value=\""+this.dest_options[i].value+"\">"+this.dest_options[i].prompt+"</option>";
	}
	dest_select+="</select>";
	dest_select+="<input type=\"hidden\" name=\""+this.name+"\">";
		
	result="<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	result+="<tr>";
	result+="<td>"+src_select+"</td>";
	result+="<td width=\"60\" align=\"center\">"+select_btns+"</td>";
	result+="<td>"+dest_select+"</td>";
	result+="</tr>";
	result+="</table>";

	document.all(this.renderArea).innerHTML=result;
}


var __chooseFroms=new Array();

function ChooseFrom(form, name, size, style, renderArea) {
	this.form=form;
	this.name=name;
	this.size=size;
	this.style=style;
	this.renderArea=renderArea;

	this.initSourceOptions=ChooseFrom_InitSourceOptions;
	this.genForm=ChooseFrom_GenForm;
	this.ChooseFromSource=ChooseFrom_Source;
	this.ChooseFromDest=ChooseFrom_Dest;
	this.GetChosenOption=ChooseFrom_GetChosenOption;
		
	__chooseFroms[name]=this;
}