var menus=[];
var settPanel=null;
var App =
	{
	title:null,
	titlePasted:false,
	// array of tabs.
	tabs:new Array(),
	// array of modules constructors
	Module:new Object(),
	// selected tabs
	SelectTab:-1,
	// creating div for mouse control
	TabArea:null,
	rtl:false,
	langs:new Array(),
	loadedModules:Array(),
	errorReporting:true,
	query:null,
	started:false,
	titleObj:
		{
		objName:"title",
		past:function(str,redraw)
			{
			var div = $("pageTitle");
			if(str=="My Homepage")
				str=_(str);
			document.title=str;
			if(redraw==null || !redraw)
				{
				div.innerHTML=str;
				return true;
				}
			else
				div.firstChild.innerHTML=str;
			div.firstChild.onmouseover = function()
				{
				this.style.backgroundColor = "#FAFAFA";
				this.style.border = "1px solid #EEE";
				}
			div.firstChild.onmouseout = function()
				{
				this.style.backgroundColor = "transparent";
				this.style.border = "none";
				}
			div.firstChild.onclick = function() 
				{
				this.onclick = null;
				this.onmouseout();
				this.onmouseover = null;
				var titleValue = this.firstChild.nodeValue;
				var titleWidth = this.offsetWidth;
				this.innerHTML = '<input type="text" class="inputPageTitle" maxlength="80" value="'+titleValue+'" style="width:'+titleWidth+'px"/>';
				var inputElm = this.firstChild;
				inputElm.focus();
				inputElm.select();
				inputElm.onkeydown=function(e)
					{
					if (!Browser.isSafari)
						if ((Browser.isIE && event.keyCode==13) || (!Browser.isIE && e.keyCode==13))
							this.onblur();
					}		
				inputElm.onkeyup = function()
					{
					this.style.width = (this.value.length*9)+20 + "px";
					}
				inputElm.onblur = function() 
					{
					var value = (this.value.trim() == '') ? App.title : this.value;
					if(App.title!=value)
						{
						App.titleObj.past(value,true);
						if(App.titlePasted)
							App.Saver.AddSave(App.titleObj);
						}
					else
						App.titleObj.past(App.title,true);
					}
				}
			App.titlePasted=true;
			App.title=str;
			}
		},
	MyNews:
		{
		myrss:null,
		myfeeds:null,
		rss:[],
		feeds:[],
		add:function(b,feed)
			{
			var to=this.where(feed);
			if(this[to][b.obj.id])
				this.del(b,feed);
			var xml=document.createElement("xml");
			xml.setAttribute("help",b.obj.title);//b.obj.data
			xml.setAttribute("name","rss");
			xml.setAttribute("ico",(b.obj.ico && b.obj.ico!='false' ? b.obj.ico : '') );
			xml.setAttribute("title",b.obj.title);
			xml.setAttribute("data",b.obj.data);

			this[to][b.obj.id]=App.Admin.BuildButton(this["my"+to],xml,1);
			},
		del:function(b,feed)
			{
			var to=this.where(feed);

			if(!this[to][b.obj.id])
				return;

			Element.remove(this[to][b.obj.id]);
			delete this[to][b.obj.id];
			},
		where:function(feed)
			{
			var to="rss";
			if(feed)
				to="feeds";
			return to;
			}
		},
	Admin: 
		{
		Width:9,
		IsOpen:true,
		deleteInfo:function()
			{
			var div = $("navInfosBox");
			div.innerHTML = "";
			div.style.display = "none";	
			},
		BuildButton:function(frame,xml,sub)
			{
			var rootDiv=document.createElement("div");
			rootDiv.className='liLike';
			//??? ?, ? ?? ??
			var itemDiv=document.createElement("div");
			itemDiv.className='itemLineMain';
			itemDiv.style.cursor = "pointer";
			itemDiv.onmouseover=function()
				{
				if((help=this.getAttribute("help")) && help!="")
					{
					var div = $("navInfosBox");
					div.style.display = "block";

					/*var frame = document.createElement("div");
					//frame.className = "frame";
					//var frame2 = document.createElement("div"); //a second div is unnecessary...
					//frame2.className = "frame2";
					//frame2.style.backgroundColor = "#F1FDF3"; //Moved to classes.css
					frame.className = "frame2";
					frame.innerHTML = help; //This is the RSS tooltip...
					//frame2.innerHTML = help;
					div.style.width = frame.style.width;
					//frame.appendChild(frame2);
					div.appendChild(frame);*/
//					div.parent.style.backgroundColor="purple";
					div.innerHTML = "<table class=\"frame2\"><tr><td>"+help+"</td></tr></table>";
					div.style.top = (findPosY(this)-8)+"px";
					div.className="frame2";
					if(!App.rtl)
						div.style.left = eval(App.Admin.Width)-5+"px";
					else
						div.style.left = (Browser.isIE&&!window.opera? ietruebody().clientWidth : window.innerWidth)-App.Admin.Width-div.clientWidth-2+"px";
					}
				this.lastChild.style.color = "#F60";
				this.lastChild.style.borderBottom = "1px solid #F60";
				}
			itemDiv.onmouseout=function()
				{
				this.lastChild.style.color = "#333";
				this.lastChild.style.borderBottom = "1px solid #DDD";
				App.Admin.deleteInfo();
				}

			if(sub)
				itemDiv.className='itemLine';

			help=xml.getAttribute("help");
			if(help && help!="")
				itemDiv.setAttribute("help",help);

			var color = xml.getAttribute("color");
			if(color && color!=''){
				itemDiv.setAttribute("color",color);
			}

			var iconDiv=document.createElement("div");
			iconDiv.className='folderIcon';
			var ico = xml.getAttribute("ico");
			if(ico && ico!=''){
				iconDiv.style.backgroundImage = "url("+ico+")";
			}
			
			

			var textDiv=document.createElement("div");
			textDiv.className='text';

			var div=document.createElement("div");
			div.className='separator';
			moduleName=xml.getAttribute("name");

			var inAdmin=true;

			switch(moduleName)
				{
				case "separator":
				frame.appendChild(div);
				break;
				//
				case "link":
				textDiv.innerHTML=xml.getAttribute("title");
				itemDiv.onclick=function()
					{
					App.Admin.deleteInfo();
					var tmp=xml.getAttribute("href");
					document.location.href=tmp;
					};
				itemDiv.appendChild(iconDiv);
				itemDiv.appendChild(textDiv);
				rootDiv.appendChild(itemDiv);
				frame.appendChild(rootDiv);
				break;
				case "group":
				case "myrss":
				case "myfeeds":
				//
				var img=document.createElement("img");
				img.src='i/showModBlueNav.gif';
				img.className='edit';
				
				var divShow=document.createElement("div");
				divShow.className='showSub';
				
				textDiv.innerHTML=xml.getAttribute("title");
				
				itemDiv.appendChild(divShow);
				itemDiv.appendChild(img);
				itemDiv.appendChild(textDiv);
				
				var obj=xml.getElementsByTagName("mod");
				textDiv.innerHTML = textDiv.innerHTML + ' ('+obj.length+')';
				rootDiv.appendChild(itemDiv);
				var subDiv=document.createElement("div");
				subDiv.className='ulLike';
				if(moduleName!="group")
					{
					App.MyNews[moduleName]=subDiv;
					}
				for(var i=0;i<obj.length;i++)
					{
					this.BuildButton(subDiv,obj[i],1);
					i+=obj[i].getElementsByTagName("mod").length;
					}
				itemDiv.onclick=function()
					{
					App.Modules.DelBox();
					if(this.parentNode.lastChild.style.display=='none')
						this.parentNode.firstChild.firstChild.className='hideSub';
					else
						this.parentNode.firstChild.firstChild.className='showSub';
					ShowOrHide(this.parentNode.lastChild);
					}
				subDiv.style.display='none';
				rootDiv.appendChild(subDiv);
				frame.appendChild(rootDiv);			
				break;
				default:
				//
				itemDiv.setAttribute("data",(xml.firstChild)?xml.firstChild.nodeValue : xml.getAttribute("data"));
				itemDiv.setAttribute("name",moduleName);
				itemDiv.setAttribute("title",xml.getAttribute("title"));
				itemDiv.setAttribute("len",(l=xml.getAttribute("len"))?l:7);
				itemDiv.setAttribute("ico",(l=xml.getAttribute("ico"))?l:false);

				itemDiv.onclick=function()
					{
					var div = document.createElement("div");
					div.style.paddingBottom = "4px";
					div.innerHTML = '<div style="float:right; cursor:pointer"><img src="i/closeMod.gif"/></div>'+
							'<div class="addToPage"><span class="addToPageLinkOut">'+_("Add to my page")+'</span></div>'+
							'<div style="clear:both"></div>';
					div.firstChild.onclick = function()
						{
						App.Modules.DelBox();
						}
					var linkNode = div.firstChild.nextSibling.firstChild;
					linkNode.onmouseover = function()
						{
						this.className = "addToPageLinkOver";
						}
					linkNode.onmouseout = function()
						{
						this.className = "addToPageLinkOut";
						}
					linkNode.onclick=function()
						{
						App.Modules.CreateModul();
						}
					App.Modules.DrawBox(this);
					App.Modules.isClicked=this;
					var pickupZone = $("pickupZone");
					pickupZone.style.paddingTop = "2px";
					pickupZone.appendChild(div);
					App.Modules.AttachToBox(div.lastChild);
					}
				itemDiv.appendChild(iconDiv);
				textDiv.innerHTML=xml.getAttribute("title");
				itemDiv.appendChild(textDiv);
				rootDiv.appendChild(itemDiv);
				frame.appendChild(rootDiv);
				}
			return rootDiv;
			},
		CloseOpen:function()
			{
			if(!this.IsOpen)
				{
				var Width=Math.round(App.Admin.Width/(Browser.isIE&&!window.opera? ietruebody().clientWidth : window.innerWidth)*100);
				if(App.rtl)
					{
					$("nav").style.left=(Browser.isIE&&!window.opera? ietruebody().clientWidth : window.innerWidth)-App.Admin.Width+"px";
					}
				$("selectionTree").style.width=Width+"%";
				if(!App.rtl)
					$("topPart").style.paddingLeft =App.Admin.Width + "px";
				else
					{
					$("modulesArea").parentNode.style.width=100-(App.User.vars['noTabOpt']=="1"? 0 : 18)-Width+"%";
					$("topPart").style.paddingRight=App.Admin.Width + "px";
					}
				$("contentLink").style.display='none';
				$("nav").style.width=App.Admin.Width+"px";
				$("nav").firstChild.style.display = "block";
				this.IsOpen=true;
				}
			else
				{
				if(App.rtl)
					$("topPart").style.paddingRight =0+ "px";
				else
					$("topPart").style.paddingLeft =0+ "px";
				$("modulesArea").parentNode.style.width=100-(App.User.vars['noTabOpt']=="1"? 0 : 18)+"%";
				$("selectionTree").style.width=0+"px";
				$("contentLink").style.display='';
				$("nav").style.width=0+"px";
				$("nav").firstChild.style.display = "none";
				App.Modules.DelBox();
				this.IsOpen=false;			
				}
			},
		Build:function()
			{
			Request.sendGET("menu.php?nocache="+Math.random(),
				function(r)
					{
						if (r.responseText == ''
						    || r.responseXML.documentElement==null
						    || r.responseXML.documentElement.nodeName=="parsererror"
						   )
							{
							alert(_("1Server is down! Or your connection very slowly!"));
							return true;
							}
						//alert(r.responseText);
						var frame2 = document.createElement("div");
						frame2.id = "widgetsList";
						frame2.style.margin = "3px";
						frame2.innerHTML= '<div style="padding: 0 0 5px;height:100%;">'+
									'<div style="float:right;padding:2px;"><img src="i/closeMod.gif" /></div>'+
									'</div>';
						var closeNode = frame2.firstChild.firstChild;
						closeNode.style.cursor = "pointer";
						closeNode.onclick = function()
							{
							App.Admin.CloseOpen();
							}
						xml=r.responseXML.documentElement;
						App.Admin.Width=xml.getAttribute("width");
						var obj=xml.getElementsByTagName("mod");
						for(var i=0;i<obj.length;i++)
							{
							App.Admin.BuildButton(frame2,obj[i]);
							i+=obj[i].getElementsByTagName("mod").length;
							}
						var Area=frame2.firstChild;
						var moduleSelection = document.createElement("div");
						moduleSelection.id = "moduleSelection";
			
						var selectionFrame = document.createElement("div");
						selectionFrame.id = "moduleSelectionFrame";
						selectionFrame.appendChild(frame2);
						moduleSelection.appendChild(selectionFrame);
						$("nav").appendChild(moduleSelection);

						App.Page.loadXML();
					}
			
				)
			}
		},
	User:
		{
		id:null,
		name:false,
		vars:Object(),
		reg:function(r)
			{
			if (r.responseXML.documentElement.nodeName=="ERROR")
				{
				var errorText=r.responseXML.firstChild.firstChild.nodeValue.split("\n").join("<BR/>");
				$("ErrorMsgsignup").innerHTML=errorText;
				}
			else
				{
				App.User.name=r.responseXML.firstChild.getAttribute("login");
				alert(_("Confirmation message was sent."));
				App.stop();
				App.start();
				}
			},
		forgot:function(r)
			{
			if (r.responseText == ''
			    || r.responseXML.documentElement==null
			   )
				alert("????? ???! ??? ??????!");
			else
				{
				var errorText=r.responseXML.firstChild.firstChild.nodeValue.split("\n").join("");
				alert(errorText);
				//App.Page.showOtherInformation('recoverpwdDiv','signinDiv');
				}
			},
		login:function(r)
			{
				
			if (r.responseXML.documentElement.nodeName=="ERROR")
				{
			
				var errorText=r.responseXML.firstChild.firstChild.nodeValue.split("\n").join("<BR>");
				if(errorText.length > 0)
					$("ErrorMsgsignin").innerHTML=errorText;
			}
			else
			{
				 
				App.updateAll();
			}
			}
		},
	Modules:
		{
		isClicked:null,
		moduleTempObj:null,
		conteiner:null,
		numCol:3,
		Dragging:false,
		DelBox:function()
			{
			var div = $("navModuleBox");
			div.innerHTML = "";
			div.style.display = "none";
			this.isClicked=null;
			},
		DrawBox:function(node)
			{
			this.DelBox();
			App.Admin.deleteInfo();
			var div = $("navModuleBox");
			div.style.width = "350px";
			div.style.display = "block";
			if(!App.rtl)
				div.style.left = (App.Admin.Width-2)+"px";
			else
				div.style.left = (Browser.isIE&&!window.opera? ietruebody().clientWidth : window.innerWidth)-App.Admin.Width-353+"px";
			div.style.top = (findPosY(node)-12)+"px";
			var frame = document.createElement("div");
			frame.className = "frame";

			var frame2 = document.createElement("div");
			frame2.className = "frame2";
			frame2.id = "pickupZone";

			frame.appendChild(frame2);
			div.appendChild(frame);
			},
		AttachToBox:function(node)
			{
			this.conteiner=node;
			this.moduleTempObj=new Modul(this.isClicked);
			this.conteiner.appendChild(this.moduleTempObj.divs.module);
			},
		CreateModul:function(col)
			{
			if(!col)
				col=1;
			App.columns["col"+col].insertBefore(this.conteiner.firstChild,App.columns["col"+col].firstChild);
			this.moduleTempObj.AdminMode=false;
			this.moduleTempObj.ConvertBox();
			App.tabs[App.SelectTab].modules.push(this.moduleTempObj);
			App.Saver.AddSave(this.moduleTempObj,'add');
			this.moduleTempObj=null;

			App.updateColumnLayout();
			this.DelBox();
			},
		PreloadOk:function(del)
			{
			if(del!='no')
				App.Page.PreloadModules.splice(0,1);
			if(App.Page.PreloadModules.length==0)
				{
					
				//App.tabs.first().Select();
				App.tabs.first().Select();
				
				if(App.User.name!=false)
					App.Page.genLogoutLink();
				else
					App.Page.genLoginLink();

				App.displayApp();
				App.Admin.CloseOpen();
				ShowOrHide($("nav"));
				App.Admin.CloseOpen();
				App.Page.loadModuleContext();
				return;
				}
			var current=App.Page.PreloadModules.first();
			App.tabs[current.getAttribute("tabNum")].modules.push(new Modul(current,App.Modules.PreloadOk));
			},
		Collapse:function()
			{
			mods=App.tabs[App.SelectTab].modules;
			for(i=0;i<mods.length;i++)
				if(mods[i].status==1)
					mods[i].showhide(1);
			},
		Expand:function()
			{
			mods=App.tabs[App.SelectTab].modules;
			for(i=0;i<mods.length;i++)
				if(mods[i].status==0)
					mods[i].showhide(1);
			}
		},
	Page:
		{
		PreloadModules:new Array(),
		loadXML:function()
			{
			/////////////////////////////////////////////////////
			//alert("before getUserData");
			Request.sendGET("getUserData.php?nocache="+Math.random(),
				function(r)
					{
					if (r.responseText == ''
					    || r.responseXML.documentElement==null
					    || r.responseXML.documentElement.nodeName=="parsererror"
					   )
						{
						alert(_("2Server is down! Or your connection very slowly!"));
						return true;
						}
					//alert(r.responseText);
					var root=r.responseXML.documentElement;
					App.titleObj.past(root.getElementsByTagName("title")[0].firstChild.nodeValue,true);
					if(root.getElementsByTagName("user").length)
						App.User.name=root.getElementsByTagName("user")[0].firstChild.nodeValue;
					var tabs=root.getElementsByTagName("tabs")[0].firstChild;
					var tabNum=0;
					// "Sibling"  - brother/sister
					for(xml=tabs;xml!=null;xml=xml.nextSibling)
						{
						//alert("Running tab!");
						AddTab(xml.getAttribute("id"),xml.getAttribute("title"));
						var mods=xml.getElementsByTagName("mod");
						for(i=0;i<mods.length;i++)
							{
							var mod=mods[i];
							if(!lastCol || lastCol!=mod.getAttribute("col"))
								pos=0;
							var lastCol=mod.getAttribute("col");
							var att=document.createElement("div");
							att.setAttribute("tabNum",tabNum);
							att.setAttribute("id",mod.getAttribute("id"));
							att.setAttribute("name",mod.getAttribute("name"));
							att.setAttribute("ico",mod.getAttribute("ico"));
							att.setAttribute("title",mod.getAttribute("title"));
							att.setAttribute("col",mod.getAttribute("col"));
							att.setAttribute("len",mod.getAttribute("len"));
							att.setAttribute("data",(mod.firstChild)?mod.firstChild.nodeValue : "");
							att.setAttribute("collapse",mod.getAttribute("collapse"));
							att.setAttribute("color",mod.getAttribute("color") || "");
							att.setAttribute("position",pos);
							App.Page.PreloadModules.push(att);
							pos++;
							}
						delete lastCol;
						tabNum++;
						}
					App.Modules.PreloadOk('no');
					}
				);
			},
		loadModuleContext:function()
			{
			for(var i=0;i<App.loadedModules.length;i++)
				{
				var mod=App.loadedModules[i];
				if(typeof mod == "object" && mod.name && App.Module[mod.name] && App.Module[mod.name]!=undefined)
					mod.builder= new App.Module[mod.name](mod);
				delete App.loadedModules[i];
				}
			if(App.User.vars['hideSearchOpt']!="1")
				SearchInt.create();
			App.started=true;
			},
		genLoginLink:function()
			{
			$("userProfileWrapper").style.display='none';
			var obj=$("signInOutLink");
			obj.innerHTML=_("signIn");
			if(!App.rtl)
				obj.style.background="url(i/signin.gif) no-repeat 0 0;";
			else
				obj.style.padding="0px";
			obj.onclick=function()
				{
				App.Page.showSiteInformation(this.getAttribute("page"),this);
				}
			},
		genLogoutLink:function()
			{
			var obj=$("userProfileWrapper");
			obj.style.display='';

			var obj=$("userProfile");
			obj.innerHTML=App.User.name;
			obj.href="ecosystem.php?page_type=profile";
			obj.target="_blank";

			var obj=$("signInOutLink");
			obj.innerHTML=_("signOut");
			obj.onclick=function()
				{
				if(!window.confirm(_("Changes after the logout will not be saved. Continue anyway?")) )
					return false;
				return true;
				};
			if(!App.rtl)
				obj.style.background="url(i/signout.gif) no-repeat 0 0;";
			else
				obj.style.padding="0px";
			obj.href="?action=logout";
			},
		// Hides one object, show another
		showOtherInformation:function(hide,show)
			{
			$(hide).style.display='none';
			if($(show))
				$(show).style.display='';
			else if(App.errorReporting)
				alert(show+ " Not FOUND!");
			},
		onSubmitInformation:function(obj)
			{
			var inputs=obj.getElementsByTagName("input");
			var str="?";
			for(var i=0;i<inputs.length;i++)
				{
				if(inputs[i].type=="submit" || inputs.type=="button")
					continue;
				if(inputs[i].type=="checkbox" && !inputs[i].checked)
					continue;
				if(i!=0)
					str+="&";
				
				str+=inputs[i].name+"="+encodeURIComponent(inputs[i].value);
				}
			if(obj.name)
				str+=(str==""?"?":"&")+"action="+encodeURIComponent(obj.name);
			str+=(str==""?"?":"&")+"rand="+Math.random();
			
			Request.sendGET(obj.getAttribute("page")+str,App.User[obj.name])
			},
		showSiteInformation:function(page,obj)
			{
			function display(r)
				{
				var content=$("siteInformation").lastChild;
				content.innerHTML = r.responseText;
				var forms=content.getElementsByTagName("form");
				for(var i=0;i<forms.length;i++)
					{
					forms[i].onsubmit=function()
						{
						App.Page.onSubmitInformation(this);
						objs=this.getElementsByTagName("div");
						for(var k=0;k<objs.length;k++)
							if(objs[k].id.substr(0,8)=="ErrorMsg")
								objs[k].innerHTML="Loading...";
						return false;
						}
					forms[i].setAttribute("page",obj.getAttribute("page"));
					}
				}
				 
			$("application").style.display='none';
			if(App.Admin.IsOpen)
				App.Admin.CloseOpen();
			$("footer").style.display='none';
			var obj=$("siteInformation");
			obj.style.display = "block";
			obj.innerHTML='<BR><BR><div style="margin-bottom:20px;text-align:center"><a id="backToPage" href="javascript:App.Page.hideSiteInformation()"><< '+_("Back to my page")+'</a></div>'+
						'<div id="siteInformationFrame">'+_("Loading ...")+'</div>';
	
			obj.setAttribute("page",page);
			Request.sendGET(page+"?rand="+Math.random(),display);
			
			},
		hideSiteInformation:function()
			{
			
			obj=$("siteInformation");
			obj.style.display = "none";
			$("footer").style.display='block';
			$("application").style.display='block';
			}
		},
	start:function()
		{
		$("addContentLink").innerHTML = _("Add content");
		// 9.1.07
		$("collapseAllLink").innerHTML = _("Collapse all");

		$("settingsLink").innerHTML=_("Settings");
		$("settingsLink").onclick=function()
			{
			SettPanel.open();
			}
		$("expandAllLink").innerHTML = _("Expand all");
		$("aNewTab").innerHTML=_("New Tab");
		App.TabArea=$("Tabs");
		var container = $("modulesArea");
		var columns = document.createElement("div");
		App.columns = {};
		columns.id = "columns";

		App.Modules.numCol=App.User.vars['countRowsOpt'];
		
		for(var i=1;i<=App.Modules.numCol;i++)
			{
			var div = document.createElement("div");
			div.style.minHeight = "1px";
			div.className = "divColonne";
			div.setAttribute("colNum", i);
			App.columns["col"+i] = div;
			columns.appendChild(div);
			}

		container.appendChild(columns);
		App.User.id=getCookie("uid");
		if(App.rtl)
			{
			var obj=$("contentLink");
			obj.parentNode.style.textAlign="right";
			obj=$("addContentLink");
			obj.parentNode.className="addLink2";
			obj=$("collapseAllLink");
			obj.parentNode.style.textAlign="left";
			}

		App.Admin.Build();

		if(App.User.vars['noTabOpt']=="1")
			{
			var divTab=$("divTabs");
			if(App.rtl && divTab.parentElement)
				divTab.parentElement.style.width="0%";
			divTab.style.display="none";
			}

		},
	stop:function()
		{
		$("modulesArea").innerHTML="";
		$("Tabs").innerHTML="";
		$("startMsg").style.display='';
		$("globalSearch").innerHTML="";
		$("application").style.display='none';
		$("siteInformation").style.display='none';
		$("footer").style.display='block';
		$("nav").innerHTML="";
		App.tabs=new Array();

		App.MyNews.myrss=null;
		App.MyNews.myfeeds=null;
		App.MyNews.rss=[];
		App.MyNews.feeds=[];

		App.Admin.IsOpen=true;
		var divTab=$("divTabs");
		divTab.style.display="block";

		if(App.rtl && divTab.parentElement)
			divTab.parentElement.style.width="18%";
		ShowOrHide($("nav"));
		App.title=null;

		if(SearchInt)
			SearchInt.destroy();
		if(SettPanel)
			SettPanel.destroy();
		App.started=false;
		App.titlePasted=false;

		},
	restart : function()
		{
		App.stop();
		App.start();
		},
	updateAll : function()
		{
		document.location.href="/?"+Math.random();
		},
	displayApp:function()
		{
		App.updateColumnLayout();
		SettPanel=new SettingsPanel();
		ShowOrHide($("startMsg"));
		ShowOrHide($("application"));
		}
	}
