var objectMouseOver = {};
var objectMovingPrefix = 'moving_';
var objectMovingCounter = 1;

var competitionCounter = 0;
var thisCompetitionForm;

var commentCounter = 0;
var thisCommentForm;

var questionCounter = 0;
var thisQuestionForm;

var feedbackCounter = 0;
var thisFeedbackForm;

var subscribeCounter = 0;
var thisSubscribeForm

function setupScrollNews(obj, move) {
  var listIdx;
  var extraData = '';
  var pl = document.getElementById(obj.place);

  //for the first time
  if (obj.show.length == 0) {
     for (var i=obj.index; i<(obj.index+obj.amount); i++) {
         if (i < obj.list.length) {
            obj.show.push(i);
         }
     }
  }

  for (var i=0; i<obj.show.length; i++) {
      extraData = extraData + setupScrollNewsItem(obj.list[obj.show[i]]);
  }
  if (move < 0) {
     pl.style.left = obj.delta * -1;
  } else if (move > 0 && pl.style.left != 0) {
     pl.style.left = 0;
  }
  pl.innerHTML = extraData;
}

function setupScrollNewsItem(list) {
  var htmlBlock = '<div style="display: inline; width: 321px; float: left; cursor:pointer;" onclick="gotoFramedLink(\''+list[0]+'\')">';
  htmlBlock = htmlBlock + '<table border="0" cellpadding="0" cellspacing="0" width="318">';
  htmlBlock = htmlBlock + '<tr><td rowspan="4"><img src="'+list[1]+'" alt="" width="120" height="90" border="0"></td></tr>';
  htmlBlock = htmlBlock + '<tr><td class="slide_hdt"><img src="i/s.gif" alt="" width="198" height="1" border="0"></td></tr>';
  htmlBlock = htmlBlock + '<tr><td class="slide_text"><h1><a href="'+list[0]+'" style="color">'+list[2]+'</a></h1>'+list[3]+'</td></tr>';
  htmlBlock = htmlBlock + '<tr><td class="slide_hdb"><img src="i/s.gif" alt="" width="198" height="1" border="0"></td></tr>';
  htmlBlock = htmlBlock + '</table>';
  htmlBlock = htmlBlock + '</div>';

  return htmlBlock;
}

function moveScrollNews(obj, direction) {
  if (obj.list.length <= obj.amount) {
     return;
  }

  if (direction > 0) {
     var next = obj.show[obj.show.length-1] + 1;
     if (next == obj.list.length) {
        obj.show.push(0);
     } else {
        obj.show.push(next);
     }
  } else {
     var prev = obj.show[0] - 1;
     if (prev < 0) {
        obj.show.unshift(obj.list.length - 1);
     } else {
        obj.show.unshift(prev);
     }
  }

  if (direction > 0) {
     setupScrollNews(obj, direction);
     var t = setTimeout("moveOnAxisX('"+obj.place+"',-15,"+(obj.delta*-1)+")",50);
     obj.show.shift();
  } else {
     setupScrollNews(obj, direction);
     var t = setTimeout("moveOnAxisX('"+obj.place+"',15,0)",50);
     obj.show.pop();
  }
}

function gotoFramedLink(lnk) {
  if (lnk.indexOf('http') == 0) {
     window.parent.location = lnk;
  } else {
     document.location.href = lnk;
  }
}

function setupTop3News(obj) {
  var extraData = '';
  var mainImageData = '';
  var pl = document.getElementById(obj.place);
  var dotedLine = '<tr><td class="topnews_hd"><img src="i/s.gif" alt="" width="300" height="1" border="0"></td></tr>';

  for (var i=0; i<obj.list.length; i++) {
      var l = dotedLine;
      var f = false;
      var css = obj.regularItemCSS;
      if (i == obj.selected) {
         var rowS = 1 + obj.list.length * 2;
         mainImageData = '<tr><td rowspan="'+rowS+'"><a href="'+obj.list[i][0]+'"><img src="'+obj.list[i][1]+'" alt="" width="230" height="173" border="0"></a></td></tr>'
         css = obj.selectedItemCSS;
         f = true;
         l = '';
      } else {
         if (i > 0 && obj.selected == (i-1)) {
            l = '';
         }
      }
      extraData = extraData + l + setupTop3NewsItem(obj.list[i], obj.name, i, css, f);
      if (i != obj.selected && i == (obj.list.length - 1)) {
         extraData = extraData + dotedLine;
      }
  }

  extraData = '<table border="0" cellpadding="0" cellspacing="0">'+mainImageData+extraData+'</table>';
  pl.innerHTML = extraData;
}

