<table width="100%" class="topmenu">
	<tr><td>
		<a href="index.php?catid={?$catid?}"><em>栏目内容</em></a><span>|</span>
		<a href="post.php?catid={?$catid?}" class="on"><em>添加产品</em></a><span>|</span>
		<a href="expand.php"><em>产品扩展属性设置</em></a><span>|</span>
		<a href="{?$saxue_admin_url?}/move.php?catid={?$catid?}"><em>批量移动</em></a>
	</td></tr>
</table>
<form id="formAdd" method="post" onsubmit="return checkform()">
<input type="hidden" name="dosubmit" value="1">
<input type="hidden" name="catid" value="{?$catid?}">
{?if $row.id>0?}<input type="hidden" name="id" value="{?$row.id?}">{?/if?}
<table width="100%" class="grid">
	<tr>
		<td class="tdleft" width="80">语言：</td>
		<td>
			<select name="lang" id="lang" onchange="change_expand(this.value)">
				<option value="">选择语言</option>{?section name=i loop=$lang?}<option value="{?$i['key']?}"{?if $i['key']==$row.lang?} selected{?/if?}>{?$lang[i].name?}</option>{?/section?}
			</select>
		</td>
	</tr>
	<tr>
		<td class="tdleft">产品标题：</td>
		<td>
			<input name="title" id="title" type="text" value="{?$row.title?}" size="80" class="text" />&nbsp;
			<label><input type="checkbox" name="islink" id="islink" value="1" onclick="setlinkurl();"{?if 1==$row.islink?} checked{?/if?} /><span class="red">转向链接</span><label>
		</td>
	</tr>
	<tr id="linkshow"{?if 0==$row.islink?} style="display:none"{?/if?}>
		<td class="tdleft">转向链接：</td>
		<td><input name="linkurl" id="linkurl" type="text" value="{?if 1==$row.islink?}{?$row.url?}{?/if?}" size="80" class="text" /></td>
	</tr>
	<tr>
		<td class="tdleft">详细说明：</td>
		<td>{?function saxue_geteditor:'content':680:320:'':1:array('Flash','Media')?}<textarea name="content" id="content">{?$row.content?}</textarea></td>
	</tr>
	<tr>
		<td class="tdleft">内容选项：</td>
		<td>
			<label><input name="auto_remote" type="checkbox" value="1" checked />下载非本站图片到本地</label>&nbsp;
			<label><input name="auto_intro" type="checkbox" value="1" checked />截取内容 </label><input name="intro_length" type="text" size="2" value="240" class="text"/> 字符至简介&nbsp;
			<label><input name="auto_link" type="checkbox" value="1" checked />清除非本站链接</label>&nbsp;
		</td>
	</tr>
	<tr>
		<td class="tdleft">摘要：</td>
		<td><textarea name="intro" id="intro" rows="2" style="width:670px;" class="textarea">{?$row.intro?}</textarea></td>
	</tr>
	<tr>
		<td class="tdleft">产品组图：</td>
		<td>
			<div id="uploadImgcontainer" class="clearfix pre-z"></div>
			<div class="clearfix mb30">
				<a class="fl mr10 w_local" href="javascript:void(0)" >
                    <span style="z-index:10" id="upload_Tip" onclick="$('#upload_Tip').hide();"><em></em>按住"Ctrl"可多选</span>
                    <span id="flashContent"></span>
				</a>
				<a class="fl mr10 w_album" href="javascript:void(0)" id="albumDialog">已上传选取</a>
				<span class="fl f12 c_ccc"><span id="hazupinfo">已上传图片<b class="green upnum">0</b>/<b class="maxnum red">{?$configs.maxitem?}</b>，</span>每张最大<span id="size_limit">{?$configs.maxfilesize?}</span>KB，支持<span id="photo_type">jpg/gif/png</span>格式</span>
			</div>
		</td>
	</tr>
	<tr>
		<td class="tdleft">扩展属性：</td>
		<td>
			<table width="200" class="grid" id="expandTab">
				<tr><td>属性名称</td><td>属性值</td><td><input type="button" class="button" id="addRow" value="增加一行" /></td></tr>
				{?if $row.hasexpand==1?}
				{?section name=i loop=$row['expand']?}
				<tr>
					<td><select name="expands[name][]" class="expands">{?section name=j loop=$expands?}<option value="{?$j['value']?}" {?if $j['value']==$row['expand'][i].name?} selected{?/if?}>{?$j['value']?}</option>{?/section?}</select></td>
					<td><input name="expands[value][]" type="text" size="30" class="text" value="{?$row['expand'][i].value?}" /></td>
					<td><input type="button" class="button delRow" value="删除" /></td>
				</tr>
				{?/section?}
				{?elseif $row.id>0?}
				<tr>
					<td><select name="expands[name][]" class="expands">{?section name=j loop=$expands?}<option value="{?$j['value']?}">{?$j['value']?}</option>{?/section?}</select></td>
					<td><input name="expands[value][]" type="text" size="30" class="text" /></td>
					<td><input type="button" class="button delRow" value="删除" /></td>
				</tr>
				{?else?}
				<tr>
					<td><select name="expands[name][]" class="expands"><option value="">属性名称</option></select></td>
					<td><input name="expands[value][]" type="text" size="30" class="text" /></td>
					<td><input type="button" class="button delRow" value="删除" /></td>
				</tr>
				{?/if?}
			</table>
		</td>
	</tr>
	<tr>
		<td class="tdleft">购买链接：</td>
		<td><input name="buylink" id="buylink" type="text" value="{?$row.buylink?}" size="80" class="text" /></td>
	</tr>
	<tr>
		<td class="tdleft">状态：</td>
		<td>
			<label><input name="display" type="checkbox" value="1"{?if '1'==$row.display || ''==$row.display?} checked{?/if?} />发布<label>&nbsp;
			<label><input name="istop" type="checkbox" value="1"{?if '1'==$row.istop?} checked{?/if?} />置顶<label>
		</td>
	</tr>
	<tr>
		<td class="tdleft"></td>
		<td><input type="submit" name="submit" id="submit" class="button" value="提 交"/></td>
	</tr>
