function $A(obj) {
	return Array.prototype.slice.call(obj, 0);
}

Function.prototype.toClosure = function() {
	var f = this;
	var a = $A(arguments);
	return function() {
		return f.apply(this, a.concat($A(arguments)));
	}
};

if (typeof Trace == "undefined") {
	window.Trace = function(msg) {
		if ("console" in window && typeof console.log == "function") {
			console.log(msg);
		}
	}
}

if (typeof trace == "undefined") {
	window.trace = window.Trace;
}

function NewString(string, repeats) {
	return (new Array((repeats == undefined ? 1 : repeats) + 1)).join(string);
}

/********************************
Flash support functions     
********************************/

function thisMovie(movieName)
{
	return document.getElementById(movieName);
}

function FlashOptions(attrs, params, vars, width, height)
{
	this.width = width || 1;
	this.height = height || 1;
	this.attrs = attrs || {};
	this.params = params || {};
	this.vars = vars || {};

	this.id = this.attrs.id || targetId;
	this.name = this.attrs.name || targetId;
}

function InsertFlash(swfFile, targetId, flashOptions)
{
	swfobject.switchOffAutoHideShow();
	swfobject.embedSWF(swfFile, targetId, flashOptions.width, flashOptions.height, "9.0.0", "../flash/expressInstall.swf", flashOptions.vars, flashOptions.params, flashOptions.attrs);
}

function XRaterFlashObject(swfFile, targetId, width, height, vars, params, attrs, onLoad)
{
	this.vars = vars || {};
	this.params = params || {};
	this.attrs = attrs || {};
	this.id = this.attrs.id || targetId;
	this.name = this.attrs.name || targetId;

	this.object = null;
	this.isLoaded = false;

	swfobject.switchOffAutoHideShow();
	swfobject.embedSWF(swfFile, targetId, width, height, "9.0.0", "../flash/expressInstall.swf", this.vars, this.params, this.attrs);
	//swfobject.embedSWF(swfFile, targetId, width, height, "9.0.0", "<%= ResolveUrl("~/flash/expressInstall.swf") %>", this.vars, this.params, this.attrs);

	var context = this;
	var initInterval = setInterval(function() {
		context.object = document.getElementById(context.id);
		if (context.isLoaded || (context.object && typeof context.object.isLoaded == "function" && context.object.isLoaded())) {
			clearInterval(initInterval);
			context.isLoaded = true;
			if (typeof onLoad == "function") {
				onLoad.call(context, context.object);
			}
		}
	}, 200);
}

/*********************************
     Window support functions     
*********************************/

function getDefaultWindowOptions() {
	return {
		left: "0px",
		top: "0px",
		width: screen.availWidth + "px",
		height: screen.availHeight + "px",
		scrollbars: "yes",
		resizable: "no",
		toolbar: "no",
		location: "no",
		status: "no"
	};
}

function openWindow() {
	if (arguments.length == 4) {
		return openWindowSimple(arguments[0], arguments[1], arguments[2], arguments[3]);
	} else {
		return openWindowCustom(arguments[0], arguments[1], arguments[2]);
	}
}

function openWindowCustom(winURL, winName, options) {

	if (typeof options == "undefined") {
		options = getDefaultWindowOptions();
	} else if (options == null) {
		options = { };
	}

	var winParams = "";
	for (var k in options) {
		if (options[k] != null && options[k] != "") {
			winParams += (winParams.length > 0 ? "," : "") + k + "=" + options[k];
		}
	}

	try {
		var win = window.open(winURL, winName, winParams);
	} catch (e) {}
	if (typeof win == "undefined" || win == null) {
		return null;
	} else {
		try { win.focus(); } catch (e) {}
		return win;
	}
}

function openWindowSimple(winURL, winName, width, height) {
	try {
		var win = window.open(winURL, winName, "left=0px,top=0px,width="+width+"px,height="+height+"px,scrollbars=yes,resizable=no,toolbar=no,location=no,status=no");
	} catch (e) {}
	if (typeof win == "undefined" || win == null) {
		return null;
	} else {
		try { win.focus(); } catch (e) {}
		return win;
	}
}

/************************************************
     Javascript 1.6 and 1.8 Array extensions     
************************************************/