function Tab()
	{
	var self = this;
	this.id=arguments[0];
	this.modules=new Array();
	this.DrawModules=false;
	this.title=null;
	this.proto=null;
	this.objName="tab";
	this.buttons=null;
	this.selected=false;
	//?reating the main container, into which everything loads
	this.li=document.createElement("li");
	//this.li.style.width="150px";
	//?reating button for tab closure
	this.close=document.createElement("img");
	this.close.src='i/closeTab.gif';
	this.close.style.display='none';
	this.close.onclick=function()
		{
		if(App.tabs.length==1)
			{
			alert(_("This tab could not delete. This tab is single!")); 
			return;
			}
		if(confirm(_("We realy delete this?")))
			{
			self.Remove();
			App.Saver.AddSave(self,'del');
			}
		}

	//?ename tab button
	this.options=document.createElement("img");
	this.options.src='i/tabEdit.gif';
	this.options.style.display='none';
	this.options.onclick=function()
		{
		self.PastText();
		}
	this.options.className='options';
	this.close.className='close';

	//create spacer
	this.spacer=document.createElement("img");
	this.spacer.src='i/s.gif';
	this.spacer.className='spacer';
	this.spacer.style.display='none';

	///////////
	this.span=document.createElement("span");
	this.span.className='';
	this.span.innerHTML='';

	//////
	//?eate navigation for tabs
	this.tabLeft=document.createElement("img");
	this.tabRight=document.createElement("img");
	if(App.rtl)
		{
		this.tabLeft.src='i/tabUp.gif';
		this.tabRight.src='i/tabDown.gif';
		}
	else
		{
		this.tabLeft.src='i/tabLeft.gif';
		this.tabRight.src='i/tabRight.gif';
		}
	this.tabLeft.className='tableft';
	this.tabRight.className='tabright';
	this.tabRight.style.display='none';
	this.tabLeft.style.display='none';
	this.tabLeft.onclick=function(){self.Repick(-1);};
	this.tabRight.onclick=function(){self.Repick(1);};
	this.Select=function()
		{
		if(self.selected)
			return true;
		if(App.SelectTab!=-1 && App.tabs[App.SelectTab])
			{
			var lastTab=App.tabs[App.SelectTab];
			
			lastTab.li.className='';
			lastTab.options.style.display='none';
			lastTab.close.style.display='none';
			lastTab.spacer.style.display='none';
			lastTab.tabLeft.style.display='none';
			lastTab.tabRight.style.display='none';
			lastTab.selected=false;
			for(var i=0;i<lastTab.modules.length;i++)
				lastTab.modules[i].divs.module.style.display='none';
			}
		App.SelectTab=App.tabs.indexOf(self);
		self.selected=true;
		self.li.className='selected';
		self.options.style.display='';
		self.close.style.display='';
		self.spacer.style.display='';

		self.tabLeft.style.display='';
		self.tabRight.style.display='';

		self.Repick(0);

		if(!this.DrawModules)
			{
			for(var i=0;i<this.modules.length;i++)
				this.modules[i].AddModule();
			this.DrawModules=true;
			}
		else
			{
			for(var i=0;i<this.modules.length;i++)
				this.modules[i].divs.module.style.display='block';
			}
		};
	this.Remove=function()
		{
		App.TabArea.removeChild(self.li);
		for(var i=0;i<this.modules.length;i++)
			Element.remove(this.modules[i].divs.module);
		App.tabs.splice(App.tabs.indexOf(self),1);
		if(this.title!=null)
			App.tabs.first().Select();
		};
	this.Create=function()
		{
		self.li.onclick=null;
		self.li.className='';
		App.TabArea.appendChild(self.li);
		}
	this.PastText=function()
		{
		self.li.innerHTML="<input type='text' maxlength='20' value='"+(self.title!=undefined?self.title:'')+"'/>";
		obj=self.li.firstChild;
		obj.focus();
		obj.select();
		obj.onkeydown=function(e)
			{
			if (!Browser.isSafari)
				if ((Browser.isIE && event.keyCode==13) || (!Browser.isIE && e.keyCode==13))
					this.onblur();
			}
		obj.onblur=function()
			{
			if(this.value.trim()=="")
				{
				if(self.title==null)
					self.Remove();
				else
					{
					self.PastTitle(self.title);
					self.Select();
					}
				}
			else
				{
				self.PastTitle(this.value,1);
				self.li.onclick();
				}
			}
		}
	this.Repick=function(num)
		{
		for(var i=App.TabArea.firstChild;i!=null;i=i.nextSibling)
			{
			if(i==self.li)
				{
				if(num==-1 && i.previousSibling)
					{
					App.TabArea.insertBefore(this.li,i.previousSibling);
					self.Repick(0);
					}
				else if(num==1 && i.nextSibling)
					{
					App.TabArea.insertBefore(this.li,i.nextSibling.nextSibling);
					self.Repick(0);
					}
				else if(num==0)
					{
					if(!i.previousSibling)
						self.tabLeft.style.display='none';
					else
						self.tabLeft.style.display='';
					if(!i.nextSibling)
						self.tabRight.style.display='none';
					else
						self.tabRight.style.display='';
					return false;
					}
				else 
					return false;
				this.posChange=num;
				App.Saver.AddSave(this,'pos');
				break;
				}
			}
		}
	this.PastTitle=function(value,save)
		{
		self.li.innerHTML="";
		self.li.onclick=function()
			{
			self.Select();
			}
		self.span.innerHTML=value;
		self.li.appendChild(self.span);
		self.li.appendChild(self.spacer);
		self.li.appendChild(self.close);
		self.li.appendChild(self.options);
		self.li.appendChild(this.tabLeft);
		self.li.appendChild(this.tabRight);
		self.title=value;
		if(save=="1")
			App.Saver.AddSave(this,'add');
		}
	function build()
		{
		self.Create();
		}
	build();
	}
