<script src="<{$config.weburl}>/script/jquery.niceforms.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
	$(".radio").dgStyle();
});
</script>
<form method="post" action="" enctype="multipart/form-data">
<div class="admin_right_top"><{$lang.trade_post}></div>
<table border="0" align="center" cellpadding="6" cellspacing="1" class="admin_table">
    <tr>
    	<td colspan="2" class="sheader"><strong><{$lang.basic_inf}></strong></td>
    </tr>
    <tr>
        <td width="16%" class="td">Type<font color="red"> *</font></td>
        <td width="84%">
            <{foreach item=list key=num from=$infoType}>
                <label class="radio">
                <input type="radio" name="type" value="<{$num}>" <{if $de.type==$num||$num==0}>checked="checked"<{/if}> /><{$list}>
                </label>
            <{/foreach}>
        </td>
    </tr>
    <tr>
        <td class="td"><{$lang.titles}><font color="red"> *</font></td>
        <td><input maxlength="100" name="title" type="text" id="title" value="<{$de.title}>" /></td>
    </tr>
    <tr>
        <td class="td"><{$lang.key_words}><font color="red"> *</font></td>
        <td><input name="keywords" id="key_word" type="text" maxlength="50" value="<{$de.keywords|escape:html}>" /><p><{$lang.key_des}></p></td>
    </tr>
    <tr>
        <td class="td">Introduction</td>
        <td><textarea maxlength="100" style="height:45px;" name="con" id="con"><{$de.con}></textarea></td>
    </tr>
    <tr>
        <td class="td"><{$lang.category}><font color="red"> *</font></td>
        <td>
        <span id="cate_show"><{$typenames}></span>
        <input class="btn" type="button" onclick="showCategory();" value="<{$lang.select_business_category}>">
        <input name="catid" id="catid" type="hidden" value="<{$de.catid}>" />
        <input name="tcatid" id="tcatid" type="hidden" value="<{$de.tcatid}>" />
        <input name="scatid" id="scatid" type="hidden" value="<{$de.scatid}>" />
        <input name="sscatid" id="sscatid" type="hidden" value="<{$de.sscatid}>" />
        </td>
    </tr>
    <tr>
        <td class="td"><{$lang.picture}><font color="red"> *</font></td>
        <td>          
            <div class="product_image clearfix">
                <ul id="list1" class="clearfix">
                <{foreach item=list key=key from=$de.pic}>
                    <li  id="p<{$key+1}>" data-itemid='<{$key+1}>'>
                        <div class="product_image_list"> 
                            <div nc_type="handle_image">
                                <div class="image">
                                <input name="pic[]" type="hidden" id="img<{$key}>" value="<{$list}>" />
                                <img id="img<{$key}>_img" src="<{$list}>" width="60">
                                </div>
                                <div nc_type="handle" class="bg">
                                    <span title="Delete" nctype="delete_image">Delete</span>
                                </div>
                            </div>
                            <div class="upload-btn"><a class="upload-button" href="javascript:uploadfile('Style images','img<{$key}>',300,300,'offer')"><{$lang.upload}></a></div>
                        <div>
                    </li>
                <{/foreach}>
                <{assign var=count value=$de.pic|@count}>
                <{section name=name loop=$count*-1+5}>
                    <li id="p<{$key+$smarty.section.name.index+1}>" data-itemid='<{$key+$smarty.section.name.index+1}>'>
                        <div nc_type="handle_image">
                            <div class="image">
                            <input name="pic[]" type="hidden" id="pic<{$smarty.section.name.index}>" value="" />
                            <img width="60" id="pic<{$smarty.section.name.index}>_img" src="<{$config.weburl}>/image/default/nopicsmall.gif"  />
                            </div>
                            <div nc_type="handle" class="bg">
                                <span title="Delete" nctype="delete_image" class="delete">Delete</span>
                            </div>
                        </div>
                        <div class="upload-btn"><a class="upload-button" href="javascript:uploadfile('Style images','pic<{$smarty.section.name.index}>',300,300,'offer')"><{$lang.upload}></a></div>
                    </li>
                <{/section}>
                </ul>
            </div>
        </td>
    </tr>
    <tr>
		<td colspan="2" class="sheader"><strong><{$lang.fieldadd}></strong></td>
    </tr>
    <tr>
        <td class="td"><{$lang.valid_time}></td>
        <td>
        <{foreach item=list key=num from=$valid_time}>
        <label class="radio"><input name="valid_time" type="radio" value="<{$num}>" <{if $num==$de.valid_time}>checked="checked"<{/if}> /><{$list}></label>
        <{/foreach}>
        </td>
    </tr>
    <tr>
        <td class="td"><{$lang.price}>(<{$config.money}>)</td>
        <td>
        <input type="text" name="price" id="price" class="w100" maxlength="10" value="<{$de.price}>" />
        / 
        <select name="unit" <{if !$de}>onchange="document.getElementById('pro_unit_des').innerHTML='('+this.value+')'"<{/if}>>
        <{foreach item=list from=$unit}>
         <option <{if $list==$de.priceDes}>selected="selected"<{/if}> ><{$list}></option>
        <{/foreach}>
        </select>
        </td>
    </tr>
    <tr>
        <td class="td"><{$lang.brand}></td>
        <td>
        <input type="text" value="<{$de.brand}>" class="text" name="pinpai" maxlength="30">
        </td>
    </tr>
    <{if $firstvalue}>
    <tr>
        <td class="ext_table" id="fv_box" colspan="2" style="padding:0">
            <table width="100%" cellspacing="0" cellpadding="1" >
                <{foreach item=list key=num from=$firstvalue}>
                	<{$list}>
                <{/foreach}>
            </table>
        </td>
    </tr>
    <{/if}>
    <tr>
		<td colspan="2" class="sheader"><strong><{$lang.detail}></strong></td>
    </tr>
    <tr>
      <td colspan="2">
		<script charset="utf-8" src="lib/kindeditor/kindeditor-min.js"></script>             
        <script>
		var editor;
		KindEditor.ready(function(K) {
			editor = K.create('textarea[name="detail"]', {
				langType : 'en'
			});
		});
        </script>
        <textarea name="detail" style="width:99%; height:400px;"><{$de.detail}></textarea>
    </td>
    </tr>
    <tr>
        <td class="td"><{$lang.cus_cat}></td>
        <td>
        <select name="custom_cat">
        <option value="0"><{$lang.no_cat}></option>
        <{foreach item=list from=$custom_cat}> <{if $de.custom_cat_id==$list.id}>selected="selected"<{/if}> value="<{$list.id}>"><{$list.name}><option <{if $de.custom_cat_id==$list.id}>selected="selected"<{/if}> value="<{$list.id}>"><{$list.name}>
        </option>
        <{/foreach}>
        </select>
        [<a target="_blank" href="main.php?m=offer&s=admin_product_cat"><{$lang.mag_cat}></a>] </td>
    </tr>
    <tr>
        <td colspan="2">
        <input type="submit" value="<{$lang.submit}>" class="btn" onClick="return check_value();"/>
        <input name="submit" type="hidden" id="submit" value="<{if $de.id}>edit<{else}>submit<{/if}>" />
        <input name="editID" type="hidden" id="editID" value="<{$de.id}>" />
        </td>
    </tr>
  </table>
