// Function to include jQuery
function include(filename)
{
    var head = document.getElementsByTagName('head')[0];
   
    script = document.createElement('script');
    script.src = filename;
    script.type = 'text/javascript';
   
    head.appendChild(script);
}

if (window.jQuery == undefined)
{
	include(('https:' == document.location.protocol ? 'https://' : 'http://') + 'ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
}

// Google Analytics tracking snippet
var _gaq = _gaq || [];
_gaq.push(['ct._setAccount', 'UA-17653566-4']);
_gaq.push(['ct._trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

// Phone tracking
function getParameterByName(name)
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

function setCookie(key, value)
{
    var expires = new Date();
    expires.setTime(expires.getTime() + 31536000000); //1 year
    document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
}

function getCookie(key)
{
    var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
    return keyValue ? keyValue[2] : null;
}

phone = null;
phone_query = getParameterByName('utm_phone');
phone_cookie = getCookie('utm_phone');
// Found phone number
if (phone_query != "" || phone_cookie)
{
    if (phone_query != "")
    {
        setCookie('utm_phone', phone_query);
        phone = phone_query;
    }
    else if (phone_cookie)
    {
        phone = phone_cookie;
    }
}