function AddTab(i,title,save)
	{
	if(typeof i == "undefined")
		i=App.genUniqValue();
	var t=new Tab(i);
	App.tabs.push(t);
	if(typeof title=="undefined")
		t.PastText();
	else
		t.PastTitle(title,save);
	return t;
	}
var moduleGhost = document.createElement("div");
moduleGhost.id = "moduleGhost";
function Modul(xml,preload)
	{
	var self=this;
	this.col=1;
	this.tab=1;
	this.position=0;
	this.AdminMode=true;
	this.divs=new Object();
	this.status=1;
	this.objName="modul";
	this.ico=false;
	this.title="";
	this.loaded=false;
	this.name='rss'
	this.builder=null;
	this.color="";
	this.collapse
	this.refreshMode=false;
	this.editMode	=true;
	this.callback=preload;
	this.saved=false;
	this.collnextSave=true;
	if(xml)
		{
		this.id=xml.getAttribute("id") || App.genUniqValue();
		this.name=xml.getAttribute("name");
		this.title=xml.getAttribute("title") || "";
		this.ico=xml.getAttribute("ico");
		this.len=xml.getAttribute("len") || 7;
		this.data=xml.getAttribute("data") || "";
		this.col=xml.getAttribute("col") || 1;
		this.tab=xml.getAttribute("tabNum") || 0;
		var color=xml.getAttribute("color");
		this.color=(!color || color=="") ? "#EFF5FF":color;
		this.status=xml.getAttribute("collapse")=="1" ? 0:1;
		this.tab=xml.getAttribute("tabNum");
		this.position=xml.getAttribute("position") || 0;
		}
	function buildDivs()
		{
		var divModule = document.createElement("div");
		self.divs.module = divModule;
		divModule.className = "module";
		divModule.style.display ='block';
		divModule.obj=this;
		var divModuleFrame = document.createElement("div");
		self.divs.moduleFrame = divModuleFrame;
		divModuleFrame.className = "moduleFrame";

		var divModuleHeader = document.createElement("div");
		self.divs.moduleHeader = divModuleHeader;
		divModuleHeader.className = "moduleHeader";
		divModuleHeader.style.cursor = "default";
		divModuleHeader.style.backgroundColor=self.color;
		divModuleHeader.onmouseover = function()
			{
			self.highlight();
			}
		divModuleHeader.onmouseout = function()
			{
			self.unHighlight();
			}

		var divShowHide = document.createElement("div");
		self.divs.showHide = divShowHide;
		divShowHide.className = "showHide";
		divShowHide.innerHTML = (self.status==0) ? '<img src="i/showMod.gif"/>' : '<img src="i/hideMod.gif"/>';
		divShowHide.style.visibility = "hidden";
		Event.observe(divShowHide, 'mousedown',function(e){e.cancelBubble = true;self.showhide()}, false);

		var divTitle = document.createElement("div");
		self.divs.title = divTitle;
		divTitle.className = "title";
		divTitle.appendChild(document.createTextNode(self.title));	
		divTitle.style.backgroundRepeat ="no-repeat";
		divTitle.style.backgroundPosition = "3px 2px";

		var divIco = document.createElement("div");
		self.divs.ico = divIco;
		divIco.className = "ico";
		if(self.ico && self.ico!="false")
			{
			divIco.innerHTML = '<img width="16" height="16" src="'+self.ico+'" class="hicon" />';
			if (!Browser.isOpera)
				divIco.firstChild.style.display = "none";
			divIco.firstChild.onload = function()
				{
				this.style.display = "block";
				}
			}
		var divClose = document.createElement("div");
		self.divs.close = divClose;
		divClose.className = "close";
		divClose.innerHTML = '<img src="i/closeMod.gif" title="'+_("Close")+'"/>';
		divClose.style.display='none';
		Event.observe(divClose, 'mousedown',function(e){e.cancelBubble = true;self.close()}, false);
		var divRefresh = document.createElement("div");
		self.divs.refresh = divRefresh;
		divRefresh.className = "refresh";
		divRefresh.innerHTML = '<img src="i/refresh.gif" title="'+_("Refresh")+'"/>';
		divRefresh.style.display = "none";
		Event.observe(divRefresh, 'mousedown',function(e){e.cancelBubble = true;self.refresh()}, false);

		var divEdit = document.createElement("div");
		divEdit.className = "edit";
		
		// This code segment represents 'edit' button	//	//	//	//
		//alert ("self.title = " + self.title + ", toLowerCase" + self.title.toLowerCase());
		if (self.title.toLowerCase() == 'popmail' ||
			self.title.toLowerCase() == 'hotmail' ||
			self.title.toLowerCase() == 'yahoo!' ||
			self.title.toLowerCase() == 'aol' ||
			self.title.toLowerCase() == 'gmail')
		{
			divEdit.innerHTML = '<a href="javascript:void(0);">'+_("Close Edit")+'</a>';
			divEdit.style.display = "none";
			self.divs.edit=divEdit;
			Event.observe(divEdit, 'mousedown',self.closeEdit, false);			
		} else {
			divEdit.innerHTML = '<a href="javascript:void(0);">'+_("Edit")+'</a>';
			divEdit.style.display = "none";
			self.divs.edit=divEdit;
			Event.observe(divEdit, 'mousedown',self.edit, false);
		}
		//	//	//	//	//	//	//	//	//	//	//	//	//

		var divEditContent = document.createElement("div");
		self.divs.editContent = divEditContent;
		divEditContent.className = "editContent";

		var divModuleContent = document.createElement("div");
		self.divs.moduleContent = divModuleContent;
		divModuleContent.className = "moduleContent";
		divModuleContent.innerHTML = _("Loading ...");
		if (self.status==0) divModuleContent.style.display = "none";
		//?ssembling...
		divModuleHeader.appendChild(divShowHide);
		divModuleHeader.appendChild(divClose);
		divModuleHeader.appendChild(divEdit);
		divModuleHeader.appendChild(divRefresh);
		divModuleHeader.appendChild(divIco);
		divModuleHeader.appendChild(divTitle);

		divModuleFrame.appendChild(divModuleHeader);
		divModuleFrame.appendChild(divEditContent);
		divModuleFrame.appendChild(divModuleContent);

		divModule.appendChild(divModuleFrame);
		self.load();
		Drag.init(self.divs.moduleHeader,self.divs.module);
		};
	this.highlight = function()
		{
		if(!this.AdminMode)
			{
			this.divs.showHide.style.visibility = "visible";
			this.divs.showHide.style.width = "40px";
			this.divs.ico.style.display = "none";
			this.divs.close.style.display = "block";
			if (this.refreshMode) this.divs.refresh.style.display = "block";
			}
		if (this.loaded && this.editMode) this.divs.edit.style.display = "block";
		}
	this.unHighlight = function()
		{
		if (!this.AdminMode)
			{
			this.divs.moduleFrame.style.border = "1px solid #79A7E2";
			this.divs.showHide.style.visibility = "hidden";
			this.divs.showHide.style.width = 0;
			this.divs.ico.style.display = "block";
			this.divs.close.style.display = "none";
			this.divs.refresh.style.display = "none";
			this.divs.edit.style.display = "none";
			}
		}
	this.refresh=function()
		{
		this.builder.refresh();
		}
	this.load=function()
		{
		if(App.Module[self.name])
			{
			this.onLoad();
			return false;
			}
		var path='modules/'+self.name+'/index.js?'+Math.random();
		if (Browser.isSafari)
			{
			function onscriptload(response)
				{
				eval(response.responseText);
				self.onLoad();
				}
			Request.sendGET(path, onscriptload);
			}
		else
			{
			var oHead = document.getElementsByTagName("head")[0];
			var oScript = document.createElement('script');
			oScript.setAttribute('src', path);
			oScript.setAttribute('type', 'text/javascript');
			if (Browser.isFirefox)
				{
				oScript.onload = function()
					{
					if (typeof App.Module[self.name] != "function")
						return false;
					self.onLoad();
					}
				oHead.appendChild(oScript);
				}
			else
				{
				oHead.appendChild(oScript);
				waitForExistence();
				}
			}
		function waitForExistence()
			{
			if (App.Module[self.name])
				self.onLoad();
			else
				setTimeout(waitForExistence,100);
			}
		}
	this.onLoad=function()
		{
		if(App.started)
			this.builder=new App.Module[this.name](self);
		else
			App.loadedModules.push(this);
		if(typeof this.callback!="undefined")
			setTimeout(this.callback,100);
		this.loaded=true;
		}
	this.onLoadContext=function()
		{
		this.refreshMode=true;
		}
	this.close=function(noconfirm)
		{
		if(!noconfirm && !window.confirm(_('Are you sure you want to close this')+' '+ this.title + '?'))
			return;

		if(this.builder && typeof this.builder.onClose=="function")
			this.builder.onClose();

		for(i in App.tabs[App.SelectTab].modules)
			if(App.tabs[App.SelectTab].modules[i]==self)
				{
				Element.remove(this.divs.module);
				App.tabs[App.SelectTab].modules.splice(i,1);
				break;
				}
		App.Saver.AddSave(self,"del");
			
		delete self;
		}
	this.hide	=	function()
		{
		this.divs.showHide.innerHTML='<img src="i/showMod.gif"/>';
		this.divs.moduleContent.style.display='none';
		this.status=0;
		}
	this.show	=	function()
		{
		this.divs.showHide.innerHTML='<img src="i/hideMod.gif"/>';
		this.divs.moduleContent.style.display='';
		this.status=1;
		}
	this.showhide=function(nosave)
		{
		if(this.divs.moduleContent.style.display=='none')
			{
			self.show();
			}
		else
			{
			self.hide();
			}
		if(this.collnextSave && nosave!=1)
			{
			if(!this.saved)
				App.Saver.AddSave(self,"collapse");
			else
				this.saved=false;
			}
		else
			this.saved=true;
		this.collnextSave=true;
		}
	this.edit=function(e)
		{
		edit=self.divs.edit;
		e.cancelBubble = true;
		if(self.builder.onEdit)
			self.builder.onEdit();
		editModule=self.divs.editContent;
		edit.innerHTML='<a href="javascript:void(0);">'+_("Close Edit")+'</a>'
		editModule.style.display='block';
		Event.stopObserving(edit, 'mousedown', self.edit, false);
		Event.observe(edit, 'mousedown',self.closeEdit, false);
		}
	this.closeEdit=function(e)
		{
		e.cancelBubble = true;
		if(self.builder.onCloseEdit)
			self.builder.onCloseEdit();
		editModule=self.divs.editContent;
		edit=self.divs.edit;
		edit.innerHTML='<a href="javascript:void(0);">'+_("Edit")+'</a>';
		editModule.style.display='none';
		Event.stopObserving(edit, 'mousedown', self.closeEdit, false);
		Event.observe(edit, 'mousedown',self.edit, false);
		}
	this.AddModule=function()
		{
		this.ConvertBox();
		this.divs.module.style.display='block';	
		if(this.col>App.Modules.numCol)
			{
			this.close(1);
			return;
			}	
		App.columns['col'+this.col].appendChild(this.divs.module);
		//FIX IE BUG
		if(Browser.isIE)
			{
			var inp=this.divs.moduleContent.getElementsByTagName("input");
			for(var i=0;i<inp.length;i++)
				if(inp[i].type=="checkbox" && inp[i].getAttribute("check"))
					{
					inp[i].checked=false;
					inp[i].checked=true;
					}
			}
		}
	this.ConvertBox=function()
		{
		this.divs.moduleHeader.style.cursor="move";
		divModule=this.divs.module;
		divModule.onDragStart = function(x,y,mousex, mousey)
			{
			var left = findPosX(this);
			var top = findPosY(this);
			var w = this.offsetWidth;
			this.style.width = (w-5)+"px";
			this.style.left = (left-5)+"px";
			this.style.top = (top-4)+"px";
			this.parentNode.insertBefore(moduleGhost, this);
			this.style.position = "absolute";
			this.isDragging = true;
			moduleGhost.col=this.parentNode;
			moduleGhost.style.height = this.offsetHeight+"px";
			App.Modules.Dragging=true;
			this.col1X = findPosX(App.columns.col1);
			if (App.Modules.numCol>=2) this.col2X = findPosX(App.columns.col2);
			if (App.Modules.numCol>=3) this.col3X = findPosX(App.columns.col3);
			moduleGhost.style.display = "block";
			}
		divModule.onDrag = function(x,y, mousex, mousey)
			{
			if ((x+this.offsetWidth/2)>=this.col1X) col=App.columns.col1;
			if (App.Modules.numCol>=2) if ((x+this.offsetWidth/2)>=this.col2X) col=App.columns.col2;
			if (App.Modules.numCol>=3) if ((x+this.offsetWidth/2)>=this.col3X) col=App.columns.col3;

			if (!moduleGhost.parentNode && moduleGhost.col)
				{
				moduleGhost.col.appendChild(moduleGhost);
				}

			if (moduleGhost.col!=col)
				{
				$("moduleGhost").parentNode.removeChild($("moduleGhost"));
				moduleGhost.col = col;
				col.appendChild(moduleGhost);
				}
			var elems = App.getModuleArr(col);
			var myPos = App.getGhostPos(elems, y);
			if (myPos!=0 && y<=findPosY(elems[myPos-1]))
				{
				$("moduleGhost").parentNode.removeChild($("moduleGhost"));
				col.insertBefore(moduleGhost, elems[myPos-1]);
				}
			if (myPos!=(elems.length-1) && y>=findPosY(elems[myPos+1]))
				{
				if (elems[myPos+2])
					col.insertBefore(moduleGhost, elems[myPos+2]);
				else
					col.appendChild(moduleGhost);
				}
			}
		divModule.onDragEnd = function(x,y,el)
			{
			this.isDragging = false;
			var op = 100;
			this.style.opacity = op/100;
			this.style.filter = 'alpha(opacity=' + op + ')';
			
			self.unHighlight();
			var tempcol = moduleGhost.col.getAttribute("colNum");
			saveCol=false;
			if(tempcol!=self.col)
				var saveCol=true;
			self.col=tempcol;
			var col = moduleGhost.col;
			if (!moduleGhost.parentNode)
				{
				moduleGhost.col.appendChild(moduleGhost);
				}
			var k=0;
			for(i=col.firstChild;i!=null;i=i.nextSibling)
				{
				if(i.style.display=='none')
					continue;
				if(i==moduleGhost)
					break;
				k++;
				}
			if(saveCol || self.position!=k)
				{
				if(self.position<k && !saveCol)
					k--;
				self.position=k;
				App.Saver.AddSave(self,'repos');
				}
			col.insertBefore(this, moduleGhost);
			$("moduleGhost").parentNode.removeChild($("moduleGhost"));
			
			this.style.position = "static";
			this.style.width = "auto";
			App.Modules.Dragging=false;
			}
		if(this.builder && typeof this.builder.onCloseAdminMode=="function")
			this.builder.onCloseAdminMode();
		this.AdminMode=false;
		}
	buildDivs();
	}
