var strGATagConfiguration
strGATagConfiguration = ".pdf=PDF|.doc=DOC|.mp3=MP3|.mov=MOV|.ppt=PPT|.exe=EXE|.zip=ZIP|.jpg=JPG|.png=PNG|mailto:=MAILTO|.swf=MOV|.mpg=MOV|.mpeg=MOV|.sit=SIT|.hqx=HQX"//append new file types here

//==================================================================
//This function is used to decode the URL
//===================================================================
function URLDecode(strURL)
{
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = strURL;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // end while
   return plaintext
}
 
//==================================================================
//This function is used to handle mailto tag
//===================================================================
function GATagMailto(strFile){
	var strTagtype;
	strTagtype = "mailto:";
	strFile = strFile.substring(strTagtype.length, strFile.length)
	if(strFile.length > 0){
		strFile = "/MAILTO/" + strFile;
		strFile = strFile.replace(new RegExp( "//", "g") , "/");
		GATaggingfunctionCall(strFile);
	}
	return false;
}

//==================================================================
//This function is used to create GAtag
//===================================================================
function GATag(strFile){
	
	var strDomain,strOriginalLink,bprocess,strFile1;
	strFile = URLDecode(strFile);
	strFile1 = strFile;
	bprocess = false;
	strOriginalLink = "";
	strDomain = "";
	strOriginalLink = strFile;
	if ( strFile.indexOf("http") >= 0) {
		strDomain = "http://" + window.location.hostname;
	}
	if ( strFile.indexOf("https") >= 0) {
		strDomain = "https://" + window.location.hostname;
	}
	 if (strDomain.length > 0) {
		strFile = strFile.substring(strDomain.length , strFile.length)
	 }
	strFile = strFile.replace(/\s/g, "_");
	strFile = strFile.replace(/__/g, "_")
	if (strGATagConfiguration.split(",").length > 0)
	{
		for (i=0; i < strGATagConfiguration.split("|").length; i++) {
			if(strGATagConfiguration.split("|")[i].split("=").length > 0) {
				if(strFile.toLowerCase().indexOf(strGATagConfiguration.split("|")[i].split("=")[0])  > -1) {
					strFile = strFile.replace(new RegExp(strGATagConfiguration.split("|")[i].split("=")[0] + "$", "i") , "")
					if( strFile.indexOf("_tcm") > 0 ) {
						strFile = strFile.substring(0,strFile.indexOf("_tcm")) 
					}
					if (/images/i.test(strFile)) {
						strFile = strFile.replace(new RegExp( "images", "i") , strGATagConfiguration.split("|")[i].split("=")[1])
					}
					else{
						strFile = "/" + strGATagConfiguration.split("|")[i].split("=")[1] + "/" + strFile;

					}
					strFile = strFile.replace(new RegExp( "//", "g") , "/")
					bprocess = true;
					
				}
			}
		}
	}
	var bcurrentdomain;
	bcurrentdomain = false;
	bcurrentdomain = isCurrentdomain(strFile);
	if( strFile.toLowerCase().indexOf("mailto:") > -1){
		strFile = strFile.replace(new RegExp( "mailto:", "g") , "")
	}
	else if(hasExternaldomain(strOriginalLink) && !bcurrentdomain){
		strOriginalLink= strOriginalLink.replace(new RegExp("http://" + window.location.hostname, "g") , "");
		strFile = "/External/" + strOriginalLink ;
		bprocess = true;
	}
	strFile = strFile.replace(new RegExp( "/External/External/", "g") , "/External/")
	strFile = strFile.replace(new RegExp( "/External//", "g") , "/External/")
	strFile = strFile.replace(new RegExp( "/External/http://", "g") , "/External/")
	if( strFile.toLowerCase().indexOf("javascript:") > -1){
		return false;
	}
	if (strFile.length > 0 && bprocess == true)	{
		GATaggingfunctionCall(strFile);
	}			
		return false;
}

//========================================================================================================================
// This function is used attach onclick event to hyperlink elements( currently available for anchor element and image map.
//========================================================================================================================
	function attachEvents(){
		var objElements,i,strfilepath,strPath,j;
		objElements = null;
		objElements=document.getElementsByTagName('a');
		for(i in objElements){			
			if (objElements[i].href != undefined) {
				strfilepath = "";
				strPath = "";
				strfilepath  = objElements[i].href;
				strPath	=	objElements[i].href;
				strfilepath = strfilepath.toLowerCase();				
				for (j=0; j < strGATagConfiguration.split("|").length; j++) {
					if(strGATagConfiguration.split("|")[j].split("=").length > 0) {
						if( strfilepath.indexOf(strGATagConfiguration.split("|")[j].split("=")[0]) > -1 || hasExternaldomain(strPath)){
							objElements[i].onclick=function() { 
								GATag(this.href);
							}
								
						}
					}
				}
				
			}
		}
		objElements = null;
		objElements=document.getElementsByTagName('area');
		for(i in objElements){
			if (objElements[i].href != undefined) {
				strfilepath = "";
				strPath = "";
				strfilepath  = objElements[i].href;
				strPath	=	objElements[i].href;
				strfilepath = strfilepath.toLowerCase();				
				for (j=0; j < strGATagConfiguration.split("|").length; j++) {
					if(strGATagConfiguration.split("|")[j].split("=").length > 0) {						
						if( strfilepath.indexOf(strGATagConfiguration.split("|")[j].split("=")[0]) > -1 || hasExternaldomain(strPath) ){
							objElements[i].onclick=function() { 
								GATag(this.href);
							}
								
						}
					}
				}
			}
		}
	}

