﻿
// Display rows from database in the SELECT tag
function comboBox_ClientCallback(result, context)
{
    // convert rows into an 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 = -1;
		comboSelect.style.display='block';
	}
	else
		comboSelect.style.display='none';
}

// When leaving comboBox, get selected value from SELECT
function comboBox_Blur(src)
{
	src.style.display = 'none';
	var container = src.parentNode;
    document.getElementById(container.id+"_input").focus(); 
}

function comboBox_selectText(src)
{
    var selectText = document.getElementById(src.id);
    selectText.select();
}

function comboBox_onChange(src)
{
    var container = src.parentNode;
    var inputText = document.getElementById(container.id+"_input");  
    inputText.value = src.options[src.selectedIndex].text;    
}

function comboBox_onDownKeyPress(src, e)
{
    var container = src.parentNode;
    var selectText = document.getElementById(container.id+"_select");
    if(e.keyCode == '40'&& selectText.style.display!="none" )
    {   
        selectText.focus();
    }
}

function comboBox_onUpKeyPress(src, e)
{
    if((e.keyCode == '38'&& src.selectedIndex==0) ||e.keyCode =='13')
    {   
        var container = src.parentNode;
        var inputText = document.getElementById(container.id+"_input"); 
        inputText.focus();
    }  
}

function comboBox_onDblClick(src)
{
  var container = src.parentNode;
  var inputText = document.getElementById(container.id+"_input"); 
  inputText.focus();
}

// If server error, just show it
function comboBox_ErrorCallback(result)
{
    alert( result );
}
