var fadeValue = 0.2;
var filesToUpload = 0;
var filesUploaded = 0;
function chechLogin(login, obj)
{
	obj.load('/ajax/register/checklogin?login='+login);
}
function confirmPass(){
	if (document.getElementById('pass1').value != document.getElementById('pass2').value)
	{
		document.getElementById('pass_equal').style.display = '';
		return false;
	} else document.getElementById('pass_equal').style.display = 'none';
	return true;
}
function validEmail(email)
{
	return /\w+@\w+\.[a-z]{2,4}/.test(email);
}
function getOffsetLeft(obj){
	var top = obj.offsetLeft;
	
	while( (obj = obj.offsetParent) != null ){
		top += obj.offsetLeft;
	}
	
	return top;
}
function getOffsetTop(obj){
	var top = obj.offsetTop;
	
	while( (obj = obj.offsetParent) != null ){
		top += obj.offsetTop;
	}
	
	return top;
}

function replaceText(text, textarea)
{
 if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
 {
 var caretPos = textarea.caretPos;

 caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
 caretPos.select();
 }
 else if (typeof(textarea.selectionStart) != "undefined")
 {
 var begin = textarea.value.substr(0, textarea.selectionStart);
 var end = textarea.value.substr(textarea.selectionEnd);
 var scrollPos = textarea.scrollTop;

 textarea.value = begin + text + end;

 if (textarea.setSelectionRange)
 {
 textarea.focus();
 textarea.setSelectionRange(begin.length + text.length, begin.length + text.length);
 }
 textarea.scrollTop = scrollPos;
 }
 else
 {
 textarea.value += text;
 textarea.focus(textarea.value.length - 1);
 }
}
function newComment(callback, id, textarea)
{
	$.post('/ajax/comment_adder/addArticleComment?type=ajax', {'callback':callback, 'foreign_id':id, 'text':textarea[0].value}, function(e){
	$('#newComment').html($('#newComment')[0].innerHTML + e);
	});
}
