	
function confirmLink()
{
    return confirm("Действительно?");
} 

function htmlspecialchars_decode (string, quote_style) {   
    string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"');
    return string;
}
/*обсудить новость*/




/*новая шапка*/
var initSubmenu = function() {
    $(".main-menu").css({height: 26});
    
	$('.main-li').each(function(){
		var $this = $(this);
        $this.find(".sub-menu").css({opacity: 0, display: 'none', marginLeft: 0} );
        
		$this.hover(
			function(){
				if(this.showing) {
					$(this).find("a:first").next().stop().animate({opacity: 1});
					this.showing = true;

				} else {
					$(this).find("a:first").next().css({display: "block"}).animate({opacity: 1}, "fast");
					this.showing = true;

				}
			},
			function(){
				$(this).find("a:first").next().stop().animate({opacity: 0}, "fast", function(){ $(this).css({display: "none"}).parent().get(0).showing = false; })
			}
		);
	});
}

var initSubtext = function() {
}



//скрываем показываем див (для расширеного поиска)
function collapse(id)
{
var d=document;
if(d.getElementById(id).style.display=='none')  d.getElementById(id).style.display=''
else d.getElementById(id).style.display='none';
}
function trim (str) {
	var str = str.replace(/^\s+/, '');
		for (var i = str.length; --i >= 0;) {
   			if (/\S/.test(str.charAt(i))) {
   				str = str.substring(0, i + 1);
   				break;
   			}
  		}
	return str;
}

//аякc запрос на ури и сгружаем содержимое в div_id
function GetData(uri,div_id) {
	var ajax = new Ajax();
	if (ajax.isValid){
		ajax.get(
			'http://'+ document.domain  + uri,
			function () {
				var response = ajax.response();
				if ( response && response.status == 200 )
					document.getElementById(div_id).innerHTML = response.text;
				else if ( response && response.status >= 500 )
					document.getElementById(div_id).innerHTML = '<'+'p'+'>'+'Произошла ошибка'+'<'+'/'+'p'+'>';
				else
				document.getElementById(div_id).innerHTML = '<'+ 'center'+'>' +'<'+ 'img' + ' src="/forums/img/roter.gif"'+'/' +'>' + '<'+ '/' + 'center' + '>';	
			}
		);
		return false;
	}
	else {
		return true;
	}
}
//подмена содержимого
function cHTML(eid,code){
	var element=document.getElementById(eid);
	element.innerHTML = code;
}

  function chkfs()
     {  
		var d=document;
		var ms="";
			if (d.f.qry.value=='') ms+='Введите запрос для поиска!\n';
		if(ms)
 		{
   			alert('Ошибка при заполнении формы:\n'+ms);return false;
 		} 
 		
	}
	
	  function chkfs2()
     {  
		var d=document;
		var ms="";
			if (d.f2.qry.value=='') ms+='Введите запрос для поиска!\n';
		if(ms)
 		{
   			alert('Ошибка при заполнении формы:\n'+ms);return false;
 		} 
	}
	
	
function fserialize (fname) {
	var elements = eval("document." + fname + ".elements");
	var fields = new Array();
	fields.push('ajax=1');
	for (var i=0; i < elements.length; i++) {
		var element = elements[i];
		
		switch (element.type.toLowerCase()) {
			case 'hidden':
			case 'password':
			case 'text':
			case 'select-one':
				fields.push( encodeURIComponent(element.name) + '=' + (element.value) );
			case 'textarea':
				fields.push( encodeURIComponent(element.name) + '=' + encodeURIComponent(element.value) );
			case 'checkbox':
			case 'radio':
				if (element.checked)
					fields.push(
						encodeURIComponent(element.name)
						+ '=' +
						encodeURIComponent(element.value)
					);
		}
	}
	return fields.join('&');
}



