
function getXmlHttp() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}
var xmlHttp = getXmlHttp();

function registration() {

un = document.getElementById("username-r").value;
    ps = document.getElementById("password-r").value;
	reps = document.getElementById("repassword-r").value;
	e = document.getElementById("email-r").value;
	c = document.getElementById("registration-code-r").value;
	d = encodeURIComponent(document.getElementById("day").value);
	m = encodeURIComponent(document.getElementById("month").value);
	y = encodeURIComponent(document.getElementById("year").value);
	g = encodeURIComponent(document.getElementById("gender").value);
	
	document.getElementById("login-text").innerHTML = 'логин';
	document.getElementById("password-text").innerHTML = 'пароль - дважды';
	document.getElementById("email-text").innerHTML = 'e-mail';
	document.getElementById("code-text").innerHTML = 'код';
   document.getElementById("error-registration-text").innerHTML = '<i>Пожалуйста, подождите</i>';
    

	
    // execute the quickstart.php page from the server
    
      var url = "/xml/registration.php";
var params = "username=" + un + "&password=" + ps + "&repassword=" + reps + "&email=" + e + "&code=" + c + "&day=" + d + "&month=" + m + "&year=" + y + "&gender=" + g;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");


    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponseRegistration;
    // make the server request
    xmlHttp.send(params);
}
function handleServerResponseRegistration() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // extract the XML retrieved from the server
      xmlResponse = xmlHttp.responseXML;
      // obtain the document element (the root element) of the XML structure
      
       xmlRoot = xmlResponse.documentElement;  
      
      error = xmlRoot.getElementsByTagName("error");
	  if(error.length > 0) {
	    document.getElementById("error-registration-text").innerHTML = '';
        for (var i=0; i < error.length; i++) {
		    if(error.item(i).firstChild.data == 0) document.getElementById("login-text").innerHTML = 'логин <span style="color: red">такой логин уже зарегистрирован</span>';
            if(error.item(i).firstChild.data == 1) document.getElementById("login-text").innerHTML = 'логин <span style="color: red">слишком короткий логин</span>';
            if(error.item(i).firstChild.data == 2) document.getElementById("password-text").innerHTML = 'пароль <span style="color: red">слишком короткий пароль: минимум 4 символа</span>';
		    if(error.item(i).firstChild.data == 3) document.getElementById("password-text").innerHTML = 'пароль <span style="color: red">пароль и его подтверждение не совпадают</span>';
		    if(error.item(i).firstChild.data == 4) document.getElementById("email-text").innerHTML = 'e-mail <span style="color: red">e-mail набран неправильно</span>';
		    if(error.item(i).firstChild.data == 5) document.getElementById("code-text").innerHTML = 'код <span style="color: red">неправильно указан код с картинки</span>';
		 if(error.item(i).firstChild.data == 6) document.getElementById("email-text").innerHTML = 'e-mail <span style="color: red">пользователь с этим e-mail уже есть</span>';
		   
		}
	} else {
	document.getElementById("error-registration-text").innerHTML = '';
	    document.getElementById("reg-content").innerHTML = '<div style="padding: 10px;color: #666;   -moz-border-radius: 5px; background: #fbf9be; margin: 10px 0; font-size: 11px;border: 1px dotted #ccc;">Регистрация почти завершена. На ваш электронный ящик выслано письмо с подтверждением вашего почтового адреса.</div>';
	}

	 
	
	  
	 
	
	  
      
      // restart sequence
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
function ctrlEnter(event)
    {
    if((event.ctrlKey) && ((event.keyCode == 0xA)||(event.keyCode == 0xD)))
        {
        addcomment();
        }
    }
	

function add_submit(id) {
    document.getElementById("submit").innerHTML = '<input type="submit" value="отдать голос" onclick="do_vote();" class="submit" />';
    answerId = id;
}
function do_vote() {
  
    
var url = "/xml/votes.php";
var params = "voteId=" + voteId + "&answerId=" + answerId;
xmlHttp.open("POST", url, true);
document.getElementById("submit").innerHTML = '<img src="/templates/default/style/img/loader.gif" />';
//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");

    

    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleRequestStateChangeAddVote;
    // make the server request
    xmlHttp.send(params);
	
}
function handleRequestStateChangeAddVote() 
{
  // when readyState is 4, we are ready to read the server response
  if (xmlHttp.readyState == 4) 
  {
    // continue only if HTTP status is "OK"
    if (xmlHttp.status == 200) 
    {
      try
      {
        
		// do something with the response from the server
        handleServerResponseAddVote();
		
      }
      catch(e)
      {
        // display error message
        alert("Error reading the response: " + e.toString());
      }
    } 
    else
    {
      // display status message
      alert("There was a problem retrieving the data:\n" + 
            xmlHttp.statusText);
    }
  }
}

