/*
 * Date:        Jan 27 2009
 * 
 * Written by:  Ecomerce Intelligence.  www.ecomiq.com
 * 
 * Dependancies:Prototype javascript framework -   prototype.js
 *		Google Analytics tracking script - ga.js
 *
 * Usage:       This file should be included towards the top of all webpages, 
 * 		but after jquery.js and ga.js.
 *
 * Purpose:     This script automatically tags links, with Google Analytics' session
 *		tagging function.  In order to preserve a users session as he
 *		hops from one domain to another. links to different 
 *		URLs will be tagged with that users' session data.
 */



/* List of websites that should be tagged.   All links to any of the websites listed in this 
 * array will be tagged.
 */

var URLs = 	new Array('safesecureweb.com');

jQuery(document).ready(function(){

	// Links
	jQuery("a").each(function(){    
		if (tagLink(this.href)){
			this.href = __utmLinkerUrl(this.href);
		}
	});

	// Forms
	jQuery("form").each(function(){    
		if (tagLink(jQuery(this).attr('action'))){
			var nAction = __utmLinkerUrl(jQuery(this).attr('action'));
			jQuery(this).attr('action',nAction);
		}
	});
});


/**************************************************************/
/*************** Do Not Edit Below This Line ******************/
/**************************************************************/

function tagLink(link){

	if (!link){ return false;}

	// Get rid of http:// and querystring in link (if exists).
	if (link.indexOf('://') > 0)
		link = link.substring(link.indexOf('://') + 3);

	if (link.indexOf('?') > 0)
		link = link.substring(0,link.indexOf('?'));

	if (link.indexOf('/') > 0)
		link = link.substring(0,link.indexOf('/'));

	// First check, if it's in the list of URLs to skip.
	if (typeof(noTagURLs) != 'undefined'){
		if (noTagURLs.length){
			for(var i=0; i<noTagURLs.length; i++){
				if ((noTagURLs[i].length) && (link.indexOf(noTagURLs[i]) >= 0)){
					return 0;
				}
			}
		}
	}

	// Get Current URL and clean up.
	var thisURL = new String(window.location);
	if (thisURL.indexOf('://') > 0)
		thisURL = thisURL.substring(thisURL.indexOf('://') + 3);

	if (thisURL.indexOf('?') > 0)
		thisURL = thisURL.substring(0,thisURL.indexOf('?'));

	if (thisURL.indexOf('/') > 0)
		thisURL = thisURL.substring(0,thisURL.indexOf('/'));

	// Don't tag links to current domain.
	if (thisURL == link.substring(link.indexOf('://'),link.indexOf('/'))){
		return 0;
	}

	for(var i=0; i<URLs.length; i++){
		var regExp = new RegExp("\\."+ URLs[i] + '$','i');
		if (link.match(regExp) || (link == URLs[i])) {
			return 1;
		}
	}

	// If we got this far, link shouldn't be tagged.
	return 0;
}