function GATagRedirect(strfile){
	if (strfile.length > 0)
	{
		GATaggingfunctionCall(strfile);
	}
}


//==================================================================
// This function is used call google's function
//===================================================================

function GATaggingfunctionCall(strTag){

	//alert(strTag) //if any issues in tagging uncomment this line and see the tag information in the alert window
	if (strTag.length > 0 ){
		if( strTag.toLowerCase().indexOf("javascript:") > -1){
		return false;
	}
		if(typeof(pageTracker)=="object"){// if gs.js is used
			pageTracker._trackPageview(strTag);
		}
		else if(typeof(urchinTracker)=="function"){// if urchin.js is used
			urchinTracker(strTag);
		} else {
			return false;
		}
	}
	return false;
}

function generic()
{
	attachEvents();
};

//setup onload function
if(typeof window.addEventListener != 'undefined')
{
	//.. gecko, safari, konqueror and standard
	window.addEventListener('load', generic, false);
}
else if(typeof document.addEventListener != 'undefined')
{
	//.. opera 7
	document.addEventListener('load', generic, false);
}
else if(typeof window.attachEvent != 'undefined')
{
	//.. win/ie
	window.attachEvent('onload', generic);
}

//** remove this condition to degrade older browsers
else
{
	//.. mac/ie5 and anything else that gets this far
	
	//if there's an existing onload function
	if(typeof window.onload == 'function')
	{
		//store it
		var existing = onload;
		
		//add new onload handler
		window.onload = function()
		{
			//call existing onload function
			existing();
			
			//call generic onload function
			generic();
		};
	}
	else
	{
		//setup onload function
		window.onload = generic;
	}
}
function isCurrentdomain(strFile){
	if (strFile.toLowerCase().indexOf("/authfiles/pdf") == 0){
		return true;
	}
	return false;
}

function hasExternaldomain(strPath){
	var	bexternaldomain,icount;
	var strUrlPattern,strFoundUrl;
	strFoundUrl = "";
	strUrlPattern = "[A-Z|a-z|0-9]+[\.]+[\_|\-|a-z|A-Z|0-9]+[\.]+[a-z|A-Z|0-9]*";
	strUrlPattern = strUrlPattern + "~" + "[A-Z|a-z]+[\.]+[a-z|A-Z]+[\-]+[a-z|A-Z]+[\.]+[a-z|A-Z]+[\.]+[a-z|A-Z]*";
	strUrlPattern = strUrlPattern + "~" + "[A-Z|a-z|0-9]+[\.]+[\_|\-|a-z|A-Z|0-9]+[\.]+[a-z|A-Z|0-9]+[\.]+[\_\-|a-z|A-Z|0-9]*";
	strUrlPattern = strUrlPattern + "~" + "[0-9]+[\.]+[0-9]+[\.][0-9]+[\.][0-9]*";

	strUrlPattern = strUrlPattern + "~" + "[A-Z|a-z|0-9]+[\.]+[\_|\\-|a-z|A-Z|0-9]+[\.]+[a-z|A-Z|0-9]*";
	strUrlPattern = strUrlPattern + "~" + "[A-Z|a-z]+[\.]+[a-z|A-Z]+[\\-]+[a-z|A-Z]+[\.]+[a-z|A-Z]+[\.]+[a-z|A-Z]*";
	strUrlPattern = strUrlPattern + "~" + "[A-Z|a-z|0-9]+[\.]+[\_|\\-|a-z|A-Z|0-9]+[\.]+[a-z|A-Z|0-9]+[\.]+[\_\\-|a-z|A-Z|0-9]*";
	strUrlPattern = strUrlPattern + "~" + "[0-9]+[\.]+[0-9]+[\.][0-9]+[\.][0-9]*";
	bexternaldomain = false;
	strPath = strPath.replace(new RegExp( window.location.hostname, "g") , "");
	strPath = strPath.replace(new RegExp( "http://", "g") , "");
	strPath = strPath.replace(new RegExp( "https://", "g") , "");
	if (strUrlPattern.split("~").length > 0){
		for(icount = 0; icount < strUrlPattern.split("~").length; icount++){
			var re = new RegExp(strUrlPattern.split("~")[icount]);
			var strMatch = re.exec(strPath);
			if (strMatch != null) {
				for (i = 0; i < strMatch.length; i++) {
					strFoundUrl = strFoundUrl + strMatch[i];
						if(strFoundUrl.toString().toLowerCase() != window.location.hostname.toString().toLowerCase()){
							  if (!bexternaldomain) {
								  bexternaldomain = true;
								  break;
							  }
						  }
						  
						}
					}
				}
			}
		return bexternaldomain;
}