function handleServerResponseAddVote() {
  var  xmlResponse = xmlHttp.responseXML;
  xmlRoot = xmlResponse.documentElement;  
  
  val = xmlRoot.getElementsByTagName("value");
  per = xmlRoot.getElementsByTagName("percent");
  na = xmlRoot.getElementsByTagName("name");
  
  
  var html = "";  
 
  for (var i = 0; i<val.length; i++) 
   html += '<div class="answer">' + per.item(i).firstChild.data + '%  (' + val.item(i).firstChild.data + ') - ' + na.item(i).firstChild.data + '</div>';
  		 
    document.getElementById("answers").innerHTML = html;
    document.getElementById("submit").innerHTML = 'Спасибо, Ваш голос принят';
}


function favorite(user_id, type, id)
{
 
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
   var idname = '';
  if(type == 'comment') {
    idname = "favorite" + id;
    } else { 
	idname = "favorite-publication";
	}
	document.getElementById(idname).innerHTML = 'Загрузка';


   
    xmlHttp.open("GET", "/xml/favorite.php?user_id=" + user_id + "&type=" + type + "&id=" + id, true);  
	
    
    xmlHttp.onreadystatechange = handleRequestStateChangeFavorite;
    
    xmlHttp.send(null);
  }
}
function handleRequestStateChangeFavorite() 
{
  // when readyState is 4, we are ready to read the server response
  if (xmlHttp.readyState == 4) 
  {
    // continue only if HTTP status is "OK"
    if (xmlHttp.status == 200) 
    {
      try
      {
        // do something with the response from the server
        handleServerResponseFavorite();
      }
      catch(e)
      {
        // display error message
        alert("Error reading the response: " + e.toString());
      }
    } 
    else
    {
      // display status message
      alert("There was a problem retrieving the data:\n" + 
            xmlHttp.statusText);
    }
  }
}
function handleServerResponseFavorite() 
{

  if (xmlHttp.readyState == 4) 
  {
    
    if (xmlHttp.status == 200) 
    {
  
       var xmlResponse = xmlHttp.responseXML;

  xmlRoot = xmlResponse.documentElement;  
    

favoriteid = xmlRoot.getElementsByTagName("favoriteid");
smt = xmlRoot.getElementsByTagName("smt");
type = xmlRoot.getElementsByTagName("type");


    if(type.item(0).firstChild.data == 'comment') 

	      document.getElementById("favorite" + favoriteid.item(0).firstChild.data).innerHTML = smt.item(0).firstChild.data;
		  else  document.getElementById("favorite-publication").innerHTML = smt.item(0).firstChild.data;
      
    } 
  
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

function delete_favorite(user_id, id)
{
 
  




   
    xmlHttp.open("GET", "/xml/favorite-delete.php?user_id=" + user_id +  "&id=" + id, true);  
	
    
    xmlHttp.onreadystatechange = handleRequestStateChangeFavoriteDelite;
    
    xmlHttp.send(null);
  
}
function handleRequestStateChangeFavoriteDelite() 
{
  // when readyState is 4, we are ready to read the server response
  if (xmlHttp.readyState == 4) 
  {
    // continue only if HTTP status is "OK"
    if (xmlHttp.status == 200) 
    {
      try
      {
        // do something with the response from the server
        handleServerResponseFavoriteDelite();
      }
      catch(e)
      {
        // display error message
        alert("Error reading the response: " + e.toString());
      }
    } 
    else
    {
      // display status message
      alert("There was a problem retrieving the data:\n" + 
            xmlHttp.statusText);
    }
  }
}
function handleServerResponseFavoriteDelite() 
{

  if (xmlHttp.readyState == 4) 
  {
    
    if (xmlHttp.status == 200) 
    {
  
       var xmlResponse = xmlHttp.responseXML;

  xmlRoot = xmlResponse.documentElement;  
    

favoriteid = xmlRoot.getElementsByTagName("favoriteid");
smt = xmlRoot.getElementsByTagName("smt");



  if(smt.item(0).firstChild.data == 0) document.getElementById("fav" + favoriteid.item(0).firstChild.data).innerHTML = '';
else
	      document.getElementById("delete" + favoriteid.item(0).firstChild.data).innerHTML = smt.item(0).firstChild.data;
		  
      
    } 
  
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

document.onkeydown = catchKey;

function catchKey (event) {
//    var event;
	if (!document.getElementById) return;
	if (window.event) event = window.event;

	if (event.ctrlKey) {
		switch (event.keyCode ? event.keyCode : event.which ? event.which : null) {
			case 13:
                		openMailWindow();
				break;
			case 45:
			   if (document.getElementById("rnews_bloger2")) {
				var txt = "";
				if (document.getSelection) {
					txt = document.getSelection();
				} else if (document.selection && document.selection.createRange) {
					txt = document.selection.createRange().text;
				}
                		if (txt) {
                		   var txt1 = $("#rnews_bloger_txt").val();
                		   if (!document.getElementById("rnews_bloger_add")) {
                		   	$("#blog_link").after('<div id="rnews_bloger_add" style="display: none; visibility: hidden;"></div>');
                		   }
                		   $("#rnews_bloger_add").html(txt1);
                		   $("#rnews_bloger1").text(txt);
                		   $("#rnews_bloger_txt").val($("#rnews_bloger_add").html());
                		   $("#rnews_bloger2").text(txt);
                		   x = document.getElementById("blog_link").offsetLeft+200;
	        		   y = document.getElementById("blog_link").offsetTop-200;
	        		   document.getElementById("blocks_tabs_id").style.top = y;
	        		   document.getElementById("blocks_tabs_id").style.Left = x;
	        		   var of = $("#blog_link").offset();
	        		   $("body").scrollTop(of.top-300);
	        		   $(".blocks_tabs").show();
	        		}
			   }
			   break;
		}
	}
}

function openMailWindow() {
	var html = showDialog();
}

function showDialog(pagePath, args, width, height)
{
	 misprintWindow = window.open("/mistake_report.php", "Misprint", 'width=400,height=400') 
}

function msgs(page) {

    
    to = document.getElementById("to").value;
    document.getElementById("page" + pageID).innerHTML = '<a onclick="msgs(' + pageID + ')">' + pageID + '</a>';
    document.getElementById("page" + page).innerHTML = '<b>' + page + '</b>';
	pageID = page;
	
	
    document.getElementById("msgs").innerHTML = '<table><tr><td><img src="/templates/default/style/img/loader.gif" /> Загрузка</td></tr></table>';
      var url = "/xml/msgs.php";
var params = "page=" + page + "&to=" + to;
xmlHttp.open("POST", url, true);

xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");


  
    xmlHttp.onreadystatechange = handleServerResponseMsgs;

    xmlHttp.send(params);
}
function handleServerResponseMsgs() 
{
  
  if (xmlHttp.readyState == 4) 
  {

    if (xmlHttp.status == 200) 
    {
        var xmlResponse = xmlHttp.responseXML;
        xmlRoot = xmlResponse.documentElement;  
        
		id = xmlRoot.getElementsByTagName("id");
        author = xmlRoot.getElementsByTagName("author");
        date = xmlRoot.getElementsByTagName("date");
	    text = xmlRoot.getElementsByTagName("text");
	    del = xmlRoot.getElementsByTagName("delete");
		st = xmlRoot.getElementsByTagName("st");
	    var msgs = '<table width="100%" cellspacing="0">';
	    for (var i=0; i<author.length; i++) {
	        msgs += '<tr id="msg-history-list"' + st.item(i).firstChild.data + '><td style="padding: 10px 0;width: 80px;"><span class="blue"><b>' + author.item(i).firstChild.data + '</b></span><br /><span class="date">' + date.item(i).firstChild.data + '</span></td><td  class="t2">' + text.item(i).firstChild.data + '</td><td style="width: 20px;"><input type="checkbox" name="' + del.item(i).firstChild.data +'[]" value="' + id.item(i).firstChild.data+'" /></td></tr>';
	    }
	   
	   
	   msgs += '</table>';
	   document.getElementById("msgs").innerHTML = msgs;
	
	  
	 
	
	  
      
      
    } 
    
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
function addquestion() {

	commentz = encodeURIComponent(document.getElementById("comment-form").value);
    authorz = encodeURIComponent(document.getElementById("author-form").value);
	
	emailz = encodeURIComponent(document.getElementById("email-form").value);
	cityz = encodeURIComponent(document.getElementById("city-form").value);
	codez = encodeURIComponent(document.getElementById("codefromimg").value);
	
	
	document.getElementById("butLoad").innerHTML = '<i>Подождите...</i>';
    
	document.getElementById("add-comment").style.opacity = "0.7";
	document.getElementById("add-comment").style.filter = "alpha(opacity=70)";
	
    // execute the quickstart.php page from the server
    
      var url = "/xml/question.php";
var params = "id=" + dataId + "&comment=" + commentz + "&author=" + authorz + "&email=" + emailz + "&code=" + codez  + "&city=" + cityz;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");


    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponseAddQuestion;
    // make the server request
    xmlHttp.send(params);
}
function handleServerResponseAddQuestion() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // extract the XML retrieved from the server
      xmlResponse = xmlHttp.responseXML;
      // obtain the document element (the root element) of the XML structure
      xmlDocumentElement = xmlResponse.documentElement;
      // get the text message, which is in the first child of
      // the the document element
      statuss = xmlDocumentElement.firstChild.data;
      
      document.getElementById("add-comment").style.opacity = "1";	
 if(statuss == 0) { 

	 document.getElementById("comment-form").value = '';
	
	 
	 
	 document.getElementById("butLoad").innerHTML = '<div class="success">Ваш вопрос добавлен</span>';
	  
	 }
	 else {
	
      document.getElementById("butLoad").innerHTML = '<ul>' + statuss + '</ul>';
	  
	 }
	 
	  
      
      // restart sequence
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

function activation() {

m = document.getElementById("email-activation").value;
    c = document.getElementById("code-activation").value;
document.getElementById("email-activation-text").innerHTML = 'e-mail';
	document.getElementById("code-activation-text").innerHTML = 'код';
    // execute the quickstart.php page from the server
    document.getElementById("error-activation-text").innerHTML = '<i>Пожалуйста, подождите</i>';
      var url = "/xml/activation.php";
var params = "email=" + m + "&code=" + c;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");


    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponseActivation;
    // make the server request
    xmlHttp.send(params);
}
function handleServerResponseActivation() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // extract the XML retrieved from the server
      xmlResponse = xmlHttp.responseXML;
      // obtain the document element (the root element) of the XML structure
      
       xmlRoot = xmlResponse.documentElement;  
      
      error = xmlRoot.getElementsByTagName("error");
	  if(error.length > 0) {
	  document.getElementById("error-activation-text").innerHTML = '';
        for (var i=0; i < error.length; i++) {
		    if(error.item(i).firstChild.data == 0) document.getElementById("email-activation-text").innerHTML = 'e-mail <span style="color: red">пользователь с таким e-mail не зарегистрирован или его учетная запись активирована</span>';
            if(error.item(i).firstChild.data == 1) document.getElementById("code-activation-text").innerHTML = 'код <span style="color: red">Неверный код</span>';
          if(error.item(i).firstChild.data == 2) document.getElementById("error-activation-text").innerHTML = '<span style="color: red">К сожелению письмо выслать не удалось, попробуйте позже</span>';
		}
	} else {
	document.getElementById("error-activation-text").innerHTML = '';
	    document.getElementById("activation-content").innerHTML = '<div style="padding: 10px;color: #666;   -moz-border-radius: 5px; background: #fbf9be; margin: 10px 0; font-size: 11px;border: 1px dotted #ccc;">Код активации выслан на Ваш e-mail</div>';
	}

	 
	
	  
	 
	
	  
      
      // restart sequence
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
function slide(id) {
      if (document.getElementById(id).style.display == "none")
         {document.getElementById(id).style.display = "block"}
      else
         {document.getElementById(id).style.display = "none"}
      }





function ratingg(id, action, user_id)
{
 
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {

    document.getElementById("plus"+id).innerHTML = '';
	document.getElementById("minus"+id).innerHTML = '';

	document.getElementById("rate"+id).innerHTML = 'Загрузка...';

  
    xmlHttp.open("GET", "/xml/rating.php?id=" + id + "&action=" + action + "&user_id=" + user_id, true);  
	
    
    xmlHttp.onreadystatechange = handleServerResponseRating;
 
    xmlHttp.send(null);
  }
}
function handleServerResponseRating() 
{

  if (xmlHttp.readyState == 4) 
  {
    
    if (xmlHttp.status == 200) 
    {
 
  
    
    
	  
	     var xmlResponse = xmlHttp.responseXML;

  xmlRoot = xmlResponse.documentElement;  
    

value = xmlRoot.getElementsByTagName("value");
commentid = xmlRoot.getElementsByTagName("commentid");
    for (var i=0; i<commentid.length; i++) {

	
	      document.getElementById("rate" + commentid.item(i).firstChild.data).innerHTML = value.item(i).firstChild.data;
      }
      
    } 
    
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}


function restore() {

m = document.getElementById("email-restore").value;
    c = document.getElementById("code-restore").value;
document.getElementById("email-restore-text").innerHTML = 'e-mail';
	document.getElementById("code-restore-text").innerHTML = 'код';
    // execute the quickstart.php page from the server
     document.getElementById("error-restore-text").innerHTML = '<i>Пожалуйста, подождите</i>';
      var url = "/xml/restore.php";
var params = "email=" + m + "&code=" + c;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");


    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponseRestore;
    // make the server request
    xmlHttp.send(params);
}
function handleServerResponseRestore() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // extract the XML retrieved from the server
      xmlResponse = xmlHttp.responseXML;
      // obtain the document element (the root element) of the XML structure
      
       xmlRoot = xmlResponse.documentElement;  
      
      error = xmlRoot.getElementsByTagName("error");
	  if(error.length > 0) {
	  document.getElementById("error-restore-text").innerHTML = '';
        for (var i=0; i < error.length; i++) {
		    if(error.item(i).firstChild.data == 0) document.getElementById("email-restore-text").innerHTML = 'e-mail <span style="color: red">пользователь с таким e-mail не зарегистрирован</span>';
            if(error.item(i).firstChild.data == 1) document.getElementById("code-restore-text").innerHTML = 'код <span style="color: red">Неверный код</span>';
            if(error.item(i).firstChild.data == 2) document.getElementById("error-restore-text").innerHTML = '<span style="color: red">К сожелению письмо выслать не удалось, попробуйте позже</span>';
		}
	} else {
	    document.getElementById("restore-content").innerHTML = '<div style="padding: 10px;color: #666;   -moz-border-radius: 5px; background: #fbf9be; margin: 10px 0; font-size: 11px;border: 1px dotted #ccc;">Новый пароль выслан на Ваш e-mail</div>';
	}

	 
	
	  
	 
	
	  
      
      // restart sequence
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

/*****************************************/
// Name: Javascript Textarea BBCode Markup Editor
// Version: 1.3
// Author: Balakrishnan
// Last Modified Date: 25/jan/2009
// License: Free
// URL: http://www.corpocrat.com
/******************************************/

var textarea;
var content;


function edToolbar(obj) {
    document.write("<div class=\"toolbar\">");
	document.write("<img class=\"button\" src=\"/templates/default/style/bbeditor/images/bold.gif\" name=\"btnBold\" title=\"Жирный\" onClick=\"doAddTags('[b]','[/b]','" + obj + "')\">");
    document.write("<img class=\"button\" src=\"/templates/default/style/bbeditor/images/italic.gif\" name=\"btnItalic\" title=\"Курсив\" onClick=\"doAddTags('[i]','[/i]','" + obj + "')\">");
	document.write("<img class=\"button\" src=\"/templates/default/style/bbeditor/images/underline.gif\" name=\"btnUnderline\" title=\"Подчеркнутый\" onClick=\"doAddTags('[u]','[/u]','" + obj + "')\">");
	document.write("<img class=\"button\" src=\"/templates/default/style/bbeditor/images/link.gif\" name=\"btnLink\" title=\"Вставить ссылку\" onClick=\"doURL('" + obj + "')\">");
	document.write("<img class=\"button\" src=\"/templates/default/style/bbeditor/images/picture.gif\" name=\"btnPicture\" title=\"Вставить картинку\" onClick=\"doImage('" + obj + "')\">");
	document.write("</div>");
	//document.write("<textarea id=\""+ obj +"\" name = \"" + obj + "\" cols=\"" + width + "\" rows=\"" + height + "\"></textarea>");
				}

function doImage(obj)
{
textarea = document.getElementById(obj);
var url = prompt('Введите URL картинки:','http://');
var scrollTop = textarea.scrollTop;
var scrollLeft = textarea.scrollLeft;

if (url != '' && url != null) {

	if (document.selection) 
			{
				textarea.focus();
				var sel = document.selection.createRange();
				sel.text = '[img]' + url + '[/img]';
			}
   else 
    {
		var len = textarea.value.length;
	    var start = textarea.selectionStart;
		var end = textarea.selectionEnd;
		
        var sel = textarea.value.substring(start, end);
	    //alert(sel);
		var rep = '[img]' + url + '[/img]';
        textarea.value =  textarea.value.substring(0,start) + rep + textarea.value.substring(end,len);
		
			
		textarea.scrollTop = scrollTop;
		textarea.scrollLeft = scrollLeft;
	}
}

}

function doURL(obj)
{
textarea = document.getElementById(obj);
var url = prompt('Введите адрес страницы:','http://');
var scrollTop = textarea.scrollTop;
var scrollLeft = textarea.scrollLeft;

if (url != '' && url != null) {

	if (document.selection) 
			{
				textarea.focus();
				var sel = document.selection.createRange();
				
			if(sel.text==""){
					sel.text = '[url]'  + url + '[/url]';
					} else {
					sel.text = '[url=' + url + ']' + sel.text + '[/url]';
					}			

				//alert(sel.text);
				
			}
   else 
    {
		var len = textarea.value.length;
	    var start = textarea.selectionStart;
		var end = textarea.selectionEnd;
		
        var sel = textarea.value.substring(start, end);
		
		if(sel==""){
				var rep = '[url]' + url + '[/url]';
				} else
				{
				var rep = '[url=' + url + ']' + sel + '[/url]';
				}
	    //alert(sel);
		
        textarea.value =  textarea.value.substring(0,start) + rep + textarea.value.substring(end,len);
		
			
		textarea.scrollTop = scrollTop;
		textarea.scrollLeft = scrollLeft;
	}
 }
}

function doAddTags(tag1,tag2,obj)
{
textarea = document.getElementById(obj);
	// Code for IE
		if (document.selection) 
			{
				textarea.focus();
				var sel = document.selection.createRange();
				//alert(sel.text);
				sel.text = tag1 + sel.text + tag2;
			}
   else 
    {  // Code for Mozilla Firefox
		var len = textarea.value.length;
	    var start = textarea.selectionStart;
		var end = textarea.selectionEnd;
		
		
		var scrollTop = textarea.scrollTop;
		var scrollLeft = textarea.scrollLeft;

		
        var sel = textarea.value.substring(start, end);
	    //alert(sel);
		var rep = tag1 + sel + tag2;
        textarea.value =  textarea.value.substring(0,start) + rep + textarea.value.substring(end,len);
		
		textarea.scrollTop = scrollTop;
		textarea.scrollLeft = scrollLeft;
		
		
	}
}

function doList(tag1,tag2,obj){
textarea = document.getElementById(obj);
// Code for IE
		if (document.selection) 
			{
				textarea.focus();
				var sel = document.selection.createRange();
				var list = sel.text.split('\n');
		
				for(i=0;i<list.length;i++) 
				{
				list[i] = '[*]' + list[i];
				}
				//alert(list.join("\n"));
				sel.text = tag1 + '\n' + list.join("\n") + '\n' + tag2;
			} else
			// Code for Firefox
			{

		var len = textarea.value.length;
	    var start = textarea.selectionStart;
		var end = textarea.selectionEnd;
		var i;
		
		var scrollTop = textarea.scrollTop;
		var scrollLeft = textarea.scrollLeft;

		
        var sel = textarea.value.substring(start, end);
	    //alert(sel);
		
		var list = sel.split('\n');
		
		for(i=0;i<list.length;i++) 
		{
		list[i] = '[*]' + list[i];
		}
		//alert(list.join("<br>"));
        
		
		var rep = tag1 + '\n' + list.join("\n") + '\n' +tag2;
		textarea.value =  textarea.value.substring(0,start) + rep + textarea.value.substring(end,len);
		
		textarea.scrollTop = scrollTop;
		textarea.scrollLeft = scrollLeft;
 }
}

function subscribe() {
for (i = 0; i < document.subscriber.agency.length; ++i)
if (document.subscriber.agency.options[i].selected == true)
id = document.subscriber.agency.options[i].value;
document.getElementById("subscribe-month").innerHTML = '<img src="/templates/default/style/img/loader.gif" />';
var url = "/xml/subscribe.php";
var params = "id=" + id;
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = handleServerResponseSubscirbe;
xmlHttp.send(params);
}
function handleServerResponseSubscirbe() 
{
  if (xmlHttp.readyState == 4) 
  {
    if (xmlHttp.status == 200) 
    {
xmlResponse = xmlHttp.responseXML;
xmlRoot = xmlResponse.documentElement;  
value = xmlRoot.getElementsByTagName("value");
document.getElementById("subscribe-month").innerHTML = value.item(0).firstChild.data
} 
else {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}
 
