﻿var currentPostPage = 1;
var currentBandId = 0;
var currentSiteId = 0;
var currentFestivalId = 0;

$(document).ready(
  function(){
  
      $('.new_mainmenu > a').click(function(){
            $('.new_mainmenu span').hide();
            $('.new_mainmenu a').show();
            $('.new_mainmenu').removeClass('new_active');
            $(this).parent().addClass('new_active');
            $(this).hide();
            $(this).parent().children('span').show();
            
      });
      $('ul[name=list] > li > a').click(function(event){
            event.stopPropagation();
            $('ul[name=list] > li span').hide()
            $('ul[name=list] > li a').show();
            $('.new_mainmenu span').hide();
            $('.new_mainmenu a').show();
            $('.new_mainmenu').removeClass('new_active');
            $(this).parent().parent().parent().addClass('new_active');
            $(this).hide();
            $(this).parent().children('span').show();
      });
    
      $('a[rel^=lightbox]').lightBox();
      
      $('.commentTextArea').prettyComments();
      
      $('.commentTextArea').mousedown(function(){
        // hide default text
        if($(this).val()=="Szólj hozzá!")
        {
            $(this).val("");
        }
        // show avatar
        $(this).parent().parent().children('.new_avatar').show();
        // show send button
        $(this).parent().children('a').show();
        // enlarge textarea
        $(this).removeClass("slim");
        // set preety comments behaviour
        $(this).css('height','26px').prettyComments(); 
       });
       
      $('.commentTextArea').blur(function(){
            if(jQuery.trim($(this).val())=='')
            {
                // hide avatar
                $(this).parent().parent().children('.new_avatar').hide();
                // hide send button
                $(this).parent().children('a').hide();
                // small textarea
                $(this).css('height','14px');
                $(this).addClass("slim");
                $(this).val("Szólj hozzá!");
            }
        });
        
     // $('.postTextArea').prettyComments(); 
     // $('.slimpost').css('height','14px');
      $('.postTextArea').mousedown(function(){
        // hide default text
        if($(this).val()=="Írj saját bejegyzést Te is!")
        {
            $(this).val("");
        }
        // show radio button list
        $('.new_PostUserSelector').show();
        // show avatar
        $('.new_PostAvatar').show();
        // show send button
        if($('#upSelClose').css('display')=='none' && $('#upSelOpen').css('display')=='none')
        {
            $('#upSelClose').show();
        }
        // enlarge textarea
        $(this).removeClass("slimpost");
        
        $('.new_MainPostContainer').css('padding-bottom','0px');
        $(this).focus();
        $(this).css('height','56px').prettyComments(); 
       });
       
       // hide postarea
       $(document).click(function(e){
        if(!$('#pContent').hasClass('slimpost') && !$('#pContent').attr('disabled'))
        {
            if($(e.target).is('.new_MainPostContainer, .new_MainPostContainer *')) return;
            else{
                if(jQuery.trim($('.postTextArea').val())=='' && !$('#pContent').attr('disabled'))
                {
                    // hide radio button list
                     $('.new_PostUserSelector').hide();
                    // hide avatar
                    $('.new_PostAvatar').hide();
                    // hide send button
                    $('#upSelClose').hide();
                    $('#upSelOpen').hide();
                    // small textarea
                    $('.postTextArea').css('height','14px');
                    $('.postTextArea').addClass("slimpost");
                    $('.postTextArea').val("Írj saját bejegyzést Te is!");
                    $('.new_MainPostContainer').css('padding-bottom','10px');
                }
            
            
            }
        }
       });

       $('input:radio').click(function(){
            $('.new_PostAvatar img').hide();
            $('#av_' + $(this).val()).show();
        });
        
        $('.new_AddPicsLink a').click(function(){
            $('#upSelClose').hide();
            $('#upSelOpen').show();
        });
        
        $('.new_PicsCancel a').click(function(){
            $('.new_PicsSelectorForm input').replaceWith("<input type='file' name='datafile' />");
            $('.new_fileWarningText').empty();
            $('#upSelOpen').hide();
            $('#upSelClose').show();
        });
        
        $('#no').click(function() { 
            $.unblockUI(); 
            return false; 
        }); 
  }
);

