<script src="<{$config.weburl}>/script/jquery.niceforms.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
	$(".checkbox").dgStyle();
});
</script>
<style>
.mod-more-product{width:600px;overflow:hidden; }
.mod-more-product .product-list {
	overflow: hidden;
	zoom: 1;
}
.mod-more-product .product-list-title {
	overflow: hidden;
	zoom: 1;
}
.mod-more-product .product-list-on .fd-hide {
	display: block;
}
.mod-more-product .sub-name {
	width: 280px;
	margin: 5px 5px 5px 0;
}
.mod-more-product .sub-count {
	width: 100px;
	margin: 5px 5px 5px 0;
}
.mod-more-product .sub-unit {
	width: 76px;
	margin: 5px 5px 5px 0;
}
.mod-more-product .sub-price {
	width: 86px;
	margin: 5px 0px 5px 0;
}
.mod-more-product .sub-delete {
	width: 30px;
	margin: 5px 5px; 5px 0;
}
.mod-add-product {
	margin: 10px 0 10px 0;
	_display: inline;
}
.fd-left {
	float: left;
}
.fd-hide {
	display:none;
}
.fd-clear{ clear:both;}

.red{ color:#FF0000;}
em{ margin-right:5px;}
.msg-wrap .msg{display:block; color:#FF0000; height:30px; line-height:30px; width:100%;}
</style>
<form method="post" action=""  onsubmit="return check_value();" enctype="multipart/form-data">
<div class="admin_right_top"><{$lang.post_quotation}></div>
<table class="admin_table">
    <tr>
    	<td colspan="2" class="sheader"><{$lang.basic_inf}></td>
    </tr>
	<tr>
        <td width="16%" class="td"> <{$lang.type}></td>
        <td width="84%">
        <{foreach item=list key=num from=$buyType}>
        <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.title}><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}></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"><{$lang.summary}><font color="red"> *</font></td>
        <td><textarea maxlength="100" 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>&nbsp;
        <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">
		<ul id="list1">
        <{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="删除" nctype="delete_image">删除</span>
                    </div>
                </div>
                <div class="upload-btn"><a class="upload-button" href="javascript:uploadfile('Style images','img<{$key}>',300,300,'buy')"><{$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="删除" nctype="delete_image" class="delete">删除</span>
                </div>
            </div>
            <div class="upload-btn"><a class="upload-button" href="javascript:uploadfile('Style images','pic<{$smarty.section.name.index}>',300,300,'product')"><{$lang.upload}></a></div>
        </li>
        <{/section}>
		</ul>
        </div>
        </td>
    </tr>
	<tr>
    	<td class="sheader" colspan="2"><{$lang.demand_details}></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="desc"]', {
					langType : 'en'
				});
            });
            </script>
            <textarea name="desc" style="width:99%; height:400px;"><{$de.desc}></textarea>
        </td>
    </tr>
    <tr>
    	<td colspan="2" class="sheader"><{$lang.buy_product_list}></td>
    </tr>
    <tr>
		<td colspan="2"><div class="mod-more-product" id="mod-more-product">
          <div class="product-list-title">
            <div class="fd-left sub-name"><em class="red">*</em><{$lang.info_title}></div>
            <div class="fd-left sub-count"><em class="red">*</em><{$lang.num}></div>
            <div class="fd-left sub-unit"><em class="red">*</em><{$lang.unit}></div>
            <div class="fd-left sub-price"><{$lang.target_price}></div>
            <div class="fd-clear"></div>
          </div>
          <p>
          	 <input type="hidden" id="mod-more-product-input"  name="buyid" value="<{$de.id}>" >
          </p>
          <{if !is_array($de.prolist)||empty($de.prolist)}>
          	 <div class="product-list">
            <div class="fd-left check_null sub-name">
              <input type="hidden"  name="id[]"  class="prolist_id" value="0" >
              <input name="pname[]" type="text"  value="" style="width: 270px;" class="content-name" maxlength="80">
            </div>
            <div class="fd-left check_null sub-count">
              <input name="number[]" type="text" value="" style="width:86px;" maxlength="5" class="content-count"> 
            </div>
            <div class="fd-left check_null sub-unit">
            <input name="unit[]" type="text"  value="" style="width: 65px;" class="content-unit" maxlength="10"> 
            </div>
            <div class="fd-left sub-price">
              <input name="price[]" type="text"  value="" style="width: 74px;" class="content-price" maxlength="6">
            </div>
            <div class="fd-left sub-delete fd-hide"><a href="#nogo"><{$lang.del}></a></div>
            <div class="fd-clear"></div>
          </div>
          <{else}>
              <{foreach item=list from=$de.prolist}>
                 <div class="product-list">
                <div class="fd-left check_null sub-name">
                  <input type="hidden"  name="buyproid[]" class="prolist_id" value="<{$list.id}>" >
                  <input name="pname[]" type="text"  value="<{$list.pname}>" style="width: 270px;" class="content-name" maxlength="80">
                </div>
                <div class="fd-left check_null sub-count">
                  <input name="number[]" type="text" value="<{$list.number}>"  maxlength="5" style="width: 86px;" class="content-count"> 
                </div>
                <div class="fd-left check_null sub-unit">
                  <input name="unit[]" type="text"  value="<{$list.unit}>" style="width: 65px;" class="content-unit" maxlength="10" > 
                </div>
                <div class="fd-left sub-price">
                  <input name="price[]" type="text"  value="<{$list.price}>" style="width: 74px;" class="content-price" maxlength="6">
                </div>
                <div class="fd-left sub-delete fd-hide"><a href="#nogo"><{$lang.del}></a></div>
                <div class="fd-clear"></div>
              </div>
              <{/foreach}>
          <{/if}>
        </div>
        <div class="value mod-add-product"> <a class="add_item_note" id="fun-add-product" href="#nogo"><{$lang.type}>Add product</a></div>  <script>
		
	    $(function(){
		function bind_del()
		{  
			var all_list_con=$("#mod-more-product .product-list");
			var	numi=$("#mod-more-product .product-list").size();
			if(numi>1){
				all_list_con.each(function(index,element) {
					all_list_con.eq(index).find('a').bind('click',function(){				
						//----如果是已经加入数据库的后台删除--
						var prid=all_list_con.eq(index).find('.prolist_id').val();
						if(prid>0)
						{
							if(!confirm("Confirm that you want to delete this data has been stored"))
								return false;
							var url = '<{$config.weburl}>/main.php?m=buy&s=admin_buy&ajax=1';
							var sj = Math.random();
							var pars = 'shuiji=' + sj+'&id='+prid;
							$.post(url, pars,function (originalRequest)
											{
												if(originalRequest!=1)
												{
													alert("Delete failed..");
													return;
												}
											}
							);
						}
						all_list_con.eq(index).remove();
					    numi=numi-1;
						if(numi==1)
						{
							$("#mod-more-product .product-list").eq(0).unbind('mouseover');
							$("#mod-more-product .product-list").eq(0).unbind('mouseout');
							$("#mod-more-product .product-list").eq(0).find('.sub-delete').hide();
						}
					});
					all_list_con.eq(index).bind('mouseover',function(){
						all_list_con.find('.sub-delete').hide();
						$(this).find('.sub-delete').show();
					});
				    all_list_con.eq(index).bind('mouseout',function(){
						all_list_con.find('.sub-delete').hide();
					});
				});
			}
			else
			{
				all_list_con.eq(0).unbind('mouseover');
				all_list_con.eq(0).unbind('mouseout');
				all_list_con.eq(0).find('.sub-delete').hide();
			}
		}
		 bind_del();
		 //添加绑定
		  $("#fun-add-product").bind('click',function(){
			  var obj=$("#mod-more-product>.product-list").last();
			  $("#mod-more-product").append(" <div class='product-list' data-purchasenoteitemid=''>"+obj.html()+"</div>");
			  obj=$("#mod-more-product>.product-list").last();
			  obj.find('.prolist_id').val('');
			  obj.find('.content-name').val('');
			  obj.find('.content-count').val('');
			  obj.find('.content-unit').val('');
			  obj.find('.content-price').val('');
			
			  bind_del();
		  });
		});
        </script>
		</td>
    </tr>
    <tr>
    	<td colspan="2" class="sheader"><{$lang.req_seller}></td>
    </tr>
    <tr>
        <td class="td"><{$lang.deadline_quote}><font color="red"> *</font></td>
        <td><input readonly="readonly" type="text" class="w150 time" id="valid_time" name="valid_time" onfocus="cdr.show(this);" value="<{$de.valid_time|date_format}>"/></td>
    </tr>
    <tr>
        <td class="td"><{$lang.expected_date}><font color="red"> *</font></td>
        <td><input readonly="readonly" type="text" class="w150 time" id="buy_time"  name="buy_time" onfocus="cdr.show(this);" value="<{$de.buy_time|date_format}>"/></td>
    </tr>
    <tr>
        <td class="td"><{$lang.delivery_date}><font color="red"> *</font></td>
        <td><input readonly="readonly" type="text" class="w150 time" id="delivery_time" name="delivery_time" value="<{$de.delivery_time|date_format}>" onfocus="cdr.show(this);"/></td>
    </tr>
    <tr>
        <td class="td"><{$lang.area}></td>
        <td>
        <select class="select" name="country" id="country">
        <option value="" selected><{$lang_show.allcountry}></option>
        <{foreach item=list from=$country}>
        <option value="<{$list.coname}>" <{if $de.seller_country==$list.coname}> selected <{/if}> ><{$list.coname}></option>
        <{/foreach}>
        </select>
        </td>
    </tr>
    <tr>
        <td class="td"><{$lang.province_city}></td>
        <td>
        <input class="w150" id="province" name="province" type="text" value="<{$de.seller_province}>"/>  
        <input class="w150" id="city" name="city" type="text" value="<{$de.seller_city}>"/>
        </td>
    </tr>
    <tr>
        <td class="td"><{$lang.suppliers_con}></td>
        <td>
        <{foreach item=list from=$seller_need}>
        <label class="checkbox">
        <input <{if  is_array($de.seller_need)&&in_array($list,$de.seller_need)}>checked="checked"<{/if}>  name="seller_need[]" type="checkbox" value="<{$list}>" /><{$list}> 
        </label><br/><br/>
        <{/foreach}>
        </td>
    </tr>
    <tr>
        <td colspan="2">
        <input class="btn" type="submit" value="<{$lang.submit}>" />
        <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" src="<{$config.weburl}>/script/Calendar.js"></script>
