var common_js_loaded;
if( !common_js_loaded )
{
	/**************************************************
	 *	this file defines the basis for JS constructs on any page of COMBY (and maybe not only)
	 **************************************************/
	common_js_loaded = 1;
	var isDOM=document.getElementById; //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
	var isOpera5=window.opera && isDOM; //Opera 5+
	var isOpera6=isOpera5 && window.print; //Opera 6+
	var isOpera7=isOpera5 && document.readyState; //Opera 7+
	var isOpera=(isOpera5||isOpera6||isOpera7);
	var isOpera8 = false;
	var isMSIE=document.all && document.all.item && !isOpera; //Microsoft Internet Explorer 4+
	var isMSIE5=isDOM && isMSIE; //MSIE 5+
	var isNetscape4=document.layers; //Netscape 4.*
	var isMozilla=isDOM && navigator.appName=="Netscape"; //Mozilla ????????? Netscape 6.*
	var active_nick;
	var context_menu_active=0;
	var mouse_on_nick=0;
	var menu_type='user';
	var Menu_timeout=1000;
	var menu_item=false;
	var drop_menu_timeout=false;
	var launch_next_menu=1;
	var menu_param_keys=false;
	var menu_param_values=false;
	var delayhide=false;
	var update_menu=1;
	var newMenuCaller = {};
	var currentMenuCaller = {};
	var comby_loaded=false;

	// ***************  ERROR HANDLING  ***************

	function logjserror(sev, msg)
	{
		return;
	    var img = new Image();
	    img.src = "/logjserror?sev="
	        + encodeURIComponent(sev)
	        + "&msg=" + encodeURIComponent(msg);
	}

/*	window.onerror = function (desc,page,line,chr)
	{
	    logjserror("ERROR",
	        'JavaScript error occurred! \n'
	        +'The error was handled by '
	        +'a customized error handler.\n'
	        +'\nError description: \t'+desc
	        +'\nPage address:      \t'+page
	        +'\nLine number:       \t'+line
	        );
	    return true;
	}*/

	// ****************  NEW MODULES  ********************

	/***********************************************
	 * 	onLoad events controller module
	 * 	USAGE
	 * 	addition format onLoadHandlers['(module prefix)_(handler name)'] = function
	 * 	modules add personal onLoad hanlers like this onLoadHandlers['olh_locationSelector'] = locationSelectorInit;
	 ***********************************************/
	// GLOBAL VARIABLE
	onLoadHandlers = {}; // storage for onload handlers

	function combyOnLoad() {
		if (comby_loaded) return;
		completeBrowserDetection();
		comby_loaded = true;
		combyExecHandlers();
	}

	function combyExecHandlers() {
		for(i in onLoadHandlers)
		{
			if ('function' == typeof onLoadHandlers[i])
			{
				onLoadHandlers[i]();
			}
		}
		onLoadHandlers = {};
	}

	window.onload = combyOnLoad;
	// 	onLoad events controller module END

	function setOnLoadHandler(name, handler) {
		onLoadHandlers[name] = handler;
	}

	function completeBrowserDetection(){
		detectOpera8();
	}

	function detectOpera8(){
		if (isOpera && ('object' != (typeof document.body.currentStyle))){
			isOpera8 = true;
		}
	}
	//onLoadHandlers['detectOpera8'] = detectOpera8;
	/***********************************************
	 * 	event hendlers controller module
	 * 	suport assigning multiple handlers to same event on same node
	 * 	suport save removing of handlers
	 ***********************************************/
	// GLOBAL VARIABLE
	var handlerCollection  = {};// storage for handlers

	/**	Service function
	 *	Run a set of handlers by key, eventName and event reference
	 *
	 *	@param		string 		key			key of node
	 *	@param		string		eventName	name of current event
	 *	@param		object		_event		reference to current event
	 *
	 *	@return		void
	 **/
	function runHandlers(key,eventName,_event){
		$A(handlerCollection[key][eventName]).foreach(function (handler)
				{
				handler(_event);
				});
	}
	/**
	 *	add a handler to node
	 *
	 *	@param		element 	node		target DHTML element (reference)
	 *	@param		string		eventName	name of event to handle
	 *	@param		function	handler		a handler to add
	 *	@param		string		key			optional, if not set generated by node
	 do not leave blank if node className or id may be changed.
	 must be unical
	 must be set for document or window
	 TODO make autofill of key for document and window
	 *
	 *	@return		void
	 **/
	function addHandlerToNode(node,eventName,handler,key){
		/**
		  Service function used as prototype for handlers puted on nodes.
		 **/
		function RunHandlersCaller(_event){
			if ('creation' == _event) _this = this;
			else runHandlers(_this.key,_this.eventName,_event);
		}
		if (!key) key = node.tagName + node.className + node.id;
		if (!handlerCollection[key]) handlerCollection[key] = {};
		if (!handlerCollection[key][eventName]) {handlerCollection[key][eventName] = [];}
		if (handlerCollection[key][eventName].length == 0) {
			handlerCollection[key][eventName].push(handler);
			node[eventName] = handler;
		}
		else {
			var index = -1;
			for (var i = 0, length = handlerCollection[key][eventName].length; i < length; i++)
				if (handlerCollection[key][eventName][i] == handler) index = i;
			if (index!=-1)
				return;
			handlerCollection[key][eventName].push(handler);
			var runner = new RunHandlersCaller('creation');
			runner.key = key;
			runner.eventName = eventName;
			node[eventName] = runner;
		}
	}
	/**
	 *	add a handler to node
	 *
	 *	@params	SAME AS addHandlerToNode
	 *
	 *	@return		boolean		true if handler deleted sucsessfuly
	 **/
	function removeHandlerFromNode(node,eventName,handler,key){
		if (!key) key = node.tagName + node.className + node.id;
		if (!handlerCollection || !handlerCollection[key] || !handlerCollection[key][eventName]) return false;

		var index = -1;
		for (var i = 0, length = handlerCollection[key][eventName].length; i < length; i++)
			if (handlerCollection[key][eventName][i] == handler) index = i;

		if (index>0) handlerCollection[key][eventName].splice(index,1);
		if (handlerCollection[key][eventName].length == 0) {
			node[eventName] = null;
		}
		return true;
	}
	// 	event hendlers controller module END

	/***********************************************
	 * 	LANG module
	 * 	colect LANG and let all get them
	 ***********************************************/

	function Lang(){
		var langStorage = {};
		var debug = false;
		this.add = function LAdd(key,value,force)
		{
			if (langStorage[key])
			{
				if (debug) alert('double setting of '.key);
				if (force) langStorage[key] = value;
			}
			else langStorage[key] = value;
		}
		this.get = function LGet(key){return langStorage[key]}
	}
	// GLOBAL VARIABLE
	lang = new Lang();
	function L(key)
	{
		return lang.get(key);
	}
	// LANG module


	//*** Separate functions may be moved to tools.js

	/**
	 *	Return coordinates of given element relative to start of the document
	 *
	 *	@param		element		DHTML element (reference)
	 *
	 *	@return		object		structure {left:(left coordinate),top:(top coordinate)}
	 **/
	function getElementPosition(element,debug){
		var offsetLeft = 0;
		var offsetTop = 0;
		while(element) {
			/********************************************************
			  IE 6.0 and earlyer have a bug in offsetTop of LI element
			  code lower will partualy correct this bug.
			  function will detect offset of LI but miss offset of element in LI
			 *********************************************************/
			/*if (offsetTrail.tagName == 'LI'){
			  offsetTop += 6;
			  offsetLeft += offsetTrail.offsetLeft;
			  offsetTrail = offsetTrail.offsetParent;
			  continue;
			  }*/
			if (debug) alert([element.tagName,element.offsetLeft,element.outerHTML]);
			offsetLeft += element.offsetLeft;
			offsetTop += element.offsetTop;
			element = element.offsetParent;
		}
		return { left:offsetLeft, top:offsetTop }
	}
	/**
	 *	Open browser controll of adding given url to favorites, recomend given title
	 *
	 *	@param		string		title	optional, if not set title in control will be blank
	 *	@param		string		url 	optional, if not set url of curent page is used
	 *
	 *	@return		void
	 **/
	function addToBrowserFavorites(title, url){
		//alert([title, url, window.sidebar, window.external]);
		if (!url) url = window.location.href;
		if (isMSIE)	window.external.AddFavorite(url, title);
		if (isMozilla) window.sidebar.addPanel(title, url, '');

		/*else if(window.sidebar)
		  window.sidebar.addPanel(title, url, '');*/
	}
	/**
	 *	Show homepage icon
	 **/
	function showHomepageIcon()
	{
		if (!isMSIE)
			return false;
		var shp = document.getElementById('setHP');
		if (shp)
			shp.style.visibility = 'visible';
	}
	/**
	 *	returns y coordinate of element relative to screen;
	 *
	 *	@param		element		DHTML element (reference)
	 *
	 *	@return		int
	 **/

	// XBrowser functions - may be collected in browser object in future

	function getObjectScreenTop (node){
		return getElementPosition(node).top - getBodyScrollTop();
	}
	/**
	 *	returns curren height of element;(XBrowser)
	 *
	 *	@param		element		DHTML element (reference)
	 *
	 *	@return		int
	 **/
	function getObjectCurrentHeight(node){
		if (isMozilla || isOpera8) {
			if ('auto' == document.defaultView.getComputedStyle(node, null).height)
				return node.offsetHeight;
			return parseInt(document.defaultView.getComputedStyle(node, null).height);
		}
		else {
			if ('auto' == node.currentStyle.height) return node.clientHeight;
			return parseInt(node.currentStyle.height);
		}
	}
	/**
	 *	returns curren width of element;(XBrowser)
	 *
	 *	@param		element		DHTML element (reference)
	 *
	 *	@return		int
	 **/
	function getObjectCurrentWidth(node){
		// TODO change isOpera to isOpera8
		if (isMozilla || isOpera8) return parseInt(document.defaultView.getComputedStyle(node, null).width);
		else return parseInt(node.currentStyle.width);
	}
	/**
	 *	removes node from DOM (XBrowser)
	 *
	 *	@param		element		DHTML element (reference)
	 *
	 *	@return		void
	 **/
	function removeNodeXB(node){
		if (isMSIE){
			node.removeNode();
		}
		else {
			node.parentNode.removeChild(node);
		}
	}
	// TODO coments
	function getBodyClickTop(e){
		if (event) e = event;
		if (!e) return 0;
		return e.screenY+document.body.parentNode.scrollTop-screenTop-10;
	}
	function getBodyClickLeft(e){
		if (event) e = event;
		if (!e) return 0;
		return e.screenX+document.body.parentNode.scrollLeft-screenLeft;
	}
	// ****************  OLD MODULES ********************

	/***********************************************
	 * Drop Down Menu
	 ***********************************************/
	var menuwidth='100px' //default menu width
		var menubgcolor='#FFF6E5'  //menu bgcolor
		var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
		var hidemenu_onclick="no" //hide menu when user clicks within menu?

		/////No further editting needed

		var ie4=document.all
		var ns6=document.getElementById&&!document.all

		//   if (ie4||ns6)
		//         document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

		// old shortcut usage not recomended, left here for compatibility to current code.
		// use getElementPosition().left(.top) instead
		function getposOffset(what, offsettype)
		{
			if (offsettype=="left") return getElementPosition(what).left;
			else return getElementPosition(what).top;

			// OLD CODE to be deleted
			/*var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
			  var parentEl=what.offsetParent;
			  while (parentEl.offsetParent)
			  {
			  totaloffset+=(offsettype=="left")?parentEl.offsetLeft : parentEl.offsetTop;
			  parentEl=parentEl.offsetParent;
			  }
			  return totaloffset;*/
		}

	function showhide(menucontents, obj, event_type, visible, hidden, menuwidth, gettype)
	{
		if(update_menu)
		{
			if (gettype == 'ajax')
			{
				dropmenuobj.innerHTML = '<a><img src="'+portal_url+'img/indicator.gif" align="absmiddle">&nbsp;&nbsp;'+str_loading+'</a>';
				if (!window.XMLHttpRequest && !window.ActiveXObject)
					return true;
				getmenuhtml(menucontents, menu_param_keys, menu_param_values);
			}
			else
			{
				populatemenu_js(menucontents, menu_param_keys, menu_param_values);
			}
			if(obj===false)
				obj=dropmenuobj.style;
			if (ie4||ns6)
				obj.left=obj.top="-500px";
			if (menuwidth!="")
			{
				dropmenuobj.widthobj=dropmenuobj.style
					dropmenuobj.widthobj.width=menuwidth
			}
			if (event_type=="click" && obj.visibility==hidden || event_type=="mouseover")
			{
				update_menu=0;
				obj.visibility=visible;
			}
			else if (event_type=="click")
			{
				context_menu_active=0;
				update_menu=1;
				obj.visibility=hidden;
			}
			dropmenuobj.x=getposOffset(menu_item, "left");
			dropmenuobj.y=getposOffset(menu_item, "top");
			dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(menu_item, "rightedge")+"px";
			dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(menu_item, "bottomedge")+menu_item.offsetHeight+"px";
		}

	}

	function iecompattest(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}

	function clearbrowseredge(obj, whichedge){
		var edgeoffset=0
			if (whichedge=="rightedge"){
				var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
					dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
					if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
						edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
			}
			else{
				var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
					var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
					dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
					if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
						edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
							if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
								edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
					}
			}
		return edgeoffset
	}

	function getmenuhtml(menucontents, param_keys, param_values)
	{
		var URL="/ajax/?Action="+menucontents; //+"&service_name="+service_name;
		var param_keys;
		var param_values;

		if (param_keys.length)
			for (i=0;i<param_keys.length;i++)
				URL=URL+"&"+param_keys[i]+"="+param_values[i]
					LoadData(URL,"populatemenu_ajax","menu");
		return;
	}

	function populatemenu_js(what, param_keys, param_values)
	{
		if (ie4||ns6)
			if (what!="undefined") {
				menu_html=what.join("")
					if (param_keys.length)
						for (i=0;i<param_keys.length;i++)
							menu_html=menu_html.replace(new RegExp("%"+param_keys[i]+"%", "gim"), param_values[i]);

				dropmenuobj.innerHTML=menu_html
			}
	}

	function populatemenu_ajax()
	{
		RequestIndex=FindRequest("menu");
		//  alert(RequestIndex);
		if (RequestIndex!==false) {
			// only if reg shows "complete"
			if (RequestStack[RequestIndex].Request.readyState == 4)
			{
				// only if "OK"
				if (RequestStack[RequestIndex].Request.status == 200)
				{
					// ...processing statements go here...
					if (RequestStack[RequestIndex].Request.responseText == null) return false;
					dropmenuobj.innerHTML=RequestStack[RequestIndex].Request.responseText;
					UnsetRequest("menu");
					return true;
				}
			}
		}
		return false;
	}
	/*onmouseover="return dropdownmenu('user_my_menu',this,event,'ajax',
	  ['me', 'user_id' ],[1669, 1669 ],'125px');"
	  onmouseover="return dropdownmenu('user_context_menu',this,event,'ajax',
	  ['me', 'user_id' ],[1669, 132 ],'125px');"
	  */
	function dropdownmenu(menucontents, obj, e, gettype, param_keys, param_values, menuwidth)
	{

		context_menu_active=1;
		launch_next_menu=0;
		menu_item=obj;
		if (window.event)
			event.cancelBubble=true;
		else if (e.stopPropagation)
			e.stopPropagation();
		clearhidemenu();
		menu_param_keys=param_keys;
		menu_param_values=param_values;
		dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv;
		if (ie4||ns6)
		{
			if(e.type=='click')
				showhide(menucontents, false, e.type, "visible", "hidden", menuwidth, gettype);
			else
			{
				var argString = '"'+menucontents+'", '+false+', "'+e.type+'", "visible", "hidden",';
				argString += ' "'+menuwidth+'", "'+gettype+'"';
				var funcString = 'showhide(' + argString + ')';
						drop_menu_timeout=setTimeout(funcString,Menu_timeout);
						}
						}
						return clickreturnvalue();
						}

						function clickreturnvalue()
						{
						if (ie4||ns6) return false
						else return true
						}

						function contains_ns6(a, b)
						{
						while (b.parentNode)
						if ((b = b.parentNode) == a)
						return true;
						return false;
						}

						function dynamichide(e)
						{
							if (ie4&&!dropmenuobj.contains(e.toElement))
								delayhidemenu()
							else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
								delayhidemenu()
						}

						function hidemenu(e)
						{
							context_menu_active=0;
							if(!mouse_on_nick)
								show_hide_arrow(false,0,menu_type);
							if (typeof dropmenuobj!="undefined")
							{
								if (ie4||ns6)
								{
									dropmenuobj.style.visibility="hidden";
									update_menu=1;
								}
							}
						}

						function delayhidemenu()
						{
							if (ie4||ns6)
							{
								delayhide=setTimeout("hidemenu()",disappeardelay);
								launch_next_menu=1;
							}
						}

						function clearhidemenu(){
							if (typeof delayhide!="undefined")
								clearTimeout(delayhide)
						}

						if (hidemenu_onclick=="yes")
							document.onclick=hidemenu

								function show_hide_arrow(obj,type,whom)
								{
									if(type)
									{
										if(active_nick!=obj)
											update_menu=1;
										//		alert('active=' + active_nick+ 'menu_type='+menu_type);
										if(active_nick)
											show_hide_arrow(active_nick,0,menu_type);
										active_nick=obj;
										clearTimeout(delayhide);

									}
									clearTimeout(drop_menu_timeout);
									if(!whom)
										whom='user';
									menu_type=whom;
									var class_type=(whom=='user')?'usernav':'communitynav';
									var class_name=(type)?'m-'+class_type+'-active':'m-'+class_type;
									if(active_nick)
										active_nick.className=class_name;
								}
						/***********************************************
						 * Menu Script ends here
						 ***********************************************/

						function repeat_changed(id_pefix)
						{
							var obj=document.getElementById(id_pefix+'repeat');
							var radio=document.getElementsByName(id_pefix+'position');
							for(var i=0;i<radio.length;i++)
							{
								if(obj.value=='repeat')
								{
									radio[i].disabled=true;
									continue;
								}
								if(obj.value=='repeat-x')
								{
									switch(radio[i].value)
									{
										case 'top left':
										case 'center left':
										case 'bottom left':
											radio[i].disabled=false;
											break;
										default:
											radio[i].disabled=true;
											break;
									}
									continue;
								}
								if(obj.value=='repeat-y')
								{
									switch(radio[i].value)
									{
										case 'top left':
										case 'top center':
										case 'top right':
											radio[i].disabled=false;
											break;
										default:
											radio[i].disabled=true;
											break;
									}
									continue;
								}
								radio[i].disabled=false;
								continue;
							}
						}

						/***********************************************
						 * FAVORITES AJAX functions
						 ***********************************************/
						var favorites = new Array();

						var fav_ajax_big_indicator_img = portal_url+"img/sandglass.gif";
						var fav_add_big_img = portal_url+"img/fav.gif";
						var fav_remove_big_img = portal_url+"img/fav-off.gif";

						var fav_ajax_indicator_img = portal_url+"img/sandglass-small.gif";
						var fav_remove_img = portal_url+"img/fav-small-off.gif";
						var fav_add_img = portal_url+"img/fav-small.gif";

						var prev_img = '';

						function addToFavArray(type, id_info, img_size, change_link, id_fav)
						{
							var idx = favorites.length;
							favorites[idx] = new Object();
							favorites[idx].type = type;
							favorites[idx].id_info = id_info;
							favorites[idx].img_size = img_size;
							favorites[idx].change_link = change_link;
							favorites[idx].id_fav = id_fav;
						}

						function FindFav(type, id_info)
						{
							var found_idx=false;
							for(var i=0;i<favorites.length;i++)
							{
								if(favorites[i].type==type && favorites[i].id_info==id_info)
								{
									found_idx=i;
									break;
								}
							}
							return found_idx;
						}

						function Fav(type, id_info)
						{
							idx = FindFav(type, id_info);

							if (idx !== false)
							{
								type = favorites[idx].type;
								id_info = favorites[idx].id_info;
								img_size = favorites[idx].img_size;
								id_fav = favorites[idx].id_fav;
								// REMOVE -----------------------------
								if (id_fav > 0)
								{
									var action = "removefav";
									var return_func = "RemoveFavRequestProcessing";
									var req_name = "RemoveFav";
								}
								// ADD --------------------------------
								else
								{
									var action = "add2fav";
									var return_func = "Add2FavRequestProcessing";
									var req_name = "Add2Fav";
								}

								var fimg = document.getElementById('fav_img_'+type+'_'+id_info);
								if (fimg) {
									prev_img = fimg.src;
									if (img_size == 'big') fimg.src = fav_ajax_big_indicator_img;
									else fimg.src = fav_ajax_indicator_img;
								}
								var URL="/ajax/?Action="+action+"&type="+type+"&id_info="+id_info+"&id_fav="+id_fav+"&idx="+idx;
								LoadData(URL, return_func, req_name);
							}
						}

						function Add2FavRequestProcessing() {return FavRequestProcessing("Add2Fav");}
						function RemoveFavRequestProcessing() {return FavRequestProcessing("RemoveFav");}

						function FavRequestProcessing(req_name)
						{
							var Response=GetXMLResponse(req_name);
							if (Response===false) return;
							if (Response==='') return;

							var AN = Response.getElementsByTagName(req_name);

							if (!AN)
							{
								UnsetRequest(req_name);
								return false;
							}

							AN = AN[0];

							//alert(AN);
							//  var action = AN.getAttribute('action');
							var res = AN.getAttribute('res');
							//	var type  = AN.getAttribute('type');
							//	var id_info  = AN.getAttribute('id_info');
							var idx  = AN.getAttribute('idx');
							//	var idx  = FindFav(type, id_info);

							if (favorites[idx]) {
								var type  = favorites[idx].type;
								var id_info  = favorites[idx].id_info;
								var img_size = favorites[idx].img_size;
								var change_link = favorites[idx].change_link;

								var flink = document.getElementById('fav_link_'+type+'_'+id_info);
								var fimg = document.getElementById('fav_img_'+type+'_'+id_info);

								UnsetRequest(req_name);
								// -----------------------------
								if (req_name == "Add2Fav")
								{
									if (res<0)
									{
										// too many requests
										if (prev_img) fimg.src = prev_img;
										flink.title = fav_too_much;
										fimg.alt = fav_too_much;
										alert(fav_too_much);
										return false;
									}
									else if (res>0)
									{
										favorites[idx].id_fav = res;
										if (change_link) flink.innerHTML = fav_remove;
										flink.title = fav_remove;
										if (img_size == 'big') {fimg.src = fav_remove_big_img;}
										else {fimg.src = fav_remove_img;}
										fimg.alt = fav_remove;
									}
								}
								// -----------------------------
								else if (req_name == "RemoveFav")
								{
									if (res == 1)
									{
										favorites[idx].id_fav = 0;
										if (change_link) flink.innerHTML = fav_add;
										flink.title = fav_add;
										if (img_size == 'big') {fimg.src = fav_add_big_img;}
										else {fimg.src = fav_add_img;}
										fimg.alt = fav_add;
									}
								}
							}
							return res;
						}


						/***********************************************
						 * Additional functions
						 ***********************************************/
						function jsTrim(str){
							return str.replace(/^\s+/,'').replace(/\s+$/,'')
						}

						function jsStripTags(str){
							var re= /<\S[^><]*>/g
								return str.replace(re, "")
						}

						function js_in_array(what, arr){
							var i;
							if (!arr.length)
								return false;

							for(i in arr){
								if (arr[i].toLowerCase() == what.toLowerCase()){
									return true;
								}
							}
							return false;
						}

						function getBodyScrollTop()
						{
							return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
						}

						function getBodyScrollLeft()
						{
							return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
						}

						function getClientWidth()
						{
							return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
						}

						function getClientHeight()
						{
							return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
						}

						function moveCaretToStart(inputObject)
						{
							if (inputObject.createTextRange)
							{
								var r = inputObject.createTextRange();
								r.collapse(true);
								r.select();
							}
						}

						function moveCaretToEnd(inputObject)
						{
							if (inputObject.createTextRange)
							{
								var r = inputObject.createTextRange();
								r.collapse(false);
								r.select();
							}
						}


						function getPageScroll()
						{
							var yScroll = 0;

							if (self.pageYOffset) {
								yScroll = self.pageYOffset;
							} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
								yScroll = document.documentElement.scrollTop;
							} else if (document.body) {// all other Explorers
								yScroll = document.body.scrollTop;
							}

							return yScroll;
						}


						function getPageSize(){

							var xScroll, yScroll;

							if (window.innerHeight && window.scrollMaxY) {
								xScroll = document.body.scrollWidth;
								yScroll = window.innerHeight + window.scrollMaxY;
							} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
								xScroll = document.body.scrollWidth;
								yScroll = document.body.scrollHeight;
							} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
								xScroll = document.body.offsetWidth;
								yScroll = document.body.offsetHeight;
							}

							var windowWidth, windowHeight;
							if (self.innerHeight) {	// all except Explorer
								windowWidth = self.innerWidth;
								windowHeight = self.innerHeight;
							} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
								windowWidth = document.documentElement.clientWidth;
								windowHeight = document.documentElement.clientHeight;
							} else if (document.body) { // other Explorers
								windowWidth = document.body.clientWidth;
								windowHeight = document.body.clientHeight;
							}

							// for small pages with total height less then height of the viewport
							if(yScroll < windowHeight){
								pageHeight = windowHeight;
							} else {
								pageHeight = yScroll;
							}

							// for small pages with total width less then width of the viewport
							if(xScroll < windowWidth){
								pageWidth = windowWidth;
							} else {
								pageWidth = xScroll;
							}

							arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
								return arrayPageSize;
						}



						function hideSelect(obj,form,type)
						{
							if(isMozilla)
								return;
							if(type==1)
								var show='hidden';
							else
								var show='visible';
							//	var form=document.all.appearance_form;
							var left=obj.offsetLeft;
							var top=obj.offsetTop;
							var obj1=obj;
							while(obj1.offsetParent){
								top+= obj1.offsetParent.offsetTop;
								left+= obj1.offsetParent.offsetLeft;
								obj1 = obj1.offsetParent;
							}
							var bottom=top-(-obj.scrollHeight);
							var right=left-(-obj.scrollWidth);
							for(var i=0;i<form.elements.length;i++)
							{
								if(form[i].type=='select-one')
								{
									fl=form[i].offsetLeft;

									ft=form[i].offsetTop;
									obj1=form[i];
									while(obj1.offsetParent){
										ft+= obj1.offsetParent.offsetTop;
										fl+= obj1.offsetParent.offsetLeft;
										obj1 = obj1.offsetParent;
									}
									fb=ft-(-form[i].scrollHeight);
									fr=fl-(-form[i].scrollWidth);
									//			alert(left+","+top+"  "+right+","+bottom+"\n"+fl+","+ft+"  "+fr+","+fb);
									//			alert(ft+","+bottom+"  "+fb+","+top+"  "+fl+","+right+"  "+fr+","+left);
									if(ft<bottom && fb>top && fl<right && fr>left)
									{
										form[i].style.visibility=show;
									}
								}
							}
						}

						function coCheckEmail(email){
							var emailTest = "^[_\\.0-9A-Za-z-]+@([0-9A-Za-z][0-9A-Za-z_-]*\\.)+[A-Za-z]{2,}$";
							var regex = new RegExp(emailTest);
							if (!regex.test(email) || !(email.length > 0))
								return false;

							return true;
						}


						/***********************************************
						 * Adding/Removing From Contacts
						 ***********************************************/
						// in_contacts: 1 - in contact list, 0 - not in contact list
						var IdProcessingArray = new Array();
						var IdContactStatuses = new Array();
						function ContactsRequest(id_user_, in_contacts, userNickObj)
						{
							var c_obj = document.getElementById('id_contact_link_'+id_user_);
							c_obj.style.color='red';
							if (!c_obj.in_contacts)
								c_obj.in_contacts = in_contacts;

							if (!IdContactStatuses[id_user_])
								IdContactStatuses[id_user_] = in_contacts;


							if (IdContactStatuses[id_user_] == 0){
								c_obj.innerHTML = str_contact_adding;
								//c_obj.parentNode.className = 'usermenu-contact remove';
							}else{
								c_obj.innerHTML = str_contact_removing;
								//c_obj.parentNode.className = 'usermenu-contact';
							}
							if (IdProcessingArray[id_user_])
								return false;

							IdProcessingArray[id_user_] = 1;
							var URL="/ajax/?Action=contact&id_user_="+id_user_;
							LoadData(URL,"ContactsRequestProcessing","ContactsRequest");

						}

						function getCookie(sName)
						{
							// cookies are separated by semicolons
							var aCookie = document.cookie.split("; ");
							for (var i=0; i < aCookie.length; i++)
							{
								// a name/value pair (a crumb) is separated by an equal sign
								var aCrumb = aCookie[i].split("=");
								if (sName == aCrumb[0])
									return unescape(aCrumb[1]);
							}
							// a cookie with the requested name does not exist
							return null;
						}

						function createCookie(name,value,days,domain) {
							if (days) {
								var date = new Date();
								date.setTime(date.getTime()+(days*24*60*60*1000));
								var expires = "; expires="+date.toGMTString();
							}
							else var expires = "";
							document.cookie = name+"="+value+expires+"; path=/; domain="+domain;
						}



						function ContactsRequestProcessing(){
							var Response=GetXMLResponse("ContactsRequest");
							if (Response===false) return;
							if (Response==='') return;
							var AN = Response.getElementsByTagName("ContactsRequest");
							if (!AN)
							{
								UnsetRequest("ContactsRequest");
								return false;
							}
							AN = AN[0];
							var id_user_     = AN.getAttribute('id_user_');
							var in_contacts  = AN.getAttribute('in_contacts');

							var c_obj = document.getElementById('id_contact_link_'+id_user_);
							c_obj.style.color='';
							IdProcessingArray[id_user_] = 0;
							IdContactStatuses[id_user_] = in_contacts;

							if (IdContactStatuses[id_user_] == 0)
								c_obj.innerHTML = str_contact_add;
							else
								c_obj.innerHTML = str_contact_remove;

							UnsetRequest("ContactsRequest");
						}
	function $(element) {
	if (arguments.length > 1) {
		for (var i = 0, elements = [], length = arguments.length; i < length; i++)
			elements.push($(arguments[i]));
		return elements;
	}
	if (typeof element == 'string')
		element = document.getElementById(element);
	return element;
}

