/*-------------------------------------------------------------------------------*/
/*---                                                                         ---*/
/*---                          S M A R T P L A C E                            ---*/
/*---                                                                         ---*/
/*---                                                                         ---*/
/*---                 Copyright ThinkMarketPlace 2004-2008                    ---*/
/*---                                                                         ---*/
/*-------------------------------------------------------------------------------*/

//Initialize the Javascript Control
function Initialize(e,selectName,frmEle)
{
  //Initialize the selection box
  if(selectName!=selectInputName && selectInputName!="")
  {
	 document.getElementById(selectInputName).style.display='none';
  }
  if (time_flag == 0)
  {
    document.getElementById(selectName).style.display='';
		//frmEle.value = document.getElementById(selectName).options[document.getElementById(selectName).selectedIndex].text;
		combotext_onkeyupdown(e,frmEle,document.getElementById(selectName));
  }
  time_flag = 1;
  selectInputName = selectName;
} 
//Set the text box value from selection box
function combotext_onkeyupdown(e,oText,oSelect)
{
  keyCode = e.keyCode;
  //Check for UP/DOWN arrow
  if (keyCode == 40 || keyCode == 38)
  {
    oSelect.style.display = 'block';  
    oSelect.focus();  
    //comboselect_onchange(oSelect, oText);  
  }
  //Check for ENTER/ESC key
  else if (keyCode == 13 || keyCode == 27)
  {  
    e.cancelBubble = true;  
    if (e.returnValue) e.returnValue = false;  
    if (e.stopPropagation) e.stopPropagation();  
    //comboselect_onchange(oSelect, oText);
    oSelect.style.display='none';  
    oText.focus();  
    return false;
  }  
  else if(keyCode == 9) return true;  
  else
  {
    oSelect.style.display = 'block';
    var c = String.fromCharCode(keyCode);
    //c = c.toUpperCase();
    toFind = oText.value;// + c; //.toUpperCase()
    for (i=0; i < oSelect.options.length; i++)
		{
       nextOptionText = oSelect.options[i].text;//.toUpperCase();
       if(toFind == nextOptionText)
	   	 {
           oSelect.selectedIndex = i;
           break;
       }

       if(i < oSelect.options.length-1)
	     {
          lookAheadOptionText = oSelect.options[i+1].text;//.toUpperCase();
          if( (toFind > nextOptionText) && (toFind < lookAheadOptionText) )
		      {
             oSelect.selectedIndex = i+1;
             break;
          }  
       }
       else
	     {  
          if(toFind > nextOptionText)
		      {
			        // stick it at the end
              oSelect.selectedIndex = oSelect.options.length-1;
              break;  
          }
	     }
    }
  }
}

function comboselect_onkeyup(keyCode,oSelect,oText){  
  // ENTER
  if (keyCode == 13) {  // || keyCode == 27
    comboselect_set(oSelect, oText);  
    oSelect.style.display='none';  
    oText.focus();  
  }
  // ESCAPE
  else if(keyCode==27)
  {
	oSelect.style.display='none';  
    oText.focus();
  }
}  

function comboselect_set(oSelect,oText) {  
  if(oSelect.selectedIndex != -1)  
    oText.value = oSelect.options[oSelect.selectedIndex].text;  
}

/*
var time_flag=0;
var selectInputName = "";

function deInitialize()
{
  //De activate the selection box.
  if (time_flag == 0 && selectInputName!="")
  {
    document.getElementById(selectInputName).style.display='none';
  }
  time_flag = 0;
} 

//Initialize the Javascript Control
function Initialize(selectName,frmEle)
{
  //Initialize the selection box
  if(selectName!=selectInputName && selectInputName!="")
  {
	 document.getElementById(selectInputName).style.display='none';
  }
  if (time_flag == 0)
  {
    document.getElementById(selectName).style.display='';
		frmEle.value = document.getElementById(selectName).options[document.getElementById(selectName).selectedIndex].text;
  }
  time_flag = 1;
  selectInputName = selectName;
} 
//Set the text box value from selection box
function combotext_onkeyupdown(e,oText,oSelect)
{
  keyCode = e.keyCode;
  //Check for UP/DOWN arrow
  if (keyCode == 40 || keyCode == 38)
  {
    oSelect.style.display = 'block';  
    oSelect.focus();  
    comboselect_onchange(oSelect, oText);  
  }
  //Check for ENTER/ESC key
  else if (keyCode == 13 || keyCode == 27)
  {  
    e.cancelBubble = true;  
    if (e.returnValue) e.returnValue = false;  
    if (e.stopPropagation) e.stopPropagation();  
    comboselect_onchange(oSelect, oText);
    oSelect.style.display='none';  
    oText.focus();  
    return false;  
  }  
  else if(keyCode == 9) return true;  
  else
  {
    oSelect.style.display = 'block';
    var c = String.fromCharCode(keyCode);
    //c = c.toUpperCase();
    toFind = oText.value;// + c; //.toUpperCase()
    for (i=0; i < oSelect.options.length; i++)
		{
      nextOptionText = oSelect.options[i].text;//.toUpperCase();
      if(toFind == nextOptionText)
	   	{
      	oSelect.selectedIndex = i;
        break;
      }

      if(i < oSelect.options.length-1)
	   	{
        lookAheadOptionText = oSelect.options[i+1].text;//.toUpperCase();
        if( (toFind > nextOptionText) && (toFind < lookAheadOptionText) )
		  	{
        	oSelect.selectedIndex = i+1;
          break;
        }  
      }
      else
	   	{  
      	if(toFind > nextOptionText)
		  	{
			  	// stick it at the end
          oSelect.selectedIndex = oSelect.options.length-1;
          break;  
        }
	   	}
    }
  }
}
  
  
function comboselect_onchange(oSelect,oText) {  
  if(oSelect.selectedIndex != -1)  
    oText.value = oSelect.options[oSelect.selectedIndex].text;  
}  
  
function comboselect_onkeyup(keyCode,oSelect,oText){  
  if (keyCode == 13 || keyCode == 27) {  
    comboselect_onchange(oSelect, oText);  
    oSelect.style.display='none';  
    oText.focus();  
  }  
}
*/