var ft_w = 150;
var ft_h = 100;

var ImagesDisabled	= 666;

function bodyOnload() {
	DetectImageState.init(default_img, images_check);
	if(typeof(initDragnDrop) != 'undefined')
		initDragnDrop();
}

function images_check(s) {
	ImagesDisabled = s;
}

function ge(id) {
	return document.getElementById(id);
}

var DetectImageState = {
	 version: '1.0'
	,imagesDisabled: true
	,inserted_id: 'detectimagestate-test-img'
	,callback: function() { }
	,ie_detectionComplete: false
	,img: null
	,ie_Timeout: 100

	,init: function(testerimg, cb) {
		this.callback = cb;

		var _img = document.createElement('img');
		_img.id = this.inserted_id;
		_img.style.visibility = 'hidden';
		_img.style.position = 'absolute';
		_img.style.left = '-1000px';
		_img.alt = '';
		_img.src = testerimg+'?'+Math.random();

		document.body.appendChild(_img);
// 		document.body.innerHTML += '<img id="'+this.inserted_id+'" style="visibility:hidden; position:absolute;left:-1000px;" src="'+testerimg+'?'+Math.random()+'" alt="" />';

		this.img = document.getElementById(this.inserted_id);

		if(window.opera || navigator.userAgent.toLowerCase().indexOf('opera')>-1) {
			var pre = this.img.complete;
			this.img.src = 'about:blank';
			this.imagesDisabled = (!pre && this.img.complete) ? false : true;
			DetectImageState.callback(this.imagesDisabled);
			return;
		} else if(typeof this.img.readyState != 'undefined') {
			this.img.src = this.img.src+'?'+Math.random();
			this.img.onabort = function() {
				DetectImageState.ie_detectionComplete = true;
				DetectImageState.imagesDisabled = false;
				DetectImageState.callback(DetectImageState.imagesDisabled);
			};

			setTimeout('if(!DetectImageState.ie_detectionComplete) DetectImageState.callback(DetectImageState.imagesDisabled);', this.ie_Timeout);
			return;
		} else {
			this.imagesDisabled = this.img.complete;
			DetectImageState.callback(this.imagesDisabled);
			return;
		}
	}
};

function goto(url, conf)
{
	if((conf != null && confirm(conf)) || conf == null)
		window.location = url;
}

function rand(n)
{
	return(Math.floor(Math.random() * n + 1));
}

function disable(id, _form)
{
	_form[id].onclick = _form.onsubmit =  function () { return false; };
	_form[id].style.background = '#ccc';
	_form[id].value = ' ' + loading_text + ' ';
}

function unescapeIt(str)
{
	return str.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,"\"").replace(/&#039;/g,"'");
}

// function escapeIt(str)
// {
// 	return str.replace(/&/g,'%26');
// }

function resetScroll(goto)
{
	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' )
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
	}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
	}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}

	if(goto != '')
		window.scrollBy(0, goto);
	else
		return scrOfY;
}

