﻿var pageTracker;

/* Simplifies onload, you will no longer have to add an onload event call just call addLoadEvent */
function addLoadEvent(func, arg) {
    if (!arg) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
                oldonload();
                func();
            }
        }
    }
    else {/*if the onload event has an argument/parameter cater for that*/
        if (arg) {
            oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func(arg);
            }
            window.onload = function() {
                oldonload();
                func(arg);
            }
        }
    }
}

function trackGAPageview(url) {

    if (typeof (pageTracker) == 'object') {
        pageTracker._trackPageview(url);
    }

}

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://secure." : "http://static.");
    /*Writes in the script to the document head*/
    var gaScript = document.createElement("script");
    gaScript.setAttribute("src", gaJsHost + "recon.com/js/ga.js");
    gaScript.setAttribute("type", "text/javascript");
    var domHead = document.getElementsByTagName("head")[0]
    domHead.appendChild(gaScript);
}
loadGAScript();

/*Calls the analytics function*/
function callGA() {
    if (typeof (_gat) == 'object') {
        pageTracker = _gat._getTracker("UA-6285190-1");
        pageTracker._setDomainName("recon.com");
        pageTracker._initData();
        pageTracker._trackPageview();
    }
}

addLoadEvent(callGA);