﻿
function loadGAScript() {
    /*Check browser for Dom compatibility*/
    if (!document.getElementsByTagName) return false;
    /*Determines whether the page is using a secure or unsecure protocol*/
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    /*Writes in the script to the document head*/
    var gaScript = document.createElement("script");
    gaScript.setAttribute("src", gaJsHost + "google-analytics.com/ga.js");
    gaScript.setAttribute("type", "text/javascript");
    var domHead = document.getElementsByTagName("head")[0]
    domHead.appendChild(gaScript);
}
loadGAScript();


/*Calls the analytics function*/
function callGA() {
    try {
        if (typeof _gat!="undefined") {
            pageTracker = _gat._getTracker(GoogleAnalyticsID);
            pageTracker._initData();
            pageTracker._trackPageview();
        }
    } catch (err) { }
}

function trackPage(pagePath) {
    try {
        if (typeof pageTracker != "undefined")
            pageTracker._trackPageview(pagePath);
    } catch (err) { }
}
function trackEvent(category, action, optional_label, optional_value) {
    try {
        if (typeof pageTracker != "undefined")
            pageTracker._trackEvent(category, action, optional_label, optional_value);
    } catch (err) { }
}

addLoadEvent(callGA);
