// WebTrends SmartSource Data Collector
// $DateTime: 10/13/2005 12:44 PM

var gImages=new Array;
var gIndex=0;
var DCS=new Object();
var WT=new Object();
var DCSext=new Object();

var gDomain="sdc.iona.com";  // Should be the fully qualified hostname of the SDC server (ie. sdc.iona.com)
var gDcsId="dcsalh9py00000kj8bkry8uqh_7v7x";
// Production: dcsalh9py00000kj8bkry8uqh_7v7x
// Development: dcs97g0v010000kn3eaf1wfcu_7f5m

// START OF ADVANCED ONCLICK TRACKING
function dcsEvt(evt){
	var e=evt.target||evt.srcElement;
	var tags="IMG,STRONG,FONT,B";
	if (tags.indexOf(e.tagName) !=-1){
		e=e.parentElement||e.parentNode;
	}
	//alert("dcsEvt function: " + e);
	return e;
}


function dcsBind(event,func){
	if (typeof(window[func])=="function"){
		if ((document.links) && (document.links.length>0) ) {
			for (var i =0;i < document.links.length;i++) {
				if (document.links[i].addEventListener){
					document.links[i].addEventListener(event, window[func], true);
				}
				else if(document.links[i].attachEvent){
					document.links[i].attachEvent("on"+event, window[func]);
				}
			}
		}
	}
}

function dcsET(){
	dcsBind("click","dcsDownload");
	dcsBind("mousedown","dcsRightClick");
}

function dcsMultiTrack(){
	//alert("dcsMuliTrack called");
	for (var i=0;i<arguments.length;i++){
		if (arguments[i].indexOf('WT.')==0){
				WT[arguments[i].substring(3)]=arguments[i+1];
				i++;
		}
		if (arguments[i].indexOf('DCS.')==0){
				DCS[arguments[i].substring(4)]=arguments[i+1];
				i++;
		}
		if (arguments[i].indexOf('DCSext.')==0){
				DCSext[arguments[i].substring(7)]=arguments[i+1];
				i++;
		}
	}
	var dCurrent=new Date();
	DCS.dcsdat=dCurrent.getTime();
	dcsTag();
}

// Track clicks to download links.
function dcsDownload(evt){
	evt=evt||(window.event||"");
	if (evt){
		var e=dcsEvt(evt);
		var types="xls,doc,pdf,txt,csv,zip,wsdl,xsd";   //customize download types
		var support="htm,html"; // list of support page types
		//alert("evt detected:");
		//alert(e.pathname);
		if (types.indexOf(e.pathname.substring(e.pathname.lastIndexOf(".")+1,e.pathname.length))!=-1){
			var qry=e.search?e.search.substring(e.search.indexOf("?")+1,e.search.length):"";
			var path=(e.pathname.indexOf("/")!=0)?"/"+e.pathname:e.pathname;
			var ref=window.location;
			dcsMultiTrack("DCS.dcssip",e.hostname,"DCS.dcsuri",path,"WT.ti","Download:"+path,"WT.dl","1","DCS.dcsref",DCS.dcsuri);
		}

		//alert("e.pathname.indexOf/products/artix/: "+ e.pathname.indexOf('products/artix/'));
		//alert("navigator.userAgent.indexOf: "+navigator.userAgent.indexOf('MSIE'));
		//if (support.indexOf(e.pathname.substring(e.pathname.lastIndexOf(".")+1,e.pathname.length))==0){alert("end of string match html or htm");}else{ alert("string doesn't match htm or html");}
		//alert("what we are getting in that long thing: " + support.indexOf(e.pathname.substring(e.pathname.lastIndexOf(".")+1,e.pathname.length)));


		if ((e.pathname.indexOf('support/docs/') != -1) && (support.indexOf(e.pathname.substring(e.pathname.lastIndexOf(".")+1,e.pathname.length))!=-1) ){
//		if ((e.pathname.indexOf('products/artix/') != -1) && (support.indexOf(e.pathname.substring(e.pathname.lastIndexOf(".")+1,e.pathname.length))!=-1) ){
			//alert ("Pattern match for: "+e.pathname);
			var qry=e.search?e.search.substring(e.search.indexOf("?")+1,e.search.length):"";
			var path=(e.pathname.indexOf("/")!=0)?"/"+e.pathname:e.pathname;
			var ref=window.location;
			dcsMultiTrack("DCS.dcssip",e.hostname,"DCS.dcsuri",path,"WT.ti","Support Link:"+path);
			//alert("IE IS NOT COOL: "+e.pathname);
		}
		else if ((e.pathname.indexOf('support/docs/') != -1) && (support.indexOf(e.pathname.substring(e.pathname.lastIndexOf(".")+1,e.pathname.length))!=-1)){
//		else if ((e.pathname.indexOf('products/artix/') != -1) && (support.indexOf(e.pathname.substring(e.pathname.lastIndexOf(".")+1,e.pathname.length))!=-1)){
			//alert ("Pattern match for MSIE: "+e.pathname);
			var qry=e.search?e.search.substring(e.search.indexOf("?")+1,e.search.length):"";
			var path=(e.pathname.indexOf("/")!=0)?"/"+e.pathname:e.pathname;
			var ref=window.location;
			dcsMultiTrack("DCS.dcssip",e.hostname,"DCS.dcsuri",path,"WT.ti","Support Link:"+path);
			//alert("FIREFOX IS OK: "+e.pathname);
		}
	DCS.dcssip=DCS.dcsuri=WT.ti=WT.svl=WT.dl=WT.cg_n=WT.cg_s=DCS.dcsref="";
	}
}