function SubmitForm(fname,uri,divid) {
var result=true;
if (typeof(checkform) == "function") {
result=checkform(fname);
}	
if (result==true) {
	var ajax = new Ajax();
	if (ajax.isValid){
		var formContent = fserialize(fname);
		ajax.post(
			'http://'+ document.domain +  uri,
			formContent,
			function () {
				var response = ajax.response();
				if ( response && response.status == 200 )
					document.getElementById(divid).innerHTML = response.text;
				else if ( response && response.status >= 500 )
					document.getElementById(divid).innerHTML = '<'+'p'+'>'+'Произошла ошибка'+'<'+'/'+'p'+'>';
				else
					document.getElementById(divid).innerHTML = '<'+ 'center'+'>' +'<'+ 'img' + ' src="/forums/img/roter.gif" '+'/' +'>' + '<'+ '/' + 'center' + '>';	
				
			}
		);
		return false;
	}
	else {
		return true;
	}
}
}
//сгружаем в див данные из аякса
function SubmitLink(uri,divid) {
	var result=true;
	var ajax = new Ajax();
	if (ajax.isValid){
		ajax.get(
			'http://'+ document.domain +  uri,
			function () {
				var response = ajax.response();
				if ( response && response.status == 200 )
					document.getElementById(divid).innerHTML = response.text;
				else if ( response && response.status >= 500 )
					document.getElementById(divid).innerHTML = '<'+'p'+'>'+'Произошла ошибка'+'<'+'/'+'p'+'>';
				else
					document.getElementById(divid).innerHTML = '<'+ 'center'+'>' +'<'+ 'img' + ' src="/forums/img/roter.gif"'+'/' +'>' + '<'+ '/' + 'center' + '>';	

			}
		);
		return false;
	}
	else {
		return true;
	}
}
//сгружаем в див данные из аякса
function ConfirmSubmitLink(uri,divid) {
	var cnf;
	cnf= confirm("Действительно?");
	
if (cnf) {
	var result=true;
	var ajax = new Ajax();
	if (ajax.isValid){
		ajax.get(
			'http://'+ document.domain +  uri+ '&pi='+Math.random(100000),
			function () {
				var response = ajax.response();
				if ( response && response.status == 200 )
					document.getElementById(divid).innerHTML = response.text;
				else if ( response && response.status >= 500 )
					document.getElementById(divid).innerHTML = '<'+'p'+'>'+'Произошла ошибка'+'<'+'/'+'p'+'>';
				else
					document.getElementById(divid).innerHTML = '<'+ 'center'+'>' +'<'+ 'img' + ' src="/forums/img/roter.gif"'+'/' +'>' + '<'+ '/' + 'center' + '>';
			}
		);
		return false;
	}
	else {
		return true;
	}
}
}
function areadis()  {
if (document.getElementById("kwd1").disabled==true) {
 document.getElementById("kwd1").disabled=false;
 document.getElementById("kwd1").style.background='#ffffff';  
}
else  {
 document.getElementById("kwd1").disabled=true;
 document.getElementById("kwd1").style.background='#e6e6e6';  

}
}
function areadis2()  {
if (document.getElementById("desc").disabled==true) {
 document.getElementById("desc").disabled=false;
 document.getElementById("desc").style.background='#ffffff';  
}
else  {
 document.getElementById("desc").disabled=true;
 document.getElementById("desc").style.background='#e6e6e6';  

}

}
//для форумов
function uinfo (uid) {
	isDOM=document.getElementById; isMSIE=document.all && document.all.item; isNetscape4=document.layers; isOpera=window.opera; isOpera5=isOpera && isDOM; isMSIE5=isDOM && isMSIE; isMozilla=isNetscape6=isDOM && !isMSIE && !isOpera;
	if (isMozilla || (isOpera && !isMSIE5)) { offset=document.documentElement.scrollTop;tt=screen.height-250; }
	if (isMSIE5) { offset=document.body.scrollTop;tt=document.body.clientHeight; }
	document.getElementById('info').style.height=150+'px';
	var z = document.getElementById('info').style.height;
	zz=(z.replace('px','')/2);
	var y = Math.floor(offset + ((tt)/2))-zz;
	var x = Math.floor((document.body.clientWidth-460)/2);
	var agt=navigator.userAgent.toLowerCase() ;
	var check = agt.search("msie 7.0") 
	if (check!=-1) { 	
		document.getElementById("info").style.position='fixed';
		document.getElementById("info").style.top=(screen.height/2)-250;
		document.getElementById("info").style.left=Math.floor((document.body.clientWidth-460)/2);
	
	}
	else {
		document.getElementById('info').style.top = y + 'px';
		document.getElementById('info').style.left = x + 'px';
	}
	
	document.getElementById("info").style.display='';
	
	var ajax = new Ajax();
	if (ajax.isValid){
		ajax.get(
			'http://'+ document.domain + '/forums/uinfo.php?uid=' + uid + '&pi='+Math.random(100000),
			function () {
				var response = ajax.response();
				if ( response && response.status == 200 )
					document.getElementById("info").innerHTML = response.text;
				else if ( response && response.status >= 500 )
					document.getElementById("info").innerHTML = '<'+'img'+' src="/forums/img/roter.gif" /' + '>';
				else
					document.getElementById("info").innerHTML = '<'+ 'center'+'>' +'<'+ 'img' + 'src="/forums/img/roter.gif+'+'/' +'>' + '<'+ '/' + 'center' + '>';
					
			}
		);
		return false;
	}
	else {
		return true;
	}
}function loveinfo (uid) {
	alert(1);
	isDOM=document.getElementById; isMSIE=document.all && document.all.item; isNetscape4=document.layers; isOpera=window.opera; isOpera5=isOpera && isDOM; isMSIE5=isDOM && isMSIE; isMozilla=isNetscape6=isDOM && !isMSIE && !isOpera;
	if (isMozilla || (isOpera && !isMSIE5)) { offset=document.documentElement.scrollTop;tt=screen.height-250; }
	if (isMSIE5) { offset=document.body.scrollTop;tt=document.body.clientHeight; }
	document.getElementById('info').style.height=150+'px';
	var z = document.getElementById('info').style.height;
	zz=(z.replace('px','')/2);
	var y = Math.floor(offset + ((tt)/2))-zz;
	var x = Math.floor((document.body.clientWidth-460)/2);
	var agt=navigator.userAgent.toLowerCase() ;
	var check = agt.search("msie 7.0") 
	if (check!=-1) { 	
		document.getElementById("info").style.position='fixed';
		document.getElementById("info").style.top=(screen.height/2)-250;
		document.getElementById("info").style.left=Math.floor((document.body.clientWidth-460)/2);
	
	}
	else {
		document.getElementById('info').style.top = y + 'px';
		document.getElementById('info').style.left = x + 'px';
	}
	
	document.getElementById("info").style.display='';
	
	var ajax = new Ajax();
	if (ajax.isValid){
		ajax.get(
			'http://'+ document.domain + '/cards/_card.php?action=' + uid + '&pi='+Math.random(100000),
			function () {
				var response = ajax.response();
				if ( response && response.status == 200 )
					document.getElementById("info").innerHTML = response.text;
				else if ( response && response.status >= 500 )
					document.getElementById("info").innerHTML = '<'+'img'+' src="/forums/img/roter.gif" /' + '>';
				else
					document.getElementById("info").innerHTML = '<'+ 'center'+'>' +'<'+ 'img' + 'src="/forums/img/roter.gif+'+'/' +'>' + '<'+ '/' + 'center' + '>';
					
			}
		);
		return false;
	}
	else {
		return true;
	}
}

