function urlCleanup(url, arr) {
    var new_url = new String;
	var new_url = '';
    url_org = url.split('?');
	
    if (url_org[1]) {
		url = url_org[1].split('#');
        url = url[0].split('&');
    	if (arr && (arr.length > 0)) {
			for(var u=0; u<url.length; u++) {
				if (typeof(url[u]) != 'undefined' && url[u] != '') {
					val = url[u].split('=');
					da_eba_javascript = false;
					for(var i=0; i<arr.length; i++) {
						da_eba_javascript = (val[0] == arr[i]) && (val[1] != '');
						if (da_eba_javascript === true) break;
                    }
					if (da_eba_javascript !== true) {
						new_url = new_url + '&' + val[0] + '=' + val[1];
						i=arr.length;
					}
                }
            }
        }
    } else {
		url_org = url.split('#');
		new_url = '';
	}
	
	new_url = url_org[0] +  (new_url != '' ? '?' + new_url.substring(1) : (!arr ? '' : '?')); //
    return new_url;
}

function $(obj_id) {
    if (typeof(obj_id) == 'object') {
        return obj_id;
    } else {
        return document.getElementById(obj_id)
    }
}

function $$(obj_id) {
    if (typeof(obj_id) == 'object') {
        return obj_id;
    } else {
        return document.getElementById(obj_id)
    }
}

function show(obj, type) {
    type = type ? type : 'block';
    
    $(obj).style.display = type;
}

function showEffect(obj, effect, type) {
    if (!obj) return false;
    
    var display = $(obj).style.display;
    
    type = type ? type : 'block';
	
    $(obj).style.display = type;
	if (effect) effect();
}

function hide(obj) {
    if ($(obj)) {
        $(obj).style.display = 'none';
    }
}

function checkSubmit(e, form) {
    if (!e) e = window.event;
    
    var code = e.keyCode || e.which;
    if(code == 13) {
        form.submit();
    }
}

function removeNode(el) {
    if (!el) return;
    
    if (el.parentNode) {
        fadeOut(el, 80, function () {el.parentNode.removeChild(el);});
    }
}

function nextNode(obj, count) {
	if(typeof(obj) != 'object') return null;
	
	var n = obj;
	count = count ? count : 1;
    
	while(count > 0) {
		do (n && (n = n.nextSibling));
		while (n && n.nodeType != 1);
		count--;
	}
	
	return count == 0 ? n : null;
}

function prevNode(obj, count) {
	if(typeof(obj) != 'object') return null;
	
	var n = obj;
	count = count ? count : 1;
    
	while(count > 0) {
		do (n && (n  = n.previousSibling));
		while (n && n.nodeType != 1);
		count--;
	}
	
	return count == 0 ? n : null;
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return {"0": scrOfX, "1": scrOfY, "x": scrOfX, "y": scrOfY};
}

function windowSize() {
    var myWidth = 0,
        myHeight = 0;
  
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    
    return {"0": myWidth, "1": myHeight, "width": myWidth, "height": myHeight};
}

