// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// Track all external links via ajax
	function track_onclick(evt) {
		evt = (evt) ? evt : ((window.event) ? window.event : "")
		if (evt) {
		   	var target
				if (evt.target) {
		        	target = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target
		        } else {
		            target = evt.srcElement
		        }
		
		}

		// If this isn't an anchor, we don't care
		if (target.nodeName != 'A') {
			return;
		}
            
		// If the target is https://secure.eFieldHouse, dev, or, local then ignore it
		if (target.href.match(/https:\/\/[^\.]*\.efieldhouse\.com/i)) {
			return;
		} else if (target.href.match(/http:\/\/dev.efieldhouse.com/i)) {
			return;
		} else if (target.href.match(/http:\/\/localhost:3000/i)) {
			return;	 
		} else if (target.href.match(/file:\/\/\//)) {
			return
		} else {
		var url = '/main/track_external_hit_action?target=' + encodeURIComponent(target) + '&src=' + encodeURIComponent(document.location.href);
		new Ajax.Request(url,{method:'put'}); }
	}

		document.onclick = track_onclick;
