﻿var __jsonData;
var __aid;
var __updateMode;
var __resizeArea;
var __heightBase1;
var __heightBase2;
var __dialog;
var __clickNode;
var __addEvent;
var __thisNode;
var __isDblClick;
var __clkProc;
var __isMobile;
var __itemList;

function getCheckItems(inCheckBoxName) {

	var checked = $("input:checkbox:checked");
	var value = "";
	$(checked).each(function() {
		if ($(this).attr('name') == inCheckBoxName) {
			value += "," + $(this).val();
		}
	});
	if (value.length > 0) value = value.substring(1);

	return value;
}

function saveCookie(inCookieName, inValue) {
	$.cookie(inCookieName, inValue, {path: '/', expires: 90});
}

//---------------------
//  関連商品の説明表示
//---------------------
function disp(msg){
	$("#simDisp").text(msg);
}

function closeDialog(inDialog, inCookieName) {
	saveDialogPosition(inDialog, inCookieName);
	inDialog.dialog('close');
}

function saveDialogPosition(inDialog, inCookieName) {
	// ダイアログの位置、大きさを保存
	if (!inDialog) return;

	var obj = inDialog.parent();
	var val = obj.width() + "," + obj.height();
	saveCookie(inCookieName, val);
}

function setDialogPosition(inDialog, inCookieName, inWidth, inHeight) {
	// ダイアログの位置、大きさを取得
	var val = $.cookie(inCookieName);
	var vv = (val) ? val.split(",") : Array(inWidth, inHeight);

	var ww = parseInt(vv[0]);
	var hh = parseInt(vv[1]);
	if (ww < 1) ww = inWidth;
	if (hh < 1) hh = inHeight;

	inDialog.dialog('option', 'width', ww);
	inDialog.dialog('option', 'height', hh);

	// センターよりより若干上に設定
	var top = Math.max(0, ($(window).height() - hh) / 3);
	var pos = Array("center", top);
	inDialog.dialog('option', 'position', pos);
}

function dialogResized() {
	if (!__heightBase1) return;
	if (!__heightBase2) return;
	if (!__resizeArea) return;

	var hh = __heightBase2.position().top - __heightBase1.position().top;
	__resizeArea.css("height", hh);
}

//---------------------
//  処理中表示
//---------------------
function setBusy() {

	var dialogObj = $("#dialog");

	// buttonsは後で option で設定する
	// （２回目以降正しく設定されないため）
	dialogObj.dialog({
		autoOpen: false,
		draggable: false,
		modal: true,
		resizable: false,
		width: '300px',
		//height: '120px', // IEでエラーになる
		overlay: { opacity: 0.15, background: '#000' }
	});

	// ボタン、タイトル、メッセージの設定
	dialogObj.dialog('option', 'title', $(".ui-dialog-title").text());
	dialogObj.text('処理中....');
	dialogObj.dialog('option', 'buttons', {});

	// ダイアログ表示
	dialogObj.dialog('open');

	$(".ui-dialog-overlay").css("z-index", 9999);
	return dialogObj;
}

//------------------------ Category START -------------------

//---------------------
//  カテゴリー更新処理
//---------------------
function initCategoryItem(inMode, isMobile) {
	__isMobile = isMobile;
	if (inMode == "pop") {
		if (__isMobile == "Yes") {
			var node = $("#currNode").text();
		} else {
			var node = $.cookie('subNode');
			if (!node) node = $.cookie('popNode');
			if (!node) node = $("#currNode").text();
		}
		if (!node) node = $.cookie('currNodeObj');
		if (node) requestSubCategoryAjax(node);
	} else if (inMode == "reco") {
		getCategoryRecoItem("init");
	}
}

function getRecommendItem(inNode) {
	var ttl = (inNode.attr('node') > 0) ? " - " + inNode.text() : "";
	$('#recommendItem h2').text('お勧めアイテム' + ttl);
	$('#recoMenu li.recoItemS').attr('class', 'recoItemR');
	inNode.attr('class', "recoItemS");
	getCategoryRecoItem(inNode);
}

function getCategoryItem(inNode) {
	if (inNode.attr('proc') == 'pop') {
		$('#popularItem h2').text('人気アイテム - ' + inNode.text());
		getCategoryPopItem(inNode);
	} else if (inNode.attr('proc') == 'open') {
		$('#popularItem h2').text('人気アイテム - ' + inNode.text().substr(3));
		getCategoryPopItem(inNode);
	}
}

function getCategoryRecoItem(inNode) {
	drawCategoryRecoItemUpdate('データ取得中...');
	requestCategoryRecoItemAjax(inNode);
}

function getCategoryPopItem(inNode, inIsDblClick) {
	var node = inNode.attr('node');
	if (inNode.attr('idx')) {
		// idx 有りはメインカテゴリー
		inIsDblClick = true;
		saveCookie('currNode', inNode.attr('idx'));
		saveCookie('subNode', node);
	}
	__isDblClick = inIsDblClick;
	saveCookie('popNode', node);

	if (__isDblClick) {
		drawSubCategoryUpdate('更新中...');
		requestSubCategoryAjax(inNode);
	}
	drawCategoryPopItemUpdate('更新中...');
	requestCheckUpdatePopItemAjax(inNode);
}

function showCategoryRecoItemList() {
	$('#recommendItemList').css('display', 'block');
	$('#recommendItemListMsg').css('display', 'none');
}
function showCategoryPopItemList() {
	showSubCategoryList(); // 消すな！！（clickEventが効かない場合がある現象の対策）
	$('#popularItemList').css('display', 'block');
	$('#popularItemListMsg').css('display', 'none');
}

function catItemClickC(inNode) {
	if (__thisNode) return;

	if (__clkProc) clearTimeout(__clkProc);
	__clickNode = inNode;
	__addEvent = false;
	__clkProc = setTimeout("doGetCategoryItem(false)", 200);
}
function catItemClickAB(inNode) {
	if (__thisNode) return;

	if (__clkProc) clearTimeout(__clkProc);
	__clickNode = inNode;
	__addEvent = true;
	__clkProc = setTimeout("doGetCategoryItem(true)", 100);
}
function catBtnClick(inBtn) {
	if (__thisNode) return;

	if (__itemList) {
		msg = getMsgBoxText('データ取得中...', "msgBox");
		__itemList.html(msg);
	}

	isDblClick = (inBtn.attr("name") == "A");
	if (__clkProc) clearTimeout(__clkProc);
	__clickNode = inBtn;
	__isMobile = "Yes";

	var sel = $("#catSelect option:selected");
	if (sel.val() == null) return;
	inBtn.attr('node', sel.val());
	inBtn.attr("name", sel.text());

	__clkProc = setTimeout("doGetCategoryItem(" + isDblClick + ")", 100);
}

