DOM=document.getElementById;
Netscape4=document.layer;
Netscape6=Mozilla=(navigator.appName=="Netscape")&&DOM;
Netscape7=navigator.userAgent.indexOf("Netscape/7")>=0;
Opera5=window.opera&&DOM;
Opera6=Opera5&&window.print;
Opera7=Opera5&&navigator.userAgent.indexOf("Opera 7")>=0;
IE=document.all&&!Opera5;
Firefox=navigator.userAgent.indexOf("Firefox")>=0;
isDOM=document.getElementById;
isOpera=isOpera5=window.opera&&isDOM;
isOpera6=isOpera&&window.print;
isOpera7=isOpera&&document.readyState;
isMSIE=document.all&&document.all.item&&!isOpera;
isMSIE5=isDOM&&isMSIE;
isNetscape4=document.layers;
isMozilla=isDOM&&navigator.appName=='Netscape';

function getElementsByClass(searchClass,node,tag){
var classElements=new Array();
if(node==null) node=document;
if(tag==null) tag='*';
var els=node.getElementsByTagName(tag);
var elsLen=els.length;
var pattern=new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
for(i=0,j=0;i<elsLen;i++){if(pattern.test(els[i].className)){classElements[j]=els[i];j++;}}
return classElements;
}
function show_comment_form(id,parent,mode){
var body=document.body;
var screen_width=0;
if(document.documentElement.clientWidth){screen_width=document.documentElement.clientWidth-4;}
else{screen_width=document.body.offsetWidth-20;}
var screen_height=0;
if(document.documentElement.clientHeight){screen_height=document.documentElement.clientHeight+4;}
else{var sizes=getPageSizeWithScroll();screen_height=sizes[1];}
var body_height=body.offsetHeight;
var scroll=body.scrollTop?body.scrollTop:document.documentElement.scrollTop;
var div=document.createElement('div');
div.id='bglayer';
div.style.position='absolute';
div.style.border='none';
div.style.backgroundColor='rgb(33,33,33)';
div.style.top='0px';
div.style.left='0px';
div.style.width=body.offsetWidth+'px';
div.style.height=body_height+'px';
div.style.opacity='0.8';
div.style.filter='progid:DXImageTransform.Microsoft.BasicImage(opacity=0.8)';
div.style.zIndex='998';
body.appendChild(div);
var layer=document.getElementById('comment');
if(layer){
document.comment_form.f_Object_ID.value=id;
document.comment_form.f_Parent_Message_ID.value=parent;
document.comment_form.mode.value=mode;
var width=layer.offsetWidth;
//var width = 680;
var height=layer.offsetHeight;
//layer.style.display='block;';
if(width<screen_width){var offset=(screen_width-width)/2;layer.style.left=offset+'px';}
if(height<screen_height){var offset=(screen_height-height)/2;layer.style.top=(scroll+offset)+'px';}
layer.style.visibility='visible'; layer.style.zIndex='999';
}
}

function TrimString(sInString){return sInString.replace(/(^\s+)|(\s+$)/g,"");}
function createRequestObject(){
var request=null;
try{request=new ActiveXObject('Msxml2.XMLHTTP');}
catch(e){}
if(!request)try{request=new ActiveXObject('Microsoft.XMLHTTP');}
catch(e){}
if(!request)try{request=new XMLHttpRequest();}
catch(e){}
return request;}
var request=createRequestObject();
function getPageSizeWithScroll(){
if(window.innerHeight&&window.scrollMaxY){yWithScroll=window.innerHeight+window.scrollMaxY;xWithScroll=window.innerWidth+window.scrollMaxX;}
else if(document.body.scrollHeight>document.body.offsetHeight){yWithScroll=document.body.scrollHeight;xWithScroll=document.body.scrollWidth;}
else{yWithScroll=document.body.offsetHeight;xWithScroll=document.body.offsetWidth;}
arrayPageSizeWithScroll=new Array(xWithScroll,yWithScroll);
return arrayPageSizeWithScroll;
}

