function $(v){return(document.getElementById(v))}function getEventSrc(e){return window.event?window.event.srcElement:e.target}function CancelEvent(e){if((typeof(e)=="undefined")&&(typeof(window.event)!="undefined")){e=window.event}if(typeof(window.event)!="undefined"){e.cancelBubble=true;}else{e.stopPropagation();}}function AjaxCreate(){try{return new XMLHttpRequest()}catch(e){}try{return new ActiveXObject("MSXML2.XMLHTTP")}catch(e){}try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}return false}function AjaxExecute(url,data,funct){var xhr=AjaxCreate();xhr.onreadystatechange=function(){if((xhr.readyState==4)&&(xhr.status==200)){funct(xhr.responseText)}};xhr.open("POST",url,true);xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xhr.send(data)}function AjaxDummy(data){}function ltrim(s){return s.replace(/^\s*/,"")}function rtrim(s){return s.replace(/\s*$/,"")}function trim(s){return rtrim(ltrim(s))}function setFavorite(iURL,iTitle){if(navigator.appVersion.indexOf("Mac",0)>0){alert("This function is not available on Macintosh.\n\nUse instead the key combination \"Apple-D\".");return}if((navigator.appName.indexOf("Microsoft",0)>=0)&&(parseInt(navigator.appVersion)>=4)){window.external.AddFavorite(iURL,iTitle)}else{alert("This function is only available on Internet Explorer.\n\nFor Netscape, you can use instead the key combination \"Control-D\".");}}function showHelp(iShow){$("help").style.display=(iShow?"block":"none");return false}function __Query(iQueryId,iPath){window.location.href="http://"+window.location.hostname+iPath+"/"+$("__query_"+iQueryId).value;return false;}





var bJava = true;



function displayNoJava()
	{
	return ;		/////////


	bJava = false;

	if (iLanguage!="fr")
		iLanguage ="en";

	if (iLanguage=="fr")
			iMessage = "Java est nécessaire pour faire fonctionner ce site.\nVoulez-vous installer la dernière version de Java ?";
	  else	iMessage = "Java is required to run this website.\nDo you want to install latest Java Runtime Environment ?";

	if (confirm(iMessage))
		{
		window.open ("http://www.java.com/"+iLanguage+"/download/", "ePlanetPopUp", "left=100,top=100,width=900,height=600,scrollbars=yes");
		}
	}



function noJava()
	{
	return false;	//////////


	if (!navigator.javaEnabled()
	 || !bJava )
		{
		displayNoJava(iLanguage);

		return true;
		}

	return false;
	}






var morse_	;
var wpm_	;
var fwpm_	;
var pitch_	;
var volume_	;

var isPaused;





function tieSpeeds()
	{
	if (noJava())	return;

	$('fwpm').value = Math.min (parseInt($('fwpm').value ),
								parseInt($('wpm' ).value ));
	}



function translate()
	{
	if (noJava())	return;

	var input	= $('input').value;
	var output	= String($('morse').convert(removeAccents(input)));

	$('output').value = output;

	return ($('morse').isMorse(output)) ? output : input;
	}



function play()
	{
	if (noJava())	return;

	var morse	= translate();
	var wpm		= parseInt	($('wpm'	).value);
	var fwpm	= parseInt	($('fwpm'	).value);
	var pitch	= parseInt	($('pitch'	).value);
	var volume	= parseFloat($('volume'	).value);

	if (morse	!= morse_
	 || wpm		!= wpm_
	 || fwpm	!= fwpm_
	 || pitch	!= pitch_
	 || volume	!= volume_)
		{
		morse_	= morse;
		wpm_	= wpm;
		fwpm_	= fwpm;
		pitch_	= pitch;
		volume_	= volume;

		reset();

		var times = $('morse').morse2timings (morse, wpm, fwpm);

		$('morse').makeSample (times, pitch, volume);
		}


	if (!isPaused)
		{
		reset();
		}

	$('morse').playSample();

	isPaused = false;
	}




function pause()	{ if (noJava())	{return;}	$('morse').stopSample ();  isPaused = true ; }
function reset()	{ if (noJava())	{return;}	$('morse').resetSample();  isPaused = false; }





function increase(o, step, max)
	{
	if (noJava())	return;

	var v = $(o).value;

	if (step<1)
			{ v = Math.round (10 *(parseFloat(v) + step)) / 10;
			  v = v.toFixed(1);			}
	  else	{ v = parseInt (v) + step;	}

	if (v <= max)
		{
		$(o).value = v;

		if ((o=='wpm' )
		 || (o=='fwpm'))  {tieSpeeds();}
		}
	}



function decrease(o, step, min)
	{
	if (noJava())	return;

	var v = $(o).value;

	if (step<1)
			{ v = Math.round (10 *(parseFloat(v) - step)) / 10;
			  v = v.toFixed(1);			}
	  else	{ v = parseInt (v) - step;	}

	if (v >= min)
		{
		$(o).value = v;

		if ((o=='wpm' )
		 || (o=='fwpm'))  {tieSpeeds();}
		}
	}




function removeAccents(s)
	{
	return s.replace(/[àâä]/gi,	"a")
			.replace(/[éèêë]/gi,"e")
			.replace(/[îï]/gi,	"i")
			.replace(/[ôö]/gi,	"o")
			.replace(/[ùûü]/gi,	"u");
	}




