	 	function refresh_img_list_box()
		{
			var curr_id = $("#gallery_id").val();
			var thumb_list = document.getElementById("gallery_list").getElementsByTagName("IMG");
			var input_list = document.getElementById("gallery_list").getElementsByTagName("INPUT");
			for(var i=0;i<input_list.length;i++)
			{
				if(input_list[i].value == curr_id)
				{
					thumb_list[i].className="selectborder";
				}
				else
				{
					thumb_list[i].className = "";
				}
			}
		}
		
		function setgallery(id)
		{		
			$.ajax({
				  url: APP+"?"+VAR_MODULE+"=Goods&"+VAR_ACTION+"=setGallery&id="+id,
				  cache: false,
				  success:function(data)
				  {
					data = $.evalJSON(data); 

					if(data.info)
					{
						alert(data.info);
					}
					else
					{
						$("#gallery_id").val(data.id);
						$("#goods_img_box").attr("src",ROOT_PATH+data.big_img);
						refresh_img_list_box();						
					}
				  }
				}); 
		}
		
		function delgallery(id,obj)
		{
			if(confirm(CONFIRM_DELETE_IMAGE))
			$.ajax({
				  url: APP+"?"+VAR_MODULE+"=Goods&"+VAR_ACTION+"=delGallery&id="+id,
				  cache: false,
				  success:function(data)
				  {

					
					if(data!='')
					{
						data = $.evalJSON(data); 
						alert(data.info);
					}
					else
					{
						if($("#gallery_id").val()==id)
						{
							$("#gallery_id").val(0);
							$("#goods_img_box").attr("src",PUBLIC+"/Images/nopic.gif");
						}
						obj.parentNode.parentNode.removeChild(obj.parentNode);
					}
				  }
				}); 
		}

		
		function getAttrList(obj)
		{
			var type_id = obj.value;
			var goods_id = document.getElementById("goods_id")?document.getElementById("goods_id").value:0;	
			
			$.ajax({
				  url: APP+"?"+VAR_MODULE+"=Goods&"+VAR_ACTION+"=getTypeAttr&type_id="+type_id+"&goods_id="+goods_id,
				  cache: false,
				  success:function(data)
				  {		

					  data = $.evalJSON(data); 					  
					  var html = "";
					  var lang_ids_array = lang_ids.split(',');
					  var lang_names_array = lang_names.split(',');
					  for(var i=0;i<data.length;i++)
					  {
						  if(data[i].row_count==0)
						  {
							 m=0;
							 html+= "<div style='padding-bottom:5px;'>"+data[i]['name_'+default_lang_id]+":";
							  if(data[i]['input_type']=='0')
							  {
								  //列表
								  for(var k=0;k<lang_ids_array.length;k++)
								  {
									  html+="<select name='attr_value["+data[i]['id']+"]["+lang_ids_array[k]+"][]'>";

									  for(var j=0;j<data[i]['attr_value_'+lang_ids_array[k]].length;j++)
									  {
										  html+="<option value='"+data[i]['attr_value_'+lang_ids_array[k]][j]+"'";
										  var c_val ='';
										  if(data[i]['value_'+lang_ids_array[k]]!=undefined)
										  {
											  c_val = data[i]['value_'+lang_ids_array[k]][m];
										  }

										  if(c_val==data[i]['attr_value_'+lang_ids_array[k]][j])
										  {
											  html+=" selected='selected' ";
										  }
										  html+=" >"+data[i]['attr_value_'+lang_ids_array[k]][j]+"</option>";
									  }
									  html+="</select>&nbsp;("+lang_names_array[k]+")&nbsp;";
								  }
						
							  }
							  else
							  {
								  for(var k=0;k<lang_ids_array.length;k++)
								  {
									  var c_val ='';
									  if(data[i]['value_'+lang_ids_array[k]]!=undefined)
									  {
										  c_val = data[i]['value_'+lang_ids_array[k]][m];
									  }
									  html+="<input type='text' value='"+c_val+"' name='attr_value["+data[i]['id']+"]["+lang_ids_array[k]+"][]' />&nbsp;("+lang_names_array[k]+")&nbsp;";
								  }
								  
							  }
							  
							  
							  //if(data[i]['attr_type']==1)
							  if(true)
							  {
								  /*var p_val ='';
								  if(data[i]['price']!=undefined)
								  {
									  p_val = data[i]['price'][m];
								  }
								  html+=ATTR_PRICE+"：<input type='text' name='attr_price["+data[i]['id']+"][]' value='"+p_val+"' />";
								  var s_val ='';
								  if(data[i]['stock']!=undefined)
								  {
									  s_val = data[i]['stock'][m];
								  }
								  if(s_val&&s_val==1)
									  html+=ATTR_STOCK+"：<input type='checkbox' value='1' checked='checked' onchange='setStockVal(this);' /><input type='hidden' value='1' name='attr_stock["+data[i]['id']+"][]'  />";
								  else
									  html+=ATTR_STOCK+"：<input type='checkbox' value='1' onchange='setStockVal(this);'  /> <input type='hidden' value='0' name='attr_stock["+data[i]['id']+"][]'  />";
								  */
								  if(m==0)
								  html+="[<a href='javascript:;' onclick='addAttrInputRow(this);'>+</a>]";
								  else
							      html+="[<a href='javascript:;' onclick='delAttrInputRow(this);'>-</a>]";
							  }
							  
							  html+="</div>";
						  }
						  else
						  {
						  for(var m=0;m<data[i].row_count;m++)
						  {
						  html+= "<div style='padding-bottom:5px;'>"+data[i]['name_'+default_lang_id]+":";
						  if(data[i]['input_type']=='0')
						  {
							  //列表
							  for(var k=0;k<lang_ids_array.length;k++)
							  {
								  html+="<select name='attr_value["+data[i]['id']+"]["+lang_ids_array[k]+"][]'>";
								  for(var j=0;j<data[i]['attr_value_'+lang_ids_array[k]].length;j++)
								  {
									  html+="<option value='"+data[i]['attr_value_'+lang_ids_array[k]][j]+"'";
									  var c_val ='';
									  if(data[i]['value_'+lang_ids_array[k]]!=undefined)
									  {
										  c_val = data[i]['value_'+lang_ids_array[k]][m];
									  }

									  if(c_val==data[i]['attr_value_'+lang_ids_array[k]][j])
									  {
										  html+=" selected='selected' ";
									  }
									  html+=" >"+data[i]['attr_value_'+lang_ids_array[k]][j]+"</option>";
								  }
								  html+="</select>&nbsp;("+lang_names_array[k]+")&nbsp;";
							  }
					
						  }
						  else
						  {
							  for(var k=0;k<lang_ids_array.length;k++)
							  {
								  var c_val ='';
								  if(data[i]['value_'+lang_ids_array[k]]!=undefined)
								  {
									  c_val = data[i]['value_'+lang_ids_array[k]][m];
								  }
								  html+="<input type='text' value='"+c_val+"' name='attr_value["+data[i]['id']+"]["+lang_ids_array[k]+"][]' />&nbsp;("+lang_names_array[k]+")&nbsp;";
							  }
							  
						  }
						  
						  
						  //if(data[i]['attr_type']==1)
						  if(true)
						  {
							  /*var p_val ='';
							  if(data[i]['price']!=undefined)
							  {
								  p_val = data[i]['price'][m];
							  }
							  html+= ATTR_PRICE+"：<input type='text' name='attr_price["+data[i]['id']+"][]' value='"+p_val+"' />";
							  var s_val ='';
							  if(data[i]['stock']!=undefined)
							  {
								  s_val = data[i]['stock'][m];
							  }
							  if(s_val&&s_val==1)
								  html+=ATTR_STOCK+"：<input type='checkbox' value='1' checked='checked' onchange='setStockVal(this);' /><input type='hidden' value='1' name='attr_stock["+data[i]['id']+"][]'  />";
							  else
								  html+=ATTR_STOCK+"：<input type='checkbox' value='1' onchange='setStockVal(this);'  /> <input type='hidden' value='0' name='attr_stock["+data[i]['id']+"][]'  />";
							  */
							  if(m==0)
							  html+="[<a href='javascript:;' onclick='addAttrInputRow(this);'>+</a>]";
							  else
						      html+="[<a href='javascript:;' onclick='delAttrInputRow(this);'>-</a>]";
						  }
						  else
						  {
							  if(data[i]['input_type']==1)
							  {
								  html+="("+ATTR_TIPS+")";
							  }
						  }
						  
						  html+="</div>";
						  } //end row_count loop
						  } // end if count
					  }
					  $("#attr_list").html(html);
				  }
				}); 
		}
		function setStockVal(obj)
		{
			if(obj.checked)
				$(obj).next("input").val(1);
			else
				$(obj).next("input").val(0);	
		}
		function addAttrInputRow(obj)
		{
			var contentbox = obj.parentNode;
			var innerhtml = contentbox.innerHTML;
			innerhtml = innerhtml.replace(/addAttrInputRow/g,"delAttrInputRow");
			innerhtml = innerhtml.replace(/\+/g,"-");	
			var html = "<div style='padding-bottom:5px;'>"+innerhtml+"</div>";
			$(contentbox).after(html);
		}
		
		
		function addSpecTypeItem(obj)
		{
			$.ajax({
				  url: APP+"?"+VAR_MODULE+"=SpecType&"+VAR_ACTION+"=addRow",
				  cache: false,
				  success:function(html)
				  {
						var contentbox = obj.parentNode;
						$(contentbox).after(html);
				  }
				}); 
			
		}
		function delAttrInputRow(obj)
		{
			var contentbox = obj.parentNode;
			$(contentbox).remove();
		}
		
		function delSpecData(obj)
		{
			var id = $(obj.parentNode).find(".spec_item_id").val();
			if(confirm(CONFIRM_DELETE))
			{
				$.ajax({
					  url: APP+"?"+VAR_MODULE+"=SpecType&"+VAR_ACTION+"=delSpecItem&id="+id,
					  cache: false,
					  success:function(data)
					  {
						if(data>0)
						{
							var contentbox = obj.parentNode;
							$(contentbox).remove();
						}
						else
						{
							alert(SPEC_USED);
						}
					  }
					}); 
			}
		}
		
		
		function getSpecList(obj)
		{
			$.ajax({
				  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=listSpec&id="+obj.value,
				  cache: false,
				  success:function(data)
				  {
		     		  list = $.evalJSON(data);
					  html = "<input type='hidden' id='spec_type_id' value='"+obj.value+"' />";
					  for(var i=0;i<list.length;i++)
					  {
						  	html = html + "<input type='checkbox' value='"+list[i].id+"' />";	
						  	for(var j=0;j<(list[i].spec_name).length;j++)
						  	{
						  		var names = list[i].spec_name;
						  		html += "&nbsp;&nbsp;&nbsp;&nbsp;"+names[j];
						  	}
						  	html+="<br />";
					  }
					  $("#content_box").html(html);
				  }
				}); 
		}
		
		function makeGoodsSpec(obj,goods_id,idx)
		{
			$.ajax({
				  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=checkEditable&is_ajax=1&goods_id="+$("#goods_id").val(),
				  cache: false,
				  success:function(data)
				  {
		     		  if(data == 1)
		     		  {
		     			  	var spec_type_id = obj.value;
		     			 
			     			 $.ajax({
			   				  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=makeGoodsSpec&spec_type="+spec_type_id+"&goods_id="+goods_id+"&idx="+idx,
			   				  cache: false,
			   				  success:function(data)
			   				  {
			   		     		    res = $.evalJSON(data);
			   		     		    loadSpecConf(goods_id,idx);
			   		     		    var selectbox;
			   		     		    if(idx==1)
			   		     		    {
			   		     		    	selectbox = document.getElementById("spec_type_box2");
			   		     		    }
			   		     		    else
			   		     		    {
			   		     		    	selectbox = document.getElementById("spec_type_box1");
			   		     		    }
			   		     		    var html = "<option value='0'>"+SELECT_SPEC_TYPE+"</option>";
			   		     		    for(var i=0;i<res.spec_type_list.length;i++)
			   		     		    {
			   		     		    	html+="<option value='"+res.spec_type_list[i].id+"'>"+res.spec_type_list[i].name+"</option>";
			   		     		    }
			   		     		    var o_v = $(selectbox).val();
			   		     		    $(selectbox).html(html);
			   		     		    $(selectbox).val(o_v);
			   				  }
			   				});			     			 
		     		  }
		     		  else
		     		  {
		     			 alert(GOODS_SPEC_ITEM_EXIST);
		     		  }
				  }
				});		
				
		}
		

		function addSpecRow(obj,spec_id_o,idx)
		{
			if(!spec_id_o) var spec_id_o=0;
			$.ajax({
 				  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=addSpecRow&spec_id="+spec_id_o,
 				  cache: false,
 				  success:function(spec_id)
 				  {
   				 	 var contentbox = obj.parentNode;
	     			 var innerhtml = contentbox.innerHTML;
	     			
	     			 innerhtml = innerhtml.replace(/<input(.*)select_goods_spec(.*)>/g,"<input type=\"checkbox\" value=\""+spec_id+"\" class=\"select_goods_spec spec_group_"+idx+"\" onclick=\"makeSpecItemTable();\"/>");
	     			 innerhtml = innerhtml.replace(/<input(.*)spec_id_hidden(.*)>/g,"<input type='hidden' class='spec_id_hidden' name='spec_id[]' value='"+spec_id+"'/>");
	     			 innerhtml = innerhtml.replace("value="+spec_id_o,"value="+spec_id);
	     			 innerhtml = innerhtml.replace("value="+spec_id_o,"value="+spec_id);
	     			 innerhtml = innerhtml.replace(/<font(.*)font>/gi,"");	
	     			 innerhtml = innerhtml.replace(/<object(.*)object>/gi,"<span id='image_browse_"+spec_id+"'></span>");	
	     			 innerhtml = innerhtml.replace(/<script(.*)t>/g,"");
	     			 
	     			 innerhtml = innerhtml.replace("_"+spec_id_o,"_"+spec_id);	
	     			 innerhtml = innerhtml.replace(","+spec_id_o,","+spec_id);	
	     			 innerhtml = innerhtml.replace(","+spec_id_o,","+spec_id);	
	     			 innerhtml = innerhtml + "<font>存入预设：<input type='checkbox' name='insert_to_spec[]' value='"+spec_id+"' /></font>";
	     			 
	     			 var html = "<div style='padding-bottom:5px;'>"+innerhtml+"</div>";
	     			 $(contentbox).after(html);
	     			 bindChangeValue();
	     			
	     			 
	     			 //开始重新绑定上传控件
	     			 var settings = {
	     					flash_url : PUBLIC+"/Js/swfupload/swfupload.swf",
	     					upload_url: APP,				
	     					post_params: {"m":"Public","a":"uploadSpecIcon","spec_id":spec_id,"idx":idx},
	     					file_size_limit : MAX_UPLOAD,
	     					file_types : "*.jpg;*.gif",
	     					file_types_description : MAX_UPLOAD_TIP,
	     					file_upload_limit : 100,
	     					file_queue_limit : 100,
	     					custom_settings : {
	     						progressTarget : "fsUploadProgress",
	     						cancelButtonId : "btnCancel"
	     					},
	     					debug: false,

	     					// Button settings
	     					button_image_url: PUBLIC+"/Images/uploadSpec.gif",
	     					button_width: "13",
	     					button_height: "13",
	     					button_placeholder_id: "image_browse_"+spec_id,

	     					
	     					// The event handler functions are defined in handlers.js
	     					file_queued_handler : fileQueued,
	     					file_queue_error_handler : fileQueueError,
	     					file_dialog_complete_handler : fileDialogComplete,
	     					upload_start_handler : uploadStart,
	     					upload_progress_handler : uploadProgress,
	     					upload_error_handler : uploadError,
	     					upload_success_handler : uploadSpecSuccess,
	     					upload_complete_handler : uploadComplete,
	     					queue_complete_handler : queueComplete	// Queue plugin event
	     				};
	     			 	
	     				var swfu = new SWFUpload(settings,idx+'_'+spec_id);
	     			 //上传控件绑定结束
 				  }
 				});	
   			
   				makeSpecItemTable();			
			
		}
		

		
		function delSpecRow(obj,spec_id,idx)
		{
			if(!spec_id) var spec_id=0;
			$.ajax({
				  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=checkDelAble&goods_id="+$("#goods_id").val()+"&spec_id="+spec_id,
				  cache: false,
				  success:function(data)
				  {
		     		  if(data == 1)
		     		  {
		     				$.ajax({
		     	 				  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=delSpecRow&spec_id="+spec_id,
		     	 				  cache: false,
		     	 				  success:function(data)
		     	 				  {
			     					if(SWFUpload.instances["SWFUpload_"+idx+"_"+spec_id])
			     					{				
			     						SWFUpload.instances["SWFUpload_"+idx+"_"+spec_id].destroy();
			     					}
		     	   				 	 var contentbox = obj.parentNode;			     				
		     		     			 $(contentbox).remove();
		     	 				  }
		     	 				});	
		     				 
		     				 	makeSpecItemTable();		     			 
		     		  }
		     		  else
		     		  {
		     			 alert(GOODS_SPEC_ITEM_EXIST);
		     		  }
				  }
				});	
			
			
			
		}
		
		function addSpecItem()
		{
			$.ajax({
				  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=addSpecItem&goods_id="+$("#goods_id").val(),
				  cache: false,
				  success:function(data)
				  {
					  location.href = location.href;
				  }
				});	
		}
		
		function modifySpecDetail(spec_type_id,spec_item_id)
		{
			$.ajax({
				  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=getGoodsSpec&goods_id="+$("#goods_id").val()+"&spec_type_id="+spec_type_id,
				  cache: false,
				  success:function(data)
				  {
					  res = $.evalJSON(data);
					  var html = '';
					  for(var i=0;i<res.length;i++)
					  {
						  html+="<a href='javascript:;' onclick='selectSpec("+spec_type_id+","+spec_item_id+","+res[i].id+",this);'>"+res[i].spec_name+"</a>";
					  }
					  html+="<a href='javascript:;' onclick='closeThisSpan(this);'>"+CLOSE+"</a>";
					  $("#select_box_"+spec_type_id+"_"+spec_item_id).fadeIn(200);
					  $("#select_box_"+spec_type_id+"_"+spec_item_id).html(html);
				  }
				});	
		}
		
		function selectSpec(spec_type_id,spec_item_id,spec_id,obj)
		{
			$.ajax({
				  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=setGoodsSpec&spec_type_id="+spec_type_id+"&spec_item_id="+spec_item_id+"&spec_id="+spec_id,
				  cache: false,
				  success:function(data)
				  {
				    if(data == 1)
				    	location.href = location.href;
				    else
				    	alert(EXIST_SAME_SPEC);
				  }
				});	
		}
		
		function closeThisSpan(obj)
		{
			$(obj.parentNode).fadeOut(200);			
		}
		
		function delSpecItem(obj)
		{
			if(confirm(CONFIRM_DELETE))
			{
				var spec_item_id = $(obj.parentNode.parentNode).find(".select_spec_item_id").val();
				if(spec_item_id>0)
				$.ajax({
					  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=delSpecItem&spec_item_id="+spec_item_id,
					  cache: false,
					  success:function(data)
					  {							
							data = data.split("|");
							if(data.length>0)
							{
								resetUploader(1);
								$("#spec_type_1").html(data[0]);	
							}
							if(data.length>1)
							{
								resetUploader(2);
								$("#spec_type_2").html(data[1]);
							}
							$(obj.parentNode.parentNode).remove();
					  }
				});	
				else
				{
					$(obj.parentNode.parentNode).remove();
				}
			}
		}

	function loadSpecConf(goods_id,idx)
	{
		$.ajax({
			  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=loadSpecConf&goods_id="+goods_id+"&idx="+idx,
			  cache: false,
			  success:function(data)
			  {		
				resetUploader(idx);
				$("#spec_type_"+idx).html(data);				
			  }
			});	
	}
	function resetUploader(idx)
	{
		var spec_id_box = $(".spec_group_"+idx);		
		for(var i=0;i<spec_id_box.length;i++)
		{			
			if(SWFUpload.instances["SWFUpload_"+idx+"_"+spec_id_box[i].value])
			{				
				SWFUpload.instances["SWFUpload_"+idx+"_"+spec_id_box[i].value].destroy();
			}
		}	
	}
	
	function bindChangeValue()
	{
		var box = $("#spec_table").find(".spec_name_box");
		
		for(var i=0;i<box.length;i++)
		{
		
			box[i].onblur=function()
			{
				var eventobj = this;
				var spec_id = $(eventobj.parentNode).find(".spec_id_hidden").val();
				var field = eventobj.name;
				var value = escape(eventobj.value);
				
				$.ajax({
					  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=setSpecValue&spec_id="+spec_id+"&field="+field+"&value="+value,
					  cache: false,
					  success:function(data)
					  {
							makeSpecItemTable();
					  }
					});	
				
			}
		}
		
	}

	function makeSpecItemTable()
	{
		
		var goods_id = $("#goods_id").val();
		var boxes_1 = $(".spec_group_1");
			var spec_ids_1 = new Array();
			for(var i=0;i<boxes_1.length;i++)
			{
				if(boxes_1[i].checked)
				{
					spec_ids_1.push(boxes_1[i].value);
				}
			}
			var boxes_2 = $(".spec_group_2");
			var spec_ids_2 = new Array();
			for(var i=0;i<boxes_2.length;i++)
			{
				if(boxes_2[i].checked)
				{
					spec_ids_2.push(boxes_2[i].value);
				}
			}
			var spec_conf = new Array();
			spec_conf[0] = spec_ids_1;
			spec_conf[1] = spec_ids_2;
			spec_conf = $.toJSON(spec_conf);
			
			$.ajax({
				  url: APP+"?"+VAR_MODULE+"=GoodsSpec&"+VAR_ACTION+"=makeSpecItemTable&spec_conf="+spec_conf+"&shop_price="+$("#shop_price").val()+"&weight="+$("#weight").val()+"&cost_price="+$("#cost_price").val()+"&sn="+$("#sn").val(),
				  cache: false,
				  success:function(data)
				  {
						
						$("#spec_item_list").html(data);
						
						
						
						 //编辑会员
						  var ut = $('#user_price div.jqmdMSG');	  
						  $('#user_price').jqm({
						    trigger: 'a.user_price_trigger',
						    url: '@href', /* Extract ajax URL from the 'href' attribute of triggering element */
						    target: ut,
						    modal: true, /* FORCE FOCUS */	
						    onShow:function(h)
						    {						   
							   h.w.show(100); // hide window	 
						    },
						    onHide: function(h) { 
						    	
							  if($("#is_close_user").val()==1)
							  {
								 var price_boxes = $(".user_price_box");
								 var user_price = new Array();
								 for(var i=0;i<price_boxes.length;i++)
								 {
									 var group_id = price_boxes[i].id;
									 group_id = group_id.split("_");
									 user_price_obj = new Object();
									 user_price_obj.user_price = price_boxes[i].value;
									 user_price_obj.user_group_id = group_id[1];
									 
									 $(h.t.parentNode).find(".user_group_"+user_price_obj.user_group_id).val(user_price_obj.user_price);
									 user_price.push(user_price_obj);
								 }
								 user_price = $.toJSON(user_price);
								 
								 
								 h.o.remove(); // remove overlay
							     h.w.hide(100); // hide window	   
							  }
							  else
							  {
								  $("#is_close_user").val(1);
								  h.o.remove(); // remove overlay
							      h.w.hide(100); // hide window	   
							  }
						         
						    },
						    overlay: 10});
				  }
				});	
		
		
	}
