
function writeOption(param,name,text)
{
  document.write(
	  '<option value="'+name+'"'+((param==name) ? " selected" : "")+'>'+
		text+'</option>');
}

function unmangle(param)
{
	return param+unescape("%40")+"leafdigital"+"."+unescape("%63")+"om";
}

function selectionChanged()
{
  // Get chosen address
  var select=document.getElementById("address");
	var param=select.options[select.selectedIndex].value;
	
	// Update address link
	var email=document.getElementById("email");
	email.removeChild(email.firstChild);
	email.appendChild(document.createTextNode(unmangle(param)));
	email.setAttribute("href","mail"+"to"+unescape("%3a")+unmangle(param));
	
	// Update FAQs
	var faqs=document.getElementById("faqs");
	var faqsTarget=param+".html";
	switch(param)
	{
	  case "mindsi" :
	  case "nakedelves" :
	  case "sam" :
		case "quen" : 
		  faqsTarget="none.html";
			break;	
	}
	
	faqs.src=faqsTarget;
}

if(document.getElementById)
{
	document.write("<h2>Topic selector</h2>");
	
	// Get parameter if provided
	var param=window.location.search.split("?",2)[1];
	if(param)
		document.write('<p>The appropriate topic has been selected for you '+
			'below.</p>');
	else
	{
		document.write('<p>Please select a topic that you\'d like to email me '+
			'about.</p>');
		param="sam";
	}
			
	// Write the selection box
	document.write(
		'<select id="address" name="address" onchange="selectionChanged()">');

	writeOption(param,"leafdrums","leafDrums drum machine");
	writeOption(param,"leafchat","leafChat IRC client");
	writeOption(param,"mindsi","mind's:i IF system");
	writeOption(param,"sysex","SysEx Solution");
	writeOption(param,"software","Software (general)");
	writeOption(param,"fiction","Fiction / writing");
	writeOption(param,"nakedelves","Naked elves");
	writeOption(param,"sam","General contact (sam)");
	writeOption(param,"quen","General contact (quen)");

	document.write('</select>');
	
	document.write('<h2>Frequently asked questions</h2>'+
		'<p>I\'d appreciate if you could briefly check this list to see if '+
		'your question might be answered without having to email me.</p>'+
		'<iframe id="faqs" src="none.html">'+
		'<p>(Sorry - it looks like your browser doesn\'t support IFRAME tags, so I '+
		'can\'t show you the list; you\'ll have to just email me.)</p>'+	
		'</iframe>');
		
	document.write('<h2>Email address</h2>'+
		'<p>If you still need to contact me, please use the following address:</p>'+
		'<p><a id="email">(Whoops - this bit isn\'t working! See below)</a></p>'+
		'<p>Please give me a few days to reply. I reply to most email, unless '+
		'I don\'t understand it or it doesn\'t seem to need a reply.</p>');
	
	document.write('<h2>Page broken?</h2>'+
		'<p>If this page is broken and the address above doesn\'t appear correctly, that '+
		'probably indicates that your Web browser could use an upgrade. But, no '+
		'worries - just send your email to <em>sam</em> at this site '+
		'(<em>leafdigital</em> dot <em>com</em>). Make sure to let me know clearly what '+
		'you are writing about. For example, if it\'s about software, let me know '+ 
		'which program!</p>');
		
	selectionChanged();
}
else
{
	document.write('<div id="oldbrowser"><h2>Email address</h2>'+
		'<p>You are using a browser that doesn\'t support current Web standards, '+
		'so I can\'t display the email address '+
		'selector. Instead, just send your email to '+
		'<a href="mail'+'to'+unescape("%3a")+unmangle("sam")+'">'+
		unmangle("sam")+'</a>. '+
		'Make sure to let me know clearly what '+
		'you are writing about. For example, if it\'s about software, tell me '+ 
		'which program!</p></div>');		
}



