//network central tracking control script
//copyright 2009 Analytics Pros, Inc. (analyticspros.com)
//licensed to Digital Five, Inc. (digitalfive.com)
function utmCrossTrk (cPage, passCookies, value) {
	// cPage: a custom page to specify the Pageview string
	// passCookies: boolean - should GA provide a URL including the cookies?
	
	
	var tracker = window.utmCrossTracker, 
			iframe_url = document.location.protocol + '//access.analyticsbackup.com/iframe/track.php';

	// These get passed as arguments in the URL (to the iframe)
	var values = {
		pRef: document.referrer.toString(),
		pPage: document.location.toString(),
		cPage: cPage,
		type: 'pageview',
		'value': value // optional
	};

	// compose a parameter string
	var params = ''; // document.location.search;
	for(var i in values) {
		params += '&' + urlencode(i) + '=' + urlencode(values[i]);
	}

	// assemble the iframe source URL
	var psep = (params.charAt(0) == '?') ? '' : '?';
	iframe_url += psep + params;
	if(passCookies && tracker) iframe_url = tracker._getLinkerUrl(iframe_url, true);

	try {
		// remove the iframe if it already exists
		var l = document.getElementById('_UTM_iframe_tracker');
		if(l && l.parentNode) {
			l.parentNode.removeChild(l);
		}

		// generate the iframe (again)
		var b = document.getElementsByTagName('body')[0];
		var f = document.createElement('iframe');
		f.setAttribute('id', '_UTM_iframe_tracker');
		f.setAttribute('src', iframe_url);
		f.setAttribute('style', 'display: none; height: 0; width: 0;');
		f = b.appendChild(f);
		if(f.style) f.style.display = 'none';

		return f;
	} catch (e) {
		return false;
	}
}

function urlencode(s) {
	var e = escape(s).replace(/[*+\/@]|%20/g, function(t){
		switch(t){
		case '%20': return '+';
		default: return t.toString(16);
		}
	});
	return e;
}