</table>
</form>
<br><br>
<link type="text/css" rel="stylesheet" href="{?$saxue_skin_server?}/flashupload/upload.css">
<script type="text/javascript">
try { 
	var ____jsoncfg = { 
		maxsize:'{?$configs.maxfilesize?}', 
		attachsurl:'{?$configs.attachsurl?}', 
		flashurl:'{?$saxue_skin_server?}/flashupload', 
		posturl:'{?$saxue_url?}/api/swf_upload.php'
	} 
} catch (e) { }; 
</script>
<script type="text/javascript" src="{?$saxue_skin_server?}/flashupload/upload.js"></script>
<script type="text/javascript">
// 异步加载扩展属性
function change_expand(lang) {
	if(lang) {
		$.getJSON('get_expand.php?catid={?$catid?}&lang='+lang, function(data){
			$('.expands').html(data.expands);
		});
	}
}
// 转向链接
function setlinkurl() {
	if($('#islink').attr('checked')) {
		$('#linkshow').show(); 
	} else {
		$('#linkshow').hide(); 
	}
}
// 接收图片控件的值
function getPicValueForPost() {
    var pic = [];
    var tag = [];
    var desc = [];
    var data = UpImageShowBar.getImgs();
    if(data != null && data.length > 0) {
        $(data).each(function(i, n){
            // 图片路径
            pic.push(n.url);

            // 标签
            var _tag = n.label;
            if(_tag == null) _tag = '';
            tag.push(_tag);

            // 描述
            var _detail = n.detail;
			if(_detail=='图片简介...') _detail = '';
            desc.push(_detail);
        });
    }
    return { "pic" : pic, "tag" : tag, "desc" : desc };
}
// 图片元素赋值
function setPicValueForPost() {
    var data = getPicValueForPost();
    createinput('pic', data.pic.join('|'));
    createinput('pictag', data.tag.join('|'));
    $(data.desc).each(function(i,n){
        var id = 'picdesc' + (i++);
        createinput(id, n);
    });
}
// 创建input
function createinput(name,val,text){
	try{
		if($("#"+name).length==0){
			var str='<input type="hidden" name="'+name+'" id="'+name+'" value="" />';
			$("#formAdd").append(str)
		}
		$("#"+name).val(val);
		return true
	}catch(e){
		alert("err: createinput");
		return false
	}
}
// 表单提交图片处理
function checkform(){
	return setPicValueForPost();
}
// 重载alert函数
window.alert = function(msg) {
	msg = msg.replace( "\n", '<br>' ).replace( "10M", '{?$configs.maxfilesize?}K' );
	doTip(msg);
}
// 多图选择窗口
KindEditor.ready(function(K) {
	var editor = K.editor({
		langType : 'zh_CN',
		urlType  : 'domain',
		fileManagerJson : '{?$saxue_url?}/api/file_manager_json.php'
	});
	K('#albumDialog').click(function() {
		if (K('#albumDialog').hasClass('w_albumn')) {
			return false;
		}
		editor.loadPlugin('filemanagers', function() {
			editor.plugin.filemanagerDialog({
				viewType : 'VIEW',
				dirName : 'image',
				clickFn : function(pics) {
					editor.hideDialog();
					if (pics.length>1) {
						pics = pics.substr(1);
						var picarr = pics.split('|');
						for (var i = 0; i < picarr.length; i++) {
							if (picarr[i].indexOf('{?$saxue_url?}')==-1) {
								picarr[i] = '{?$saxue_url?}' + picarr[i];
							}
							picarr[i] = picarr[i].replace('{?$configs.attachsurl?}', '');
							UpImageShowBar.addImg({ url : picarr[i] }, true);
						}
					}
				}
			});
		});
	});
});
$(function(){
	// 初始化上传控件
	var upimgs = [];
	{?section name=i loop=$row['pics']?}
	upimgs.push({'url' : "{?$row['pics'][i].url?}", 'label' : "{?$row['pics'][i].tag?}", 'detail' : "{?$row['pics'][i].desc?}"});
	{?/section?}
	UpImageShowBar.initBar({
		container:'uploadImgcontainer',
		flashName:'PictureUpload',
		images:upimgs,
		hazDetail:true,
		maxFilsSize:1024*{?$configs.maxfilesize?},
		imgMax:{?$configs.maxitem?}
	});

	// 添加行
	$("#addRow").click(function() {
		var tempTr = $("#expandTab tr:last").clone(true);
		$("#expandTab tr:last").after(tempTr);
		$("#expandTab tr:last > td > select").val('');
		$("#expandTab tr:last > td > input:eq(0)").val('');
	});

	// 删除行
	$(".delRow").click(function() {
		if ($(".delRow").length < 2) {
			alert("至少保留一行!");
		} else if (confirm("确认删除?")) {
			$(this).parent().parent().remove();
		}
	});

	// 表单提交
	$("#formAdd").ajaxForm({
		beforeSubmit : function(){
			if ($("#lang").val()=='') {
				doTip('请选择语言');
				$("#lang").focus();
				return false;
			} 
			if ($("#title").val()=='') {
				doTip('请输入标题');
				$("#title").focus();
				return false;
			} 
			if($('#islink').attr('checked')) {
				if ($("#linkurl").val()=='') {
					doTip('请输入转向链接');
					$("#linkurl").focus();
					return false;
				} 
			} else if(e_content.isEmpty()) {
				doTip('内容不能为空');
				return false;
			}
		},
        dataType: "json",
        success : function(data){
			if(data.flag == 0){
				doTip(data.msg);
			}else{
				window.top.mainframe.location.href='index.php?catid={?$catid?}';
				doDialogClose();
				doTip('内容保存成功');
			}
        }
    });
})
</script>