<script language="javascript">
	var cdr = new Calendar("cdr");
	document.write(cdr);
	cdr.showMoreDay = true;
</script>
<{if !$de}>
<script language="javascript">
	document.getElementById('sscatid').value = '';
	document.getElementById('scatid').value = '';	
	document.getElementById('tcatid').value = '';
	document.getElementById('catid').value = '';
</script>
<{/if}>
<script>
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('brand').innerHTML= MyMe.brand;
			document.getElementById('fv_box').innerHTML = '<table width="100%">'+MyMe.firstvalue+'</table>';
			if(document.getElementById('fv_list'))
				document.getElementById('fv_list').style.display=MyMe.firstvalue!=''?'':'none';
		}			

	 }
	close_win();
}
//--------------------------
var city='<{$de.seller_city}>';
var province='<{$de.seller_province}>';
function getHTML(v)
{	
	var ob="city";
	var url = '<{$config.weburl}>/ajax_back_end.php';
	var sj = Math.random();
	var pars = 'shuiji=' + sj+'&prov_id='+v;
	$.post(url, pars,showResponse);
	function showResponse(originalRequest)
	{
		var tempStr = 'var MyMe = ' + originalRequest; 
		var i=0;var j=0;
		eval(tempStr);
		for(var s in MyMe)
		{
			++j;
		}
		document.getElementById(ob).options.length =j+1;
		for(var k in MyMe)
		{
			var cityId=MyMe[k][0];
			var ciytName=MyMe[k][1];
			document.getElementById(ob).options[k].value = cityId;
			document.getElementById(ob).options[k].text = ciytName;
			if(city!=''&&city==ciytName)
				document.getElementById(ob).options[k].selected = true;
	　	}
	 }
　}
<{if $de.seller_city}>
getHTML('<{$de.seller_province}>');
<{/if}>
//==========================================
function check_pro_null()
{
	var obj=$("#mod-more-product .product-list .check_null");
	var flag=false;
	obj.each(function(index,element) {
		  if($(this).find('.content-name').val()=='')
		  { 
		  		alert('Product name cannot be empty');
				$(this).find('.content-name').focus();
				 flag=true;
				 return;
		  }
		   if($(this).find('.content-count').val()=='')
		  { 
		  		alert('The number of products can not be empty');
				$(this).find('.content-name').focus();
				 flag=true;
				 return;
		  }
		  if($(this).find('.content-unit').val()=='')
		  { 
		  		alert('Unit product cannot be empty');
				$(this).find('.content-name').focus();
				 flag=true;
				 return;
		  }
	
	});
	return flag;
}
function check_value()
{
	if(check_pro_null())
		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_business_category}>');
		return false;
	}
	if(document.getElementById('con').value.length>199) 
	{
		alert("<{$lang.sumisbig}>");
		return false;
	}
	if(!document.getElementById('con').value) 
	{
		alert("<{$lang.notice_con}>");
		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;
    }
	
	if(document.getElementById('valid_time').value=='')
	{
		alert('The deadline for quotation is not emp');
		return false;
	}
	
	if(document.getElementById('buy_time').value=='')
	{
		alert('Is expected to place an order of time cannot be empty');
		return false;
	}
	
	if(document.getElementById('delivery_time').value=='')
	{
		alert('Expected delivery date cannot be empty');
		return false;
	}
	
}
//=========================================
</script>