function umail (md5,uid) {
	isDOM=document.getElementById; isMSIE=document.all && document.all.item; isNetscape4=document.layers; isOpera=window.opera; isOpera5=isOpera && isDOM; isMSIE5=isDOM && isMSIE; isMozilla=isNetscape6=isDOM && !isMSIE && !isOpera;
	if (isMozilla || (isOpera && !isMSIE5)) { offset=document.documentElement.scrollTop;tt=screen.height-250; }
	if (isMSIE5) { offset=document.body.scrollTop;tt=document.body.clientHeight; }
	document.getElementById('info').style.height=150+'px';
	var z = document.getElementById('info').style.height;
	zz=(z.replace('px','')/2);
	var y = Math.floor(offset + ((tt)/2))-zz;
	var x = Math.floor((document.body.clientWidth-460)/2);
	var agt=navigator.userAgent.toLowerCase() ;
	var check = agt.search("msie 7.0") 
	if (check!=-1) { 	
		document.getElementById("info").style.position='fixed';
		document.getElementById("info").style.top=(screen.height/2)-250;
		document.getElementById("info").style.left=Math.floor((document.body.clientWidth-460)/2);
	
	}
	else {
		document.getElementById('info').style.top = y + 'px';
		document.getElementById('info').style.left = x + 'px';
	}
	
	
	
	
	document.getElementById("info").style.display='';
	var ajax = new Ajax();
	if (ajax.isValid){
		ajax.get(
			'http://'+ document.domain + '/forums/sendmail.php?uid=' + uid + '&to=' + md5+ '&pi='+Math.random(100000),
			function () {
				var response = ajax.response();
				if ( response && response.status == 200 )
					document.getElementById("info").innerHTML = response.text;
				else if ( response && response.status >= 500 )
					document.getElementById("info").innerHTML = '<'+'img'+' src="/forums/img/roter.gif" /' + '>';
				else
					document.getElementById("info").innerHTML = '<'+ 'center'+'>' +'<'+ 'img' + 'src="/forums/img/roter.gif"'+'/' +'>' + '<'+ '/' + 'center' + '>';
					
			}
		);
		return false;
	}
	else {
		return true;
	}
}

 function chkfsend() {
 		var d=document;	
        var ms="";
		if (d.send.subj.value=='') ms+='Пустая тема письма!\n';
		if (d.send.addit.value=='') ms+='Пустое соообщение!\n';
		if (ms) {
			alert ("Ошибка при отправке формы:\n" + ms );
			return false;
		}
		SubmitForm('send','/forums/smail.php','send') 
		return true;
		
     }
 function chkNsend() {
 		var d=document;	
        var ms="";
		if (d.send.subj.value=='') ms+='Пустая тема письма!\n';
		if (d.send.addit.value=='') ms+='Пустое соообщение!\n';
		if (ms) {
			alert ("Ошибка при отправке формы:\n" + ms );
			return false;
		}
		SubmitForm('send','/pmail/smail.php','send') 
		return true;
		
     }
 		
     
function CloseInfo() {
	document.getElementById("info").style.display='none';
}	