function showSubCategoryList() {

	if (__addEvent == true) {
		$('.catItem').click( function() { catItemClickC($(this)); __addEvent = true; });
		$('.catItemA').click( function() { catItemClickAB($(this)); });

		if (__isMobile != "Yes") {
			$('.catItemB').click( function() { catItemClickAB($(this)); });
			$('.catItemC').click( function() { catItemClickC($(this)); });
			$('.catItemC').dblclick( function() { catItemClickAB($(this)); });
		}
		__addEvent = false;
	}

	$('#subCategoryList').css('display', 'block');
	$('#subCategoryListMsg').css('display', 'none');
	__thisNode = null;
}

function doGetCategoryItem(inIsDblClick) {

	__thisNode = __clickNode;
	inNode = __thisNode;

	if (inNode.attr('proc') == 'popsub') {
		if (__isMobile == "Yes") {
			var nodeName = inNode.attr('name');
			__itemList.parent().children("h2").text(nodeName);
		} else {
			var nodeName = inNode.parent().attr('name');
			if (!nodeName) nodeName = inNode.attr('name');
			if (!nodeName) nodeName = inNode.text();
			$('#popularItem h2').text('人気アイテム - ' + nodeName);
		}
		if (inIsDblClick)
			saveCookie('subNode', inNode.attr('node'));
		getCategoryPopItem(inNode, inIsDblClick);
		__thisNode = null;
		return false;
	}
}

function requestCategoryRecoItemAjax(inNode) {

	var request = new Request();
	if (!request.ajax) return;

	var params = "mode=reco&node=" + ((typeof(inNode) == 'string') ? "init" : inNode.attr('node'));
	var callback = function (response, option) {
		try {
	    	drawCategoryRecoItemList(response);
		} catch (e) {
			drawCategoryPopItemUpdate(e.message + '<br />' + response);
		}
	}
	request.get("ajaxCategory.php", params, callback);

}

function requestCategoryPopItemAjax(inNode, inIsUpdate) {

	var request = new Request();
	if (!request.ajax) return;

	var params = "mode=" + inNode.attr('proc') + "&node=" + inNode.attr('node');
	if (__isMobile == "Yes") params += '&mobile=1';
	var callback = function (response, option) {
		try {
	    	drawCategoryPopItemList(response, option.node);
			if (option.isUpdate == 'aft')
				requestUpdatePopItemAjax(option.node, option.isUpdate);
		} catch (e) {
			drawCategoryPopItemUpdate(e.message + '<br />' + response);
		}
	}
	request.option.isUpdate = inIsUpdate;
	request.option.node = inNode;
	request.get("ajaxCategory.php", params, callback);

}

function requestSubCategoryAjax(inNode) {

	var request = new Request();
	if (!request.ajax) return;

	request.option.isInit = (typeof(inNode) == 'string');
	var node = (request.option.isInit) ? inNode : inNode.attr('node');
	var params = "node=" + node;

	var callback = function (response, option) {
    	if (!option.isInit) drawSubCategoryUpdate('編集中...');
    	__addEvent = true;
		try {
	    	drawSubCategoryList(response, option.node);
		} catch (e) {
			drawSubCategoryUpdate(e.message + '<br />' + response);
		}
	}

	request.option.node = inNode;
	request.get("ajaxSubCategory.php", params, callback);

}

function requestCheckUpdatePopItemAjax(inNode) {

	var request = new Request();
	if (!request.ajax) return;

	var params = "node=" + inNode.attr('node') + "&mode=check";
	var callback = function (response, option) {
		try {
			// now : すぐに更新を実行
			// aft : 後で更新を実行
			// non : 更新を実行しない
			if (response == 'now')
				requestUpdatePopItemAjax(option.node, response);
			else
				requestCategoryPopItemAjax(option.node, response);
		} catch (e) {
			drawSubCategoryUpdate(e.message + '<br />' + response);
		}
	}
	request.option.node = inNode;
	request.get("ajaxPopItem.php", params, callback);

}

function requestUpdatePopItemAjax(inNode, inIsNow) {

	var request = new Request();
	if (!request.ajax) return;

	var params = "node=" + inNode.attr('node') + "&mode=update";
	var callback = function (response, option) {
    	// ここで ajax.responseText が空の場合がある
    	// その場合何もしない
		try {
			if (option.isNow == 'now') {
				requestCategoryPopItemAjax(option.node, "non");
			}
		} catch (e) {
			drawSubCategoryUpdate(e.message + '<br />' + response);
		}
	}
	request.option.isNow = inIsNow;
	request.option.node = inNode;
	request.post("ajaxPopItem.php", params, callback);

}

//---------------------
//  アイテム一覧表示
//  （人気アイテム）
//---------------------
function getImgStyle(width, height) {
	var _style = "";
	if (parseInt(width) > 0) {
		_style = ' style="width:' + width + 'px; height:' + height + 'px;"';
	}
	return _style;
}
function drawCategoryPopItemList(inData, inNode) {

	try{
		var data = json_parse(inData);
		__jsonData = data;
	}catch(e){
		drawCategoryPopItemUpdate("データの取得に失敗しました。<br />" + e.message);
		return;
	}

	try {
		var msg = data.msg;
	} catch (e) {
		drawCategoryPopItemUpdate("Error: B -> " + e.message);
		drawCategoryPopItemList(inData);
		return;
	}

	var tmp = new Array();
	if (data.msg == "") {
		if (data.html)
			tmp.push(data.html);
		else {
			var ii = data.item.length;
			if (__isMobile == "Yes") {
				for (var i = 0; i < ii; i++) {
					var v = data.item[i];
					var _style = getImgStyle(v.width, v.height);

					tmp.push('<li>');
					tmp.push('<a href="#" class="im" i="asin=' + v.asin + '">');
					tmp.push('<img src="' + v.image + '" alt="' + v.alt + '"' + _style + ' />');
					tmp.push('<br /><span class="users">' + v.users + '</span>');
					tmp.push('<br />' + v.title );
					tmp.push('</a>');
					tmp.push('</li>');
				}
			} else {
				for (var i = 0; i < ii; i++) {
					var v = data.item[i];
					var _style = getImgStyle(v.width, v.height);

					tmp.push('<li>');
					tmp.push('<a href="item/asin/' + v.asin + '/">');
					tmp.push('<img src="' + v.image + '" title="' + v.alt + '"' + _style + ' />');
					tmp.push('<br /><span class="users">' + v.users + '</span>');
					tmp.push('<br />' + v.title );
					tmp.push('</a>');
					tmp.push('</li>');
				}
			}
		}
	} else {
		tmp.push('<div class="msgBox">');
		tmp.push(data.msg);
		tmp.push('</div>');
	}
	tmp.push('<div class="clr"></div>');

	if (__isMobile == "Yes") {
		__itemList.html(tmp.join(""));
		var browser = document.getElementById('browser').object;
		var Pfix = browser.getCurrentPfix();
		browser.idList.pop();
		browser.idList.push(inNode.attr('node'));
		$('.im').click( function() { drawItemDetail(Pfix, $(this)); return false; });
	} else
		$("#popularItemList").html(tmp.join(""));

	setTimeout('showCategoryPopItemList()', 50);
	return;
}

