 // JavaScript Document

var currentLang;	// Contains current language use by URL  pctimewatch.com/{currentLang}/myPage.htm

function langMgr_getLangCode()
{
	var thePath = ''; // Contains url from current page, at the end the language
	var indexLastSlash = -1;
	
	thePath = document.location.pathname;
	
	// host,hostname,href,pathname.port,protocol,search
	// assign() reload() replace()
	
	// If the full URL is http:www.pctimewatch.com/fr/pctwoverview.htm
	// thePath is equal to  /fr/pctwoverview.htm
	// or
	// If the full URL is http:www.pctimewatch.com/test/fr/pctwoverview.htm
	// thePath is equal to  /test/fr/pctwoverview.htm
	
	// Find the last / in string
	indexLastSlash = thePath.lastIndexOf( "/", thePath.length - 1); // Remove 1 to be sure if url ends with / (should not happens...)
	
	thePath = thePath.substr(1,indexLastSlash-1);

	indexLastSlash = thePath.lastIndexOf( "/", thePath.length ); // Find last /
	thePath = thePath.substr( indexLastSlash+1);
	currentLang = thePath;
	 
	return ( thePath );
}

// menuItem_EN give menu entry in english to get the localization in current displayed language (Not sensible to case)
function entryLocalized ( menuItem_EN )
{
	var result = '';
	var myLang;
	
	//myLang = langMgr_getLangCode();
	//myLang = myLang.toLowerCase();
	myLang = currentLang;
	
	switch( menuItem_EN.toLowerCase() )
	{
		// *******************************************************		
		// Menu item OVERVIEW
		case 'overview':
		{
			switch ( myLang )
			{
				//case 'en':
				//	document.write ('Overview');
				//break;
				
				case 'fr':
					document.write ('Description');
				break;
				
				case 'de':
					document.write ('Übersicht');
				break;
				
				case 'it':
					document.write ('Panoramica');
				break;
				
				case 'es':
					document.write ('Sumario');
				break;
				
				case 'ptbr':
					document.write ('Visão geral');
				break;
				
				case 'ptib':
					document.write ('Descrição geral');
				break;
				
				default: // anglais
					document.write ('Overview');
				break;
				
				
			}
			break;

		}
		// *******************************************************
		
		
		
		// *******************************************************		
		// Menu item FEATURES
		case 'features':
		{
			switch ( myLang )
			{
				//case 'en':
				//	document.write ('Features');
				//break;
				
				case 'fr':
					document.write ('Fonctions');
				break;
				
				case 'de':
					document.write ('Funktionen');
				break;

				case 'it':
					document.write ('Caratteristiche');
				break;
				
				case 'es':
					document.write ('Características');
				break;
				
				case 'ptbr':
					document.write ('Características');
				break;
				
				case 'ptib':
					document.write ('Características');
				break;
				
				default: // anglais
					document.write ('Features');
	

			}
			break;

		}
		
		// *******************************************************
		
		
		// *******************************************************
		// Menu item SUPPORT
		case 'support':
		{
			switch ( myLang )
			{				
				case 'fr':
					document.write ('Support');
				break;
				
				case 'de':
					document.write ('Support');
				break;

				case 'it':
					document.write ('Supporto');
				break;
				
				case 'es':
					document.write ('Apoyo Tècnico');
				break;
				
				case 'ptbr':
					document.write ('');
				break;
				
				case 'ptib':
					document.write ('');
				break;
				
				default: // anglais
					document.write ('Support');	

			}
			break;

		}
		// *******************************************************
		
		

		
		// *******************************************************
		// Menu FREEWARE
		case 'freeware':
		{
			switch ( myLang )
			{				
				case 'fr':
					document.write ('Graticiel / Freeware');
				break;
				
				case 'de':
					document.write ('Freeware');
				break;

				case 'it':
					document.write ('Freeware');
				break;
				
				case 'es':
					document.write ('Freeware');
				break;
				
				case 'ptbr':
					document.write ('');
				break;
				
				case 'ptib':
					document.write ('');
				break;
				
				default: // anglais
					document.write ('Freeware');	

			}
			break;

		}
		// *******************************************************
		
		
		
		// *******************************************************
		// Menu DOWNLOAD
		case 'download':
		{
			switch ( myLang )
			{				
				case 'fr':
					document.write ('Télécharger');
				break;
				
				case 'de':
					document.write ('Download');
				break;

				case 'it':
					document.write ('Scaricalo');
				break;
				
				case 'es':
					document.write ('Descargar');
				break;
				
				case 'ptbr':
					document.write ('');
				break;
				
				case 'ptib':
					document.write ('');
				break;
				
				default: // anglais
					document.write ('Download');	

			}
			break;

		}
		// *******************************************************
		
		
		// *******************************************************
		// Menu BUY
		case 'buy':
		{
			switch ( myLang )
			{				
				case 'fr':
					document.write ('Acheter');
				break;
				
				case 'de':
					document.write ('Kaufen');
				break;

				case 'it':
					document.write ('Ordinare');
				break;
				
				case 'es':
					document.write ('Comprar');
				break;
				
				case 'ptbr':
					document.write ('Ordenar');
				break;
				
				case 'ptib':
					document.write ('Comprar');
				break;
				
				default: // anglais
					document.write ('Buy');	

			}
			break;

		}


	// *******************************************************
		// Menu BUY
		/*
		case 'buy':
		{
			switch ( myLang )
			{				
				case 'fr':
					document.write ('Acheter');
				break;
				
				case 'de':
					document.write ('Kaufen');
				break;

				case 'it':
					document.write ('Ordinare');
				break;
				
				case 'es':
					document.write ('Encargar');
				break;
				
				case 'ptbr':
					document.write ('Ordenar');
				break;
				
				case 'ptib':
					document.write ('Comprar');
				break;
				
				default: // anglais
					document.write ('Buy');	

			}
			break;

		}
	*/
		// *******************************************************
		
		case 'aboutpljsoft':
		{
			switch ( myLang )
			{				
				case 'fr':
					document.write ('PLJ Soft');
				break;
				
				case 'de':
					document.write ('PLJ Soft');
				break;

				case 'it':
					document.write ('PLJ Soft');
				break;
				
				case 'es':
					document.write ('PLJ Soft');
				break;
				
				case 'ptbr':
					document.write ('PLJ Soft');
				break;
				
				case 'ptib':
					document.write ('PLJ Soft');
				break;
				
				default: // anglais
					document.write ('PLJ Soft');	

			}
			break;
			
		}

		// *******************************************************
		
		case 'faq':
		{
			switch ( myLang )
			{				
				case 'fr':
					document.write ('Foire aux questions');
				break;
				
				case 'de':
					document.write ('F.A.Q.');
				break;

				case 'it':
					document.write ('Domande frequenti / F.A.Q.');
				break;
				
				case 'es':
					document.write ('Preguntas frecuentes (FAQ)');
				break;
				
				case 'ptbr':
					document.write ('F.A.Q.');
				break;
				
				case 'ptib':
					document.write ('F.A.Q.');
				break;
				
				default: // anglais
					document.write ('F.A.Q.');

			}
			break;
			
		}
		
			// *******************************************************
		
		case 'affiliates':
		{
			switch ( myLang )
			{				
				case 'fr':
					document.write ('Programme d\'affiliation');
				break;
				
				case 'de':
					document.write ('Affiliate program');
				break;

				case 'it':
					document.write ('Affiliate program');
				break;
				
				case 'es':
					document.write ('Affiliate program');
				break;
				
				case 'ptbr':
					document.write ('Affiliate program');
				break;
				
				case 'ptib':
					document.write ('Affiliate program');
				break;
				
				default: // anglais
					document.write ('Affiliate program');	

			}
			break;
			
		}
		
		// *******************************************************
		
		case 'doc_and_tutorial':
		{
			switch ( myLang )
			{				
				case 'fr':
					document.write ('Tutoriels & documentation');
				break;
				
				case 'de':
					document.write ('Tutorial & Dokumentation');
				break;

				case 'it':
					document.write ('Tutorial & Documentazione');
				break;
				
				case 'es':
					document.write ('Tutoriales y Documentación');
				break;
				
				case 'ptbr':
					document.write ('Tutorial');
				break;
				
				case 'ptib':
					document.write ('Tutorial');
				break;
				
				default: // anglais
					document.write ('Tutorials & documentation');	

			}
			break;
			
		}
		// *******************************************************
	
	}
}

	// Return current page name in lower case with extension: i.e. pctwbuy.htm
	function getCurrentPageName ()
	{
		var thePath = ""; // Current path
		var lastDash = 0;
		var pageName = "";
		

		try {
			thePath = document.location.href; // 
			lastDash = thePath.lastIndexOf('/');
			pageName = thePath.substring ( lastDash + 1,thePath.length );
			
			// Remove parameter like ?version=....
			lastDash = pageName.lastIndexOf('?');
			if ( lastDash != -1 )
			{
				pageName = pageName.substring ( 0 , lastDash );
			}
			
		}
		catch ( err )
		{
			 ; // Handle any error here
		}
		return ( pageName.toLowerCase() )			

	}
	
	// Build menu Language depending of current page location
	function menu_buildLanguage ()
	{
		var match_language = /\/(fr|en|de|es|it|ptbr|ptib)\//gi;

		
		var thePath = ""; // Current path
		var asCurrentLangInURL; // Array string Current lang in URL
		var currentLangInURL; // Current lang in URL
		var posOfLangInURL;
		var url_left;
		var url_right;
		
		try
		{
			thePath = document.location.href; // http://pb-x86.local/~louisthoumin/sandbox/fr/pctwoverview.htm
			
			asCurrentLangInURL = thePath.match ( match_language );
			
			if ( asCurrentLangInURL.length > 0 )
			{
				currentLangInURL = asCurrentLangInURL[asCurrentLangInURL.length -1];
				posOfLangInURL = thePath.lastIndexOf( currentLangInURL );
				//thePath.lastIndexOf(searchstring, start)
				if ( posOfLangInURL >= 0 )
				{
					url_left = thePath.substring ( 0 , posOfLangInURL );   // http://pb-x86.local/~louisthoumin/sandbox
					url_right = thePath.substring ( posOfLangInURL + currentLangInURL.length ); // pctwoverview.htm
					
					// Build menu itself
					
					document.write ( '<dl class="dropdown">' );
					document.write ( '<dt id="mLANG-ddheader" onMouseOver="ddMenu(\'mLANG\',1)" onMouseOut="ddMenu(\'mLANG\',-1)">' );
					switch ( currentLangInURL )
					{
						case '/fr/':
							document.write ( '<a href="../fr/' + url_right + '"><img src="../picts/flags_country/FR.png" alt="FR" width="14" height="14" align="absmiddle" /> Français</a>');
						break;
						
						case '/de/':
							document.write ( '<a href="../de/' + url_right + '"><img src="../picts/flags_country/DE.png" alt="DE" width="14" height="14" align="absmiddle" /> Deutsch</a>');
						break;
	
						case '/it/':
							document.write ( '<a href="../it/' + url_right + '"><img src="../picts/flags_country/IT.png" alt="IT" width="14" height="14" align="absmiddle" /> Italiano</a>');
						break;

						case '/es/':
							document.write ( '<a href="../es/' + url_right + '"><img src="../picts/flags_country/ES.png" alt="ES" width="14" height="14" align="absmiddle" /> Español</a>');
						break;
					
						default: // If not found, use english
							document.write ( '<a href="../en/' + url_right + '"><img src="../picts/flags_country/US.png" alt="EN" width="14" height="14" align="absmiddle" /> English</a>');
						break;
					}
					
					document.write ( '</dt>' );
					
					document.write ( '<dd id="mLANG-ddcontent" onMouseOver="cancelHide(\'mLANG\')" onMouseOut="ddMenu(\'mLANG\',-1)">' );
					document.write ( '<ul>' );
					
					// English
					document.write ( '<li onClick="javascript:window.location=\'en/' + url_right + '\';">' );
					<!-- document.write ( '<a href="../en/' + url_right + '" title="English">English</a>' ); -->
					document.write ( '<a href="../en/' + url_right + '"><img src="../picts/flags_country/US.png" alt="English" width="14" height="14" align="absmiddle" title="English" /> English</a>' );
					
					
					document.write ( '</li>' );
					
					// Français
					document.write ( '<li onClick="javascript:window.location=\'fr/' + url_right + '\';">' );
					<!-- document.write ( '<a href="../fr/' + url_right + '" title="Français">Français</a>' );-->
					document.write ( '<a href="../fr/' + url_right + '"><img src="../picts/flags_country/FR.png" alt="Français" width="14" height="14" align="absmiddle" title="Français" /> Français</a>' );					
					document.write ( '</li>' );
					
					// Deutsch
					document.write ( '<li onClick="javascript:window.location=\'de/' + url_right + '\';">' );
					<!--document.write ( '<a href="../de/' + url_right + '" title="Deutsch">Deutsch</a>' );-->
					document.write ( '<a href="../de/' + url_right + '"><img src="../picts/flags_country/DE.png" alt="Deutsch" width="14" height="14" align="absmiddle" title="Deutsch" /> Deutsch</a>' );	
					document.write ( '</li>' );
					
					//  Italien
					document.write ( '<li onClick="javascript:window.location=\'it/' + url_right + '\';">' );
					<!--document.write ( '<a href="it/' + url_right + '" title="Italiano">Italiano</a>' );-->
					document.write ( '<a href="../it/' + url_right + '"><img src="../picts/flags_country/IT.png" alt="Italiano" width="14" height="14" align="absmiddle" title="Italiano" /> Italiano</a>' );
					document.write ( '</li>' );
					

					// Espagnol
					document.write ( '<li onClick="javascript:window.location=\'es/' + url_right + '\';">' );
					<!--document.write ( '<a href="es/' + url_right + '" title="Español">Español</a>' );-->
					document.write ( '<a href="../es/' + url_right + '"><img src="../picts/flags_country/ES.png" alt="Español" width="14" height="14" align="absmiddle" title="Español" /> Español</a>' );
					document.write ( '</li>' );
/* Remove other languages until end of update					
					// Portugais Bresil
					document.write ( '<li onClick="javascript:window.location=\'ptbr/' + url_right + '\';">' );
					<!--document.write ( '<a href="ptbr/' + url_right + '" title="Português (Brasil)">Português (Brasil)</a>' );-->
					document.write ( '<a href="../ptbr/' + url_right + '"><img src="../picts/flags_country/BR.png" alt="Português (Brasil)" width="14" height="14" align="absmiddle" title="Português (Brasil)" /> Português (Brasil)</a>' );
					document.write ( '</li>' );
					
					// Portugais Portugal
					document.write ( '<li onClick="javascript:window.location=\'ptib/' + url_right + '\';">' );
					<!--document.write ( '<a href="ptib/' + url_right + '" title="Português (Portugal)">Português (Portugal)</a>' );-->
					document.write ( '<a href="../ptib/' + url_right + '"><img src="../picts/flags_country/PT.png" alt="Português (Portugal)" width="14" height="14" align="absmiddle" title="Português (Portugal)" /> Português (Portugal)</a>' );
					document.write ( '</li>' );
					
	*/				
					// Close tags
					document.write ( '</ul>' );
					document.write ( '</dd>' );
					document.write ( '</dl>' );

				}
			}
			
		} // try
		
		catch( err )
		{
			// Handle errors here
			;
		}
		
		
	}
	
	