function setupTop3NewsItem(list, obj, item, cssClass, full) {
  var htmlBlock = '<tr>';
  if (full) {
     htmlBlock = htmlBlock + '<td class="'+cssClass+'" style="cursor:pointer" onClick="location.href = \''+list[0]+'\'"><div style="overflow: hidden; width: 300px; height: 83px;"><div class="inner"><h1>'+list[2]+'</h1>'+list[3]+'</div></div></td>';
  } else {
     htmlBlock = htmlBlock + '<td class="'+cssClass+'" style="cursor:pointer" onClick="location.href = \''+list[0]+'\'"><div onMouseOver="changeTop3News('+obj+','+item+')" style="overflow: hidden; width: 300px; height: 44px;"><div class="inner"><h1>'+list[2]+'</h1></div></div></td>';
  }
  htmlBlock = htmlBlock + '</tr>';

  return htmlBlock;
}


function changeTop3News(obj, item) {
  obj.selected = item;
  setupTop3News(obj);
}

function moveOnAxisX(objId,step,finish) {
  var o = document.getElementById(objId);
  var cp = parseInt(o.style.left);
  if (!objectMouseOver[objId]) {
     objectMouseOver[objId] = {}
  }

  if (finish < 0) {
      if ((cp + step) < finish) {
         o.style.left = finish + "px";
      } else {
         o.style.left = cp + step + "px";
         objectMouseOver[objId].workerX = setTimeout("moveOnAxisX('"+objId+"',"+step+","+finish+")",50);
      }
  } else {
      if ((cp + step) >= finish) {
         o.style.left = finish + "px";
      } else {
         o.style.left = cp + step + "px";
         objectMouseOver[objId].workerX = setTimeout("moveOnAxisX('"+objId+"',"+step+","+finish+")",50);
      }
  }
}

function moveOnAxisY(objId,step,finish) {
  var o = document.getElementById(objId);
  var cp = parseInt(o.style.top);

  if (!objectMouseOver[objId]) {
     objectMouseOver[objId] = {}
  }
  if (finish < 0) {
      if ((cp + step) < finish) {
         o.style.top = finish + "px";
      } else {
         o.style.top = cp + step + "px";
         objectMouseOver[objId].workerY = setTimeout("moveOnAxisY('"+objId+"',"+step+","+finish+")",50);
      }
  } else {
      if ((cp + step) >= finish) {
         o.style.top = finish + "px";
      } else {
         o.style.top = cp + step + "px";
         objectMouseOver[objId].workerY = setTimeout("moveOnAxisY('"+objId+"',"+step+","+finish+")",50);
      }
  }
}

function realMouseOverOut(e,th,mode,objPath,step,finish) {
  var tg = (e.srcElement) ? e.srcElement : e.target;
  var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;

  var objId;
  var o = th;
  var path = objPath.split('-');
  for (var i=0; i<path.length; i++) {
      if (o.hasChildNodes()) {
         var list = new Array;
         for (var j=0; j<o.childNodes.length; j++) {
             if (o.childNodes[j].nodeName != '#text') {
                list.push(o.childNodes[j]);
             }
         }
         if (path[i] < list.length) {
             if (i == (path.length - 1)) {
                if (list[path[i]].id && list[path[i]].id.length) {
                   objId = list[path[i]].id;
                } else {
                   objectMovingCounter = objectMovingCounter + 1;
                   objId = objectMovingPrefix + objectMovingCounter;
                   list[path[i]].id = objId;
                }
             } else {
                o = list[path[i]];
             }
         }
      } else {
         return;
      }
  }

  if (mode == 1) {
     if (!objectMouseOver[objId] || objectMouseOver[objId].mode != 1) {
        if (!objectMouseOver[objId]) {
           objectMouseOver[objId] = {workerY: null};
        } else {
           clearTimeout(objectMouseOver[objId].workerY);
           objectMouseOver[objId].workerY = null;
        }

        th.isOpened = 1;
        objectMouseOver[objId].mode = 1;
        moveOnAxisY(objId,step,finish);
     }
  } else {
     var realOut = false;
     if (tg.isOpened == 1) {
        realOut = true;
     } else {
        var o = reltg;
        do {
            if (o) {
                if (o.isOpened == 1) {
                   break;
                } else if (o.nodeName == 'BODY') {
                   realOut = true;
                   break;
                }
            } else {
               break
            }
        } while (o = o.parentNode);
     }

     if (realOut && objectMouseOver[objId].mode == 1) {
        clearTimeout(objectMouseOver[objId].workerY);
        objectMouseOver[objId].workerY = null;
        th.isOpened = 0;
        objectMouseOver[objId].mode = 0;
        moveOnAxisY(objId,step,finish);
     }
  }
}

