﻿<public:attach event="oncontentready" onevent="init()" />
<script type="text/javascript">
	/*
	* This will make each level of nested quotes alternate between
	* single and double quotes.
	* Reference: http://en.wikipedia.org/wiki/Quotation_mark
	*/
	var quotes = {
		even: { open: 0x00AB, close: 0x00BB },
		odd: { open: 0x2018, close: 0x2019 }
	};
	/* Returns the level that a tag is nested within itself  */
	function getNestedLevel(tagName, node, cLevel) {
		var level = 0;
		var parent = node.parentNode;
		if (parent != null) {
			if (node.parentNode.tagName == tagName) {
				level++;
			}
			level += getNestedLevel(tagName, parent, level);
		}
		return level;
	}
	function init() {
		var nestedLevel = getNestedLevel(this.tagName, this, 0);
		var type = (nestedLevel % 2 == 0) ? "even" : "odd";
		var openQ = document.createTextNode(
		String.fromCharCode(quotes[type].open));
		var closeQ = document.createTextNode(
		String.fromCharCode(quotes[type].close));
		this.insertBefore(openQ, this.firstChild);
		this.appendChild(closeQ);
	}
</script>