// Track right clicks to download links.
function dcsRightClick(evt){
	evt=evt||(window.event||"");
	if (evt){
		var btn=evt.which||evt.button;
		if (btn!=1){
			var e=evt.target||evt.srcElement;
			var types="xls,doc,pdf,txt,csv,zip,wsdl,xsd";	//customize download types
			if (types.indexOf(e.pathname.substring(e.pathname.lastIndexOf(".")+1,e.pathname.length))!=-1){
				var path=(e.pathname.indexOf("/")!=0)?"/"+e.pathname:e.pathname;
				dcsMultiTrack("DCS.dcssip",e.hostname,"DCS.dcsuri",path,"WT.ti","Download:"+path,"WT.dl","1");
				DCS.dcssip=DCS.dcsuri=WT.ti=WT.svl=WT.dl=WT.cg_n=WT.cg_s=DCS.dcsref="";
			}
		}
	}
}

function dcsAdv(){
	dcsFunc("dcsET");
}

// END OF ADVANCED ONCLICK TRACKING

function dcsVar(){
	var dCurrent=new Date();
	WT.tz=dCurrent.getTimezoneOffset()/60*-1;
	if (WT.tz==0){
		WT.tz="0";
	}
	WT.bh=dCurrent.getHours();
	WT.ul=navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
	if (typeof(screen)=="object"){
		WT.cd=navigator.appName=="Netscape"?screen.pixelDepth:screen.colorDepth;
		WT.sr=screen.width+"x"+screen.height;
	}
	if (typeof(navigator.javaEnabled())=="boolean"){
		WT.jo=navigator.javaEnabled()?"Yes":"No";
	}
	if (document.title){
		WT.ti=document.title;
	}
	WT.js="Yes";
	if (typeof(gVersion)!="undefined"){
		WT.jv=gVersion;
	}
	DCS.dcsdat=dCurrent.getTime();
	// Records iona.com requests to www.iona.com
	if (window.location.hostname == "www.iona.com" || window.location.hostname == "iona.com") {
		DCS.dcssip="www.iona.com";
	} else {
		DCS.dcssip=window.location.hostname;
	}

	DCS.dcsuri=window.location.pathname;
	DCS.dcsqry=window.location.search;
	if ((window.document.referrer!="")&&(window.document.referrer!="-")){
		if (!(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)<4)){
			DCS.dcsref=window.document.referrer;
		}
	}
}

function A(N,V){
	return "&"+N+"="+dcsEscape(V);
}

function dcsEscape(S){
	if (typeof(RE)!="undefined"){
		var retStr = new String(S);
		for (R in RE){
			retStr = retStr.replace(RE[R],R);
		}
		return retStr;
	}
	else{
		return escape(S);
	}
}

function dcsCreateImage(dcsSrc){
	if (document.images){
		gImages[gIndex]=new Image;
		gImages[gIndex].src=dcsSrc;
		gIndex++;
	}
	else{
		document.write('<IMG BORDER="0" NAME="DCSIMG" WIDTH="1" HEIGHT="1" SRC="'+dcsSrc+'">');
	}
}

function dcsMeta(){
	var myDocumentElements;
	if (document.all){
		myDocumentElements=document.all.tags("meta");
	}
	else if (document.documentElement){
		myDocumentElements=document.getElementsByTagName("meta");
	}
	if (typeof(myDocumentElements)!="undefined"){
		for (var i=1;i<=myDocumentElements.length;i++){
			myMeta=myDocumentElements.item(i-1);
			if (myMeta.name){
				if (myMeta.name.indexOf('WT.')==0){
					WT[myMeta.name.substring(3)]=myMeta.content;
				}
				else if (myMeta.name.indexOf('DCSext.')==0){
					DCSext[myMeta.name.substring(7)]=myMeta.content;
				}
				else if (myMeta.name.indexOf('DCS.')==0){
					DCS[myMeta.name.substring(4)]=myMeta.content;
				}
			}
		}
	}
}

