﻿/*
New Main file for JQuery functions
*/

// linkTracking - Tracking various link clicks through Google Analytics
// Requires jQuery, Google analytics
jQuery(document).ready(function ()
{

    /*
    Track External Link Clicks 
 
    Add the attribute rel="external" to any external link
    on your site, and this function will track the click. 
 
    Click reported as: /custom-tracking/outgoing-link/{url of link clicked}
    */

    jQuery('a[rel="external"]').click(function ()
    {
        customLink = '/custom-tracking/outgoing-link/' + jQuery(this).attr('href');
        pageTracker._trackPageview(customLink);
    });

    /* =================================================================== */

    /*
    Track Email Link Clicks
 
    This simply tracks the click on any link that uses
    the "mailto:email@domain.com" method.
 
    Click reported as: /custom-tracking/email-link/mailto:{email address clicked}
    */

    jQuery('a[href*=mailto]').click(function ()
    {
        customLink = '/custom-tracking/email-link/' + jQuery(this).attr('href');
        pageTracker._trackPageview(customLink);
    });

    /* =================================================================== */

    /*
    Track PDF/XLS/XLSX/CSV/DOC/DOCX File Downloads
 
    This adds the tracking code to any link with a .pdf extension, allowing
    you to track file downloads
 
    Click reported as: /custom-tracking/pdf-link/{url of pdf clicked}
    */

    jQuery('a[href*=\\.pdf]').click(function ()
    {
        customLink = '/custom-tracking/pdf-link/' + jQuery(this).attr('href');
        pageTracker._trackPageview(customLink);
    });
    jQuery('a[href*=\\.xls]').click(function ()
    {
        customLink = '/custom-tracking/xls-link/' + jQuery(this).attr('href');
        pageTracker._trackPageview(customLink);
    });
    jQuery('a[href*=\\.xlsx]').click(function ()
    {
        customLink = '/custom-tracking/xlsx-link/' + jQuery(this).attr('href');
        pageTracker._trackPageview(customLink);
    });
    jQuery('a[href*=\\.csv]').click(function ()
    {
        customLink = '/custom-tracking/csv-link/' + jQuery(this).attr('href');
        pageTracker._trackPageview(customLink);
    });
    jQuery('a[href*=\\.doc]').click(function ()
    {
        customLink = '/custom-tracking/doc-link/' + jQuery(this).attr('href');
        pageTracker._trackPageview(customLink);
    });
    jQuery('a[href*=\\.docx]').click(function ()
    {
        customLink = '/custom-tracking/docx-link/' + jQuery(this).attr('href');
        pageTracker._trackPageview(customLink);
    });

    /* =================================================================== */

    /*
    Track Custom Page Elements
 
    If you want to track anything specific, this will allow you
    to do so anywhere you want.
 
    To use this:
    - add a class of "customTracker" to your link.
    - add a title attribute to your link to be used in your reports
 
    For example: <a class="customTracker" title="Log in to your account" href="{some url">Click here to log in</a>
    Would report as /custom-tracking/page-element/Log in to your account
    */

    jQuery('a.customTracker').click(function ()
    {
        customLink = '/custom-tracking/page-element/' + jQuery(this).attr('title');
        pageTracker._trackPageview(customLink);
    });

    /* =================================================================== */

    (function ($)
    {
        $('.hover').each(function ()
        {
            $(this).mouseover(function (event)
            {
                var tPosX = event.pageX + 15;
                var tPosY = event.pageY;
                $(this).next('.popup').css({ 'position': 'absolute', 'top': tPosY, 'left': tPosX, 'z-index': '999999999' }).fadeIn();
            }).mouseout(function ()
            {
                $(this).next('.popup').fadeOut();
            });
        });
    })(jQuery);

});


//====================================================================================================
//
// Login functions.
//
//====================================================================================================
// Shows the ajax loader image when the login button is clicked.
function showLoginLoading()
{
	if (jQuery('input[id*="UsernameTextBox"]').val() != '' && jQuery('input[id*="PasswordTextBox"]').val() != '')
	{
		jQuery('.loginLoadingContainer').show();
		jQuery('.loginFailureContainer').hide();
	}
}

// Resets the loging fields when the cancel link button is clicked.
function cancelLogin()
{
	jQuery('input[id*="UsernameTextBox"]').val('');
	jQuery('input[id*="PasswordTextBox"]').val('');
	jQuery('.loginLoadingContainer').hide();
	jQuery('.loginFailureContainer').hide();
	jQuery('input[id*="PersistCookieCheckBox"]').removeAttr("checked");
}
