$PWT.Class.create
(
	{
		$namespace:	'SC.search',
		$name:		'Simple'//,
		//$extends:	SC.search.Core
	}
)
(
	{
		core:			null,
		field:
		{
			where:		null,
			contentType:null,
			which:		null,
			query:		null
		},
		fieldset:		null,
		init:			function(core)
		{
			this.core=core;
			this.makeForm();
//			this.init.$parent();
//			if (Object.isElement(this.field.query))
//			{
//				jQuery(this.field.query).keyup
//				(
//					function()
//					{
//						if (!Object.isEmpty(this.field.query.value))
//						{
//							this.submitButton.disabled='';
//						}
//						else
//						{
//							this.submitButton.disabled='disabled';
//						}
//					}.bind(this)
//				);
//			}
		},
		makeForm: function()
		{
			this.field.query=new Ext.ux.form.SearchField
			(
				{
					name:		'search_criterion',
					width:		300,
					fieldLabel:	'<b>Search Term</b>',
					emptyText:	'Enter search term...',
					onTrigger2Click: this.performSearch.bind(this)
				}
			);
			this.field.which=new Ext.ux.form.SelectBox
			(
				{
					name:			'search_which',
					fieldLabel:		'Type',
					width:			190,
					displayField:	'key',
					valueField:		'value',
					autoSelect:		true,
					value:			'[song_writer,version_genres,song_subject,song_description]',
					tpl:			new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item">{key}</div></tpl>'),
					store:			new Ext.data.ArrayStore
					(
						{
							fields:	['key','value'],
							data:
							[
								['All','[song_writer,version_genres,song_subject,song_description]'],
								['Song Writers','song_writer'],
								['Song Genres','version_genres'],
								['Song Subjects','song_subject'],
								['Song Descriptions','song_description']
							]
						}
					)
				}
			);
			this.field.where=new Ext.form.RadioGroup
			(
				{
					fieldLabel:	'I want to search&#8230;',
					items:
					[
						{boxLabel: 'all songs &#8230;', name: 'search_where', inputValue: 0,checked:true},
						{boxLabel: 'songs with <span class="showProf">P</span> only', name: 'search_where', inputValue: 2}
					]
				}
			);
			this.field.contentType=new Ext.form.RadioGroup
			(
				{
					fieldLabel:	'&#8230; that contain',
					columns:	2,
					items:
					[
						{boxLabel: 'Sound', name: 'search_contentType', inputValue: 'file_name'},
						{boxLabel: 'Lyrics', name: 'search_contentType', inputValue: 'file_lyrics'},
						{boxLabel: 'Sound or Lyrics', name: 'search_contentType', inputValue: 'either',checked:true},
						{boxLabel: 'Sound and Lyrics', name: 'search_contentType', inputValue: 'both'}
					]
				}
			);
			this.form=new Ext.form.FormPanel
			(
				{
					id:			'search-simple',
					border:		false,
					width:		700,
//					height:		60,
					labelWidth:	120,
			        bodyStyle:	'padding:5px 5px 0',
					items:
					[
						this.field.query,
						this.moreOptions=new Ext.form.FieldSet
						(
							{
								title:			'Click For More Options',
								collapsible:	true,
								titleCollapse:	true,
								collapsed:		true,
								width:			440,
								items:
								[
									this.field.which,
									this.field.where,
									this.field.contentType
								]
							}
						)
					]
				}
			);
		},
		getForm: function()
		{
			return this.form;
		},
		performSearch: function(name)
		{
			application.showMask('Collecting Search Results. Please wait...');
			application.API.search.main.simple
			(
				this.getFormValues(),
				function(response)
				{
//					this.moreOptions.collapse();
					application.hideMask();
					if (response.success)
					{
						this.core.addResultSet(response,response.params,name);
					}
					else
					{
						application.error(response.message || 'Sorry, no results were found.');
					}
				}.bind(this)
			);
		},
		loadAndPerformSearch: function(name,values)
		{
			this.field.where		.setValue(values.search_where);
			this.field.contentType	.setValue(values.search_contentType);
			this.field.which		.setValue(values.search_which);
			this.field.query		.setValue(values.search_criterion);
			this.performSearch(name);
		},
		getFormValues: function()
		{
			var values=this.form.getForm().getValues();
			values.search_which=this.field.which.getValue();
			return values;
		}
	}
);
