var nWinExist=0; // признак открытия доп.окна
var nWinBExist=0; // признак открытия большого доп.окна
var nWinExistXY=0; // признак открытия доп.окна с координатами
var name_field;
var nPostidEx=-1; // уже открытая форма комментариев

// снежинки
var count = 17;
var speed = 1;
var snowfall = true;
function start() {
if (document.all) {     // IExplorer
  yMax = document.body.clientHeight;
  xMax = document.body.clientWidth;
  }
else if (document.layers) {     // Netscape
  yMax = window.innerHeight;
  xMax = window.innerWidth;
  }
xachse = new Array();
for(i = 1; i <=40; i++)  {
 x = 10000;
 do
 { x = Math.round(Math.random() * 10000);  } 
 while(x > xMax-50);
 xachse[i] = x;
};
yachse = new Array();
for(i = 1; i <=40; i++)  { yachse[i] = - Math.round(Math.random() * 1000); };
show();
movesnow(); }
function movesnow() {
if (snowfall) {
for(i = 1; i <=count; i++)
 { 
 wind = Math.round(Math.random() * 10); // horizontale Bewegung
 nn="snow"+i;
 if (wind == 2) {
  if (document.all) {  document.all(nn).style.left = xachse[i] + wind;}
  else if (document.layers) { document.layers[nn].left = xachse[i] + wind;       }
 }
 if (wind == 1) {
  if (document.all) {  document.all(nn).style.left = xachse[i] - wind;}
  else if (document.layers) { document.layers[nn].left = xachse[i] - wind;       }
  }
if (document.all) {       if (yachse[i] >= yMax-50+document.body.scrollTop) { yachse[i] = - Math.round(Math.random() * 100); }; }
else if (document.layers) {      if (yachse[i] >= yMax-50+pageYOffset) { yachse[i] = - Math.round(Math.random() * 100); };     }
if ( count >= 30 ) { yachse[i] = yachse[i] + speed + 1;  }
else  { yachse[i] = yachse[i] + speed;  };
if (document.all) {      document.all(nn).style.top = yachse[i];}
else if (document.layers) {     document.layers[nn].top = yachse[i];      }
 }
setTimeout('movesnow()',10);
}
}
function hide(){
  for(i = 1; i <=count; i++)
  { 
    nn="snow"+i;
    if (document.all) {  document.all(nn).style.visibility = "hidden"; }
    else if (document.layers) { document.layers[nn].visibility = "hide";       } 
  }
}
function show(){
for(i = 1; i <=count; i++)
{ 
  nn="snow"+i;
  if (document.all) {  document.all(nn).style.visibility = "visible"; }
  else if (document.layers) { document.layers[nn].visibility = "show";       }
  }
}
// конец снежинок


function ShowHide(pid1)
{
  var container = document.getElementById("tr_" + pid1);		
  if (container!=null)
  {
    if (container.style.display != "none")
      container.style.display = 'none';
    else
      container.style.display = 'block';
  }
}

function winop(cPage) {
 if (nWinExist==1) {
   windop.close();
   nWinExist=0;
 }
 windop = window.open(cPage,"mywin","toolbar=yes,resizable=yes,scrollbars=yes,height=500,width=700,left=100,top=30");
 nWinExist=1;
} 

function winopxy(cPage,nHeight,nWidth) {
// height +30 width +20 
 if (nWinExistXY==1) {
   windopxy.close();
   nWinExistXY=0;
 }
 windopxy = window.open(cPage,"mywin","toolbar=no,scrollbars=no,height="+nHeight+",width="+nWidth+",left=50,top=50");
 nWinExistXY=1;
}

function winopxysc(cPage,nHeight,nWidth) {
// height +30 width +20 
 if (nWinExistXY==1) {
   windopxy.close();
   nWinExistXY=0;
 }
 windopxy = window.open(cPage,"mywin","toolbar=no,scrollbars=yes,resizable=yes,height="+nHeight+",width="+nWidth+",left=100,top=30");
 nWinExistXY=1;
}

function winbop(cPage) {
 if (nWinBExist==1) {
   winbdop.close();
   nWinBExist=0;
 }
 winbdop = window.open(cPage,"mywinb","");
 nWinBExist=1;
}


