		
   			 $(document).ready(function() {
   			 
   			 		  		 
			   
			   // 1) parse the url to get the name pairs
			   
					    var GETDATA = new Array();
		
						var sGet = window.location.search;
						
						if (sGet) // if has a value...
						{
						    // Drop the leading "?"
						    sGet = sGet.substr(1);
						    
						    // Generate a string array of the name value pairs.
						    // Each array element will have the form "foo=bar"
						    var sNVPairs = sGet.split("&");
						    
						    // Now, for each name-value pair, we need to extract
						    // the name and value.
						    for (var i = 0; i < sNVPairs.length; i++)
						    {
						        // So, sNVPairs[i] contains the current element...
						        // Split it at the equals sign.
						        var sNV = sNVPairs[i].split("=");
						        
						        // Assign the pair to the GETDATA array.
						        var sName = sNV[0];
						        var sValue = sNV[1];
						        GETDATA[sName] = sValue;
						        
						    }
						}
			   
			   
			   // 2) Put the values we are looking for into variables
			   
			   			found_cmpid=GETDATA["cmpid"]; // locate the existing cmpid string and put it here.
			   			found_target=GETDATA["target_id"]; // locate the existing target_id string and put it here.
			   			
			   			var empty; // an empty (undefined) variable
			   			var new_outbound_cmpid_string; // a variable to hold the new OUTBOUND campaign string
			   			var event_string_to_add = "Redirect_"+eventname+"_";  // Take the event name and turn it into the right format for the cmpid
			   
			   // 3) Perform logic on setting up new strings
			  
						  if (found_cmpid == empty){ // if there is no existing campaign id coming in
								new_outbound_cmpid_string=event_string_to_add; // so add the campaign redirect.
								found_cmpid="";
						  }
						  else if (found_cmpid.indexOf("redirect")!=-1 || found_cmpid.indexOf("Redirect")!=-1) {
								new_outbound_cmpid_string=found_cmpid; // There is already a "redirect" found in the campaign string, keep as is. 
						  }
						  else // there was an existing cmpid, but it had no "redirect" found so lets set our appending variable next
						  {
								new_outbound_cmpid_string=event_string_to_add+found_cmpid;
					      }

						 if (found_target == empty){ // if there is no existing target id coming in
								found_target=""; // don't let it be undefined
						  }

				// 4) We now have captured and processed our url and have our variables set. 
				//    4a) We need to find all internal links and append the found target and found campaign strings
				//    4b) We need to find all external links and append the found target and our new external outbound campaign string
			   
			   
			   $('a.internal').each(function()
				{
					var url = this.href;
					if (url.indexOf("?")!=-1) {
						//alert ("found a ?, use a &");
						$(this).attr('href', ($(this).attr('href'))+'&target_id='+found_target+'&cmpid='+found_cmpid );
					}
					else $(this).attr('href', ($(this).attr('href'))+'?target_id='+found_target+'&cmpid='+found_cmpid );
    			});
    			
    			$('a.external').each(function()
				{
					var url = this.href;
					if (url.indexOf("?")!=-1) {
						//alert ("found a ?, use a &");
						$(this).attr('href', ($(this).attr('href'))+'&target_id='+found_target+'&cmpid='+new_outbound_cmpid_string );
					}
					else $(this).attr('href', ($(this).attr('href'))+'?target_id='+found_target+'&cmpid='+new_outbound_cmpid_string );
    			});
    						   

   			   });