{include file="page_header.htm"}
{insert_scripts files="../js/utils.js"}

<form enctype="multipart/form-data" name="theForm" action="category.php" method="post" onsubmit="return validate()">
{foreach from=$category_info item=list name=foo}
	<table width="100%"  border="0" cellspacing="0" cellpadding="0" class="table_form1" {if $smarty.foreach.foo.index>0} style="display:none" {/if} id="language_{$list.language_id}-table">	
	<tr>
	<td class="label" valign="top">分类名称:</td>
	<td><input name="name_{$list.language_id}" type="text" value="{$list.name}" size="40" class="FormSmall" /><span class="required">&nbsp;</span></td>
	</tr>
	<tr>
	<td class="label" valign="top">上级分类:</td>
	<td>
	<select name="parent_id_{$list.language_id}" id="parent_id_{$list.language_id}" class="category_select" style="padding-top:3px; padding-bottom:3px;">
	<option value="0">--设为顶级分类--</option>
	{foreach from=$list.category_tree item=val}
	<option value="{$val.category_id}"{if $val.category_id == $category.parent_id} selected{/if}>{'--'|str_repeat:$val.level}{$val.name}</option>
	{/foreach}
	</select>
	</td>
	</tr>	
	{if $smarty.foreach.foo.index == 0}
	<tr>
	<td class="label">图片:</td>
	<td>
	<input class="upload_image_btn" id="upload_image" name="upload_image" type="file" />
	<div id="image_box">
	{if $category.image neq ""}<br />
	<a href="../{$category.image}" target="_blank"><img src="../{$category.image_thumb}" border="0"  /></a>
	<div style="margin-top:5px;width:150px;text-align:center;margin-bottom:10px;">
	{literal}
	<a href="javascript:;" onclick="if(confirm('您确实要删除该图片吗?')){drop_image();}">删除</a>
	{/literal}
	</div>
	{/if}
	</div>
	<input name="image" type="hidden" value="{$category.image}" id="image" />
	</td>
	</tr>
	{/if}		
	<tr>
	<td class="label" valign="top">描述:</td>
	<td>{$list.description}</td>
	</tr>	
	{if $smarty.foreach.foo.index == 0}
	<tr>
	<td class="label" valign="top">排序:</td>
	<td><input name="sort_order" type="text" value="{$category.sort_order}" class="FormSmall" style="width:60px;" /> 输入整数，数字越小排在越前</td>
	</tr>		
	{/if}	

	<tr>
	<td class="label" valign="top">模版:</td>
	<td>
	<select name="template_{$list.language_id}" class="select_input">
	<option value="">默认</option>
	{foreach from=$template item=t}
	<option value="{$t}" {if $list.template == $t}selected{/if}>{$t}</option>
	{/foreach}
	</select>
	</td>
	</tr>
	
	<tr>
	<td style="border:none;"></td>
	<td style="border:none;">
		<input type="hidden" name="id" value="{$category.category_id}" />
		<input type="hidden" name="act" value="{$form_act}" />
		<input type="submit" value="提交" class="bginput" />
		<input type="reset" value="重置" class="bginput" />
	</td>
	</tr> 	
	</table>
{/foreach}
</form>

{literal}
<script language="JavaScript">
function validate(){
    validator = new Validator("theForm");
	validator.required("name_{/literal}{$language[0].language_id}{literal}",'分类名称不能为空!');
    return validator.passed();
}

$(document).ready(function(){
	$('.category_select').change(function(){
		var sel_id = $(this).val();
		$('.category_select').val(sel_id);
	})
}) 

$('.upload_image_btn').uploadify({
	'formData'     : {
		'rand_str' 	: '{/literal}{$rand_str}{literal}',
		'hash'     	: '{/literal}{$hash}{literal}',
		'session_id' : '{/literal}{$session_id}{literal}',
		'thumb_width'  : '150',
		'thumb_height' : '150',
		'img_type'  : 'image'
	},	
	'multi':false,
	'width':'94',
	'height':'25',
	'buttonText':'',
	'buttonImage':'images/add_image_1.png',
	'swf':'images/uploadify.swf',
	'uploader' : 'uploadify.php',
	'fileTypeDesc' : 'Image Files',
	'fileSizeLimit' : '2048KB',
	'fileTypeExts' : '*.gif; *.jpg; *.png',
	'itemTemplate' : '',
	'onUploadStart' : function(file) {
		//$("#loading").fadeIn("fast");
	},
	'onUploadSuccess' : function(file, data, response) {
		result = $.parseJSON(data);
		if(result.error == 1){
			alert(result.message);
		}else{
			$('#image_box').html("<a href=\"../"+result.image+"\" target=\"_blank\"><img src=\"../"+result.image_thumb+"\" border=\"0\"  /></a><div style=\"margin-top:5px;width:150px;text-align:center;margin-bottom:10px;\"><a href=\"javascript:;\" onclick=\"if(confirm('您确实要删除该图片吗?')){drop_image();}\">删除</a></div>");
			$('#image').val(result.image);
		}
	 }
});

function drop_image(){
	$('#image_box').html('');
	$('#image').val('');
}
</script>
{/literal}
{insert_scripts files="tab.js,validator.js"}
{include file="page_footer.htm"}