//---------------------
//  アイテム一覧表示
//  （お勧めアイテム）
//---------------------
function drawCategoryRecoItemList(inData) {

	try{
		var data = json_parse(inData);
		__jsonData = data;
	}catch(e){
		drawCategoryRecoItemUpdate("データの取得に失敗しました。<br />" + e.message);
		return;
	}

	try {
		var msg = data.msg;
	} catch (e) {
		drawCategoryRecoItemUpdate("Error: B -> " + e.message);
		drawCategoryRecoItemList(inData);
		return;
	}
	if (__isMobile != "Yes")
		$('#recommendItem h2').text('お勧めアイテム' + data.categoryName);

	var tmp = new Array();
	if (data.msg == "") {
		tmp.push(data.html);
	} else {
		tmp.push('<div class="msgBox">');
		tmp.push(data.msg);
		tmp.push('</div>');
	}
	$("#recommendItemList").html(tmp.join(""));
	setTimeout('showCategoryRecoItemList()', 300);
	return;
}

//---------------------
//  サブカテゴリー一覧表示
//---------------------
function drawSubCategoryList(inData, inNode) {

	try{
		var data = json_parse(inData);
	}catch(e){
		drawSubCategoryUpdate("データの取得に失敗しました。<br />" + e.message);
		if ((typeof(inNode) != 'string'))
			requestSubCategoryAjax(inNode);
		return;
	}

	var tmp = new Array();
	try {
		var msg = data.msg;
	} catch (e) {
		drawSubCategoryUpdate("Error: C -> " + e.message);
		drawSubCategoryItemList(inData);
		return;
	}

	var currName = "";
	var currNode = $.cookie('popNode');
	if (!currNode) data.node;
	if (data.msg == "") {
		var _id = null;
		var _name = null;
		var isMain = false;
		if ((typeof(inNode) != 'string')) isMain = inNode.attr('proc') == 'open';
		if (isMain) {
			_id = inNode.attr('id');
			_name = inNode.text().substr(3);
			tmp.push('<span class="catItemA" name="' + _name);
			tmp.push('" proc="popsub" node="' + _id + '" >' + _name + '</span>');
		} else {
			for (var i = data.item.length - 1; i >= 0; i--) {
				var v = data.item[i];
				if (!v.parent) {
					// 保存しておく
					if (_id) saveCookie('currNodeObj', _id);
					break;
				}

				_id		= v.id;
				_name	= v.name;
				if (currNode == _id) currName = _name;
				tmp.push('<span class="catItemA" name="' + _name);
				tmp.push('" proc="popsub" node="' + _id + '" >' + _name + '</span>');
			}
		}
		tmp.push('<div class="clr catItemLine"></div>');

		// 子ノード
		tmp.push('<div style="float: left; width: 100%;">');
		if (__isMobile == "Yes") {
			var onclick = 'onclick="catBtnClick($(this)); return false;"';
			tmp.push('<select id="catSelect">');
			for (var i = 0, ii = data.item.length; i < ii; i++) {
				var v = data.item[i];
				if (v.parent) break;
				tmp.push('<option value="' + v.id + '">' + v.name + '</option>');
			}
			tmp.push('</select>');
			tmp.push('<br />');
			tmp.push('<div style="width: 97%; margin-top: 6px;">');
			tmp.push('<input class="catBtn" name="A" type="button" proc="popsub" ' + onclick + ' value="下の階層に移動" />');
			tmp.push('<input class="catBtn" name="B" type="button" proc="popsub" ' + onclick + ' value="この階層を表示" />');
			tmp.push('</div>');
		} else {
			tmp.push('<ul>');
			for (var i = 0, ii = data.item.length; i < ii; i++) {
				var v = data.item[i];
				if (v.parent) break;

				_id		= v.id;
				_name	= v.name;
				if (currNode == _id) currName = '[ ' + _name + ' ] ';
				tmp.push('<div class="catLine">');
				tmp.push('<li class="catItemB" proc="popsub" node="' + _id + '" name="' + _name + '">&nbsp;</li>');
				tmp.push('<li class="catItemC" proc="popsub" node="' + _id + '">[ ' + _name + ' ] </li>');
				tmp.push('</div>');
			}
			tmp.push('</ul>');
		}
		tmp.push('</div>');

	} else {
		tmp.push('<div class="msgBox">');
		tmp.push(data.msg);
		tmp.push('</div>');
	}
	tmp.push('<br clear="both">');

	$("#subCategoryList").html(tmp.join(""));
	showSubCategoryList();
	return;
}

function getMsgBoxText(inMsg, inClass) {
	var tmp = new Array();
	tmp.push('<div class="'+ inClass + '">');
	tmp.push(inMsg);
	tmp.push('</div>');
	tmp.push('<div clear="clr"></div>');
	return tmp.join("");
}

function drawSubCategoryUpdate(inMsg) {
	if (inMsg == '') return;
	msg = getMsgBoxText(inMsg, "msgBoxB");
	$('#subCategoryList').css('display', 'none');
	$('#subCategoryListMsg').css('display', 'block');
	$("#subCategoryListMsg").html(msg);
	return;
}

function drawCategoryRecoItemUpdate(inMsg) {
	msg = getMsgBoxText(inMsg, "msgBox");
	$('#recommendItemList').css('display', 'none');
	$('#recommendItemListMsg').css('display', 'block');
	$("#recommendItemListMsg").html(msg);
	return;
}
function drawCategoryPopItemUpdate(inMsg) {
	msg = getMsgBoxText(inMsg, "msgBox");
	$('#popularItemList').css('display', 'none');
	$('#popularItemListMsg').css('display', 'block');
	$("#popularItemListMsg").html(msg);
	return;
}

//------------------------ Category END -------------------

//------------------------ Tag START -------------------
var COOKIE_TAG_DIALOG = 'tagdialog';

function closeTagDialog(inDialog) {
	if (!inDialog) return;

	// 削除の確認は保存しない
	if (__updateMode != 'del')
		closeDialog(inDialog, COOKIE_TAG_DIALOG);

	inDialog.dialog('close');
}