function dcsTag(){
	var P="http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+gDomain+(gDcsId==""?'':'/'+gDcsId)+"/dcs.gif?";
	for (N in DCS){
		if (DCS[N]) {
			P+=A(N,DCS[N]);
		}
	}
	for (N in WT){
		if (WT[N]) {
			P+=A("WT."+N,WT[N]);
		}
	}
	for (N in DCSext){
		if (DCSext[N]) {
			P+=A(N,DCSext[N]);
		}
	}
	if (P.length>2048&&navigator.userAgent.indexOf('MSIE')>=0){
		P=P.substring(0,2040)+"&WT.tu=1";
	}
	dcsCreateImage(P);
}

function dcsFunc(func){
	if (typeof(window[func])=="function"){
		window[func]();
	}
}

// Purpose: Assign content groups and sub-content groups based on URI structure
function dcsAssignGroups(){
    // For testing purposes
    // DCS.dcsuri = '/login/login.jsp';

    // Assign content groups
    if (DCS.dcsuri.indexOf('/products/') == 0){
        WT.cg_n='Products';
    } else if (DCS.dcsuri.indexOf('/support/') == 0){
        WT.cg_n='Support';
    } else if (DCS.dcsuri.indexOf('/info/services') == 0){
        WT.cg_n='Services';
    } else if (DCS.dcsuri.indexOf('/devcenter') == 0){
        WT.cg_n='Tech Zone';
    } else if (DCS.dcsuri.indexOf('/info/aboutus') == 0){
        WT.cg_n='About Us';
    } else if (DCS.dcsuri.indexOf('/partners') == 0){
        WT.cg_n='Partners';
    } else if (DCS.dcsuri.indexOf('/Account') == 0){
        WT.cg_n='Account Administration';
    } else if (DCS.dcsuri.indexOf('/login') == 0){
        WT.cg_n='Account Log-In';
    }

    // Assign sub-content groups
    if (DCS.dcsuri.indexOf('/products/artix') == 0){
        WT.cg_s='Artix';
    } else if (DCS.dcsuri.indexOf('/products/orbix') == 0){
        WT.cg_s='Orbix';
    } else if (DCS.dcsuri.indexOf('/products/mobile_orchestrator') == 0){
        WT.cg_s='Mobile Orchestrator';
    } else if (DCS.dcsuri.indexOf('/support/docs') == 0){
        WT.cg_s='Product Documentation';
    } else if (DCS.dcsuri.indexOf('/support/knowledge_base') == 0){
        WT.cg_s='Knowledge Base';
    } else if (DCS.dcsuri.indexOf('/info/services/consulting') == 0){
        WT.cg_s='Consulting';
    } else if (DCS.dcsuri.indexOf('/info/services/ps/training') == 0){
        WT.cg_s='Training';
    } else if (DCS.dcsuri.indexOf('/info/services/jboss') == 0){
        WT.cg_s='JBoss';
    } else if (DCS.dcsuri.indexOf('/devcenter/artix') == 0){
        WT.cg_s='Web Services';
    } else if (DCS.dcsuri.indexOf('/devcenter/corba') == 0){
        WT.cg_s='CORBA';
    } else if (DCS.dcsuri.indexOf('/devcenter/mainframe') == 0){
        WT.cg_s='Mainframe';
    } else if (DCS.dcsuri.indexOf('/pressroom') == 0){
        WT.cg_s='Press/News';
    } else if (DCS.dcsuri.indexOf('/info/aboutus/customers') == 0){
        WT.cg_s='Customers';
    } else if (DCS.dcsuri.indexOf('/worldwide') == 0){
        WT.cg_s='Worldwide';
    } else if (DCS.dcsuri.indexOf('/info/aboutus/resources.htm') == 0){
        WT.cg_s='Resources';
    } else if (DCS.dcsuri.indexOf('/info/aboutus/events') == 0){
        WT.cg_s='Events';
    } else if (DCS.dcsuri.indexOf('/info/aboutus') == 0){
        WT.cg_s='Careers';
    } else if (DCS.dcsuri.indexOf('/forms/dccontact.htm') == 0){
        WT.cg_s='Contact Us';
    }
}