App.genUniqValue=function()
	{
	uniq=Math.floor(Number(Math.random())*1000000);
	return uniq;
	}
App.updateColumnLayout = function()
	{
	var width=99;
	var value = (Browser.isIE) ? Math.round(width/App.Modules.numCol-0.1) : Math.round(width/App.Modules.numCol);
	for(var i=1;i<=App.Modules.numCol;i++)
		{
		App.columns["col"+i].style.width=value + "%";
		}
	}
App.getModuleArr = function(column) {
	var arr = [];
	var ln = column.childNodes.length;
	for (var z=0; z<ln; z++) {
		if (!column.childNodes[z].obj && column.childNodes[z] != moduleGhost || column.style.display=='none') {
			continue;
		};
		if (!column.childNodes[z].isDragging)  {
			arr.push(column.childNodes[z]);
		}
	}
	return arr;
}
App.getGhostPos = function(arr, y) {
	var ln = arr.length;
	for (var z=0; z<ln; z++) {
		if (arr[z]==moduleGhost) return z;
	}
}
function $()
	{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++)
		{
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
		}
	return elements;
	}
function _(str)
	{
	//alert(LANG[str.toLowerCase()]);
	if(LANG[str.toLowerCase()])
		return LANG[str.toLowerCase()];
	return str;
	}
