/*
 * 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.exttimecardwork");

aipo.exttimecardwork.onLoadFormDialog = 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.exttimecardwork.onReceiveMessage = function(msg){
    if(!msg) {
        var arrDialog = dijit.byId("modalDialog");
        if(arrDialog){
            arrDialog.hide();
        }
        aipo.portletReload('exttimecard');
    }
    if (dojo.byId('messageDiv')) {
        dojo.byId('messageDiv').innerHTML = msg;
    }
};

aipo.exttimecardwork.hideDialog = function() {
    var arrDialog = dijit.byId("modalDialog");
    if(arrDialog){
      arrDialog.hide();
    }
    aipo.portletReload('exttimecard');
};

aipo.exttimecardwork.addHiddenValue = function(form, name, value){
    if (form[name]) {
        form[name].value = value;
    } else {
        var q = document.createElement('input');
        q.type = 'hidden';
        q.name = name;
        q.value = value;
        form.appendChild(q);
    }
}

aipo.exttimecardwork.onLoadexttimecardworkDialog = function(portlet_id){
  var obj = dojo.byId("reason");
  if(obj){
     obj.focus();
  }
}


//Add 2010/08/23 zhaopeng Start--- 
aipo.exttimecardwork.onChangeSelecter = function(portletId , url , values, named , flgName){

    dojo.byId(flgName).checked = false;
    var callbackArgs = new Array();
    callbackArgs["named"] = "workflow_" + named;

    aimluck.io.sendRawData(url + "&value=" + values,values,aipo.workflow.setTemplate,callbackArgs);

    return false;

}
//Add 2010/08/23 zhaopeng End--- 

//Add 2010/08/26 kohama Start--- 
aipo.exttimecardwork.openRevList = function(url){
    var wx = 800;
    var wy = 500;
    var x = (screen.width  - wx) / 2;
    var y = (screen.height - wy) / 2;

	// Update 2010/10/15 kanehiro Start---
    //var revlist_subwin = window.open(url,"rev_list_window","left="+x+",top="+y+",width="+wx+",height="+wy+",resizable=yes,status=yes,scrollbars=yes");
	revlist_subwin = window.open(url,"rev_list_window","left="+x+",top="+y+",width="+wx+",height="+wy+",resizable=yes,status=yes,scrollbars=yes");
	// Update 2010/10/15 kanehiro End---
    revlist_subwin.focus();
}

aipo.exttimecardwork.joborder = function(value){
	document.getElementById('job').innerHTML = value;
}
//Add 2010/08/26 kohama End--- 

//Add 2010/10/08 kanehiro Start---
aipo.exttimecardwork.joborderid = function(val){
	document.getElementById('job_order_id').value = val;
}
//Add 2010/10/08 kanehiro End---

//Add 2010/08/30 kohama Start--- 
aipo.exttimecardwork.onSubmitSerchButton = function(form,url,p_id){
     var exec_url = url;
     //var search_params = [["sword",form.sword.value]];
     var search_params = [["number",form.number.value],["word",form.word.value],["completionclass",form.completionclass.value]];
     aipo.viewPage(exec_url, p_id, search_params);
}
//Add 2010/08/30 kohama End--- 
aipo.exttimecardwork.jobOrderChanged = function(){
  var index = dojo.byId('job_list').selectedIndex;
  var str = dojo.byId('job_list').options[index].text;
  document.getElementById('job_order_id').title = str;
}
