function RemoveIskurParameterListBoxAllItems(listName, hiddenName)
{
    var list = document.getElementById(listName);
    var hidden = document.getElementById(hiddenName);
    
    if (list != null && hidden != null)
    {              
        while (list.options.length)
            list.remove(0);                              
                
        hidden.value = '';
        
        AdjustIskurDialogParameterListBoxSize(list, 'Multiple');
    }
}

function RemoveIskurDialogParameterListBoxItem( listName, hiddenName, key, mode )
{
    var itemSeperator = '$$$';
    var textValueSeperator = '$';
    
    var list = document.getElementById(listName);
    var hidden = document.getElementById(hiddenName);
    
    if (list != null && hidden != null)
    {
        var hiddenValue = '';
        var index = 0 ;
        while ( index < list.options.length )
        {
            if( mode == 'Single' ){
                list.options[index] = null;
                continue;
            }
            else if ( list.options[index].selected ){
                list.options[index] = null;
                continue;
            }
            else if ( hiddenValue == '' )
            {
                if( key == 'Value' )
                    hiddenValue = list.options[index].text + textValueSeperator + list.options[index].value;
                else if( key == 'Text' )
                    hiddenValue = list.options[index].text;
            }
            else
            {
                if( key == 'Value' )
                    hiddenValue = hiddenValue + itemSeperator + list.options[index].text + textValueSeperator + list.options[index].value;
                else if( key == 'Text' )
                    hiddenValue = hiddenValue + itemSeperator + list.options[index].text;
            }
            index++;
        }
        hidden.value = hiddenValue;
    }
    AdjustIskurDialogParameterListBoxSize(list, mode);
    OnItemChangeIskurDialogParameterListBox (list);
}

function AddIskurDialogParameterListBoxItem( listName, hiddenName, text, value, key, mode )
{
    var itemSeperator = '$$$';
    var textValueSeperator = '$';
            
    var list = document.getElementById(listName);
    var hidden = document.getElementById(hiddenName);
    
    if(mode == 'Single')
    {
        list.options.length = 0;
        hidden.value = '';        
    }

    if (list != null && hidden != null)
    {
        var index = 0 ;
        while ( index < list.options.length )
        {
            if( key == 'Value' ) {
                if ( list.options[index].text == text && list.options[index].value == value )
                    return;
            } else if( key == 'Text' ) {
                if ( list.options[index].text == text )
                    return;
            }
            index++;
        }
        if ( hidden.value == null || hidden.value == '' )
        {
            if( key == 'Value' )
                hidden.value = text + textValueSeperator + value;
            else if( key == 'Text' )
                hidden.value = text;
        }
        else
        {
            if( key == 'Value' )
                hidden.value = hidden.value + itemSeperator + text + textValueSeperator + value;
            else if( key == 'Text' )
                hidden.value = hidden.value + itemSeperator + text;
        }
        list.options[list.options.length] = new Option(text, value) ;
        list.size = list.options.length ;
                        
        AdjustIskurDialogParameterListBoxSize(list, mode);
        OnItemChangeIskurDialogParameterListBox (list);
        
    }
}

function AdjustIskurDialogParameterListBoxSize(list, mode)
{
    if(mode == 'Single')
    {
        list.size = 1;
    }
    else if(mode == 'Multiple')
    {
        if(list.MaxSize){}
        else{return;}
        if(list.MinSize){}
        else{return;}
        
        if (list.options.length < list.MinSize)
            list.size = list.MinSize;
        else if (list.options.length > list.MaxSize)
            list.size = list.MaxSize;
        else
            list.size = list.options.length;
    }
}

function AdjustIskurDialogParameterListBoxSizeFromID(listName, mode)
{
    var list = document.getElementById(listName);
    if(list != null) AdjustIskurDialogParameterListBoxSize(list, mode);
}

function OnItemChangeIskurDialogParameterListBox (list)
{
    if ( eval('window.'+list.id + '_onItemChange') )
    {
        eval ('window.'+list.id + '_onItemChange();');
    }
}

//DateBox'in methodlariyle problem veriyor: Array.prototype.binarySearch

//Array.prototype.binarySearch=function(q)
//{
//	var mid, lower=0, upper=this.length;
//	while (lower<=upper) {
//		mid=Math.floor((lower+upper)/2);
//		if (q==this[mid]) return mid;
//		if (q<this[mid]) upper=mid-1;
//		else lower=mid+1
//	}
//	return -1;
//}

//function createSortedArray(hidden)
//{
//    var no = new Array();
//    var txt = new Array();
//}