function ShowOrHide(obj)
	{
	if(obj.style.display=='none')
		obj.style.display='';
	else
		obj.style.display='none';
	}
App.Saver=
	{
	SaveArr:new Array(),
	LastReq:null,
	AddSave:function(el,mode,func)
		{
		//alert ("element=" + el.objName);
		var str="element="+el.objName+"&";
		switch(el.objName)
			{
			case "title":
			str+="value="+encodeURIComponent(App.title);
			break;

			case "tab":
			str+="id="+encodeURIComponent(el.id);
			if(mode=='add')
				str+="&title="+encodeURIComponent(el.title)+"&mode=add";
			else if(mode=='pos')
				str+="&pos="+el.posChange;
			else
				str+="&mode=del";
			break;

			case "settingsPlugin":

			//Mode - this parameter replaced for data settings;
			
			str+="&"+mode;

			break;

			case "modul":
			str+="id="+el.id;
			switch(mode)
				{
				case "repos":
				str+= "&col="+encodeURIComponent(el.col);
				str+= "&pos="+encodeURIComponent(el.position);
				str+= "&mode=repos";
//				alert(el.position);
				break;
				
				case "add":
				str+= "&name="+encodeURIComponent(el.name)+
					"&id="+encodeURIComponent(el.id)+
					"&icon="+encodeURIComponent(el.ico)+
					"&tab_id="+App.tabs[App.SelectTab].id+
					"&color="+encodeURIComponent(el.color)+
					"&title="+encodeURIComponent(el.title)+
					"&mode=add"+
					"&data="+encodeURIComponent(el.data);
				break;
				
				case "edit":
				str+= "&color="+encodeURIComponent(el.color)+
					"&title="+encodeURIComponent(el.title)+
					"&data="+encodeURIComponent(el.data)+
				"&lines="+encodeURIComponent(el.len)+
					"&mode=edit";
				//alert(str);
				break;
				case "del":
				case "collapse":
				str+="&mode="+mode;
				break;
				}
			break;

			default:
			return;
			}
		App.Saver.SaveArr.push([str,func]);
		if(App.Saver.SaveArr.LastReq==null)
			//alert ("before call to 'this.request'\n\t Savearr(0): " + App.Saver.SaveArr[0] + "\n str: " + str);
			this.request();
		},
	isValid:function(r,func)
		{
			
		 if(r.responseText == ''|| r.responseText!='<OK/>')
		   alert(r.responseText);
		   
		App.Saver.SaveArr.splice(0,1);
		
		if(typeof func =="function")
			func();
		if(App.Saver.SaveArr.length==0)
			this.LastReq=null;
		else
			setTimeout(App.Saver.request,100);
		},
	request:function()
		{
 
			var newR=App.Saver.SaveArr.first();

			if(typeof newR!="object"){
				newR={0:newR,1:""};
			}
			
			// This line calls to "isValid" function and "isValid" function calls back to this line... sometimes appears deadlock.
			if (typeof newR!="undefined")
				if (typeof newR[0]!="undefined") {
					this.LastReq=Request.sendGET("saveUserData.php?"+newR[0]+"&nocache="+Math.random(),App.Saver.isValid,newR[1]);
				}
		}
	}

