$(function(){
  $("#makeHtmlTab li").click(function(){
	$("#makeHtmlTab li").attr("class","")
	$(this).attr("class","hover")
	var id=$(this).attr("id")
	for(var i=1;i<5;i++)
	{
	  if(id+"tbody"=="li_"+i+"tbody")
	  {$("#li_"+i+"tbody").show()}
	  else
	  {$("#li_"+i+"tbody").hide()}
	}
  })
})
  function GetFromDate()
  {
	var Property,IsLimitbuy,str,val
	str="{"
	var arr1 = ["pre_commend","LimitBuyPrice", "LimitBuyAmount", "pre_name","pre_type", "pre_downdata","pre_fromUrl", "Price_Market","pre_price", "Unit","Discount","pre_hit","Weight","pre_amount","AlarmNum","pre_SaleNum","pre_score_send","pre_score","keyword","brand","pre_note","pre_attribute","AttributeCart","pre_content","pre_id"]; 
	for(var i=0;i<arr1.length;i++)
	{ 
	  val=arr1[i]
	  str=str + "\""+val+"\":\"" + $("#"+val).val() +"\","
	} 
	Property=$("[name=\"Property\"]:checked").val()
	IsLimitbuy=$("[name=\"IsLimitbuy\"]:checked").val()
	var picstr,smallpicArr,pic;
	var test = $("input[name^='picid']");
	var bgcolor = $("input[name^='bgcolor']");
    var arr = new Array();pic=""
    for(var i=0;i<test.length;i++){
		smallpicArr = $("input[name^='pic"+test[i].value+"']");
		WArr = $("input[name^='W"+test[i].value+"']");
        HArr = $("input[name^='H"+test[i].value+"']");
		picstr = "";
		for(var j=0;j<smallpicArr.length;j++)
		{
            picstr = picstr + smallpicArr[j].value + "[rendie:1]" +bgcolor[i].value + "[rendie:1]" + WArr[j].value + "[rendie:1]" + HArr[j].value + "[rendie:2]"
		}
		 pic = pic + picstr + "[rendie:3]"
       }
	str=str+ "Property:"+Property+",IsLimitbuy:"+IsLimitbuy+",pic:\""+pic+"\"}"
	return str
  }
function addbig(j){
  return '\
  <div id="bigpic'+j+'">\
	<input type="hidden" name="picid" value="'+j+'"/>\
	<input type="text" size="6" name="bgcolor" style="border-left:20px #666666 solid;border-right:1px #666666 solid; border-bottom:1px #666666 solid; border-top:1px #666666 solid;">\
	<input type="text" class="tip" size="40" name="pic'+j+'" id="pic'+j+'_1">\
	<iframe src="fckeditor/rendie_upload.htm?pic'+j+'_1" scrolling="no" topmargin="0" width="200" height="30" marginwidth="0" marginheight="0" frameborder="0" align="center"></iframe>\
	<input type="text"size="2"name="W'+j+'"id="W'+j+'_1"/>x\
	<input type="text"size="2"name="H'+j+'"id="H'+j+'_1"/>\
	<input type="button" value="生成" size="2" class="pn" onclick="GenerateImages($(\'#pic'+j+'_1\').val(),\'pic'+j+'_1\',$(\'#W'+j+'_1\').val(),$(\'#H'+j+'_1\').val());"/>\
	<img onclick="$(\'#bigpic'+j+'\').remove();" src="'+imagesPath+'img/btn_dec.gif" class="pointer" alt="删除第'+j+'组的所有图片" align="absmiddle"/>'+addsmallSkin(j,1)+'\
  </div>'
}
function addbigend(j){
  $("#addproductpicSkin-"+j).before(addbig(j+1)+addproductpicSkin(j+1));	
  $("#addproductpicSkin-"+j).remove()
}
function addproductpicSkin(j){
  return '<div id="addproductpicSkin-'+j+'">\
			 <img src="'+imagesPath+'img/btn_add.gif" style="cursor:pointer" onclick="addbigend('+j+')"/>&nbsp;&nbsp;\
			 <font color="red">您可以单击前面的按钮添加一组图片</font>\
		   </div>'
}
function addsmallSkin(j,i){
  return '<div id="addsmallSkin'+j+'-'+i+'">\
		    &nbsp;&nbsp;└<img src="'+imagesPath+'img/btn_add.gif" style="cursor:pointer" onclick="addsmallend('+j+','+i+');"/>&nbsp;&nbsp;\
			<font color="red">您可以单击前面的按钮添加一个"子图片"，也可以按大小生成"子图片"或上传"子图片"</font>\
		  </div>'
}
function addsmall(j,i)
{
	return '<div id="smallpic'+j+'-'+i+'">\
				&nbsp;&nbsp;├<input type="text" size="2" name="W'+j+'" id="W'+j+'-'+i+'"/>x\
				<input type="text"size="2" name="H'+j+'" id="H'+j+'-'+i+'"/>\
				<input type="button" value="生成" size="2" class="pn" onclick="ImagesWH('+j+','+i+')" />\
				<input type="text" size="30" class="tip" name="pic'+j+'" id="pic'+j+'-'+i+'">\
				<iframe src="fckeditor/rendie_upload.htm?pic'+j+'-'+i+'" scrolling="no" topmargin="0" width="200" height="30" marginwidth="0" marginheight="0" frameborder="0" align="center"></iframe>\
				<img onclick="$(\'#smallpic'+j+'-'+i+'\').remove();" src="'+imagesPath+'img/btn_dec.gif" class="pointer" alt="删除第'+j+'组的'+i+'个图片" align="absmiddle"/>\
			  </div>'
}
function ImagesWH(j,i){
  var W,H,path
  W=$("#W"+j+"-"+i).val()
  H=$("#H"+j+"-"+i).val()
  path=$('#pic'+j+'_1').val()
  GenerateImages(path,"pic"+j+"-"+i,W,H)
}
function addsmallend(j,i){
  $("#addsmallSkin"+j+"-"+i).before(addsmall(j,i+1)+addsmallSkin(j,i+1));	
  $("#addsmallSkin"+j+"-"+i).remove()
}

