/* Fix to IE and Opera 8.2, which returns first element with name="id" or id="id".
 *
 * @link http://webbugtrack.blogspot.com/2007/08/bug-152-getelementbyid-returns.html
 **/
document.nativeGetElementById = document.getElementById;

document.getElementById = function(id) {
	var el = document.nativeGetElementById(id);
	
	if (el) {
		// Not a valid element!
		if (!el.attributes['id'] || el.attributes['id'].value != id) {
			// The non-standard, document.all array has keys for all name'd,
			// and id'd elements. Start at one, because we know the first match is wrong.
			for (var i = 1; i < document.all[id].length; i++) {
				// Found first element with correct ID
				if (document.all[id][i].attributes['id'] && document.all[id][i].attributes['id'].value == id) {
					return document.all[id][i];
				}
			}
		}
	}
	
	return el;
}