function refresh()
{
            $('.new_mainmenu > a').click(function(){
            $('.new_mainmenu span').hide();
            $('.new_mainmenu a').show();
            $('.new_mainmenu').removeClass('new_active');
            $(this).parent().addClass('new_active');
            $(this).hide();
            $(this).parent().children('span').show();
            
      });
      $('ul[name=list] > li > a').click(function(event){
            event.stopPropagation();
            $('ul[name=list] > li span').hide()
            $('ul[name=list] > li a').show();
            $('.new_mainmenu span').hide();
            $('.new_mainmenu a').show();
            $('.new_mainmenu').removeClass('new_active');
            $(this).parent().parent().parent().addClass('new_active');
            $(this).hide();
            $(this).parent().children('span').show();
      });
    
      $('a[rel^=lightbox]').lightBox();
      
      $('.commentTextArea').prettyComments();
      
      $('.commentTextArea').mousedown(function(){
        // hide default text
        if($(this).val()=="Szólj hozzá!")
        {
            $(this).val("");
        }
        // show avatar
        $(this).parent().parent().children('.new_avatar').show();
        // show send button
        $(this).parent().children('a').show();
        // enlarge textarea
        $(this).removeClass("slim");
        // set preety comments behaviour
        $(this).css('height','26px').prettyComments(); 
       });
       
      $('.commentTextArea').blur(function(){
            if(jQuery.trim($(this).val())=='')
            {
                // hide avatar
                $(this).parent().parent().children('.new_avatar').hide();
                // hide send button
                $(this).parent().children('a').hide();
                // small textarea
                $(this).css('height','14px');
                $(this).addClass("slim");
                $(this).val("Szólj hozzá!");
            }
        });
        
     // $('.postTextArea').prettyComments(); 
     // $('.slimpost').css('height','14px');
      $('.postTextArea').mousedown(function(){
        // hide default text
        if($(this).val()=="Írj saját bejegyzést Te is!")
        {
            $(this).val("");
        }
        // show radio button list
        $('.new_PostUserSelector').show();
        // show avatar
        $('.new_PostAvatar').show();
        // show send button
        if($('#upSelClose').css('display')=='none' && $('#upSelOpen').css('display')=='none')
        {
            $('#upSelClose').show();
        }
        // enlarge textarea
        $(this).removeClass("slimpost");
        
        $('.new_MainPostContainer').css('padding-bottom','0px');
        $(this).focus();
        $(this).css('height','56px').prettyComments(); 
       });
       
       // hide postarea
       $(document).click(function(e){
        if(!$('#pContent').hasClass('slimpost') && !$('#pContent').attr('disabled'))
        {
            if($(e.target).is('.new_MainPostContainer, .new_MainPostContainer *')) return;
            else{
                if(jQuery.trim($('.postTextArea').val())=='' && !$('#pContent').attr('disabled'))
                {
                    // hide radio button list
                     $('.new_PostUserSelector').hide();
                    // hide avatar
                    $('.new_PostAvatar').hide();
                    // hide send button
                    $('#upSelClose').hide();
                    $('#upSelOpen').hide();
                    // small textarea
                    $('.postTextArea').css('height','14px');
                    $('.postTextArea').addClass("slimpost");
                    $('.postTextArea').val("Írj saját bejegyzést Te is!");
                    $('.new_MainPostContainer').css('padding-bottom','10px');
                }
            
            
            }
        }
       });

       $('input:radio').click(function(){
            $('.new_PostAvatar img').hide();
            $('#av_' + $(this).val()).show();
        });
        
        $('.new_AddPicsLink a').click(function(){
            $('#upSelClose').hide();
            $('#upSelOpen').show();
        });
        
        $('.new_PicsCancel a').click(function(){
            $('.new_PicsSelectorForm input').replaceWith("<input type='file' name='datafile' />");
            $('.new_fileWarningText').empty();
            $('#upSelOpen').hide();
            $('#upSelClose').show();
        });
        
        $('#no').click(function() { 
            $.unblockUI(); 
            return false; 
        }); 
}