function ToHTMLDeCode(str)
{
	var s = "";
	if (str.length == 0) return "";
	s = str.replace(/&gt;/g, "&");
	s = s.replace(/&lt;/g, "<");
	s = s.replace(/&gt;/g, ">");
	s = s.replace(/&nbsp;/g, " ");
	s = s.replace(/'/g, "\'");
	s = s.replace(/&quot;/g, "\"");
	s = s.replace(/<br>/g, "\n");
	return s;
}

function getProduct()
{			 
  $(parent.document).find("#ajaxmsg").toggle("fast");
  var key=escape($('input[name=key]').val());
  var tid=$('#kbtid>option:selected').val();
  var priceType=$('#PriceType>option:selected').val();
  var minPrice=$("#minPrice").val();
  var maxPrice=$("#maxPrice").val();
  var str='';
  if (key!='')
  {
   str='&nbsp;&nbsp;商品名称:'+$('input[name=key]').val();
  } 
  if (tid!='' && tid !='0')
  {
   str+='&nbsp;&nbsp;&nbsp;&nbsp;栏目:'+$('#kbtid>option:selected').get(0).text+"&nbsp;&nbsp;&nbsp;&nbsp;"
  }
  if (priceType!=0)
  {
	str+= minPrice +' 元';
	switch (parseInt(priceType))
	{
	  case 1 :
	    str+='<=当前零售价<=';
	    break;
	  case 2 :
	   str+='<=商城价<=';
	   break;
	 case 3 :
	   str+='<=原始零售价<=';
	   break;
	}
	str+= maxPrice +' 元';
  }
 $("#keyarea").html(str);
 $.get("ajax/admin_shop.asp?GetPackagePro/"+key+"/"+tid+"/"+priceType+"/"+minPrice+"/"+maxPrice+".html",function(data){$("#prolist").empty().append(data);});
}
function addProductIn(){
  var proid=$('#prolist>option:selected').val();
  if (proid!=undefined)
  {
	$.post("ajax/admin_content.aspx?kbprice/"+proid,function(result){
	  updateKBXS(proid+"@@@"+result+"@@@"+$('#prolist>option:selected').get(0).text)
    })
  }
  else
  {
    alert('请选择要加入捆绑销售的商品!');
  }
}
function updateKBXS(arrstr)
{
  if (arrstr!='')
  {
	var finder=false;
	var arr=arrstr.split('@@@');
	$('#KBProList>option').each(function()
	{
	 if (arr[0]==this.value.split('|')[0])
	 {
	   this.text=arr[2]+"(捆绑销售价:￥"+arr[1]+"元)";
	   this.value=arr[0]+"|"+arr[1];
	   finder=true;
	 }
	});
	if(finder==false){
	  $('#KBProList').append("<option value='"+arr[0]+"|"+arr[1]+"' selected>"+arr[2]+"(捆绑销售价:￥"+arr[1]+"元)</option>");
	}
  }

}
function modifyKBXS(){
  var l=$('#KBProList>option:selected').length;
  if (l==1)
  {
    var kb=$('#KBProList>option:selected').val().split('|');
    top.openWin('设置捆绑销售价格','KS.Shop.asp?action=SetKBXSPrice&proid='+kb[0]+'&kbprice='+kb[1]+'&rnd='+Math.random(),false,350,200);
  }
  else if(l==0)
  {
    alert('请选择一个商品!');
  }
  else
  {
    alert('一次只能选择一个商品!');
  }
}
function delAllKBXS(){
$("#KBProList").empty();
}
function delSelectKBXS(){
  var dest = document.getElementById('KBProList');
  for (var i = dest.options.length - 1; i >= 0 ; i--)
  {
	if (dest.options[i].selected)
	{
	  dest.options[i] = null;
	}
  }
}
function selectAllKBXS(){
  $("#KBProList option").each(function()
  {
	$(this).attr("selected",true);
  });
}