App.highlight = function(str, key, test) {
	if (typeof str != "string") return str;
	if (typeof test == "undefined") test = false;

	highlightStartTag = "<span class='highlight'><b>";
	highlightEndTag = "</b></span>";

	var newText = "";
	var i = -1;
	var lcSearchTerms = [];
	var lcBodyText = str.toLowerCase();
	
	key = key.toLowerCase();
	lcSearchTerms.push(key);

	if (key.indexOf("&") != -1) {
		var newKey = key.replace(/&/g, "&amp;");
		lcSearchTerms.push(newKey);
	}
	
	var keyLength = key.length;
	if (test) {
		var i, count = 0;
		for (var k = 0; k < keyLength; k++) {
			i = 0;
			while (i > -1) {
				i = lcBodyText.indexOf(lcSearchTerms[k], i);
				if (i == -1) break;
				i += 1;
				count += 1;
			}
			if (count > 0) return count;
		}
		return false;
	}
	
	while (str.length > 0) {
		var start = i + 1;
		for (var k = 0; k < keyLength; k++) {
			search = lcSearchTerms[k];
			i = lcBodyText.indexOf(search, start);
			if (i != -1) break;
		}
		
		if (i < 0) {
			// no (further) result
			newText += str;
			break;
		}
		
		// skip anything inside an HTML tag
		if (str.lastIndexOf(">", i) < str.lastIndexOf("<", i)) continue;
		
		// skip anything inside a <script> block
		if (lcBodyText.lastIndexOf("/script>", i) < lcBodyText.lastIndexOf("<script", i)) continue;
		
		newText += str.substring(0, i) + highlightStartTag + str.substr(i, search.length) + highlightEndTag;
		str = str.substr(i + search.length);
		lcBodyText = str.toLowerCase();
		i = -1;
	}
	
	return newText;
}

App.launchPlayer = function(file, podName)
	{
	if (!$("podPlayer"))
		{
		var player = "";
		if (Browser.isSafari || document.all)
			{
			player = '<embed id="podPlayer" type="application/x-shockwave-flash" src="i/player.swf?pod='+encodeURIComponent(file)+'&podname='+encodeURIComponent(podName)+'" width="238" height="17" '+
			'movie="i/player.swf?pod=' + encodeURIComponent(file) + '&podname=' + encodeURIComponent(podName)+'" '+
			'wmode="transparent">'+
			'</embed>';
			}
		else
			{
			player = '<object id="podPlayer" type="application/x-shockwave-flash" data="i/player.swf?pod=' + encodeURIComponent(file) + '&podname=' + encodeURIComponent(podName) + '" width="238" height="17">' + 
			'<param name="movie" value="i/player.swf?pod=' + encodeURIComponent(file) + '&podname=' + encodeURIComponent(podName) + '" />' + 
			'<param name="wmode" value="transparent" />'+
			'</object>';
			}
		content = '<div>'+
				player +
				'<img style="padding:0 0 4px 6px" src="i/closeMod.gif"/>'+
				'</div>';
		var div = $("player");
		div.innerHTML = content;
		div.style.display = "block";
		var imgClose = div.getElementsByTagName("img")[0];
		imgClose.style.cursor = "pointer";
		imgClose.onclick = function()
			{
			div.innerHTML = "";
			div.style.display = "none";
			}
		}
	else
		{
		var podPlayer = $("podPlayer");
		podPlayer.SetVariable("/fileChange:pod", encodeURIComponent(file));
		podPlayer.SetVariable("/fileChange:podname", podName);
		podPlayer.TPlay("/fileChange");
		}
	}

var Feed = function(feed)
	{
	//		alert(feed.responseText+"US");

	this.root = feed.responseXML.documentElement;
	this.items = [];
	if(!this.root)
		return; 
	//this.newNews=this.root.getAttribute("len");
	//this.newNews=this.root.firstChild.childNodes.length;
	this.type = (this.root.nodeName=="feed") ? 1 : 0;
	// htmlUrl
	var root = (this.type==1) ? this.root : this.root.getElementsByTagName("channel")[0];
	if(this.type!=1)
		{
		var im=root.getElementsByTagName("image");
		if(im[0])
			{
			var icon=im[0].getElementsByTagName("url");
			if(icon[0])
				this.icon=icon[0].firstChild.nodeValue;
			}
		}
	node=root.getElementsByTagName("link");
	var ln = (node && node.childNodes) ? node.childNodes.length : 0;
	var arr = [];	
	for (var z=0; z<ln; z++)
		if (node.childNodes[z].nodeName=="link")
			arr.push(node.childNodes[z]);

	if (this.type==1)
		{
		for (var z=0; z<link.length; z++)
			if (link[z].getAttribute("type")=="text/html" || link.length==1)
				this.htmlUrl = link[z].getAttribute("href");
		}
	else
		this.htmlUrl = (link && link[0] && link[0].firstChild) ? link[0].firstChild.nodeValue : "";
	
	var title = root.getElementsByTagName("title")[0];
	this.title = (title && title.firstChild) ? title.firstChild.nodeValue : "";
	
	// description
	var desc = (this.type==1) ? this.root.getElementsByTagName("tagline") : this.root.getElementsByTagName("description");
	this.description = (desc && desc.length>0) ? ((desc[0].firstChild) ? desc[0].firstChild.nodeValue : '') : '';


	var items = (this.type==1) ? root.getElementsByTagName("entry") : root.getElementsByTagName("item");
	var ln = items.length;

	this.getNode = function(i)
		{
		return items[i];
		}
	
	for (var z=0; z<ln; z++)
		{
		var obj = {};
		obj.node = items[z];
		obj.enclosures = items[z].getElementsByTagName("enclosure");
		
		var title = items[z].getElementsByTagName('title')[0];
		if (title && title.firstChild)
			obj.title = title.firstChild.nodeValue;
		else
			{
			var d = items[z].getElementsByTagName("description");
			if (d[0] && d[0].firstChild)
				{
				var tmp = document.createElement("div");
				tmp.innerHTML = d[0].firstChild.nodeValue;
				obj.title = ((tmp.innerText)?tmp.innerText.substring(0,50):'')+"...";
				}
			else
				obj.title = '[...]';
			}
		
		var dcDate = (Browser.isIE) ? items[z].getElementsByTagName("dc:date")[0] : items[z].getElementsByTagName("date")[0];
		if (items[z].getElementsByTagName("pubDate")[0])
			obj.date = (items[z].getElementsByTagName("pubDate")[0].firstChild) ? items[z].getElementsByTagName("pubDate")[0].firstChild.nodeValue : "";
		else if (dcDate)
			obj.date = dcDate.firstChild.nodeValue;
		else if (items[z].getElementsByTagName("issued")[0])
			obj.date = items[z].getElementsByTagName("issued")[0].firstChild.nodeValue;
		
		var link = items[z].getElementsByTagName("link");
		if (link.length>0)
			{
			if (this.type==1)
				{
				for (var n=0; n<link.length; n++)
					{
					if (link[n].getAttribute("type")=="text/html" || link.length==1)
						obj.link = link[n].getAttribute("href");
					}
				}
			else
				{
				if (link[0] || link[0].firstChild)
					{
					obj.link = (link[0].firstChild) ? link[0].firstChild.nodeValue : '';
					}
				 else if (items[z].getElementsByTagName("guid")[0].firstChild)
					{
					obj.link = items[z].getElementsByTagName("guid")[0].firstChild.nodeValue;
					}
				}
			}
		else
			obj.link = this.htmlUrl;
		
		if (obj.link!="" && obj.link!=this.htmlUrl)
			var str = obj.link;
		else
			var str = obj.title+obj.date+obj.link;
		obj.id = str.replace(/([^0-9a-zA-Z])/g,"");
		obj.id_old = (obj.title+obj.date+obj.link).replace(/([^0-9a-zA-Z])/g,"");
		
		if (this.type==1)
			{
			obj.content = items[z].getElementsByTagName("content")[0];
			obj.description = items[z].getElementsByTagName("summary")[0];
			}
		else
			{
			obj.content = (Browser.isIE) ? items[z].getElementsByTagName("content:encoded")[0] : items[z].getElementsByTagName("encoded")[0];
			obj.description = items[z].getElementsByTagName("description")[0];
			}
		this.items.push(obj);
		}
	this.newNews = items.length;
	}

