/**
 * SearchView class
 *
 */
var SearchView = {
	_submitBut : null,
	_form : null,

	init : function(form){
		SearchView._form = form;
		SearchView._submitBut = DomHtml.getElementsByClassName(form,'submitInput')[0];
	},

	submitForm : function(progressTxt){
		SearchView._submitBut.value = progressTxt;
		SearchView._submitBut.disabled = true;
		SearchView._form.submit();
	},
	
	populateSelection : function(sourceElm, targetElm, data, emptyTitle, allTitle, selectKey){
	
		var sourceValue = sourceElm.options[sourceElm.selectedIndex].value;
		
		//clear all existing options (except the first one which is a title-element)
		for(var i=(targetElm.options.length-1);i>=0;i--){
			targetElm.options[i].parentNode.removeChild(targetElm.options[i]);
		}

		//create options based on data-array
		var e;
		var entityTitle;
		var selectIndex = null;
		var i = 0;
		
		if(typeof data[sourceValue] == 'undefined' || data[sourceValue].length == 0) data[sourceValue] = {'0':emptyTitle};
		else{
			e = document.createElement('option');
			e.value = '';
			e.innerHTML = allTitle;
			targetElm.appendChild(e);
		}
		
		for(var key in data[sourceValue]){
		
			if(selectKey == key) selectIndex = i;
			entityTitle = data[sourceValue][key];
			
			e = document.createElement('option');
			e.value = key;
			e.innerHTML = entityTitle;
			targetElm.appendChild(e);
			i++;
		}
		
		if(selectKey && selectIndex != null){
			targetElm.selectedIndex = selectIndex;
		}
	}
}