function addHandler(obj, event, action) { 
            if(document.addEventListener) { 
                 obj.addEventListener(event, action, false); 
            } else if(document.attachEvent) { 
                 obj.attachEvent('on' + event, action); 
            } else { 
                 obj['on' + event] = action; 
            } 
        
            obj['has' + event] = true; 
       } 
 $$  = function(id)
 {
 	return document.getElementById(id);
 }
 $$.query = function(className, method, args, data, callback)
 {
 	
 }
 $$.setUP = function(id, obj)
 {
 	if(!obj)
 	{
 		return;
 	}
 	obj.ident = id;
 	if(window.UP == undefined)
 	{
 		window.UP = [];
 	}
 	obj.onmouseout = function()
 	{
 		window.UP[this.ident] = false;
 		setTimeout(function()
 		{
 			if(!window.UP[id])
 			{
 				$$.slide(obj);
 			}
 		}, 500);
 	}
 	obj.onmouseover = function() {window.UP[this.ident] = true;} 
 }
 $$.slide = function(el, speed, callback)
{
	if($$.isMSIE())
	{
		if(el.style.display == 'none')
		{
			var d = el.cloneNode(true);
			el.parentNode.insertBefore(d, el);
			var tmp = function()
			{
				d.parentNode.removeChild(d);
				$(el).css('display', '');	
				if(callback)
				{
					new callback;
				}
			}
			$(d).slideDown(speed, tmp);
		}
		else
		{
			$(el).slideUp(speed, callback);
		}
	}
	else
	{
		el.style.display == 'none' ? $(el).slideDown(speed, callback) : $(el).slideUp(speed, callback);
	}
}

$$.openContact = function (contactId, debugers)
{
	var dStr = debugers ? '&debugers' : '';  
	window.open('/contact/?id=' + contactId + dStr, '', 'width=500,height=600,resizable=no,scrollbars=yes');
} 
$$.createContact = function (userId, debugers, text)
{
	var dStr = debugers ? '&debugers' : '';  
	dStr += text ? '&text=' + text : '';
	window.open('/contact/?id=0&user=' + userId + dStr, '', 'width=500,height=600,resizable=no,scrollbars=yes');
} 
$$.openUserGallery = function(companyId, userId)
{
	window.open('/gallery/?company=' + companyId + '&user=' + userId, '', 'height=600,width=800,scrollbars=yes');
}
$$.isChrome = function()
{
	return false;
}
$$.isFirefox = function()
{
	return !$$.isMSIE() && !$$.isSafari() && !$$.isChrome();
}
$$.isMSIE = function()
{
	return (document.all && !$$.isOpera() && !$$.isSafari() ? true : false);
}
$$.isOpera = function()
{
	return navigator.userAgent.indexOf ("Opera") != -1 ;
}
$$.isSafari = function()
{
	return navigator.userAgent.indexOf ("Safari") != -1 ;
}

$$.print = function(obj, getOnlyNoneEmpty)
{
	var s = '';
	for(var i in obj)
	{
		if((obj[i] != undefined && obj[i].length != undefined) || !getOnlyNoneEmpty)
		{
			s += i + ': ' + obj[i] + "\r\n";
		}
	}
	return s;
}

$$.getJSON = function(jsonString)
{
	eval(" var tmp = " + jsonString);
	return tmp;
}

$$.addToNotebook = function(event, type, id, doNotShow)
	{
		if(!event)
		{
			event = window.event;
		}
		if(!doNotShow)
		{
			this.showSavingProcess(event);
		}
		$.post(	'/_engine/controllers.php', 
				{
					'd': JSON.stringify({
						'vars':
						{
							'type':		type,
							'data':		id
						},
						'class':	'Labyrinth_NE_Notepad',
						'method':	'add'})
				}, 
				function(r)
				{
					var r = $$.getJSON(r);
					if(r.errors.length)
					{
						alert(r.errors);
					}					
				});
	}

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

$$.getBodyScrollTop = function()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}	
	
$$.showSavingProcess = function(event)
	{
		if(!this.savingIcon)
		{
			this.savingIcon 				= document.createElement("img");
			this.savingIcon.src 			= "/img2/notebook_add.gif";
			this.savingIcon.style.display	= "none";
			this.savingIcon.style.position 	= "absolute";
			this.savingIcon.style.zIndex	= 1020;
			document.body.appendChild(this.savingIcon);
		}
		if(!event)
		{
			event = window.event;
		}
		var y = $$.getBodyScrollTop() + event.clientY;
		var x = $$.getBodyScrollLeft() + event.clientX;	

		if(this.savingIcon.parentNode != document.body)
		{
			document.body.appendChild(this.savingIcon);
		}
		this.savingIcon.style.display = "block";
		this.savingIcon.style.left	= (x - this.savingIcon.offsetWidth / 2) + 'px';
		this.savingIcon.style.top	= (y - this.savingIcon.offsetHeight / 2) + 'px';
		this.savingIconUp();
	}