function AddTags(id, start_tag, end_tag)
{
	// Get current position
	var obj		= ge(id);
	if(obj == null)
		return true;

	var inner		= '';
	var url		= '';
	var _scroll	= obj.scrollTop;
	var url_check	= /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;

	obj.focus();

	if(document.selection) // For IE
	{
		var sel	= document.selection.createRange();
		inner	= sel.text;
		if(start_tag == '[url]')
		{
			if(sel.text != '' && url_check.test(sel.text))
			{
				inner = prompt(lng_enter_the_capture , sel.text);
				if(inner == null) return;
				url = sel.text;
			}
			else if(sel.text != '')
			{
				url = prompt(lng_enter_the_url , 'http://');
				if(url == null || url == 'http://') return;
			}
			else
			{
				inner = prompt(lng_enter_the_capture , lng_default_capture );
				if(inner == null) return;
				url	 = prompt(lng_enter_the_url , 'http://');
				if(url == null || url == 'http://') return;
			}
			start_tag	= '[url=' + url + ']';
		}
		else if(start_tag == '[img]')
		{
			if(sel.text != '' && url_check.test(sel.text))
			{
				start_tag	= '[img]' + sel.text + '[/img]';
			}
			else
			{
				url = prompt(lng_enter_the_image , 'http://');
				if(url == null || url == 'http://') return;
				start_tag	= '[img]' + url + '[/img]';
			}
			inner = '';
		}
		sel.text	= start_tag + inner + end_tag;
		sel.select();
	}
	else // For Mozilla Firefox
	{
// 		obj.selectionStart = obj.selectionEnd = 0;
		var len	= obj.value.length;
		var start	= obj.selectionStart;
		var end	= obj.selectionEnd;
		var sel	= obj.value.substring(start, end);
		inner	= sel;

		if(start_tag == '[url]')
		{
			if(sel.text != '' && url_check.test(sel))
			{
				inner = prompt(lng_enter_the_capture , sel);
				if(inner == null) return;
				url = sel;
			}
			else if(sel != '')
			{
				url = prompt(lng_enter_the_url , 'http://');
				if(url == null || url == 'http://') return;
			}
			else
			{
				inner = prompt(lng_enter_the_capture , lng_default_capture );
				if(inner == null) return;
				url	 = prompt(lng_enter_the_url , 'http://');
				if(url == null || url == 'http://') return;
			}
			start_tag	= '[url=' + url + ']';
		}
		else if(start_tag == '[img]')
		{
			if(sel != '' && url_check.test(sel))
			{
				start_tag	= '[img]' + sel + '[/img]';
			}
			else
			{
				url = prompt(lng_enter_the_image , 'http://');
				if(url == null || url == 'http://') return;
				start_tag	= '[img]' + url + '[/img]';
			}
			inner = '';
		}

		obj.value =  obj.value.substring(0, start) + start_tag + inner + end_tag + obj.value.substring(end, len);
		obj.selectionStart = obj.selectionEnd = start + start_tag.length + end_tag.length + sel.length;
		obj.focus();
	}
	// Return to previous position
	obj.scrollTop = _scroll;

	return false;
}

function getSlectedText()
{
	var txt = '';
	if(window.getSelection)
	{
		txt = window.getSelection();
	}
	else if(document.getSelection)
	{
		txt = document.getSelection();
	}
	else if(document.selection)
	{
		txt = document.selection.createRange().text;
	}
	return txt;
}

var selected_text = '';
function quoteText(obj, e, author)
{
	selected_text = getSlectedText();

	if(selected_text != '' && ge('post_text'))
	{
		var posx = 0;
		var posy = 0;
		if (!e)
			e = window.event;
		if (e.pageX || e.pageY)
		{
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY)
		{
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}

		var popup = document.createElement('input');
		popup.id = 'quote_popup';
		popup.type = 'button';
		popup.className = 'btn';
		popup.value = 'Quote selected';
		popup.style.position = 'absolute';
		popup.style.left = posx - 40 + 'px';
		popup.style.top = posy - 30 + 'px';
		popup.onmousedown = function () { return AddTags('post_text', '[quote=' + author + ']' + selected_text + '[/quote]', ''); }

		document.body.appendChild(popup);
		document.body.onmousedown = function () { document.body.removeChild(ge('quote_popup')); document.body.onmousedown = ''; }
	}
}


function CheckHTML(id)
{
	var obj	= ge(id);
	var check	= new RegExp(/<[^>]*>/);
	return check.test(obj.value);
}

