/* =============================================================================
Description:
	Function for tracking external links and for adding leaving IBM notifica-
	tions in front of external links which do not use 'ibm-leaving-prompt' yet.

	This function should be linked in all v16 UK IT Manager pages via
	the following include file:
		./itsolutions/ssi-v16/head-itsolutions-v2.shtml
================================================================================
Author:
	Jan Mac/Slovakia/IBM

Version:
	- v2.0, 2009-07-28
		- rewritten from DOM to jQuery to achieve better cross-browser
		  compatibility
		- added tracking code for surfAid
			[- CoreMetrics support has been removed until CM is enabled for SWG]
		- added logging function, sample usage:
			jQuery().itmCommonLogToggle();

	- v1.1, 2009-05-19:
		- updated code to allow co-existence with ibm-leaving-prompt

	- v1.0, 2008-08-15: initial release into production
================================================================================
Requires:
	//www.ibm.com/common/js/ibmcommon.js
	//www.ibm.com/itsolutions/uk/js/itmcommon-log.js

Default location:
	//www.ibm.com/itsolutions/uk/js/rel-external-v2.js

	Please do not link directly to the default location outside of
	ibm.com/itsolutions/uk - create a local copy of the script instead.
================================================================================
Sample usage:
	The script automatically binds events to anchors coded as follows:
	1.) old system which opens popups (v16 pages before 'ibm-leaving-prompt')
		<a href="..." rel="external">...</a>

	2.) temporary transition from popups to overlays
		<a href="..." class="ibm-leaving-overlay">...</a>

	3.) new system - overlays, but with rel="external" (re-added for semantics)
		<a href="..." class="ibm-leaving-overlay" rel="external">...</a>


	As of version 2.0, all cases shown above are tracked via sa_onclick at
	the following URL (example shows tracking of "http://www.google.com/"):

		/www-01.ibm.com/software/uk/itsolutions/
			?sa_message=http%3A%2F%2Fwww.google.com%2F


============================================================================= */

if(typeof (jQuery().itmCommonLog)!=="function"){jQuery.fn.extend({itmCommonLog:function(B,A){return(this)}});jQuery.extend({itmCommonLogInitCheck:function(){},itmCommonLogToggle:function(){}})}jQuery.fn.extend({itmCommonExternal:function(){return(this.each(function(A,B){if(!jQuery(this).hasClass("ibm-leaving-prompt")){jQuery(this).bind("click",function(C){C.preventDefault();leavingPopupAttrs="width="+jQuery.fn.itmCommonExternal.config.leavingPopup.width+",height="+jQuery.fn.itmCommonExternal.config.leavingPopup.height;
if(jQuery.fn.itmCommonExternal.config.leavingPopup.otherAttrs!==""){leavingPopupAttrs+=","+jQuery.fn.itmCommonExternal.config.leavingPopup.otherAttrs}window.open(jQuery.fn.itmCommonExternal.config.leavingPopup.uriPrefix+jQuery(this).attr("href"),jQuery.fn.itmCommonExternal.config.leavingPopup.windowName,leavingPopupAttrs);jQuery(this).itmCommonLog("log","itmCommonExternal: opening leaving IBM popup")});jQuery(this).itmCommonLog("log","itmCommonExternal: binded leaving IBM popup")}else{jQuery(this).itmCommonLog("log","itmCommonExternal: link uses ibm-leaving-prompt (popup not needed)")
}jQuery(this).itmCommonLog("log","itmCommonExternal: binding tracking functions");jQuery(this).bind("click",function(C){externalUri=jQuery(this).attr("href");if(externalUri.search(/ibm\.com\/links/)>=0){externalUri=externalUri.replace(/.*\?.*url=/,"")}else{if(externalUri.search(/leaving-ibm-popup-uk-itm.jsp/)>=0){externalUri=externalUri.replace(/.*\?.*sa_target=/,"");externalUri=encodeURIComponent(externalUri)}else{externalUri=encodeURIComponent(externalUri)}}currentUri=window.location.href;separatorChar="?&";
if(currentUri.search(/.*ibm\.com.*\?.*/)>=0){separatorChar="&"}else{separatorChar="?"}jQuery(this).itmCommonLog("groupCollapsed","itmCommonExternal: tracking call");surfAidCall=currentUri+separatorChar+"sa_target="+externalUri;sa_onclick(surfAidCall);jQuery(this).itmCommonLog("log","itmCommonExternal: surfAid tracking call for external URI:\n"+surfAidCall);jQuery(this).itmCommonLog("groupEnd",null)})}))}});jQuery.fn.itmCommonExternal.config={leavingPopup:{uriPrefix:"/software/uk/itsolutions/jsp/leaving-ibm-popup-uk-itm.jsp?sa_target=",windowName:"leaving_ibm",width:443,height:310,otherAttrs:"scrollbars=1"}};
jQuery(function(){jQuery(this).itmCommonLog("groupCollapsed","itmCommonExternal: init");jQuery("a[rel=external],a[class*=ibm-leaving-prompt]").each(function(){jQuery(this).itmCommonExternal()});jQuery(this).itmCommonLog("groupEnd",null)});