function drawTagItemUpdate(inMsg) {
	if (inMsg == '') return;

	msg = getMsgBoxText(inMsg, "msgBoxMin");
	$('#tagItems').css('display', 'none');
	$('#tagItemsMsg').css('display', 'block');
	$("#tagItemsMsg").html(msg);
	return;
}

function showTagItemList() {
	$('#tagItems').css('display', 'block');
	$('#tagItemsMsg').css('display', 'none');
}

//---------------------
//  ダイアログ表示
//---------------------
function showInputTagDialog(proc){

	if (proc == 'open')	{

		var dialogObj = $("#inputTag");

		// buttonsは後で option で設定する
		// （２回目以降正しく設定されないため）
		dialogObj.dialog({
			autoOpen: false, draggable: true, modal: true, resizable: true,
			overlay: {opacity:0.5, background:'#000'}
		});

		// ボタン、タイトル、メッセージの設定
		var btn = {};
		btn['ＯＫ'] = function(){ requestTagAjax(__updateMode, $(this)); };
		btn['キャンセル'] = function(){ closeTagDialog($(this)); };
		dialogObj.dialog('option', 'buttons', btn);
		dialogObj.dialog('option', 'title', (__updateMode == 'add') ? 'タグの登録' : 'タグの修正');
		$("#addMsg").css('display', (__updateMode == 'add') ? 'block' : 'none');

		// width,height,left,top
		var MAX_HEIGHT = 250;
		setDialogPosition(dialogObj, COOKIE_TAG_DIALOG, 500, MAX_HEIGHT);
		dialogObj.dialog('option', 'minWidth', 350);
		dialogObj.dialog('option', 'minHeight', MAX_HEIGHT);
		dialogObj.dialog('option', 'maxHeight', MAX_HEIGHT);

		dialogObj.dialog('open');
		dialogObj.css('display', 'block');
		$("#tagName").focus().select();

		// ダイアログ表示
		dialogObj.dialog('open');
	}

}

//---------------------
//  タグの追加
//---------------------
function addTagData() {
	__updateMode = "add";
	showInputTagDialog('open');
}
//---------------------
//  タグの編集
//---------------------
function updTagData(item) {
	__aid = 0;
	var idx = -1;
	for (var i = 0, ii = __jsonData.item.length; i < ii; i++) {
		if (__jsonData.item[i].tagCode == item) {
			idx = i;
			break;
		}
	}

	if (idx >= 0) {
		$("#tagName").val(__jsonData.item[idx].tagName);
		__aid = __jsonData.item[idx].tagCode;
	}
	__updateMode = "upd";
	showInputTagDialog('open');
}

//---------------------
//  タグの削除
//---------------------
function delTagData() {

	__updateMode = "del";

	var dialogObj = $("#dialog");

	// buttonsは後で option で設定する
	// （２回目以降正しく設定されないため）
	dialogObj.dialog({
		autoOpen: false, draggable: true, modal: true, resizable: false,
		width: '400px',
		//height: '250px',
		overlay: {opacity:0.2, background:'#000'}
	});

	// ボタン、タイトル、メッセージの設定
	var btn = {};
	var cnt = $("input:checkbox[@name=tags]:checked").size();
	if (cnt == 0) {
		btn['閉じる'] = function(){ closeTagDialog($(this)); };
		dialogObj.dialog('option', 'title', 'タグの削除');
		dialogObj.text('タグが選択されていません。');
	} else {
		btn['はい'] = function(){ requestTagAjax(__updateMode, $(this)); };
		btn['いいえ'] = function(){ closeTagDialog($(this)); };
		dialogObj.dialog('option', 'title', '削除の確認');
		dialogObj.text('選択した ' + cnt + '個のタグを削除しますか？');
	}
	dialogObj.dialog('option', 'buttons', btn);

	// ダイアログ表示
	dialogObj.dialog('open');

}

//---------------------
//  タグ更新処理
//---------------------
function requestTagAjax(mode, dialogObj) {

	var request = new Request();
	if (!request.ajax) return;

	var params = "mode=" + mode;
	if (mode == "del") {
		params += "&aid=" + getCheckItems("tags");
	} else if (mode != "get") {
		params += "&t=" + $("#tagName").val();
		if (mode == "upd") {
			params += "&aid=" + __aid;
		}
	}

	var callback = function (response, option) {
    	drawTagList(response);
		closeTagDialog(option.dialog);
		return;
	}
	request.option.dialog = dialogObj;
	request.post("ajaxTag.php", params, callback);

}

//---------------------
//  タグ一覧表示
//---------------------
function drawTagList(inData) {

	try{
		var data = json_parse(inData);
		__jsonData = data;
	}catch(e){
		alert("エラー：" + e.message);
		return;
	}

	var tmp = new Array();
	tmp.push('<table class="list">');
	tmp.push('<tr>');
	tmp.push('<th width="30px">選択</th>');
	tmp.push('<th width="30px">編集</th>');
	tmp.push('<th width="300px">タグ名</th>');
	tmp.push('<th width="70px">アイテム数</th>');
	tmp.push('<th width="30px">表示</th>');
	tmp.push('</tr>');

	$("#msgArea").html(data.msg);
	for (var i = 0, ii = data.item.length; i < ii; i++) {
		var v = data.item[i];
		var _code	= v.tagCode;

		tmp.push('<tr align="center">');
		tmp.push('<td>');
		tmp.push('<input type="checkbox" id="Tag' + _code + '" name="tags" value="' + _code + '" />');
		tmp.push('</td>');
		tmp.push('<td>');
		tmp.push('<input type="button" id="btn_' + _code + '" value="..." onclick="updTagData(\'' + _code + '\');" />');
		tmp.push('</td>');
		tmp.push('<td align="left">');
		tmp.push(v.tagName);
		tmp.push('</td>');
		tmp.push('<td align="right">');
		tmp.push(v.tagCount);
		tmp.push('</td>');
		tmp.push('<td>');
		tmp.push('<input type="button" value="..." onclick="requestTagItemAjax(\'' + _code + '\');" />');
		tmp.push('</td>');
		tmp.push('</tr>');
	}
	tmp.push('</table>');

	$("#tagList").html(tmp.join(""));
	return;
}