function FitThumbnail(obj)
{
	var w = obj.parentNode.getAttribute('ft_w') ? obj.parentNode.getAttribute('ft_w') : ft_w;
	var h = obj.parentNode.getAttribute('ft_h') ? obj.parentNode.getAttribute('ft_h') : ft_h;

	obj.className = 'bb_img';
	if(document.images && obj.getAttribute('image') != '')
	{
		var preload_image = new Image();
		preload_image.src = obj.getAttribute('image');
		obj.setAttribute('alt', lng_loading_img);

		preload_image.onload = function () {
			var mod_w = (preload_image.width > w) ? w / preload_image.width : 1;
			var mod_h = (preload_image.height > h) ? h / preload_image.height : 1;
			var mod = (mod_w > mod_h) ? mod_h : mod_w;

			obj.width = Math.round(preload_image.width * mod);
			obj.height = Math.round(preload_image.height * mod);
			obj.src = preload_image.src;
// 			obj.setAttribute('alt', '[img]' + preload_image.src + '[/img]');
			obj.setAttribute('image', '');
			obj.setAttribute('alt', lng_click_for_full_size);
			obj.setAttribute('title', lng_click_for_full_size);
			obj.onclick = function () {
				window.open(preload_image.src, 'image_window');
			}
		}
	}
}

function deadReport(obj, id)
{
	if(ImagesDisabled == false && ImagesDisabled != 666)
	{
		OnLoad = function() {
			obj.src = default_img;
			obj.onerror = void(0);
		}

		OnComplete = function() {
			void(0);
		}

		PostRequest(http_root + '/report/', 'deadIMG=' + id);
	}
}

function rolloverButton(obj, over, down)
{
	if(!obj.onmouseout)
	{
		window.classChange = null;
		obj.style.cursor = 'pointer';
		obj.onmouseout = function () {
			obj.className = classChange;
			classChange = '';
		}
	}

	if(!obj.onmousedown)
	{
		obj.onmousedown = function () {
			obj.className = classChange + ' ' + down;
		}
	}

	if(!obj.onmouseup)
	{
		obj.onmouseup = function () {
			obj.className = classChange + ' ' + over;
		}
	}

	if(!classChange)
	{
		classChange = obj.className;
		obj.className = obj.className + ' ' + over;
	}
}

// function CheckAll(checkname, exby)
// {
// 	if(typeof(checkname) != 'undefined')
// 	{
// 		for (i = 0; i < checkname.length; i++)
// 			checkname[i].checked = exby.checked ? true : false;
// 		checkname.checked = exby.checked ? true : false; // fix for single checkbox
// 	}
// }

function CheckAll(checkname, exby)
{
	var tick	= exby.checked ? true : false;
	var els	= exby.form.elements;
	var i	= els.length;
	while(i--)
		if(els[i].type == 'checkbox' && els[i].name == checkname)
			els[i].checked = tick;
}


function disableSelection(target)
{
	if(typeof target.onselectstart != 'undefined') //IE route
		target.onselectstart = function() { return false; }
	else if(typeof target.style.MozUserSelect != 'undefined') //Firefox route
		target.style.MozUserSelect = 'none';
	else //All other route (ie: Opera)
		target.onmousedown=function() { return false; }
	target.style.cursor = 'default';
}

function makeactive(obj, target, num, tabs)
{
	var d = ge(target).getElementsByTagName('div').length;
	var p = (typeof(tabs) == 'undefined') ? obj.parentNode.parentNode : ge(tabs);
	var c = p.getElementsByTagName('li').length;
	for(i = 0; i < c; i++)
		p.getElementsByTagName('li')[i].className = '';

	if(typeof(tabs) == 'undefined')
		obj.parentNode.className = 's';

	for(i = 0; i < d; i++)
		ge(target).getElementsByTagName('div')[i].style.display = 'none';

	ge(target).getElementsByTagName('div')[num-1].style.display = '';

	return false;
}




var http_request = false;

