var prevcategory=null;
function CategoryWindow(options){
	this.options =jQuery.extend({
		defaults:[],
		searchmode:true, //允许搜索
		mutiplemode:true//允许多选
	},options);
	//this.options.mutiplemode=this.options.maxselcount>1;
	this.id = options.id;
	this.rootmenuid=null;
	this.maxselcount = options.maxselcount;
	this.lasta = null;
	this.xmlpath = options.xmlpath;
	this.xml=null;
	this.handler=null;
	this.root=null;
	this.searchdiv=null;
	this.position={};
}
CategoryWindow.prototype.GetSelectCount = function(){
	if (this.options.mutiplemode) {
		return this.root.find("a.checkitem").length;
	}
	else{
		return this.root.find(":radio:checked").length;
	}
}
CategoryWindow.prototype.Bind =function(__handler){
	this.handler = $(__handler.replace("$","_"));
	this.handler.val(this.options.text);
	var _this = this;
	this.handler.click(function(){
		if (prevcategory!=null) {
			if (prevcategory.root.is(":visible")) prevcategory.Close();
		}
		prevcategory = _this;
		if (!_this.rootmenuid) {
			_this.LoadXmlData(function(xml){
				_this.CreateLevelWindow(0);
				_this.LoadLevelData();
				_this.BindLevelEvents(0);
				_this.FixSearchPos();
				
				/*click remove selector events*/
				_this.root.find("#main_selpath").click(function(e){
					if (e.target.nodeName=="A"||e.target.nodeName=="SPAN") {
						var a = e.target.nodeName=="A"?$(e.target):$(e.target).parent();
						var id=a.attr("val");
						var type=a.attr("type");
						var chkboxs= $(":checkbox[value='"+id+"']");
						chkboxs.attr({"checked":false});
						if (type==1){
							chkboxs.change();
						}
						_this.UpdateSelectedValue(id,type,true);//remove 	
					}
				});
				_this.root.find("#scjobkey").keyup(function(e){
					if (e.keyCode==13) {
						_this.root.find("a[ac='search']").click();
					}
					else if(e.keyCode==8&&$(this).val()==''){//删除
						_this.ShowSearchCategory(false);
					}
				});
				_this.LoadDefaults(); //载入默认选择
			});
		}
		else{
		   $("#"+_this.rootmenuid).show();
		   $("#"+_this.rootmenuid).find("a[level='1']:first").mouseout();
		}
});
}
CategoryWindow.prototype.LoadDefaults = function(){
	//默认值选定
	var _this = this;
	if (this.options.defaults) {
		$.each(this.options.defaults,function(i,n){
			_this.UpdateSelectedValue(n,1,false);
		});
	}
}
CategoryWindow.prototype.LoadXmlData = function(__datacallback){
	var _this = this;
	$.get(this.xmlpath, function(doc){
		 _this.xml = $(doc.documentElement);
		  __datacallback(_this.xml);
	}); 
}
CategoryWindow.prototype.LoadLevelData=function(_pid,_checked){
	var sb = new StringBuilder();
	var _exp =typeof(_pid)!='undefined'?"c[type!='1'][pid='"+_pid+"']":"c[type='1']";
	var level=0;
	var _this = this;
	this.xml.children(_exp).each(function(i,n){
		var pid = $(this).attr("pid");
		var id =  $(this).attr("id");
		var clen =$(this).attr("counts");
		      level = parseInt($(this).attr("type"))-1;
		      clen = clen<2?0:clen;
		 
		if (id==pid&&$(this).attr("type")>1) return true;
		var mchecked = _this.options.defaults.indexOf(id)!=-1||_checked==true?"checked":"";//fix default select options
		var url = clen==0?"javascript:selectmenubyid('"+id+"')":"javascript:void(null)";
		sb.append("<a href=\""+url+"\" level=\""+$(this).attr("type")+"\" pid='"+pid+"' clen='"+clen+"' tid='"+id+"' class=\"menuitem\">");
		sb.append("    <input value=\""+id+"\" name=\"chx\" id=\"chx"+id+"\"  pid='"+pid+"' type=\""+(_this.options.mutiplemode==true?"checkbox":"radio")+"\" "+mchecked+"\/>");
		sb.append("    "+$(this).text());
		if (clen>0)
		sb.append("<span class=\"jj\"><\/span>");
		
		sb.append("<\/a>");		
	});
	var levelid=this.id+"_level"+level;
	var _isexp = level==0?this.root.children(".bt"):$("#"+levelid).children("h1");
	var html =sb.toString();
	if (html=='') return;
	_isexp.after(html);
}
CategoryWindow.prototype.IsDataLoaded = function(_pid){
	var item =this.root.find("a.menuitem[tid='"+_pid+"']");
	return (item.attr("dataloaded")=='true');
}
CategoryWindow.prototype.BindLevelEvents =function(_level,_pid){
	if (_level==0) this.UpdateMenuShader(this.root);
	if (this.options.mutiplemode==false) {
		var _this = this;
		this.root.find(":radio").change(function(){
			_this.UpdateSingleValue($(this).val(),!$(this).attr("checked"));
		});
		return;
	}
	var levelid=this.id+"_level"+_level;
	var container = $("#"+levelid);
	var _this = this;
	var _expre="a.menuitem[clen!='0']"+(_pid?"[pid='"+_pid+"']":"");
	var _expre2="a.menuitem[clen='0']"+(_pid?"[pid='"+_pid+"']":"");
	container.children(_expre2).click(function(){
		var level = parseInt($(this).attr("level"));
		_this.CloseLevelWindow(level);
	});
//	debug("BindLevelEvents",_level,_pid,_expre,_expre2);
	container.children(_expre).click(function(e){
			var level = parseInt($(this).attr("level"));
			var pid = parseInt($(this).attr("pid"));
			var tid = parseInt($(this).attr("tid"));
			var nextlevelid=_this.id+"_level"+level;
			var chkbox =$(this).children(":checkbox");
			if (chkbox.attr("disabled")) return;
			var menu =container;
			menu.find("a.hover").removeClass("hover");
			var nextmenu = $("#"+nextlevelid);
			if(!nextmenu.length) { //创建子级菜单
				_this.CreateLevelWindow(level);
				nextmenu = $("#"+nextlevelid);
			}
			else if (nextmenu.is(":visible")&&nextmenu.data("pid")==tid){
				_this.CloseLevelWindow(level);
				return;
			}
			if(_this.IsDataLoaded(tid)==false){
				_this.LoadLevelData(tid,chkbox.attr("checked"));
				_this.BindLevelEvents(level,tid);
				$(this).attr("dataloaded",true);
			}
			nextmenu.data("pid",tid).show();
			nextmenu.children("a[pid]:visible").hide();
			nextmenu.children("a[pid='"+tid+"']:hidden").show();
			$(this).addClass("hover");
			nextmenu.find("#chkcategoryall_"+level).attr("checked",chkbox.attr("checked"));
			if (chkbox.attr("checked")) {
				nextmenu.find(":checkbox[name='chx'][pid='"+tid+"']").attr({"disabled":true,"checked":true});
			}
			_this.CloseLevelWindow(level+1);
			//nextmenu.find(".selsubcategory,.hrt,.cover").hide();//隐藏下一级菜单
			var pos={};
			//fix hover shader
			var hrt  = menu.children(".hrt");
			var cover = menu.children(".cover");
			if (!_this.position[tid]) {
				var aps = $(this).position();
				var awt = $(this).width();
				var aht = $(this).height();
				//修正位置
				var premnu_w = menu.width();
				var premnu_h = menu.height();
				var nextmenu_w = nextmenu.width();
				var nextmenu_h = nextmenu.height();
				var x_ = aps.left+awt-20;
				var y_ = aps.top;
				//y 
				var ofy_ = (y_+nextmenu_h-premnu_h);
				if (ofy_>80) {
					y_ -=ofy_-60 ;
				}
				//x 
				var ofx_=(x_+nextmenu_w-premnu_w);
				var reserve_x = false;
				if (ofx_>nextmenu_w/2) {
					x_ -= nextmenu_w+awt-30;reserve_x=true;
				}
				pos["nextmenu"] ={
					"left":x_,
					"top":y_
				};
				pos["hrt"] ={
					"left":aps.left+12,
					"top":aps.top+aht+2,
					"width":reserve_x?awt-3:awt-12,"height":2
				};
				pos["cover"] ={
					"left":reserve_x?(aps.left+10):(aps.left+awt-22),
					"top":aps.top+1
				};
				_this.position[tid] = pos;
			}
			else{
				pos = _this.position[tid];
			}
		//	nextmenu.find(".selsubcategory").hide();
			nextmenu.css(pos["nextmenu"]).show();
			hrt.css(pos["hrt"]).show();
			cover.css(pos["cover"]).show();
			_this.UpdateMenuShader(nextmenu);
			$(this).blur();
		}).hover(function(){
			$(this).addClass("hover2")
		},function(){
			$(this).removeClass("hover2");
		});		
	//chkbox
	var __exp=":checkbox[name='chx']"+(_pid?"[pid='"+_pid+"']":"");
	container.find(__exp).click(function(){
		return _this.CheckUpdateStatus($(this));
	});
}
CategoryWindow.prototype.CheckUpdateStatus = function(chkbox){
		var checked=chkbox.attr("checked");	
		var level = parseInt(chkbox.parent().attr("level"));
		var id = chkbox.val();
		if (checked) {
			this.ClearSubChecked(id);//将子类选择项清除
			if (this.GetSelectCount()>=this.maxselcount) {
				this.showOverflowWarning();
				return false;	
			}
		}
		this.UpdateSelectedValue(id,level,!checked);
		this.CheckedLevel(level,id,checked);
		return true;
}
CategoryWindow.prototype.CheckedLevel=function(level,pid,checked){
		var nextmenu = $("#"+this.id+"_level"+level);
		if(!nextmenu.length) return; //没有子菜单。
		this.SetSubChecked(pid,checked);
		nextmenu.find(":checkbox[name='chkcategoryall']").attr("checked",checked);
}
CategoryWindow.prototype.Close = function(){
	var win = $("#"+this.rootmenuid);
	if (win.length) win.hide();
	var id="";
	var text="";
	if (!this.options.mutiplemode) { //单选
		var value = this.root.find("input:checked").val();
		if (value) {
			id = value;
			text = $.trim(this.root.find("input:checked").parent().text());
		}
	}
	else{ //多选
		var ids=[];
		var texts=[];
		this.root.find("a.checkitem").each(function(){
			ids.push($(this).attr("val"));
			texts.push($(this).text());
		})
		id = ids.join(',');
		text = texts.join(',');
	}
	$("#"+this.options.id).val(text==""?"请选择":text);
	$("#"+this.options.valuehandler).val(id);
}
CategoryWindow.prototype.FixSearchPos = function(){
	this.searchdiv = this.root.find(".searchcategorys");
	this.searchdiv.css({left:0,top:62,
	"width":this.root.width(),
	"height":this.root.height()-134});
}
CategoryWindow.prototype.ShowSearchCategory=function(bshow){
	var ht = this.root.height()-134;
	if (bshow){
		if (this.searchdiv.is(":visible")) return;
		//this.CloseLevelWindow();
		//this.searchdiv.css({"top":-ht}).show().animate({top:62},100);
		this.searchdiv.show();
	}else{
		if (this.searchdiv.is(":hidden")) return;
	//	this.searchdiv.css({"top":62}).show().animate({top:-ht},100,function(){
			this.searchdiv.empty().hide();
	//	});
	}
}
CategoryWindow.prototype.UpdateMenuShader =function(menu){
	var bt = menu.children(".bt");
	var rt  = menu.children(".rt");
	bt.css({
		    "left":3,
			"bottom":-3,
			"width":menu.width()-2,
			"height":2
		   }).show();
	rt.css({
		    "right":-3,
			"top":3,
			"height":menu.height()
		 }).show();
}
function selectmenubyid(id){
		var chkbox = prevcategory.root.find("#chx"+id);
		if (!chkbox.length) return;
		if (chkbox.attr("disabled")) return;
		if (prevcategory.options.mutiplemode) {//多选
			chkbox.attr("checked",!chkbox.attr("checked"));
			if(!prevcategory.CheckUpdateStatus(chkbox)){
				chkbox.attr("checked",false);
			}
		}
		else{//单选
			if (chkbox.attr("checked")) return;
			chkbox.attr("checked",!chkbox.attr("checked")).change();
		}
}
CategoryWindow.prototype.CreateLevelWindow= function(level){
	var levelid=this.id+"_level"+level;
	if ($("#"+levelid).length) return;
	var sb = new StringBuilder();
	var _this = this;
	if (level==0) {
		this.rootmenuid = levelid;
		sb.append("<div class=\"stzpjobmenu rootmenu\" id=\""+levelid+"\">");
		sb.append("<div class='searchcategorys'></div>");
		sb.append("  <div class=\"selcaption\" id=\"winhandler\">");
		sb.append("    <h1> <a class=\"sellogo\" style=\"height:56px; width:56px;\"><\/a><span>"+this.options.caption+"<\/span>");
		sb.append("      <div class=\"navs\"><a class=\"selected\" href=\"javascript:void(null)\">"+this.options.label+"<\/a><\/div>");
		sb.append("      <a href=\"javascript:void(null)\" ac='closemain' class=\"alt-x\"><\/a><\/h1>");
		sb.append("    <h2><span class=\"caption\">"+this.options.subcaption[0]+"<font disabled=\"disabled\">(最多不超过"+this.options.maxselcount+"项)<\/font><\/span>");
		if (this.options.searchmode) {
			sb.append("      <div class=\"searchbox\"><a class=\"searchicon\" style='color:red;'>快速定位：<\/a>");
			sb.append("        <input type=\"text\" id=\"scjobkey\" name=\"scjobkey\">");
			sb.append("        <a style=\"margin-top:4px; margin-left:4px;\" class=\"selbtn\" href=\"javascript:void(null)\"  ac='search'>搜&nbsp;索<\/a>");
			sb.append("	   <\/div>");
		}
		sb.append("    <\/h2>");
		sb.append("  <\/div>");
		sb.append("  <div class=\"cover\"><\/div>");
		sb.append("  <div class=\"shader bt\"><\/div>");
		//内容插入区域
		sb.append(" <div class=\"shader hrt\"><\/div>");
		sb.append("  <div class=\"shader rt\"><\/div>");
		sb.append("  <div class=\"maincategorybt\">");
		sb.append("    <div id=\"main_selpath\">");
		sb.append(" <span class=\"greenfont\">已选择：<\/span> <span class=\"selchecks\"> <\/span>");
		sb.append(" <\/div>");
		sb.append("    <div id=\"main_controlband\">");
		if (this.options.mutiplemode) sb.append(" <a id=\"mainclsbtn\" class=\"selbtn\" href=\"javascript:void(null)\" ac='clearselector'>清除选择<\/a> ");
		sb.append(" <a id=\"btn1\" class=\"selbtn\" href=\"javascript:javascript:void(null)\" ac='closemain'>确&nbsp;定<\/a> <a id=\"btn2\" class=\"selbtn\" href=\"javascript:void(null)\" ac='closemain'>关&nbsp;闭<\/a> <\/div>");
		sb.append("  <\/div>");
		sb.append("<\/div>");
		$("BODY").append(sb.toString());
		this.root = $("#"+levelid);
		this.root.easydrag(true).setCenter();
		this.root.bgiframe();
		this.root.find("a.sellogo").bgiframe();
		this.root.find(".selcaption,.maincategorybt").click(function(){
			_this.CloseLevelWindow();
		});
	}
	else{
		sb.append("  <div class=\"stzpjobmenu selsubcategory\" id=\""+levelid+"\" style=\"display:none;\">");
		sb.append("    <div class=\"shader bt\"><\/div>");
		sb.append("    <h1><span class=\"caption\"> "+this.options.subcaption[level]+"<\/span><a class=\"alt-x alt-x2\" href=\"javascript:void(null)\"  ac='closelevel'  level='"+level+"'><\/a><\/h1>");
		//内容插入区域
		sb.append("    <div class=\"subselectall\">");
		sb.append("      <label for=\"chkcategoryall_"+level+"\">");
		sb.append("        <input  type=\"checkbox\" name=\"chkcategoryall\" id=\"chkcategoryall_"+level+"\"\ value='"+levelid+"'/>");
		sb.append("        全选/取消<\/label>");
		sb.append("      <a href=\"javascript:void(null)\" class=\"selbtn\" id=\"subclsbtn\"  ac='closelevel'  level='"+level+"'>关&nbsp;闭<\/a> <\/div>");
		sb.append("    <div class=\"cover\"><\/div>");
		sb.append("    <div class=\"shader hrt\"><\/div>");
		sb.append("    <div class=\"shader rt\"><\/div>");
		sb.append("  <\/div>");
		
		var plevelid = this.id+"_level"+(level-1);
		$("#"+plevelid).children(".rt").after(sb.toString());
		var menu = $("#"+levelid);
		menu.children("h1,.subselectall").click(function(){
			_this.CloseLevelWindow(level+1);
		});
		//全选/取消事件
		this.root.find("#chkcategoryall_"+level).unbind().click(function(e){
			var checked=$(this).attr("checked");
		//	debug(checked);
			var v = $(this).val();
			var pid = $("#"+v).data("pid");
			if (pid!=null) {
				var chkbox=_this.root.find("a.menuitem[tid='"+pid+"']").children(":checkbox:first");
				chkbox.attr("checked",checked);
				if(!_this.CheckUpdateStatus(chkbox)){
					chkbox.attr("checked",false);
					return false;
				}
			}
		//	e.stopPropagation();
		//	return true;
		});
	}
	this.root.find("a[ac]").unbind().click(function(){
		switch($(this).attr("ac")){
			case "closemain": //关闭主窗口
				_this.Close();
				break;
			case "clearselector"://清除选择
				var p= _this.root.find(".selchecks");
					p.children("a").each(function(){
						$(this).click();
					});
				break; 
			case "search"://搜索
				_this.DoSearch(_this.root.find("#scjobkey"));
				break;
			case "closelevel"://关闭子层
				var level = $(this).attr("level");
				_this.CloseLevelWindow(level);
				break;
		}
	});
}
CategoryWindow.prototype.CloseLevelWindow=function(level){
		var premenu =level?$("#"+this.id+"_level"+(level-1)):this.root;
		premenu.find(".stzpjobmenu:visible").find("a.hover").removeClass("hover");
		premenu.find("div.selsubcategory,div.hrt,div.cover").hide();
		premenu.find("a.hover").removeClass("hover");
}
/*
	更新选择值：
	参数：ID,是否删除
*/
CategoryWindow.prototype.UpdateSelectedValue = function(id,level,bdelete){
	var p= this.root.find(".selchecks");
	var idkey="chk_"+id;
	var obj=$("#l_"+idkey);
	if (!bdelete&&obj.length==0) {
		if (p.find("#l_"+idkey).length==0) 
		p.append("<a href='javascript:void(null)' id='l_"+idkey+"' class='checkitem' type='"+level+"' val='"+id+"' >"+this.xml.children("c[id='"+id+"']").text()+"<span class='cc'></span></a>");
	}
	else if (bdelete&&obj.length>0) {
		obj.remove();
	}
	return true;
}
CategoryWindow.prototype.UpdateSingleValue= function(id,bdelete){
		var p= this.root.find(".selchecks");
		p.empty();
		if (!bdelete) {
			p.append("<a href='javascript:void(null)' id='l_"+id+"' class='checkitem'  val='"+id+"' >"+this.xml.children("c[id='"+id+"']").text()+"<span class='cc'></span></a>");
		}
}
CategoryWindow.prototype.DeleteSelectedValue = function(id){
		var idkey="chk_"+id;
		var obj=$("#l_"+idkey);
		obj.remove();//删除子类选择
}
CategoryWindow.prototype.ClearSubChecked=function(pid){
	var _this = this;
	this.xml.children("c[pid='"+pid+"']").each(function(i,n){
		var id =$(this).attr("id");
		_this.DeleteSelectedValue(id);
		if (parseInt($(this).attr("counts"))>0) {
			_this.ClearSubChecked2(id);
			_this.SetSubChecked(id,false);
		}
	});
	this.SetSubChecked(pid,false);
}
CategoryWindow.prototype.SetSubChecked=function(pid,b){
	this.root.find(".selsubcategory:visible").find(":checkbox[name='chx'][pid='"+pid+"']").attr({"checked":b,"disabled":b});
}
CategoryWindow.prototype.ClearSubChecked2=function(pid){
	var _this = this;
	this.xml.children("c[pid='"+pid+"']").each(function(i,n){
			var id =$(this).attr("id");
			_this.DeleteSelectedValue(id);
	});
}
CategoryWindow.prototype.DoSearch = function(sinput){
	var key =$.trim(sinput.val());
	if(key=='') {
		this.ShowSearchCategory(false);
		return;
	}
	this.ShowSearchCategory(true);
	var nodes = this.xml.children("c:contains('"+key+"')");
	var pagesize=24;
	var maxpage = nodes.length%pagesize==0?(nodes.length/pagesize):Math.ceil(nodes.length/pagesize);
	
	var sc = this.searchdiv;
	var _this = this;
	var sb = new StringBuilder();
	sb.append("<div class='stzpjobmenu searchmenu'>");
	sb.append("<div class='scinfo'><span>共有"+nodes.length+"项查询结果:</span><a href='javascript:void(null)'class='hdc'> 关闭搜索结果</a><a class='cc' href='javascript:void(null)'></a>");
	sb.append("</div>");

	nodes.each(function(i,n){
		var id=$(this).attr("id");
		var pid=$(this).attr("pid");
		var type=$(this).attr("type");
		sb.append('<a href="javascript:void(0);" class="menuitem" id="'+id+'" pid="'+pid+'" type="'+type+'" index="'+(i+1)+'" style="display:none;"><input type="checkbox"  value="'+id+'" name="sejob" id="'+id+'" t="'+type+'"><span class="chktext">'+$(this).text().replace(key,"<font>"+key+"</font>")+'</span> </a>');
	});
	if (maxpage>1) 
	sb.append("<div class='pages'><span class='pagetext'>显示更多搜索结果<font>(第<label>1</label>/"+maxpage+"页)</font>：</span>"+GetSelectPages(1,maxpage)+"</div>");
	sb.append("</div><div class='searchmenubg'></div>");
	
	sc.empty().html(sb.toString());
	var scmenu=sc.children(".searchmenu");
	var scinfo = sc.find(".pages");
	scmenu.height(sc.height()-14);
	sc.children(".searchmenubg").height(scmenu.height()+6);
	sc.find("a[index]").slice(0,pagesize).show();

	//binding events 
	sc.find("a.cc,a.hdc").click(function(){
		_this.ShowSearchCategory(false);
	});
	sc.find("a[pageindex]").click(function(){
		var i = $(this).attr("pageindex");
		sc.find("a[index]").hide();
		sc.find("a[index]").slice((i-1)*pagesize,i*pagesize).show();
		scinfo.find("label").text(i);
		scinfo.find("a.selected").removeClass('selected');
		scinfo.find("a:eq("+(i-1)+")").addClass("selected");
	});
	sc.find("a[index]").click(function(i,n){
		var id=$(this).attr("id");
		var type=$(this).attr("type");
		var chkbox =$(this).children(":checkbox");
		var checked = chkbox.attr("checked");
		chkbox.attr("checked",!checked);
		
		var suc = _this.SelectedByID(id,!checked);
	//	debug(suc);
		if (!suc) {
			chkbox.attr("checked",false);
		}
	});
	sc.find(":checkbox").click(function(){
		$(this).blur();
		$(this).attr("checked",!$(this).attr("checked"));
		e.stopPropagation();
		return false;
	});
}
CategoryWindow.prototype.SelectedByID =function(id,b){
		var ochkbox = this.root.find(":checkbox[name='chx'][value='"+id+"']");
		this.SetSubChecked(id,b);
		if (ochkbox.length) {//已存在
			ochkbox.attr("checked",b);
			if (!this.CheckUpdateStatus(ochkbox)) {
				ochkbox.attr("checked",false);
				return false;
			}
		}
		else{//不存在
			if (this.GetSelectCount()>=this.maxselcount&&b) {
				this.showOverflowWarning();
				return false;
			}
			this.UpdateSelectedValue(id,-1,!b);
		}	
		return true;
}
CategoryWindow.prototype.showOverflowWarning =function(){
	alert('最多只能选择'+this.maxselcount+"个项目。");
}
function GetSelectPages(index,maxpage){
	var sb = new StringBuilder();
	for (var i=1; i <=maxpage; i++) {
		sb.append("<a href='javascript:void(null);' pageindex='"+i+"' class='"+(index==i?'selected':'')+"'>"+i+"</a>");
	}
	return sb.toString();
}
function debug(){
	//alert(arguments.length);
		var sb = new StringBuilder();
		for(var i=0;i<arguments.length;i++)
		sb.append("<span>"+arguments[i]+"</span>");
		
		$("#debugdiv").append("<div>"+sb.toString("&nbsp;")+"</div>");
}