function disable_controls()
{
	for(var i = 0; i < document.links.length; i++ )
	{
		if(document.links[i].className != 'preview_link')
		{
			document.links[i].onclick = return_false;
			document.links[i].href = 'javascript:void(0);';
			document.links[i].onmouseover = return_false;
			document.links[i].onmousemove = return_false;
		}
	}

	var forms = document.getElementsByTagName('form');
	for(var i = 0; i < forms.length; i++ )
	{
		forms[i].onsubmit = return_false;
	}

	var imgs = document.getElementsByTagName('img');
	for(var i = 0; i < imgs.length; i++ )
	{
		imgs[i].onmouseover = return_false;
		imgs[i].onmousemove = return_false;
	}

	var buttons = document.getElementsByTagName('button');
	for(var i = 0; i < buttons.length; i++ )
	{
		buttons[i].onclick = return_false;
	}
}

function return_false()
{
	return false;
}

}
setOnLoadHandler('show_homepage_icon', showHomepageIcon);


/************************************************/
/* PopupMenu                                    */
/************************************************/

(function()
{
    var UA = navigator.userAgent;
    is_gecko = /gecko/i.test(UA);
    is_opera = /opera/i.test(UA);
    is_mac = /mac_powerpc/i.test(UA);
    is_ie = /msie/i.test(UA) && !is_opera && !is_gecko && !is_mac;
    is_ie5 = is_ie && /msie 5\.[^5]/i.test(UA);
    is_nn4 = document.layers ? true : false;
})();

