if (typeof(FOH) == "undefined") FOH = {};





FOH.Feedback = Class.create();
Object.extend(FOH.Feedback.prototype, {
	video: {
		url: null,
		poster: null,
		end: null
	},

	initialize: function(options) {
		Object.extend(this, options);

		this.form = this.content.down('form');
		this.form.observe('submit', this.submit.bind(this));
		
		this.populateCategory();
		this.populateBrowser();
		this.populatePlatform();
		this.populateQuicktime();
	},

	populateCategory: function() {
		if (this.elements.category) {
			var section = document.title.toString().strip();
			section = section.substring(section.indexOf('-')+1, section.length).strip();
			section = section.substring(section.indexOf('-')+1, section.length).strip();
			if (section.indexOf('-')>0) section = section.substring(0, section.indexOf('-')-1).strip();
			
			var option = this.elements.category.down('option[value='+section+']');
			if (option) option.selected = true;
		}
	},

	populateBrowser: function() {
		if (this.elements.browser) {
			var browser = 'Other';
			if (AC.Detector.isWebKit()) {
				browser =  'Safari';
			} else if (AC.Detector.isMobile()) {
				browser =  'Mobile Safari';
			} else if (AC.Detector.isOpera()) {
				browser =  'Opera';
			} else if (AC.Detector.isIEStrict()) {
				browser =  'IE';
			} else if (AC.Detector.isFirefox()) {
				browser =  'Firefox';
			}

			this.elements.browser.value = browser;
			// try { console.log('browser: '+browser); } catch(e) { }
		}
	},

	populatePlatform: function() {
		if (this.elements.platform) {
			var platform = 'Other';
			if (AC.Detector.isMac()) {
				platform =  'Mac';
			} else if (AC.Detector.isWin()) {
				platform =  'Windows';
			} else if (AC.Detector.isWin2k()) {
				platform =  'Windows 2000';
			} else if (AC.Detector.isWinVista()) {
				platform =  'Windows Vista';
			}

			this.elements.platform.value = platform;
			// try { console.log('platform: '+platform); } catch(e) { }
		}
	},

	populateQuicktime: function() {
		if (this.elements.quicktime) {
			var quicktime = 'Not Installed';
			if (AC.Detector.getQTVersion()) quicktime =  AC.Detector.getQTVersion();

			this.elements.quicktime.value = quicktime;
			// try { console.log('quicktime: '+quicktime); } catch(e) { }
		}
	},

	populateVideo: function(video) {
		if (video && this.elements.video) {
			this.elements.video.value = video;
			// try { console.log('video: '+video); } catch(e) { }
		}
	},

	checkFields: function(evt) {
		var flag = true;

		var required = this.form.getElementsBySelector('.required');
		for (var i=0; i<required.length; i++) {
			var thisFlag = true;

			var label = required[i];
			var input = label.getElementsBySelector('input[type=radio]') || label.getElementsBySelector('input[type=checkbox]');
			if (input.length>0) {
				if (!label.down('input:checked')) {
					var thisFlag = false;
					flag = false;
				}
			}

			var input = label.down('input') || label.down('select') || label.down('textarea');
			if (!input.value || input.value == '') {
				var thisFlag = false;
				flag = false;
			} else if (input.name.match('email') && !isEmail(input.value)) {
				var thisFlag = false;
				flag = false;
			}

			this.setField(label, input, thisFlag);
		}
		
		return flag;
	},

	setField: function(label, input, state) {
		if (label) setLabel(label, state);
		if (input) setBG(input, state);
	},

	submit: function(evt) {
		if (!this.checkFields()) {
			if (evt) Event.stop(evt);
		}
	},
	
	activate: function() {},
	deactivate: function() {}
});