//---------------------
//  タグ更新処理
//---------------------
function requestTagItemAjax(inCode) {
	drawTagItemUpdate("データ取得中...");

	var request = new Request();
	if (!request.ajax) return;

	var params = "t=" + inCode;
	var callback = function (response, option) {
		drawTagItemUpdate("編集中...");
    	drawTagItemList(response);
    	return;
	}
	request.get("ajaxTagItem.php", params, callback);

}
//---------------------
//  タグアイテム一覧表示
//---------------------
function drawTagItemList(inData) {

	try{
		var data = json_parse(inData);
	}catch(e){
		alert("エラー：" + e.message);
		return;
	}

	var tmp = new Array();

	if (data.msg == "") {
		for (var i = 0, ii = data.item.length; i < ii; i++) {
			var v = data.item[i];
			tmp.push('<img src="' + v.image + '" title="' + v.title + '" />');
		}
	} else {
		tmp.push(data.msg);
	}

	$("#tagItems").html(tmp.join(""));
	setTimeout("showTagItemList()", 50);
	return;
}

//------------------------ Tag END -------------------

//------------------------ ItemRecommend START -------------------
var COOKIE_RECO_DIALOG = 'recodialog';

function closeRecoDialog(inDialog) {
	if (!inDialog) return;

	// 削除の確認は保存しない
	if (__updateMode != 'rmv')
		closeDialog(inDialog, COOKIE_RECO_DIALOG);

	inDialog.dialog('close');
}

function itemRecommend(inObj) {
	__updateMode = inObj.attr('mode');

	switch(__updateMode) {
		case "add":
		case "edt":
			getRecoData(inObj);
			break;
		case "rmv":
			removeRecommend(inObj);
			break;
		default:
			alert("エラー");
	}
}

//---------------------
//  お勧めアイテム取得
//---------------------
function getRecoData(inObj) {

	var request = new Request();
	if (!request.ajax) return;

	var params = "mode=get&i=" + inObj.attr('item');
	var callback = function (response, option) {
    	if (updateRecoDialog(response))
			addRecommend(option.obj);
	}
	request.option.obj = inObj;
	request.post("ajaxRecoItem.php", params, callback);

}

function updateRecoDialog(inData) {

	try{
		var data = json_parse(inData);
	}catch(e){
		alert("エラー：" + e.message);
		return false;
	}

	if (data.isMax != "No") {
		if (__updateMode == "add") {
			return false;
		}
		$("#recoFree").text("　");
	} else {
		$("#recoFree").text(data.free);
	}

	$("#recoDate").text(data.date);
	$("#recoCount").text(data.count);
	$("#recoComment").val(data.comment);
	return true;
}

//---------------------
//  お勧めの追加
//---------------------
function addRecommend(inObj) {

	// ダイアログ設定
	__dialog = $("#inputReco");
	__heightBase1 = $("#recoHeightBase1");
	__heightBase2 = $("#recoHeightBase2");
	__resizeArea = $("#recoComment");

	// buttonsは後で option で設定する
	// （２回目以降正しく設定されないため）
	__dialog.dialog({
		autoOpen: false, draggable: true, modal: true, resizable: true,
		overlay: {opacity:0.5, background:'#000'},
		close: function() { closeRecoDialog(null); },
		resize: function() { dialogResized(); }
	});

	// ボタン、タイトル、メッセージの設定
	var btn = {};
	btn['登録'] = function(){ requestRecommendAjax(inObj, "add"); closeRecoDialog($(this)); };
	if (__updateMode == "edt") {
		btn['解除'] = function(){ removeRecommend(inObj); };
	}
	btn['キャンセル'] = function(){ closeRecoDialog($(this)); };
	__dialog.dialog('option', 'title', 'お勧めの登録');

	// width,height,left,top
	var MIN_HEIGHT = 300;
	var MAX_HEIGHT = 500;
	setDialogPosition(__dialog, COOKIE_RECO_DIALOG, 500, MIN_HEIGHT);
	__dialog.dialog('option', 'minWidth', 350);
	__dialog.dialog('option', 'minHeight', MIN_HEIGHT);
	__dialog.dialog('option', 'maxHeight', MAX_HEIGHT);

	__dialog.dialog('option', 'buttons', btn);

	// ダイアログ表示
	__dialog.dialog('open');
	__dialog.css("display", 'block');
	dialogResized();

}

//---------------------
//  お勧めの解除
//---------------------
function removeRecommend(inObj) {

	var dialogObj = $("#dialog");

	// buttonsは後で option で設定する
	// （２回目以降正しく設定されないため）
	dialogObj.dialog({
		autoOpen: false, draggable: true, modal: true, resizable: false,
		width: '400px',
		//height: '200px',
		overlay: {opacity:0.2, background:'#000'}
	});

	// ボタン、タイトル、メッセージの設定
	var btn = {};
	btn['はい'] = function(){
		requestRecommendAjax(inObj, "rmv");
		closeRecoDialog($(this));
		if (__updateMode == "edt") closeRecoDialog(__dialog);
	};
	btn['いいえ'] = function(){ closeRecoDialog($(this)); };
	dialogObj.dialog('option', 'title', '解除の確認');
	dialogObj.text('このアイテムをお勧めから解除しますか？');

	dialogObj.dialog('option', 'minWidth', 400);
	dialogObj.dialog('option', 'minHeight', 200);
	dialogObj.dialog('option', 'maxHeight', 200);

	dialogObj.dialog('option', 'buttons', btn);

	// ダイアログ表示
	dialogObj.dialog('open');
}

//---------------------
//  お勧めリクエスト
//---------------------
function responseRecommendAjax(inObj, inData, inMode) {

	try{
		var data = json_parse(inData);
	}catch(e){
		alert("エラー：" + e.message);
		return;
	}

	if (data.sts < 0) {
		// エラー
		alert(data.msg);
		return;
	}

	var itemNo = inObj.attr('item');
	$("#recoCmt_" + itemNo).html(data.comment);

	switch (inMode) {
		case "add":
			var dsp1 = "none";
			var dsp2 = "inline";
			break;
		case "rmv":
			var dsp1 = "inline";
			var dsp2 = "none";
			break;
		default:
			return;
	}

	$("#recoAdd_" + itemNo).css("display", dsp1);
	$("#recoEdt_" + itemNo).css("display", dsp2);
	$("#recoRmv_" + itemNo).css("display", dsp2);
	$("#Reco_" + itemNo).html(data.html);
}

//---------------------
//  お勧め更新処理
//---------------------
function requestRecommendAjax(inObj, inMode) {

	var request = new Request();
	if (!request.ajax) return;

	var params = "mode=" + inMode + "&i=" + inObj.attr('item');
	if (inMode != "rmv") params += "&cm=" + $("#recoComment").val();

	var callback = function (response, option) {
   		responseRecommendAjax(option.obj, response, option.mode);
	}
	request.option.obj = inObj;
	request.option.mode = inMode;
	request.post("ajaxRecoItem.php", params, callback);

}

//------------------------ ItemRecommend END -------------------

//------------------------ Item START -------------------
var COOKIE_ITEM_DIALOG = 'itemdialog';

