	var LinkDrag;
	function SendLink(obj,jokelink,mp3link,show){
		var mp3_link = $('mp3_link');
		var joke_link = $('joke_link');
		if(show==0){
			if(mp3_link) mp3_link.value='';	
			if(joke_link) joke_link.value='';
			pop('sendlink',0,0,0);
		}else{
			var mp3_show = $('mp3_show');
			if(mp3_show){
				if(mp3link!='') mp3_show.style.display = 'block';
				else mp3_show.style.display = 'none';
			}
			var pos = GetPos(obj);
			pop('sendlink',pos[0],pos[1],0);
			if(mp3_link) mp3_link.value=mp3link;	
			if(joke_link){
				joke_link.value=jokelink;	
				//joke_link.focus();
				joke_link.select();				
			}
			
		}
		var LinkDrag = new Draggable('sendlink',{handle:'pophead_link'});
	}
	
	
	function login(obj){
		var dim = $('wrapper');
		if(dim){
			dim = dim.clientWidth;
			var pos = GetPos(obj);
			pop('wrapper',pos[0]-dim-50,pos[1],1);
		}
	}

	function GetPos(obj){
		return Position.cumulativeOffset(obj);
	}
	
	var block = '';
	
	function ShowInfo (id){
		var id = $(id);
		if(id) id.style.visibility="visible";
	}
	
	function HideInfo(id){
		var id = $(id);
		if(id) id.style.visibility="hidden";
	}
	
	function ShowBlock(obj){
		var obj = $(obj);
		if(obj.style.display=="block"){
			obj.style.display="none";
		}else
			obj.style.display="block";
	}
	
	function ShowForm(obj){
		var pos = GetPos(obj);
		pop(block+'_form',pos[0],pos[1],0,620);
	}
	
	function HideForm(){
		pop(block+'_form',0,0,0);
	}	
	
	function SendComment(obj){
		
		var form = $('commentForm');
		if(!form) return;

		for(var i=0; i<form.elements.length, node = form.elements[i];i++){
			if(node.getAttribute('required')=='required'){
				if(node.value=="" || (node.getAttribute('type')=='select' && node.selectedIndex==0)){
					alert('Поле обязательно для заполнения!');
					node.focus();
					return;
				}
			}
		}
		
		var param = 'name=Comments&method=Add&ajax=yes&obj='+obj+'&ajax=yes';
		param = param+'&'+Form.serialize(form);
		var url = location.protocol+'//'+document.domain;

		var AjaxForm = new Ajax.Request(url,{
				method:'post',
				parameters: param,
				onComplete: _sendComment
		});
		HideForm();
		return;	
	
	}
	function _sendComment(res){
		var obj = res.responseText;
		if(obj){
			var obj_link = $('link_'+obj);
			if(obj_link) obj_link.focus();
			ShowComments(obj);
		}	
	}	

	function DeleteComment(url){
		var param='ajax=yes&name=Comments&method=Delete';
		var AjaxForm = new Ajax.Request(url,{
				method:'post',
				parameters: param,
				onComplete: _deleteComment
		})
	}
	function _deleteComment(req){
		var id = req.responseText;
		if(id>0){
			var comment = $('comment_'+id);
			comment.parentNode.removeChild(comment);
		}
	}	
	
	var comment = 0;
	function ShowComments(id){
		var param = 'name=Comments&method=Get&obj='+id+'&ajax=yes';
		var comment_block = $('comment_'+comment);
		if(comment_block)
			comment_block.innerHTML = "";
		var ptext = $('comment_preloader').innerHTML;
		var cont = $('comment_'+id);
		if(cont) cont.innerHTML = ptext;
		comment = id;
		var url = location.protocol+'//'+document.domain;

		var AjaxForm = new Ajax.Request(url,{
			method:'post',
			parameters: param,
			onComplete: _showComments
		});
	}
	
	function _showComments(res){
		var text = res.responseText;
		if(text){
			var cont = $('comment_'+comment);
			cont.innerHTML = text;
		}
	}		
	
	function SendItem(cat){
		var author = $('post_author');
		var text = $('post_text');
		
		var topic = $('post_topic');
		var mp3	= $('mp3');
		var tags = $('tags_field');
		
		if(!author.value){
			alert('Поле "Имя" является обязательным для заполнения!');
			author.focus();
			return;
		}

		if(text && text.value==''){
			alert('Поле "Текст" является обязательным для заполнения!');
			text.focus();
			return;
		}
		if (cat == 13 || cat == 19){
			if (text.value.length > 6000) {
				alert('Длина текста превышает 6000 сиволов.');
				return;
			}
		} else {
			if (text.value.length > 15000) {
				alert('Длина текста превышает 15000 сиволов.');
				return;
			}
		}
		
		if(topic && !topic.value){
			alert('Поле "Тема" является обязательным для заполнения!');
			topic.focus();
			return;
		}		
		
		var form = document.forms['post_form'];

		var param = 'name=Media&method=AddPost&cat='+cat+'&ajax=yes';
		param = param+'&'+Form.serialize(form);
		var url = location.protocol+'//'+document.domain;

		var AjaxForm = new Ajax.Request(url,{
				method:'post',
				parameters: param,
				onComplete: _sendItem
		});
		HideForm();
//		form.reset();
		return;
	}

	function _sendItem(originalRequest){
		var xml = originalRequest.responseXML;
		var child = xml.firstChild;
		if (!child) return;
		if (child.getAttribute('position') == 'none'){
			alert('Такое сообщение уже усть в базе данных!');
		}else{
			var r = document.getElementsByClassName('refresher',$('c31'));
			for(var i=0;i<r.length;i++){
				if(r[i].style.display=='block'){
					GetNews(r[i],r[i].getAttribute('cat'),r[i].getAttribute('href'),true);
					break;
				}
			}
		}	

	}
	
	function Vote(id,vote){
		var param = 'name=Media&method=Vote&ajax=yes';
		param = param+'&'+'vote='+vote+'&'+'id='+id;

		$('mark_'+id).style.display = "none";
		var url = location.protocol+'//'+document.domain;

		var AjaxForm = new Ajax.Request(url,{
			method:'post',
			parameters: param,
			onComplete: showVoteResponse
		});
		return;
	}
	
	function showVoteResponse(originalRequest){
		var text = originalRequest.responseText;
		if(text){
		
			var arg = text.split("|");
			$('vote_'+arg[0]).innerHTML=arg[1];
			
			$('vote_ok_'+arg[0]).style.display = "block";
		}
	}
	
	function Delete(url){
		var param='ajax=yes&name=Media&method=Delete';
		var AjaxForm = new Ajax.Request(url,{
				method:'post',
				parameters: param,
				onComplete: _delete
		})
	}
	function _delete(req){
		var id = req.responseText;
		if(id>0){
			var block = $('block_'+id);
			block.parentNode.removeChild(block);
		}
	}
	
	
	function PhraseVote(id,vote){
		var param = 'name=Media&method=VotePhrase&cat=13&ajax=yes';
		param = param+'&'+'vote='+vote+'&'+'id='+id;
		$('phrase_mark_'+id).style.display = "none";
		if(!readCookie('phrase['+id+']')){
			createCookie('phrase['+id+']',1,1);
			var AjaxForm = new Ajax.Request(location.href,{
				method:'post',
				parameters: param,
				onComplete: showVotePhrase
			});
			return;
		}
	}
	
	function showVotePhrase(originalRequest){
		var text = originalRequest.responseText;
		if(text){
			var arg = text.split("|");
			$('phrase_vote_'+arg[0]).innerHTML=arg[1];
			$('phrase_vote_ok_'+arg[0]).style.display = "block";
		}
	}	
	
	function ShowPopup(wx,wy,url){
		wx=wx+40;
		win=window.open('','popup','width='+wx+',height='+wy+',left=100,top=0,location=no,menubar=no,resizable=no,scrollbars=yes');
		doc=win.document;
		doc.writeln('<html><head><link rel="shortcut icon" href="favicon.ico" /><meta http-equiv="content-type" content="text/html; charset=utf-8" /><meta name="author" content="дизайн-студия Идея" /><meta http-equiv="Reply-to" content="support@idea.net.ua" /><title>ЮморFM</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link rel="stylesheet" type="text/css" media="screen" href="css/s.css" /></head><body><form action="'+url+'" method="post" enctype="multipart/form-data"><table cellpadding="10" cellspacing="0" border="0"><tr valign="top"><td>Звуковой файл:</td><td><input type="file" class="form100" id="joke_mp3" name="fields[mp3]" /><br />Вы можете загрузить голосовую версию Вашего анекдота в формате mp3. Размер файла не должен превышать 4 Mb. (<a href="#">Чем я могу записать файл!</a>)</td></tr><tr><td colspan="2" align="right"><input type="submit" value="Загрузить" /></td></tr></table></form></body></html>');
		doc.close();
	}
	


	
	function EmailJoke(id){
		win3=window.open('http://'+document.domain+'/sendjoke/j.'+id+'/','popup2','width=600,height=400,left=100,top=0,location=no,menubar=no,resizable=no,scrollbars=yes');
	}
	
	
	function TagsList(id_obj,visible){
		var tags = $('BlockTags');
		if(visible==1){
			var obj = $(id_obj);
			var pos = GetPos(obj);
			var div = Element.getDimensions(obj);

			tags.style.position = 'absolute';
			tags.style.zIndex = 500;
			tags.style.left=pos[0]+div.width-80+'px';
			tags.style.top = pos[1]+10+'px';
			tags.style.display="block";
		}else{
			if (tags) tags.style.display="none";
		}
	}
	
	function InsertTag(tag){
		var field = $('tags_field');
		if(field.value)
			field.value = field.value+', '+tag.innerHTML;
		else
			field.value = tag.innerHTML;
	}
	
	function CountSymbols(obj,c){
		var cont = $('count_symbols');
		cont.innerHTML = c - obj.value.length;
	}
	
