Starmind.Question = {
	Marked: {
		blocked: new Array(),
		click: function(qid) {
			if (!this.isBlocked(qid)) {
				this.block(qid);
				this.changeButton(qid, '...', 'fav_loading');
				new Starmind.Utilities.AjaxRequest('/ajax/question/mark/id/' + qid);
			}
		},
		block: function(qid) {
			if (!this.isBlocked(qid)) this.blocked[this.blocked.length] = qid;
		},
		unblock: function(qid) {
			var t = new Array();
			for(var i = 0; i < this.blocked; i++) {
				if (this.blocked[i] != qid) t[t.length] = this.blocked[i];
			}
			this.blocked = t;
		},
		isBlocked: function(qid) {
			for(var i = 0; i < this.blocked; i++) {
				if (this.blocked[i] == qid) return true;
			}
			return false;
		},
		changeButton: function(qid, label, cls) {
			$('favor_question_' + qid).className = cls;
			$('favor_question_' + qid).title = label;
		}
	},
	Tags: {		
		getPredefinedTags: function(language_id) {
			var preload = new Image(16,16); 
			preload.src="/img/loading_small.gif"; 

			$('predefined_tag_container').innerHTML = '<img src="/img/loading_small.gif" width="16" height="16" alt="..." style="margin-left: 252px;" />';
			new Ajax.Updater('predefined_tag_container', '/ajax/question/predefinedtags/id/' + language_id + '/');
			
			Starmind.Question.Tags.getSpread();
		},
		
		setSpread: function(message, c) {
			$('question_pose_spread').innerHTML = message;
			$('question_pose_spread').className = c;
		},
		
		getSpreadOnType: function(evt, elem) {
			evt = (evt) ? evt : window.event;
			var charCode = (evt.which) ? evt.which : evt.keyCode;
			var char = elem.value.charAt(elem.value.length-1);
		    if (charCode == 44) {
		    	Starmind.Question.Tags.getSpread();
		    }
		},
		
		getSpread: function() {
			var pTagContainer = $('predefined_tag_container');
			var iTagTextarea = $('question_tags');
			var langSelect = $('');
			
			$('question_pose_spread').className = 'loading';
			
		    var pTags = '';
		    if (pTagContainer != null) {
				var cbs = pTagContainer.getElementsByTagName('input');
				for (var i = 0; i < cbs.length; i++) {
					if (cbs[i].type == 'checkbox' && cbs[i].checked) {
						pTags += cbs[i].value + ',';
					}
				}
		    }
		    
		    var iTags = '';
		    if (iTagTextarea != null) {
		    	iTags = iTagTextarea.value;
		    }
		    	
		    if (pTags.length > 0) pTags = pTags.substring(0, (pTags.length-1));
		    	
		    new Starmind.Utilities.AjaxRequest('/ajax/question/solvercount/', 'ptags='+pTags+'&itags='+iTags);
		}
	},
	Pioneer: {
		isVerified: false,
		verifyTitle: 'Verify your Account',
		onChange: function() {
			if($('reward_choose_pioneer').checked) {
				if (this.isVerified) {
					$('pioneer_select').className = 'reward_choose';
					$('amount_select').className = 'reward_choose_passive';
					$('question_reward').value = '';
					$('question_reward').disable();
					$('pioneer_select').insert(new Element('input', {type: 'hidden', value: '0', id: 'question_reward_hidden', name: 'question_reward'}));
				} else {
					$('reward_choose_pioneer').checked = false;
					$('reward_choose_amount').checked = true;
					new Starmind.Utilities.AjaxPopup('/ajax/user/verify/', {title: this.verifyTitle, width: 350});
				}
			} else {
				$('pioneer_select').className = 'reward_choose_passive';
				$('amount_select').className = 'reward_choose';
				$('question_reward').enable();
				$('question_reward').focus();
				try {
					$('question_reward_hidden').remove();
				} catch(e) {}
			}
			
		}
	},
	Menu: {
		update: function(qid) {
			$('question_menu').update('<div style="margin: 5px 0 0 340px;"><img src="/img/loading_small.gif" alt="..." width="16" height="16" /></div>');
			new Ajax.Updater(
				'question_menu', 
				'/ajax/question/menu/id/'+qid+'/', 
				{
					method: 'get',
					evalScripts: true,
					encoding: 'UTF-8'
				}
			);
		}
	},
	Submission: {
		StepForm: null,
		form: null,
		init: function(form) {
			if (this.StepForm.hasNext()) {
				this.StepForm.next();
				return false;
			} else {
				Starmind.Utilities.Internal.Form.indicateSubmission();
				if (this.form == null) {
					this.form = form;
					window.setTimeout('Starmind.Question.Submission.submit();', 2000);
					return false;
				} else {
					return true;
				}
			}
		},
		submit: function() {
			if (this.form != null) {
				$(this.form).submit();
			}
		}
	}
};