/**
 * @author phillipa
 */

declarePackage("picknpay");
declarePackage("picknpay.modlets");
picknpay.modlets.TipSearch = function() {
	var self;
	
	function constructorFn(){
		self = this;
	}
	
	constructorFn.prototype.submit = function(thisForm) {
		thisForm.submit();
	}
	
	constructorFn.prototype.switchDivStates = function(divId) {
		var show = $(divId + "_display").style.display == "none" ;
		
		if (show) {
			$(divId + "_header").src = $(divId + "_header").src.replace("_closed", "_open");
			$(divId + "_display").style.height = "";
			Effect.BlindDown(divId + "_display");
		} else {
			$(divId + "_header").src = $(divId + "_header").src.replace("_open", "_closed");
			$(divId + "_display").style.height = "";
			Effect.BlindUp(divId + "_display");
		}
	}
	
	constructorFn.prototype.selectItem = function(categoryId) {		
		var selected = $("select_" + categoryId).selected;
		
		if (selected) {
			$("select_" + categoryId).selected = false;
			$(categoryId).src = $(categoryId).src.replace("_active", "_inactive");			
		} else {
			$("select_" + categoryId).selected = true;
			$(categoryId).src = $(categoryId).src.replace("_inactive", "_active");
		}
	}
	
	constructorFn.prototype.init = function(selectedCategories) {
		
		if (selectedCategories.length > 0) {
			picknpay.modlets.tipSearch.switchDivStates('advanced_search');
			
			for (var i=0; i< selectedCategories.length; i++) {
				if ($("tip_category_" + selectedCategories[i])) {
					picknpay.modlets.tipSearch.selectItem('tip_category_' + selectedCategories[i], false);
				} 		
			}
		}
	}
	
	return new constructorFn();	
}
picknpay.modlets.tipSearch = new picknpay.modlets.TipSearch();
