﻿$(function() 
{
    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    //  TOGGLE ADD TAGS FORM
    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    $('a.AddTags').click(function() 
    {
        var isAuth = $('#isAuth').val();
        var linkId = $(this).attr("id");   
        var id = linkId.substr(4);
          
        if(isAuth == 'True')
        {
            $('#LinkTags' + id).slideToggle(500);
            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 = $("#fmLink").serialize();
                data = newdata; 
            }
            
              //alert(data);
            
            
            $.ajax
            ({
                type: "POST",
                url: "AddTags.publisha",
                data: data,
                async: false,
            
                success: function(msg)
                {  
                  alert('Your tag was added successfully!');
                  $('#LinkTags' + 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.Thank').click(function() 
    {
        var isAuth = 'True';
        var thankId = $(this).attr("id");   
        var id = thankId.substr(1);
        
        if(isAuth == 'True')
        {
            var data = $("#fmThank"  + id).serialize(); 

            $.ajax
            ({
                type: "POST",
                url: "ThankMentor.publisha",
                data: data,
                async: false,
                success: function(msg)
                {  
                    alert('Your thank you was deposited in the mentors "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 the mentor!');
        }    
    });
    
});


