// --------------------------------------------------------------------------------
// ow_ui.js
// Travis Musika 11-Apr-2008
// Contains various useful user-interface scripts.
// --------------------------------------------------------------------------------
///<reference path="ow_util.js">

// --- Functions and variables. ---
OneWeb.UI = {};

///#region TabControl

OneWeb.UI.TabControl = function (headerId, containerId) {
	this.headerId = headerId;
	this.containerId = containerId;
	this.tabIds = [];
	this.tabs = [];
	this.sections = [];
	this.tablist = null;
	this.container = null;
}
OneWeb.UI.TabControl.controls = { };
OneWeb.UI.TabControl.tabHeaderClassRx = new RegExp("(^|\\s)ow_tab_container(\\s|$)");
OneWeb.UI.TabControl.tabListClassRx = new RegExp("(^|\\s)ow_tab_nav(\\s|$)");
OneWeb.UI.TabControl.tabSectionClassRx = new RegExp("(^|\\s)ow_tab_section(\\s|$)");

OneWeb.UI.TabControl.prototype = {
	// type member, points to the object type for static members
	"type": OneWeb.UI.TabControl,
	
	// toggleTab
	/// <summary>Toggle the current tab</summary>
	"toggleTab": function (tabId) {

		if (this.tablist != null) {
			for (var i=0; i<this.tabs.length; i++) {		  
				if (this.tabs[i].getAttribute("tabid") == tabId) {
					this.tabs[i].className = "active";
					this.sections[i].style.display="block";
				} else {
					this.tabs[i].className = "";
					this.sections[i].style.display="none";
				}
			}
		}
		this.currentTab = tabId;
		return false;
	},

	"clickTab": function (e) {
		if (!e) var e = window.event;
		if (e.target) elm = e.target;
		else elm = e.srcElement;
		
		while (elm.tagName.toLowerCase() != "li") elm = elm.parentNode;

		var tabid;
		// pass the event on to the tab object
		if (elm != null) {
			tabid = elm.getAttribute("tabid");
			
			while (elm.tagName.toLowerCase() != "div" || typeof(OneWeb.UI.TabControl.controls[elm.id]) == "undefined") elm = elm.parentNode;
			
			if (elm != null)
				OneWeb.UI.TabControl.controls[elm.id].toggleTab(tabid);
		}
		if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; }
		return false;
	},

	// initialize
	/// <summary>Initializes the tabs</summary>
	"initialize": function (currentTabId) {
		try {
			var lists = document.getElementById(this.headerId).getElementsByTagName("ul");
			for (var i = 0; i < lists.length; i++) {
				if (this.type.tabListClassRx.test(lists[i].className)) {
					this.tablist = lists[i];
					break;
				}
			}
			if (this.tablist != null) {
				this.tabs = this.tablist.getElementsByTagName("li");
			}
		} catch (e) {
			// tab list not found
			return;
		}
		
		this.container = document.getElementById(this.containerId);
		if (this.container != null) {
			// find the tab sections and get their id's
			var divs = this.container.getElementsByTagName("div");
			var i = -1;
			for (div in divs) {
				div = divs[div];
				if (this.type.tabSectionClassRx.test(div.className)) {
					// found a tab section
					i++;
					if (div.getAttribute("id")=="") 
						div.setAttribute("id", this.containerId + "_" + i);
					this.tabIds.push(div.id);
					this.sections.push(div);
					// attach the onclick handler
					if (this.tabs.length > i && this.tabs[i] != null) {
						var li = this.tabs[i];
						var a = null;
						li.setAttribute("tabid", div.id);
						a = li.getElementsByTagName("a").item(0);
						if (a != null) {
						    a.href = "javascript:void(0);";
							OneWeb.Util.addEvent(a, "click", this.clickTab);
						}	
					}
				}
			}
		} else {
			// no container
			return;
		}
		// add the tabcontrol to the static list
		this.type.controls[this.headerId] = this;
		if (this.sections.length > 0) {
			if (currentTabId != null) 
				this.toggleTab(currentTabId);
			else
				this.toggleTab(this.tabIds[0]);
		}
	}
};

