/*****************************************************************/
/*  Functions and variables related to language identification,  */
/*  page translation and associated links.                       */
/*****************************************************************/

// start by keeping in memory the URL of the page with a global variable
var pageURL = location.href;

// keep in memory position of telltale sign of an english page
var englishMarkerPosition = pageURL.indexOf("_en.html");

// look for any query in the URL that we might needs later on
if(window.location.search){ var query = window.location.search.substring(1); }
else { var query = ""; }

/*****************************************************************/
/*  Function that tests to see if the page is in english.        */
/*****************************************************************/
function isEnglish() {
	var isthisenglish = false;
	if(englishMarkerPosition != -1){ isthisenglish = true; }
	return isthisenglish;
}

// Setting translation variables
var extPosition = pageURL.indexOf(".html");
if(isEnglish()){ // i.e. this is an english page
	var clippedURL = pageURL.substring(0,englishMarkerPosition);
	var translatedURL = clippedURL + ".html";
	var translateMessage = "Cliquez sur le drapeau pour traduire cette page en Fran&ccedil;ais.";
	var textLink = "Version Fran&ccedil;aise";
	var textTip = "Cliquez ce lien pour traduire cette page en Fran&ccedil;ais.";
	var flag = "flag_fr.gif";
	var targetLanguage = "Fran&ccedil;ais";
}
else { // i.e. this is a french page
	if (extPosition == -1) { // i.e. there is no ".html" extension which means this is the french index page
		var translatedURL = pageURL + "index_en.html";
	}
	else { // i.e. this is a standard french page
		var clipPosition = pageURL.indexOf(".html");
		var clippedURL = pageURL.substring(0,clipPosition);
		var translatedURL = clippedURL + "_en.html";
	}
	var translateMessage = "Click the flag to translate this page in English.";
	var textLink = "English Version";
	var textTip = "Click this link to translate this page in English."
	var flag = "flag_uk.gif";
	var targetLanguage = "English";
}
// append the query onto the translated URL if there is one
if(query != "") { translatedURL = translatedURL + "?" + query; }

/*****************************************************************/
/*  Functions that creates the translation links without the use */
/*  of any tooltips.                                             */
/*****************************************************************/
function do_translate_orig() {
	document.write('<a href="' + translatedURL + '" title="' + translateMessage + '"><img src="./img/' + flag + '" alt="' + translateMessage + '"></a>');
}
function do_translatelink_orig() {
	document.write('<a href="' + translatedURL + '" title="' + textLink + '">' + textLink + '</a>');
}

/***********************************************************************************************/
/*  Use of open-source boxover.js code [http://boxover.swazz.org] to create tooltips:          */
/*  This script requires the inclusion in the <head>...</head> section of each page of         */
/*  <script type="text/javascript" language="JavaScript" src="./scripts/boxover.js"></script>  */
/*  and altering the title of the HTML element you want the tooltip to appear over, such as    */
/*  in <span title="header=[h text] body=[b text]">T Text</span>                               */
/***********************************************************************************************/
function do_translate() {
document.write('<a href="' + translatedURL + '" title="header=[<img src=\'./img/info.gif\' style=\'vertical-align:middle\'>&nbsp;&nbsp;' + textLink + '] body=[' + translateMessage + '] cssbody=[dvbdy1] cssheader=[dvhdr1] fade=[on]"><font class="lang">' + targetLanguage + '</font>&nbsp;<img src="./img/' + flag + '"></a>');
}
function do_translatelink() {
document.write('<a href="' + translatedURL + '" title="header=[<img src=\'./img/info.gif\' style=\'vertical-align:middle\'>&nbsp;&nbsp;' + textLink + '] body=[' + textTip + '] cssbody=[dvbdy1] cssheader=[dvhdr1] fade=[on]">' + textLink + '</a>');
}
