/*
 * Aipo is a groupware program developed by Aimluck,Inc.
 * Copyright (C) 2004-2008 Aimluck,Inc.
 * http://aipostyle.com/
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/* Add　2010/8/9 tou Start--- */
dojo.require("aipo.widget.DropdownDatepicker");
/* Add　2010/8/9 tou End--- */


/* Add　2011/01/19 キョク Start--- */
dojo.provide("aipo.common");
/* Add　2011/01/19 キョク End--- */

dojo.provide("aipo.juchu_user");

dojo.require("aipo.widget.GroupNormalSelectList");

aipo.juchu_user.onLoadUserDialog = function(portlet_id){

    var fpicker = dijit.byId("groupnormalselect");
    if(fpicker){
        var select = dojo.byId('init_grouplist');
        var i;
        var s_o = select.options;
        if (s_o.length == 1 && s_o[0].value == "") return;
        for(i = 0 ; i < s_o.length; i ++ ) {
            fpicker.addOptionSync(s_o[i].value,s_o[i].text,true);
        }
    }      
   
    var username = dojo.byId("username");
    if(username && username.type == 'text'){
      username.focus();
    }
}

aipo.juchu_user.formSwitchPostInput = function(button) {
    if(button.form.is_new_post.value == 'TRUE' || button.form.is_new_post.value == 'true') {
        button.value = '新しく入力する';
        aipo.juchu_user.formPostInputOff(button.form);
    } else {
        button.value = '一覧から選択する';
        aipo.juchu_user.formPostInputOn(button.form);
    }
}

aipo.juchu_user.formPostInputOn = function(form) {
    dojo.byId('postSelectField').style.display = "none";
    dojo.byId('postInputField').style.display = "";

    form.is_new_post.value = 'TRUE';
}

aipo.juchu_user.formPostInputOff = function(form) {
    dojo.byId('postInputField').style.display = "none";
    dojo.byId('postSelectField').style.display = "";
    
    form.is_new_post.value = 'FALSE';
}


aipo.juchu_user.formSwitchPositionInput = function(button) {
    if(button.form.is_new_position.value == 'TRUE' || button.form.is_new_position.value == 'true') {
        button.value = '新しく入力する';
        aipo.juchu_user.formPositionInputOff(button.form);
    } else {
        button.value = '一覧から選択する';
        aipo.juchu_user.formPositionInputOn(button.form);
    }
}

aipo.juchu_user.formPositionInputOn = function(form) {
    dojo.byId('positionSelectField').style.display = "none";
    dojo.byId('positionInputField').style.display = "";

    form.is_new_position.value = 'TRUE';
}

aipo.juchu_user.formPositionInputOff = function(form) {
    dojo.byId('positionInputField').style.display = "none";
    dojo.byId('positionSelectField').style.display = "";
    
    form.is_new_position.value = 'FALSE';
}


aipo.juchu_user.onReceiveMessage = function(msg){
    if(!msg) {
        var arrDialog = dijit.byId("modalDialog");
        if(arrDialog){
            arrDialog.hide();
        }
        aipo.portletReload('juchu_user');
    }
    if (dojo.byId('messageDiv')) {
        dojo.byId('messageDiv').innerHTML = msg;
    }
}

aipo.juchu_user.submit2 = function(form) {
  var s_o = form.member_so.options;
  var tmp = '';

  for(i = 0 ; i < s_o.length; i++ ) {
    s_o[i].selected = false;
  }

  if(s_o.length > 0) {
    for(i = 0 ; i < s_o.length-1; i++ ) {
      tmp = tmp + s_o[i].value + ',';
    }
    tmp = tmp + s_o[s_o.length-1].value;
  }
  form.positions.value = tmp;
}
/* Add　2010/8/16 tou Start--- */

// カレンダーをクリアする
// （aipo.widget.DateCalendar.disabledCalendar メソッドと同じ処理を行う）
aipo.juchu_user.clearDatepicker = function(dateId) {
           var viewvalue = dojo.byId(dateId+'_view');
           viewvalue.innerHTML = "---- 年 -- 月 -- 日&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

           var hiddendate_year = dojo.byId(dateId+'_year');
           hiddendate_year.value = "";
           var hiddendate_month = dojo.byId(dateId+'_month');
           hiddendate_month.value = "";
           var hiddendate_day = dojo.byId(dateId+'_day');
           hiddendate_day.value = "";
           
           dojo.byId(dateId).value = "";
           
           if(! dojo.byId(dateId+'_flag').checked) dojo.byId(dateId+'_flag').checked = true;
           //dojo.byId(dateId+'_flag').checked = false;
           //alert("flagchecked = " + dojo.byId(dateId+'_flag').checked);
          
}

aipo.juchu_user.onSubmitSerchButton = function(form,url,p_id){
     var exec_url = url;
     /** Update　2010/08/25 チョウコウ Start */
     var search_params = [["kanryoFlag",form.kanryoFlag.checked]];
     /** Update　2010/08/25 チョウコウ End */
     aipo.viewPage(exec_url, p_id, search_params);
}

/* Add　2010/8/16 tou End--- */

/* Add　2011/01/19 キョク Start--- */
aipo.juchu_user.onSubmitSerchSort = function(url,p_id){
     var checkboxValue=dojo.byId('kanryoFlag').checked;
     var search_params = [["isKBNOrderBy",checkboxValue]];
     aipo.viewPage(url,p_id,search_params);
}
 
aipo.juchu_user.switchJuchuCheckbox = function(checkbox) {
  var element;
      
  if (checkbox.checked) {
    for (i = 0; i < checkbox.form.elements.length; i++) {
      element = checkbox.form.elements[i];
       　　if(! element.disabled){
       	if(element.id!='kanryoFlag'){
        	element.checked = true;
		}      
      }
    }
  }
  else {
    for (i = 0; i < checkbox.form.elements.length; i++) {
      element = checkbox.form.elements[i];
      if(! element.disabled){
      	if(element.id!='kanryoFlag'){
        	element.checked = false;
        }
      }
    }
  }
}
/* Add　2011/01/19 キョク End--- */

