﻿

$(function() 
{
    ////////////////////////////
    $('#edit_description').keyup(function(){
        //$('#edit_description').wordCount({size: '4000', counter:'charcounter' });
        limitChars('edit_description', 1000, 'charcounter');
    });
    $('#add_description').keyup(function(){
        //$('#edit_description').wordCount({size: '4000', counter:'charcounter' });
        limitChars('add_description', 1000, 'charcounter');
    });
    ////////////////////////////
    var auth = $("#userId").val();
     //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    //  TOGGLE ADD TAGS FORM
    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
   $('a.AddTags').click(function()
    {
       if(auth != "")
       {
            var id = $(this).attr('id');  
            var tagId = id.substr(4);
            $('#TagForm' + tagId).slideToggle('slow');
            return false;
       }
       else
       {
            alert('You have to be logged in to add tags');
       }
    });
    
    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    //  ADD THE TAG ENTERED  - REPLY WITH SUCCESS/FAIL MESSAGE!
    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    $('input.AddLinkTag').click(function()
    {   
        gid = $(this).attr("id");
        id = gid.substr(4);
        var tags = $('#tags' + id).val();
        
        if(tags != "")
        {
            var data = $("#fmLinkTag"  + id).serialize();
            
            if (data == null || data =="")
            {
                var newdata = $("#frmBook").serialize();
                data = newdata; 
            }
            
            $.ajax
            ({
                type: "POST",
                url: "AddTags.publisha",
                data: data,
                async: false,
            
                success: function(msg)
                {  
                  alert('Your tag was added successfully ');
                  $('#TagForm' + id).slideToggle('slow');    
                },
                error: function(msg)
                {
                    alert('Oops - your tag was either blocked or a duplicate!');
                }
            });
        }
        else
        {
            alert('Please enter the tag you wish to add!');
        }        
        return false;
    });
    
    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    //  THANK MENTOR - INCREASE MENTOR THANK YOU BANK
    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    $('a.lnkThankU').click(function() 
    {
        var isAuth = 'True';
        if(isAuth == 'True')
        {
            var fullId = $(this).attr("id"); 
            var id = fullId.substr(6);
            var data = $("#fmThank"  + id).serialize(); 
            
            $.ajax
            ({
                type: "POST",
                url: "ThankMentor.publisha",
                data: data,
                async: false,
                success: function(msg)
                {  
                    alert('Your thank you has been added to the mentor \"thank you bank\"');
                },
                error: function(msg)
                {
                   alert('Ooops! Your thank you was not recorded! Please try again!');
                }
            });
        }
        else
        {
            alert("You have to be logged in to thank a mentor.");
        }  
        return false;  
    });
});



function limitChars(textid, limit, infodiv)
{
    var text = $('#'+textid).val();
    var textlength = text.length;
    if(textlength > limit)
    {
        $('#' + infodiv).html('all '+limit+' characters used');
        $('#'+textid).val(text.substr(0,limit));/// <reference path="spell.js" />
        return false;
    }
    else
    {
        $('#' + infodiv).html((limit - textlength) +' characters left.');
        return true;
    }
}
