﻿var infoTable_grid,infoTable_buffer,options={};

options['DISPATCH'] = {
  sortCol : 2,
  sortDir : 'DESC',
  visibleRows : 5,
  frozenColumns : 1,
  highlightElem : 'cursorRow',
  columnSpecs   : [
    { Hdg: "案件番号", width: 60 },
    { Hdg: "登録日", visible:false},
    { Hdg: "更新", width: 60 , ClassName:'redtext'},
    { Hdg: "業種", width: 60 },
    { Hdg: "紹介情報", width: 330 },
    { Hdg: "リンク", width: 50, control:new Rico.TableColumn.link('http://www.fe-brain.com/work/haken/detail/MakeHakenInfo.php?id={0}','_blank') },
    { Hdg: "表示の有無", visible:false}
  ]
};


//業種別にグリッドを切り替える
//選択業種に該当するphpを呼び出す
function newGridForWorkFolder(TableName,businesstype) {
	var makesession =  new makeCorectSession('http://www.fe-brain.com/src/MakeDispatchSession.php','');
	var tabid;
	switch (businesstype){
		case '設計' :
			makesession.setBusinessType(1);
			tabid='1';
			break;
		case '製造' :
			makesession.setBusinessType(2);
			tabid='2';
			break;
		case 'プラント' :
			makesession.setBusinessType(3);
			tabid='3';
			break;
		case '解析' :
			makesession.setBusinessType(4);
			tabid='4';
			break;
		default:
			//just dummy
	};

	var urlnode = '';
	var tabimg = '';
	var i = '';

	for(i = 1; i < 5; i++){
		tabimg = $('tab_' + i + '-2');
		if(i == tabid){
			urlnode = '../../img/tab_haken_on_' + i + '.jpg';
		}else{
			urlnode = '../../img/tab_haken_' + i + '.jpg';
		};
		tabimg.style.backgroundImage = 'url(' + urlnode + ')';
	};

	//セッションスタート
	makesession.callSession();

  //表示グリッドのクリア
  if (infoTable_grid) {
    if (Event.unloadCache) {
      Event.unloadCache();   // this does all of the "unplugs", and is critical to enable memory to be released
    } else if (Event.destroyCache) {
      Event.destroyCache();  // unloadCache was removed from Prototype 1.6
    }
    infoTable_buffer.clear();
  };
  //グリッドの表示領域(クリア)
  var outerDiv=$('infoTable_outerDiv');
  outerDiv.innerHTML='';
  infoTable_buffer=null;
  infoTable_grid=null;
  //ライブグリッドのインスタンス
  //バッファの取得
  infoTable_buffer=new Rico.Buffer.AjaxSQL('http://www.fe-brain.com/src/ricoXMLquery.php', { requestParameters: ['id=infoTable'+TableName],waitMsg: "<img src='http://www.fe-brain.com/img/waiting.gif'>" });
  //グリッドの生成
  infoTable_grid=new Rico.LiveGrid ('infoTable', infoTable_buffer, options[TableName]);
  //メニューの追加
  infoTable_grid.menu = new Rico.GridMenu();
};

var makeCorectSession = Class.create();

makeCorectSession.prototype = {
	//コンストラクタ
	initialize: function(url,businesstype){
		this.url = url;
		this.businesstype = businesstype;
},

	setBusinessType: function(businesstype){
		this.businesstype = businesstype;
	},

	callSession: function(){
			var ajaxbuff = new Ajax.Request(this.url, {
				method: "post",
				asynchronous: "false",
				parameters: "businesstype=" + this.businesstype ,
				onSuccess: function(httpObj){
					return false;
				}
			}
		)
	}
};
