var browser = null;

function browserType() {
	browser = typeof(window.addEventListener) != 'undefined' ? 1 : (typeof(window.attachEvent) != 'undefined' ? 2 : 3); // 1 = no-ie, 2 = ie, 3 = old browser
}

// From http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function browserSize() {
	var width = 0, height = 0;
	if (typeof(window.innerWidth) != 'undefined') { // Non-IE
		width = window.innerWidth;
		height = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { // IE 6+ in 'standards compliant mode'
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { // IE 4 compatible
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	}
	return [width, height];
}

// From http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function windowScroll() {
	var x = 0, y = 0;
	if (typeof( window.pageYOffset ) != 'undefined') { // Netscape compliant
		y = window.pageYOffset;
		x = window.pageXOffset;
	} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) { // DOM compliant
		y = document.body.scrollTop;
		x = document.body.scrollLeft;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) { // IE6 standards compliant mode
		y = document.documentElement.scrollTop;
		x = document.documentElement.scrollLeft;
	}
	return [x, y];
}

function escapeHTMLEncode(str) {
	var div = document.createElement('div');
	var text = document.createTextNode(str);
	div.appendChild(text);
	return div.innerHTML;
}

function getElementsByClassName(tagName, className) {
	var elements = document.getElementsByTagName(tagName); // Get all the elements from the page of type tagName
	var classEls = new Array(); // Store the elements we find of className
	var index = 0;
	for (var i = 0; i < elements.length; i++) { // Cycle through the found tagName elements
		var obj = elements[i].className.split(" "); // Split up possible multiple classes
		var found = false;
		for (var p = 0; p < obj.length && !found; p++) {
			if (obj[p] == className) { // The found element has className
				classEls[index] = elements[i]; // Store the element
				found = true; // Break out of this loop
				index++;
			}
		}
	}
	return classEls;
}
