﻿
var _activeComboBoxTextBox = null;
var _enableAutoComplete = true;


/////////////////////////////////////////////////////
var SelectedItemIndex = 0;
var SelectedItemValue = '';
var SelectedItemText = '';
var ItemsVisible = false;
var ComboBoxClientId = '';
var AutoPostBack = false;
var OverrideDelayHide = false;
var ContainerId = '';
var HideTimer = '';
var Value = '';


function ItemSelected(itmSelected, comboBoxId)
{
    var selectedVal = itmSelected.getAttribute("value") + '';
    var selectedInd = itmSelected.getAttribute("index") + '';
    var selectedTxt = itmSelected.getAttribute("text") + '';
    
    //Set the global vars;
    SelectedItemValue = selectedVal;
    SelectedItemIndex = selectedInd;
    SelectedItemText = selectedTxt;
    
    //Hide the box
    OverrideDelayHide = true;
    HideItems();
    
    //Set the value of the txtBox;
    if(comboBoxId == '')
    {
        alert('Error:There was not an ID provided for the parent ComboBox Textbox.');
    }
    else
    {
        if(selectedVal == 'other')
        {
            selectedVal = '';
        }
        document.getElementById(comboBoxId).value = selectedVal;
        //if(AutoPostBack == true)
        //{
            //__doPostBack(comboBoxId, selectedVal);
        //}
    }
    if(SelectedItemValue == '')
    {
        document.getElementById(comboBoxId).focus();
    }
    else
    {
        SetWager(comboBoxId);
    }
    
}

function HideItems()
{
    if(HideTimer == '')
    {
        HideTimer = new Array();
    }
    HideTimer = setTimeout ( "document.getElementById('" + ContainerId + "').style.display = 'none'; ItemsVisible = false;", 300 );
}

function StopAutoHideItems()
{
    if(!OverrideDelayHide)
    {
        clearTimeout (HideTimer);
        HideTimer = '';
    }
}


function ShowHideItems(containerId, txtBoxClientId)
{
    OverrideDelayHide = false;
    var containerCtr = document.getElementById(containerId);
    ContainerId = containerId;
    if(ItemsVisible)
    {
        ItemsVisible = false;
        containerCtr.style.display = 'none';
    }
    else
    {
        ItemsVisible = true;
        var txtBox = document.getElementById(txtBoxClientId);
        containerCtr.style.display = 'block';
        

        containerCtr.style.position = 'absolute';
        //alert(txtBox.offsetTop);
        //containerCtr.style.left = txtBox.offsetLeft + 10;//(txtBox.offsetLeft - txtBox.clientWidth);
        //containerCtr.style.top = (txtBox.offsetTop + 20 +  txtBox.clientHeight);
        containerCtr.style.width = txtBox.clientWidth + 3;
        
        
    }    
}