function fconfirm(inForm)
{
  var cError="Форма не заполнена:";
  if (inForm.name=='forget_form')
  {
    if (inForm.useremail.value=='')
      cError=cError+"\n- Не введен E-mail";
    if (inForm.control.value=='')
      cError=cError+"\n- Не введено контрольное число";
  }  
  if (inForm.name=='message_form')
  {
    if (inForm.author.value=='')
      cError=cError+"\n- Вы не представились";
    if (inForm.useremail.value=='')
      cError=cError+"\n- Не введен E-mail";
    if (inForm.mescont.value=='')
      cError=cError+"\n- Нет текста сообщения";
    if (inForm.control.value=='')
      cError=cError+"\n- Не введено контрольное число";
  }  
  if (inForm.name=='gbook_form')
  {
    if (inForm.author.value=='')
      cError=cError+"\n- Вы не представились";
    if (inForm.useremail.value=='')
      cError=cError+"\n- Не введен E-mail";
    if (inForm.contgbook.value=='')
      cError=cError+"\n- Нет текста сообщения";
    if (inForm.control.value=='')
      cError=cError+"\n- Не введено контрольное число";
  }  
  if (inForm.name=='login_form')
  {
    if (inForm.username.value=='')
      cError=cError+"\n- Нет выражения для поиска";
  }
  if (inForm.name=='poisk_form')
  {
    if (inForm.poisk.value=='')
      cError=cError+"\n- Нет выражения для поиска";
  }
  if (inForm.name=='coment_form')
  {
    if (inForm.author.value=='')
      cError=cError+"\n- Вы не представились";
    if (inForm.useremail.value=='')
      cError=cError+"\n- Не введен E-mail";
    if (inForm.contcoment.value=='')
      cError=cError+"\n- Нет комментария";
  }  
  if (inForm.name=='new_blog_form')
  {
    if (inForm.content.value==0)
      cError=cError+"\n- Не выбрана категория";
    if (inForm.mainrazd.value==0)
      cError=cError+"\n- Не выбрана подкатегория";
    if (inForm.statusblog.value==0)
      cError=cError+"\n- Не выбран статус блога";
    if (inForm.nameblog.value=='')
      cError=cError+"\n- Нет названия блога";
    if (inForm.keywords.value=='')
      cError=cError+"\n- Нет ключевых слов";
    if (inForm.contblog.value=='')
      cError=cError+"\n- Нет текста блога";
    if (inForm.useremail.value=='')
      cError=cError+"\n- Не введен E-mail";
  }  
  if (cError!="Форма не заполнена:")
    alert (cError);
  else
  {
    if (confirm("Подтверждаете выполнение операции ?"))
      inForm.submit();
  }
}


var hotkey=13;
var inFormObj;
if (document.layers)
  document.captureEvents(Event.KEYPRESS);

function confirmobj(inForm,inFormOb)
{
  if (confirm("Подтверждаете выполнение операции ?"))
  {
    inFormObj=inFormOb;
    inFormObj.value=true;
    inForm.submit();
  }
}  

function pressonoff(onoff,inFormOb)
{
  inFormObj=inFormOb;
  if (inFormObj==null)
  {
    document.onkeypress=null;
    return;
  }
  if (onoff==1)
    document.onkeypress=mypress;
  else
    document.onkeypress=null;
}

function mypress(key)
{
 if (document.layers)
 {
   if (key.which==hotkey)
     inFormObj.value=inFormObj.value+"<BR>";
 }
 else if (!document.all)
 {
   if (key.which==hotkey)
     inFormObj.value=inFormObj.value+"<BR>";
 }

 if (document.all)
 {
   if (event.keyCode==hotkey)
     inFormObj.value=inFormObj.value+"<BR>";
 }
}


function fnWrapWithTags(txt, sTag, sClass){
    var sHTML = "[" + sTag;
    sHTML += (sClass) ? " class=\"" + sClass + "\"" : "";
    sHTML += ("]" +txt + "[/" + sTag + "]");
    return sHTML;
}

function fnAddHtml(){
    var txt = this.toString();
    var sTag = Teg;
    return fnWrapWithTags(txt, sTag, "");
}

String.prototype.i = fnAddHtml;
String.prototype.b = fnAddHtml;
String.prototype.u = fnAddHtml;
String.prototype.s = fnAddHtml;
String.prototype.left = fnAddHtml;
String.prototype.center = fnAddHtml;
String.prototype.right = fnAddHtml;
String.prototype.justify = fnAddHtml;
String.prototype.hr = fnAddHtml;

function fnCode(){
    var txt = this.toString();
    var sTag = "code";
    return fnWrapWithTags(txt, sTag, "");
}

String.prototype.code = fnCode;

var Teg = 'b';
function fnApplyTag(sTag){
    Teg = sTag;
    if (!document.all && !document.all.item) return;
    var oSelTxt = document.selection.createRange();
    var sSelTxt = oSelTxt.text;
    if (sSelTxt) 
     oSelTxt.text = eval("sSelTxt."+sTag+"()");
    else {
     document.selection.createRange();
     document.selection.value += 'ffffffff';
    }
     
}

function pastesmile_com(inForm,text)
{
  if (inForm) 
  {
    if (document.selection) { 
      if (name_field=='message') 
        inForm.message.focus();
      else
        inForm.ftitle.focus();
  	  
  	  inForm.document.selection.createRange().text = text;
    } 
    else {
      if (name_field=='message') 
        inForm.message.value += text;
      else
        inForm.ftitle.value += text;
    }
  }
}