function getBounds(element){
var left=element.offsetLeft;
var top=element.offsetTop;
for(var parent=element.offsetParent;parent;parent=parent.offsetParent){
left+=parent.offsetLeft-parent.scrollLeft;
top+=parent.offsetTop-parent.scrollTop
}
return{left:left,top:top,width:element.offsetWidth,height:element.offsetHeight};
}
function placeMark(){
var cooridantes=document.adminForm.Map_koor.value;
if(cooridantes.length<5){alert("Просьба выбрать на карте координаты места");return false;}
var name=document.adminForm.f_name.value;
if(name.length<3){alert("Укажите название водоема (мнимум 3 символа)");return false;}
var descr=document.adminForm.f_description.value;
if(descr.length<10){alert("Просьба заполнить особенности водоема");return false;}
return true;
}
function send_comment(root)
{
var width=400;
var offset=40;
var title="";
var file="";
if(root){
var id=document.root_comment_form.f_Object_ID.value;
var parent=document.root_comment_form.f_Parent_Message_ID.value;
var mode=document.root_comment_form.mode.value;
var text=document.root_comment_form.comment_text.value;
if(document.root_comment_form.comment_title){
title=document.root_comment_form.comment_title.value;
}
if(document.root_comment_form.f_Picture){
file=document.root_comment_form.f_Picture.value;
}
}else{
var id=document.comment_form.f_Object_ID.value;
var parent=document.comment_form.f_Parent_Message_ID.value;
var mode=document.comment_form.mode.value;
var text=document.comment_form.comment_text.value;
if(document.comment_form.comment_title){title=document.comment_form.comment_title.value;}
if(document.comment_form.f_Picture){file=document.comment_form.f_Picture.value;}
}
if(file==""){if((text.length<10&&title.length==0)||text.length>1000){alert('Длина комментария от 10 до 1000 символов. У Вас - '+text.length);return false;}
var r=Math.round(Math.random()*1000);
var url='/ajax/comment.php?mode='+mode+'&id='+id+'&parent='+parent+'&text='+encodeURIComponent(text)+'&title='+encodeURIComponent(title)+'&r='+r;
request.open('GET',url,false);
request.send('');
var result=request.responseText;
var params=result.split(':::');
var insertid=params[0];
var userid=params[1];
var login=params[2];
var name=params[3];
var surname=params[4];
var toname=params[5];
var day=params[6];
var month=params[7];
var year=params[8];
var hour=params[9];
var min=params[10];
var level=params[11];
var text=params[12];
var avatar=params[13];
var title="";
if(params[14]){title=params[14];}
if(result!=''){hide_form('comment');var nocom=document.getElementById('no_comments');
if(nocom){nocom.parentNode.removeChild(nocom);}
var div=document.createElement('div');
div.id=insertid;
div.className='com_block';
var edit_mode='';
var del_mode='';
if(mode=='addComment'){edit_mode='editComment';del_mode='deleteComment';}
if(mode=='addarticle'){edit_mode='editarticle';del_mode='deletearticle';}
else if(mode=='addnews'){edit_mode='editnews';del_mode='deletenews';}
else if(mode=='addblog'){edit_mode='editblog';del_mode='deleteblog';}
else if(mode=='addvideo'){edit_mode='editvideo';del_mode='deletevideo';}
var avatar_path='/images/no/no_credne.gif';
if(avatar!=""){avatar_path='/netcat_files/u/'+avatar;}
var totalname=login;
if(name!=""&&surname!=""){totalname=name+' '+surname;}
var html='<div class="com"><div class="ava"><img src="'+avatar_path+'" alt=""></div><div class="txt"><div class="member_time"><a href="/users/'+login+'.html">'+totalname+'</a>  (Опубликовано: '+day+' '+month+' '+year+' '+hour+':'+min+')</div>';
if(title!=""){html=html+'<div class="title"><h1>'+title+'</h1></div>';}
html=html+'<div class="text">'+text+'</div></div><div class="clear"></div><div class="bottom"><a href="#" onClick="show_comment_form(\''+id+'\', \''+insertid+'\', \''+mode+'\'); return false;">Ответить</a> <a href="#" class="edit" onClick="show_edit_form(\''+insertid+'\', \''+edit_mode+'\'); return false;">Редактировать</a> <a href="#" class="delete" onClick="delete_comment(\''+insertid+'\', \''+del_mode+'\'); return false;">Удалить</a></div></div><div class="com_line"></div></div>';
div.innerHTML=html;
div.style.paddingLeft=(level*offset)+'px';
var child_div=document.createElement('div');
child_div.id='childs'+insertid;
if(parent==0)
{
var comments=document.getElementById('childs0');
if(comments){comments.appendChild(div);comments.appendChild(child_div);}
}
else
{
var childs=document.getElementById('childs'+parent);
if(childs)
{
childs.appendChild(div);
childs.appendChild(child_div);
}
}
if(root){
document.root_comment_form.comment_text.value='';
if(document.root_comment_form.comment_title){
title=document.root_comment_form.comment_title.value='';
}
}else{
document.comment_form.comment_text.value='';
if(document.comment_form.comment_title){
title=document.comment_form.comment_title.value='';
}
}
}
return false;
}
else
{
if((text.length<10&&title.length==0)||text.length>1000){alert('Длина комментария от 10 до 1000 символов. У Вас - '+text.length);return false;}
}
return true;
}