///#endregion

///#region PairedDropDownController

OneWeb.UI.PairedDropDownController = function (parentId, childId, attributeName) {
	this.parent = document.getElementById(parentId);
	this.child = document.getElementById(childId);
	this.attributeName = attributeName;
	this.options = null;
}
OneWeb.UI.PairedDropDownController.controllers = { };

OneWeb.UI.PairedDropDownController.prototype = {
	// type member, points to the object type for static members
	"type": OneWeb.UI.PairedDropDownController,

	// updateChild
	/// <summary>Reset the child options</summary>
	"updateChild": function () {

		if (this.parent && this.child) {
			this.child.options.length = 0;

			var opts = this.options[this.parent.options[this.parent.selectedIndex].value];
			
			// add the Select element
			if (this.parent.selectedIndex != 0)
				this.child.options.add(this.options[""][""]);
			
			if (opts) {
				for (var i in opts) 
					this.child.options.add(opts[i]);
				if (this.parent.selectedIndex != 0 && this.child.options.length != 0) {
					this.child.focus();
				}
			}
		}

		return false;
	},

	"changeItem": function (e) {
		if (!e) var e = window.event;
		if (e.target) elm = e.target;
		else elm = e.srcElement;

		var parentId;
		// pass the event on to the tab object
		if (elm != null) {
			parentId = elm.id;
			OneWeb.UI.PairedDropDownController.controllers[elm.id].updateChild();
		}
		if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; }
		return false;
	},

	// initialize
	/// <summary>Initializes the tabs</summary>
	"initialize": function () {
		
		// set up the general/specific item options
		if (this.parent != null && this.child != null) {
			
			this.options = new Object();

			var parentVal, childOpt;
			for (var i = 0; i < this.parent.options.length; i++) {
				parentVal = this.parent.options[i].value;
				if (this.options[parentVal] == null) 
					this.options[parentVal] = new Object();
			}
			for (var i = 0; i < this.child.options.length; i++) {
				childOpt = this.child.options[i];
				parentVal = childOpt.getAttribute(this.attributeName);
				if (parentVal == null && i == 0)
					parentVal = "";
				if (parentVal != null && this.options[parentVal] != null && this.options[parentVal][childOpt.value] == null)
					this.options[parentVal][childOpt.value] = childOpt;
			}
			this.type.controllers[this.parent.id] = this;

			// attach the change event handler
			OneWeb.Util.addEvent(this.parent, "change", this.changeItem, false);

			// do the initial call for the listbox to set up the Select element
			this.updateChild();

		}
	}
};

///#endregion

///#region ProgressBar

OneWeb.UI.ProgressBar = function(divId, options) {
    if (typeof (divId.innerHTML) !== "undefined")
        this.element = divId;
    else
        this.element = document.getElementById(divId);
    if (!this.element)
        return;
    this.element.className = this.type.progressContainerClass;

    this.bar = document.createElement("div");
    this.bar.className = this.type.progressBarClass;

    this.element.appendChild(this.bar);
    this.options = options;

    var lower = 0;
    this.type.prototype.getLowerBound = function() { return lower; };
    this.type.prototype.setLowerBound = function(value) { if (value <= upper) lower = value; };

    var upper = 100;
    this.type.prototype.getUpperBound = function() { return upper; };
    this.type.prototype.setUpperBound = function(value) { if (value >= lower) upper = value; };
    this.type.prototype.setBounds = function(lbound, ubound) { if (lbound >= ubound) { lower = lbound; upper = ubound; } };

    var current = 0;
    this.type.prototype.getCurrent = function() { return current; }
    this.type.prototype.setCurrent = function(value) { if (value === null || (value >= lower && value <= upper)) current = value; }

    var currentSpin = 0;
    this.type.prototype.getCurrentSpin = function() { return currentSpin; }
    this.type.prototype.setCurrentSpin = function(value) { if (!isNaN(value)) currentSpin = value%100; }

    this.text = null;
    this.orientation = "horizontal";
    this.spin = false;
    if (options !== null) {
        if (typeof (options.orientation) !== "undefined") {
            if (options.orientation === "vertical")
                this.orientation = "vertical";
            else
                this.orientation = "horizontal";
        }
        if (typeof (options.spin) == "boolean")
            this.spin = options.spin;
        if (typeof (options.overlay) !== "undefined") {
            this.overlay = document.createElement("img");
            this.overlay.setAttribute("src", options.overlay);
            this.bar.appendChild(this.overlay);
        }
        if (typeof (options.text) !== "undefined") {
            this.text = document.createElement("span");
            this.text.className = this.type.progressTextClass;
            if (options.text === "inside") {
                this.bar.appendChild(this.text);
            } else {
                this.element.appendChild(this.text);
            }
        }
    }
    this.update();
}
OneWeb.UI.ProgressBar.progressBarClass = "ow_progressBar";
OneWeb.UI.ProgressBar.progressTextClass = "ow_progressText";
OneWeb.UI.ProgressBar.progressContainerClass = "ow_progressBarContainer";

