<!-- $Id: bonus_by_user.htm 15589 2009-02-10 09:24:05Z sunxiaodong $ -->
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js"}

<div class="main-div">
<form action="bonus.php" method="post" name="theForm2" onsubmit="return validate2()">
  <table width="100%">
  <tr>
    <td class="label">{$lang.senduserrank}:</td>
    <td>
      <select name="rank_id">
      <option value="0">{$lang.select_rank}</option>
      {html_options options=$ranklist selected=$smarty.get.rank_id}
      </select>&nbsp;&nbsp;&nbsp;
      <input type="checkbox" name="validated_email" value="1">{$lang.validated_email}
    </td>
  </tr>
  <tr>
     <td style="text-align:center" colspan =2>
     <input type="submit" name="send_rank" value="{$lang.confirm_send_bonus}" class="button" />
     </td>
   </tr>
</table>
<input type="hidden" name="act" value="send_by_user" />
<input type="hidden" name="id" value="{$id}" />
</form>


</div>

<div class="main-div">
<form name="theForm" action="bonus.php" method="post" onsubmit="return validate();">
<div class="form-div">
<img src="images/icon_search.gif" border="0" alt="SEARCH" />{$lang.keywords}
      <input type="text" name="keyword" size="30" />
      <input type="button" name="search" value="{$lang.button_search}" onclick="searchUser();" />
</div>
<div class="list-div">
<table cellspacing='1' cellpadding='3'>
  <tr>
    <th>{$lang.userlist}</th>
    <th>{$lang.handler}</th>
    <th>{$lang.send_to_user}</th>
  </tr>
  <tr>
    <td width="45%" align="center">
      <select name="user_search[]" id="user_search" size="15" style="width:260px" ondblclick="addUser()" multiple="true">
      </select>
    </td>
    <td align="center">
      <p><input type="button" value="&gt;" onclick="addUser()" class="button" /></p>
      <p><input type="button" value="&lt;" onclick="delUser()" class="button" /></p>
    </td>
    <td width="45%" align="center">
      <select name="user[]" id="user" multiple="true" size="15" style="width:260px" ondblclick="delUser()">
      </select>
    </td>
  </tr>
  <tr>
    <td align="center" colspan="3"><input type="submit" name="send_user" value="{$lang.confirm_send_bonus}" class="button" /></td>
  </tr>
</table>
</div>
<input type="hidden" name="id" value="{$id}" />
<input type="hidden" name="act" value="send_by_user" />
</form>
</div>

{literal}
<script language="JavaScript">
<!--
document.forms['theForm'].elements['keyword'].focus();

onload = function()
{
    // 开始检查订单
    startCheckOrder();
}
/**
* 按用户名搜索用户
*/
function searchUser()
{
  var eles = document.forms['theForm'].elements;

  /* 填充列表 */
  var keywords = Utils.trim(eles['keyword'].value);
  if (keywords != '')
  {
    Ajax.call('bonus.php?is_ajax=1&act=search_users', 'keywords=' + keywords, searchUserResponse, "GET", "JSON");
  }
}

function searchUserResponse(result)
{
  var eles = document.forms['theForm'].elements;
  eles['user_search[]'].length = 0;

  if (result.error == 0)
  {
    for (i = 0; i < result.content.length; i++)
    {
      var opt = document.createElement('OPTION');
      opt.value = result.content[i].user_id;
      opt.text  = result.content[i].user_name;
      eles['user_search[]'].options.add(opt);
    }
  }
}

function validate2()
{
    var user_rank = document['theForm2'].elements['rank_id'].value;

    if (user_rank == 0)
    {
        alert(user_rank_empty);
        return false;
    }
    return true;
}

var submiting = false;

function validate()
{
  if(!submiting)
  {
    var idArr = new Array();
    var dest = document.getElementById('user');
    for (var i = 0; i < dest.options.length; i++)
    {
        dest.options[i].selected = "true";
        idArr.push(dest.options[i].value);
    }
    if (idArr.length <= 0)
    {
        alert(user_name_empty);
        return false;
    }
    else
    {
        submiting = true;
        return true;
    }
  }
  else
  {
    alert('Submitting...');
    return false;
  }
}

  function addUser()
  {
      var src = document.getElementById('user_search');
      var dest = document.getElementById('user');

      for (var i = 0; i < src.options.length; i++)
      {
          if (src.options[i].selected)
          {
              var exist = false;
              for (var j = 0; j < dest.options.length; j++)
              {
                  if (dest.options[j].value == src.options[i].value)
                  {
                      exist = true;
                      break;
                  }
              }
              if (!exist)
              {
                  var opt = document.createElement('OPTION');
                  opt.value = src.options[i].value;
                  opt.text = src.options[i].text;
                  dest.options.add(opt);
              }
          }
      }
  }

  function delUser()
  {
      var dest = document.getElementById('user');

      for (var i = dest.options.length - 1; i >= 0 ; i--)
      {
          if (dest.options[i].selected)
          {
              dest.options[i] = null;
          }
      }
  }

//-->
</script>
{/literal}
{include file="pagefooter.htm"}