function delete_comment(id,mode)
{
if(confirm('Подтвердите удаление комментария?'))
{
var r=Math.round(Math.random()*1000);
var url='/ajax/comment.php?mode='+mode+'&id='+id+'&r='+r;
request.open('GET',url,false);
request.send('');
var result=request.responseText;
if(result!=0)
{
var comment=document.getElementById(id);
var text=getElementsByClass("text",comment,"div");
if(text[0])
{
text=text[0];
text.innerHTML='<b>Комментарий удален</b>';
var title=getElementsByClass("title",comment,"div");
if(title[0]){title=title[0];title.innerHTML='';}
var edit=document.getElementById('edit'+id);
if(edit){edit.parentNode.removeChild(edit);}
var del=document.getElementById('delete'+id);
if(del){del.parentNode.removeChild(del);}
}
else{}
}}}

function show_edit_form(id,mode)
{
var body=document.body;
var screen_width=0;
if(document.documentElement.clientWidth){screen_width=document.documentElement.clientWidth-4;}
else{screen_width=document.body.offsetWidth-20;}
var screen_height=0;
if(document.documentElement.clientHeight){screen_height=document.documentElement.clientHeight+4;}
else{var sizes=getPageSizeWithScroll();screen_height=sizes[1];}
var body_height=body.offsetHeight;
var scroll=body.scrollTop?body.scrollTop:document.documentElement.scrollTop;
var div=document.createElement('div');
div.id='bglayer';
div.style.position='absolute';
div.style.border='none';
div.style.backgroundColor='rgb(33,33,33)';
div.style.top='0px';
div.style.left='0px';
div.style.width=body.offsetWidth+'px';
div.style.height=body_height+'px';
div.style.opacity='0.8';
div.style.filter='progid:DXImageTransform.Microsoft.BasicImage(opacity=0.8)';
div.style.zIndex='998';
body.appendChild(div);
var layer=document.getElementById('edit_comment');
if(layer)
{
var r=Math.round(Math.random()*1000);
var url='/ajax/comment.php?mode='+mode+'&id='+id+'&r='+r;
request.open('GET',url,false);
request.send('');
var result=request.responseText;
var save_mode='';
if(mode=='editComment'){save_mode='saveComment';}
if(mode=='editarticle'){save_mode='savearticle';}
else if(mode=='editnews'){save_mode='savenews';}
else if(mode=='editblog'){save_mode='saveblog';}
else if(mode=='editvideo'){save_mode='savevideo';}
if(result!=""&&result!=0)
{
var params=result.split(':::');
var text=params[0];
var title="";
if(params[1]){title=params[1];}
text=str_replace("<br/>","\n",text);
document.edit_form.f_Object_ID.value=id;
document.edit_form.mode.value=save_mode;
document.edit_form.comment_text.value=text;
if(mode=='editblog'||mode=='editComment')
{
document.edit_form.message.value=id;
document.edit_form.comment_title.value=title;
}
var width=layer.offsetWidth;
var height=layer.offsetHeight;
if(width<screen_width){var offset=(screen_width-width)/2;layer.style.left=offset+'px';}
if(height<screen_height){var offset=(screen_height-height)/2;layer.style.top=(scroll+offset)+'px';}
layer.style.visibility='visible';
layer.style.zIndex='999';
}
}
}