OneWeb.UI.ProgressBar.prototype = {
    // type member, points to the object type for static members
    "type": OneWeb.UI.ProgressBar,
    "set": function(value) {
        this.setCurrent(value);
        this.update();
    },
    "getText": function(value) {
        return (this.text === null) ? null : this.text.innerHTML;
    },
    "setText": function(value) {
        if (this.text !== null) {
            this.text.innerHTML = value;
        }
    },
    "update": function() {
        if (this.spin)
            this.setCurrentSpin((this.getCurrentSpin() + 10));  // add a fifth-rate spin to the graphic.
        // regular value
        var pos, spin, text;
        if (this.getCurrent() === null) {
            pos = 0;
            switch (this.getText()) {
                case "/": text = "-"; pos = 0; break;
                case "-": text = "\\"; pos = 0; break;
                case "\\": text = "|"; pos = 0; break;
                case "|": text = "/"; pos = 0; break;
                default: text = "-"; break;
            }
        } else if (this.getUpperBound() !== this.getLowerBound()) {
            var percent = ((this.getCurrent() - this.getLowerBound()) * 100) / (this.getUpperBound() - this.getLowerBound());
            pos = (100 - percent);
            text = (Math.round(percent) + "%");
        }
        spin = this.getCurrentSpin();
        if (this.orientation == "horizontal")
            this.bar.style.backgroundPosition = pos + "% " + spin + "%";
        else
            this.bar.style.backgroundPosition = spin + "% " + pos + "%";
        this.setText(text);
    },
    "initialize": function() {

    }
}

///#endregion

///#region TextResizer object definition

