﻿

DataFloat.Agora.CustomDropBox = function(destinationCombo, clearCombo){
            //Variables
            this.DestinationCombo = destinationCombo;
            this.WaitItem = new Option('Loading...', -1);
            this.DefaultItem = new Option('All', -1);
            this.TextItem = "Text";
            this.ValueItem = "Value";
            //Variables
            if (clearCombo)
                this.DestinationCombo.length = 0;
}
    
DataFloat.Agora.CustomDropBox.prototype.PopulateCombo = function(objCollection, clearCombo){
    if (this.DestinationCombo != null){
            
                if (clearCombo || clearCombo == undefined)
                    this.DestinationCombo.length = 0;
                
                
                if (this.DefaultItem != null)
                    this.DestinationCombo[this.DestinationCombo.length] = this.DefaultItem;

                for (objCombo=0; objCombo< objCollection.length; objCombo++){
                    this.DestinationCombo[this.DestinationCombo.length] = new Option(unescape(eval("objCollection[objCombo]." + this.TextItem)), unescape(eval("objCollection[objCombo]." + this.ValueItem)), '', '');
                }
            }
}

DataFloat.Agora.CustomDropBox.prototype.ValueExists = function(value){
    for (iV = 0; iV < this.DestinationCombo.length; iV++){
        if (this.DestinationCombo.options[iV].value == value)
            return true;
    }
    return false;
}

DataFloat.Agora.CustomDropBox.prototype.MoveUp = function(){
  element = this.DestinationCombo;
  for(i = 0; i < element.options.length; i++) {
    if(element.options[i].selected == true) {
      if(i != 0) {
        var temp = new Option(element.options[i-1].text,element.options[i-1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i-1] = temp2;
        element.options[i-1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
DataFloat.Agora.CustomDropBox.prototype.MoveDown = function() {
  element = this.DestinationCombo;
  for(i = (element.options.length - 1); i >= 0; i--) {
    if(element.options[i].selected == true) {
      if(i != (element.options.length - 1)) {
        var temp = new Option(element.options[i+1].text,element.options[i+1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i+1] = temp2;
        element.options[i+1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}

DataFloat.Agora.CustomDropBox.prototype.TextToArray = function(){
    element = this.DestinationCombo;
    var arrResult = new Array();
    for(i = 0; i < element.options.length; i++) {
        arrResult.push(element.options[i].text);
    }
    return arrResult;
}

DataFloat.Agora.CustomDropBox.prototype.AddItem = function(value, text){
    this.DestinationCombo[this.DestinationCombo.length] = new Option(text, value, '', '');
}

DataFloat.Agora.CustomDropBox.prototype.WaitToLoad = function(){
    this.DestinationCombo.length = 0;
    this.DestinationCombo[this.DestinationCombo.length] = this.WaitItem;
    this.DestinationCombo.disabled = true;
}

DataFloat.Agora.CustomDropBox.prototype.ReadyToGo = function(){
    this.DestinationCombo.disabled = false;
}
            
        
