function hideshow(id){
	if (!document.getElementById) return;
	if (document.getElementById(id).style.display=="none"){
		document.getElementById(id).style.display="";
		if(document.getElementById('img'+id)) document.getElementById('img'+id).src="/services/images/items/menuclose.gif";
	} else {
		document.getElementById(id).style.display="none";
		if(document.getElementById('img'+id)) document.getElementById('img'+id).src="/services/images/items/menuopen.gif";
	}
}
function hide(id){
	if (!document.getElementById) return;
	if (document.getElementById(id).style.display==""){
		document.getElementById(id).style.display="none";
		if(document.getElementById('img'+id)) document.getElementById('img'+id).src="/services/images/items/menuopen.gif";
	}
}
function confirmAction(x){ if(confirm('Are you sure?')==1) document.location.href=x; }
function insertTags(tagOpen, tagClose, sampleText) {
	var txtarea;
	if (document.WikiArticleCreate) {
		txtarea = document.WikiArticleCreate.PageContent;
	} else {
		// some alternate form? take the first one we can find
		var areas = document.getElementsByTagName('textarea');
		txtarea = areas[0];
	}
	var selText, isSample = false;

	if (document.selection  && document.selection.createRange) { // IE/Opera

		//save window scroll position
		if (document.documentElement && document.documentElement.scrollTop)
			var winScroll = document.documentElement.scrollTop
		else if (document.body)
			var winScroll = document.body.scrollTop;
		//get current selection  
		txtarea.focus();
		var range = document.selection.createRange();
		selText = range.text;
		//insert tags
		checkSelectedText();
		range.text = tagOpen + selText + tagClose;
		//mark sample text as selected
		if (isSample && range.moveStart) {
			if (window.opera)
				tagClose = tagClose.replace(/\n/g,'');
			range.moveStart('character', - tagClose.length - selText.length); 
			range.moveEnd('character', - tagClose.length); 
		}
		range.select();   
		//restore window scroll position
		if (document.documentElement && document.documentElement.scrollTop)
			document.documentElement.scrollTop = winScroll
		else if (document.body)
			document.body.scrollTop = winScroll;

	} else if (txtarea.selectionStart || txtarea.selectionStart == '0') { // Mozilla

		//save textarea scroll position
		var textScroll = txtarea.scrollTop;
		//get current selection
		txtarea.focus();
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		selText = txtarea.value.substring(startPos, endPos);
		//insert tags
		checkSelectedText();
		txtarea.value = txtarea.value.substring(0, startPos)
			+ tagOpen + selText + tagClose
			+ txtarea.value.substring(endPos, txtarea.value.length);
		//set new selection
		if (isSample) {
			txtarea.selectionStart = startPos + tagOpen.length;
			txtarea.selectionEnd = startPos + tagOpen.length + selText.length;
		} else {
			txtarea.selectionStart = startPos + tagOpen.length + selText.length + tagClose.length;
			txtarea.selectionEnd = txtarea.selectionStart;
		}
		//restore textarea scroll position
		txtarea.scrollTop = textScroll;
	} 

	function checkSelectedText(){
		if (!selText) {
			selText = sampleText;
			isSample = true;
		} else if (selText.charAt(selText.length - 1) == ' ') { //exclude ending space char
			selText = selText.substring(0, selText.length - 1);
			tagClose += ' '
		} 
	}

}
function writeMWtoolbar() {
	document.write("<a onclick=\"insertTags('\\\'\\\'\\\'','\\\'\\\'\\\'','Bold text');\"><img src='/services/images/wiki/button_bold.png' width='23' height='22' alt='Bold text' title='Bold text' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('\\\'\\\'','\\\'\\\'','Italic text');\"><img src='/services/images/wiki/button_italic.png' width='23' height='22' alt='Italic text' title='Italic text' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('[[',']]','Link title');\"><img src='/services/images/wiki/button_link.png' width='23' height='22' alt='Internal link' title='Internal link' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('[',']','http://www.example.com link title');\"><img src='/services/images/wiki/button_extlink.png' width='23' height='22' alt='External link (remember http:// prefix)' title='External link (remember http:// prefix)' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('\\n==','==\\n','Level 2 headline');\"><img src='/services/images/wiki/button_headline.png' width='23' height='22' alt='Headline text' title='Headline text' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('[[File:',']]','Example.jpg');\"><img src='/services/images/wiki/button_image.png' width='23' height='22' alt='Embedded file' title='Embedded file' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('[[Media:',']]','Example.ogg');\"><img src='/services/images/wiki/button_media.png' width='23' height='22' alt='File link' title='File link' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('\x3cmath\x3e','\x3c/math\x3e','Insert formula here');\"><img src='/services/images/wiki/button_math.png' width='23' height='22' alt='Mathematical formula (LaTeX)' title='Mathematical formula (LaTeX)' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('\x3cnowiki\x3e','\x3c/nowiki\x3e','Insert non-formatted text here');\"><img src='/services/images/wiki/button_nowiki.png' width='23' height='22' alt='Ignore wiki formatting' title='Ignore wiki formatting' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('','--~~~~','');\"><img src='/services/images/wiki/button_sig.png' width='23' height='22' alt='Your signature with timestamp' title='Your signature with timestamp' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('','\\n----\\n','');\"><img src='/services/images/wiki/button_hr.png' width='23' height='22' alt='Horizontal line' title='Horizontal line' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('<s>','</s>','Strike-through text');\"><img src='/services/images/wiki/button_strike.png' width='23' height='22' alt='Strike' title='Strike' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('','<br />\\n','');\"><img src='/services/images/wiki/button_enter.png' width='23' height='22' alt='Insert Break' title='Insert Break' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('<sup>','</sup>','Superscript text');\"><img src='/services/images/wiki/button_upper_letter.png' width='23' height='22' alt='Superscript' title='Superscript' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('<sub>','</sub>','Subscript text');\"><img src='/services/images/wiki/button_lower_letter.png' width='23' height='22' alt='Subscript' title='Subscript' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('<!-- ',' -->','Comment text');\"><img src='/services/images/wiki/button_hide_comment.png' width='23' height='22' alt='Insert hidden Comment' title='Insert hidden Comment' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('<blockquote>\\n','\\n</blockquote>','Quoted text');\"><img src='/services/images/wiki/button_blockquote.png' width='23' height='22' alt='Insert block of quoted text' title='Insert block of quoted text' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('','\\n{| class=\\\'wikitable\\\' border=\\\'1\\\'\\n|+ caption\\n|-\\n! header 1\\n! header 2\\n! header 3\\n|-\\n| row 1, cell 1\\n| row 1, cell 2\\n| row 1, cell 3\\n|-\\n| row 2, cell 1\\n| row 2, cell 2\\n| row 2, cell 3\\n|}\\n','');\"><img src='/services/images/wiki/button_insert_table.png' width='23' height='22' alt='Insert a table' title='Insert a table' style='cursor:pointer;' /></a>");
	document.write("<a onclick=\"insertTags('<ref>','</ref>','Insert footnote text here');\"><img src='/services/images/wiki/button_reflink.png' width='23' height='22' alt='Insert a referece' title='Insert a reference' style='cursor:pointer;' /></a>");
}