﻿// See http://stackoverflow.com/questions/18082/validate-numbers-in-javascript-isnumeric/1830844#1830844
function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

if (typeof console == "undefined") console = { log: function() {} }; 

function TrackPageView(pageURL)
{
    if ((/^true$/i).test($('div#useGA:first').text()))
    {
        if (!isNumber($('meta[name="Machine"]').attr('content')))
            console.log("Tracking " + pageURL);
        _gaq.push(['_trackPageview', pageURL]);
    }
}

function TrackEvent(category, action, label, value)
{
    if ((/^true$/i).test($('div#useGA:first').text()))
    {
        if (isNumber(value) && parseInt(value) == value)
        {
            if (!isNumber($('meta[name="Machine"]').attr('content')))
                console.log("Tracking event " + category + " " + action + " " + label + " " + value);
            _gaq.push(['_trackEvent', category, action, label, value]);
        }
        else
        {
            _gaq.push(['_trackEvent', category, action, label]);
        }
    }
}
