//======================= check_reg_form
function check_reg_form()
{
Str= '';

//	if(document.Reg.alias.value== '')
//	{
//		Str= 'Заполните поле =Логин=.';
//	}

	if(!/^.{3,34}$/i.test(document.Reg.alias.value) || (/^\s+$/i.test(document.Reg.alias.value)))
	{
		Str= 'Поле =Псевдоним= должно содержать не менее 3х символов.';
	}

	if((document.Reg.PWD.value== '') && (document.Reg.UID.value== ''))
	{
		if(Str!= '') Str+= "\n";
		Str+= 'Пароль не должен быть пустым.';
	}

	if(document.Reg.PWD.value!= document.Reg.PWD1.value)
	{
		if(Str!= '') Str+= "\n";
		Str+= 'Проверьте правильность введенных паролей.';
	}

	if(!/^[a-z0-9_+.-]+\@([a-z0-9_-]+\.)+[a-z0-9]{2,4}$/i.test(document.Reg.email.value))
	{
		if(Str!= '') Str+= "\n";
		Str+= 'Некорректный адрес электронной почты.';
	}

	if(Str== '')
	{
		return true;
	}
	else
	{
		alert(Str);
		return false;
	}
}

function mail(u, s, d, txt)
{
var l="ilto";
	if (txt == null)
		{document.write("<a"+" href="+"ma"+l+":"+u+"&#64;"+s+ "." +d+">"+u+"&#64;"+s+ "." +d+"</a>");}
	else
		{document.write("<a"+" href="+"ma"+l+":"+u+"&#64;"+s+ "." +d+">"+txt+"</a>");}
}

function mail_(d, txt)
{
var l="ilto";
	if (txt == null)
		{document.write("<a"+" href="+"ma"+l+":"+d+">"+d+"</a>");}
	else
		{document.write("<a"+" href="+"ma"+l+":"+d+">"+txt+"</a>");}
}

//======================= shittext
function show_abstracts(div) {
        var tez = document.getElementById('abstracts').childNodes;
        var tez_new = new Array();
        var j=0;
        for (var i in tez) {
                if(tez[i].nodeType==1) {
                        tez_new[j] = tez[i];
                        j++;
                }
        }
        tez = tez_new;
        var rand = getrandom(0,(tez.length-1));
        for(var i=0; i<tez.length; i++)
                tez[i].style.display = 'none';

        tez[rand].style.display = 'block';

				document.getElementById('prefooter').style.display = 'block';
}

function getrandom(min,max) {
	max++;
	var range = max - min;
	return Math.floor(Math.random()*range) + min;
}

//======================= sliders embed
$(document).ready(function(){

	//hide message_body after the first one
	$(".embed_input").hide();

	//toggle message_body
	$(".embed").click(function(){
		$("div#d"+ this.id+ ".embed_input").slideToggle(500)
		return false;
	});
});

//======================= sliders forums
$(document).ready(function(){

	//hide message_body after the first one
	$(".my_forums_list").show();

	//toggle message_body
	$(".my_forums").click(function(){
		$("div#d"+ this.id+ ".my_forums_list").slideToggle(500)
		return false;
	});
});

//======================= автовыделение в inputах
function selectText(input) {
    if (input.createTextRange) {
        var oRange = input.createTextRange();
        oRange.moveStart("character", 0);
        oRange.moveEnd("character", 0);
        oRange.select();
    } else if (input.setSelectionRange) {
        input.setSelectionRange(0, input.value.length);
    }

    input.focus();
};

//======================= logon
$(document).ready(
	function()
	{
		$('#windowOpen').bind(
			'click',
			function() {
				if($('#window').css('display') == 'none') {
					$(this).TransferTo(
						{
							to:'window',
							className:'transferer2',
							duration: 400,
							complete: function()
							{
								$('#window').show();
								$("#login_user").focus();
							}
						}
					);
				}
				this.blur();
				return false;
			}
		);
		$('#windowClose').bind(
			'click',
			function()
			{
				$('#window').TransferTo(
					{
						to:'windowOpen',
						className:'transferer2',
						duration: 400
					}
				).hide();
			}
		);
		$('#windowMin').bind(
			'click',
			function()
			{
				$('#windowContent').SlideToggleUp(300);
				$('#windowBottom, #windowBottomContent').animate({height: 10}, 300);
				$('#window').animate({height:40},300).get(0).isMinimized = true;
				$(this).hide();
				$('#windowResize').hide();
				$('#windowMax').show();
			}
		);
		$('#windowMax').bind(
			'click',
			function()
			{
				var windowSize = $.iUtil.getSize(document.getElementById('windowContent'));
				$('#windowContent').SlideToggleUp(300);
				$('#windowBottom, #windowBottomContent').animate({height: windowSize.hb + 13}, 300);
				$('#window').animate({height:windowSize.hb+43}, 300).get(0).isMinimized = false;
				$(this).hide();
				$('#windowMin, #windowResize').show();
			}
		);
		$('#window').Resizable(
			{
				minWidth: 200,
				minHeight: 60,
				maxWidth: 700,
				maxHeight: 400,
				dragHandle: '#windowTop',
				handlers: {
					se: '#windowResize'
				},
				onResize : function(size, position) {
					$('#windowBottom, #windowBottomContent').css('height', size.height-33 + 'px');
					var windowContentEl = $('#windowContent').css('width', size.width - 25 + 'px');
					if (!document.getElementById('window').isMinimized) {
						windowContentEl.css('height', size.height - 48 + 'px');
					}
				}
			}
		);
	}
);

CommentLength= 3072;
function CharsLeft() {
  txt = document.getElementById('txt').value;
  value = CommentLength - txt.length;
  if (value <= 0) {
    getElementById('txt').value = txt.substring(0,CommentLength);
    value = 0;
  }
  document.getElementById('CharsCountID').innerText = value;
}

var hHided= [];
function HideBadComments(Type)
{
	var RE= new RegExp("RATE_(.+)");
	var aElements= document.getElementsByTagName(Type || "*");
	for(var i= 0; i< aElements.length; i++ )
	{
		if(!/^RATE_/i.test(aElements[i].id)) continue;
		RE.exec(aElements[i].id);
		var ID= RegExp.$1;

		var Rate= parseInt(document.getElementById('RATE_'+ID).innerHTML);
		if(Rate< -20)
		{
			hHided['P'+ID]= document.getElementById('P'+ID).innerHTML;
			document.getElementById('P'+ID).innerHTML= "<SPAN style=\"cursor: pointer; color: #CC0000;\" onclick=\"UnHideBadComments('"+ 'P'+ID+ "')\">Заминусован пользователями.</SPAN>";
		}
		ID= '';
	}

return(0);
}

function UnHideBadComments(ID)
{
	document.getElementById(ID).innerHTML= hHided[ID];

return(0);
}

//======================= окно для vkontakte
function getClientCenterX()
{
	return parseInt(getClientWidth()/2)+getBodyScrollLeft();
}

function getClientCenterY()
{
	return parseInt(getClientHeight()/2)+getBodyScrollTop();
}

function VKWindow(URI, width, height, left, top) 
{
	if(!left) left= (document.documentElement.clientWidth/2)- (width/ 2);
	if(!top)  top=  (document.documentElement.clientHeight/2)- (height/ 2);

	window.open(URI, "_blank", 
"width="+width+",height="+height+",left="+left+",top="+top+",titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no"); 
}