function PopupMenu()
{
}

PopupMenu.div = null;
PopupMenu.timer = null;
PopupMenu.showDiv = 0;
PopupMenu.overDiv = 0;

PopupMenu.sessionId = null;
PopupMenu.photoId = null;
PopupMenu.manuHtml = null;

PopupMenu.popupDiv = function(e, paramsArr)
{
    var x = e.clientX;
    var y = e.clientY;

    PopupMenu.prepareDiv(paramsArr);
    PopupMenu.timer = setTimeout("showPopupMenu(" + x + "," + y + ")", 600);
}

PopupMenu.hideDiv = function()
{
    if (PopupMenu.timer)
    {
        clearTimeout(PopupMenu.timer);
        PopupMenu.timer = null;
    }

    if (PopupMenu.showDiv == "1")
    {
        PopupMenu.overDiv = 0;
        setTimeout('closePopupMenu()', 500);
    }
}

var closePopupMenu = function()
{
    var div = E('popupDivBlock');

    if (PopupMenu.overDiv == "0")
    {
        div.style.visibility = "hidden";
        PopupMenu.showDiv = 0;
    }
}

PopupMenu.continueDiv = function()
{
    if (PopupMenu.showDiv == "1")
    {
        PopupMenu.overDiv = "1";
    }
}