function shDiv2 (uri,div) {
	//alert (div);
	isDOM=document.getElementById; isMSIE=document.all && document.all.item; isNetscape4=document.layers; isOpera=window.opera; isOpera5=isOpera && isDOM; isMSIE5=isDOM && isMSIE; isMozilla=isNetscape6=isDOM && !isMSIE && !isOpera;
	if (isMozilla || (isOpera && !isMSIE5)) { offset=document.documentElement.scrollTop;tt=screen.height-250; }
	if (isMSIE5) { var offset=document.body.scrollTop;tt=document.body.clientHeight; }
	document.getElementById(div).style.height=150+'px';
	var z = document.getElementById(div).style.height;
	zz=(z.replace('px','')/2);
	var y = Math.floor(offset + ((tt)/2))-zz;
	var x = Math.floor((document.body.clientWidth-460)/2);
	var agt=navigator.userAgent.toLowerCase() ;
	var check = agt.search("msie 7.0") 
	if (check!=-1) { 	
		document.getElementById("info").style.position='fixed';
		document.getElementById("info").style.top=(screen.height/2)-260;
		document.getElementById("info").style.left=Math.floor((document.body.clientWidth-460)/2);
	
	}
	else {
		document.getElementById('info').style.top = y + 'px';
		document.getElementById('info').style.left = x + 'px';
	}
	document.getElementById(div).width='420px';
	document.getElementById(div).style.display='';
	
	var ajax = new Ajax();
	if (ajax.isValid){
		ajax.get(
			'http://'+ document.domain + uri+ '&pi='+Math.random(100000),
			function () {
				var response = ajax.response();
				if ( response && response.status == 200 )
					document.getElementById(div).innerHTML = response.text;
				else if ( response && response.status >= 500 )
					document.getElementById(div).innerHTML = '<'+'img'+' src="/forums/img/roter.gif" /' + '>';
				else
					document.getElementById(div).innerHTML = '<'+ 'center'+'>' +'<'+ 'img' + ' src="/forums/img/roter.gif"'+'/' +'>' + '<'+ '/' + 'center' + '>';
					
			}
		);
		return false;
	}
	else {
		return true;
	}
}

function checkvote() {
	document.getElementById('bid').disabled=false;
}

function checkvote2(id) {
	document.getElementById('bid_'+id).disabled=false;
}

function SubmitVote(value) {
	SubmitForm('fvote','/vote/vote.php','cc1') ;
return true;	
}
function SubmitVote_n(value) {
	SubmitForm('fvote','/vote/vote_n.php','cc1') ;
return true;	
}
function SubmitVote_n2(id) {
	SubmitForm('fvote_'+id,'/vote/vote_n.php','cc1_'+id) ;
return true;	
}


function go_url(url) {
	window.location.href=url;	
}
function Login() {
	document.getElementById('login-form').style.display = 'block';
	
}
function hideLogin() {
	document.getElementById('login-form').style.display = 'none';
}
function Discuss(id,uid) {
	var cid="comms_"+id;
	//alert(cid);
	var cm=document.getElementById(cid).innerHTML;
	if (uid) window.location="/forums/discuss.php?id="+ id +"&pi="+Math.random(100000);	
	else {
		if (cm!=0) window.location="/forums/goton.php?id="+ id;	
		else Login();
	}
	
}
function set_cookie(name,value) {
	var today = new Date();
	var zero_date = new Date(0,0,0);
	today.setTime(today.getTime() - zero_date.getTime());
	var cookie_expire_date = new Date(today.getTime() + (8 * 7 * 86400000)); 
	var cookieString = name + "=" +escape(value) +
        ";expires=" + cookie_expire_date.toUTCString()  +
        ";path=/";
    document.cookie = cookieString;
}
function LMovie(id,pr) {
   	var s1 = new SWFObject("/stuff/mediaplayer.swf","mediaplayer","360","240","7");
	s1.addParam("allowfullscreen","true");
	s1.addVariable("width","360");
	s1.addVariable("height","240");
	s1.addVariable("file","/video/src/"+pr+"/"+id+".flv");
	s1.write("c_"+id);
   }
function EroYes(url) {
	set_cookie('ero',1);
	go_url(url);	
}
function cit(nickname)
{
	var t;
	var nickname;
	isDOM=document.getElementById; isMSIE=document.all && document.all.item; isNetscape4=document.layers; isOpera=window.opera; isOpera5=isOpera && isDOM; isMSIE5=isDOM && isMSIE; isMozilla=isNetscape6=isDOM && !isMSIE && !isOpera;
	if (isMozilla || (isOpera && !isMSIE5)) { t=window.getSelection().toString(); }
	if (isMSIE5) { text_obj=document.selection.createRange(); t=text_obj.text; }
	if (nickname!='') { t = "[user]"+nickname+"[/user]\r\n"+t; }
	if (t!='')
	{
		var f=document.getElementById("topic");
		f.message.value+="\n[cit]"+t+"[/cit]\n";	
	}
	else { alert('Для использования функции цитирования следует выделить мышкой цитируемый текст');
	}
}
function citu(nickname,uid)
{
	var t;
	var nickname;
	isDOM=document.getElementById; isMSIE=document.all && document.all.item; isNetscape4=document.layers; isOpera=window.opera; isOpera5=isOpera && isDOM; isMSIE5=isDOM && isMSIE; isMozilla=isNetscape6=isDOM && !isMSIE && !isOpera;
	if (isMozilla || (isOpera && !isMSIE5)) { t=window.getSelection().toString(); }
	if (isMSIE5) { text_obj=document.selection.createRange(); t=text_obj.text; }
	if (nickname!='') { t = "[user]"+nickname+"[/user]\r\n"+t; }
	document.getElementById('touid').value = document.getElementById('touid').value + "_" + uid;
	if (t!='')
	{
		var f=document.getElementById("topic");
		f.message.value+="\n[cit]"+t+"[/cit]\n";	
	}
	else { alert('Для использования функции цитирования следует выделить мышкой цитируемый текст');
	}
}


