// JavaScript Document
//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 WhereDoIGo;
var DestinationURL;
//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 WhereDoIGo = destinationURL.substring(100);

//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('WT.mc');

//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
if (WhereDoIGo.length < 1 )
{ 
  Redirect = "http://www.ebookers.fr?WT.mc_ev=click&WT.mc_id=EBFRM30001&tduid=" + mytduid;
}

//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)
 {
 var Question = WhereDoIGo.indexOf('?');
  if (Question > 0)
 { 
 
  Redirect = WhereDoIGo + "&WT.mc_ev=click&WT.mc_id=EBFRM30001&tduid=" + mytduid;

}
  else 
   { 
   Redirect = WhereDoIGo + "?WT.mc_ev=click&WT.mc_id=EBFRM30001&tduid=" + mytduid;
}

}
else
{
  
  Redirect = WhereDoIGo + "&tduid=" + mytduid;

 }


return Redirect;


}


window.location = redirTo();



