// op_uk.js
// Andrei Boris 16-12-04

function printOpForm(racine, ptpage){
  document.write('<a name="f"></a><form name="am" action="'+racine+'op/add.php?l=u" method="post">');
  document.write('<input type="hidden" name="edited_page" value="'+ptpage+'">');
  document.writeln('<table width="100%" cellspacing=1 cellpadding=2 style="BACKGROUND-COLOR:#FFF;BORDER:#666 1px solid;">');
  document.write('<tr>');
  document.write('<td colspan=2 align="center" class="chapeau">Додайте Ваш коментар</td>');
  document.write('</tr>');
  document.write('<tr>');
  document.write('<td colspan=2 valign="top" class="note" style="text-align:center">');
  document.write('Щоб додати коментар, заповніть поля унизу. Прохання не надсилати запитань - для цього існує Форум.');
  document.write('<br>Якщо у Вас не встановлена українська клавіатура, вживайте ');

  document.write('<a href="#f" onClick=window.open("');
  document.write(racine+'op/translit.html","konvertor","width=580,height=280,resizable");return false;" ');
  document.write(' class="here">транслітератор</a>.');

  document.write('<br>Поля, відзначені (<span style="color:red">*</span>) є обов\'язковими.</td>');
  document.write('</tr>');
  document.write('<tr>');
  document.write('<td class="champ" align="right">Ім\'я<span style="color:red">*</span> :</td>');
  document.write('<td class="champ"><input type="text" name="author" size=40 maxlength=40 class="ajo" value=""></td>');
  document.write('</tr>');
  document.write('<tr>');
  document.write('<td class="champ" align="right">Email<span style="color:red">*</span> :');
  document.write('<br><input type="checkbox" name="masked" value="y">');
  document.write('<span class="note"> Заховати email</span></td>');
  document.write('<td class="champ" valign="top">');
  document.write('<input type="text" name="email" size=40 maxlength=40 class="ajo" value=""></td>');
  document.write('</tr>');
  document.write('<tr>');
  document.write('<td class="champ" align="right" valign="top">Коментар<span style="color:red">*</span> :');
  document.write('<br><span class="note"> Ви можете надрукувати ще ');
  document.write('<input readonly type="text" name="remLen" size="2" maxlength="3" value="5000" ');
  document.write('style="font-size:9px;font-weight:bold;color:#666;BORDER:#666 0px;padding:0px;background-color:#EEE;"> ');
  document.write('знаків</span></td>');
  document.write('<td class="champ"><textarea name="bi" cols="60" rows="5" class="ajo" onFocus="storeCaret();" ');
  document.write('onChange="storeCaret();" onKeyDown="storeCaret();" onKeyUp="storeCaret();" onselect="storeCaret();">');
  document.write('</textarea></td>');
  document.write('</tr>');

  document.write('<tr>');
  document.write('<td class="champ" align="right" valign="top"><span class="note">Натисніть на іконку, щоб вставити в текст</span>');
  document.write('</td><td class="champ">');

  document.write('<img src="'+racine+'op/img/smilies/smile.gif" border=0 style="cursor:pointer;cursor:hand;" ');
  document.write('onclick="AddSmile(\' :-) \');" alt=""> ');
  document.write('<img src="'+racine+'op/img/smilies/wink.gif" border=0 style="cursor:pointer;cursor:hand;" ');
  document.write('onclick="AddSmile(\' ;-) \');" alt=""> ');
  document.write('<img src="'+racine+'op/img/smilies/biggrin.gif" border=0 style="cursor:pointer;cursor:hand;" ');
  document.write('onclick="AddSmile(\' :-)) \');" alt=""> ');
  document.write('<img src="'+racine+'op/img/smilies/cool.gif" border=0 style="cursor:pointer;cursor:hand;" ');
  document.write('onclick="AddSmile(\' 8-) \');" alt=""> ');
  document.write('<img src="'+racine+'op/img/smilies/heart.gif" border=0 style="cursor:pointer;cursor:hand;" ');
  document.write('onclick="AddSmile(\' :heart: \');" alt=""> ');
  document.write('<img src="'+racine+'op/img/smilies/kiss.gif" border=0 style="cursor:pointer;cursor:hand;" ');
  document.write('onclick="AddSmile(\' :-* \');" alt=""> ');
  document.write('<img src="'+racine+'op/img/smilies/laugh.gif" border=0 style="cursor:pointer;cursor:hand;" ');
  document.write('onclick="AddSmile(\' :-D \');" alt=""> ');
  document.write('<img src="'+racine+'op/img/smilies/sad.gif" border=0 style="cursor:pointer;cursor:hand;" ');
  document.write('onclick="AddSmile(\' :-( \');" alt=""> ');
  document.write('<img src="'+racine+'op/img/smilies/smoke.gif" border=0 style="cursor:pointer;cursor:hand;" ');
  document.write('onclick="AddSmile(\' :-Q \');" alt=""> ');
  document.write('<img src="'+racine+'op/img/smilies/surprised.gif" border=0 style="cursor:pointer;cursor:hand;" ');
  document.write('onclick="AddSmile(\' :-O \');" alt=""> ');
  document.write('<img src="'+racine+'op/img/smilies/tired.gif" border=0 style="cursor:pointer;cursor:hand;" ');
  document.write('onclick="AddSmile(\' *-O \');" alt=""> ');
  document.write('<img src="'+racine+'op/img/smilies/tongue.gif" border=0 style="cursor:pointer;cursor:hand;" ');
  document.write('onclick="AddSmile(\' :-P \');" alt=""> ');

  document.write('</td>');
  document.write('</tr>');
  document.write('<tr>');
  document.write('<td class="champ" align="center" colspan=2>');
  document.write('<input type="submit" name="submit_comment" value="Відіслати" class="btn">');
  document.write('<input type="submit" name="preview_comment" value="Переглянути" class="btn">');
  document.write('</td>');
  document.write('</tr>');
  document.write('</table>');
  document.write('</form>');
}

function checkCount() {
  var maxlimit = 5000;
  if (document.am.bi.value.length > maxlimit) {
    document.am.bi.value = document.am.bi.value.substring(0, maxlimit);
  }
  else {
    document.am.remLen.value = maxlimit - document.am.bi.value.length;
  }
}

function AddSmile(text) {
  document.am.bi.focus();
  if ((document.am.bi.createTextRange) && (document.am.bi.caretPos)) {
       var caretPos = document.am.bi.caretPos;
       caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
  }
  else {
      document.am.bi.value += text;
  }
  checkCount();
}

function storeCaret() {
  document.am.bi.focus();
  if (document.am.bi.createTextRange) {
    document.am.bi.caretPos = document.selection.createRange().duplicate();
  }
  checkCount();
}