function closeItemDialog(inDialog) {
	if (!__dialog) return;

	if (inDialog) {
		closeDialog(inDialog, COOKIE_ITEM_DIALOG);
	}

	__dialog = null;
	__resizeArea = null;
	__heightBase1 = null;
	__heightBase2 = null;
}

//---------------------
//  ダイアログ表示
//---------------------
function showInputItemDialog(proc){

	if (proc == 'open')	{

		// クリア
		closeItemDialog(null);

		// ダイアログ設定
		__dialog = $("#inputData");
		__heightBase1 = $("#itemHeightBase1");
		__heightBase2 = $("#itemHeightBase2");
		__resizeArea = $("#comment");

		// buttonsは後で option で設定する
		// （２回目以降正しく設定されないため）
		__dialog.dialog({
			autoOpen: false, draggable: true, modal: true, resizable: true,
			overlay: {opacity:0.5, background:'#000'},
			close: function() { closeItemDialog(null); },
			resize: function() { setTimeout('dialogResized()', 20); }
		});

		var isAdd = ($("#proc").val() == "add");
		var btn = {};
		var btnCaption = (isAdd) ? "登録する" : "更新する";
		btn[btnCaption] = function(){ itemUpdate('upd'); };
		btn['キャンセル'] = function(){ closeDialog(__dialog, COOKIE_ITEM_DIALOG); };
		__dialog.dialog('option', 'buttons', btn);
		__dialog.dialog('option', 'title', (isAdd) ? 'データの登録' : 'データの修正');

		// width,height,left,top
		setDialogPosition(__dialog, COOKIE_ITEM_DIALOG, 730, 550);
		__dialog.dialog('option', 'minWidth', 730);
		__dialog.dialog('option', 'minHeight', 550);

		__dialog.dialog('open');
		__dialog.css("display", 'block');
		dialogResized();
		$("#tagtext").focus().select();
	}
}

//---------------------
//  アイテム更新
//---------------------
function itemEdit() {
	showInputItemDialog('open');
}
//---------------------
//  更新処理
//---------------------
function itemUpdate(proc) {
	setBusy();
	saveDialogPosition(__dialog, COOKIE_ITEM_DIALOG);
	$("#proc").val(proc);
	$("#inputDataForm").submit();
	setTimeout("closeItemDialog(null)", 1000);
}
//---------------------
//  削除処理
//---------------------
function itemDelete() {
	if ($("#checkDelete").attr("checked")) {
		itemUpdate('del');
		return;
	}
	alert("削除する場合は、「本当に削除する」をチェックしてください。");
}

function requestNdcAjax(isDialog) {

	var request = new Request();
	if (!request.ajax) return;

	var asinCode = $("#asinCode").val();
	var params = "mode=upd&a=" + asinCode;
	if (isDialog) {
		_dialog = showBusy("取得中...");
		params += "&m=1";
	} else {
		if ($("#updNdcBtn")) {
			$("#updNdcBtn").attr("disabled", true);
			$("#updNdcBtn").val("取得中...");
		}
	}
	var callback = function (response, option) {
		var data = json_parse(response);
		if (data.text)
			$("#NDCNBN").html(data.text);
		else {
			$("#updNdcBtn").css("display", "none");
		}
		if (isDialog) hideBusy();
	}
	request.post("ajaxItemData.php", params, callback);
}

//------------------------ Item END -------------------

//------------------------ Action START -------------------
var COOKIE_ACTION_DIALOG = 'actdialog';

function closeActionDialog(inDialog) {
	if (!__dialog) return;

	if (inDialog) {
		closeDialog(inDialog, COOKIE_ACTION_DIALOG);
	}

	__dialog = null;
	__heightBase1 = null;
	__heightBase2 = null;
	__resizeArea = null;
}

//---------------------
//  ダイアログ表示
//---------------------
function showActionDialog(proc) {

	if (proc == 'open')	{

		__dialog = $("#inputAction");
		__heightBase1 = $("#actHeightBase1")
		__heightBase2 = $("#actHeightBase2")
		__resizeArea = $("#itemActMemo");

		// buttonsは後で option で設定する
		// （２回目以降正しく設定されないため）
		__dialog.dialog({
			autoOpen: false, draggable: true, modal: true, resizable: true,
			overlay: {opacity:0.8, background:'#000'},
			close: function() { closeActionDialog(null); },
			resize: function() { dialogResized(); }
		});

		var btn = {};
		if (__updateMode == "dsp") {
			btn['閉じる'] = function(){ closeActionDialog($(this)); };
		} else {
			btn["ＯＫ"] = function(){ updateActionData(__updateMode); closeActionDialog($(this)); };
			btn['キャンセル'] = function(){ closeActionDialog($(this)); };
		}
		__dialog.dialog('option', 'buttons', btn);
		switch (__updateMode) {
			case "add":
				__dialog.dialog('option', 'title', '履歴の登録');
				break;
			case "upd":
				__dialog.dialog('option', 'title', '履歴の修正');
				break;
			case "dsp":
				__dialog.dialog('option', 'title', '履歴の詳細');
				break;
		}

		// width,height,left,top
		setDialogPosition(__dialog, COOKIE_ACTION_DIALOG, 500, 350);

		__dialog.dialog('open');
		__dialog.css('display', 'block');

		dialogResized();
		$("#itemAct").focus().select();
	}

}

//---------------------
//  履歴の取得
//---------------------
function getActionData() {
	requestAjax("get");
}
//---------------------
//  履歴の一覧取得
//---------------------
function listActionData() {
	requestActionAjax("list", "actionList");
}
//---------------------
//  履歴の一覧取得
//---------------------
function listActionDataMobile() {
	requestActionAjax("listAll", "actionListAll");
}
//---------------------
//  履歴の追加
//---------------------
function addActionData() {
	__updateMode = "add";
	var today = new Date();
	var yy = today.getFullYear();
	var mm = today.getMonth() + 1;
	var dd = today.getDate();
	if (mm < 10) mm = '0' + mm;
	if (dd < 10) dd = '0' + dd;
	$("#itemActDate").val(yy + '-' + mm + '-' + dd);
	showActionDialog('open');
}
//---------------------
//  履歴の削除
//---------------------
function delActionData() {
	updateActionData("del");
}
//---------------------
//  履歴の編集・詳細
//---------------------
function showUpdActionData(item, inMode) {

	__aid = 0;
	var idx = -1;
	for (var i = 0, ii = __jsonData.item.length; i < ii; i++) {
		if (__jsonData.item[i].id == item) {
			idx = i;
			break;
		}
	}

	if (idx >= 0) {
		var v = __jsonData.item[idx];
		$("#itemAct").val(v.actType);
		$("#itemActArea").val(v.actArea);
		$("#itemActDate").val(v.actDate);
		$("#itemActPrice").val(v.actPrice.split(",").join(""));
		$("#itemActMemo").val(v.actMemo);
		__aid = v.id;
	}
	__updateMode = inMode;
	showActionDialog('open');
}