// constructor function
OneWeb.UI.TextResizer = function(config) {
	///<param name="config" type="text_config">Configuration of the text resizer widget</param>
	this.smaller = document.getElementById(config.smaller_id);
	this.larger = document.getElementById(config.larger_id);
	this.resetter = config.reset_id ? document.getElementById(config.reset_id) : null;

	this.link = document.getElementById(config.stylesheet_id);
	this.indexSheets(config.sizes);
	this.path = config.path;

	this._default = (isNaN(parseInt(config["default"]))) ? this.indexFromName(config["default"]) : parseInt(config["default"]);
	if (this._default == -1 && this.link !== null) {
		if (this.link.tagName.toUpperCase() == "LINK")
			this._default = this.indexFromSheet(this.link.href);
		else if (this.link.tagName.toUpperCase() == "STYLE")
			this._default = this.indexFromSheet(this.link.innerHTML);
	}
	this._current = this._default;

	this._disabledClass = config.disable_class;

	// cookie stuff
	this._cookieName = config.cookie;
	this._expiry = config.expiry;
	this._engine = OneWeb.Util.engine;

	// create handler delegates for this object
	var me = this;
	this._reduce = function(e) { me.reduce(e); };
	this._enlarge = function(e) { me.enlarge(e); };
	this._reset = function(e) { me.reset(e); };

	// add handlers
	if (this.smaller) OneWeb.Util.addEvent(this.smaller, "click", this._reduce, false);
	if (this.larger) OneWeb.Util.addEvent(this.larger, "click", this._enlarge, false);
	if (this.resetter) OneWeb.Util.addEvent(this.resetter, "click", this._reset, false);

	// read the cookie (if available) and set the stylesheet, if it doesn't match
	if (this.readCookie() && !this.sheetIsCurrent()) {
		// set to cookie value
		this.setSheet();

	} else if (this.validIndex(this._current) && this.link == null) {
		// set to default value, when not set to default
		this.setSheet();
	}

	// add the disabled class if we're set to the minimum or maximum or default
	if (this.smaller && !this.validIndex(this._current - 1)) this.disableLink(this.smaller);
	if (this.larger && !this.validIndex(this._current + 1)) this.disableLink(this.larger);
	if (this.resetter && this._current == this._default) this.disableLink(this.resetter);

	// check if there is an element we should unhide for users with javascript enabled
	if (config.resizer_id && config.resizer_style) {
		var resizer = document.getElementById(config.resizer_id);
		if (resizer) {
			var style = config.resizer_style.split("=");
			resizer.style[style[0]] = style[1];
		}
	}

};

