var nWinExist=0; // признак открытия доп.окна
var nWinBExist=0; // признак открытия большого доп.окна
var nWinExistXY=0; // признак открытия доп.окна с координатами
var name_field;

function winop(cPage) {
 if (nWinExist==1) {
   windop.close();
   nWinExist=0;
 }
 windop = window.open(cPage,"mywin","toolbar=yes,scrollbars=yes,height=600,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=100,top=30");
 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)
{
  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;

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+"()");
}

function pastesmile(text)
{
  if (document.new_post_form) 
  {
    if (document.selection) 
    { 
      if (name_field=='title') 
  	    document.new_post_form.ftitle.focus();
  	  else
	    document.new_post_form.message.focus();

  	  document.new_post_form.document.selection.createRange().text = text;
    } 
    else
    { 
      if (name_field=='title') 
        document.new_post_form.ftitle.value += text;
  	  else
        document.new_post_form.message.value += text;
    }
  }
}

// - End of JavaScript - -->
