var Softgames = {};
Softgames.WindowPopup = {
	STYLE: {
		NORMAL: [['dependent','yes'],['resizable','yes'],['status','yes'],['menubar','no'],['toolbar','no']]
	},
	POSITION: {
		NONE: 1,
		TOPLEFT: 2,
		CENTER: 3
	},
	open: function(url,name,width,height,position,style) {
		var pos = position == undefined ? this.POSITION.CENTER : position;
		var opts = style == undefined ? this.STYLE.NORMAL : style;
		if(width > 0) { opts[opts.length] = ['width',''+width]; } else { opts[opts.length] = self.outerWidth; }
		if(height > 0) { opts[opts.length] = ['height',''+height]; } else { opts[opts.length] = self.outerHeight; }
		switch(pos) {
			case this.POSITION.TOPLEFT:
				opts[opts.length] = ['top','0'];
				opts[opts.length] = ['left','0'];
			case this.POSITION.CENTER:
				opts[opts.length] = ['top',''+this.__getCenterPosition(self.outerHeight,height)];
				opts[opts.length] = ['left',''+this.__getCenterPosition(self.outerWidth,width)];
			default: break;
		}
		var optsStr ='';
		var optsLength = opts.length;
		while(optsLength-->0) {
			optsStr += (optsStr!=''?',':'') + opts[optsLength][0]+'='+opts[optsLength][1];
		}
		return window.open(url,name,optsStr);
	},
	__getCenterPosition: function(outer, inner) {
		if(inner > outer) return '0';
		return (Math.floor(outer/2) - Math.floor(inner/2));
	}
};

Softgames.Fold = {
	toggle: function(id) {
		var el = $(id);
		if(!el) return;
		if(el.visible()) {
			Effect.Fade(el);
		} else {
			Effect.Appear(el);
		}
	}
};

Softgames.Form = {};
Softgames.Form.SelectControls = {
	selectAll: function(fEl) {
		this.__select(fEl,true);
	},
	selectNone: function(fEl) {
		this.__select(fEl,false);
	},
	__select: function(fEl,state) {
		if(!fEl)return;
		if(!fEl.options)return;
		var i = fEl.length;
		while(i-->0) { fEl.options[i].selected=state; }
	}
};