function save_comment()
{
var id=document.edit_form.f_Object_ID.value;
var mode=document.edit_form.mode.value;
var text=document.edit_form.comment_text.value;
var title="";
if(document.edit_form.comment_title){title=document.edit_form.comment_title.value;}
var file="";
if(document.edit_form.f_Picture){file=document.edit_form.f_Picture.value;}
if(file=="")
{
if((text.length<10&&title.length==0)||text.length>1000){alert('Длина комментария от 10 до 1000 символов. У Вас - '+text.length);return false;}
var r=Math.round(Math.random()*1000);
var url='/ajax/comment.php?mode='+mode+'&id='+id+'&text='+encodeURIComponent(text)+'&title='+encodeURIComponent(title)+'&r='+r;
request.open('GET',url,false);
request.send('');
var result=request.responseText;
if(result!=''&&result!=0)
{
var params=result.split(':::');
var text=params[0];
var title="";
if(params[1]){title=params[1];}
hide_form('edit_comment');
var comment=document.getElementById(id);
var text_div=getElementsByClass("text",comment,"div");
if(text_div[0]){text_div=text_div[0];text_div.innerHTML=text;}
var title_div=getElementsByClass("title",comment,"div");
if(title_div[0]){title_div=title_div[0];title_div.innerHTML='<h1>'+title+'</h1>';}
document.edit_form.comment_text.value='';
if(document.edit_form.comment_title){title=document.edit_form.comment_title.value='';}
}
return false;
}
else
{
if((text.length<10&&title.length==0)||text.length>1000){alert('Длина комментария от 10 до 1000 символов. У Вас - '+text.length);return false;}
}
return true;
}

function hide_form(form_name)
{
var layer=document.getElementById(form_name);
if(layer){layer.style.visibility='hidden';}
var bglayer=document.getElementById('bglayer');
if(bglayer){bglayer.parentNode.removeChild(bglayer);}
}