function printNow() {
  var monthNames = new Array('января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря');
  var currentTime = new Date();
  var day = currentTime.getDate();
  var month = currentTime.getMonth();
  document.write(day+' '+monthNames[month]);
}

function showBGImage(objId, src, width, height, descr, author, link_name, link_href, nxt) {
  var obj = document.getElementById(objId);
  var extra = '';
  if (author.length > 0) {
     extra = extra + '<strong>Автор: '+author+'</strong><br/>';
  }
  if (descr.length > 0) {
     extra = extra + descr+'<br/>';
  }
  if (link_name.length > 0 && link_href.length > 0) {
     extra = extra + 'Фото: <a href="'+link_href+'">'+link_name+'</a><br/>';
  } else if (link_name.length > 0) {
     extra = extra + 'Фото: '+link_name;
  }
  if (extra.length > 0) {
     extra = '<div style="text-align: left;">' + extra + '</div>';
  }
  obj.innerHTML = '<a href="javascript:void(showBGImageNext('+"'"+objId+"',"+nxt+'))"><img src="'+src+'" width="'+width+'" height="'+height+'" border="0"/></a>'+extra;
}

function showBGImageNext(objId, idx) {
  var nnext = idx + 1;
  if (nnext >= allImages.length) {
     nnext = 0;
  }
  showBGImage(objId,allImages[idx][0],allImages[idx][1],allImages[idx][2],allImages[idx][3],allImages[idx][4],allImages[idx][5],allImages[idx][6],nnext);
}

function mainPageSetNews(mode) {
  var list;
  if (mode == 1) {
     document.getElementById('mainPageNewsTab1').className = 'headerf';
     document.getElementById('mainPageNewsTab2').className = 'header';
     document.getElementById('mplinktonews').setAttribute('href', '/news');
     list = mainPage1News;
  } else {
     document.getElementById('mainPageNewsTab1').className = 'header';
     document.getElementById('mainPageNewsTab2').className = 'headerf';
     document.getElementById('mplinktonews').setAttribute('href', '/rbnews');
     list = mainPage2News;
  }

  var html = '<table border="0" cellpadding="0" cellspacing="0">';
  for (var i=0; i<list.length; i++) {
      html = html + '<tr>';
      if (list[i][1].length) {
         html = html + '<td class="image_l"><a href="'+list[i][0]+'"><img src="'+list[i][1]+'" alt="" border="0"></a></td>';
      } else {
         html = html + '<td class="image_l"><img src="/s/i/s.gif" width="1" height="1" alt="" border="0"></a></td>';
      }
      html = html + '<td class="text" style="cursor:pointer;" onClick="document.location.href = \''+list[i][0]+'\'"><h1><span class="date">'+list[i][4]+'</span> <a href="'+list[i][0]+'">'+list[i][2]+'</a></h1>'+list[i][3]+'</td>';
      html = html + '</tr>';
  }
  html = html + '</table>';
  document.getElementById('mainPageNews').innerHTML = html;
}

function mainPageSetRDNews(mode) {
  var list;
  if (mode == 1) {
     document.getElementById('mainPageRDTab1').className = 'headerf';
     document.getElementById('mainPageRDTab2').className = 'header';
     list = mainPage1RDNews;
  } else {
     document.getElementById('mainPageRDTab1').className = 'header';
     document.getElementById('mainPageRDTab2').className = 'headerf';
     list = mainPage2RDNews;
  }

  var html = '<table border="0" cellpadding="0" cellspacing="0" class="topact">';
  for (var i=0; i<list.length; i++) {
      html = html + '<tr>';
      html = html + '<td valign="top"><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="count">&nbsp;'+list[i][1]+'&nbsp;</td></tr><tr><td class="tail"><img src="/s/i/tail.gif" alt="" width="4" height="4" border="0"/></td></tr></table></td>';
      html = html + '<td class="article"><a href="'+list[i][0]+'">'+list[i][2]+'</a></td>';
      html = html + '</tr>';
  }
  html = html + '</table>';
  document.getElementById('mainPageRDNews').innerHTML = html;
}