function buildMainMenu ()
{
	// --------------------------------------
	// Menu PC TimeWatch
	// --------------------------------------
	document.write ( '<nav class="contentbox">' );
	//document.write ( '<table border="0" cellspacing="0" style="max-width: 880px;">' );
	document.write ( '<table border="0" cellspacing="0">' );
	document.write ( '<tr>' );
	document.write ( '<td>');
	document.write ( '<dl class="dropdown">');
	document.write ( '<dt id="mPCTW-ddheader" onMouseOver="ddMenu(\'mPCTW\',1)" onMouseOut="ddMenu(\'mPCTW\',-1)"><a href="pctwoverview.htm" class="tab">PC TimeWatch</a></dt>');
	document.write ( '<dd id="mPCTW-ddcontent" onMouseOver="cancelHide(\'mPCTW\')" onMouseOut="ddMenu(\'mPCTW\',-1)">' );
	document.write ( '<ul>' );
	document.write ( '<li onClick="javascript:window.location=\'pctwoverview.htm\';"><a href="pctwoverview.htm" title="PC TimeWatch Overview"><script language="javascript" type="text/javascript">entryLocalized("overview" );</script></a></li>' );
	document.write ( '<li onClick="javascript:window.location=\'pctwfeatures.htm\';"><a href= "pctwfeatures.htm" title="Features"><script language="javascript" type="text/javascript">entryLocalized("features" );</script></a></li>' );
	
	document.write ( '<li onClick="javascript:window.location=\'pctwsupport.htm\';"><a href="pctwsupport.htm" title="Support"><script language="javascript" type="text/javascript">entryLocalized("support" );</script></a></li>' );
	
	
	document.write ( '<li onClick="javascript:window.location=\'pctwdownload.htm\';"><a href="pctwdownload.htm" title="Try PC TimeWatch"><script language="javascript" type="text/javascript">entryLocalized("download" );</script></a></li>' );

	
	document.write ( '</ul>' );
	document.write ( '</dd>' );
	document.write ( '</dl>' );
	document.write ( '</td>' );

	// --------------------------------------
	// Separator |
	// --------------------------------------
	document.write ( '<td>|</td>' );
	
	// --------------------------------------
	// Menu Freeware
	// --------------------------------------
	document.write ( '<td><a href="pctwfreeware.htm" onClick="javascript:window.location=\'pctwfreeware.htm\';"><script language="javascript" type="text/javascript">entryLocalized("freeware" );</script>' );
	document.write ( '</a></td>' );

	// --------------------------------------
	// Separator |
	// --------------------------------------
	document.write ( '<td>|</td>' );
	
	// --------------------------------------
	// Menu Download
	// --------------------------------------
	document.write ( '<td><a href="pctwdownload.htm" onClick="javascript:window.location=\'pctwdownload.htm\';"><script language="javascript" type="text/javascript">entryLocalized("download" );</script></a></td>' );


	// --------------------------------------
	// Separator |
	// --------------------------------------
	document.write ( '<td>|</td>' );

	// --------------------------------------
	// Menu Buy
	// --------------------------------------
	
    document.write ( '<td><a href="pctwbuy.htm" onClick="javascript:window.location=\'pctwbuy.htm\';"><script language="javascript" type="text/javascript">entryLocalized("buy" );</script></a></td>' );
	
	
	// --------------------------------------
	// Separator |
	// --------------------------------------
	document.write ( '<td>|</td>' );
	
	
	// --------------------------------------
	// Menu Languages
	// --------------------------------------
	document.write ( '<td><script language="javascript" type="text/javascript">menu_buildLanguage();</script></td>' );

	// --------------------------------------
	// Close Row and table
	// --------------------------------------
	document.write ( '</tr></table>' );
	
}
