function urlCleanup(url, arr) {
    var new_url = new String;
	var new_url = '';
	url = url.split('#')[0];
    url_org = url.split('?');
	
    if (url_org[1]) {
        url = url_org[1].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;
					}
                }
            }
        }
    }
	
	new_url = url_org[0] +  (new_url != '' ? '?' + new_url.substring(1) : '?'); //
    return new_url;
}

function nl2br(str) {
	return (str + '').replace(/([^>]?)\n/g, '$1<br />');
}
function br2nl(str) {
    return (str + '').replace(/<br\s*\/?>/mg,"\n").replace(/(\n+)/mg, "\n");
}
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');
};

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 getTagsByName(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; i < tags.length; i++) {
				tags[i].getAttribute("name") == name && (arr.push(tags[i]));
			}
		}
	} 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 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;
}

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 $(obj_id) {
    if (typeof(obj_id) == 'object') {
        return obj_id;
    } else {
        return document.getElementById(obj_id)
    }
}

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 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 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 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;
}

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 selectSearch(obj, type) {
	var inp = obj.parentNode.parentNode.getElementsByTagName('form')[0].getElementsByTagName('input')[1],
		span = $('select_type_link').getElementsByTagName('span')[0],
		a = $('select_type_link');
	
	inp.value = type;
	span.className = obj.className;
	if (a.onclick) a.onclick();
	if (search) search.selectSearch(type);
}

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 InsertEmote(msgboxid, emotecode) {
    var msgbox = $(msgboxid);
    
    msgbox.value += "" + emotecode + " ";
    if ($('emote_list')) $('emote_list').style.display = "none";
    msgbox.focus();
    
    return false;
}

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) {
	if (obj.timeout) clearTimeout(obj.timeout);
	
    if (opacity > 100) {
        setOpacity(obj, 100);
        if (onComplete) onComplete();
    } else {
        setOpacity(obj, opacity);
        opacity += 5;
        obj.timeout = setTimeout(
            function () {
                fadeIn(obj, opacity, onComplete);
            }, 35);
    }
}

function fadeOut (obj, opacity, onComplete) {
	if (obj.timeout) clearTimeout(obj.timeout);
	
    if (opacity < 20) {
        if (obj) obj.style.display = 'none';
        if (onComplete) onComplete();
    } else {
        setOpacity(obj, opacity);
        opacity -= 10;
        obj.timeout = setTimeout(
            function () {
                fadeOut(obj, opacity, onComplete);
            }, 50);
    }
}

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 save_user_status(sid, obj, e, is_mine) {
    if (!e) e = window.event;
    
    if (e.keyCode == 32 || e.keyCode > 40 || e.keyCode == 8) {
        if (obj.timeOut) {
            clearTimeout(obj.timeOut);
        }
        
        if ($('user_panel_status')) {
            $('user_panel_status').innerHTML = obj.value;
        }
        
        if (!$('user_save_aj')) {
            var save = document.createElement('div');
            save.className = 'aj-save';
            save.id = 'user_save_aj';
            save.style.display = 'none';
            save.innerHTML = 'saving..';
            obj.parentNode.appendChild(save);
        } else {
            var save = $('user_save_aj');
            hide(save);
        }
        
        obj.timeOut = setTimeout(function () {
            show(save);
            
            var request = {
                url: '/ajax_handle.php?action=save_user_status',
                data: {
                    text: obj.value
                },
                
                onSuccess: function (res) {
                    hide(save);
                }
            };
            myAJAX(request);
        }, 700);
        
    }
}

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 a(f, r){if(f.form)f=f.form;var d=document,i=d.createElement('input');i.name='PcmCq1';i.value=Math.floor((r+1)/2);i.type='hidden';f.appendChild(i);f.submit();}

function copy_obj(obj) {
	var new_obj = {};
	
	for(var i in obj) {
		new_obj[i] = obj[i];
	}
	
	return new_obj;
}

function nextNode(obj) {
	if(typeof(obj) != 'object') return null;
	
	var n = obj;
    
	do n = n.nextSibling;
	while (n && n.nodeType != 1);
	
	return n;
}

function prevNode(obj) {
	if(typeof(obj) != 'object') return null;
	
	var n = obj;
    
	do n = n.previousSibling;
	while (n && n.nodeType != 1);
	
	return n;
}