if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function(elt /*, from*/) {
		var len = this.length;
		var from = Number(arguments[1]) || 0;
		from = (from < 0) ? Math.ceil(from) : Math.floor(from);
		if (from < 0) {
			from += len;
		}
		for (; from < len; from++) {
			if (from in this && this[from] === elt) {
				return from;
			}
		}
		return -1;
	};
}

if (!Array.prototype.lastIndexOf) {
	Array.prototype.lastIndexOf = function(elt /*, from*/) {
		var len = this.length;
		var from = Number(arguments[1]);
		if (isNaN(from)) {
			from = len - 1;
		} else {
			from = (from < 0) ? Math.ceil(from) : Math.floor(from);
			if (from < 0) {
				from += len;
			} else if (from >= len) {
				from = len - 1;
			}
		}
		for (; from > -1; from--) {
			if (from in this && this[from] === elt) {
				return from;
			}
		}
		return -1;
	};
}

if (!Array.prototype.every) {
	Array.prototype.every = function(fun /*, thisp*/) {
		var len = this.length;
		if (typeof fun != "function") {
			throw new TypeError();
		}
		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this && !fun.call(thisp, this[i], i, this)) {
				return false;
			}
		}
		return true;
	};
}

if (!Array.prototype.filter) {
	Array.prototype.filter = function(fun /*, thisp*/) {
		var len = this.length;
		if (typeof fun != "function") {
			throw new TypeError();
		}
		var res = new Array();
		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this) {
				var val = this[i]; // in case fun mutates this
				if (fun.call(thisp, val, i, this)) {
					res.push(val);
				}
			}
		}
		return res;
	};
}

if (!Array.prototype.forEach) {
	Array.prototype.forEach = function(fun /*, thisp*/) {
		var len = this.length;
		if (typeof fun != "function") {
			throw new TypeError();
		}
		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this) {
				fun.call(thisp, this[i], i, this);
			}
		}
	};
}

if (!Array.prototype.map) {
	Array.prototype.map = function(fun /*, thisp*/) {
		var len = this.length;
		if (typeof fun != "function") {
			throw new TypeError();
		}
		var res = new Array(len);
		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this) {
				res[i] = fun.call(thisp, this[i], i, this);
			}
		}
		return res;
	};
}

if (!Array.prototype.some) {
	Array.prototype.some = function(fun /*, thisp*/) {
		var len = this.length;
		if (typeof fun != "function") {
			throw new TypeError();
		}
		var thisp = arguments[1];
		for (var i = 0; i < len; i++) {
			if (i in this && fun.call(thisp, this[i], i, this)) {
				return true;
			}
		}
		return false;
	};
}

if (!Array.prototype.reduce) {
	Array.prototype.reduce = function(fun /*, initial*/) {
		var len = this.length;
		if (typeof fun != "function") {
			throw new TypeError();
		}
		// no value to return if no initial value and an empty array
		if (len == 0 && arguments.length == 1) {
			throw new TypeError();
		}
		var i = 0;
		if (arguments.length >= 2) {
			var rv = arguments[1];
		} else {
			do {
				if (i in this) {
					rv = this[i++];
					break;
				}
				// if array contains no values, no initial value to return
				if (++i >= len) {
					throw new TypeError();
				}
			} while (true);
		}
		for (; i < len; i++) {
			if (i in this) {
				rv = fun.call(null, rv, this[i], i, this);
			}
		}
		return rv;
	};
}

if (!Array.prototype.reduceRight) {
	Array.prototype.reduceRight = function(fun /*, initial*/) {
		var len = this.length;
		if (typeof fun != "function") {
			throw new TypeError();
		}
		// no value to return if no initial value, empty array
		if (len == 0 && arguments.length == 1) {
			throw new TypeError();
		}
		var i = len - 1;
		if (arguments.length >= 2) {
			var rv = arguments[1];
		} else {
			do {
				if (i in this) {
					rv = this[i--];
					break;
				}
				// if array contains no values, no initial value to return
				if (--i < 0) {
					throw new TypeError();
				}
			} while (true);
		}
		for (; i >= 0; i--) {
			if (i in this) {
				rv = fun.call(null, rv, this[i], i, this);
			}
		}
		return rv;
	};
}