function top20PageSetRDNews(mode) {
  var header;
  var list;
  if (mode == 1) {
     document.getElementById('top20PageRDTab1').className = 'headerf';
     document.getElementById('top20PageRDTab2').className = 'header';
     header = 'Просмотров: ';
     list = top20Page1RDNews;
  } else {
     document.getElementById('top20PageRDTab1').className = 'header';
     document.getElementById('top20PageRDTab2').className = 'headerf';
     list = top20Page2RDNews;
     header = 'Комментариев: ';
  }

  var html = '<table border="0" cellpadding="0" cellspacing="0">';
  for (var i=0; i<list.length; i++) {
      html = html + '<tr>';
      if (list[i][5].length) {
         html = html + '<td class="image_l"><a href="'+list[i][0]+'"><img src="'+list[i][5]+'" alt="" border="0"></a></td>';
      } else {
         html = html + '<td class="image_l"><img src="/s/i/s.gif" width="1" height="1" alt="" border="0"></a></td>';
      }
      html = html + '<td class="text"><h1><span class="date">'+list[i][6]+'</span> <a href="'+list[i][0]+'">'+list[i][2]+'</a></h1><a href="/rubrica/'+list[i][7]+'">'+list[i][4]+'</a><br>'+list[i][3]+'<div class="count">'+header+list[i][1]+'</div></td>';
      html = html + '</tr>';
  }
  html = html + '</table>';
  document.getElementById('top20PageRDNews').innerHTML = html;
}

function preParseString(text) {
   var nv = navigator.appVersion;
   if (nv.indexOf('MSIE') > 0) {
      text = utf8decode(unescape(text));
   }
   return text;
}   

function utf8decode(utftext) {
   var string = "";
   var i = 0;
   var c = c1 = c2 = 0;

   while (i < utftext.length) {
         c = utftext.charCodeAt(i);
         if (c < 128) {
            string += String.fromCharCode(c);
            i++;
         } else if((c > 191) && (c < 224)) {
            c2 = utftext.charCodeAt(i+1);
            string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
         } else {
            c2 = utftext.charCodeAt(i+1);
            c3 = utftext.charCodeAt(i+2);
            string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
         }
   }

   return string;
}

function prepareString(text) {
   var nv = navigator.appVersion;
   if (nv.indexOf('MSIE') > 0) {
      text = utf8encode(text);
   }
   return text;
}   

function utf8encode(string) {
   string = string.replace(/\r\n/g,"\n");  
   var utftext = "";  
  
   for (var n=0, k=string.length; n < k; n++) {  
       var c = string.charCodeAt(n);  
  
       if (c < 128) {  
           utftext += String.fromCharCode(c);  
       }  
       else if((c > 127) && (c < 2048)) {  
           utftext += String.fromCharCode((c >> 6) | 192);  
           utftext += String.fromCharCode((c & 63) | 128);  
       }  
       else {  
           utftext += String.fromCharCode((c >> 12) | 224);  
           utftext += String.fromCharCode(((c >> 6) & 63) | 128);  
           utftext += String.fromCharCode((c & 63) | 128);  
       }  
   }  

   return escape(utftext);
}

function changeFontSize(objIf, mode) {
  var obj = document.getElementById(objIf);
  var ff = parseInt(obj.style.fontSize);
  if (mode == 1) {
     if (ff < 24) {
        ff = ff + 1;
     }
  } else {
     if (ff > 8) {
        ff = ff - 1;
     }
  }
  obj.style.fontSize = ff+'px';
}

/* feedback */
function saveFeedbackAnswer(myForm, ifr) {
  var choosen = new Array();
  
  for (var i=0; i<myForm.elements.length; i++) {
      input = myForm.elements[i]; 
      if (input.getAttribute('type') == 'text') {
         choosen.push(input.getAttribute('name')+'='+prepareString(input.value));
      } else if (input.nodeName == 'TEXTAREA') {
         choosen.push(input.getAttribute('name')+'='+prepareString(input.value));
      }
  }
  
  var wnd;
  if (document.frames) {
     wnd = document.frames[ifr];
  } else {
     wnd = document.getElementById(ifr).contentWindow;
  }
  wnd.location = '/post?feedback=1'+'&' + choosen.join('&');
}

function feedbackIsSaved() {
  thisFeedbackForm.innerHTML = 'Ваше сообщение было успешно отправлено';
}

function feedbackIsFailed(alertText) {
  alert(alertText);
  var list = thisFeedbackForm.getElementsByTagName('img');
  for (var i=0; i<list.length; i++) {
      var lnk = list[i].getAttribute('src');
      if (lnk.indexOf('/__captcha') == 0) {
         feedbackCounter = feedbackCounter + 1;
         lnk = '/__captcha?'+feedbackCounter;
         list[i].getAttribute('src', lnk);
         list[i].src = lnk;
         break;
      }
  }
}

