// JavaScript Document
//
/*****************************
 * 選択画像アップロード処理
 *****************************/
function changeImgPath() {
    //選択画像アップロード処理
    $('item_photo').action = 'do_item_photo_update';
    $('item_photo').submit();
}

function updateItemInfo(baseuri) {
	$('itemresult').innerHTML="更新中...";

	var url = baseuri+'ajax_itemedit_itemupdate';
	var myAjax = new Ajax.Updater( 'itemresult', url, { method: 'post', parameters: Form.serialize(item_photo) });
}



function change_color(index) {
	//セレクト画像マーキング
	var before_val = document.item_photo.selected_item.value;

  if(document.getElementById("box"+before_val) == null ) {
		document.item_photo.selected_item.value = 0;
  } else {
		bytefx.color(document.getElementById("box"+before_val), "backgroundColor", "#99AAFF", "#99AAFF", 1);
	}
	
	bytefx.color(document.getElementById("box"+index), "backgroundColor", "#55CC99", "#00ffaa", 1);
	
	document.item_photo.selected_item.value = index;
	
	if( index != 0 ) {
		document.getElementById("comment").value = document.getElementById("photo_comment"+index).value;
	}
}

function item_regist_edit(baseuri, item_id) {
	
	var cl1 = document.getElementsByName("category_list1").item(0);
	var select_cate = document.getElementsByName("selected_category").item(0);
	var ary = Array();
	
	for( var i=0; i < cl1.length; i++ ) {
			ary[i] = cl1.options[i].value;
	}
	select_cate.value = ary;
//	alert(select_cate.value);
//	exit;
	
	if( isNaN(item_id) || item_id == "" ) {
		//submit送信
		$('iteminfo').action = 'ajax_item_regist_edit';
		form_submit('iteminfo');
	} else {
		//ajax送信
		$('itemresult').innerHTML="更新中...";
		var url = baseuri+'ajax_item_regist_edit';
		
		//処理開始
		var myAjax = new Ajax.Updater( 'itemresult', url, { method: 'post', parameters: Form.serialize(iteminfo) });
	}
}

function upPhoto(baseuri) {
	//画像を任意に処理
	$('itemresult').innerHTML="更新中...";

	var url = baseuri+'ajax_item_img_update';
	var target = "photo_design";
	var myAjax = new Ajax.Updater( target, url, { method: 'post', parameters: Form.serialize(item_photo) });
	var selected_item = document.item_photo.selected_item.value;
	
	if( selected_item != 0 && document.getElementById("rt1").checked == true ) {
		document.getElementById("img"+selected_item).src = document.getElementById("img").src;
	}

	document.item_photo.selected_item.value = 0;

	$('itemresult').innerHTML="";
}

function change_photo(app_baseuri, clicked, item_id, stock_id, item_photo_no) {
	//画像切り替え
	var img_src = app_baseuri+"item_img/img_resample.php?item_id="+item_id+"&stock_id="+stock_id+"&item_photo_no="+item_photo_no+"&size=L"
	document.getElementById("detail_img").src = img_src;
}

function autoexec() {
    Event.observe($('image'), 'change', changeImgPath, true);
}
