//This is the usual code for any TD redirect page in Javascript
//This first function detects and stores the TDUID value. 

function getVar(name)
{
	get_string = document.location.search;
	return_value = '';
	do
		{
		name_index = get_string.indexOf(name + '=');
		if(name_index != -1)
			{
			get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
			end_of_value = get_string.indexOf('&');
			if(end_of_value != -1)
				{
				value = get_string.substr(0, end_of_value);
				}
			else
				{
				value = get_string;
				}
			if(return_value == '' || value == '')
				{
				return_value += value;
				}
			else
				{
				return_value += ', ' + value;
				}
			}
		}
	while(name_index != -1)
		{
		space = return_value.indexOf('+');
		}
	while(space != -1)
		{
		return_value = return_value.substr(0, space) + ' ' + return_value.substr(space + 1, return_value.length);
		space = return_value.indexOf('+');
		}
	return(return_value);
}

var mytduid = getVar('tduid');




//This is the beginning of our code

function redirTo()
{
var Destination = "";
var Redirect = "";
var KLMString = "";

//This var stores the destination URL of the page but it includes the URL of the redirect page itself.

var destinationURL = document.location.href;

var KLMString = destinationURL.indexOf('Redirect.jsp');

if (KLMString == -1)
{

//This var stores the existence of a specific substring within the destination URL.

//In this case, the substring is: ad.doubleclick.net

var Destination = destinationURL.indexOf('ad.doubleclick.net');


//This var stores the destination URL without the URL of the redirect page itself by means of cutting the number of characters
//(101 characters in this case) which compose the URL of the redirect page, the variable tduid (and its content) and the variable URL:  

// http://hst.tradedoubler.com/file/77629/MasterRedirect.html?tduid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&url=   ---> It has 101 caracteres.

//Otherwise the function will enter a loop

var WhereDoIGo = destinationURL.substring(101);


//If there's NO destination URL, it goes to the home page adding only the TDUID
if (WhereDoIGo.length < 1 )
{ 
  Redirect = "http://ad.doubleclick.net/clk;208937870;29131075;l?http://www.klm.com/travel/no_en/index_default.html";
}

//If there's destination URL and it does NOT contain the string "ad.doubleclick.net", it goes to the home page adding both, the TDUID and the  
//destination URL.
else if (Destination==-1)
 { 
  Redirect = "http://ad.doubleclick.net/clk;208937870;29131075;l?" + WhereDoIGo;
}

//If there're both, the destination URL and the string "ad.doubleclick.net" it goes to the alternative redirect page adding both,
//the TDUID and the destination URL
else
{
  
  Redirect = WhereDoIGo;

 }
}

else

{
var Redirect ="";
var charposition ="";
var retrievepoint ="";
var WhereDoIGo =";"

//This var stores the existence of a specific substring within the destination URL.
//In this case, the substring is: ad.doubleclick.net
//This var stores the destination URL without the URL of the redirect page itself by means of cutting the number of characters
//(101 characters in this case) which compose the URL of the redirect page, the variable tduid (and its content) and the variable URL:  
// http://hst.tradedoubler.com/file/77629/MasterRedirect.html?tduid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&url=   ---> It has 101 caracteres.
//Otherwise the function will enter a loop
//If there's NO destination URL, it goes to the home page adding only the TDUID
//this condition only happens with textlinks
  
 var charposition = destinationURL.indexOf('.jsp');
 
 klm_local = 19;
 
 var retrievepoint = charposition+klm_local;

 var WhereDoIGo = destinationURL.substring(retrievepoint);

Redirect = "http://ad.doubleclick.net/clk;208937870;29131075;l?" + WhereDoIGo;


//If there're both, the destination URL and the string "ad.doubleclick.net" it goes to the alternative redirect page adding both,
//the TDUID and the destination URL

}
 
return Redirect;


}


window.location = redirTo();