// prototype definition
OneWeb.UI.TextResizer.prototype = {
	"_current": 0,

	"reduce": function(e) {
		///<summary>Event handler to reduce the text size of the current page for this site</summary>
		if (this.validIndex(this._current - 1)) {
			// change the current index and set the new stylesheet
			this._current--;
			this.setSheet();
			this.setCookie();

			// add the disabled class if we've reached the minimum
			if (!this.validIndex(this._current - 1))
				this.disableLink(this.smaller);
			// remove the disabled class for the larger element
			if (OneWeb.Util.hasClass(this.larger, this._disabledClass))
				this.enableLink(this.larger);
			// add/remove the disabled class for the reset element
			if (this.resetter) {
				if (this._current != this._default)
					this.enableLink(this.resetter);
				else if (this._current == this._default)
					this.disableLink(this.resetter);
			}

		}
		this.smaller.blur();
		OneWeb.Util.preventDefault(e);
		return false;
	},

	"enlarge": function(e) {
		///<summary>Event handler to enlarge the text size of the current page for this site</summary>
		if (this.validIndex(this._current + 1)) {
			// change the current index and set the new stylesheet
			this._current++;
			this.setSheet();
			this.setCookie();

			// add the disabled class if we've reached the maximum
			if (!this.validIndex(this._current + 1))
				this.disableLink(this.larger);
			// remove the disabled class for the smaller element
			if (OneWeb.Util.hasClass(this.smaller, this._disabledClass))
				this.enableLink(this.smaller);
			// add/remove the disabled class for the reset element
			if (this.resetter) {
				if (this._current != this._default)
					this.enableLink(this.resetter);
				else if (this._current == this._default)
					this.disableLink(this.resetter);
			}
		}
		this.larger.blur();
		OneWeb.Util.preventDefault(e);
		return false;
	},

	"reset": function(e) {
		///<summary>Event handler to reset the text size to the default (if available) for this site</summary>
		if (this.validIndex(this._default)) {
			// change the current index and set the new stylesheet
			this._current = this._default;
			this.setSheet();
			this.setCookie();

			// add/remove the disabled class for the smaller element
			if (!this.validIndex(this._current - 1))
				this.disableLink(this.smaller);
			else if (OneWeb.Util.hasClass(this.smaller, this._disabledClass))
				this.enableLink(this.smaller);
			// add/remove the disabled class if we've reached the maximum
			if (!this.validIndex(this._current + 1))
				this.disableLink(this.larger);
			else if (OneWeb.Util.hasClass(this.larger, this._disabledClass))
				this.enableLink(this.larger);
			// disable the resetter link
			this.disableLink(this.resetter);

		}
		this.resetter.blur();
		OneWeb.Util.preventDefault(e);
		return false;
	},

	"enableLink": function(link) {
		///<summary>Enable a link element.</summary>
		if (this._disabledClass)
			OneWeb.Util.removeClass(link, this._disabledClass);
		// if this is a hyperlink, remove the href
		if (link.tagName.toUpperCase() === "A" && link.getAttribute("_href") !== null) {
			link.href = link.getAttribute("_href");
			link.removeAttribute("_href");
			link.disabled = false;
		}
	},

	"disableLink": function(link) {
		///<summary>Disable a link element.</summary>
		if (this._disabledClass)
			OneWeb.Util.addClass(link, this._disabledClass);

		// if this is a hyperlink, remove the href
		if (link.tagName.toUpperCase() === "A" && link.href.length > 0) {
			link.setAttribute("_href", link.href);
			link.href = "";
			link.disabled = true;
		}
	},

	//save the current switcher state
	"setSheet": function() {
		///<summary>Changes the current sizing stylesheet for this site.</summary>

		//stylesheet src path

		var isSheet = this.isSheet(this._current);
		var sheet = (isSheet ? this.path : "") + this.sheetFromIndex(this._current);

		//if it exists
		if (this.link != null) {
			var me = this

			//if this is opera we have to set the href on a timer
			//otherwise the change doesn't kick in unless the stylesheet is already in cache
			if (this._engine.name == "Presto") {
				setTimeout(function() {
					if (isSheet && me.link.tagName.toUpperCase() == "LINK") {
						me.link.href = sheet;
					} else if (!isSheet && me.link.tagName.toUpperCase() == "STYLE") {
						me.link.innerHTML = sheet;
					} else if (isSheet && me.link.tagName.toUpperCase() == "STYLE") {
						me.link.parentNode.removeChild(me.link);
						me.link = document.createElement("LINK");
						if (me.link !== null) {
							me.link.rel = "stylesheet";
							me.link.type = "text/css";
							me.link.href = sheet;
							document.getElementsByTagName("HEAD")[0].appendChild(me.link);
						}
					} else if (!isSheet && me.link.tagName.toUpperCase() == "LINK") {
						me.link.parentNode.removeChild(me.link);
						me.link = document.createElement("STYLE");
						if (me.link !== null) {
							me.link.innerHTML = sheet;
							document.getElementsByTagName("HEAD")[0].appendChild(me.link);
						}
					}
				}, 10);
			}

			//if this is IE, we have to preload the stylesheet for exactly the same reason as opera
			//but we can't use the timeout method because that causes win/ie5.0 on 2k and 98se to crash
			else if (this._engine.name == "Trident" && this._engine.version <= 5 && isSheet) {
				//so preload it using XMLHttpRequest
				//I originally tried doing it using createStyleSheet
				//which was simpler and took less code
				//but it didn't solve the problem ... this does
				var request = (window.XMLHttpRequest) ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
				var tmp = null;
				// create the link object if it doesn't yet exist.
				if (me.link.tagName.toUpperCase() !== "LINK") {
					tmp = me.link;
					me.link = document.createElement("LINK");
					if (me.link !== null) {
						me.link.rel = "stylesheet";
						me.link.type = "text/css";
						me.link.href = ""
						document.getElementsByTagName("HEAD")[0].appendChild(me.link);
					}
				}

				//once the stylesheet has loaded
				request.onreadystatechange = function() {
					//readyState of 4 = document has finished loading
					//status of 200 = okay, 304 = not modified
					if (request.readyState == 4 && /(200|304)/.test(request.status.toString())) {
						//load it into the relevant link element but for some reason if we just set the href to the path directly
						//and the new sheet has an @import statement in it, IE6 will crash! but equally obscurely, if we first set it to an empty path
						//the crash doesn't happen and the whole process works smoothly!
						me.link.href = "";
						me.link.href = sheet;
						if (tmp !== null)
							tmp.parentNode.removeChild(tmp);
						//alert("LOADER change");
					}
				};

				//the request must come after the readystate function is defined
				//otherwise that function may not be called if the request is fulfilled very quickly
				request.open("GET", sheet, true);
				request.send(null);
			}

			//now load the stylesheet for *everyone* [including opera and IE so that if the stylesheet is already in cache
			// the change will happen straight away this does mean that under some circumstances, those browsers
			// will load each stylesheet twice, making two server requests but that can't be helped  - there's no way to say, don't do this
			// if the stylesheet is in cache, because there's no way to know and we can't just set a flag so it only goes through the preload routine once
			// because someone may have their browser set not to cache stylesheets (or anything)]
			// TM - actually, loading the stylesheet twice like this causes IE6 to crash, so I added this line in an else clause
			else {
				if (isSheet) {
					if (me.link.tagName.toUpperCase() !== "LINK") {
						var tmp = me.link;
						me.link = document.createElement("LINK");
						if (me.link !== null) {
							me.link.rel = "stylesheet";
							me.link.type = "text/css";
							me.link.href = sheet;
							me.link.onload = function() { tmp.parentNode.removeChild(tmp); this.onload = null; };
							document.getElementsByTagName("HEAD")[0].appendChild(me.link);
						}

					} else
						me.link.href = sheet;
				} else {
					var tmp = me.link;
					me.link = document.createElement("STYLE");
					if (me.link !== null) {
						document.getElementsByTagName("HEAD")[0].appendChild(me.link);
						if (me.link.styleSheet && me.link.styleSheet.cssText != null)
							me.link.styleSheet.cssText = sheet;
						else
							me.link.appendChild(document.createTextNode(sheet));
					}
					tmp.parentNode.removeChild(tmp);
				}
			}
		} else if (document.createElement) {
			// create a link element
			if (isSheet) {
				var link = this.link = document.createElement("LINK");
				if (link !== null) {
					link.rel = "stylesheet";
					link.type = "text/css";
					link.href = sheet;
					document.getElementsByTagName("HEAD")[0].appendChild(link);
				}
			} else {
				var link = this.link = document.createElement("STYLE");
				if (link !== null) {
					document.getElementsByTagName("HEAD")[0].appendChild(link);
					if (link.styleSheet && link.styleSheet.cssText != null)
						link.styleSheet.cssText = sheet;
					else
						link.appendChild(document.createTextNode(sheet));
				}
			}
		}

		//*** dev
		//		window.status = "size " + this._current + " (" + this.sheetFromIndex(this._current) + ")";
		//document.title = '<' + switcher.canvas.className.replace(/ /g,'+') + '>   [' + switcher.string.replace(/ /g,'+') + ']';
	},

	//set a cookie method
	"setCookie": function() {
		//format expiry date
		var thedate = new Date();
		thedate.setTime(thedate.getTime() + (this._expiry * 24 * 60 * 60 * 1000));

		//store the idstring
		var info = (this._current !== this._default) ? "css_switch=" + this.nameFromIndex(this._current) : "";

		//if the value is empty, set its expiry in the past to delete the cookie
		if (info == "")
			thedate.setTime(0);
	
		//create the cookie
		document.cookie = this._cookieName + "=" + info + ";expires=" + thedate.toGMTString() + ";path=/";

	},

	//read a cookie method
	"readCookie": function() {
		//set null reference so we always have something to return
		var cookie = null, css = null;

		//if a cookie exists and it's ours
		if (document.cookie && document.cookie.indexOf(this._cookieName + "=") != -1) {

			//split cookie to extract relevant information
			//creating a classname string to apply to the body (this.cookie string)
			//and name/value pairs array for loading a new stylesheet in load-mode (this.idcookie array)
			cookie = document.cookie.split(this._cookieName + "=")[1].split(";")[0].split("&");
			for (var i = cookie.length - 1; i >= 0; i--) {
				cookie[i] = cookie[i].split("=");
				if (cookie[i].length > 1) {
					switch (cookie[i][0]) {
						case "css_switch":
							css = cookie[i][1];
							cookie[i] = cookie[i].join("=");
							break;
						default: cookie.splice(i, 1); // remove the invalid cookie tokens
					}
				} else {
					css = cookie[i][0];
					if (css.length > 0)
						cookie[i] = "css_switch=" + css;
					else	
						cookie.splice(i, 1); // remove the invalid cookie tokens
				}
			}
			cookie = cookie.join("&");
			if (css == null)
				return false;
			if (isNaN(parseInt(css))) {
				css = this.indexFromName(css);
			} else
				css = parseInt(css);

			if (this.validIndex(css))
				this._current = css;
			else
				css = null;
		}

		return (css !== null);
	},

	"indexSheets": function(sheets) {
		///<summary>Use an array to index the sheets object so that we don't need to enumerate it each time.</summary>
		this._sheets = [];
		for (name in sheets) {
			this._sheets[name] = this._sheets.length;
			this._sheets[this._sheets.length] = [name, sheets[name], /^[^\s{}]*$/.test(sheets[name])];
		}
	},

	"nameFromIndex": function(index) {
		///<summary>Determines the name of the style from an index into the sheets object</summary>
		if (this.validIndex(index)) {
			return this._sheets[index][0];
		}
		return "";
	},

	"sheetFromIndex": function(index) {
		///<summary>Determines the filename of the style from an index into the sheets object</summary>
		if (this.validIndex(index)) {
			return this._sheets[index][1];
		}
		return "";
	},

	"indexFromName": function(name) {
		///<summary>Determines the index of the style from a name into the sheets object</summary>
		if (name in this._sheets) {
			return this._sheets[name];
		}
		return -1;
	},

	"isSheet": function(index) {
		///<summary>Determines if the sheet is a sheet or a style element from an index into the sheets object</summary>
		if (this.validIndex(index)) {
			return this._sheets[index][2];
		}
		return false;
	},

	"indexFromSheet": function(sheet) {
		///<summary>Determines the index of the style from a file or style into the sheets object</summary>
		for (var i = 0, l = this._sheets.length; i < l; i++)
			if (this.isSheet(i) && new RegExp(this.sheetFromIndex(i), "i").test(sheet))
			return i;
		else if (this.sheetFromIndex(i).replace(/\s|;/g, "").toUpperCase() == sheet.replace(/\s|;/g, "").toUpperCase())
			return i;
		return -1;
	},

	"sheetIsCurrent": function() {
		///<summary>Determines whether the current link element corresponds to the current setting.</summary>
		if (this.link == null) return false;
		if (this.isSheet(this._current)) {
			return (this.link.tagName.toUpperCase() == "LINK") && (new RegExp(this.sheetFromIndex(this._current), "i").test(this.link.href));
		} else {
			return (this.link.tagName.toUpperCase() == "STYLE") && (this.link.innerHTML.replace(/\s|;/g, "").toUpperCase() == this.sheetFromIndex(this._current).replace(/\s|;/g, "").toUpperCase());
		}
	},

	"sheetFromName": function(name) {
		if (name in this._sheets) {
			return this._sheets[this._sheets[name]][1];
		}
		return "";
	},

	"validIndex": function(index) {
		///<summary>Determines if the index is valid</summary>
		return (index >= 0 && index < this._sheets.length);
	}

}
///#endregion

// additions to the ajax control toolkit
if (typeof($AA) !== 'undefined') {
    // create a deletion animation script
    OneWeb.UI.Animations.RemoveAction = function(target, duration, fps) {
        if (typeof (duration) !== "undefined") delete duration;
        OneWeb.UI.Animations.RemoveAction.initializeBase(this, [target, duration, fps]);
    }
    OneWeb.UI.Animations.RemoveAction.prototype = {
        doAction: function() {
            try {
                OneWeb.Util.removeElement(this.get_target());
            } catch (ex) {
            }
        }
    }
    OneWeb.UI.Animations.RemoveAction.registerClass("OneWeb.UI.Animations.RemoveAction", $AA.Action); $AA.registerAnimation('removeAction', OneWeb.UI.Animations.RemoveAction);
}
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