function ShowSmiles() {
   		if (document.getElementById('dpsml').innerHTML=="") { 
   			SubmitLink('/forums/smls.html','dpsml');
   			collapse('dpsml');
   		}
   		else {
   			collapse('dpsml');
   		}
}
function ShowSmiles_pages() {
   		if (document.getElementById('dpsml').innerHTML=="") { 
   			SubmitLink('/forums/smls_p.html','dpsml');
   			collapse('dpsml');
   		}
   		else {
   			collapse('dpsml');
   		}
}

function AddSmile(text) {
	var textarea=opener.document.topic.message;
	text=" "+text;	
if(typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
{

	var caretPos = textarea.caretPos;
	caretPos.text = caretPos.checkAt(caretPost.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
	{
	if (textarea.isTextEdit){
			textarea.focus();
			var sel = document.selection;
			var rng = sel.createRange();
			rng.colapse;
			
			if ((sel.type == "Text" || sel.type == "None") && rng != null)
			{
				rng.text = text;
		
			}
		}else{
		
			textarea+=text;
		}
	}
}
function insm(text) {
var textarea=document.topic.message;
text=" "+text;	
	if(typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
{

	var caretPos = textarea.caretPos;
	caretPos.text = caretPos.checkAt(caretPost.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
	{
	if (textarea.isTextEdit){
			textarea.focus();
			var sel = document.selection;
			var rng = sel.createRange();
			rng.colapse;
			
			if ((sel.type == "Text" || sel.type == "None") && rng != null)
			{
				rng.text = text;
		
			}
		}else{
		
			textarea+=text;
		}
	}
}
function fontstyle(bbopen, bbclose) {
	var clientVer = parseInt(navigator.appVersion); // Get browser version
	var clientPC = navigator.userAgent.toLowerCase();
	var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
	var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
	var is_moz = 0;

	var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));

	var txtarea = document.topic.message;

	txtarea.focus();
	var theSelection = false;

	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = bbopen + theSelection + bbclose;
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, bbopen, bbclose);
		return;
	}
	
	storeCaret(txtarea);
}
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2) 
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}
	function inp_href() {
	var url = prompt("Вставить URL ссылки", "");
	var text = prompt("Вставить текст ссылки", "");
	var f=document.getElementById("topic");
	if(!text) text=url;
	if (url) {
		f.message.value+=" [a url="+url+"]"+text+"[/a] ";
		return true;
	}
	else return false;
}

function timedMsg()
{
	if (document.getElementById('authres').innerHTML) window.location.href=document.getElementById('authres').innerHTML; 
}

function Auth() {
	var au=document.forms['authf'];
	var ms="";
		if (au.email.value=="") ms+="Введите логин\n";
		if (au.password.value=="") ms+="Введите пароль\n";
		if(ms)
 		{
   			alert('Ошибка при заполнении формы:\n'+ms);return false;
 		} 
		else {
			//document.getElementById('idrefr').style.display='';
			SubmitForm('authf','/myuw/_uid.php','lgf2');
			setTimeout("timedMsg()",800);
		}
}
function EmCheck() {
	var f=document.authf;
	if (f.urwb.checked) urwb=1;
	else urwb=0;
	url='/myuw/_chkm.php?login='+f.email.value+'&urwb='+urwb;
	SubmitLink(url,'eml');
}
function NickCheck() {
	var f=document.authf;
	url='/myuw/_chkn.php?nick='+encodeURI(f.nickname.value);
	SubmitLink(url,'nck');
}

function CodeCheck() {
	var f=document.authf;
	url='/myuw/_code.php?c='+f.code.value;
	SubmitLink(url,'code');
}

function RezervCheck() {
	var f=document.authf;
	url='/myuw/_rezerv.php?login='+f.rezerv.value;
	SubmitLink(url,'rezrv');
}

function PhoneCheck() {
	var f=document.authf;
	url='/myuw/_phone.php?c='+decodeURI(f.phone.value);
	SubmitLink(url,'phon');
}



