/*************************************
 *
 *  Code By Attenzione
 *  Started at 21.04.2008
 *
 *************************************/

/*document.onkeyup  = function(e) {
	e = _fixE( e );
	if (e.keyCode == 8) {
		refreshPage();
	}
}*/

//var oldHref = window.location.href;
//setInterval( function() { if (oldHref != window.location.href) { refreshPage(); } }, 500 );
 
var iw = {};
 
var lastAjaxUrl = "";
var allowAutoHide = true; //system! do not change!

function _$( id ) {
	return document.getElementById( id );
}

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

function in_array(myValue,myArray) {
    function equals(a,b) {
        return (a == b);
    }

    for (var i in myArray) {
        if (equals(myArray[i],myValue))
            return true;
    }

    return false;
}

function _noBubbling( e ) {
	e = _fixE( e );
	if (e.cancelBubble) e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
    return false;
}

function _fixE( e ) {
	if (!e) e = window.event;
	return e;
}

var viewport = {
	windowX : function() { return (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth },
    windowY : function() { return (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight },
    scrollX : function() { return (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft },
    scrollY : function() { return (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop },
    pageX 	: function() { return (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth },
    pageY 	: function() { return (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight }
}

iw.preloader = {
	o : null,
	p : null,
	show : function( selector ) {
		if (!this.init( selector )) return false;
		this.p.removeClass('preloader-instance').prependTo( this.o ).show();
		return true;
	},
	hide : function( selector ) {
		if (!this.init( selector )) return false;
		this.o.find('div.preloader').remove();
		return true;
	},
	init : function( selector ) {
		var o = $( selector );
		if (!o.length) return false;
		this.o = o;
		//var p = $('div.preloader-instance');
		//if (!p.length) return false;
		var msg = typeof settings.preloader != 'undefined' ? settings.preloader : '';
		this.p = $('<div class="preloader"><div><span>'+msg+'</span></div></div>');
		var height = this.o.height();
		var padding = height < 600 ? Math.max(0, Math.round( height / 2 ) - 40) : 250;
		this.p.find('div').css({
			'padding-top' : padding,
			'height' : height - padding
		});
		return true;
	}
}

function getSelectionPositions( element ) {
	if( document.selection ){
		// The current selection
		var range = document.selection.createRange();
		// We'll use this as a 'dummy'
		var stored_range = range.duplicate();
		// Select all text
		stored_range.moveToElementText( element );
		// Now move 'dummy' end point to end point of original range
		stored_range.setEndPoint( 'EndToEnd', range );
		// Now we can calculate start and end points
		element.selectionStart = stored_range.text.length - range.text.length;
		element.selectionEnd = element.selectionStart + range.text.length;
	}
	return { start: element.selectionStart, end: element.selectionEnd };
}
function setSelectionPositions( element, start, end ) {

	if (!end || typeof end == 'undefined') end = start;
	// IE Support
	if (document.selection) {

		// Set focus on the element
		element.focus ();

		// Create empty selection range
		var oSel = document.selection.createRange ();

		// Move selection start and end to 0 position
		//oSel.moveStart ('character', -element.value.length);

		// Move selection start and end to desired position
		oSel.moveStart ('character', start);
		oSel.moveEnd ('character', -element.value.length + end);
		oSel.select ();
		
	} else if (element.selectionStart || element.selectionStart == '0') {
	
		element.focus ();
		element.selectionStart = start;
		element.selectionEnd = end;

		
	}

}

function m( n, d, s ) {

	n = n.split(',');
	var nn = '';
	for (var i = 0; i < n.length; i++) {
		nn += String.fromCharCode(n[i]);
	}
	d = d.split(',');
	var dd = '';
	for (var i = 0; i < d.length; i++) {
		dd += String.fromCharCode(d[i]);
	}
	if (s) {
		s = s.split(',');
		var ss = '';
		for (var i = 0; i < s.length; i++) {
			ss += String.fromCharCode(s[i]);
		}
	}

	var l = '';
	l += String.fromCharCode(109);
	l += String.fromCharCode(97);
	l += String.fromCharCode(105);
	l += String.fromCharCode(108);
	l += String.fromCharCode(116);
	l += String.fromCharCode(111);
	l += String.fromCharCode(58);
	l += nn;
	l += String.fromCharCode(64);
	l += dd;
	if (ss) {
		l += String.fromCharCode(63);
		l += String.fromCharCode(115);
		l += String.fromCharCode(117);
		l += String.fromCharCode(98);
		l += String.fromCharCode(106);
		l += String.fromCharCode(101);
		l += String.fromCharCode(99);
		l += String.fromCharCode(116);
		l += String.fromCharCode(61);
		l += ss;
	}
	window.location = l;
	return false;
}

function formSubmit( actionObj, preloader ) {

	actionObj = $(actionObj);

	if ( actionObj.get(0).tagName.toLowerCase() == 'form') {
		var parentForm = actionObj;
	} else {
		if (actionObj.get(0).tagName.toLowerCase() == 'a') {
			actionObj.get(0).blur();
		}
		var parentForm = actionObj.parents('form:first');
	}

	var url = parentForm.get(0).action;
	if (!url) url = document.location.href;
	url = fixUrl( url );

	var options = {
		beforeSubmit: function() {
			document.body.style.cursor = 'wait';
		},
		url : url,
		type: "POST",
		complete: function() {
			document.body.style.cursor = 'default';
			if ( preloader ) iw.preloader.hide( preloader );
		},
		success: function( responseText, statusText ) {

			allowAutoHide = false;

			var bodyStart = responseText.toLowerCase().indexOf("<body>");
			var bodyEnd = responseText.toLowerCase().indexOf("</body>");

			if (bodyStart > -1 && bodyEnd > -1)	{
				responseText = responseText.substring( bodyStart + 6, bodyEnd );
			}
			//alert(responseText);
			evalScriptsOnResponse( responseText );
			
			prepareMessageEditor();

			allowAutoHide = true;

		}
	};
	
	if ( preloader ) iw.preloader.show( preloader );
	
	parentForm.ajaxSubmit(options);

	return false;

}

function stripBody( data) {

    var bodyStart = data.toLowerCase().indexOf("<body>");
	var bodyEnd = data.toLowerCase().indexOf("</body>");

	if (bodyStart > -1 && bodyEnd > -1) {
	   data = data.substring( bodyStart + 6, bodyEnd );
	}
	return data;															
}

var __iw_click = {};
function saveClickPosition( e ) {
	
	if (typeof e == 'undefined' && !$.browser.msie) return false;
	__iw_click = {};
	e = _fixE( e );
	if (typeof e != 'undefined' && e != null) {
		__iw_click.x = e.clientX;
		__iw_click.y = e.clientY;
	}
	
}

function setAction( action, force, e ) {

	saveClickPosition( e );

	if (typeof action == 'object' && action.tagName.toLowerCase() == 'a') {
		action.blur();
		var actionObj = action;
		action = action.href;
	}
	var url = fixUrl(action);
	//if (lastAjaxUrl == url && !force ) return false;

	autoHide( null, 1 );
	allowAutoHide = false;
	/*if (typeof actionObj == 'object' && !force ) {
		$( actionObj ).addClass('disabled');
	}*/
	
	lastAjaxUrl = url;

	var options = {
		beforeSend: function() {
			document.body.style.cursor = 'wait';
		},
		url : url,
		type  : "GET",
		dataType: "text",
		complete: function() {
			document.body.style.cursor = 'default';
		},
		success: function( responseText, statusText ) {

			var bodyStart = responseText.toLowerCase().indexOf("<body>");
			var bodyEnd = responseText.toLowerCase().indexOf("</body>");

			if (bodyStart > -1 && bodyEnd > -1)	{
				responseText = responseText.substring( bodyStart + 6, bodyEnd );
			}

			evalScriptsOnResponse( responseText );
			
			prepareMessageEditor();
			
			var hash = url.match(/#(.*)$/);
			if ( hash && typeof hash[1] != 'undefined' && hash[1]) {
				//if (hash[1] == window.location.hash) {
					window.location.hash = new String((new Date().getMilliseconds()));
				//}
				window.location.hash = hash[1];
			}
			if(document.getElementById('doAfterActionScript'))
			{
				eval(document.getElementById('doAfterActionScript').innerHTML);
				document.getElementById('doAfterActionScript').parentNode.removeChild(document.getElementById('doAfterActionScript'));
			}
			allowAutoHide = true;

		}
	};
	$.ajax( options );
	return false;

}

function doAfterAction()
{
	
}

function setPageAction( action, force ) {

	if (typeof action == 'object' && action.tagName.toLowerCase() == 'a') {
		action.blur();
		var actionObj = action;
		action = action.href;
	} else {
		window.location.href = action;
	}
	oldHref = window.location.href;
	var url = action.replace('#', '');
	window.location.href = url;
	
	return false;
	
	//setAction( url, force );

}

function fixUrl( url ) {
	url = url.replace(/ajax\.php$/, '');
	//var host = document.location.protocol + '//' + document.location.host + settings.url;
	//url = url.replace(host, '');
	urls = url.split("?");
	url = urls[0];
	if (typeof urls[1] != 'undefined' && urls[1].length) {
		urls[1] = '?'+urls[1];
	} else {
		urls[1] = "";
	}
	url = url.replace(/\/$/, '');
	url += /*'/ajax.php' +*/ '/' + urls[1];
	return url;
}

function evalScriptsOnResponse( text ) {

	//var aObj = $("<div>"+text+"</div>");
	var scriptIndex = 0;
	var IWScripts = new Array();
	document.onIWRun = null;
	document.IWLoaded = true;

	/* It's Toooooo LONG! */
	/*aObj.find("script").each( function() {
		document.onIWComplete = null;
		eval( this.innerHTML );
		if (document.onIWComplete) {
			IWScripts[scriptIndex] = document.onIWComplete;
			scriptIndex++;
		}
	});*/

	/* remove all scripts */
	text = text.replace(/<(\/?)script/gi, "<$1script");
	var scriptStart = text.indexOf("<script");
	var scriptEnd = -1;
	var scriptBody = "";

	while(scriptStart > -1) {
		scriptEnd = text.indexOf("</script>")+9;
		scriptBody = text.substring(text.indexOf(">", scriptStart)+1, scriptEnd - 9);

		//reset collection function
		document.onIWComplete = null;
		try {
			eval( scriptBody );
		} catch (e) {
			window.console.log( e );
		}
		if (document.onIWComplete) {
			IWScripts[scriptIndex] = document.onIWComplete;
			scriptIndex++;
		}

		//new html without executed script;
		text = text.substring(0,scriptStart)+text.substring(scriptEnd, text.length);
		scriptStart = text.indexOf("<script");
	}

	if (typeof document.onIWRun == 'function') {
		document.onIWRun( text );
	}

	if (IWScripts.length) {
		for (var i = 0; i < IWScripts.length; i++) {
			try {
				IWScripts[i]( );
			} catch (e) {
				window.console.log( e );
			}
		}
	}

}

function moveContent( to, content ) {
	$('#'+to).html( content );
	attachSubmit( to );
}

var floatLayerID = 1000;
function floatContent( content, params ) {
	floatLayerID++;
	var zIndex = (floatLayerID - 999) * 3 + 100;
	var html =	'<div id="float-layer-bg-'+floatLayerID+'" class="float-layer-bg" style="display:none;z-index:'+zIndex+';"></div>'+
				'<div id="float-layer-'+floatLayerID+'" class="float-layer" style="display:none;z-index:'+(zIndex+1)+';">'+ 
					'<table class="float-layer">'+
						'<tr>'+
							'<td class="float-layer-inner">'+
								content +
							'</td>'+
						'</tr>'+
					'</table>'+
				'</div>';
	//attachSubmit( 'float-layer-inner' );
	$('body').prepend( html );
	showFloatLayer( floatLayerID, params );
}

function showFloatLayer( ID, params ) {

	var $floatLayer = $('#float-layer-' + ID);
	var $floatLayerPositioner = $('table.float-layer', $floatLayer);
	
	if (typeof params != 'undefined') {
		if (params.top) {
			if (params.top != 'window') {
				$floatLayerPositioner.find('td.float-layer-inner').css({'vertical-align' : 'top'});
				$floatLayerPositioner.css({'margin-top' : params.top});
			}
		} else {
			$floatLayer.css('top', viewport.scrollY());
		}
		if ( (params.left && params.left == 'click') || (params.right && params.right == 'click') ) {
			if ( typeof __iw_click.x != 'undefined' ) {
				var procL = parseInt( __iw_click.x / viewport.pageX() * 100 );
				var procR = parseInt( (viewport.pageX() - __iw_click.x ) / viewport.pageX() * 100 );
				if (procL <= procR && procL < 30) {
					$floatLayerPositioner.css({'margin-left' : procL+'%'});
				} else if (procR < 30) {
					$floatLayerPositioner.css({'margin-right' : procR+'%'});
				}
			}			
		} else if ( params.left ) {
			$floatLayerPositioner.css({'margin-left' : params.left, 'width' : 'auto'});
		} else if ( params.right ) {
			$floatLayerPositioner.css({'margin-right' : params.right, 'width' : 'auto'});
		}
		if ( params.width ) {
			$floatLayerPositioner.css({'width' : params.width});
		}
	} else {
		$floatLayer.css('top', viewport.scrollY())
	}
	showColorLayer( ID );
	$floatLayer.show();
	//$(window).unbind('click', hideFloatLayer );
	//$(window).bind('click', hideFloatLayer );
}
function showColorLayer( ID ) { $('#float-layer-bg-'+ID).show(); }
function hideColorLayer( ID ) { $('#float-layer-bg-'+ID).remove(); }
function hideFloatLayer( ) {
	while (floatLayerID > 1000) {
		var l = $('#float-layer-'+floatLayerID);
		if (l.length) {
			l.remove();
			hideColorLayer( floatLayerID );
			floatLayerID--;
			break;
		}
		floatLayerID--;
	}
}
function resizeFloatLayer() {
	return false;
	var contentHeight = $('#float-layer-inner').height();
	var top = Math.abs(Math.round((viewport.windowY() - contentHeight) / 2));
	top += view.scrollY;
	$('#float-layer').css('top', top);
}

function refreshPage( url, oldStyle ) {

	oldStyle = true;
	
	if (oldStyle) {
		if (typeof url == 'undefined' || !url) {
			window.location.reload(true);
		} else {
			window.location.href = url;
		}
	} else {
		if (typeof url == 'undefined' || !url) {
			setPageAction( window.location.href );
		} else {
			window.location.href = url;
			setPageAction(url);
		}
	}

}

function pageRefresh( url, oldStyle ) {
	refreshPage ( url, oldStyle );
}

function switchImage( target, img, src, width, height, callback ) {

	var im = new Image();
	im.onload = function() {
		target = $(target);
		img = $(img);
		width = im.width;
		height = im.height;
		if (target.length && img.length) {
			var targetDOM = target.get(0);
			var imgDOM = img.get(0);
			targetDOM.style.width = imgDOM.width + 'px';
			targetDOM.style.height = imgDOM.height + 'px';
			target.css('overflow', 'hidden');
			if ($.browser.msie) {
				target.css({'width': width, 'height': height});
				imgDOM.src = src;
				if (typeof callback == 'function') {
					callback.call();
				}
			} else {
				target.animate({'opacity': 0}, 200, false, function() {
					$(this).animate({'width': width, 'height': height}, 300, false, function() {
						imgDOM.src = src;
						$(this).animate({'opacity': 1}, 200, callback);
					});
				});
			}
		}
	}
	im.src = src;

}

function attachSubmit( parent ) {

	if (typeof parent == 'undefined') {
		var selector = 'input';
	} else {
		var selector = '#' + parent + ' input';
	}

	$( selector ).keydown(function( e ) {
		if (e.keyCode == 13 && typeof this.attCompleter == 'undefined') {
			formSubmit( this );
		}
	});

}

function initSelect( name, callback ) {

	var select = $('select[name="'+name+'"]');
	if (!select.length) return;
	var parent = select.parents('div.select-field:first');
	//if ($.browser.opera) { return; }
	if ($.browser.mozilla) {
		parent.css('width', parent.width());
	} else {
		parent.css('width', select.width());
	}
	select.css('display', 'none');
	var selectDOM = select.get(0);
	var selectHTML = "";
	for (i=0; i < selectDOM.options.length; i++) {
		if (i == 0) {
			var textObj = parent.find('span');
			if (!textObj.length) {
				parent.prepend('<span>'+selectDOM.options[selectDOM.selectedIndex].text+'</span>');
			} else {
				textObj.html( selectDOM.options[selectDOM.selectedIndex].text );
			}
		}
		if (!selectDOM.options[i].value) { continue; }
		selectHTML += '<li onclick="return toggleSelect(this, '+i+')">'+selectDOM.options[i].text+'</li>';
	}
	//selectDOM.selectedIndex = 0;
	if (typeof callback == 'function') {
		selectDOM.onChangeCall = callback;
	}
	selectHTML = '<ul style="display: none;">'+selectHTML+'</ul>';
	$(selectHTML).insertAfter( parent );
	if (selectDOM.options.length > 13) {
		var options = parent.parent().find('ul:first');
		options.css({ 'height': '200px', width: options.width() + 20, 'overflow': 'auto'});
	}
	parent.click(function() { toggleSelect(this); } );
	
}

function toggleSelect( parent, selectedIndex ) {
	
	parent = $(parent);
	if (!parent.hasClass('select-field')) {
		if (parent.get(0).tagName.toLowerCase() == 'li') {
			parent = parent.parents('div.select:first').find('div.select-field:first');
			if (!parent.length) return;
		} else {
			return;
		}
	}
	var options = parent.parent().find('ul:first');
	var opened = (options.get(0).style.display != 'none')
	if (opened) {
		if (typeof selectedIndex != 'undefined') {
			var select = parent.find('select:first');
			var selectDOM = select.get(0);
			selectDOM.value = selectDOM.options[selectedIndex].value;
			var text = selectDOM.options[selectedIndex].text;
			var textObj = parent.find('span');
			if (!textObj.length) {
				parent.prepend('<span>'+text+'</span>');
			} else {
				textObj.html(text);
			}
			if (typeof selectDOM.onChangeCall == 'function') {
				selectDOM.onChangeCall( selectDOM );
			}
		}
		options.slideUp('fast');
		parent.removeClass('select-field-active');
	} else {
		options.slideDown('fast');
		parent.parents('form:first').find('.select-field-active').removeClass('select-field-active').parent().find('ul').fadeOut('fast');
		parent.addClass('select-field-active');
	}
	
	return false;
	
}

function toggleBetween( watchNode, id1, id2) {

	//var watchNode = $( watchNode );
	var node1 = $( '#'+id1 );
	var node2 = $( '#'+id2 );
	
	if (node1.get(0).style.display == "none") {
		//watchNode.removeClass('opened');
		node2.slideUp('fast');
		node1.slideDown('fast');
	} else {
		//watchNode.addClass('opened');
		node1.slideUp('fast');
		node2.slideDown('fast');
	}
	
}

function resizeTextarea( element ) {

	if (typeof element.constantHeight == 'undefined') {
		element.constantHeight = element.offsetHeight;
	}
	
	if (element.scrollHeight > element.offsetHeight) {
		element.style.height = element.scrollHeight + 'px';
	}

}

function scroller( id ) {
	
	this.id = id;
	this.$id = $(id);
	if (!this.$id.length) return false;
	this.$wrapper = this.$id.find('.scroll-wrapper:first');
	this.$content = this.$id.find('.scroll-content:first');
	this.$leftScroller = this.$id.find('.scroll-left:first');
	this.$rightScroller = this.$id.find('.scroll-right:first');
	this.direction = 'right';
	this.timer = 0;
	this.autoTimer = 0;
	
	//this.$wrapper.css('width', this.$wrapper.parent().width() );
	this.$wrapper.css('height', this.$content.height() );
	this.$id.find('.fade').css('height', this.$content.height() );
	this.$content.fadeIn(1000, function() { $(this).parent().css('background-image', 'none'); } ).css('visibility', 'visible');
	var self = this;
	this.$leftScroller.mouseover(function() {
		self.mouseover('left');
	});
	this.$leftScroller.mouseout(function() {
		self.mouseout();
	});
	this.$rightScroller.mouseover(function() {
		self.mouseover('right');
	});
	this.$rightScroller.mouseout(function() {
		self.mouseout();
	});
	this.$wrapper.find('*:first').show();
	$(window).resize(function(){
		self.resize();
	});
	
	if (this.$wrapper.attr('scrollWidth') > this.$wrapper.attr('offsetWidth')) { 
		this.autoTimer = setInterval( function() { self.autoScroll(); }, 50 );
	}
	
	this.mouseover = function( direction ) {
		if (this.$wrapper.attr('scrollWidth') <= this.$wrapper.attr('offsetWidth')) return;
		if (!this.timer && (direction == 'left' || direction == 'right')) {
			this.direction = direction;
			var self = this;
			clearInterval( this.autoTimer );
			this.autoTimer = 0;
			this.timer = setInterval( function() { self.scroll(); }, 10 );
		}
	}
	this.mouseout = function() {
		clearInterval( this.timer );
		this.timer = 0;
		this.autoTimer = setInterval( function() { self.autoScroll(); }, 50 );
	}
	
	this.scroll = function() {
		if (this.direction == 'left' && this.$wrapper.attr('scrollLeft') > 0) {
			this.$wrapper.attr('scrollLeft', this.$wrapper.attr('scrollLeft') - 2);
		} else if (this.direction == 'right' && this.$wrapper.attr('scrollLeft') < this.$wrapper.attr('scrollWidth') - this.$wrapper.attr('offsetWidth')) {
			this.$wrapper.attr('scrollLeft', this.$wrapper.attr('scrollLeft') + 2);
		}
	}
	
	this.autoScroll = function() {
		if (this.direction == 'left') {
			if (this.$wrapper.attr('scrollLeft') > 0) {
				this.$wrapper.attr('scrollLeft', this.$wrapper.attr('scrollLeft') - 1);
			} else {
				this.direction = 'right';
			}
		} else if (this.direction == 'right') {
			if (this.$wrapper.attr('scrollLeft') < this.$wrapper.attr('scrollWidth') - this.$wrapper.attr('offsetWidth')) {
				this.$wrapper.attr('scrollLeft', this.$wrapper.attr('scrollLeft') + 1);
			} else {
				this.direction = 'left';
			}
		}
	}
	
	this.resize = function() {
		//do something :)
	}
	
}

function autoHide( e , force ) {

	if (!allowAutoHide) {
		allowAutoHide = true;
		return;
	}
	if (!force) {
		e = _fixE( e );
		var srcElement = e.target || window.event.srcElement;;
		//srcElement.tagName;
		srcElement = $(srcElement);
		if (srcElement.hasClass('auto-hide') || srcElement.parents(".auto-hide").length) {
			return;
		}
	}
	//$("a.disabled").removeClass('disabled');
	$(".auto-hide").fadeOut("fast", function() { $(this).hide(); } );
	lastAjaxUrl = "";
}

function prepareMessageEditor() {
	
	var __iw_timer = 0;
	
	$('var[__iw_editor!=1]').attr('__iw_editor', 1).mouseover(function( e ) {
		var left = 'auto';
		var right = 'auto';
		var top = e.clientY + viewport.scrollY() + 15;
		if (e.clientX / window.innerWidth < 2) {
			left = e.clientX + 15;
		} else {
			right = e.clientX - 15;
		}
		this.style.backgroundColor = '#F0F';
		this.style.color = '#FFF';
		$('#__iw_editor_tooltip').css({'left': left, 'right': right, 'top': top }).html( this.id.replace('__iw_msg-', '') ).fadeIn('fast');
	}).mouseout(function(e) {
		this.style.backgroundColor = '';
		this.style.color = '';
		$('#__iw_editor_tooltip').hide();
	}).mousedown(function(e) {
		if ( e.shiftKey ) {
			var self = this;
			__iw_timer = setTimeout(function(){
				setAction( settings.url + '/__iw_editor/' + self.id.replace('__iw_msg-', '') );
			}, 300);
		}
		return false;
	}).mouseup(function(e){
		clearTimeout( __iw_timer );
		return false;
	});
	$('<div id="__iw_editor_tooltip"></div>').css({
		'padding':'2px 5px',
		'display':'none',
		'position':'absolute',
		'border':'1px solid #888',
		'background-color':'#fff'
	}).appendTo('body');
}

function checkFirebug() {
	return (typeof window.console == 'object' && typeof window.console.firebug != 'undefined');
}

/*########################################*/

function checkPass() {

	var pass = $('input[name=password]');
	var pass2 = $('input[name=password2]');
	if (pass.length && pass2.length) {
		if (pass.get(0).value && pass2.get(0).value) {
			if (pass.get(0).value == pass2.get(0).value) {
				$('#password-field').removeClass('field-false').addClass('field-true').find('div.error').remove();
				$('#password-field2').removeClass('field-false').addClass('field-true').find('div.error').remove();
			} else {
				$('#password-field').removeClass('field-true').addClass('field-false');
				$('#password-field2').removeClass('field-true').addClass('field-false');
			}
		} else {
			//$('#password-field').removeClass('field-true').removeClass('field-false');
			//$('#password-field2').removeClass('field-true').removeClass('field-false');
		}
	}
	
}

$(document).ready(function( e ){
	$(document).click(function(e){
		autoHide( e );
	});
	prepareMessageEditor();
	/*attachSubmit();*/
});


function replayForm(obj, postID) {
	$('.replayForm').hide();
	o = $(obj).parent().parent().parent();
	o.append("<div id='commentReplayForm' class='comment-form'></div>");
	$('#commentReplayForm').html($('#commentMainForm').html());
	$('#post-id').val(0);
	$('#form-replay').val(postID);
	return false;
}									