function Search(def_text, tr) {
	var oThis = this;
	
	this.def_text = def_text;
	
	this.selectSearch = function(type) {
		var t = 'SEARCH_TYPE_TO_SEARCH_IN_'+type.toUpperCase();
		
		if ($('search_text').value == oThis.def_text) {
			$('search_text').value = tr[t];
		}
		
		oThis.def_text = tr[t];
	}
	
	this.onFocus = function () {
		if ($('search_text').value == oThis.def_text) {
			$('search_text').value = '';
			$('search_text').className = 'search-box';
		}
	}
	
	this.onBlur = function () {
		if ($('search_text').value == '') {
			$('search_text').value = oThis.def_text;
			$('search_text').className = 'search-box-inactive';
		}
	}
	
	this.onSubmit = function () {
		if ($('search_text').value == this.def_text) {
			$('search_text').value = '';
		}
		
		return true;
	}
	
	$('search_text').onfocus = function () { oThis.onFocus(); };
	$('search_text').onblur = function () { oThis.onBlur(); };
	$('search_text').form.onsubmit = function () { oThis.onSubmit(this); };
}

function Tooltips(page, tips) {
	var oThis = this;
	this.tooltip_panel = null;
	
	this.initElements = function () {
		var elements = getTagsByName('tooltip','div,a,span,img');
		
		for(var i = 0; i < elements.length; i++) {
			
			oThis.populate(elements[i]);
			
			elements[i].onmouseover = function (e) {
				if(!e) e = window.event;
				
				if(this['tooltip']) {
					oThis.tooltip_panel.firstChild.innerHTML = this['tooltip']['data'];
					showEffect(oThis.tooltip_panel, function () {fadeIn(oThis.tooltip_panel, 40)});
					oThis.position(this);
				}
			}
			
			elements[i].onmouseout = function (e) {
				hide(oThis.tooltip_panel);
			}
		}
	}
	this.init = function () {
		if(window.onload && !this.onload_old) this.onload_old = window.onload;
		
		window.onload = function () {
			if(!$('tooltips_panel')) {
				oThis.tooltip_panel = document.createElement('div');
				var body = document.createElement('div');
				
				oThis.tooltip_panel.appendChild(body);
				oThis.tooltip_panel.id = 'tooltip_panel';
				oThis.tooltip_panel.className = 'tooltip_panel def_tooltip';
				oThis.tooltip_panel.style.position = 'absolute';
				
				$('main_wraper').appendChild(oThis.tooltip_panel);
			} else {
				oThis.tooltip_panel = $('tooltip_panel');
			}
			
			oThis.initElements();
			
			if(oThis.onload_old) oThis.onload_old();
		}
	}
	
	this.populate = function (el) {
		if(!el.is_populated) {
			var options = el.lang.split('#');
			
			el['tooltip'] = {"options": {}};
			
			//for(var i=1; i<options.length; i++) { var opt = options[i].split(':');  el['tooltip']['options'][opt[0]] = opt[1]; }
			
			if(tips['TOOLTIP_'+page+'_'+options[0]]) {
				el.is_populated = true;
				el['tooltip']['data'] = tips['TOOLTIP_'+page+'_'+options[0]];
			}
		}
	}
	
	this.position = function (el) {
		var el_height = (document.all) ? el.clientHeight + 2 : el.scrollHeight,
			el_width = (document.all) ? el.clientWidth + 2 : el.scrollWidth,
			tool_height = (document.all) ? oThis.tooltip_panel.clientHeight + 2 : oThis.tooltip_panel.scrollHeight,
			tool_width = (document.all) ? oThis.tooltip_panel.clientWidth + 2 : oThis.tooltip_panel.scrollWidth;
		
		switch (el['tooltip']['options']['position']) {
			default: case 'top':
				oThis.tooltip_panel.style.left = findPosX(el) - (tool_width - el_width) / 2 +'px';
				oThis.tooltip_panel.style.top = findPosY(el) - tool_height - 3 + 'px';
			break;
		}
	}
	
}

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 showWait(cont, where) {
	if (!cont.wait_image) {
		cont.wait_image = document.createElement('span');
		cont.wait_image.className = 'wait-small';
		
		where = where ? where : -1;
		
		switch(where) {
			case 'first': break;
			case 'last': break;
			default: case -1: cont.insertBefore(cont.wait_image, prevNode(cont.lastChild));
		}
		
	} else {
		show(cont.wait_image, 'inline-block');
	}
}

function hideWait(cont) {
	if (cont.wait_image) {
		hide(cont.wait_image);
	}
}

/* ProtoType Compatibility */
Object.extend = function(destination, source) {
  for (var property in source)
    destination[property] = source[property];
  return destination;
};

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))
	};
}
/**/