/*
* Function PostRequest(url) where url - processing script.
* (ext - OnLoad = function() { do something } and OnComplete = function() { do something (with "var result")})
*/
function PostRequest(url, parameters) {

	if (window.XMLHttpRequest) { 				// Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { 			// IE
		try {
			http_request = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
		try {
			http_request = new ActiveXObject('Microsoft.XMLHTTP');
		} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}

	http_request.onreadystatechange = function() {

		if (http_request.readyState == 1) {
			OnLoad();
		}

		if (http_request.readyState == 4) {
			result = http_request.responseText;
			OnComplete();
		}
	}

	http_request.open('POST', url, true);
	http_request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=utf-8');
	http_request.setRequestHeader('Content-length', parameters.length);
	http_request.setRequestHeader('Connection', 'close');
	http_request.send(parameters);
}


/*
* Function GetRequest(url) where url - processing script.
* (ext - OnLoad = function() { do something } and OnComplete = function() { do something (with "var result")})
*/
function GetRequest(url) {

	if (window.XMLHttpRequest) { 				// Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { 			// IE
		try {
			http_request = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
		try {
			http_request = new ActiveXObject('Microsoft.XMLHTTP');
		} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}

	http_request.onreadystatechange = function() {

		if (http_request.readyState == 1) {
			OnLoad();
		}

		if (http_request.readyState == 4) {
			result = http_request.responseText;
			OnComplete();
		}
	}

	http_request.open('GET', window.self.location.toString().replace(/#.*/i, '').replace(/\?.*/i, '') + url, true);
	http_request.send(null);
}

function FAform(fname)
{
	var o	= fname.getElementsByTagName('input');
	var c	= o.length;
	var str	= 'a=1';

	for(i = 0; i < c; i++)
		if((o[i].type == 'checkbox' || o[i].type == 'radio') && o[i].checked)
			str += '&' + o[i].name + '=' + o[i].value;
		else if(o[i].type != 'checkbox' && o[i].type != 'radio' && o[i].name != '')
			str += '&' + o[i].name + '=' + o[i].value;

	os = fname.getElementsByTagName('select');
	cs = os.length;

	for(i = 0; i < cs; i++)
		if(o[i].name != '')
			str += '&' + os[i].name + '=' + os[i].value;

	OnLoad = function() {
		ge(fname.id + '_btn').style.display = 'none';
		ge(fname.id + '_res').innerHTML = '<img src="' + loading_img + '" alt="' + loading_text + '" />';
	}

	OnComplete = function() {
		ge(fname.id + '_btn').style.display = '';
		ge(fname.id + '_res').innerHTML = result;
	}

	PostRequest(fname.action, str);
	return false;
}

function findIt(id, s)
{
	var labels = ge(id).getElementsByTagName('label');
	var c = labels.length;
	var pattern = new RegExp(s, 'i');

	for(i = 0; i < c; i++)
	{
		if(pattern.test(labels[i].innerHTML.replace(/<\/?[^>]+>/gi, '')))
			labels[i].style.display = 'block';
		else
			labels[i].style.display = 'none';
	}
}

function checkArray(ch, array, prefix)
{
	for(i = 0; i < array.length; i++)
	{
		document.getElementById(prefix+array[i]).checked = (ch.checked==true) ? true : false;
	}
}

function view_message()
{
	if(check_message())
	{
		ge('t_message').target = '_view';
		document.message.submit();
		ge('t_message').target = '_self';
	}
}

function check_message()
{
	if(document.message.msg_body.value == '' || document.message.subject.value == '')
	{
		alert(lng_empty_alert);
		return false;
	}
	else
	{
		return true;
	}
}


function get_anchor()
{
	if(location.hash == 0)
		return null;
	else
		return location.hash.match(/#(\w.*)/)[1];
}

function disableSelection(target)
{
	if(typeof target.onselectstart != 'undefined') //IE route
		target.onselectstart = function() { return false; }
	else if(typeof target.style.MozUserSelect != 'undefined') //Firefox route
		target.style.MozUserSelect = 'none';
	else //All other route (ie: Opera)
		target.onmousedown=function() { return false; }
	target.style.cursor = 'default';
}

function makeScrollable(id)
{
	var table = ge(id);
	var thead = table.getElementsByTagName('table')[0];
	var tbody = table.getElementsByTagName('table')[1];

	if(typeof(tbody) != 'undefined')
	{
// 		table.scrollTop = 0; // Little FF header fix

		// Set width to inner elements
		thead.style.width = table.clientWidth + 'px';
		tbody.style.width = (table.clientWidth - 16) + 'px';

		for(i = 0; i < thead.getElementsByTagName('td').length; i++)
			if(typeof(tbody.getElementsByTagName('td')[i]) != 'undefined')
				tbody.getElementsByTagName('td')[i].style.width = thead.getElementsByTagName('td')[i].style.width;
	}
}

function createCookie(name, value, days)
{
	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=/';
}

function readCookie(name) {
	var nameEQ = name + '=';
	var ca = document.cookie.split(';');
	for(var i = 0; i < ca.length; i++)
	{
		var c = ca[i];
		while(c.charAt(0) == ' ')
			c = c.substring(1,c.length);
		if(c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function changeInputType(obj, _type)
{
	var new_obj = document.createElement('input');
	new_obj.type = _type;
	if(obj.value) new_obj.value = obj.value;
	if(obj.size) new_obj.size = obj.size;
	if(obj.name) new_obj.name = obj.name;
	if(obj.id) new_obj.id = obj.id;
	if(obj.className) new_obj.className = obj.className;
	obj.parentNode.replaceChild(new_obj, obj);
	return new_obj;
}

function changeText(obj)
{
	var deftext = obj.getAttribute('deftext');
	if(deftext == null)
	{
		deftext = obj.value;
		obj.setAttribute('deftext', obj.value);
	}

	if(obj.value == deftext)
		obj.value = '';

	obj.onblur = function () {
		if(obj.value == '')
			obj.value = deftext;
	}
}

function addCommentBtn()
{
	ge('comment_txt').value = '';

	onFadeIn = function() {
		void(0);
	}

	onOpen = function () {
		ge('comment_txt').focus();
	}

	collapseChecker('add_comment', 250);
}

function replyCommentBtn(id)
{
	onFadeIn = function () {
		ge('btn_' + id).value = ge('btn_' + id).getAttribute('posttxt');
		ge('btn_' + id).onclick = function () { eval(ge('btn_' + id).getAttribute('postact')) };
		ge('txt_' + id).value = '';
	}

	onOpen = function () {
		ge('txt_' + id).focus();
	}

	collapseChecker('reply_' + id, 250);
}

function smilesBtn(id)
{
	onFadeIn = function() {
		void(0);
	}

	onOpen = function () {
		void(0);
	}

	collapseChecker('smiles_' + id, 250);
}

function replyComment(obj, id)
{
	if(ge('txt_' + id).value == '')
	{
		alert(lng_empty_alert);
	}
	else
	{
		var tmp_txt = obj.value;
		OnLoad = function() {
			obj.disabled = 'disabled';
			obj.value = loading_text;
		}

		OnComplete = function() {
			obj.disabled = '';
			obj.value = tmp_txt;
			getComments();
		}
		PostRequest(window.self.location, 'a=1&reply=' + id + '&comment=' + ge('txt_' + id).value.replace(/&/g, '%26'));
	}
}
var first_get = true;
function getComments()
{
	OnLoad = function() {
		if(first_get)
		{
			ge('comments_container').innerHTML = '<div style="text-align: center;"><img src="' + loading_img + '" /></div>';
			first_get = false;
		}
	}

	OnComplete = function() {
		ge('comments_container').innerHTML = result;
	}
	GetRequest('?a=1&comments=get');
}

function addComment(obj)
{
	if(ge('comment_txt').value == '')
	{
		alert(lng_empty_alert);
	}
	else
	{
		var tmp_txt = obj.value;
		OnLoad = function() {
			obj.disabled = 'disabled';
			obj.value = loading_text;
		}

		OnComplete = function() {
			obj.disabled = '';
			obj.value = tmp_txt;
			addCommentBtn();
			getComments();
		}
		PostRequest(window.self.location, 'a=1&comment=' + ge('comment_txt').value.replace(/&/g, '%26'));
	}
}

function removeComment(obj, id)
{
	var tmp_inner = obj.innerHTML;
	var tmp_onclick = obj.onclick;

	OnLoad = function() {
		obj.onclick = '';
		obj.innerHTML = loading_text;
	}

	OnComplete = function() {
		getComments();
	}

	GetRequest('?a=1&delete=' + id);
}

// Delete all entries
// function clearComments(obj)
// {
// 	var tmp_inner = obj.innerHTML;
// 	var tmp_onclick = obj.onclick;
//
// 	OnLoad = function() {
// 		obj.onclick = '';
// 		obj.innerHTML = loading_text;
// 	}
//
// 	OnComplete = function() {
//
// 		obj.onclick = tmp_onclick;
// 		obj.innerHTML = tmp_inner;
// 		getComments();
// 	}
//
// 	GetRequest('?a=1&comments=clear');
// }

function editComment(obj, id)
{
	var tmp_inner = obj.innerHTML;
	var tmp_onclick = obj.onclick;

	OnLoad = function() {
		obj.onclick = '';
		obj.innerHTML = loading_text;
	}

	OnComplete = function() {
		onFadeIn = function () {
			ge('btn_' + id).value = obj.getAttribute('edittxt');
			ge('btn_' + id).onclick = function () { eval(obj.getAttribute('editact')) };
			ge('txt_' + id).value = unescapeIt(result);
		}

		onOpen = function() {
			void(0);
		}

		collapseChecker('reply_' + id, 250);

		obj.onclick = tmp_onclick;
		obj.innerHTML = tmp_inner;
	}

	GetRequest('?a=1&edit=' + id);
}

function saveComment(obj, id)
{
	var scrollto = resetScroll();

	OnLoad = function() {
		obj.disabled = 'disabled';
		obj.value = loading_text;
	}

	OnComplete = function() {
		obj.disabled = '';
		ge('txt_' + id).value = '';
		obj.value = obj.getAttribute('posttxt');
		obj.onclick = function () { eval(obj.getAttribute('postact')) };
		getComments();
		resetScroll(scrollto);
	}
	PostRequest(window.self.location, 'a=1&comment=' + ge('txt_' + id).value.replace(/&/g, '%26') + '&save=' + id);
}
/**
  *	Collapse DIV's with fade effect
  *
  *	Author: KiriK ( http://kirik.ws )
  *	Version: 1.0
**/

// function collapse(id, millisec)
// {
// 	onOpen	= function () { ge('res').innerHTML = 'Opened'; }
// 	onClose	= function () { ge('res').innerHTML = 'Closed'; }
// 	onFadeIn	= function () { ge('res').innerHTML = 'Load Info'; }
// 	onFadeOut	= function () { ge('res').innerHTML = 'Close Info'; }
// 	collapseChecker(id, millisec);
// }

function collapseChecker(id, millisec)
{
	if(id.constructor.toString().indexOf('Array') > -1)
	{
		for(i = 1; i < id.length; i++)
			if(ge(id[i]).firstChild.style.visibility == 'visible')
				var close_id = id[i];
		if(typeof(close_id) != 'undefined')
			collapseMain(close_id, millisec);
		collapseMain(id[0], millisec);
	}
	else
		collapseMain(id, millisec);
}

function collapseMain(id, millisec)
{
	var obj		= ge(id);
	var speed		= Math.round(millisec / 100);
	var now_height	= obj.clientHeight;
	var max_height	= obj.firstChild.clientHeight;

	if(obj.firstChild.style.visibility == 'hidden')
		collapseChangeOpacity(id, 0);

	if(obj.getAttribute('status') == 'closed' || obj.getAttribute('status') == null) // start open
		for(i = now_height, timer = 0; i <= max_height; i++, timer++)
			setTimeout('collapseChangeHeight("' + id + '", ' + i + ', ' + max_height + ')', (timer * speed));
	else if(obj.getAttribute('status') == 'opened') // start close
	{
		if(typeof(onFadeOut) != 'undefined')
			onFadeOut();
		for(i = 100, timer = 0; i >= 0; i--, timer++)
			setTimeout('collapseChangeOpacity("' + id + '", ' + i + ', true);', (timer * speed));
	}
}

function collapseChangeHeight(id, h, to)
{
	var speed		= Math.round(200 / 100);
	var obj		= ge(id);

	obj.style.height = h + 'px';

	if(h == to && to > 0) // opened
	{
		if(typeof(onFadeIn) != 'undefined')
			onFadeIn();

		obj.firstChild.style.visibility = 'visible';

		obj.firstChild.style.position = 'relative';
		obj.style.height = '';
		obj.setAttribute('status', 'opened');

		for(i = 0, timer = 0; i <= 100; i++, timer++)
			setTimeout('collapseChangeOpacity("' + id + '", ' + i + ')', (timer * speed));
	}
	else if(h == 0 && !to) // closed
	{
		if(typeof(onClose) != 'undefined')
			onClose();

		obj.setAttribute('status', 'closed');
		obj.firstChild.style.position = 'absolute';
	}
}

function collapseChangeOpacity(id, opacity, hide)
{
	var speed	= Math.round(200 / 100);
	var obj	= ge(id);
	var child	= obj.firstChild.style;

	if(hide == true && opacity == 0)
	{
		child.visibility = 'hidden';
		for(i = obj.clientHeight, timer = 0; i >= 0; i--, timer++)
			setTimeout('collapseChangeHeight("' + id + '", ' + i + ')', (timer * speed));
	}
	else if(hide != true && opacity == 100)
		if(typeof(onOpen) != 'undefined')
			onOpen();

	child.opacity		= (opacity / 100);
	child.MozOpacity	= (opacity / 100);
	child.KhtmlOpacity	= (opacity / 100);
	child.filter		= 'alpha(opacity=' + opacity + ')';
}

function changeOpacity(id, start, end, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;

	if(start > end) {
		for(i = start; i >= end; i--) {
			setTimeout("_changeOpacity(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(start < end) {
		for(i = start; i <= end; i++)
		{
			setTimeout("_changeOpacity(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

function _changeOpacity(opacity, id)
{
	var object = ge(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = 'alpha(opacity=' + opacity + ')';
}

// Rating stars
function starsSelect(obj, val)
{
	var container = obj.parentNode;
	var folder = container.getAttribute('folder');
	for(var i = 0; i < val; i++)
	{
		container.getElementsByTagName('img')[i].onmouseout = function () { starsReset(container); };
		container.getElementsByTagName('img')[i].onclick = function () { starSet(container, val); };
		container.getElementsByTagName('img')[i].src = folder + 'star_on.gif';
		container.getElementsByTagName('span')[0].innerHTML = container.getElementsByTagName('img')[i].getAttribute('txt');
	}
}

function starsReset(obj)
{
	var folder = obj.getAttribute('folder');
	for(var i = 0; i < 5; i++)
	{
		obj.getElementsByTagName('img')[i].src = folder + 'star_off.gif';
	}
	obj.getElementsByTagName('span')[0].innerHTML = obj.getAttribute('txt');
}

function starSet(obj, vote)
{
	var folder = obj.getAttribute('folder');

	OnLoad = function() {
		obj.getElementsByTagName('span')[0].innerHTML = loading_text;
	}

	OnComplete = function() {
		for(var i = 0; i < 5; i++)
		{
			obj.getElementsByTagName('img')[i].onmouseover = obj.getElementsByTagName('img')[i].onmouseout = obj.getElementsByTagName('img')[i].onclick = function () { return false };
			obj.getElementsByTagName('img')[i].src = folder + ((vote > i) ? 'star_on.gif' : 'star_off.gif');
			obj.getElementsByTagName('img')[i].style.cursor = 'default';
		}
		obj.getElementsByTagName('span')[0].innerHTML = success_text;
	}
	GetRequest('?a=1&vote=' + vote);
}

function getHistory()
{
	OnLoad = function() {
		ge('history').innerHTML = '<img src="' + loading_img + '" alt="' + loading_text + '" />';
	}

	OnComplete = function() {
		ge('history').innerHTML = result;
	}

	GetRequest('?history');
}


function watchListIt(act)
{
	OnLoad = function() {
		ge('watchlist_ph').innerHTML = '<img src="' + loading_img + '" alt="' + loading_text + '" />';
	}

	OnComplete = function() {
		ge('watchlist_ph').innerHTML = result;
	}

	PostRequest(window.self.location, 'a=1&' + act + '=1');
}

function watchListRemove(act, obj)
{
	OnLoad = function() {
		obj.onclick = function () {};
		obj.innerHTML = loading_text;
	}

	OnComplete = function() {
		obj.parentNode.parentNode.removeChild(obj.parentNode);
		var entries = ge('users_watchlist').getElementsByTagName('div');

		if(entries.length == 0)
			window.location = window.self.location;

		for(i = 0; i < entries.length; i++)
		{
			entries[i].getElementsByTagName('b')[0].innerHTML = i + 1;
		}
	}

	PostRequest(window.self.location, 'a=1&listremove=' + act);
}

function friends_stuff(username, act, params, obj)
{
	ge(username).setAttribute('draggable', 'no');
	switch(act)
	{
	case 'remove':
		OnLoad = function() {
			changeOpacity(username, 100, 30, 500);
		}

		OnComplete = function() {
			ge(username).style.display = 'none';
		}

		GetRequest('?a=1&remove=' + params);
	break;

	case 'unfave':
		OnLoad = function() {
			changeOpacity(username, 100, 50, 500);
		}

		OnComplete = function() {
			if(ge(username).className == 'edit orange')
			{
				ge(username).style.display = 'none';
			}
			else
			{
				changeOpacity(username, 50, 100, 500);
				obj.className = 'fave_mini';
				obj.setAttribute('title', '');
			}
			obj.onclick = function () {
				friends_stuff(username, 'fave', params, obj);
			}
		}

		GetRequest('?a=1&unfave=' + params);
	break;

	case 'fave':
		OnLoad = function() {
			changeOpacity(username, 100, 50, 500);
		}

		OnComplete = function() {
			changeOpacity(username, 50, 100, 500);
			obj.className = 'unfave_mini';
			obj.setAttribute('title', '');

			obj.onclick = function () {
				friends_stuff(username, 'unfave', params, obj);
			}
		}

		GetRequest('?a=1&fave=' + params);
	break;
	}
}

function autoComplete(obj, evt)
{
	var elm = (obj.setSelectionRange) ? evt.which : evt.keyCode;

	if(elm == 13)
	{
		obj.value = obj.value + ', ';

		if(document.selection)
		{
			rng = obj.createTextRange();
			rng.moveStart('character', obj.value.length);
			rng.moveEnd('character', obj.value.length);
			rng.select();
		}
		else
		{
			obj.selectionStart = obj.selectionEnd = obj.value.length;
		}

		return;
	}

	if ((obj.value.length == 0) || (!obj) || (!evt) || (autoCompleteTags.length == 0) || (elm < 32) || (elm >= 33 && elm <= 46) || (elm >= 112 && elm <= 123)) {
		return;
	}

	elm = obj.value.split(',');
	var txt = elm.pop();
	txt = txt.replace(/^\s*/, "");

	if(txt.length == 0)
	{
		return;
	}

	if(document.selection)
	{
		var rng = document.selection.createRange();
		if(rng.parentElement() == obj)
		{
			elm = rng.text;
			var ini = obj.value.lastIndexOf(elm);
		}
	}
	else
	{
		var ini = obj.selectionStart;
	}

	for(var i = 0; i < autoCompleteTags.length; i++)
	{
		elm = autoCompleteTags[i].toString();

		if(elm.toLowerCase().indexOf(txt.toLowerCase()) == 0)
		{
			obj.value += elm.substring(txt.length, elm.length);
			break;
		}
	}

	if(obj.createTextRange)
	{
		rng = obj.createTextRange();
		rng.moveStart('character', ini);
		rng.moveEnd('character', obj.value.length);
		rng.select();
	}
	else if(obj.setSelectionRange)
	{
		obj.setSelectionRange(ini, obj.value.length);
	}
}