offer.Offer = function(){

}
offer.Offer.prototype = {
	urlParams: {},
	/**
	 *
	 * @type {offer.AuthenticateView}
	 */
	authenticateView: null,
	init: function(){
		this.progressView = new jslt.Progress(document.getElementById("progressContainer"), 500, 40)
		this.progressView.stopDocument = true
		this.serviceDelegate = new offer.ServiceDelegate()
		this.serviceDelegate.init()
		this.serviceDelegate.initSession(lang)
		$(document).bind(jslt.rb.DRB.EVENT_DYNAMIC_RESOURCE_BUNDLE_AVAILABLE, $.proxy(this.evResourceBundleAvailable,this))
		$(document).bind('EVENT_LOGOUT', $.proxy(this.evLogout,this))
		jslt.rb.DRB.init(this.serviceDelegate)
	},
	evResourceBundleAvailable: function(e, txt){
		$.validator.messages={
		required: jslt.rb.DRB.getString('validator','required'),
		remote: "Please fix this field.",
		email: jslt.rb.DRB.getString('validator','email'),
		url: "Please enter a valid URL.",
		date: "Please enter a valid date.",
		dateISO: "Please enter a valid date (ISO).",
		dateDE: "Bitte geben Sie ein gültiges Datum ein.",
		number: jslt.rb.DRB.getString('validator','number'),
		numberDE: "Bitte geben Sie eine Nummer ein.",
		digits: jslt.rb.DRB.getString('validator','digits'),
		creditcard: "Please enter a valid credit card number.",
		equalTo: jslt.rb.DRB.getString('validator','equalTo'),
		accept: "Please enter a value with a valid extension.",
		maxlength: $.format(jslt.rb.DRB.getString('validator','maxlength')),
		minlength: $.format(jslt.rb.DRB.getString('validator','minlength')),
		rangelength: $.format(jslt.rb.DRB.getString('validator','rangelength')),
		range: $.format(jslt.rb.DRB.getString('validator','range')),
		max: $.format(jslt.rb.DRB.getString('validator','max')),
		min: $.format(jslt.rb.DRB.getString('validator','min'))
	}
		
		var t=this
		this.tabView = new jslt.TabView("offerTabView")
		this.tabView.selectById("productsView", true)
		var loc = new jslt.element.Location()
		this.urlParams = loc.keysFromHash()
		
		this.groupsView = new offer.GroupsView();
		this.cartView = new offer.CartView();
		this.productsView = new offer.ProductsView();
		this.searchView = new offer.SearchView();
		this.authenticateView = new offer.AuthenticateView();
		this.authenticateView.bindHTML()
		this.evCartRequired()
		if(!$.HistoryManager.loadFromURL()){
			this.groupsView.evMainLabelClick()
		}
		this.staticContentView = new offer.StaticContentView()
		this.serviceDelegate.readShopClientAccount()
		this.shopClientVO = new cms2.offer.vo.ShopClientVO()
		this.shopClientVO.is_temporary = true
		$(document).bind('siteMenuClick', this.evMenuClick)
	},
	evMenuClick: function(e, txt){
		if (txt != 'offer') {
		}
	},
	evError: function(msg){
		alert(msg)
		/*var s = "Błąd"
		 alert(s)*/
	},
	/**
	 *
	 * @param {String} msg
	 */
	inform: function(msg){
		alert(msg)
	},
	evGroupChange: function(id){
		this.productFilter = new cms2.offer.vo.ProductsFilterVO()
		this.productFilter.id_offer_group = id
		this.serviceDelegate.filterProducts(this.productFilter)
	},
	evProductPageChange: function(currentPage){
		this.productFilter.currentPage = currentPage
		this.serviceDelegate.filterProducts(this.productFilter)
	},
	evSearchRequired: function(phase){
		this.productFilter = new cms2.offer.vo.ProductsFilterVO()
		this.productFilter.description = this.productFilter.name = phase
		this.serviceDelegate.filterProducts(this.productFilter)
	},
	evProductViewRequired: function(p){
		this.serviceDelegate.getProduct(p)
	},
	evCartRequired: function(){
		this.serviceDelegate.readShoppingCart()
	},
	addShoppingCartItem: function(shoppingCartVO){
		this.serviceDelegate.addShoppingCartItem(shoppingCartVO)
	},
	changeQuantity: function(shoppingCartVO){
		this.serviceDelegate.changeQuantity(shoppingCartVO)
	},
	removeShoppingCartItem: function(shoppingCartVO){
		this.serviceDelegate.removeShoppingCartItem(shoppingCartVO)
	},
	getMainGroups: function(){
		this.serviceDelegate.getMainGroups()
	},
	config: {},
	shopClientVO: {},
	showPrices: function(){
		return this.config.show_prices_for == 'all' || !this.shopClientVO.is_temporary
	},
	/**
	 * Informuj o zmianie menu
	 */
	informWorld: function(){
		$(document).trigger('siteMenuClick', ['offer'])
	},
	evLogout:function(){
		this.shopClientVO.is_temporary=true
	}
}
offerInstance = new offer.Offer();
function initOffer(){
	offerInstance.init();
	$.validator.setDefaults({
		skipValidation: skipValidation
	})
	
	//$.tooltip.defaults.delay=0
	//$.tooltip.defaults.fade=1000
}

onLoadQueue.appendOnLoad(initOffer)
validateForms = false

