#*
 * Aipo is a groupware program developed by Aimluck,Inc.
 * Copyright (C) 2004-2011 Aimluck,Inc.
 * http://www.aipo.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *#

## ---------------------------------------------------------------------------
#set($enable_userlist = true)
#if($config.getString("action.login.enable.select.userlist") != "true")
#set($enable_userlist = false)
#end
#set($uri = "portal/")
<script language="JavaScript" type="text/JavaScript">
<!--

var tmpUsername = "";

function set_username(form){
  form.username.value = form.member_username.value;
}

function submit2(form) {
  set_cookie("username", form.username.value);
  if (form.save_password.checked) {
    set_cookie("password", form.password.value);
  } else {
    remove_cookie("password");
  }
  set_cookie("save_password", form.save_password.checked);
}

function init() {
  var form = document.forms[0];
  var savePassStr = get_cookie("save_password");
  var savePassObj = form.save_password;
  if (savePassStr == "true") {
    savePassObj.checked = true;
  } else {
    savePassObj.checked = false;
  }
  change_login_type(form);
}

function set_input_value(form) {
  var usernameStr = "";
  if (tmpUsername == "") {
    usernameStr = get_cookie("username");
  } else {
    usernameStr = tmpUsername;
  }
  var usernameObj = form.username;
  usernameObj.value = usernameStr;

  if (form.save_password.checked) {
    form.password.value = get_cookie("password");
  }
}

function set_select_value(form) {
  var usernameStr = "";
  if (tmpUsername == "") {
    usernameStr = get_cookie("username");
  } else {
    usernameStr = tmpUsername;
  }
  if (form.save_password.checked) {
    form.password.value = get_cookie("password");
  }
}

function get_cookie(strName) {
  var strReturn = "";
  var nLoop = 0;
  var nLength = 0;
  var strNameEx = strName + "=";
  var strTemp = "";
  while (nLoop < document.cookie.length) {
    nLength = nLoop + strNameEx.length;
    if (document.cookie.substring(nLoop, nLength) == strNameEx) {
      strTemp = document.cookie.indexOf(";", nLength);
      if (strTemp == -1) {
        strReturn = document.cookie.substring(nLength, document.cookie.length);
      } else {
        strReturn = document.cookie.substring(nLength, strTemp);
      }
      break;
   }
   nLoop = document.cookie.indexOf(" ", nLoop) + 1;
   if (nLoop == 0) {
     break;
    }
  }
  return strReturn;
}

function set_cookie(strName, strValue) {
  var dtExpire = new Date();
  dtExpire.setTime(dtExpire.getTime() + 10*24*60*60*1000);
  document.cookie = strName + "=" + strValue + "; expires=" + dtExpire.toGMTString() + "; path=${context_path}/";
}

function remove_cookie(strName) {
  var strValue;
  var dtExpire = new Date();
  dtExpire.setTime(dtExpire.getTime() - 1);
  strValue = get_cookie(strName);
  document.cookie = strName + "=" + strValue + "; expires=" + dtExpire.toGMTString() + "; path=${context_path}/";
}

function change_login_type(form) {
  if (form.username.value != "") {
    tmpUsername = form.username.value;
  }
  set_input_value(form);
}


//-->
</script>
#ALcell_pagetitle_iphone($career "ログインフォーム")
#ALcell_contents_header($career)
$!data.Message
<form action="${clink.setURI($uri)}" method="post" onSubmit="submit2(this)">
<input name="$jslink.ActionKey" type="hidden" value="$config.getString("action.login")" />
<h3 class="mb5">ユーザー名</h3>
<input class='text' name='username' value='' type='text' size='30' maxlength='50' style='ime-mode:disabled' />
<h3 class="mb5">パスワード</h3>
<input class="text" name="password" value="" type="password" size="30" maxlength="50" style="ime-mode:disabled" />
<br />
<input name="save_password" type="checkbox" class="checkbox" value="save" id="save_password" />
<label for="pass">パスワードを保存する</label>
<br />
<p class="center">
  <input name="login_submit" class="button" type="submit" value="ログイン" />
</p>
</p>
</form>
#ALcell_contents_footer($career)
<script language="JavaScript" type="text/JavaScript">
<!--
init();
//-->
</script>