if ( !document.IncludedFiles ) document.IncludedFiles = [];
document.IncludedFiles['http://www.backpackerscars.com/process/x_generation/0oa7WaxE%2dR3rVhGxE/mv_display/google_tools.js'] = 1;
//Included: logic/javascript/google_tools.js
function GoogleTools() {
}

GoogleTools.prototype = {
	
	observeEvent: function ( element, name, observer ) {
		if ( element.addEventListener ) {
			element.addEventListener( name, observer, false );
		} else if ( element.attachEvent ) {
			element.attachEvent( 'on' + name, observer );
		}
	},

	// determine if this url is a) for this site and b) the secure or insecure
	// -1 = not from this site
	// 0 = insecure url
	// 1 = secure url
	secureDomain: 'https://secure.zeald.com/tasbackau',
	insecureDomain: 'backpackerscars.com',
	outgoingUrlTypes: new RegExp( '^(mailto:|ftp[\.:])', 'i' ),
	isUrlSecure: function ( url ) {
		if ( url.search( this.outgoingUrlTypes ) != -1 ) return -1;
		if ( url.indexOf( this.secureDomain ) != -1 ) return 1;
		if ( url.indexOf( this.insecureDomain ) != -1 ) return 0;
		return -1;
	},

	// tracks outbound links in Google Analytics as /outbound/<link>
	// by applying an onclick to each link
	trackOutboundLink: function ( link ) {
		var href = link.href + '';
		href = href.replace( 'http://', '' );
		href = '/outgoing/' + href;
		this.observeEvent( link, 'click', function() { urchinTracker( href ); } );
	},

	// any links going from the secure to insecure servers need to run through google's linking function
	allLinks: '',
	fixLinks: function() {
		var links = document.getElementsByTagName( 'a' );

		// we first need to determine if we're on the secure or insecure server
		var loc = window.location.href + '';
		var secure = this.isUrlSecure( loc );

		// loop through all links & any that are pointing to the opposite server, 
		// run through googles link updater
		for ( var i = 0; i < links.length; i++ ) {
		    if (links[i].target) continue; //Ignore links with a target (otherwise clicking them gives a javascript error)
			var href = links[i].href + '';
			tmpSecure = this.isUrlSecure( href );
			if ( tmpSecure == secure ) continue;
			if ( tmpSecure == -1 ) {
				this.trackOutboundLink( links[i] );
			} else {
				links[i].href = "javascript: __utmLinker( '" + href + "' );";
				this.allLinks += links[i].href + '\n';
			}
		}

		// loop through all forms & place onsubmits to any that are pointing to
		// the oppoisite server
		var forms = document.getElementsByTagName( 'form' );
		for ( var i = 0; i < forms.length; i++ ) {
		    if (forms[i].target) continue; //Ignore forms with a target (otherwise clicking them gives a javascript error)
			var action = forms[i].action;
			tmpSecure = this.isUrlSecure( action );
			if ( tmpSecure == -1 || tmpSecure == secure ) continue;

			// add an onsubmit to the secure-changing form
			this.observeEvent( forms[i], 'submit', function() { __utmLinkPost( this ); } );
		}
	}
};
