/*---------------------------------------------------------------------------
* @Module Name: MultiType Blogs
* @Module Id: ls_mblogs
* @Module URI: http://livestreet.ru/addons/81/
* @Description: MultiType Blogs - multitype blog extension for LiveStreet
* @Version: 1.2.122
* @Author: aVadim
* @Author URI: 
* @LiveStreet Version: 0.3.1
* @File Name: mblogs.js
*----------------------------------------------------------------------------
*/

function ajaxJoinLeaveBlog(obj,idBlog) {   
  obj=$(obj);
  JsHttpRequest.query(
    DIR_WEB_ROOT+'/include/ajax/modules/mblogs/joinLeaveMBlog.php',
    {
      idBlog: idBlog
    },
    function(result, errors) {
      if (!result) {
        msgErrorBox.alert('Error','Please try again later');
      }
      if (result.bStateError) {
        msgErrorBox.alert(result.sMsgTitle,result.sMsg);
      } else {
        msgNoticeBox.alert(result.sMsgTitle,result.sMsg);
        if (obj)  {
          obj.getParent().removeClass('active');
          if (result.bState) {
            obj.getParent().addClass('active');
          }
          divCount=$('blog_user_count_'+idBlog);
          if (divCount) {
            divCount.set('text',result.iCountUser);
          }
        }
      }
    },
    true
  );
}


function ajaxBlogInfo(idBlog) {
  return ajaxMBlogInfo(idBlog);
}

function ajaxMBlogInfo(idBlog) {
  JsHttpRequest.query(
    DIR_WEB_ROOT+'/include/ajax/modules/mblogs/mblogInfo.php',
    { idBlog: idBlog },
    function(result, errors) {
      if (!result) {
        msgErrorBox.alert('Error','Please try again later');
        alert(errors);
      }
      if (result.bStateError) {

      } else {
        if ($('block_blog_info')) {
          $('block_blog_info').set('html',result.sText);
        }
        if ($('type-'+result.sType)) {
          $('type-'+result.sType).show();
        }
        if (result.sType=='subcat') {
          clearSubcatSelect();
          for (var key in result.aSubcats) {
            subcatSelect.options[subcatSelect.options.length] =
              new Option(result.aSubcats[key]['subcat_name'], key);
          }
        } else {
          $('type-subcat').hide();
        }
        if (result.aParams && parseInt(result.aParams['attach_allow'])) {
          $('mtopic_param_attach_allow').show();
        } else {
          $('mtopic_param_attach_allow').hide();
        }
      }
    },
    true
  );
}

function clearSubcatSelect() {
  if (!subcatSelect) subcatSelect = $('subcat');
  if (subcatSelect.options.length)
    for (key in subcatSelect) subcatSelect.remove(key);
}

function ajaxMBlogTransliterate(text, setFunc) {
  JsHttpRequest.query(
    DIR_WEB_ROOT+'/include/ajax/modules/mblogs/mblogTransliterate.php',
    { text: text },
    function(result, errors) {
      if (!result) {
        //msgErrorBox.alert('Error','Please try again later');
      }
      if (result.bStateError) {
        // nothing
      } else {
          setFunc(result.sText);
      }
    },
    true
  );
}

var subcatSelect;