var SearchInterface		=	function()
	{
	var lastSearch	=	false;
	var self		=	this;
	var inp		=	null;
	var stopInp	=	null;

	this.search	=	function(all)
		{
		if(lastSearch)
			this.stop();
		App.query=inp.value.toLowerCase();
		for(var i=0;i<App.tabs.length;i++)
			{
			var current=App.tabs[i].modules;
			for(var k=0;k<current.length;k++)
				{
				var b=current[k].builder;
				current[k].collnextSave=false;
				if(typeof b.doSearch!="function" || !b.doSearch(App.query,all))
					{
					current[k].hide();
					continue;
					}
				current[k].show();
				}
			}

		stopInp.style.display="";
		lastSearch=true;
		}

	this.stop		=	function()
		{
		stopInp.style.display="none";
		App.query=null;
		for(var i=0;i<App.tabs.length;i++)
			{
			var current=App.tabs[i].modules;
			for(var k=0;k<current.length;k++)
				{
				var b=current[k].builder;
				current[k].collnextSave=false;
				current[k].show();
				if(typeof b.stopSearch=="function")
					{
					b.stopSearch();
					continue;
					}
				}
			}
		lastSearch=false;
		}

	this.create	=	function()
		{

		var doc=document.createElement("form");
	
		var input1=document.createElement("input");
		input1.style.color="rgb(170,170,170)";
		input1.className="text search";
		input1.type="text";

		var span=document.createElement("span");
		span.style.position="relative";
	
		var img=document.createElement("img");
		img.style.position="absolute";
		img.style.top="2px";
		if(Browser.isIE)
			img.style.top="7px";
		img.style.display="none";
		img.style.left="-20px";
		img.style.cursor="pointer";
		img.title=_("Clear");
		img.src="i/clear.gif"
	
		var input2=document.createElement("input");
		input2.value=_("Filter");
		input2.className="submit";
		input2.type="button";

		var input3=document.createElement("input");
		input3.value=_("Search");
		input3.className="Submit";
		input3.type="button";
		
		input1.onclick=function()
			{
			if(this.prot=="1")
				this.value="";
			}
		
		doc.onsubmit	=	function()
			{
			input3.onclick();
			return false;
			}

		input1.onblur	=function()
			{
			if(this.value.trim()=="")
				this.value=_("In my page");
			}
		
		input1.onkeyup	=function()
			{
			if(this.value.trim()=="")
				{
				this.prot="1";
				input2.disabled="disabled";
				input3.disabled="disabled";
				return true;
				}
			input2.disabled="";
			input3.disabled="";
			this.prot="0";
			}

		input2.onclick	=function()
			{
			if(inp.prot=="1")
				return true;
			input3.disabled="";
			this.disabled="disable";
			self.search();
			}

		input3.onclick	=function()
			{
			if(inp.prot=="1")
				return true;
			this.disabled="disable";
			input2.disabled="";
			self.search(1);
			}
		img.onclick	=function()
			{
			inp.value="";
			inp.onkeyup();
			inp.onblur();
			self.stop();
			}

		input1.onkeyup();
		input1.onblur();
		inp=input1;
		stopInp=img;

		span.appendChild(img);
		
		doc.appendChild(input1);
		doc.appendChild(span);
		doc.appendChild(input2);
		doc.appendChild(input3);
		$("globalSearch").appendChild(doc);
		}
	this.destroy=function()
		{
		if($("globalSearch"))
			$("globalSearch").innerHTML="";
		}
	}

var SearchInt=new SearchInterface();


