function FTFindCtrl(name){
  var reg = new RegExp("^" + FTCtrlId + "." + name + "$", "i");
  for(var i=0; i<document.forms[0].elements.length; i++){
    if(document.forms[0].elements[i].id.match(reg) || document.forms[0].elements[i].name.match(reg))
      return document.forms[0].elements[i];
  }
  return null;
}
function FTClickSubmitBttn(){
	var bttn = FTFindSubmitBttn();
	if(bttn != null && IsFTSubmitBttn(bttn)){
		bttn.focus();
		bttn.click();
	}
}
function IsFTSubmitBttn(bttn){
	if(bttn != null){
	  var pattern = FTCtrlId + ".(submitBttn|findBttn)";
	  var reg = new RegExp(pattern, "i");
	  return reg.test(bttn.name);
	}
	else
	  return false;
}
function IEFTKeyDown(e) {
	if(event.keyCode == 13)
	  FTClickSubmitBttn();
}		
function NIEFTKeyDown(e){
	if(typeof(e.keyCode) != "undefined" && e.keyCode == 13)
	  FTClickSubmitBttn();
}
function FTFindSubmitBttn(){
  for(var i=0; i<document.forms[0].elements.length; i++){
    if(document.forms[0].elements[i].type == "submit")
      return document.forms[0].elements[i];
  }
  return null;
}
function FTFillValue(list, fieldname){
	eval("document.Form1." + fieldname + ".value='" + list.options[list.selectedIndex].value + "'");
	eval("document.Form1." + fieldname + ".focus()");
}
function FTAdjustArrivalTimeRange(){
	var fromDt2List = eval("document.Form1." + FTCtrlId + "_fromDt2");
	var toDt2List = eval("document.Form1." + FTCtrlId + "_toDt2");
	var flightStatusList = eval("document.Form1." + FTCtrlId + "_flightStatus");
	
	if(flightStatusList.options[flightStatusList.selectedIndex].value == "2" || flightStatusList.options[flightStatusList.selectedIndex].value == "7"){
		fromDt2List.selectedIndex = 0;
		toDt2List.selectedIndex = 0;
	}
}
function FTFocusFID(){
  var _FTbttn = FTFindSubmitBttn();
  if(_FTbttn != null && _FTbttn.value == "Track Flight"){
    var flightNum = eval("document.Form1." + FTCtrlId + "_flightNum");
    if(flightNum != null) flightNum.focus();
  }
}
function FTUpdateTracking(){
  var numUpdate = FTFindCtrl("numUpdate");
  if(numUpdate != null){
    if(numUpdate.value == "")
      return;
    else{
      numUpdate.value = (parseInt(numUpdate.value) + 1);
      if(!_isFTUpdating){
        _isFTUpdating = true;
        FTClickSubmitBttn();
      }
    }
  }
}

if(document.all)		
  document.onkeydown = IEFTKeyDown
else{
  window.captureEvents(Event.KEYPRESS);
  window.onkeypress = NIEFTKeyDown;
}