function Register() {
	var log=document.getElementById('eml').innerHTML;
	var nick=document.getElementById('nck').innerHTML;
	var cod=document.getElementById('code').innerHTML;
	var rzv=document.getElementById('rezrv').innerHTML;
	var phon=document.getElementById('phon').innerHTML;
	
	var f=document.authf;
	var login=f.email.value;
	var nickname=f.nickname.value;
	var code=f.code.value;
	var password=f.password.value;
	var rezerv=f.rezerv.value;
	
	
	
	if (f.urwb.checked) login+="@uralweb.ru";
	var ms="";
	if (log==-1)  ms+="Некорректный email: "+login+"\n";
	if (log==-2 || login=="")  ms+="Пустой логин, выберите логин\n";
	if (log==-3)  ms+="E-mail "+ login +" уже занят, выберите другой\n";
	if (log==-4)  ms+="Имя ящика должно быть не короче 5 и не длинее 32 символов;\nсодержать в себе только латинские буквы, цифры, знак подчёркивания _ , дефис - или .\n начинаться и заканчиваться только буквой или цифрой\n";
	if (log==-5)  ms+="Несуществующий электронный адрес: " + login + "\n";	
	
	if (nick==-2 || nickname=='')  ms+="Пустой никнейм\n";
	if (nick==-3)  ms+="Никнейм "+ nickname +" уже занят, выберите другой\n";
	if (password=="")  ms+="Пустой пароль\n";
	
	if (code=='')  ms+="Пустое поле цифровой код\n";
	if (cod==-1)  ms+="Введены не все цифры и буквы цифрового кода\n";
	if (cod==-2)  ms+="Неверный цифровой код. Вводите пожалуйста, только английские буквы или цифры\n";
	if (f.urwb.checked || log==2 ) {
		if ((f.rezerv.value=="" && f.phone.value=="+7"))
		ms+="Логином выбран e-mail на нашем портале. Ввведите, пожалуйста, резервный e-mail или Ваш номер сотового телефона для восстановления пароля\n";
		if (f.rezerv.value) {
			if (rzv==-4 || rzv==-1)  ms+="Некорректный резервный email\n";
			if (rzv==-2)  ms+="Пустой резервный email\n";
			if (rzv==-5)  ms+="Несуществующий резервный email\n";
			if (rzv==-6)  ms+="Резервный e-mail не может быть адресом @uralweb.ru\n";	
		}
		if (f.phone.value) {
			if (f.phone.value!="+7") {
				if (phon==-1)  ms+="Неправильный телефонный номер. Номер в формате «+7xxxxxxxxxx»\n";		
			}
		}
	}
	
	
	
	
	if (ms) {
		alert (ms);
		return false;
	}
	else {
		document.authf.submit();
		return true;
	}
}