function saveFeedbackForm(frm) {
  thisFeedbackForm = frm;
  saveFeedbackAnswer(frm,'post_ifr');
  return false;
}
/* end of feedback */

/* question */
function saveQuestionAnswer(myForm, ifr) {
  var choosen = new Array();
  
  for (var i=0; i<myForm.elements.length; i++) {
      input = myForm.elements[i]; 
      if (input.getAttribute('type') == 'text') {
         choosen.push(input.getAttribute('name')+'='+prepareString(input.value));
      } else if (input.nodeName == 'TEXTAREA') {
         choosen.push(input.getAttribute('name')+'='+prepareString(input.value));
      }
  }
  
  var wnd;
  if (document.frames) {
     wnd = document.frames[ifr];
  } else {
     wnd = document.getElementById(ifr).contentWindow;
  }
  wnd.location = '/post?question=1'+'&' + choosen.join('&');
}

function questionIsSaved() {
  alert('Ваш вопрос был успешно отправлен');

  for (var i=0; i<thisQuestionForm.elements.length; i++) {
      input = thisQuestionForm.elements[i]; 
      if (input.getAttribute('type') == 'text') {
         input.value = '';
      } else if (input.nodeName == 'TEXTAREA') {
         input.value = '';
      }
  }

  var list = thisQuestionForm.getElementsByTagName('img');
  for (var i=0; i<list.length; i++) {
      var lnk = list[i].getAttribute('src');
      if (lnk.indexOf('/__captcha') == 0) {
         questionCounter = questionCounter + 1;
         lnk = '/__captcha?'+questionCounter;
         list[i].getAttribute('src', lnk);
         list[i].src = lnk;
         break;
      }
  }
}

function questionIsFailed(alertText) {
  alert(alertText);
  var list = thisQuestionForm.getElementsByTagName('img');
  for (var i=0; i<list.length; i++) {
      var lnk = list[i].getAttribute('src');
      if (lnk.indexOf('/__captcha') == 0) {
         questionCounter = questionCounter + 1;
         lnk = '/__captcha?'+questionCounter;
         list[i].getAttribute('src', lnk);
         list[i].src = lnk;
         break;
      }
  }
}

function saveQuestionForm(frm) {
  thisQuestionForm = frm;
  saveQuestionAnswer(frm,'post_ifr');
  return false;
}
/* end of question */

/* survey */
function saveSurveyAnswer(id, name, toshow, tohide, ifr) {
  var choosen = new Array();
  
  var e = document.getElementsByName(name);
  for (var i=0; i<e.length; i++) {
      if (e[i].checked) {
         choosen.push(e[i].getAttribute('value'));
      }
  }
  
  var wnd;
  if (document.frames) {
     wnd = document.frames[ifr];
  } else {
     wnd = document.getElementById(ifr).contentWindow;
  }
  wnd.location = '/post?survey=1&param=' + choosen.join('_');
  return;   
  
  ttlOpt = ttlOpt + choosen.length;
  for (var i=0; i<srvIds.length; i++) {
      var td = document.getElementById('srv_'+srvIds[i]);
      var amount = srvOpt[i];
      for (var j=0; j<choosen.length; j++) {
          if (choosen[j] == srvIds[i]) {
             amount = amount + 1;
             break;
          }
      }
      var percent = Math.round(1000 * amount / ttlOpt) / 10;
      var percent1 = Math.round(100 * amount / ttlOpt);
      td.innerHTML = percent1 + '%';
      var dv = document.getElementById('srv_'+srvIds[i]+'_line');
      dv.setAttribute('style', 'background-image: url(/s/i/pr-m/pr'+percent1+'.gif) left top; background-repeat: repeat-y;');
  }
  
  var ts = document.getElementById(toshow);
  var th = document.getElementById(tohide);
  th.style.display = 'none';
  ts.style.display = 'block';
}

function checkSurveyAnswer(c, id1, id2) {
  var pp;
  var p = document.cookie.indexOf(c);
  if (p > -1) {
     pp = document.getElementById(id2);
  } else {
     pp = document.getElementById(id1);
  }
  pp.style.display = 'block';
}
/* end of survey */