PopupMenu.continueEndDiv = function()
{
    if (PopupMenu.showDiv == "1")
    {
        PopupMenu.overDiv = "0";
        setTimeout('closePopupMenu()', 500);
    }
}

PopupMenu.prepareDiv = function(paramsArr) {
    var menuHtml = '';
    paramsArr = eval('(' + paramsArr + ')');

	for(var i = 0; i<paramsArr.length; i++)
	{
        if (paramsArr[i]['type'] == 'href') {
            menuHtml += "<div class=\"newMenuRow\"><a href=\"" + paramsArr[i]['href'] + "\" class=\"newMenuLink\">" + paramsArr[i]['caption'] + "</a></div>";
        } else if (paramsArr[i]['type'] == 'nick') {
            menuHtml += "<div class=\"newMenuNick\">" + paramsArr[i]['caption'] + "</div>";
        } else if (paramsArr[i]['type'] == 'hr') {
            menuHtml += "<div class=\"newMenuHr\"></div>";
        } else if (paramsArr[i]['type'] == 'function') {
            switch (paramsArr[i]['func']){
        		case 'contact':
                    if (IdContactStatuses[paramsArr[i]['userid']])
                    	inContacts = IdContactStatuses[paramsArr[i]['userid']];
                    else
                        inContacts = paramsArr[i]['inContacts'];

                    if (inContacts == "1")
                        caption = str_contact_remove;
                    else
                        caption = str_contact_add;

        		    menuHtml += "<div class=\"newMenuRow\"><a href=\"javascript:void(0);\" class=\"newMenuLink\" id=\"id_contact_link_" + paramsArr[i]['userid'] + "\" onclick=\"ContactsRequest(" + paramsArr[i]['userid'] + ", " + inContacts + ", _this);\" >" + caption + "</a></div>";
        		break;
            }
        } else if (paramsArr[i]['type'] == 'user_action') {
            switch (paramsArr[i]['action']){
        		case 'sendmessage':
        		menuHtml += "<div class=\"newMenuRow\"><a href=\"javascript:void(0);\" onclick=\"popupWindow('" + paramsArr[i]['url'] + "', '', 500, 410);\" class=\"newMenuLink\">" + paramsArr[i]['caption'] + "</a></div>";
        		break;
        		case 'friend_request':
        		menuHtml += "<div class=\"newMenuRow\"><a href=\"javascript:void(0);\" onclick=\"popupWindow('" + paramsArr[i]['url'] + "', '', 500, 300);\" class=\"newMenuLink\">" + paramsArr[i]['caption'] + "</a></div>";
        		break;
        		case 'wink':
        		menuHtml += "<div class=\"newMenuRow\"><a href=\"javascript:void(0);\" onclick=\"showUserActions('" + paramsArr[i]['to'] + "', '" + paramsArr[i]['nick'] + "', 'wink');\" class=\"newMenuLink\">" + paramsArr[i]['caption'] + "</a></div>";
        		break;
        		case 'kick':
        		menuHtml += "<div class=\"newMenuRow\"><a href=\"javascript:void(0);\" onclick=\"showUserActions('" + paramsArr[i]['to'] + "', '" + paramsArr[i]['nick'] + "', 'kick');\" class=\"newMenuLink\">" + paramsArr[i]['caption'] + "</a></div>";
        		break;
            }
        }
	}
	PopupMenu.menuHtml = menuHtml;
}

var showPopupMenu = function(x, y)
{
    var div = E('popupDivBlock');

    if (document.documentElement.clientWidth && document.documentElement.clientWidth - x < 200)
        x -= 200;
    else
        x += 5;

    if (document.documentElement.clientHeight && document.documentElement.clientHeight - y < 240)
        y -= 240;

    if (document.documentElement.scrollLeft)
        x += document.documentElement.scrollLeft;
    else if (document.body.scrollLeft)  // for safari
        x += document.body.scrollLeft;

    if (document.documentElement.scrollTop)
        y += document.documentElement.scrollTop;
    else if (document.body.scrollTop)  // for safari
        y += document.body.scrollTop;

    if (is_nn4)
    {
        div.left = x;
        div.top = y;
    }
    else if (is_ie)
    {
        div.style.pixelLeft = x;
        div.style.pixelTop = y;
    }
    else
    {
        div.style.left = x + "px";
        div.style.top = y + "px";
    }

    div.innerHTML = PopupMenu.menuHtml;
    div.style.visibility = 'visible';
    PopupMenu.showDiv = 1;
}