$$.savingIconUp = function()
	{
		if(parseInt($$.savingIcon.style.top) > 0)
		{
			$$.savingIcon.style.top = (parseInt($$.savingIcon.style.top) - 10) + 'px';			
			setTimeout($$.savingIconUp, 1);
		}
		else
		{
			$$.savingIcon.style.display = "none";
		}
	}
	
$$.TextField = function(obj)
{
	
	obj.setInnerDescription = function(text)
	{
		this.innerDescription 	= text;
		
		this.onfocus = function()
		{
			if(this.value == this.innerDescription)
			{
				this.value = '';
				this.removeStopper();
			}
		}
		if(this.onblur)
		{
			this.callOnblur = this.onblur;
		}
		this.onblur = function()
		{
			if(this.value == '')
			{
				this.value = this.innerDescription;
				this.attachStopper();
			}
			if(this.callOnblur)
			{
				this.callOnblur();
			}
		}		
		if(this.value == '')
		{
			this.value = this.innerDescription;
			this.attachStopper();
		}
	}	
	
	obj.makeNumeric = function()
	{
		if(this.onkeyup != undefined)
		{
			this.callOnkeyup = this.onkeyup;
		}
		this.onkeyup = function()
		{
			if(this.value.length > 0)
			{
				var v = parseInt(this.value);
				var l = this.value.length;
				while(isNaN(v) && l > 0)
				{
					v = parseInt(this.value.substr(0, --l));
				}
				if(l==0)
				{
					v = 0;
				}
				this.value = v;				
			}
			if(this.callOnkeyup != undefined)
			{
				this.callOnkeyup();
			}
		}
	}
	
	obj.attachStopper = function()
	{
		if(this.stopper == undefined)
		{
			this.stopper 			= document.createElement('input');
			this.stopper.type		= 'hidden';
			this.stopper.name 		= this.name;
			this.stopper.value		= '';
		}
		this.parentNode.appendChild(this.stopper);
		this.stopper.attached = true;
	}
	
	obj.attachMirror = function(mirror, limit, prefix, postfix, firstSource)
	{
		var exe	= this;
		prefix	= prefix 	? prefix 	: '';
		postfix	= postfix	? postfix 	: '';
		this.__callback = this.onkeyup;
		this.onkeyup = function()
		{
			if(!firstSource || firstSource.value.length == 0)
			{
				var v = limit > 0 ? exe.value.substr(0, limit) : exe.value;
				mirror.innerHTML = prefix + v + postfix;
			}
			if(this.__callback)
			{
				this.__callback();
			}
		}
		if(firstSource)
		{
			var callback_2 = firstSource.onkeyup;
			firstSource.onkeyup = function()
			{				
				if(callback_2)
				{
					callback_2();
				}
				if(this.value.length == 0)
				{
					var v = limit > 0 ? exe.value.substr(0, limit) : exe.value;
					mirror.innerHTML = prefix + v + postfix;
				}
			}
		}
	}
	
	obj.removeStopper = function()
	{
		if(this.stopper != undefined)
		{
			this.stopper.parentNode.removeChild(this.stopper);
		}
	}
	
	obj.setMaxLength = function(limit)
	{
		var exe = this;
		var callback = this.onkeyup;
		this.onkeyup = function()
		{
			if(exe.value.length > limit)
			{
				exe.value = exe.value.substr(0, limit);
			}
			if(callback)
			{
				callback();
			}
		}
	}
	
	return obj;
}

$$.createPassOpener = function(passId, openerId)  
	{
		var pass 	= document.getElementById(passId);
		var opener	= document.getElementById(openerId);
		if(!pass || !opener)
		{
			return false;
		}
		var text	= document.createElement("input");
		opener.changeMode = false;
		pass.opener = opener;
		text.opener = opener;
		pass.active = true;
		text.active = false;
		text.value	= pass.value;
		text.type 	= 'text';
		text.size	= pass.size;
		text.style.display = 'none';
		text.id = opener.id + "_text";
		pass.parentNode.insertBefore(text, pass);
		pass.f = text.f = opener.f = {'opener': opener, 'pass': pass, 'text': text};
		opener.onclick = function()
		{
			this.changeMode = true;
			this.f["pass"].active = !this.f["pass"].active;
			$$.slide(this.f["pass"]);//alert('1');
			this.f["text"].active = !this.f["text"].active;			
			$$.slide(this.f["text"]);
			this.changeMode = false;
			try
			{
				this.f["pass"].focus();
			}
			catch(e)
			{
				this.f["text"].focus();
			}
		}
		pass.onkeyup = function()
		{
			if(this.active && !this.opener.changeMode)
			{
				this.f["text"].value = this.value;
			}
		}
		text.onkeyup = function()
		{
			if(this.active && !this.opener.changeMode)
			{
				this.f["pass"].value = this.value;
			}
		}
	}
