
//http://www.dotnetjohn.com/runtime/example.aspx
function KeySortDropDownList_onkeypress (dropdownlist,caseSensitive) 
{
	if(ReturnKeySubmit())
	{
		return true;
	}

	// check the keypressBuffer attribute is defined on the dropdownlist
	var undefined; 
	if (dropdownlist.keypressBuffer == undefined) 
	{ 
		dropdownlist.keypressBuffer = ''; 
	} 
	// get the key that was pressed 
	var key = String.fromCharCode(window.event.keyCode); 
	dropdownlist.keypressBuffer += key;
	if (!caseSensitive) 
	{
		// convert buffer to lowercase
		dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();
	}
	// find if it is the start of any of the options 
	var optionsLength = dropdownlist.options.length; 
	for (var n=0; n < optionsLength; n++) 
	{ 
		var optionText = dropdownlist.options[n].text; 
		if (!caseSensitive) 
		{
			optionText = optionText.toLowerCase();
		}
		if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) 
		{ 
			dropdownlist.selectedIndex = n; 
			return false; // cancel the default behavior since 
							// we have selected our own value 
		} 
	} 
	// reset initial key to be inline with default behavior 
	dropdownlist.keypressBuffer = key; 
	return true; // give default behavior 
	
} 
//to submit the form if the user clicks the Return Key [13] or TAB key [9]
function ReturnKeySubmit()
{	
	//alert(event.keyCode);
    if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)
		//|| (event.which && event.which == 9) || (event.keyCode && event.keyCode == 9)
		)
    {
		//alert(event.keyCode);
        //document.all("btnSearch").click();
        //event.returnValue=false;
		//event.cancel = true;
		//Form1.submit();
		MainForm.submit();
		//this.forms[0].submit;
		return true;
    }
    else
    {
        return false;
    }    
}
//http://www.dotnetjunkies.com/WebLog/familjones/
//onkeypress does not handle TAB key event whereas onkeydown does
function HandleKeyDown(obj) {
   var tabKeyCode = 9;
   var escKeyCode= 27;
   if (event.keyCode == (tabKeyCode || escKeyCode) && event.srcElement == obj) {
      //obj.selection = document.selection.createRange();
      //obj.selection.text = String.fromCharCode(tabKeyCode);
      MainForm.submit();
      event.returnValue = false;
   }
}
function HandleBlur(obj) {
	MainForm.submit();
}
/*

//http://www.dotnetjohn.com/runtime/example.aspx
function KeySortDropDownList_onkeypress (dropdownlist,caseSensitive,e) 
{
	if(!e) var e=window.event;
	if(e.keyCode) code=e.keyCode;
	if(e.which) code=e.which;
	
	if(ReturnKeySubmit(e))
	{
		return true;
	}
	
	// check the keypressBuffer attribute is defined on the dropdownlist
	var undefined; 
	if (dropdownlist.keypressBuffer == undefined) 
	{ 
		dropdownlist.keypressBuffer = ''; 
	} 
	// get the key that was pressed 
	//var key = String.fromCharCode(window.event.keyCode); 
	var key = String.fromCharCode(code);
	dropdownlist.keypressBuffer += key;
	if (!caseSensitive) 
	{
		// convert buffer to lowercase
		dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();
	}
	// find if it is the start of any of the options 
	var optionsLength = dropdownlist.options.length; 
	for (var n=0; n < optionsLength; n++) 
	{ 
		var optionText = dropdownlist.options[n].text; 
		if (!caseSensitive) 
		{
			optionText = optionText.toLowerCase();
		}
		if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) 
		{ 
			dropdownlist.selectedIndex = n; 
			return false; // cancel the default behavior since 
							// we have selected our own value 
		} 
	} 
	// reset initial key to be inline with default behavior 
	dropdownlist.keypressBuffer = key; 
	return true; // give default behavior 
	
} 
//to submit the form if the user clicks the Return Key [13] or TAB key [9]
function ReturnKeySubmit(e)
{	
	if(!e) var e=window.event;
	if(e.keyCode) code=e.keyCode;
	if(e.which) code=e.which;
	
	//alert(event.keyCode);
//    if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)
//		//|| (event.which && event.which == 9) || (event.keyCode && event.keyCode == 9)
//		)
	if(code==13)	
    {
		//alert(event.keyCode);
        //document.all("btnSearch").click();
        //event.returnValue=false;
		//event.cancel = true;
		//Form1.submit();
		MainForm.submit();
		//this.forms[0].submit;
		return true;
    }
    else
    {
        return false;
    }    
}
*/