function MyOption(name,value,selected,optionIsSet,option2IsSet,option2Valid){ this.name=name; this.value=value; this.selected=selected; this.optionIsSet=optionIsSet; if(option2IsSet==null) option2IsSet=false; this.option2IsSet=option2IsSet; if(option2Valid==null) option2Valid=false; this.option2Valid=option2Valid;} function myOptionSort(a,b){ result=0; if(a.name<b.name){ result=-1;}else{ result=1;} return result;} function MySelectBox(){ this.unSelectedOptions=new Array(); this.selectedOptions=new Array(); this.unSelectedBoxSorted=true; this.optionsEnabled=false; this.optionsEnabled2=false; this.optionsElement=null; this.optionsElement2=null; this.addOption=addOption; this.fillSelectBoxUnselected=fillSelectBoxUnselected; this.fillSelectBoxSelected=fillSelectBoxSelected; this.sortUnselectedBox=sortUnselectedBox; this.clearBox=clearBox; this.selectOptions=selectOptions; this.removeOptions=removeOptions; this.addKey=addKey; this.removeKey=removeKey; this.moveUp=moveMyOptionUp; this.moveDown=moveMyOptionDown; this.saveData=saveData; this.enableOptions=enableOptions; this.enableOptions2=enableOptions2; this.setOptionsBox=setOptionsBox; this.setOptionsBox2=setOptionsBox2; this.optionsBoxClick=optionsBoxClick; this.optionsBox2Click=optionsBox2Click; this.findOption=findOption; this.drawOptionsBox=drawOptionsBox; this.drawOptionsBox2=drawOptionsBox2;} function setOptionsBox(source){ if(this.optionsEnabled){ for(i=0;i<source.options.length;i++){ if(source.options[i].selected){ theOption=this.findOption(source.options[i].value,this.selectedOptions); if(theOption.optionIsSet){ this.drawOptionsBox(1); return true;}else{ this.drawOptionsBox(0); return true;}}} this.drawOptionsBox(2);}} function setOptionsBox2(source){ if(this.optionsEnabled2){ for(i=0;i<source.options.length;i++){ if(source.options[i].selected){ theOption=this.findOption(source.options[i].value,this.selectedOptions); if(!theOption.option2Valid){ this.drawOptionsBox2(2); return true;}else if(theOption.option2IsSet){ this.drawOptionsBox2(1); return true;}else{ this.drawOptionsBox2(0); return true;}}} this.drawOptionsBox2(2);}} function drawOptionsBox(state){ if(state==2){ this.optionsElement.disabled=true; this.optionsElement.checked=false;}else{ this.optionsElement.disabled=false; checked=(state==1); this.optionsElement.checked=checked;}} function drawOptionsBox2(state){ if(state==2){ this.optionsElement2.disabled=true; this.optionsElement2.checked=false;}else{ this.optionsElement2.disabled=false; checked=(state==1); this.optionsElement2.checked=checked;}} function findOption(key,haystack){ for(k=0;k<haystack.length;k++){ if(haystack[k].value==key) return haystack[k];}} function optionsBoxClick(source){ theOption=this.findOption(source.options[source.options.selectedIndex].value,this.selectedOptions); theOption.optionIsSet=!theOption.optionIsSet; return true;} function optionsBox2Click(source){ theOption=this.findOption(source.options[source.options.selectedIndex].value,this.selectedOptions); theOption.option2IsSet=!theOption.option2IsSet; return true;} function enableOptions(optionsElement){ this.optionsEnabled=true; this.optionsElement=optionsElement;} function enableOptions2(optionsElement){ this.optionsEnabled2=true; this.optionsElement2=optionsElement;} function moveMyOptionDown(source){ max=source.options.length; for(i=max-1;i>=0;i--){ if(source.options[i].selected&&i<max-1){ swapMyOptions(source,i,i+1); myKey=this.selectedOptions[i]; this.selectedOptions[i]=this.selectedOptions[i+1]; this.selectedOptions[i+1]=myKey;}}} function moveMyOptionDownBrowseDef(source){ max=source.options.length; for(i=max-1;i>=0;i--){ if(source.options[i].selected&&i<max-1){ swapMyOptions(source,i,i+1);}}} function moveMyOptionUp(source){ max=source.options.length; for(i=0;i<max;i++){ if(source.options[i].selected&&i>0){ swapMyOptions(source,i,i-1); myKey=this.selectedOptions[i]; this.selectedOptions[i]=this.selectedOptions[i-1]; this.selectedOptions[i-1]=myKey;}}} function moveMyOptionUpBrowseDef(source){ max=source.options.length; for(i=0;i<max;i++){ if(source.options[i].selected&&i>0){ swapMyOptions(source,i,i-1);}}} function selectOptions(source,target){ for(j=0;j<source.options.length;j++){ if(source.options[j].selected){ this.addKey(source.options[j].value);}} this.clearBox(source); this.clearBox(target); this.fillSelectBoxSelected(target); this.fillSelectBoxUnselected(source);} function saveData(source,saveToField,saveLinksToField,saveOptions2ToField){ linksString=''; options2String=''; if(source.options.length>0){ saveString=''; for(j=0;j<source.options.length;j++){ if(saveString.length>0){ saveString=saveString+',';} if(source.options[j].value.indexOf(' ')>-1){ source.options[j].value='"'+source.options[j].value+'"';} saveString=saveString+source.options[j].value; if(this.optionsEnabled){ theOption=this.findOption(source.options[j].value,this.selectedOptions); if(theOption!=undefined){ if(theOption.optionIsSet){ if(linksString.length>0){ linksString=linksString+',';} linksString=linksString+source.options[j].value;} } } if(this.optionsEnabled2){ theOption=this.findOption(source.options[j].value,this.selectedOptions); if(theOption!=undefined){ if(theOption.option2IsSet){ if(options2String.length>0){ options2String=options2String+',';} options2String=options2String+source.options[j].value;} } }}}else{ saveString='-1';} saveToField.value=saveString; if(this.optionsEnabled) saveLinksToField.value=linksString; if(this.optionsEnabled2) saveOptions2ToField.value=options2String;} function removeOptions(source,target){ for(j=0;j<source.options.length;j++){ if(source.options[j].selected){ this.removeKey(source.options[j].value);}} this.clearBox(source); this.clearBox(target); this.fillSelectBoxSelected(source); this.fillSelectBoxUnselected(target);} function addKey(key){ for(i=0;i<this.unSelectedOptions.length;i++){ if(this.unSelectedOptions[i].value==key){ this.selectedOptions[this.selectedOptions.length]=this.unSelectedOptions[i]; this.unSelectedOptions=removeArrayElement(i,this.unSelectedOptions); return 1;}}} function removeKey(key){ for(i=0;i<this.selectedOptions.length;i++){ if(this.selectedOptions[i].value==key){ this.unSelectedOptions[this.unSelectedOptions.length]=this.selectedOptions[i]; this.selectedOptions=removeArrayElement(i,this.selectedOptions); return 1;}}} function removeArrayElement(nr,myArray){ for(x=nr;x<myArray.length-1;x++){ myArray[x]=myArray[x+1];} myArray.length+=-1; return myArray;} function addOption(name,value,selected,optionIsSet,option2IsSet,option2Valid){ if(option2IsSet==null) option2IsSet=false; if(selected==true){ this.selectedOptions[this.selectedOptions.length]=new MyOption(name,value,selected,optionIsSet,option2IsSet,option2Valid);}else{ this.unSelectedOptions[this.unSelectedOptions.length]=new MyOption(name,value,selected,optionIsSet,option2IsSet,option2Valid);}} function fillSelectBoxUnselected(selectBox){ if(this.unSelectedBoxSorted){ this.sortUnselectedBox();} for(i=0;i<this.unSelectedOptions.length;i++){ selectBox.options[i]=new Option(this.unSelectedOptions[i].name,this.unSelectedOptions[i].value,false,false);}} function fillSelectBoxSelected(selectBox){ for(i=0;i<this.selectedOptions.length;i++){ selectBox.options[i]=new Option(this.selectedOptions[i].name,this.selectedOptions[i].value,false,false);} if(this.optionsEnabled) this.setOptionsBox(selectBox); if(this.optionsEnabled2) this.setOptionsBox2(selectBox);} function sortUnselectedBox(){ this.unSelectedOptions.sort(myOptionSort);} function clearBox(selectBox){ selectBox.options.length=0;} function swapMyOptions(obj,i,j){ if(i!=-1){ var o=obj.options; var i_selected=o[i].selected; var j_selected=o[j].selected; var temp=new Option(o[i].text,o[i].value,o[i].defaultSelected,o[i].selected); var temp2=new Option(o[j].text,o[j].value,o[j].defaultSelected,o[j].selected); o[i]=temp2; o[j]=temp; o[i].selected=j_selected; o[j].selected=i_selected;}}