﻿
// 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';
		comboSelect.style.height='400px';
		comboSelect.style.width='200px';		
	}
	else
		comboSelect.style.display='none';
}

///Added by Mario 
function comboBox_Click(src)
{
 var container = src.parentNode;
 var comboSelect = container.getElementsByTagName('select')[0];
    alert( comboSelect.selectedindex);
    
    if ( comboSelect.style.display != 'none' && comboSelect.selectedIndex != -1)
        src.value = comboSelect.value;
        
        comboSelect.style.display = 'none';
       // document.getElementById("InventoryMnt1_TextBox1_select").focus(); 
}

// When leaving comboBox, get selected value from SELECT
function comboselect_click(src)
{

    var container = src.parentNode;
    var comboSelect = container.getElementsByTagName('select')[0];
    var crazyjs= container.getElementsByTagName('select')[0].previousSibling.previousSibling;
   // alert(comboSelect.tagName);
   // alert(crazyjs.tagName);
    if ( comboSelect.style.display != 'none' && comboSelect.selectedIndex != -1)
       crazyjs.value= comboSelect.value;
	  comboSelect.style.display = 'none';
   // comboSelect.selectedIndex = -1;
	//alert( comboSelect.value);
 
}
function comboBox_Blur(src)
{


    var container = src.parentNode;
    var comboSelect = container.getElementsByTagName('select')[0];
  
    if ( comboSelect.style.display != 'none' && comboSelect.selectedIndex != -1)
       src.value = comboSelect.value;
       
	  comboSelect.style.display = 'none';
    
   // comboSelect.selectedIndex = -1;
	alert( comboSelect.value);
 
	
}

// If server error, just show it
function comboBox_ErrorCallback(result)
{
    alert( result );
}