function showBandThread(bandid)
{
    currentBandId = bandid;
    $.ajax(
      {
        url: "ajax/GetBandThread.ashx",
        type: "POST",
        data: {
                bandid: bandid,
                page: 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        beforeSend: function (XMLHttpRequest) {
           $('#mband_' + bandid).append('<img width="10" height="10" border="0" alt="Betöltés" src="common/images/leftmenu_loader.gif" />');
        },
        success: function(jsonObj){
            $('#mband_' + bandid + ' img').remove();
            switch(jsonObj.Status)
             {
                case "Ok":showBandThreadCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showBandThreadCallback(jsonObj)
{
    $('#new_contentCenter').replaceWith(jsonObj.Data);
    if(jsonObj.Page == jsonObj.MaxPage)
    {
        $('#new_morePost').hide();
    }
    else
    {
        currentPostPage = parseInt(jsonObj.Page);
    }
    refresh();
}

function showMoreBandPost()
{
    $.ajax(
      {
        url: "ajax/GetBandThread.ashx",
        type: "POST",
        data: {
                bandid: currentBandId,
                page: currentPostPage + 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        success: function(jsonObj){
            switch(jsonObj.Status)
             {
                case "Ok":showMorePostCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showFestivalThread(festivalid)
{
    currentFestivalId = festivalid;
    $.ajax(
      {
        url: "ajax/GetFestivalThread.ashx",
        type: "POST",
        data: {
                festivalid: festivalid,
                page: 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        beforeSend: function (XMLHttpRequest) {
           $('#msite_' + festivalid).append('<img width="10" height="10" border="0" alt="Betöltés" src="common/images/leftmenu_loader.gif" />');
        },
        success: function(jsonObj){
            $('#msite_' + festivalid + ' img').remove();
            switch(jsonObj.Status)
             {
                case "Ok":showFestivalThreadCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showFestivalThreadCallback(jsonObj)
{
    $('#new_contentCenter').replaceWith(jsonObj.Data);
    if(jsonObj.Page == jsonObj.MaxPage)
    {
        $('#new_morePost').hide();
    }
    else
    {
        currentPostPage = parseInt(jsonObj.Page);
    }
    refresh();
}

function showMoreFestivalPost()
{
    $.ajax(
      {
        url: "ajax/GetFestivalThread.ashx",
        type: "POST",
        data: {
                festivalid: currentFestivalId,
                page: currentPostPage + 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        success: function(jsonObj){
            switch(jsonObj.Status)
             {
                case "Ok":showMorePostCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showMoreBandPostOnProfile(bandid)
{
    currentBandId = bandid;
    $.ajax(
      {
        url: "ajax/GetBandThreadOnProfile.ashx",
        type: "POST",
        data: {
                bandid: currentBandId,
                page: currentPostPage + 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        success: function(jsonObj){
          showMorePostCallback(jsonObj);
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showMoreSitePostOnProfile(siteid)
{
    currentSiteId = siteid;
    $.ajax(
      {
        url: "ajax/GetSiteThreadOnProfile.ashx",
        type: "POST",
        data: {
                siteid: currentSiteId,
                page: currentPostPage + 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        success: function(jsonObj){
          showMorePostCallback(jsonObj);
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showMoreFestivalPostOnProfile(festivalid)
{
    currentFestivalId = festivalid;
    $.ajax(
      {
        url: "ajax/GetFestivalThreadOnProfile.ashx",
        type: "POST",
        data: {
                festivalid: currentFestivalId,
                page: currentPostPage + 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        success: function(jsonObj){
          showMorePostCallback(jsonObj);
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showMoreUserPostOnProfile(userid)
{
    $.ajax(
      {
        url: "ajax/GetUserThreadOnProfile.ashx",
        type: "POST",
        data: {
                userid: userid,
                page: currentPostPage + 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        success: function(jsonObj){
          showMorePostCallback(jsonObj);
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showAllFavoriteBandThread()
{
    $.ajax(
      {
        url: "ajax/GetAllFavoriteBandThread.ashx",
        type: "POST",
        cache: false,
        data: {
                page: 1
              },
        dataType: 'json',
        timeout: 10000,
        beforeSend: function (XMLHttpRequest) {
           $('#mm_favBands img').show();
        },
        success: function(jsonObj){
          $('#mm_favBands img').hide();
          
           switch(jsonObj.Status)
             {
                case "Ok":showAllFavoriteBandThreadCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showAllFavoriteBandThreadCallback(jsonObj)
{
    $('#new_contentCenter').replaceWith(jsonObj.Data);
    refresh();
}

function showMoreAllFavoriteBand()
{
    $.ajax(
      {
        url: "ajax/GetAllFavoriteBandThread.ashx",
        type: "POST",
        cache: false,
        data: {
                page: currentPostPage + 1
              },
        dataType: 'json',
        timeout: 10000, beforeSend: function (XMLHttpRequest) {
           $('.new_pagerBtn').html('<span><img width="14" height="14" border="0" alt="Betöltés" src="common/images/btn_large_loader.gif" /></span>');
        },
        success: function(jsonObj){
          $('.new_pagerBtn').html('<span>' + $('.new_pagerBtn').attr('title') + '</span>');
             switch(jsonObj.Status)
             {
                case "Ok":showMorePostCallback(jsonObj);;
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showAllFavoriteSiteThread()
{
    $.ajax(
      {
        url: "ajax/GetAllFavoriteSiteThread.ashx",
        type: "POST",
        cache: false,
        data: {
                page: 1
              },
        dataType: 'json',
        timeout: 10000,
        beforeSend: function (XMLHttpRequest) {
           $('#mm_favSites img').show();
        },
        success: function(jsonObj){
          $('#mm_favSites img').hide();
          
           switch(jsonObj.Status)
             {
                case "Ok":showAllFavoriteSiteThreadCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showAllFavoriteSiteThreadCallback(jsonObj)
{
    $('#new_contentCenter').replaceWith(jsonObj.Data);
    refresh();
}

function showMoreAllFavoriteSite()
{
    $.ajax(
      {
        url: "ajax/GetAllFavoriteSiteThread.ashx",
        type: "POST",
        cache: false,
        data: {
                page: currentPostPage + 1
              },
        dataType: 'json',
        timeout: 10000, beforeSend: function (XMLHttpRequest) {
           $('.new_pagerBtn').html('<span><img width="14" height="14" border="0" alt="Betöltés" src="common/images/btn_large_loader.gif" /></span>');
        },
        success: function(jsonObj){
          $('.new_pagerBtn').html('<span>' + $('.new_pagerBtn').attr('title') + '</span>');
             switch(jsonObj.Status)
             {
                case "Ok":showMorePostCallback(jsonObj);;
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showSiteThread(siteid)
{
    currentSiteId = siteid;
    $.ajax(
      {
        url: "ajax/GetSiteThread.ashx",
        type: "POST",
        data: {
                siteid: siteid,
                page: 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        beforeSend: function (XMLHttpRequest) {
           $('#msite_' + siteid).append('<img width="10" height="10" border="0" alt="Betöltés" src="common/images/leftmenu_loader.gif" />');
        },
        success: function(jsonObj){
            $('#msite_' + siteid + ' img').remove();
            switch(jsonObj.Status)
             {
                case "Ok":showSiteThreadCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showSiteThreadCallback(jsonObj)
{
    $('#new_contentCenter').replaceWith(jsonObj.Data);
    if(jsonObj.Page == jsonObj.MaxPage)
    {
        $('#new_morePost').hide();
    }
    else
    {
        currentPostPage = parseInt(jsonObj.Page);
    }
    refresh();
}

function showMoreSitePost()
{
    $.ajax(
      {
        url: "ajax/GetSiteThread.ashx",
        type: "POST",
        data: {
                siteid: currentSiteId,
                page: currentPostPage + 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        success: function(jsonObj){
            switch(jsonObj.Status)
             {
                case "Ok":showMorePostCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showAllFavoriteFestivalThread()
{
    $.ajax(
      {
        url: "ajax/GetAllFavoriteFestivalThread.ashx",
        type: "POST",
        cache: false,
        data: {
                page: 1
              },
        dataType: 'json',
        timeout: 10000,
        beforeSend: function (XMLHttpRequest) {
           $('#mm_favFestivals img').show();
        },
        success: function(jsonObj){
          $('#mm_favFestivals img').hide();
          
           switch(jsonObj.Status)
             {
                case "Ok":showAllFavoriteFestivalThreadCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showAllFavoriteFestivalThreadCallback(jsonObj)
{
    $('#new_contentCenter').replaceWith(jsonObj.Data);
    refresh();
}

function showMoreAllFavoriteFestival()
{
    $.ajax(
      {
        url: "ajax/GetAllFavoriteFestivalThread.ashx",
        type: "POST",
        cache: false,
        data: {
                page: currentPostPage + 1
              },
        dataType: 'json',
        timeout: 10000, beforeSend: function (XMLHttpRequest) {
           $('.new_pagerBtn').html('<span><img width="14" height="14" border="0" alt="Betöltés" src="common/images/btn_large_loader.gif" /></span>');
        },
        success: function(jsonObj){
          $('.new_pagerBtn').html('<span>' + $('.new_pagerBtn').attr('title') + '</span>');
             switch(jsonObj.Status)
             {
                case "Ok":showMorePostCallback(jsonObj);;
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showSiteThread(siteid)
{
    currentSiteId = siteid;
    $.ajax(
      {
        url: "ajax/GetSiteThread.ashx",
        type: "POST",
        data: {
                siteid: siteid,
                page: 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        beforeSend: function (XMLHttpRequest) {
           $('#msite_' + siteid).append('<img width="10" height="10" border="0" alt="Betöltés" src="common/images/leftmenu_loader.gif" />');
        },
        success: function(jsonObj){
            $('#msite_' + siteid + ' img').remove();
            switch(jsonObj.Status)
             {
                case "Ok":showSiteThreadCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showSiteThreadCallback(jsonObj)
{
    $('#new_contentCenter').replaceWith(jsonObj.Data);
    if(jsonObj.Page == jsonObj.MaxPage)
    {
        $('#new_morePost').hide();
    }
    else
    {
        currentPostPage = parseInt(jsonObj.Page);
    }
    refresh();
}

function showMoreSitePost()
{
    $.ajax(
      {
        url: "ajax/GetSiteThread.ashx",
        type: "POST",
        data: {
                siteid: currentSiteId,
                page: currentPostPage + 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        success: function(jsonObj){
            switch(jsonObj.Status)
             {
                case "Ok":showMorePostCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showMoreBandPost()
{
    $.ajax(
      {
        url: "ajax/GetBandThread.ashx",
        type: "POST",
        data: {
                bandid: currentBandId,
                page: currentPostPage + 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        success: function(jsonObj){
            switch(jsonObj.Status)
             {
                case "Ok":showMorePostCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showMorePostCallback(jsonObj)
{
    if(jsonObj.Page == jsonObj.MaxPage)
    {
        $('#new_morePosts').append(jsonObj.Data);
        $('#new_morePost').hide();
    }
    else
    {
        $('#new_morePosts').append(jsonObj.Data);
        currentPostPage = parseInt(jsonObj.Page);
    }
    refresh();
}

function showFriendsThread()
{
    $.ajax(
      {
        url: "ajax/GetFriendsThread.ashx",
        type: "POST",
        cache: false,
        data: {
                page: 1
              },
        dataType: 'json',
        timeout: 10000,
        beforeSend: function (XMLHttpRequest) {
           $('#mm_friends').append('<img width="10" height="10" border="0" alt="Betöltés" src="common/images/leftmenu_loader.gif" />');
        },
        success: function(jsonObj){
          $('#mm_friends img').remove();
          switch(jsonObj.Status)
          {
            case "Ok":showFriendsThreadCallback(jsonObj);
                      break;
            case "SessExp":goToLoginPage();
                      break;
            default: break;
          }
        },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}


function showFriendsThreadCallback(jsonObj)
{
    $('#new_contentCenter').replaceWith(jsonObj.Data);
    refresh();
}

function showMoreFriendPost()
{
    $.ajax(
      {
        url: "ajax/GetFriendsThread.ashx",
        type: "POST",
        data: {
                  page: currentPostPage + 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        beforeSend: function (XMLHttpRequest) {
           $('.new_pagerBtn').html('<span><img width="14" height="14" border="0" alt="Betöltés" src="common/images/btn_large_loader.gif" /></span>');
        },
        success: function(jsonObj){
          $('.new_pagerBtn').html('<span>' + $('.new_pagerBtn').attr('title') + '</span>');
          
              switch(jsonObj.Status)
              {
                case "Ok":showMorePostCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showAllThread()
{
  
    $.ajax(
      {
        url: "ajax/GetAllThread.ashx",
        type: "POST",
        data: {
                page: 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        beforeSend: function (XMLHttpRequest) {
           $('#mm_all').append('<img width="10" height="10" border="0" alt="Betöltés" src="common/images/leftmenu_loader.gif" />');
        },
        success: function(jsonObj){
            $('#mm_all img').remove();
             switch(jsonObj.Status)
              {
                case "Ok":showAllThreadCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showAllThreadCallback(jsonObj)
{
    
    $('#new_contentCenter').replaceWith(jsonObj.Data);
    if(jsonObj.Page == jsonObj.MaxPage)
    {
        $('#new_morePost').hide();
    }
    else
    {
        currentPostPage = parseInt(jsonObj.Page);
    }
    refresh();
}


function showMoreAllThread()
{
  
    $.ajax(
      {
        url: "ajax/GetAllThread.ashx",
        type: "POST",
        data: {
                page: currentPostPage + 1
              },
        cache: false,
        dataType: 'json',
        timeout: 10000,
        beforeSend: function (XMLHttpRequest) {
           $('.new_pagerBtn').html('<span><img width="14" height="14" border="0" alt="Betöltés" src="common/images/btn_large_loader.gif" /></span>');
        },
        success: function(jsonObj){
          $('.new_pagerBtn').html('<span>' + $('.new_pagerBtn').attr('title') + '</span>');
          
             switch(jsonObj.Status)
              {
                case "Ok":showMorePostCallback(jsonObj);
                          break;
                case "SessExp":goToLoginPage();
                          break;
                default: break;
              }
          },
        error:function(jsonObj){
            //alert("hiba");
          }
      }
    );
}

function showComments(postid)
{
    $.ajax(
          {
            url: "ajax/GetComments.ashx",
            type: "POST",
            data: {
                    postid: postid
                  },
            cache: false,
            dataType: 'json',
            timeout: 10000,
            beforeSend: function (XMLHttpRequest) {
                $('#hd_' + postid).append('<img width="10" height="10" border="0" alt="Betöltés" src="common/images/comment_loader.gif" style="padding-left:5px"/>');
            },
            success: function(jsonObj){
              $('#hd_' + postid + ' img').remove();
                  switch(jsonObj.Status)
                  {
                    case "Ok":showCommentsCallback(jsonObj);
                              break;
                    case "SessExp":goToLoginPage();
                              break;
                    default: break;
                  }
              },
            error:function(jsonObj){
                //alert("hiba");
              }
          }
        );
}

function showRawComments(postid)
{
    $.ajax(
          {
            url: "ajax/GetRawComments.ashx",
            type: "POST",
            data: {
                    postid: postid
                  },
            cache: false,
            dataType: 'json',
            timeout: 10000,
            beforeSend: function (XMLHttpRequest) {
                $('#hd_' + postid).append('<img width="10" height="10" border="0" alt="Betöltés" src="common/images/comment_loader.gif" style="padding-left:5px"/>');
            },
            success: function(jsonObj){
              $('#hd_' + postid + ' img').remove();
                  switch(jsonObj.Status)
                  {
                    case "Ok":showCommentsCallback(jsonObj);
                              break;
                    case "SessExp":goToLoginPage();
                              break;
                    default: break;
                  }
              },
            error:function(jsonObj){
                //alert("hiba");
              }
          }
        );
}

function showCommentsCallback(jsonObj)
{
    $('#new_postComments' + jsonObj.PostId).replaceWith(jsonObj.Data);
    refresh();
}

function showFullPost(postid)
{
    
    $('#p' + postid).hide();
    $('#pfull' + postid).show();
    $('#more' + postid).hide();
}

function addComment(postid,lastvisibleid, showall)
{
    $('#pct' + postid).attr('disabled','disabled')
    $.ajax(
          {
            url: "ajax/AddComment.ashx",
            type: "POST",
            data: {
                    postid: postid,
                    comment: $('#pct' + postid).val(),
                    lastvisibleid: lastvisibleid,
                    showall: showall
                  },
            cache: false,
            dataType: 'json',
            timeout: 10000,
            beforeSend: function (XMLHttpRequest) {
               $('#cb_' + postid).html('<span><img width="10" height="10" border="0" alt="Betöltés" src="common/images/btn_medium_loader.gif" /></span>');
               },
			success: function(jsonObj){
			    $('#cb_' + postid).html('<span>' + $('#cb_' + postid).attr('title') + '</span>');
                  switch(jsonObj.Status)
                  {
                    case "Ok":showCommentsCallback(jsonObj);
                              break;
                    case "LongText":
                            $('#pct' + postid).removeAttr('disabled');
                            showLengthBox(jsonObj.Data, 160);
                              break;
                    case "SessExp":goToLoginPage();
                              break;
                    default: break;
                  }
              },
            error:function(jsonObj){
                //alert("hiba");
               }
          }
        );

}

function removeComment(pid, cid, lastvisibleid, showall, profileview)
{
if (confirm("Biztos, hogy törölni szeretnéd a kommentet? A törlés végleges és NEM visszavonható!")) {
    $.ajax(
          {
            url: "ajax/RemoveComment.ashx",
            type: "POST",
            data: {
                    postid: pid,
                    commentid: cid,
                    lastvisibleid:lastvisibleid,
                    showall: showall,
                    profileview: profileview
                  },
            cache: false,
            dataType: 'json',
            timeout: 10000,
             beforeSend: function (XMLHttpRequest) {
               $('#c_' + cid + ' .new_commentItem').append('<img width="10" height="10" border="0" alt="Betöltés" src="common/images/comment_loader.gif" style="padding-left:5px"; />');
               },
			success: function(jsonObj){
			    $('#c_' + cid + ' .new_commentItem img').remove();;
                 switch(jsonObj.Status)
                  {
                    case "Ok":showCommentsCallback(jsonObj);
                              break;
                    case "SessExp":goToLoginPage();
                              break;
                    default: break;
                  }
              },
            error:function(jsonObj){
                //alert("hiba");
               }
          }
        );
    }
}

function addSimplePost(objecttype,bandid,caller,picid)
{
    if(checkPost($('#pContent').val()) || picid != 0)
    {
        $('#pContent').attr('disabled','disabled');
		$.ajax(
          {
            url: "ajax/AddPost.ashx",
            type: "POST",
            data: {
                    objecttype: objecttype,
                    bandid: bandid,
                    caller: caller,
                    picid: picid,
                    content: $('#pContent').val() == "Írj saját bejegyzést Te is!" ? "" : $('#pContent').val()
                  },
            cache: false,
            dataType: 'json',
            timeout: 10000,
            beforeSend: function (XMLHttpRequest) {
               $('.new_postBtnSend').html('<span><img width="10" height="10" border="0" alt="Betöltés" src="common/images/btn_medium_loader.gif" /></span>');
               },
			success: function(jsonObj){
			    $('.new_postBtnSend').html('<span>' + $('.new_postBtnSend').attr('title') + '</span>');
			    $('#pContent').removeAttr('disabled');
			    $('.new_PicsSelectorForm input').removeAttr('disabled');
                switch(jsonObj.Status)
                  {
                    case "Ok":showAllThreadCallback(jsonObj);
                              break;
                    case "LongText":
                              showLengthBox(jsonObj.Data, 5000);
                              break;
                    case "SessExp":goToLoginPage();
                              break;
                    default: break;
                  }
              },
            error:function(jsonObj){
                //alert("hiba");
               }
          }
        );
    }
}

function addSimplePostWithPic(objecttype,bandid,caller)
{
    $('#pContent').attr('disabled','disabled');
    
    $('#pForm').ajaxSubmit({
                url:'fileupload/FileUploader.ashx',
                beforeSend: function (XMLHttpRequest) {
                   $('.new_postBtnSend').html('<span><img width="10" height="10" border="0" alt="Betöltés" src="common/images/btn_medium_loader.gif" /></span>');
                   },
                success: function(jsonObj){
			        switch(jsonObj.Status)
                    {
                        case "OK": addSimplePost(objecttype,bandid,caller,jsonObj.Data)
                                   $('.new_PicsSelectorForm input').attr('disabled','disabled');
                                   break;
                        case "EXT": 
                        case "SIZE": $('.new_fileWarningText').html(jsonObj.Data);
                                     $('.new_postBtnSend').html('<span>' + $('.new_postBtnSend').attr('title') + '</span>');
                                     $('#pContent').removeAttr('disabled');
                                     break;
                        default: break;
                    }
                },
				type: "POST",
                cache: false,
                dataType: 'json',
                timeout: 10000
			}
		);
		
	return false;        
}

function addPost(caller, picid)
{
    if(checkPost($('#pContent').val()) || picid != 0)
    {
        $('#pContent').attr('disabled','disabled');
        tmp = $("input[name='entity']:checked").val();
        
        id = tmp.substr(0,tmp.indexOf("_"));
        objecttype = tmp.substr(tmp.indexOf("_")+1);
        
        $.ajax(
              {
                url: "ajax/AddPost.ashx",
                type: "POST",
                data: {
                        objecttype: objecttype,
                        bandid: id,
                        caller: caller,
                        picid: picid,
                        content: $('#pContent').val() == "Írj saját bejegyzést Te is!" ? "" : $('#pContent').val()
                      },
                cache: false,
                dataType: 'json',
                timeout: 10000,
                beforeSend: function (XMLHttpRequest) {
                   $('.new_postBtnSend').html('<span><img width="10" height="10" border="0" alt="Betöltés" src="common/images/btn_medium_loader.gif" /></span>');
                   },
                success: function(jsonObj){
                  $('.new_postBtnSend').html('<span>' + $('.new_postBtnSend').attr('title') + '</span>');
                  $('#pContent').removeAttr('disabled');
                  $('.new_PicsSelectorForm input').removeAttr('disabled');
                  switch(jsonObj.Status)
                  {
                    case "Ok":showAllThreadCallback(jsonObj);
                              break;
                    case "LongText":
                            showLengthBox(jsonObj.Data, 5000);
                    case "SessExp":goToLoginPage();
                              break;
                    default: break;
                  }
                },
                error:function(jsonObj){
                    //alert("hiba");
                   }
              }
            );
     }
}

function addPostWithPic(caller)
{
    $('#pContent').attr('disabled','disabled');
    
    $('.new_fileWarningText').html('');
    $('#pForm').ajaxSubmit({
            url:'fileupload/FileUploader.ashx',
            beforeSend: function (XMLHttpRequest) {
               $('.new_postBtnSend').html('<span><img width="10" height="10" border="0" alt="Betöltés" src="common/images/btn_medium_loader.gif" /></span>');
               },
			success: function(jsonObj){
			    switch(jsonObj.Status)
                {
                    case "OK": addPost(caller,jsonObj.Data);
                               $('.new_PicsSelectorForm input').attr('disabled','disabled');
                               break;
                    case "EXT": 
                    case "SIZE": $('.new_fileWarningText').html(jsonObj.Data);
                                 $('.new_postBtnSend').html('<span>' + $('.new_postBtnSend').attr('title') + '</span>');
                                 $('#pContent').removeAttr('disabled');
                                 break;
                    default: break;
                }
            },
			type: "POST",
            cache: false,
            dataType: 'json',
            timeout: 10000
		}
	);
		
	return false;  
}

function checkPost(pContent)
{
    if(jQuery.trim(pContent)=='')
    {
        return false;
    }
    return true;
}

function removePost(postId, entityId, objectType)
{
    if (confirm("Biztos, hogy törölni szeretnéd a bejegyzést? A törlés végleges és NEM visszavonható!")) 
    {
    $.ajax(
          {
            url: "ajax/RemoveBlogPost.ashx",
            type: "POST",
            data: {
                    postid: postId,
                    entityId: entityId,
                    objectType:objectType
                  },
            cache: false,
            dataType: 'json',
            timeout: 10000,
            beforeSend: function (XMLHttpRequest){
               $('#pd_' + postId).html('<span><img width="10" height="10" border="0" alt="Betöltés" src="common/images/comment_loader.gif" style="padding-top:1px"; /></span>');
            },
			success: function(jsonObj){
			    $('#pd_' + postId).html('<span>' + $('#pd_' + postId).attr('title') + '</span>');
                switch(jsonObj.Status)
                  {
                    case "Ok":showPostOnProfileCallback(jsonObj);
                              break;
                    case "SessExp":goToLoginPage();
                              break;
                    default: break;
                  }
              },
            error:function(jsonObj){
                //alert("hiba");
            }
          }
        );
    }
}

function showPostOnProfileCallback(jsonObj)
{
    $('#new_contentCenter').replaceWith(jsonObj.Data);
    refresh();
}

function goToLoginPage()
{
    //window.location.href = '/BandlandPhase0/SignIn.aspx';
    window.location.href = '/SignIn.aspx';
}

function showLengthBox(currLen, defLen)
{ 
    $('#currLen').html(currLen + ' karakter');
    $('#defLen').html(defLen);
    $.blockUI({ message: $('#question'), css: { width: '350px' } }); 
}