//---------------------
//  履歴の更新前処理
//---------------------
function updateActionData(mode) {

	if (mode == "del") {
		var dialogObj = $("#dialog");

		// buttonsは後で option で設定する
		// （２回目以降正しく設定されないため）
		dialogObj.dialog({
			autoOpen: false, draggable: true, modal: true, resizable: false,
			width: 400,
			//height: 250,
			overlay: {opacity:0.5, background:'#000'}
		});

		var btn = {};
		var cnt = $("#actionList input:checkbox[@name=chk]:checked").size();
		if (cnt == 0) {
			btn['閉じる'] = function(){ $(this).dialog('close'); };
			dialogObj.dialog('option', 'title', 'データの削除');
			dialogObj.text('データが選択されていません。');
		} else {
			btn['はい'] = function(){ requestAjax(mode); $(this).dialog('close'); };
			btn['いいえ'] = function(){ $(this).dialog('close'); };
			dialogObj.dialog('option', 'title', '削除の確認');
			dialogObj.text('選択したデータを削除しますか？');
		}
		dialogObj.dialog('option', 'buttons', btn);
		dialogObj.dialog('open');

	} else {
		requestAjax(mode);
	}
	return;
}

//---------------------
//  履歴の更新処理
//---------------------
function requestAjax(inMode, isMobile) {
	__isMobile = isMobile;

	var request = new Request();
	if (!request.ajax) return;

	var asinCode = $("#asinCode").val();
	var itemNo = $("#itemNo").val();
	var actType = $("#itemAct").val();
	var actArea = $("#itemActArea").val();
	var actDate = $("#itemActDate").val();
	var actPrice = $("#itemActPrice").val();
	var actMemo = $("#itemActMemo").val();
	var userCode = $("#viewUser").attr('uid');

	var params = "mode=" + inMode
				+ "&u=" + userCode
				+ "&a=" + asinCode
				+ "&i=" + itemNo
				+ "&t=" + actType
				+ "&ar=" + actArea
				+ "&d=" + actDate
				+ "&p=" + actPrice
				+ "&m=" + actMemo;
	if (inMode == "del") {
		params += "&aid=" + getCheckItems("chk");
	} else if (inMode == "upd") {
		params += "&aid=" + __aid;
	}

	var callback = function (response, option) {
    	if ((option.mode == "list") || (option.mode == "all"))
    		drawUserActionList(response, option.userCode, option.asinCode, option.itemNo, option.mode);
    	else
    		drawActionList(response, option.userCode, option.asinCode, option.itemNo);
    	return;
	}
	var url = (inMode == "all") ? "ajaxAction.php" : "ajax.php";
	request.option.mode = inMode;
	request.option.asinCode = asinCode;
	request.option.itemNo = itemNo;
	request.option.userCode = userCode;
	request.post(url, params, callback);

}

//---------------------
//  履歴の一覧更新処理
//---------------------
function requestActionAjax(inMode, inName) {

	$('#updActionList').val("検索中...");
	$('#updActionList').attr("disabled", true);

	var request = new Request();
	if (!request.ajax) return;

	var asinCode = $("#asinCode").val();
	var itemNo = $("#itemNo").val();
	var actDate1 = $("#actDate1").val();
	var actDate2 = $("#actDate2").val();
	var actType = getCheckItems("actType");
	var actMemo = $("#actMemo").val();
	var actUser = $("#actUserName").val();
	var actTarget = $("#actUserSel").val();
	var actSort = $("#actSort").val();

	var actCond = new Array(actDate1, actDate2, actType, actSort);
	saveCookie('actCond', actCond.join("#"));
	saveCookie('actMemo', actMemo);
	saveCookie('actUser', actUser);

	var actArea = "";
	switch ($("#areaType").val()) {
		case "1":	// 自分の地域
		case "2":	// 一つ選択
			var adjArea = $("#adjArea").attr('checked');
			var overSea = $("#overSea").attr('checked');
			var selArea = $("#selArea").val();
			var areaOpt = new Array((adjArea) ? "checked" : "", (overSea) ? "checked" : "", selArea);
			saveCookie('areaOption', areaOpt.join("#"));
			var area = ($("#areaType").val() == "1") ? $("#areaList").attr('myArea') : selArea;
			actArea = getArea(area, adjArea, overSea);
			break;
		case "3":	// 複数選択
			actArea = getCheckItems("areaList");
			saveCookie('areaList', actArea);
			if (actArea == '') actArea = '-';
			break;
	}

	var params = "mode=" + inMode
				+ "&a=" + asinCode
				+ "&d1=" + actDate1
				+ "&d2=" + actDate2
				+ "&i=" + itemNo
				+ "&t=" + actType
				+ "&m=" + actMemo
				+ "&un=" + actUser
				+ "&us=" + actTarget
				+ "&ar=" + actArea
				+ "&s=" + actSort;

	var callback = function (response, option) {
		drawItemActionList(response, option.asinCode, option.itemNo, option.name);
		$('#updActionList').val("検索");
		$('#updActionList').attr("disabled", false);
    	return;
	}
	request.option.asinCode = asinCode;
	request.option.itemNo = itemNo;
	request.option.name = inName;
	request.post("ajaxAction.php", params, callback);

}

//---------------------
//  履歴の一覧表示
//---------------------
function drawItemActionList(inData, asinCode, itemNo, inName) {

	try{
		var data = json_parse(inData);
		__jsonData = data;
	}catch(e){
		alert("エラー：" + e.message);
		return;
	}

	var isNoMobile = (__isMobile != "Yes");
	var html = new Array();
	if (data.msg == "") {
		var ii = data.item.length;
		// 日付、地域、種類、価格、ユーザー、メモ、詳細
		for (var i = 0; i < ii; i++) {
			var v = data.item[i];
			html.push('<tr>');
			html.push('<td class="ac">' + v.actDate + '</td>');
			html.push('<td class="ac">' + v.actArea + '</td>');
			html.push('<td class="ac">' + v.actType + '</td>');
			html.push('<td class="ar">' + v.actPrice + '</td>');
			html.push('<td>' + v.actUser + '</td>');
			html.push('<td>' + v.actMemo + '</td>');
			if (isNoMobile)
				html.push('<td class="ac"><input type="button" id="btn_' + v.id + '" value="..."');
			html.push(' onclick="showUpdActionData(\'' + v.id + '\', \'dsp\');" /></td>');
			html.push('</tr>');
		}
	} else {
		if (isNoMobile)
			html.push('<tr><td colspan="7"><p class="msgBox">' + data.msg + '</p></td></tr>');
		else
			html.push('<tr><td colspan="6"><p class="msgBox">' + data.msg + '</p></td></tr>');
	}
	$("#" + inName).html(html.join(""));
	return;
}

