if (typeof $ == 'undefined') {
	$ = function(id) { return document.getElementById(id); }
}
function $bool(data) {
	if (!data) return false;
	if (data=='false') return false;
	return true;
}
function $str(obj) {
	if (!obj) {
		return '';
	} else if (typeof(obj) == 'object') {
		return '';
	}
	return obj;
}
function $arr(obj) {
	if (!obj) return [];
	if (typeof(obj) == 'object' && obj.constructor == Object) {
		for (var item in obj) return [obj];
		return [];
	}
	if (!(typeof(obj) == 'object' && obj.constructor == Array)) { obj = [obj]; }
	return obj;
}
//---- JSONscriptRequest method -------------
function JSONscriptRequest(fullUrl, nocache) {
    this.fullUrl = fullUrl; 
    this.noCacheIE = nocache || ('&noCacheIE=' + (new Date()).getTime());
    if (this.noCacheIE == 'null') this.noCacheIE = '';
    this.headLoc = document.getElementsByTagName("head").item(0);
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
    this.retry = 0;
    this.callback = fullUrl.replace(/^.*(?:callback|cbk)=(.*?)\&?$/,'$1');
 	if (!this.callback || this.callback == '') {
 	 	this.callback = 'onData';
	}
}
JSONscriptRequest.scriptCounter = 1;
JSONscriptRequest.timeout = 10;
JSONscriptRequest.max_retry = 1;
JSONscriptRequest.prototype.buildScriptTag = function () {
    this.scriptObj = document.createElement("script");
    this.scriptObj.setAttribute("type", "text/javascript");
    if (arguments.length == 1) {
	    this.scriptObj.setAttribute("charset", arguments[0]);
    } else {
	    this.scriptObj.setAttribute("charset", "utf-8");
    }
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
JSONscriptRequest.prototype.removeScriptTag = function () {
    this.headLoc.removeChild(this.scriptObj);  
}
JSONscriptRequest.prototype.addScriptTag = function () {
    this.headLoc.appendChild(this.scriptObj);
}
//---- StylesheetRequest method -------------
function StylesheetRequest() {
    this.headLoc = document.getElementsByTagName("head").item(0);
}
StylesheetRequest.prototype.buildStyleTag = function(url) {
	this.styleObj = document.createElement("link");
	this.styleObj.setAttribute("rel", "stylesheet");
	this.styleObj.setAttribute("type", "text/css");
	this.styleObj.setAttribute("href", url);
	this.headLoc.appendChild(this.styleObj);
}
//---- StringBuilder method -----------------
function StringBuilder() {
	this._strings = [];
}
StringBuilder.prototype.append = function(str) {
	var aLen = arguments.length;
	for (var i=0; i<aLen; i++) {
		this._strings.push(arguments[i]);
	}
};
StringBuilder.prototype.appendFormat = function(fmt) {
	var re = /{[0-9]+}/g;
	var aryMatch = fmt.match(re);
	var aLen = aryMatch.length;
	for (var i=0; i < aLen; i++) {
		fmt = fmt.replace(aryMatch[i], arguments[parseInt(aryMatch[i].replace(/[{}]/g, "")) + 1]);
	}
	this._strings.push(fmt);
};
StringBuilder.prototype.toString = function() {
	return this._strings.join("");
};
//---- SWODE method -------------------------
if (typeof SWODE == 'undefined') { var SWODE = {}; }
SWODE.formatHomeLogonData = function(user, type) {
	var type = type || "home";
	var userdata = {
		"username": "guest",
		"guest": true,
		"login": false,
		"local": type,
		"jcwid": (type=="space")?"JG-CW-0000000004":"JG-CW-0000000002"
	};
	if (!$bool(user.guest) && user.username) {
		userdata.login = true;
		userdata.guest = false;
		userdata.username = user.username;
	}
	return userdata;
}
//---- common method ------------------------
function checkAll(obj, className) {
	$$('input.'+ className).each(function(elm){
		elm.checked = obj.checked;
	});
}
function go2(url, tar) {
	if (tar) {
		window.open(url);
	} else {
		document.location.href = url;
	}
}