// *******************************************************************************//
//					Код для всплывающих плашек					  //
//*******************************************************************************//

	function IsOpera(){
		return (navigator.userAgent.toLowerCase().indexOf('opera') != -1);
	}

	function IsIE(){
		return (document.attachEvent && !IsOpera());
	}
	
	var current_block = '';

	var x;
	var y;
	var z;
	
	var vsrc='';
	var vshow = false;
	var vdimmer = 0;
	var drag='';
	function pop(src,ofx,ofy,dimmer,w) {
		if(ofx==undefined) ofx=0;
		if(ofy==undefined) ofy=0;
		if(dimmer==undefined) dimmer=0; vdimmer=dimmer;
		if(w==undefined) w=0;
		
		if(vsrc!=src && vshow==true){
			pop(vsrc,0,0,0);
		}
		vsrc = src;
		
		x = $('dimmer');
		
		y = $(src);
		
		var frame = $('frame');
		
		if(dimmer==1){
			var pos = getPageSize();
			var scroll = getPageScroll();
			x.style.height = pos[1]+'px';
			x.style.width = pos[0]+scroll[0]+'px';
			if (x && x.className!='hide') {x.className = 'hide';} else {x.className = 'show';}
		}
		
		if(y && !vshow){
			vshow = true;
			
			y.style.visibility = "visible";
			
			if(w>0) y.style.width=w+"px";
			else y.style.width="";

			if(IsOpera && frame){
				frame.style.display="block";
			}
			
			y.style.left = ofx-12+'px'
			y.style.top = ofy-5+'px';

			y.style.zIndex = 200;

			if(IsIE()){
				var selects = document.getElementsByTagName('select');
				for(i=0;i<selects.length;i++)
					selects[i].style.visibility = 'hidden';
				var selects = y.getElementsByTagName('select');
				for(i=0;i<selects.length;i++){
					selects[i].style.visibility = 'visible';
					selects[i].style.visibility = 'visible';
					selects[i].style.display = 'block';
				}
			}
			drag = new Draggable(src,{handle:src+'_calendar'});
			
		}else{
			TagsList('',0);
			vshow = false;
			vsrc = '';
			if(IsOpera && frame){
				frame.style.display="none";
			}			
			y.style.visibility = "hidden";

			if(IsIE()){
				var selects = y.getElementsByTagName('select');
				for(i=0;i<selects.length;i++)
					selects[i].style.display = 'none';
					
				var selects = document.getElementsByTagName('select');
				for(i=0;i<selects.length;i++)
					selects[i].style.visibility = 'visible';
			}
		}

		if(vshow){
			var input = y.getElementsByTagName('input');
			for(var j=0;j<input.length;j++){
				if(input[j].getAttribute('type')=='text'){
					input[j].focus();
					break;
				}
			}	
		}else{
			y.blur();
		}
		
		return false;
	}

	function getPageSize() {
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ 
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
		if(xScroll < windowWidth){
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	}


	function getPageScroll() {
		var yScroll;
		var xScroll;

		if (self.pageYOffset)
			yScroll = self.pageYOffset;
		else if (document.documentElement && document.documentElement.scrollTop)
			yScroll = document.documentElement.scrollTop;
		else if (document.body)
			yScroll = document.body.scrollTop;
		
		if (self.pageXOffset)
			xScroll = self.pageXOffset;
		else if (document.documentElement && document.documentElement.scrollLeft)
			xScroll = document.documentElement.scrollLeft;
		else if (document.body)
			xScroll = document.body.scrollLeft;
		
		arrayPageScroll = new Array(xScroll,yScroll) 
		return arrayPageScroll;
	}	
	
	function getPageCenter(obj){
		if(obj!=undefined){
			var obj = $(obj);
			if(obj)
			var dim = Element.getDimensions(obj);
		}
		var pos = getPageSize();
		var x2 = Math.round(pos[0]/2);
		var y2 = Math.round(pos[1]/2);
		if(dim.width!=undefined) x2 -= Math.round(dim.width/2);
		return [x2,y2];
	}


	function register(e) {	
		var code;
		if (!e) e = window.event;
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
		if (code == 27){
			if(vsrc!='alert_msg')
			if(vsrc!='' && vshow==true){
				pop(vsrc,0,0,vdimmer);
			}
		}

        if ((code == 37) && (e.ctrlKey == true)) {
            var destination = document.getElementById('prev_page');
            if (destination) location.href = destination.href;
        }
        if ((code == 39) && (e.ctrlKey == true)) {
            var destination = document.getElementById('next_page');
            if (destination) location.href = destination.href;
        }
		
        if ((code == 38) && (e.ctrlKey == true)) {
            var destination = document.getElementById('top_page');
            if (destination) location.href = destination.href;
        }
		
	}	
	document.onkeydown = function(e){
		register(e);
	}
/*
	function GetMediaCount(id){
		var node = window.document.getElementById(id);
		param = '';
		var vAjax = new Ajax.Request(location.protocol+'//'+document.domain,{
				method:'post',
				parameters: param,
				onComplete: InsertMediaCount
		});		
	}
*/

	
	