function findPosXDR(obj){
	var curleft = 0;
	
	if(obj.offsetParent)
		while(obj) {
			if (getStyle(obj, 'position') == 'relative') {
				return curleft;
			}
			
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	
	return curleft;
}

function findPosYDR(obj){
	var curtop = 0;
	
	if(obj.offsetParent)
		while(obj) {
			if (getStyle(obj, 'position') == 'relative') {
				return curtop;
			}
			
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
		
	return curtop;
}


function findPosX(obj){
	var curleft = 0;
	
	if(obj.offsetParent)
		while(obj) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	
	if(obj.offsetParent)
		while(obj) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
		
	return curtop;
}

function setOpacity(obj, opacity) {
	obj.style.zoom 				= 1;
	obj.style.opacity 			= (opacity / 100);
    obj.style.MozOpacity 		= (opacity / 100);
    obj.style.KhtmlOpacity 		= (opacity / 100);
    obj.style.filter 			= 'alpha(opacity=' + opacity + ')';
}

function fadeIn(obj, opacity, onComplete, maxOpacity) {
	if (obj.timeout) clearTimeout(obj.timeout);
    
    var max_op = maxOpacity ? maxOpacity : 100;
	
	obj._opacity = opacity;
	setOpacity(obj, obj._opacity);
	
	var time_step = (obj.style.KhtmlOpacity) ? 15 : 35,
		step = parseInt((max_op - opacity) * time_step / 200);
	
	obj.timeout = setInterval(function () { _fade_in(obj, onComplete, max_op, step); }, time_step);
}

	function _fade_in(obj, onComplete, max_op, step) {
		if (obj._opacity > max_op) {
			if (obj.timeout) clearInterval(obj.timeout);
			
			setOpacity(obj, max_op);
			if (onComplete) onComplete();
		} else {
			obj._opacity += step;
			setOpacity(obj, obj._opacity);
		}
	}


function fadeOut (obj, opacity, onComplete, minOpacity) {
	if(!obj) return;
	
	if (obj.timeout) clearTimeout(obj.timeout);
	
    var min_op = minOpacity ? minOpacity : 0;
	
	obj._opacity = opacity;
	setOpacity(obj, obj._opacity);
	
	var time_step = (obj.style.KhtmlOpacity) ? 15 : 35,
		step = parseInt((opacity - Math.abs(min_op)) * time_step / 200);
	
	obj.timeout = setInterval(function () { _fade_out(obj, onComplete, min_op, step); }, time_step);
}

	function _fade_out(obj, onComplete, min_op, step) {
		if (obj._opacity < min_op) {
			if (obj.timeout) clearInterval(obj.timeout);
			setOpacity(obj, min_op);
			
			if (!min_op && obj) obj.style.display = 'none';
			if (onComplete) onComplete();
		} else {
			obj._opacity -= step;
			setOpacity(obj, obj._opacity);
		}
	}

function toggle(obj, type) {
    if (!obj) return false;
    
    var display = $(obj).style.display;
    
    type = type ? type : 'block';
    
    
    if (display == 'none' || display == ''){
        
        $(obj).style.display = type;
    } else {
        
        $(obj).style.display = 'none';
    }
}

function toggleEffect(obj, effectIn, effectOut, link, type) {
    if (!obj) return false;
    
    var display = $(obj).style.display;
    
    type = type ? type : 'block';
	
    if (display == 'none' || display == ''){
		$(obj).style.display = type;
		if (effectOut) effectOut();
    } else {
		document.onclick = null;
		if (effectIn) effectIn();
		else $(obj).style.display = 'none';
    }
}

function flash(obj, color, count, onCompleate) {
	if(!obj) return false;
	
	if(count <= 0) {
		obj.style.background = obj.old_background;
		if(onCompleate) onCompleate();
		return false;
	}
	
	if(this.flashTimeout) clearTimeout(this.flashTimeout);
	
	count = count ? count : 6;
	color = color ? color : '#FF0000';
	
	if (typeof(obj.old_background) == 'undefined') obj.old_background = obj.style.background ? obj.style.background : '';
	
	obj.style.background = count % 2 == 1 ? color : obj.old_background;
	
	
	
	count--;
	this.flashTimeout = setTimeout(function() {flash(obj, color, count, onCompleate);}, 40);
}

function InsertEmote(msgboxid, emotecode) {
    var msgbox = $(msgboxid);
    
    msgbox.value += "" + emotecode + " ";
    if ($('emote_list')) $('emote_list').style.display = "none";
    msgbox.focus();
    
    return false;
}

function checkUncheck(obj_name, value) {
    var list = document.getElementsByName(obj_name);
    
    for(var i=0; i<list.length; i++) {
        list[i].checked = value;
    }
}

function checkForm(msg, error, inp_name) {
    var list = document.getElementsByName(inp_name),
        res = false;
    
    for(var i=0; i<list.length; i++) {
        res = res || list[i].checked;
    }
    
    if(res) {
        return confirm(msg);
    }
    
    alert(error);
    return res;
}

function getElementsByName(name, type) {
	if (type && type.indexOf(',') >= 0) {
		type = type.split(',');
		var arr = new Array();
		
		for(var j=0; j<type.length; j++) {
			var tags = document.getElementsByTagName(type[j]);
			var debug = new String();
			
			for(var i = 0, iarr = arr.length; i < tags.length; i++) {
				att = tags[i].getAttribute("name");
				
				if(att == name) {
					arr[iarr] = tags[i];
					iarr++;
				}
			}
			
			
		}
	} else {
		var tags = document.getElementsByTagName(type ? type : "div");
		var arr = new Array();
		for(var i = 0,iarr = 0; i < tags.length; i++) {
			 att = tags[i].getAttribute("name");
			 if(att == name) {
				  arr[iarr] = tags[i];
				  iarr++;
			 }
		}
	}
	return arr;
}

function extend(obj, from_obj) {
    if(from_obj && typeof(from_obj) == 'object') {
        for(var i in from_obj) obj[i] = from_obj[i];
    }
}

function stopEvent(e) {
    if(!e) return;
    
    if(e.stopPropagation) e.stopPropagation();
    if(e.preventDefault) e.preventDefault();
    e.cancelBubble = true;
	e.returnValue = false;
}

RegExp.escape = function(text) {
  if (!arguments.callee.sRE) {
    var specials = [
      '/', '.', '*', '+', '?', '|',
      '(', ')', '[', ']', '{', '}', '\\'
    ];
    arguments.callee.sRE = new RegExp(
      '(\\' + specials.join('|\\') + ')', 'g'
    );
  }
  return text.replace(arguments.callee.sRE, '\\$1');
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function br2nl(txt) {
	return txt.replace(/<br(\s+)?\/?>/gi, "\n");
}

function nl2br(txt) {
	return txt.replace(/\n/gi, "<br />");
}

function Confirm(text, e, btn_ok_txt, btn_cancel_txt) {
	!e && (e = window.event);
	
	stopEvent(e);
	
	targ = e.target || e.srcElement;
	targ.nodeType == 3 && (targ = targ.parentNode);
	
	btn_ok_txt = btn_ok_txt ? btn_ok_txt : 'OK';
	btn_cancel_txt = btn_cancel_txt ? btn_cancel_txt : 'Cancel';
	
	window.popup_win && window.popup_win.hide() && (delete window.popup_win);
	window.popup_win = new PopupWindow('', 'dialog-std top-border');
	
	
	function buttons() {
		return [new Button(btn_ok_txt, 'input-submit', function () {targ.href && (location.href=targ.href) && window.popup_win.hide();} ),
				new Button(btn_cancel_txt, 'input-button', function () {window.popup_win.hide(); } ) ];
	}
	function content() {
		var cont = document.createElement('div');
		cont.appendChild(document.createTextNode(text));
		return cont;
	}
	
	var cont = document.body.firstChild.nodeType == 1 && document.body.firstChild || nextNode(document.body.firstChild);
	window.popup_win.display(cont, content, buttons, 'center');
	
	return false;
}


function getElementsByClassName(classname,node){
	if(!node)node=document.getElementsByTagName("body")[0];
	var a=[];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	
	for(var i=0,j=els.length;i<j;i++){
		if(re.test(els[i].className)) a.push(els[i]);
	}
	return a;
}

function EffectSquashIn(obj, type, step) {
	$(obj).style.overflow = 'hidden';
	
	var width = parseInt($(obj).style.width) > 0 ? parseInt($(obj).style.width) : parseInt($(obj).clientWidth),
		height = parseInt($(obj).style.height) > 0 ? parseInt($(obj).style.height) : parseInt($(obj).clientHeight);
	
	step = step && step > 0 ? step : 5;
	
	if (type == 'horizontal') {
		width -= 5;
		if (width > 0) {
			$(obj).style.width = width+'px';
			setTimeout(function () {EffectSquashIn(obj, type, step)}, 10);
		} else {
			$(obj).style.display = 'none';
		}
	} else {
		height -= 5;
		if (height > 0) {
			$(obj).style.height = height+'px';
			setTimeout(function () {EffectSquashIn(obj, type, step)}, 10);
		} else {
			$(obj).style.display = 'none';
		}
	}
}

function EffectSquashOut(obj, to, link, type, step, dont_handle_document) {
	$(obj).style.overflow = 'hidden';
	
	var width = parseInt($(obj).style.width) > 0 ? parseInt($(obj).style.width) : parseInt($(obj).clientWidth),
		height = parseInt($(obj).style.height) > 0 ? parseInt($(obj).style.height) : parseInt($(obj).clientHeight);
	
	step = step && step > 0 ? step : 5;
	
	if(height >= to && ($(obj).style.display == 'block' || $(obj).style.display == '')) {
		EffectSquashIn(obj, type, step);
		return false;
	}
	
	if (type == 'horizontal') {
		width += 5;
		if (width < to) {
			$(obj).style.width = width+'px';
			setTimeout(function () {EffectSquashOut(obj, to, link, type, step, dont_handle_document)}, 10);
		} else {
			$(obj).style.width = to+'px';
			if (!dont_handle_document) {
				handle_onclick($(obj), link, function () {document.onclick = null;EffectSquashIn(obj, type, step)});
			}
		}
	} else {
		height += 5;
		
		if (height < to) {
			$(obj).style.height = height+'px';
			setTimeout(function () {EffectSquashOut(obj, to, link, type, step, dont_handle_document)}, 10);
		} else {
			$(obj).style.height = to+'px';
			if (!dont_handle_document){
				handle_onclick($(obj), link, function (e) {document.onclick = null;EffectSquashIn(obj, type, step);});
			}
		}
	}
}


function setPosTo(obj, link, rel) {
	var height = (document.all) ? link.clientHeight + 2 : link.scrollHeight;
	if (rel) {
		$(obj).style.left = findPosXDR(link)+'px';
		$(obj).style.top = findPosYDR(link)+(height)+1+'px';
	} else {
		$(obj).style.left = findPosX(link)+'px';
		$(obj).style.top = findPosY(link)+(height)+1+'px';
	}
}


function Search_(inp, def_text, tr) {
    var oThis = this;
	
    this.def_text = def_text;
	
	
	$('select_type_link').onclick = function (event) {
		if(!event) event = window.event;
		
		stopEvent(event);
		
		setPosTo(window.search_panel, $('select_type_link'));
		toggleEffect(window.search_panel,
			function(){EffectSquashIn(window.search_panel);},
			function(){EffectSquashOut(window.search_panel, 50, $('select_type_link'));}, $('select_type_link'));
	}
	
    this.selectSearch = function (type, dont_show) {
		if(!dont_show) {
			setPosTo(window.search_panel, $('select_type_link'));
			toggleEffect(window.search_panel,
				function(){EffectSquashIn(window.search_panel);},
				function(){EffectSquashOut(window.search_panel, 50, $('select_type_link'));}, $('select_type_link'));
		}
		
		
		var t = "SEARCH_IN_" + type.toUpperCase();
		if (inp.value == oThis.def_text) {
			inp.value = tr[t];
		}
		oThis.def_text = tr[t];
		
		$('search_in').value = type;
		$('select_type_link').getElementsByTagName('span')[0].className = 'nav-'+type;
	}
	
    this.onFocus = function () {
		if (inp.value == oThis.def_text) {
			inp.value = "";
			inp.className = "searchq";
		}
	}
    this.onBlur = function () {
		if (inp.value == "") {
			inp.value = oThis.def_text;
			inp.className = "searchq-inactive";
		}
	};
    this.onSubmit = function () {
		if (inp.value == oThis.def_text) {
			inp.value = "";
		}
		
		return true;
	};
	
    $(inp).onfocus = function () {oThis.onFocus();};
    $(inp).onblur = function () {oThis.onBlur();};
    $(inp).form.onsubmit = function () {oThis.onSubmit();};
	
	
	if(!window.search_panel) {
		window.search_panel = document.createElement('div');
		window.search_panel.style.display = 'none';
		window.search_panel.className = 'select_type';
		
		$('main-conteiner').appendChild(window.search_panel);
		
		for(var i in tr) {
			var f = i.replace('SEARCH_IN_', '').toLowerCase().charAt(0).toUpperCase();
			var type = f + i.replace('SEARCH_IN_', '').toLowerCase().substr(1);
			var a = document.createElement('a'),
				span = document.createElement('span');
			
			a.appendChild(span);
			a.appendChild(document.createTextNode(type));
			a.type = type.toLowerCase();
			a.onclick = function (e, dont_show) {
				oThis.selectSearch(this.type, dont_show);
				return false;
			}
			a.className = 'nav-'+type.toLowerCase();
			
			window.search_panel[a.type] = a;
			
			window.search_panel.appendChild(a);
		}
	}
}

function handle_onclick(obj, link, onclick) {
    obj.onclick = function (e) {if (!e) {e = window.event;}if (e.stopPropagation) {e.stopPropagation();}e.cancelBubble = true;};
    document.onclick = function (e) {if (!e) {e = window.event;}var rightclick = false;if (e.which) {rightclick = e.which == 3;} else if (e.button) {rightclick = e.button == 2;}if (rightclick) {return;}if (onclick) {onclick();} else {toggle(obj);}document.onclick = null;};
    return false;
}



/* ProtoType Compatibility */
Object.extend = function(destination, source) {
  for (var property in source)
    destination[property] = source[property];
  return destination;
};

function getStyle( element, cssRule ) {
	if( document.defaultView && document.defaultView.getComputedStyle ) {
	  var value = document.defaultView.getComputedStyle( element, '' ).getPropertyValue( cssRule.replace( /[A-Z]/g,
		  function( match, char ){ 
			  return "-" + char.toLowerCase(); 
		  }
		) 
	  );
	}
	else if ( element.currentStyle ) var value = element.currentStyle[ cssRule ];
	else                             var value = false;
		return value;
}
getDimensions = function(element) {
	var display = getStyle(element, 'display');
	if (display != 'none' && display != null) // Safari bug
	  return {width: element.offsetWidth, height: element.offsetHeight};
	
	// All *Width and *Height properties give 0 on elements with display none,
	// so enable the element temporarily
	var els = element.style;
	var originalVisibility = els.visibility;
	var originalPosition = els.position;
	var originalDisplay = els.display;
	els.visibility = 'hidden';
	els.position = 'absolute';
	els.display = 'block';
	var originalWidth = element.clientWidth;
	var originalHeight = element.clientHeight;
	els.display = originalDisplay;
	els.position = originalPosition;
	els.visibility = originalVisibility;
	return {width: originalWidth, height: originalHeight};
}

function cumulativeOffset(element) {
	var valueT = findPosYDR(element), valueL = findPosXDR(element);
	
	return _returnOffset(valueL, valueT);
}

function getWidth(element) {
	return getDimensions(element).width;
}

function getHeight(element) {
	return getDimensions(element).height;
}

function _returnOffset(l, t) {
  var result = [l, t];
  result.left = l;
  result.top = t;
  return result;
}
function bindAsEventListener (__method) {
	var args = $A(arguments), object = args.shift();
	return function(event) {
		return __method.apply(object, [event || window.event].concat(args));
	}
}
function $A(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) return iterable.toArray();
  var length = iterable.length, results = new Array(length);
  while (length--) results[length] = iterable[length];
  return results;
}
function EventPointer(event) {
	return {
		x: event.pageX || (event.clientX +
		  (document.documentElement.scrollLeft || document.body.scrollLeft)),
		y: event.pageY || (event.clientY +
		  (document.documentElement.scrollTop || document.body.scrollTop))
	};
}
/**/
function is_in(obj, in_obj) {
    while (obj) {
        if (obj === in_obj) {
            return true;
        }
        obj = obj.parentNode;
    }
    return false;
}

function chekcTarget(e, cont) {
    if (!e) {
        e = window.event;
    }
    var targ = e.target ? e.target : e.srcElement ? e.srcElement : targ.nodeType == 3 ? targ.parentNode : null;
    if (is_in(targ, cont)) {
        return true;
    }
    return false;
}

function SetListner(obj, method, func) {
	if(method.indexOf('on') == 0) {
		method = method.substring(2);
	}
	
	if(document.all) {
		obj.attachEvent('on'+method, func);
	} else {
		obj.addEventListener(method, func, false);
	}
}

function fixExploder(obj) {
    if (!$(obj) || !document.all) {
        return;
    }

    $(obj).style.position = "absolute";
    $(obj).style.top = -10 + (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight) + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + ("px");
}

function Ligths(link) {
	var oThis = this;
	
	this.toggle = function () {
		if(link.className.indexOf('-on') > -1) {
			if (link['tooltip']['data']) link['tooltip']['data'] = 'Reduceți lumina';
			link.className =  'light-off';
		} else {
			if (link['tooltip']['data']) link['tooltip']['data'] = 'Măriți lumina';
			link.className =  'light-on';
		}
		
		link.onclick = function () { oThis.toggle(); }
		
		if(!this.lights_panel) {
			var el = document.body.firstChild.nodeType == 1 ? document.body.firstChild : nextNode(document.body.firstChild),
				el_height = el.scrollHeight,
				el_width = el.scrollWidth;
			
			//if(document.all) alert(el.scrollHeight);
			
			this.lights_panel = document.createElement('div');
			this.lights_panel.className = 'lights-off';
			this.lights_panel.style.height = el_height+'px';
			el.appendChild(this.lights_panel);
			
			toggleEffect(this.lights_panel, function () { fadeOut(oThis.lights_panel, 90)},  function () {fadeIn(oThis.lights_panel, 20, null, 80)});
		} else {
			toggleEffect(this.lights_panel, function () { fadeOut(oThis.lights_panel, 90)},  function () {fadeIn(oThis.lights_panel, 20, null, 80)});
		}
	}
}