﻿//Display rows from db in the select tag
function comboBox_ClientCallback(result, context)
{

    //convert rows into array
    var rows;
    eval( 'rows=' + result );

    //get the select element
    var comboSelect = document.getElementById( context );

    //Add the options
    comboSelect.options.length = 0;
    for (var i=0;i<rows.length;i++)
    {
        var newOption = document.createElement("OPTION");
        newOption.text = rows[i];
        newOption.value = rows[i];
        
        if  (document.all)
        {
            comboSelect.add(newOption);
        }
        else
        {
            comboSelect.add(newOption, null);
        }
        
        // If results, show the SELECT, otherwise hide it
        if (comboSelect.options.length > 0)
        {
            comboSelect.size = comboSelect.options.length + 1;
            comboSelect.selectedIndex = 0;
            comboSelect.style.display = 'block';
        }
        else
        {
            comboSelect.style.display = 'none';        
        }

    }
}

//When leaving combobox get selected value from select
function comboBox_Blur(src)
{
    var mysrc = src
    var container = src.parentNode;
    var comboSelect = container.getElementsByTagName('select')[0];

    //alert(comboSelect.value);

    setTimeout(function() { nowdoit(src, comboSelect); }, 200);
 


}


function nowdoit(src, comboSelect) {

    //alert(comboSelect.style.display);

    //alert(comboSelect.selectedIndex);

    if (comboSelect.style.display != 'none' && comboSelect.selectedIndex != -1) {
        src.value = comboSelect.value;
        comboSelect.style.display = 'none';
    }
    
}



//If server error, just show it
function comboBox_ErrorCallback(result)
{
    alert( result );
}