</form>
<script src="script/my_lightbox.js" language="javascript"></script> 
<script language="javascript">
	<{if !$de}>
	document.getElementById('sscatid').value = '';
	document.getElementById('scatid').value = '';	
	document.getElementById('tcatid').value = '';
	document.getElementById('catid').value = '';
<{/if}>
function showCategory()
{
	var key= document.getElementById('key_word').value;
	alertWin('<{$lang.select_category}>','',580,480,'<{$config.weburl}>/cate_show_ajax.php?type=OCAT&key_word='+key);
}
function setCategory(catid)
{
	var url = '<{$config.weburl}>/cate_show_ajax.php?oper=ajax&call=get_cate';
	var sj = Math.random();
	var pars = 'shuiji=' + sj+'&type=OCAT&catid='+catid;
	$.post(url, pars,showResponse);
	function showResponse(originalRequest)
	{
		var tempStr = 'var MyMe = ' + originalRequest; 
		var i=0;var j=0;
		eval(tempStr);
		if(MyMe)
		{
			document.getElementById('sscatid').value = '';
			document.getElementById('scatid').value = '';	
			document.getElementById('tcatid').value = '';
			document.getElementById('catid').value = '';
			if(catid.length>8)
				document.getElementById('sscatid').value = catid;
			if(catid.length>6)
				document.getElementById('scatid').value = catid.substr(0,8);	
			if(catid.length>4)
				document.getElementById('tcatid').value = catid.substr(0,6);
			document.getElementById('catid').value = catid.substr(0,4);
		
			document.getElementById('cate_show').innerHTML= MyMe.cat;
			document.getElementById('fv_box').innerHTML = '<table cellspacing="0" cellpadding="0" width="100%">'+MyMe.firstvalue+'</table>';
			if(MyMe.firstvalue)
				document.getElementById('fv_list').style.display=MyMe.firstvalue;
		}			

	 }
	close_win();
}
//==========================================
function check_value()
{
	if(!$('#img0').val())
	{
		if($('#pic0').val()=='')
		{
			alert('Please upload pictures');
			document.getElementById('pic0').focus();
			return false;
		}
	}
	if(!document.getElementById('title').value)
	{
		alert('<{$lang.notice_title}>');
		document.getElementById('title').focus();
		return false;
	}
	if(document.getElementById('catid').value=='')
	{
		alert('<{$lang.select_category}>');
		return false;
	}
	if(document.getElementById('con').value.length>199) 
	{
		alert("<{$lang.sumisbig}>");
		return false;
	}
    var fck = FCKeditorAPI.GetInstance("detail");
    var content = fck.GetXHTML(true);
    if (content.replace(/<(?!img|input|object)[^>]*>|\s+/ig, "") == "")
	{
	   alert("<{$lang.notice_detail}>");
	   fck.Focus();
	   return false;
    }
}
</script> 
<script language="javascript" src="<{$config.weburl}>/script/product.js"></script>
<script language="javascript" src="<{$config.weburl}>/script/jquery.dragsort-0.5.1.min.js"></script>
<script type="text/javascript">
$("#list1").dragsort({ dragSelector: "div", dragSelectorExclude:"span",dragBetween: true, dragEnd: saveOrder, placeHolderTemplate: "<li class='placeHolder'><div></div></li>" });
function saveOrder()
{
	var data = $("#list1 li").map(function() { return $(this).data("itemid"); }).get();
}
function load_pic()
{
	$.getScript("<{$config.weburl}>/script/product.js");	
}
</script>