/*
 * 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/>.
 */

dojo.provide("aipo.genka");

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

aipo.genka.onLoadgenkaDialog = function(portlet_id){

  var obj = dojo.byId("todo_name");
  if(obj){
     obj.focus();
  } 
    
}

aipo.genka.onLoadCategoryDialog = function(portlet_id){

  var obj = dojo.byId("category_name");
  if(obj){
     obj.focus();
  } 
    
}

aipo.genka.formSwitchCategoryInput = function(button) {
    if(button.form.is_new_category.value == 'TRUE' || button.form.is_new_category.value == 'true') {
        button.value = '新しく入力する';
        aipo.genka.formCategoryInputOff(button.form);
    } else {
        button.value = '一覧から選択する';
        aipo.genka.formCategoryInputOn(button.form);
    }
}

aipo.genka.formCategoryInputOn = function(form) {
    dojo.byId('genkaCategorySelectField').style.display = "none";
    dojo.byId('genkaCategoryInputField').style.display = "";

    form.is_new_category.value = 'TRUE';
}

aipo.genka.formCategoryInputOff = function(form) {
    dojo.byId('genkaCategoryInputField').style.display = "none";
    dojo.byId('genkaCategorySelectField').style.display = "";
    
    form.is_new_category.value = 'FALSE';
}

aipo.genka.onReceiveMessage = function(msg){

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

aipo.genka.onListReceiveMessage = function(msg){
  
    if(!msg) {
        var arrDialog = dijit.byId("modalDialog");
        if(arrDialog){
            arrDialog.hide();
        }
        aipo.portletReload('todo');
        aipo.portletReload('schedule');
    }
    if (dojo.byId('listmessageDiv')) {
        dojo.byId('listmessageDiv').innerHTML = msg;
    }
    
}

aipo.genka.ajaxCheckAndSubmit = function(button) {

//	if(msgList == null || msgList.length == 0){
		aimluck.io.setHiddenValue(button);
    	button.form.submit();
//	} else {
//		dojo.byId('errmessageDiv').innerHTML = aipo.genka.encodeErrMessage(msgList);
	//}

}


aipo.genka.encodeErrMessage = function(list) {
	if(list == null || list.length == 0) {
		return "";
	} else {
		var errMsg = "";
		for(var i=0; i<list.length; i++){
			var msg = list[i];
			errMsg += "<li><span class='caution'>" + msg + "</span></li>";
		}
		return errMsg;
	}
}

aipo.genka.formGenkaTemp = function(form) {
    dojo.byId('genka_range_temp').style.display = "block";
    dojo.byId('profit_range_temp').style.display = "none";
    dojo.byId('profit_project_temp').style.display = "none";
}

aipo.genka.formProfitTemp = function(form) {
    dojo.byId('genka_range_temp').style.display = "none";
    dojo.byId('profit_range_temp').style.display = "block";
    dojo.byId('profit_project_temp').style.display = "block";
}