function getClientWidth(){return document.compatMode=='CSS1Compat'&&!window.opera?document.documentElement.clientWidth:document.body.clientWidth;}
function getClientHeight(){return document.compatMode=='CSS1Compat'&&!window.opera?document.documentElement.clientHeight:document.body.clientHeight;}
function getDocumentHeight(){return(document.body.scrollHeight>document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;}

function str_replace(search,replace,subject){
var f=search,r=replace,s=subject;
var ra=r instanceof Array,sa=s instanceof Array,f=[].concat(f),r=[].concat(r),i=(s=[].concat(s)).length;
while(j=0,i--){if(s[i]){while(s[i]=(s[i]+'').split(f[j]).join(ra?r[j]||"":r[0]),++j in f){};}};
return sa?s:s[0];
}
var last_elem=null;

function show_tag(elem,keyword,articles,blogs,videos,maps)
{
var bounds=getBounds(elem);
var body=document.body;
var screen_width=0;
if(document.documentElement.clientWidth){screen_width=document.documentElement.clientWidth-4;
}else{screen_width=document.body.offsetWidth-20;}
var screen_height=0;
if(document.documentElement.clientHeight){screen_height=document.documentElement.clientHeight+4;
}else{var sizes=getPageSizeWithScroll();screen_height=sizes[1];}
var body_height=body.offsetHeight;
var scroll=body.scrollTop?body.scrollTop:document.documentElement.scrollTop;
var tagtext=document.getElementById('tag_text');
if(tagtext){tagtext.innerHTML='';
if(articles>0){tagtext.innerHTML+='<a href="/tags/'+keyword+'.html?what=articles" title="Записей: '+articles+'">Статьи</a><br/>';}
if(blogs>0){tagtext.innerHTML+='<a href="/tags/'+keyword+'.html?what=blogs" title="Записей: '+blogs+'">Форумы</a><br/>';}
if(videos>0){tagtext.innerHTML+='<a href="/tags/'+keyword+'.html?what=videos" title="Записей: '+videos+'">Видео</a><br/>';}
if(maps>0){tagtext.innerHTML+='<a href="/tags/'+keyword+'.html?what=vodoemy" title="Записей: '+videos+'">Водоемы</a><br/>';}
}
var tag=document.getElementById('tag');
if(tag){if(tag.style.visibility=='visible'&&last_elem==elem){tag.style.visibility='hidden';return;}
var width=tag.offsetWidth;
var height=tag.offsetHeight;
tag.style.left=(bounds.left+bounds.width/2-width/2)+'px';
tag.style.top=(bounds.top-height)+'px';
tag.style.visibility='visible';
last_elem=elem;
}
}

function hide_tag()
{
var tag=document.getElementById('tag');
if(tag){tag.style.visibility='hidden';}
var tagtext=document.getElementById('tag_text');
if(tagtext){tagtext.innerHTML='';}
}
var scrollLeft='';
if(isOpera||isOpera6||isOpera7){scrollLeft='pixelLeft';}
else{scrollLeft='left';}
var scrollPos=148;
var scrollIndex=0;

function video_prev(){
var div=document.getElementById('divscroll');
if(div&&scrollIndex>0){
var str=div.style.left;
var temp=str.replace(/px/,"");
str=temp;
var scroll=str;
scroll=+scroll;
scroll+=scrollPos;
div.style.left=scroll+'px';
scrollIndex--;
}
}

function video_next(){
var div_parent=document.getElementById('video_scroll');
var div=document.getElementById('divscroll');
var parent_width=div_parent.offsetWidth;
if(div){
var str=div.style.left;
var temp=str.replace(/px/,"");
str=temp;
var scroll=str;
scroll=+scroll;
scroll-=scrollPos;
var max=((scrollCount+1)*scrollPos)-parent_width;
if(scroll*-1<max){
div.style.left=scroll+'px';
scrollIndex++;
}
}
}

// added by MihaKot
$.noConflict();
jQuery(document).ready(function(){
  
  // ------- Уголки -------
  jQuery(".shopCC, #cloudText, #countMarks").corner("round 3px");
  var isShop = jQuery("#netshopBasket").is("div");
  if(isShop) jQuery("#netshopBasket").corner("round 5px bottom");
  jQuery(".shopItem, .shopHelp").corner("round 3px bottom");

 jQuery(".plus").click(function(){
  id = jQuery(this).parent().attr("id").substr(1);
  m = jQuery(this).hasClass("minus");
  jQuery("#blog"+id).toggle("slow");
  if(m) {jQuery(this).removeClass("minus").addClass("plus");}
  else  {jQuery(this).removeClass("plus").addClass("minus");}
  return false;
 });

  // ------- менюшка -----
  jQuery("ul.l1 > li > a").click(function(){
    var parent = jQuery(this).parent();
	var children = jQuery(parent).children("ul");
	var disp = jQuery(children).css('display');
	if(jQuery(children).is(":hidden")){
	  jQuery(parent).parent("ul").children("li").each(function (){
	    if(jQuery(this).attr("id")!=jQuery(parent).attr("id")){
		  jQuery(this).children("ul").slideUp('slow');
		  jQuery(this).removeClass('a');
		}
	  });
	  jQuery(parent).addClass('a');
	  jQuery(children).slideDown('slow');
	  return false;
	}
	else{
	  jQuery(parent).removeClass('a');
	  jQuery(children).slideUp('slow');
	  return false;
	}
  });
  // ------------------- рейтинг ------------------
  jQuery(':submit').click(function() {
      // params
	  var re = jQuery(this).attr("name");
	  var usID=jQuery(this).parent("td").parent("tr").parent("tbody").parent("table").parent("form").children("input[name='f_Object_Author_ID']").val();
	  var objID=jQuery(this).parent("td").parent("tr").parent("tbody").parent("table").parent("form").children("input[name='f_Object_ID']").val();
	  if(usID){
	   var val = jQuery(this).attr('name');
	   var rForm = jQuery(this).parent("td").parent("tr").parent("tbody").parent("table").parent("form");
       var options = {
        target:        "#rf"+objID,
        beforeSubmit:  showRequest,
        success:       showResponse,
        url:           "/ajax/reiting.php?"+val+"=1",
        type:          "post"
       };
       jQuery(rForm).ajaxSubmit(options);
	   return false;
	  }
    });
});
function showRequest(formData, jqForm, options) {
    var queryString = $.param(formData);
	//alert(queryString);
    return true;
}
function showResponse(responseText, statusText)  {
    //alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText.');

}