var SettingsPanel	=	function()
	{
	var self      =this;
	var overlay   =null;
	var panel     =null;
	var page      =null;
	var closed    =true;
	var data      =App.User.vars;
	var lastData  =App.User.vars.toStr();
	var last 	  =0;
	var lastLI;
	var errSpan	  =null;
	var variants  = [
			_('General settings'),
			_('Local Content'),
			_('Languages'),
			_('Themes')
		       ];

	if(App.User.name!=false && App.User.name!="")
		variants.push(_('Password'));


	this.objName="settingsPlugin";


	this.open=function(id)
		{
		if(typeof id=="undefined")
			id=0;
		
		page['li'+last].className="";
		if(page['p'+last])
			Element.remove(page['p'+last]);
		lastLI=null;
		page['li'+id].className="selected";

		this.build(id);

		page['p'+id].style.display="";

		last=id;
		closed=false;
		
		panel.style.display="";

		var left=Math.floor( ((Browser.isIE&&!window.opera? ietruebody().clientWidth : window.innerWidth)-panel.clientWidth)/2);
		var top=Math.floor( ((Browser.isIE&&!window.opera? ietruebody().clientHeight : window.innerHeight)-panel.clientHeight)/2);

		overlay.style.width=(Browser.isIE&&!window.opera? ietruebody().clientWidth : window.innerWidth)+"px";
		overlay.style.height=(Browser.isIE&&!window.opera? ietruebody().clientHeight : window.innerHeight)+"px";

		panel.style.left=(left<0 ? 0 : left)+"px";
		panel.style.top=(top<0 ? 0 : top)+ "px";
		overlay.style.display="";
		}

	this.close=function()
		{
		if(closed)
			return;
		data=lastData.toObj();
		if(page['p'+last])
			Element.remove(page['p'+last]);
		panel.style.display="none";
		overlay.style.display="none";
		}

	this.save =function()
		{
		var tmp=data.toStr();
		App.User.vars=data;
		this.close();

		if(tmp==lastData)
			return;
		var tmp2=lastData.toObj();
		lastData=tmp;

		if(tmp2['langOpt']!=App.User.vars['langOpt'] || tmp2['styleOpt']!=App.User.vars['styleOpt'])
			App.Saver.AddSave(this,lastData,App.updateAll);
		else
			App.Saver.AddSave(this,lastData,App.restart);
		
		}

	this.build=function(id)
		{

		var inner=document.createElement('div');
		inner.style.display="none";
		inner.innerHTML="<h2>"+variants[id]+"</h2><br/>";
		switch(id+"") // :(
			{
			case "1": //Local information
			s='<p></p>'+
				'<map id="localContentMap" name="localContentMap">'+
					'<area shape="poly" href="javascript:void(0)" continent="6" alt="'+_('Oceania')+'" coords="372,132, 383,86, 460,107, 453,149, 432,178, 400,197, 343,175, 347,143">'+
					'<area shape="poly" href="javascript:void(0)" continent="5" alt="'+_('Asia')+'" coords="348,141, 371,132, 381,86, 405,19, 278,0, 269,11, 261,62, 238,54, 233,59, 260,99, 278,93, 295,115, 315,115, 320,106">'+
					'<area shape="poly" href="javascript:void(0)" continent="1" alt="'+_('Africa')+'" coords="259,100, 272,96, 283,139, 278,156, 254,161, 238,174, 219,170, 205,114, 180,114, 163,93, 186,67, 195,67, 215,62, 226,68, 238,68">'+
					'<area shape="poly" href="javascript:void(0)" continent="4" alt="'+_('South America')+'"  coords="108,93, 160,126, 135,205, 113,203, 78,115">'+
					'<area shape="poly" href="javascript:void(0)" continent="3" alt="'+_('North America')+'"  coords="128,104, 131,93, 109,75, 148,54, 146,36, 178,24, 200,5, 201,0, 109,0, 46,11, 16,32, 24,47, 43,37, 41,70, 61,100, 88,106, 109,91">'+
					'<area shape="poly" href="javascript:void(0)" continent="2" alt="'+_('Europe')+'" coords="176,26, 189,33, 186,64, 195,65, 214,60, 226,67, 235,67, 233,58, 238,53, 260,60, 269,7, 207,2, 184,19">'+
				'</map>'+
				'<fieldset class="autoclear"></fieldset>';
			inner.innerHTML+=s;
			
			var areas=inner.getElementsByTagName("area");
			for(var i=0;i<areas.length;i++)
				{
				//areas[i].setAttribute("alt",_(areas[i].getAttribute("alt")) );
//						alert("Translating "+areas[i].getAttribute("alt")+" to "+_(areas[i].getAttribute("alt"))+", much like Asia to "+_("Asia"));
				var c=areas[i].getAttribute("continent");
				areas[i].onclick=function()
					{
					var p  	=inner.getElementsByTagName("p")[0];
					var f	=inner.getElementsByTagName("fieldset")[0];
					p.innerHTML="";
					var c=this.getAttribute("continent");

					var map=document.createElement("img");
					map.style.height="212px";
					map.style.width ="460px";
					map.useMap="#localContentMap";
					map.src="i/worldmap-"+c+".gif";

					f.innerHTML='<legend>'+this.getAttribute("alt")+'</legend><div id="localContentRegions"></div>';
					var cd	=f.getElementsByTagName("div")[0];
					p.appendChild(map);

					if(!App.countries[c] || App.countries[c].length==0)
						return true;
					var torow=Math.ceil(App.countries[c].length/3);
					var k=0;
					for(var i in App.countries[c])
						{
						if(typeof App.countries[c][i]!="string" || k=="length")
							continue;
						if(k%torow==0 || k==0)
							{
							if(div)
								{
								div.appendChild(ul);
								cd.appendChild(div);
								}
							var div=document.createElement("div");
							div.className="column three";
							var ul=document.createElement("ul");
							ul.className ="regions";
							}
						var li=document.createElement("li");
						
						li.className="country";
						li.setAttribute("val",i);

						var a =document.createElement("a");
						a.href="javascript:void()";
						a.innerHTML=_(App.countries[c][i]);
						

						li.appendChild(a);
						ul.appendChild(li);
						li.onclick=function()
							{
							if(lastLI)
								lastLI.className=this.className;
							lastLI=this;
							this.className+=" selected";
							data['contextOpt']=this.getAttribute("val");
							return false;
							}
						if(i==App.User.vars['contextOpt'])
							li.onclick();
						k++;
						}
					if(k%torow==0 && div)
						{
						div.appendChild(ul);
						cd.appendChild(div);
						}
					}
				if(!App.countries[c])
					continue;
				if(typeof App.countries[c][App.User.vars['contextOpt']]=="string")
						{
						areas[i].onclick();
						//break;
						}
				}

			break;
			case "2": //Languages
			
			var f=document.createElement("fieldset");
			f.className="autoclear";
		
			var l=document.createElement("legend");
			l.innerHTML=_("Select a language");

			var div=document.createElement("div");
			div.id="langsContent";
			
			var ul=document.createElement("ul");
			ul.id="langsUL";
			
			for(i in App.langs)
				{
				if(typeof App.langs[i]!="string" || i=="length")
					continue;
				var li=document.createElement("li");
				li.className="language";
				li.setAttribute("lang",i);

				var a=document.createElement("a");
				a.href="javascript:void()";
				a.innerHTML=_(App.langs[i]);
			
				li.appendChild(a);
				ul.appendChild(li);
				
				li.onclick=function()
					{
					if(lastLI)
						lastLI.className=this.className;
					lastLI=this;
					this.className+=" selected";
					data['langOpt']=this.getAttribute("lang");
					return false;
					}
				if(App.User.vars['langOpt']==i)
					{
					li.onclick();
					}
				}
			div.appendChild(ul);
	

			f.appendChild(l);
			f.appendChild(div);
			inner.appendChild(f);
			break;
			case "3": //Themes
			
			var div=document.createElement("div");
			div.className="listThemes";

			for(var i in App.styles)
				{
				if(typeof App.styles[i]!="string")
					continue;
				var style=document.createElement("div");
				var lang=_(App.styles[i]);
				style.className="themeItem";
     			style.innerHTML='<p><a href="javascript:void(0)" class="switcher" title="'+lang+'"><img src="i/designs/'+App.styles[i]+'/screenshot.png" alt="" height="80" width="107"></a></p>';
      			style.innerHTML+='<p class="title">'+lang+'</p>';
				style.setAttribute("design",App.styles[i]);

				style.onclick=function()
					{
					if(lastLI)
						lastLI.firstChild.firstChild.className=this.firstChild.firstChild.className;
					lastLI=this;
					this.firstChild.firstChild.className+=" selected";
					data['styleOpt']=this.getAttribute("design");
					}

				div.appendChild(style);
				if(App.styles[i]==App.User.vars['styleOpt'])
					style.onclick();
				}
			
			inner.appendChild(div);

			break;

			case "4": //Password
			var s;
			s ="<form action='login.php?action=change'><fieldset><legend>"+_("Change password")+"</legend>";
			s+="<p class='option'><input type='password' id='lpsw'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for='lastPSWOpt'>"+_("Last password")+"</label></p>";
			s+="<p class='option'><input type='password' id='npsw'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for='newPSWOpt'>"+_("New password")+"</label></p>"
			s+="<span id='error' style='color:red;'></span><br/>";
			s+="<input type='submit' value='"+_("Save")+"'/></fieldset></form>";
			inner.innerHTML+=s;
			break;

			default: //General settings

			var s;
			s ="<fieldset><legend>"+_("Interface")+"</legend>";
			s+="<p class='option'><input type='checkbox' id='hideSearchOpt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for='hideSearchOpt'>"+_("Hide search panel")+"</label></p>";
			s+="<p class='option'><input type='checkbox' id='noTabOpt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for='noTabOpt'>"+_("Do not load page tabs")+"</label></p>";

			var tmp="";
			for(var i=1;i<4;i++)
				{
				tmp+="<option value='"+i+"'";
				if(data['countRowsOpt']==i)
					tmp+=" selected";
				tmp+="/>"+i;
				}
			s+="<p class='option'><select id='countRowsOpt'>"+tmp+"</select>&nbsp;&nbsp;<label for='countRowsOpt'>"+_("Count columns for page")+"</label></p>";
		

			inner.innerHTML+=s;
			
			}

		page['p'+id]=inner;
		page.appendChild(inner);

		var forms=inner.getElementsByTagName("form");
		if(forms.length>0)
			{
			for(var i=0;i<forms.length;i++)
				{
				if(forms[i].getAttribute("action").trim()=="")
					continue;
				forms[i].ondata=function (r,form)
					{
					errSpan.innerHTML=r.responseText;
					}
				forms[i].onsubmit = function()
					{
					var inp=this.getElementsByTagName("input");
					var obj={};
					for(var k=0;k<inp.length;k++)
						if(inp[k].type!="submit")
							obj[inp[k].id]=inp[k].value;
					Request.sendPOST(this.getAttribute("action"),obj.toStr(),this.ondata);
					errSpan=this.getElementsByTagName("span")[0];
					errSpan.innerHTML=_("Loading");
					return false;
					}
				}
			return inner;
			}

		var inp=inner.getElementsByTagName("input");
		var sel=inner.getElementsByTagName("select");

		for(var i=0;i<inp.length;i++)
			{
			switch(inp[i].type.toLowerCase())
				{
				case "checkbox":
				if(data[inp[i].id]=="1")
					inp[i].checked=1;
				inp[i].onclick=function(){data[this.id]=(this.checked ? "1" : "0");}
				break;
				default:
				inp[i].onchange=function(){data[this.id]=this.value;}
				}
			}
		for(var i=0;i<sel.length;i++)
			sel[i].onchange=function(){data[this.id]=this.value;}
		return inner;
		}
	this.destroy=function()
		{
		Element.remove(overlay);
		Element.remove(panel);
		}
	panel=document.createElement("div");
	panel.style.display="none";
	panel.className="modalDialog";
	panel.id="p-settings";
	panel.style.width="650px";

	
/*	panel.innerHTML='<table width="100%"><tr><td>' + '<h1>'+_("Settings")+'</h1>' + '</td><td>'
	+'<img title="Close" alt="Close" class="icon actions-window-close close" src="i/closeMod.gif" height="15" width="13">'
	+'</td></tr>';
	*/
	
	//</td></tr></table>';
	panel.innerHTML='<table id="settings_topic" width="100%"><tr><td>' + '<h1>'+_("Settings")+'</h1>' + '</td><td>'
//	+'<img title="Close" alt="Close" class="icon actions-window-close close" src="i/closeMod.gif" height="15" width="13" onclick="document.getElementById(\'p-settings\').close()">'
	+'</td></tr></table>';

	//</td></tr></table>';
	//panel.innerHTML='<h1>'+_("Settings")+'</h1>';//<img title="Close" alt="Close" class="icon actions-window-close close" src="i/closeMod.gif" height="15" width="13"><ol class="settings"><li class="general"><a class="" selectedindex="0" hidefocus="hidefocus" href="javascript:void(0)">General settings</a></li><li class="country"><a class="selected" selectedindex="1" hidefocus="hidefocus" href="javascript:void(0)">Local Content</a></li><li class="language"><a class="" selectedindex="2" hidefocus="hidefocus" href="javascript:void(0)">Languages</a></li><li class="theme"><a class="" selectedindex="3" hidefocus="hidefocus" href="javascript:void(0)">Themes</a></li></ol><div class="page">bla</div>';


	var img=document.createElement("img");
	img.src="i/closeMod.gif";
	img.title=_("Close");
	img.alt=img.title;
	img.className="icon actions-window-close close";
	//img.className="settings_close_button";

	//img.style.cursor = "pointer";
	//img.style.background = "url(i/closeMod.gif);";


/*	img.style.float = "right";
	img.style.margin = "2px 2px 0 0;";


	img.style.position = "absolute";
	img.style.top = "5px";
	img.style.right = "5px";
*/
//	img.height ="15";
//	img.width ="13";
	img.onclick=function()
		{
		self.close();
		}

	var ol=document.createElement("ol");
	ol.className="settings";

	page=document.createElement("div");
	page.className="page";
	
	for(var i=0;i<variants.length;i++)
		{
		var li=document.createElement("li");
		li.setAttribute("num",i);

		var a =document.createElement("a");
		a.hidefocus="hidefocus";
		a.href="javascript:void(0)";
		a.innerHTML=variants[i];
		
		page["li"+i]=a;
		li.onclick=function()
			{
			self.open(this.getAttribute("num"));
			}
		li.appendChild(a);
		ol.appendChild(li);
		}
	var submd=document.createElement("div");
	submd.width="100%";
	submd.align="right";

	var subm=document.createElement("input");
	subm.type="button";
	subm.value=_("Save");
	
	subm.onclick=function()
		{
		self.save();
		}

	var canc=document.createElement("input");
	canc.type="button";
	canc.value=_("Close");

	canc.onclick=function(){
		self.close();
	}




	submd.appendChild(subm);
	submd.appendChild(canc);
	panel.appendChild(img);
	panel.appendChild(ol);
	panel.appendChild(page);
	panel.appendChild(submd);

	overlay=document.createElement("div");
	overlay.onclick=function()
		{
		self.close();
		}
	ostyle=overlay.style;

	ostyle.position="absolute";
	ostyle.top="0pt";
	ostyle.left="0pt";
	ostyle.display="none";


	overlay.className="overlay_settings";
	
	var body=document.getElementsByTagName("body")[0];
	body.appendChild(panel);

    var sTable = document.getElementById("settings_topic");
//    if (!sTable) alert ("the table doesnt exist");
  //  else
 //   {
    	sTable.rows[0].cells[1].appendChild(img);
//    }

	
	body.appendChild(overlay);

	}