function ShowHide_Com(pid1,pid2)
{
  var container1 = document.getElementById("ttr_" + pid1);		
  var container2 = document.getElementById("ttr_" + pid2);		
  var container3 = document.getElementById("ttr_3");		
  if (container1)
  {    
    if (container1.style.display != "none")
    {
    }   
    else
      container1.style.display = 'block';
  }
  if (container2)
  {    
    if (container2.style.display != "none")   
      container2.style.display = 'none';
  }
  if (container3)
  {    
    if (pid1==2)
    {
      if (container3.style.display != "none")   
      {
      }
      else  
        container3.style.display = 'block';
    }
    if (pid1==1)
    {
      if (container3.style.display != "none")   
        container3.style.display = 'none';
    }
  }
}

function chTab(nTab) 
{

  if (nTab==1) {
    $('#c_1').css('display', 'block');
    $('#c_2').css('display', 'none');
//    $('#c_1').css('opacity', 0.3);
//    $('#c_1').stopAll().fadeTo(800,1, function(){$('#c_1').Show();});
    $('#tab1l').css('background', 'url(./images/tabwl.png) no-repeat');
    $('#tab1c').css('background', 'url(./images/tabwc.png)');
    $('#tab1r').css('background', 'url(./images/tabwr.png) no-repeat 100% 0%');
    $('#tab2l').css('background', 'url(./images/tabbl.png) no-repeat');
    $('#tab2c').css('background', 'url(./images/tabbc.png)');
    $('#tab2r').css('background', 'url(./images/tabbr.png) no-repeat 100% 0%');
  }
  else {
    $('#c_2').css('display', 'block');
    $('#c_1').css('display', 'none');
//    $('#c_2').css('opacity', 0.3);
//    $('#c_2').stopAll().fadeTo(800,1, function(){$('#c_2').Show();});
    $('#tab1l').css('background', 'url(./images/tabbl.png) no-repeat');
    $('#tab1c').css('background', 'url(./images/tabbc.png)');
    $('#tab1r').css('background', 'url(./images/tabbr.png) no-repeat 100% 0%');
    $('#tab2l').css('background', 'url(./images/tabwl.png) no-repeat');
    $('#tab2c').css('background', 'url(./images/tabwc.png)');
    $('#tab2r').css('background', 'url(./images/tabwr.png) no-repeat 100% 0%');
  }
}

function LiteMainMenu(nDiv,lLite)
{
  if (lLite)
    $('#nMMDiv'+nDiv).css('background', 'url(./images/menumlite.gif)');
  else
    $('#nMMDiv'+nDiv).css('background', 'url(./images/menug.gif)');
}

function LiteLeftMenu(nDiv,lLite)
{
  if (lLite)
    $('#nLMDiv'+nDiv).css('background', 'url(./images/cfonlite.gif)');
  else
    $('#nLMDiv'+nDiv).css('background', 'url(./images/cfon.gif)');
}

function chPicture(cPicture,nWidth){
  cPicture = '"./images/content/'+cPicture+'.jpg"';
  var cDivContent = '<A href='+cPicture+' class=thickbox><IMG style="BORDER: #D9D9D9 1px solid; padding: 1px;" src='+cPicture+' width='+nWidth+' border=0 align=middle HSPACE=0 VSPACE=0 ALT="Увеличить изображение"></A>';    
  var cZoomContent = '<IMG SRC=./images/lupa.gif BORDER=0 ALIGN=middle HSPACE=2 WIDTH=16 HEIGHT=16 VSPACE=0><A HREF='+cPicture+' class=thickbox>увеличить изображение</A>';
  $("#cPicture").empty().hide();  
  $("#cPicture").append(cDivContent).show("slow");  
  $("#cZoom").empty();  
  $("#cZoom").append(cZoomContent);  
}

function Comment_Div(nPostid) 
{
  if (nPostidEx >= 0) {
    if (nPostidEx != nPostid) 
      $('#comment_div'+nPostidEx).css('display', 'none');
    else
      $('#comment_div'+nPostidEx).hide("slow");  
    $('#nComHref'+nPostidEx).empty();  
    
    if (nPostidEx==0)
      $('#nComHref'+nPostidEx).append('Написать комментарий');  
    else
      $('#nComHref'+nPostidEx).append('Ответить');  
    if (nPostidEx == nPostid) {
      nPostidEx = -1;
      return;
    }
  }

  if (nPostidEx != nPostid) {
    $('#nComHref'+nPostid).empty();  
    $('#comment_div'+nPostid).show("slow");  
    $('#nComHref'+nPostid).append('Скрыть');  
    nPostidEx = nPostid;
  }
}

// - End of JavaScript - -->