/* competition */
function saveCompetitionAnswer(quiz, myForm, ifr) {
  thisCompetitionForm = myForm;
  var choosen = new Array();
  
  for (var i=0; i<myForm.elements.length; i++) {
      input = myForm.elements[i]; 
      if (input.getAttribute('type') == 'text') {
         choosen.push(input.getAttribute('name')+'='+prepareString(input.value));
      } else if (input.getAttribute('type') == 'radio') {
         if (input.checked) {
            choosen.push(input.getAttribute('name')+'='+input.value);
         }
      }
  }
  
  var wnd;
  if (document.frames) {
     wnd = document.frames[ifr];
  } else {
     wnd = document.getElementById(ifr).contentWindow;
  }
  wnd.location = '/post?quiz='+quiz+'&' + choosen.join('&');
  
  return false;
}

function competitionIsSaved() {
  thisCompetitionForm.innerHTML = '<div>Спасибо за участие в конкурсе</div>';
}

function competitionIsFailed(alertText) {
  alert(alertText);
  var list = thisCompetitionForm.getElementsByTagName('img');
  for (var i=0; i<list.length; i++) {
      var lnk = list[i].getAttribute('src');
      if (lnk.indexOf('/__captcha') == 0) {
         competitionCounter = competitionCounter + 1;
         lnk = '/__captcha?'+competitionCounter;
         list[i].getAttribute('src', lnk);
         list[i].src = lnk;
         break;
      }
  }
}
/* end of competition */

/* comment */
function saveCommentAnswer(content, myForm, ifr) {
  var choosen = new Array();
  
  for (var i=0; i<myForm.elements.length; i++) {
      input = myForm.elements[i]; 
      if (input.getAttribute('type') == 'text') {
         choosen.push(input.getAttribute('name')+'='+prepareString(input.value));
      } else if (input.nodeName == 'TEXTAREA') {
         choosen.push(input.getAttribute('name')+'='+prepareString(input.value));
      }
  }
  
  var wnd;
  if (document.frames) {
     wnd = document.frames[ifr];
  } else {
     wnd = document.getElementById(ifr).contentWindow;
  }
  wnd.location = '/post?comment='+content+'&' + choosen.join('&');
}

function commentIsSaved(a1,a2) {
  document.location.replace('/rubrica/'+a2+'/'+a1+'(1)');
}

function commentIsFailed(alertText) {
  alert(alertText);
  var list = thisCommentForm.getElementsByTagName('img');
  for (var i=0; i<list.length; i++) {
      var lnk = list[i].getAttribute('src');
      if (lnk.indexOf('/__captcha') == 0) {
         commentCounter = commentCounter + 1;
         lnk = '/__captcha?'+commentCounter;
         list[i].getAttribute('src', lnk);
         list[i].src = lnk;
         break;
      }
  }
}

function saveCommentForm(id,frm) {
  thisCommentForm = frm;
  saveCommentAnswer(id,frm,'post_ifr');
  return false;
}
/* end of comment */

/* subscribe */
function saveSubscribeAnswer(myForm, ifr) {
  var choosen = new Array();
  
  for (var i=0; i<myForm.elements.length; i++) {
      input = myForm.elements[i]; 
      if (input.getAttribute('type') == 'text') {
         choosen.push(input.getAttribute('name')+'='+prepareString(input.value));
      } else if (input.getAttribute('type') == 'checkbox') {
         if (input.checked) {
            choosen.push(input.getAttribute('name')+'='+input.value);
         }
      }
  }
  
  var wnd;
  if (document.frames) {
     wnd = document.frames[ifr];
  } else {
     wnd = document.getElementById(ifr).contentWindow;
  }
  wnd.location = '/post?subscribe=1'+'&' + choosen.join('&');
}

function subscribeIsSaved() {
  thisSubscribeForm.innerHTML = '<div>Через некоторое время на ваш электронный адрес придет письмо, содержащее ссылку на подтверждение подписки.</div>';
}

function subscribeIsFailed(alertText) {
  alert(alertText);
  var list = thisSubscribeForm.getElementsByTagName('img');
  for (var i=0; i<list.length; i++) {
      var lnk = list[i].getAttribute('src');
      if (lnk.indexOf('/__captcha') == 0) {
         subscribeCounter = subscribeCounter + 1;
         lnk = '/__captcha?'+subscribeCounter;
         list[i].getAttribute('src', lnk);
         list[i].src = lnk;
         break;
      }
  }
}

function saveSubscribeForm(frm) {
  thisSubscribeForm = frm;
  saveSubscribeAnswer(frm,'post_ifr');
  return false;
}
/* end of subscribe */

