<?xml version="1.0" encoding="UTF-8"?>
<dynaForm name="authSources/authSources_SearchUsers" type="xmlform" enableTemplate="1" width="95%">
  <TITLE type="title">
    <en><![CDATA[Search for user]]></en>
  </TITLE>
  <AUTH_SOURCE_UID type="hidden"/>
  <KEYWORD type="text" size="50" maxlength="50" required="0">
    <en><![CDATA[Keyword]]></en>
  </KEYWORD>
  <btnSearch type="button" onclick="searchUsers();">
    <en><![CDATA[Search]]></en>
  </btnSearch>
  <btnImport type="button" onclick="importUsers(this.form);">
    <en><![CDATA[Import]]></en>
  </btnImport>
  <BTN_CANCEL type="button" onclick="cancel();">
    <en><![CDATA[Cancel]]></en>
  </BTN_CANCEL>
  <JS type="javascript"><![CDATA[

function disableEnterKey(e)
{
  var key;
  if(window.event)
    key = window.event.keyCode;     //IE
  else
    key = e.which;     //firefox

  if(key == 13) {
    searchUsers();
    e.cancelBubble = true;
    e.returnValue = false;
    if (e.stopPropagation) {
      e.stopPropagation();
      e.preventDefault();
    }
    return false;
  } else {
    return true;
  }
}

var searchUsers = function() {
  var oRPC = new leimnud.module.rpc.xmlhttp({
    url     : 'authSources_Ajax',
    args    : 'action=searchUsers&sUID=' + getField('AUTH_SOURCE_UID').value + "&sKeyword=" + getField('KEYWORD').value
  });
  oRPC.callback = function(rpc){
    document.getElementById('spanUsers').innerHTML = rpc.xmlhttp.responseText;
    var scs = rpc.xmlhttp.responseText.extractScript();
    scs.evalScript();
  }.extend(this);
  oRPC.make();
};

function checkInfo() {
  var input_obj = document.getElementsByTagName("input");
  for (i = 0; i < input_obj.length; i++) {
    if (input_obj.item(i).type == 'checkbox' && input_obj.item(i).checked == true)
    {
      return true;
    }
  }
  return false;
}

var importUsers = function(oForm) {
  if (checkInfo()) {
    oForm.submit();
  }
  else {
    alert(_('ID_NO_SELECTION_WARNING'));
  }
};

function cancel(){
  window.location = 'authSources_List';
}

leimnud.event.add(getField('KEYWORD'), 'keypress', function(event) {
  return disableEnterKey(event);
});

]]></JS>
</dynaForm>