function drawMoreAction(userCode, asinCode, itemNo) {
	var moreHtml = new Array();
	moreHtml.push('<a href="itemAction/');
	moreHtml.push('u/' + userCode);
	if (asinCode.length > 1)
		moreHtml.push('/asin/' + asinCode);
	else
		moreHtml.push('/code/' + itemNo);
	moreHtml.push('/">もっと見る...</a><br />');
	$("#moreAction").html(moreHtml.join(""));
}

function drawUserActionList(inData, userCode, asinCode, itemNo, inMode) {

	try{
		var data = json_parse(inData);
		__jsonData = data;
	}catch(e){
		alert("エラー：" + e.message);
		return;
	}

	var html = new Array();
	if (data.msg == "") {
		// 最大５件
		var ii = data.item.length;
		if ((ii > 5) && (inMode == 'list')) ii = 5;

		// 日付、地域、種類、価格、メモ
		for (var i = 0; i < ii; i++) {
			var v = data.item[i];
			html.push('<tr>');
			html.push('<td class="ac">' + v.actDate + '</td>');
			html.push('<td class="ac">' + v.actArea + '</td>');
			html.push('<td class="ac">' + v.actType + '</td>');
			html.push('<td class="ar">' + v.actPrice + '</td>');
			html.push('<td>' + v.actMemo + '</td>');
			html.push('</tr>');
		}
	} else {
		html.push('<tr><td colspan="5">' + data.msg + '</td></tr>');
	}

	drawMoreAction(userCode, asinCode, itemNo);
	$("#actionList").html(html.join(""));
	return;
}

function drawActionList(inData, userCode, asinCode, itemNo) {

	try{
		var data = json_parse(inData);
		__jsonData = data;
	}catch(e){
		alert("エラー：" + e.message);
		return;
	}

	var isMobile = (__isMobile == "Yes");
	var html = new Array();
	if (data.msg == "") {
		var ii = data.item.length;

		// 選択、編集、日付、種類、地域、価格、メモ
		for (var i = 0; i < ii; i++) {
			var v = data.item[i];

			html.push('<tr>');

			if (!isMobile) {
				var _id = v.id;
				html.push('<td class="ac"><input type="checkbox" name="chk" id="chk_' + _id + '" value="' + _id + '" /></td>');
				html.push('<td class="ac"><input type="button" id="btn_' + _id + '" value="..." onclick="showUpdActionData(\'' + _id + '\', \'upd\');" /></td>');
			}

			html.push('<td class="ac">' + v.actDate + '</td>');
			html.push('<td class="ac">' + v.actArea + '</td>');
			html.push('<td class="ac">' + v.actType + '</td>');
			html.push('<td class="ar">' + v.actPrice + '</td>');
			html.push('<td>' + v.actMemo + '</td>');
			html.push('</tr>');
		}
	} else {
		if (isMobile)
			html.push('<tr><td colspan="5">' + data.msg + '</td></tr>');
		else
			html.push('<tr><td colspan="7">' + data.msg + '</td></tr>');
	}

	if (!isMobile) drawMoreAction(userCode, asinCode, itemNo);
	$("#actionList").html(html.join(""));
	return;
}
//------------------------ Action END -------------------

function detailDialog() {

	var dialogObj = $("#editorialReview");

	// buttonsは後で option で設定する
	// （２回目以降正しく設定されないため）
	dialogObj.dialog({
		autoOpen: false,
		draggable: true,
		modal: true,
		resizable: true,
		overlay: { opacity: 0.15, background: '#000' }
	});

	// ボタン、タイトル、メッセージの設定
	var btn = {};
	btn['閉じる'] = function(){ dialogObj.dialog('close'); };
	dialogObj.dialog('option', 'buttons', btn);
	dialogObj.dialog('option', 'title', 'アイテム詳細');

	// width,height,left,top
	setDialogPosition(dialogObj, COOKIE_ITEM_DIALOG, 730, 550);
	dialogObj.dialog('option', 'minWidth', 730);
	dialogObj.dialog('option', 'minHeight', 550);

	// ダイアログ表示
	dialogObj.dialog('open');

	$(".ui-dialog-overlay").css("z-index", 9999);

}

//------------------------ Item Search START -------------------
function showSearchMsg() {

	var dialogObj = $("#dialog");

	// buttonsは後で option で設定する
	// （２回目以降正しく設定されないため）
	dialogObj.dialog({
		autoOpen: false,
		draggable: false,
		modal: true,
		resizable: false,
		width: '250px'
	});

	// ボタン、タイトル、メッセージの設定
	dialogObj.text('データ取得中....');
	dialogObj.dialog('option', 'buttons', {});

	// ダイアログ表示
	dialogObj.dialog('open');

	$(".ui-dialog-titlebar").css("display", "none");
	$(".ui-dialog").css("height", "40px");
	$(".ui-dialog-overlay").css("z-index", 9999);

	return dialogObj;
}

function requestItemSearchAjax(inPage, inDialog) {

	var request = new Request();
	if (!request.ajax) return;

	var params = "page=" + inPage + "&" + $("#searchCond").serialize();

	var callback = function (response, option) {
		drawItemSearchList(response);
		option.dialog.dialog('close');
    	return;
	}
	request.option.dialog = (inDialog) ? inDialog : showSearchMsg();
	request.post("ajaxSearch.php", params, callback);

}

function drawItemSearchList(inData) {

	try{
		var data = json_parse(inData);
	}catch(e){
		alert("エラー：" + e.message);
		return;
	}

	var html = new Array();
	if (data.msg == "") {
		html.push(data.navi);
		html.push(data.html);
		html.push(data.navi);
	} else {
		html.push('<div class="msgBox">' + data.msg + '</div>');
	}

	$("#searchItems").html(html.join(""));
	$('.chksts label').click( function() { stsClick($(this)); } );
	return;
}

function requestItemEntryAjax(inPage) {

	var request = new Request();
	if (!request.ajax) return;

	request.option.dialog = setBusy();
	var params = "mode=update&" + $("#itemListForm").serialize();

	var callback = function (response, option) {
    	requestItemSearchAjax(option.page, option.dialog);
    	return;
	}
	request.option.page = inPage;
	request.post("checkItemEntry.php", params, callback);

}
//------------------------ Item Search END -------------------