$(document).ready(function(){
	
	$(document).keydown(function(e){	
			if((e.ctrlKey) && (e.keyCode==37 || e.keyCode==39)) {
				var l; 
				var href;
				
				if (e.keyCode==37) { //предыдущая
					var span= $(".ctrllarr");
					l = span.length;
					href=span.attr('title');
				}
				if (e.keyCode==39) { //следующая
					var span= $(".ctrlrarr");
					l = span.length;
					href=span.attr('title');
				}
				
				if (l) {//существует
					window.location.href=href; 
				}			
			}
			if(e.ctrlKey && e.keyCode==13) {
				var d=e.target.nodeName;
				/*с*/
				//alert(d);
			}
			
			
		});
	

	
	
	
	$(".vaggp").hover(function() {
    	$(this).addClass("vaggg");
			}, function() {
    	$(this).removeClass("vaggg");		
		}); 

	$(".vagpg").hover(function() {
    	$(this).addClass("vaggg");
			}, function() {
    	$(this).removeClass("vaggg");		
	}); 	
	//red
	$(".vammp").hover(function() {
    	$(this).addClass("vammg");
			}, function() {
    	$(this).removeClass("vammg");		
	}); 

	$(".vampg").hover(function() {
    	$(this).addClass("vammg");
			}, function() {
    	$(this).removeClass("vammg");		
	}); 
	
	$(".vaggp").click(function(){
    	var id=$(this).parent().attr("id");			
		var val=$("#"+ id + " .vaggp").html();
    	val++;
    	
    	$("#"+ id + " .vaggp").text(val);
    	$("#"+ id + " .vaggp").addClass("vaggg");
    	$("#"+ id + " .vaggp").addClass("vgr");
    	$("#"+ id + " .vaggp").removeClass("vaggp");
    	var nxt=$(this).next().attr("class");
    	if (nxt=="vampg") {
    		$("#"+ id + " .vampg").addClass("vmrr");
    		$("#"+ id + " .vampg").removeClass("vampg");
    	}
    	else {
    		$("#"+ id + " .vammp").addClass("vmrf");
    		$("#"+ id + " .vammp").removeClass("vammp");
    	}
    	var cls=$(this).attr("class");
		if (cls=="vaggg vgr") {
			$.get("/vote/_handler.php",{ q: id,v:1 , pi:Math.random(100000)},function(data){
    		$("#vr_"+ id).html(data);
    	});
			//$("#vr_"+ id).load("/vote/_handler.php?q="+id+"&v=1&pi=" + Math.random(100000));
		}
		
	});
	$(".vagpg").click(function(){
    	var id=$(this).parent().attr("id");			
		var val=$("#"+ id + " .vagpg").html();
    	val++;
    	
    	var nxt=$(this).next().attr("class");
    	$("#"+ id + " .vagpg").text(val);
    	$("#"+ id + " .vagpg").addClass("vaggg");
    	$("#"+ id + " .vagpg").addClass("vgr");
    	$("#"+ id + " .vagpg").removeClass("vagpg");
    	if (nxt=="vampg") {
    		$("#"+ id + " .vampg").addClass("vmrr");
    		$("#"+ id + " .vampg").removeClass("vampg");
    	}
    	else {
    		$("#"+ id + " .vammp").addClass("vmrf");
    		$("#"+ id + " .vammp").removeClass("vammp");
    	}
		var cls=$(this).attr("class");
		
    	if (cls=="vaggg vgr") {

    	$.get("/vote/_handler.php",{ q: id,v:1 , pi:Math.random(100000)},function(data){
    		$("#vr_"+ id).html(data);
    	});
    	}
    	//$("#vr_"+ id).load("/vote/_handler.php?q="+id+"&v=1&pi=" + Math.random(100000));
	});
	
	
	$(".vammp").click(function(){
    	var id=$(this).parent().attr("id");			
		var val=$("#"+ id + " .vammp").html();
    	val++;
    	
    	$("#"+ id + " .vammp").text(val);
    	$("#"+ id + " .vammp").addClass("vammg");
    	$("#"+ id + " .vammp").addClass("vmr");
    	$("#"+ id + " .vammp").removeClass("vammp");
    	var prev=$(this).prev().attr("class");
    	
    	if (prev=="vagpg") {
    		$("#"+ id + " .vagpg").addClass("vgr");
    		$("#"+ id + " .vagpg").removeClass("vagpg");
    	}
    	else {
    		$("#"+ id + " .vaggp").addClass("vgrf");
    		$("#"+ id + " .vaggp").removeClass("vaggp");
    	}
		var cls=$(this).attr("class");
		
		
		if (cls=="vammg vmr") {
			$.get("/vote/_handler.php",{ q: id,v:-1 , pi:Math.random(100000)},function(data){
    		$("#vr_"+ id).html(data);
    		});
			
		}
	
	});
	$(".vagpg").click(function(){
    	var id=$(this).parent().attr("id");			
		var val=$("#"+ id + " .vagpg").html();
    	val++;
    	
    	var prev=$(this).prev().attr("class");
    	$("#"+ id + " .vagpg").text(val);
    	$("#"+ id + " .vagpg").addClass("vaggg");
    	$("#"+ id + " .vagpg").addClass("vgr");
    	$("#"+ id + " .vagpg").removeClass("vagpg");
    	
    	if (prev=="vagpg") {
    		$("#"+ id + " .vagpg").addClass("vgr");
    		$("#"+ id + " .vagpg").removeClass("vagpg");
    	}
    	else {
    		$("#"+ id + " .vaggp").addClass("vgrf");
    		$("#"+ id + " .vaggp").removeClass("vaggp");
    	}	
    	var cls=$(this).attr("class");
    	//alert(cls);
    	//alert(id +"\n*" + cls+"*");
		if (cls=="vammg vmr") {
			$.get("/vote/_handler.php",{ q: id,v:-1 , pi:Math.random(100000)},function(data){
    		$("#vr_"+ id).html(data);
    	});
		}
		
		//$("#vr_"+ id).load("/vote/_handler.php?q=" + id +"&v=-1&pi=" + Math.random(100000));
	});
	var sect=0;
	var id=0;
	sect=$(this).find(".watch").children().attr("class");	
	id=$(this).find(".watch").children().attr("id");		
	if (sect && id) {
		//$(".watch #"+id).load('/vote/watch.php?s='+ sect + '&id='+id+'&pi='+ Math.random(100000));
		$(".watch #"+id).load('/watch/sect='+ sect + '&id='+id+'&pi='+ Math.random(100000));
		
		
	}
	//новости, календарь
	$(".agenda .agnd_ab").hover(function() {
    	$(this).css({"cursor":"pointer"});
			}, function() {
    	$(this).css({"cursor":"normal"});	
	}); 
	$(".agenda .agnd_wb").hover(function() {
    	$(this).css({"cursor":"pointer"});
			}, function() {
    	$(this).css({"cursor":"normal"});	
	}); 
	
	
	$(".agenda .agnd_wb").click(function(){
		window.location=$(this).find("a").attr("href");return false;
	});
	$(".agenda .agnd_ab").click(function(){
		window.location=$(this).find("a").attr("href");return false;
	});

	
	$(".nmail").click(function(){
	   
		var id=$(this).attr("id");
		$.blockUI({ 
            message: $("#pmail").load("/pmail/form.php?u=" + id +"&pi=" + Math.random(100000)),
            css: { 
                top:  ($(window).height() - 500) /2 + 'px', 
                left: ($(window).width() - 460) /2 + 'px', 
                width: '460px',
                border: 'none', 
            	padding: '5px',
            	cursor: 'default'
		}});
	
	});
	$(".nmail2").click(function(){
	   
		var id=$(this).attr("id");
		$.blockUI({ 
            message: $("#pmail").load("/pmail/form.php?u=" + id +"&pi=" + Math.random(100000)),
            css: { 
                top:  ($(window).height() - 500) /2 + 'px', 
                left: ($(window).width() - 460) /2 + 'px', 
                width: '460px',
                border: 'none', 
            	padding: '5px',
            	cursor: 'default'
		}});
	
	});
	
	
	$('.pm_close').live("click",function(){
			$.unblockUI(); 
            return false; 
	}); 
	
	$('#pm_send').live("click",function(){
			SendPm();
            return false; 
	}); 
	
	$('#pmsend #txt_pm_send').live("keypress", function(e){
			
		if((e.ctrlKey) && ((e.keyCode == 0xA)||(e.keyCode == 0xD))) {
			SendPm();
			return false; 
		}
	});
	/*отправка личного сообщения*/
	function SendPm() {
		var auid=$("#auid").val();
		var msg=$("#txt_pm_send").val();
		var subj=$("#pm_subj").val();
		
		
		$.post("/pmail/smail.php",{ auid: auid, msg: msg, subj: subj}, function(data){
			$("#pmsend").html(data);
			
		});
		setTimeout($.unblockUI, 600);
	}
	
	$("#new_mail").click(function(){
		window.location.href='/forums/inbox.php';	
	});
	
	$("#no_mail").click(function(){
		window.location.href='/forums/inbox.php';	
	});
	/*вход в почту uralweb.ru*/
	$("#gotouwmail").click(function(){
		$("#mailf").submit();
	});
	
	/*новая шапка*/
	   initSubmenu();
        $('.head-down ul .main-li').not('.active, .ehe').mouseover(function() {
           $(this).addClass('activeh');
            $(this).children('a').css({'text-decoration': 'underline'});
          });
        $('.head-down ul .main-li').not('.active, .ehe').mouseout(function() {
            $(this).removeClass('activeh');
            $(this).children('a').css({'text-decoration': 'none'});
        });
        $('.head-down ul li.first.main-li').not('.active, .ehe').mouseover(function() {
           $(this).addClass('activeh');
            $(this).children('a').css({'text-decoration': 'underline'});
          });
        $('.head-down ul li.first.main-li').not('.active, .ehe').mouseout(function() {
            $(this).removeClass('activeh');
            $(this).children('a').css({'text-decoration': 'none'});
        });

        $('.head-down ul .ehe').not('.active').mouseover(function() {
        	$(this).addClass('activeh2');
            $(this).children('a').css({'text-decoration': 'underline'});
          });
        $('.head-down ul .ehe').not('.active').mouseout(function() {
            $(this).removeClass('activeh2');
            $(this).children('a').css({'text-decoration': 'none'});
        });
	
     function NLogin() {
		$('#mod_cnt').load('/inc/myuw/auth_form.html');
		var width=$("#modal").css('width').replace("px", "");
		$('#cap_header').html('Вход на сайт');
		$.blockUI({ 
			message:  $("#modal"), 
            showOverlay: true, 
            css: { 
                width: width+'px', 
                top:  ($(window).height() - 300) /2 + 'px', 
                left: ($(window).width() - width) /2 + 'px', 
                border: '0px', 
               
                backgroundColor: '#fff',
                cursor: 'normal', 
                opacity: 1, 
                color: '#000' 
            } 
        }); 
	}
        
	
	$(".weather").click(function(){
		window.location.href="http://www.uralweb.ru/weather/";
		
	});
	
	//news_comm news_discuss
	
	
	
	$(".gr-com").click(function(){
		
		var iid=$(this).attr('id');
		var id=iid.split('_')
		var uid=$("#news_uid").html();
		var	cnt=$(this).html();//число комментов
		if (cnt==0) {
			if (uid==0) {
				NLogin();
			}
			else window.location="/forums/discuss.php?id="+ id[1] +"&pi="+Math.random(100000);
			
		}
		else {
			window.location="/forums/goton.php?id="+ id[1];	
		}
		
		/*if (uid) window.location="/forums/discuss.php?id="+ id +"&pi="+Math.random(100000);	
	else {
		if (cm!=0) 
		else Login();*/
	//}
		
		
	});
	
	$("#wrpr").keydown(function(e){	
		
		if(e.ctrlKey &&  e.keyCode==13) {
			
			var lyr=e.target.nodeName;
			var c=$("#wrpr");
			var s;
			if (typeof document.selection != 'undefined')  {                        
				s = document.selection.createRange().text;
			}
            else {
            	s = window.getSelection().getRangeAt(0);
            }
            if (s && lyr=="DIV") {
				if (confirm("«"+s+"»\nВы считаете, что в выделенном фрагменте есть орфографическая ошибка?")) {
					$.ajax({
   					type: "POST",
   					url: "/news/typo.php",
   					data: "msg="+s,
   					success: function(msg){
     					alert(msg);
   					}
 					});
					
					
					
				}
            }
			
 		}
	});
	
	
	
}); //close doc ready
