function dialog_act(options) {
	if(!options.parent_id)
	{
		throw  'parent_id is not null';
	}
	var set={
		parent_id		:	options.parent_id,
		height			:	(options.height?options.height:360),
		width			:	(options.width?options.width:550),
		input			:	'checkbox',//(options.input=='radio'?'radio':'checkbox'),
		tag_click_id	:	options.tag_click_id,	
		max				:	(options.max?options.max:5),
		min				:	(options.min?options.min:0),
		tag_select_id	:	options.tag_select_id,
		content_id_fix	:	options.content_id_fix,
		tag_class_id_fix:	options.tag_class_id_fix,
		tag_parent_id	:	options.tag_parent_id,
		parameter		:	(!$.trim(options.parameter)?'txt':'id')
	};
	var tips = $("#"+set.parent_id+" .dialog_content .preview ul");	
	var global_count_priview=0;	
	var errtips=$("#"+set.parent_id+" #validateTips");
	errtips.html("");
	$("#"+set.parent_id+" .dialog_content #"+set.tag_select_id+"").change(function(){
		if(!$(this).val())
		{
			$("#"+set.parent_id+" .dialog_content .content").hide();
		}
		$("#"+set.parent_id+" .dialog_content .content").hide();
		$("#"+set.parent_id+" .dialog_content #"+set.content_id_fix+""+$(this).val()).show();
		
	});
	
	$("#"+set.parent_id+" .content .dialog_category").click(function(){
		var dialog_category=$(this).parents("div").attr("id");
		var tmpid=$(this).attr("id");
		var tmpval=$(this).val();
		var disabled=false;
		
		if($(this).attr("checked")==true)
		{
			disabled=true;
			global_count_priview=tips.children("li").length;
			global_count_priview++;
			if(set.max>0 && global_count_priview>set.max)
			{
				errtips.html("&#x6700;&#x591A;&#x5141;&#x8BB8;&#x9009;&#x62E9; <span class='red'><strong>"+set.max+"</strong></span> &#x9879;").effect("highlight",{},1500);
				return false;
			}
			else
			{
				updateTips(tmpid);
			}
			$("#"+set.parent_id+"  #"+dialog_category+" .dialog_class").each(function(){
				if($(this).attr("id")!=tmpid)
				{
					$(this).attr("checked",false);
					$(this).attr("disabled",true);
				}
			});
		}
		else
		{
			$("#"+set.parent_id+"   #"+dialog_category+"  .dialog_class").each(function(){
				$(this).attr("disabled",false);
				$(this).attr("checked",false);
			});
			tips.children("#"+tmpval).remove();
			clear_content_checkbox($(this).val());
		}
		$("#"+set.parent_id+" #"+dialog_category+" input[type='radio']").each(function(){
			$(this).attr("disabled",disabled);
		});
		
	});
	
	
	$("#"+set.parent_id+" .dialog_class").click(function(){
		var tmpval=$(this).val();
		if($(this).attr("checked")==true)
		{
			var tmpid=$(this).attr('id');
			global_count_priview=tips.children("li").length
			global_count_priview++;
			if(set.max>0 && global_count_priview>set.max)
			{
				errtips.html("&#x6700;&#x591A;&#x5141;&#x8BB8;&#x9009;&#x62E9; <span class='red'><strong>"+set.max+"</strong></span> &#x9879;").effect("highlight",{},1500);
				return false;
			}
			else
			{
				updateTips(tmpid);
			}
		}
		else
		{
		tips.children("#"+tmpval).remove();
		}
	});
	
	
	function updateTips(id) {
		if($.trim(id))
		{
			var s={id:'',val:''};
			var tmp="";
			$("#"+set.parent_id+" .content input").each(function(){
				if($(this).attr('id')==id)
				{
					s.id=$(this).val();
					s.val=$(this).attr("categoryname");
				}
			});
			if(set.input=='radio')
			{
				tmp="<li id='"+s.id+"' txt='"+s.val+"'><label><input type='checkbox' class='dialog_preview' id='dialog_preview_i_"+s.id+"' value='"+s.id+"' checked>"+s.val+" , </label> </li>";
			}
			else
			{
				tmp="<li id='"+s.id+"' txt='"+s.val+"'><label><input type='checkbox' class='dialog_preview' id='dialog_preview_i_"+s.id+"' value='"+s.id+"' checked>"+s.val+" , </label></li>";
				var items='';
				tips.each(function(){
					$(this).children("li").each(function(){
						if($(this).attr('id')!=s.id)
						{
							items+="<li id='"+$(this).attr('id')+"' txt='"+$(this).attr('txt')+"'><label><input type='checkbox' class='dialog_preview'   id='dialog_preview_i_"+$(this).attr('id')+"' value='"+$(this).attr('id')+"' checked>"+$(this).attr('txt')+" , </label></li>";
						}
					});
				});
					tmp=items+tmp;
			}
			tips.html(tmp);
				tips.each(function(){
					$(this).children("li").each(function(){
						$(this).bind("click",function(){
							if($(this).attr("id"))
							{
								reid=$(this).attr("id");
								tips.children("#"+reid).remove();
								clear_content_checkbox(reid);
							}
						});
					});
				});
		}
	}
	function clear_content_checkbox(id)
	{
		if($.trim(id))
		{
			$("#"+set.parent_id+" .content input").each(function(){
				if($(this).val()==id)
				{
					$(this).attr("checked",false);
				}
			});
		}
	}
	function clear_priview()
	{
		$("#"+set.parent_id+" #"+set.tag_select_id).attr("value","Normal");
		$("#"+set.parent_id+" .content input").attr("checked",false);
		global_count_priview=0;
		tips.html('');
	}
	function each_priview()
	{
		var ids='',txt='';
		tips.each(function(){
			$(this).children("li").each(function(){
				txt+=($.trim(txt)?" \+ "+$(this).attr('txt'):$(this).attr('txt'));
				if(set.parameter=='txt')
				{
					ids+=($.trim(ids)?","+$(this).attr('txt'):$(this).attr('txt'));
				}
				else
				{
					ids+=($.trim(ids)?","+$(this).attr('id'):$(this).attr('id'));
				}
			});
		});
		if($.trim(set.cityparentid))
		{
			$(set.cityparentid+" input[name='"+set.tag_click_id+"']").each(function(){
				$(this).val(ids);						  
			});	
			$(set.cityparentid+"  div[id='"+set.tag_click_id+"_preview']").each(function(){
				
				$(this).html(txt);						  
			});	
		}
		$(set.cityparentid+" #"+set.tag_click_id+"_preview").html(txt);
		$(set.cityparentid+" #"+set.tag_click_id+"").val(ids);
	}
	
	$("#"+set.parent_id+"").dialog({
		bgiframe: true,
		autoOpen: false,
		height: set.height,
		width: set.width,
		modal: true,
		buttons: {
			'清空':function(){
				clear_priview();
				$(this).dialog('close');
			},
			'确定':function(){
					each_priview();
					//clear_disabled();
					$(this).dialog('close');
			}
		},
		close: function() {
			tips.removeClass('ui-state-error');
		}
	});
	$("#"+set.tag_click_id+"_preview").click(function() {
		set.cityparentid=$(this).parents("div").attr("id");
		if($.trim(set.cityparentid))
		{
			set.cityparentid="#"+set.cityparentid;
		}
		else
		{
			set.cityparentid='';
		}
		clear_priview();
		$("#"+set.parent_id+"").dialog('open');
	});
	
	function clear_disabled()
	{
		$("#"+set.parent_id+" input[type='checkbox']").each(function(){
			$(this).attr("disabled",false);
			});
	}
}

