/* 
	adds tracking behaviour to links contained within the element oShowProfileDescriptionContainer
*/
addLoadEvent( fAssignTrackingLinks );
function fAssignTrackingLinks(){
	// check if panel exists
	if ( oShowProfileDescriptionContainer ) {
		var oLinks = [];
		var oLinks1 = $A(oShowProfileDescriptionContainer.getElementsByTagName("area") )
		var oLinks2 = $A( oShowProfileDescriptionContainer.getElementsByTagName("a") );
		oLinks1.each( function( link ) {
			oLinks.push( link);
		});
		oLinks2.each( function( link ) {
			oLinks.push( link);
		});
		
		var oLink, i = 0;
		while( oLink = oLinks[ i++ ] ) {
		
			//alert( oLink.tagName + " " + oLink.href)
		
			// Determine which kind of link we're dealing with
			var xWWW = /^http(s)?\:/gi;
			var xEmail = /^mailto\:/gi;

			// if the link is a mailto link
			if ( oLink.href.match( xEmail ) ) {
				
				if ( oLink.innerHTML )
				{
				    var sHTML = oLink.innerHTML // the innerHTML trick is needed to fix error in IE where it replaces the children of the link, when you assign something to the href attribute
				}
				
				var xSubject = /subject\=/gi;
				if ( !oLink.href.match( xSubject ) ) {
					if ( oLink.href.indexOf("?") == -1 ) {
						oLink.href = oLink.href + "?";
					} else {
						oLink.href = oLink.href + "&amp;";
					}
					oLink.href = oLink.href + "subject=" + sSubject;
				} else {
					oLink.href = oLink.href.replace( /subject=[^"&]*/gi, "subject=" + sSubject );
				}
				
				if ( oLink.innerHTML )
				{
				    oLink.innerHTML = sHTML;
				}
				    
				oLink.onclick = fTrackLinkClick;
				
			// if the link is a http link			
			} else if ( oLink.href.match( xWWW ) ){
				// forces the link to open in a new window			
				oLink.target = "_blank";
				oLink.onclick = fTrackLinkClick;
				
			// the link is assumed to be a local link
			} else {
				// The link is not an external link, nor an email link, and will not be tracked
				break;
			}
		}
	}
}

function fTrackLinkClick() {
	// Determine which kind of link we're dealing with
	var xWWW = /^http(s)?\:/gi
	var xEmail = /^mailto\:/gi

	if ( this.href.match( xEmail ) ) {
		sType = "email";
	} else if ( this.href.match( xWWW ) ){
		sType = "www";
	} else {
		// The link is not an external link, nor an email link, and will not be tracked
		return;
	}
    var oImg = document.createElement("img");
    oImg.style.position = "absolute";
    oImg.style.top = "-1000px"
    oImg.style.left = "-1000px";
    document.body.appendChild( oImg );
    oImg.src = "/RegisterClick.aspx?mode=" + sType + "&id=" + sClickTrackingId;
}