function getQuerystring(key, default_)
{

  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

/* Google Analytics Code */
var googleDomain = document.referrer;
var _gaq = _gaq || [];

/* Synth Rollup 1 Category */
if (window.location.hostname == "www.foundationcenter.org" || window.location.hostname == "associates.foundationcenter.org" || window.location.hostname == "ccnet.foundationcenter.org" || window.location.hostname == "youth.foundationcenter.org" || window.location.hostname == "collaboration.foundationcenter.org" || window.location.hostname == "www.washfunders.org" || window.location.hostname == "washfunders.org" || window.location.hostname == "gtionline.foundationcenter.org" || window.location.hostname == "cgonline.foundationcenter.org" || window.location.hostname == "www.fdncenter.org" || window.location.hostname == "fdncenter.org" || window.location.hostname == "foundationcenter.org")
{ 
	_gaq.push(['b._setAccount', 'UA-27560938-7']); 
}

/* Synth Rollup 2 Category */
if (window.location.hostname == "glasspockets.org" || window.location.hostname == "www.glasspockets.org")
{ 
	_gaq.push(['b._setAccount', 'UA-27560938-2']); 
}

/* Synth Rollup 3 Category */
if (window.location.hostname == "grantcraft.org" || window.location.hostname == "www.grantcraft.org")
{ 
	_gaq.push(['b._setAccount', 'UA-27560938-3']); 
}

/* Synth Rollup 4 Category */
if (window.location.hostname == "grantspace.org" || window.location.hostname == "www.grantspace.org")
{ 
	_gaq.push(['b._setAccount', 'UA-27560938-4']); 
}

/* Logic For Each Hostname */
var name_value = getQuerystring('foundationname');
var state_value = getQuerystring('foundationstate');
var zip_value = getQuerystring('foundationzip');

if (window.location.hostname == "foundationcenter.org" || window.location.hostname == "www.foundationcenter.org") 
{ 
	_gaq.push(['_trackEvent', 'FoundationFinders', 'Name', 'name_value']); 
	_gaq.push(['b._trackEvent', 'FoundationFinders', 'State', 'state_value']); 
	_gaq.push(['c._trackEvent', 'FoundationFinders', 'Name', 'name_value']);
	_gaq.push(['_trackEvent', 'FoundationFinders', 'State', 'state_value']); 
	_gaq.push(['b._trackEvent', 'FoundationFinders', 'State', 'state_value']); 
	_gaq.push(['c._trackEvent', 'FoundationFinders', 'Name', 'name_value']);
	_gaq.push(['_trackEvent', 'FoundationFinders', 'Zip', 'zip_value']); 
	_gaq.push(['b._trackEvent', 'FoundationFinders', 'State', 'state_value']); 
	_gaq.push(['c._trackEvent', 'FoundationFinders', 'Name', 'name_value']);

}

if (window.location.hostname == "grantspace.org" || window.location.hostname == "www.grantspace.org") 
{
	if (location.href.indexOf("/Find-Us") > -1) {
		_gaq.push(['_trackEvent', 'Find-Us', 'Zip', 'zip_value']); 
		_gaq.push(['b._trackEvent', 'Find-Us', 'Zip', 'zip_value']);  
		_gaq.push(['c._trackEvent', 'Find-Us', 'Zip', 'zip_value']); 

        }
	else if (location.href.indexOf("/Ask-Us/Ask-Us-By-E-mail") > -1) {
		_gaq.push(['_trackEvent', 'Contact-Us', 'Email', 'Submitted']); 
		_gaq.push(['b._trackEvent', 'Contact-Us', 'Email', 'Submitted']); 
		_gaq.push(['c._trackEvent', 'Contact-Us', 'Email', 'Submitted']);

        }
	else if (location.href.indexOf("/user/success") > -1) {
		_gaq.push(['_trackEvent', 'Registration', 'Website', 'Success']); 
		_gaq.push(['b._trackEvent', 'Registration', 'Website', 'Success']); 
		_gaq.push(['c._trackEvent', 'Registration', 'Website', 'Success']);
        }
}

/* Google Page Code with tie ins */  
_gaq.push(['_setAccount', 'UA-27560938-5']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setCustomVar', 1, 'Domain', googleDomain]);
_gaq.push(['_trackPageview']);

_gaq.push(['b._setAllowLinker', true]);
_gaq.push(['b._setCustomVar', 1, 'Domain', googleDomain]);
_gaq.push(['b._trackPageview']);

_gaq.push(['c._setAccount', 'UA-27560938-6']);
_gaq.push(['c._setAllowLinker', true]);
_gaq.push(['c._setCustomVar', 1, 'Domain', googleDomain]);
_gaq.push(['c._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);
  })();
