
	function price_picker_equipment(parent, equipment_ID, eqValue, eqType) {
		var self = this;

		this.parent = parent;
		this.equipment_ID = equipment_ID;
		this.eqValue = eqValue;
		this.eqType = eqType;
		
		this.price = null;
		this.limit_price = null;
		this.input = null;
		this.info = null;
		
		this.construct = function() {
			this.info = document.getElementById("eq_info" + this.equipment_ID + "no");
			this.input = document.getElementById("eq_el" + this.equipment_ID + "no");
			this.input.onclick = function(eventRef) { self.parent.evt_equip_change(eventRef == null ? event : eventRef); }
		}
		
		this.update = function(price, limit_price, price_word, currency) {
			this.price = price;
			this.limit_price = limit_price;
			this.info.innerHTML = price_word + " " + currency;
			if (this.limit_price != 0) this.info.innerHTML += "<br/><span>(max. " + this.limit_price + " " + currency + ")</span>";
		}
		
		this.clean = function() {
			this.price = null;
			this.info.innerHTML = "0,-";
		}
		
		this.get = function() {
			switch (this.eqType) {
				case 2 :
				case 0 :
				case 3 :
				case 4 :
				case 5 :
					return this.input.checked ? 1 : 0;
					
				case 1 :
					return this.input.options[this.input.selectedIndex].value;
			}
		}
		
		this.compose = function() {
			var to_put = this.get();
			return to_put == 0 ? false : (this.equipment_ID + ":" + this.get());
		}
	}

	function price_picker() {
		var self = this;

		this.lang = null;
		this.collect_at = null;
		this.return_at = null;
		this.date_from = null;
		this.date_to = null;
		this.days = null;
		this.sipp = null;
		this.equipment = new Array();
		
		this.type = null; // normal/lowcost
		this.currency = new Array();
		this.requests = 0;
		
		this.add_equipment = function(equipment_ID, eqValue, eqType) {
			var ref = new price_picker_equipment(this, equipment_ID, eqValue, eqType);
			this.equipment[this.equipment.length] = ref;
			return ref;
		}
		
		this.compose_equipment = function() {
			var ret = "";
			var f, tmp;
			var start = true;
			
			for (f = 0; f < this.equipment.length; f++) {
				tmp = this.equipment[f].compose();
				if (tmp != false) {
					if (start) start = false;
					else ret += ",";
					
					ret += tmp;
				}
			}
			
			return ret;
		}
		
		this.query = function() {
			var data = new structure_class();
			
			data.map("head/major", "budget_refresh");
			data.map("head/lang", this.lang);
			data.map("head/collect", this.collect_at);
			data.map("head/return", this.return_at);
			data.map("head/date_from", this.date_from);
			data.map("head/date_to", this.date_to);
			data.map("head/days", this.days);
			data.map("head/sipp", this.sipp.options[this.sipp.selectedIndex].value);
			data.map("head/equipment", this.compose_equipment());
			
			this.requests++;
			context.collector.enqueue("refresh", null, function(data, request) {
				self.evt_onrequest(data, request);
			}, data.root);
			
			document.getElementById("load_info").style.display = "block";
		}
		
		this.construct = function(lang, collect_at, return_at, date_from, date_to, days) {
			var f;
			for (f = 0; f < this.equipment.length; f++)
				this.equipment[f].construct();
				
			this.lang = lang;
			this.collect_at = collect_at;
			this.return_at = return_at;
			this.date_from = date_from;
			this.date_to = date_to;
			this.days = days;
			this.sipp = document.getElementById("rent_sipp_el");
			this.sipp.onchange = function(eventRef) { self.evt_sipp_change(eventRef == null ? event : eventRef); }
		}
		
		this.load = function(body, type) {
			var body_base = body.getElementsByTagName(type);
			if (body_base.length > 0) {
				body_base = body_base[0];
				
				//var err = body_base.getElementsByTagName("error");
				
				var totalPrice = context.sub_element_value(body_base, "totalPrice");
				var totalPriceVAT = context.sub_element_value(body_base, "totalPriceVAT");
				var airportFee = context.sub_element_value(body_base, "airportFee");
				
				// mena
				var cur = body_base.getElementsByTagName("currency");
				this.currency[type] = context.sub_element_value(cur[0], "name");
				
				document.getElementById(type + "_airport_fee").innerHTML = airportFee + " " + this.currency[type];
				document.getElementById(type + "_total_price").innerHTML = totalPrice + " " + this.currency[type];
				document.getElementById(type + "_total_priceVAT").innerHTML = totalPriceVAT + " " + this.currency[type];
				
				if (type == this.type) {
					
					// update pro aktualni typ
					document.getElementById("drop_off_el").innerHTML = context.sub_element_value(body_base, "dropFee") + " " + this.currency[type];
					document.getElementById("price_list_el").innerHTML = context.sub_element_value(body_base, "priceListComment");
					
					// equipmenty
					var eq = body_base.getElementsByTagName("equipItems");
					var f, eqID, value, price, limit_price, price_word;
					var pos, founded;
					
					for (f = 0; f < this.equipment.length; f++)
						this.equipment[f].clean();
					
					for (f = 0; f < eq.length; f++) {
						eqID = context.sub_element_value(eq[f], "equipment_ID");
						value = context.sub_element_value(eq[f], "value");
						price = context.sub_element_value(eq[f], "price");
						limit_price = context.sub_element_value(eq[f], "limit_price");
						price_word = context.sub_element_value(eq[f], "price_word");
						
						founded = false;
						pos = 0;
						
						while (!founded && pos < this.equipment.length) {
							if (this.equipment[pos].equipment_ID == eqID) founded = true;
							else pos++;
						}
						
						if (founded) {
							this.equipment[pos].update(price, limit_price, price_word, this.currency[type]);
						}
					}
				}
			}
		}
		
		this.set_pay_type = function(ident) {
			switch (ident) {
				case "normal" :
				case "lowcost" :
					if (ident != this.type) {
						this.type = ident;
						
						document.getElementById("pay_type_" + this.type).checked = true;
						this.query();
					}
					break;
			}
		}
		
		this.evt_onrequest = function(data, request) {
			var res;
			if ((res = request.get_response()) != null) {
				
				var active_name = this.active != null ? this.active.value : null;
				
				var head = res[0];
				var body = res[1];
				
				// specs
				var specs = body.getElementsByTagName("sipp_spec");
				if (specs.length > 0) {
					var put = "";
					var sf;
					
					for (sf = 0; sf < specs.length; sf++) {
						if (sf != 0) put += "<br/>";
						put += context.element_value(specs[sf]);
					}
					
					document.getElementById("sipp_spec").innerHTML = put;
				}
				
				// price content
				this.load(body, "normal");
				this.load(body, "lowcost");
			}
			
			this.requests += -1;
			if (this.requests == 0) document.getElementById("load_info").style.display = "none";
		}
		
		this.evt_sipp_change = function(trgEvent) {
			self.query();
		}
		
		this.evt_equip_change = function(trgEvent) {
			self.query();
		}
		
		this.evt_line_over = function(ref) {
			var parent = ref.parentNode;
			var pos = 0;
			
			while (pos < parent.childNodes.length) {
				if (parent.childNodes[pos].nodeType == 1) parent.childNodes[pos].style.backgroundColor = "#FFEFE4";
				pos++;
			}
		}
		
		this.evt_line_out = function(ref) {
			var parent = ref.parentNode;
			var pos = 0;
			
			while (pos < parent.childNodes.length) {
				if (parent.childNodes[pos].nodeType == 1) parent.childNodes[pos].style.backgroundColor = "#FFF7F2";
				pos++;
			}
		}
	}

