
	// --- car_form_selector ---
	
	function car_form_selector(parent, type, target, caption) {
		this.parent = parent;
		this.container = null;
		this.info = null;
		this.dcont = null;
		this.remove = null;
		
		this.type = type; // radio|select|checkbox|producer
		this.target = target;
		this.s_target = null;
		this.tbase = null;
		this.caption = caption;
	}
	
	car_form_selector.prototype.construct = function() {
		var self = this;
		
		switch (this.type) {
			case "producer" :
				var nfo = this.target.get_values_info();
				this.info = document.getElementById("result_producer_top");
				if (nfo != "") this.info.childNodes[0].innerHTML = nfo.length > 47 ? (nfo.substr(0, 47) + "...") : nfo;
				break;
			
			case "checkbox" :
				this.info = document.createElement("SPAN");
				this.info.innerHTML = this.caption.innerHTML + " ";
				
				this.remove = document.createElement("A");
				this.remove.href = "javascript:blank()";
				this.remove.innerHTML = "<strong>x</strong>";
				this.remove.onclick = function() {
					if (self.o_ds == null) self.evt_remove();
				}
				
				this.target.style.visibility = "hidden";
				this.target.style.position = "absolute";
				
				this.container.parentNode.parentNode.parentNode.parentNode.appendChild(this.target);
				this.container.appendChild(this.info);
				this.container.appendChild(this.remove);
				break;
			
			case "select" :
				this.remove = document.createElement("INPUT");
				this.remove.type = "button";
				this.remove.className = "button";
				this.remove.onclick = function() {
					if (self.o_ds == null) self.evt_remove();
				}
				
				this.container.appendChild(this.remove);
				break;
				
			case "radio" :
				this.s_target = document.createElement("SELECT");
				
				this.s_target.onchange = function() {
					if (self.o_ds == null) {
						self.target[self.s_target.selectedIndex].checked = true;
						self.target[self.s_target.selectedIndex].onclick();
					}
				}
				
				var f, op;
				for (f = 0; f < this.target.length; f++) {
					op = document.createElement("OPTION");
					op.value = this.target[f].value;
					op.text = this.caption[f];
					op.selected = this.target[f].checked;
					
					this.s_target.options.add(op);
				}
				
				this.dcont = document.createElement("DIV");
				this.dcont.className = "dcont";
				
				this.dcont.appendChild(this.s_target);
				this.container.appendChild(this.dcont);
				
				for (f = 0; f < this.target.length; f++) {
					this.target[f].style.visibility = "hidden";
					this.target[f].style.position = "absolute";
					this.container.appendChild(this.target[f]);
				}
				break;
		}
	}
	
	car_form_selector.prototype.evt_remove = function() {
		switch (this.type) {
			case "radio" :
				break;
				
			case "select" :
				this.target.selectedIndex = 0;
				this.target.onchange();
				//this.hide();
				break;
				
			case "checkbox" :
				this.target.checked = false;
				this.target.onclick();
				//this.hide();
				break;
				
			case "producer" :
				this.target.clear_items();
				this.target.evt_change();
				//this.hide();
				break;
		}
	}
	
	car_form_selector.prototype.hide = function() {
		switch (this.type) {
			case "checkbox" :
				this.info.style.visibility = "hidden";
				this.info.style.position = "absolute";
				this.info.style.left = "0px";
				this.info.style.top = "0px";
				
				this.remove.style.visibility = "hidden";
				this.remove.style.position = "absolute";
				this.remove.style.left = "0px";
				this.remove.style.top = "0px";
				break;
				
			default :
				this.container.style.visibility = "hidden";
				this.container.style.position = "absolute";
				this.container.style.left = "0px";
				this.container.style.top = "0px";
				break;
		}
	}

	// --- car_form_class ---
	
	function car_form_class() {
		this.selectors = new Array();
		
		this.search_results_count = new Array();
		this.search_results_href = null;
		this.search_results_block = null;
		this.search_form = null;
		this.filter_string = null;
		
		this.sr_size = null;
		this.lang = null;
		
		this.p_container = null;
		this.p_top = null;
		this.p_point = 0;
		this.p_open = false;
		this.p_mass = 0;
		
		this.car_model_constr_toggle = null;
		this.car_model_constr = null;
		this.car_model_producer = null;
		this.car_model_producer_simple = null;
		
		this.car_model_price = null;
		this.car_model_year = null;
		this.car_model_km = null;
		this.car_model_kw = null;
		
		this.car_model_engine = null;
		this.car_model_dest_car_fuel_ID = null;
		this.car_model_dest_car_transmission_ID = null;
		
		this.car_model_dest_car_air_condition_ID = null;
		this.car_model_dest_car_doors_ID = null;
		
		this.car_model_metallic = null;
		this.car_model_equipment = null;
		this.car_model_color = null;
	}
	
	car_form_class.prototype.construct = function() {
		var self = this;
		
		var pos = 1;
		var tmp = null;
		do {
			if ((tmp = document.getElementById("search_results_count" + (pos == 1 ? "" : pos))) != null)
				this.search_results_count[this.search_results_count.length] = tmp;
			pos++;
		} while (tmp != null);
		this.search_results_block = document.getElementById("search_results_block");
		this.search_results_href = document.getElementById("search_results_href");
		this.search_form = document.getElementById("search_form");
		
		if (this.search_results_href != null) {
			this.search_results_href.childNodes[0].href = "javascript:blank()";
			this.search_results_href.childNodes[0].onclick = function() { self.search_form.submit(); }
		}
		
		var pcnt = document.getElementById("result_producer_container"), ptop = document.getElementById("result_producer_top");
		if (pcnt != null && ptop != null) {
			this.p_container = pcnt;
			this.p_top = ptop;
			this.p_container.style.height = "0px";
			this.p_point = 0.0;
		}
		
		var box = null, box2 = null;
		if ((box = document.getElementById("car_model_constr_toggle")) != null) {
			this.car_model_constr_toggle = new ic_multiple(box);
			this.car_model_constr_toggle.change_event = function() {
				self.constr_touch();
				self.changed();
			}
		}
		if ((box = document.getElementById("car_model_constr")) != null) {
			this.car_model_constr = new ic_multiple(box);
			this.car_model_constr.change_event = function() {
				self.changed();
			}
		}
		if ((box = document.getElementById("car_model_producer")) != null) {
			this.car_model_producer = new ic_producer(box);
			this.car_model_producer.change_event = function() {
				self.changed(self.car_model_producer);
			}
		} else if ((box = document.getElementById("car_model_dest_car_producer_ID")) != null && (box2 = document.getElementById("car_model_dest_car_type_ID")) != null) {
			this.car_model_producer_simple = new ic_producer(null);
			var itm = new ic_producer_item(this.car_model_producer_simple);
			
			itm.fields[0] = box;
			itm.fields[1] = box2;
			
			this.car_model_producer_simple.items[this.car_model_producer_simple.items.length] = itm;
			itm.construct();
			
			this.car_model_producer_simple.change_event = function() {
				self.changed();
			}
		}
		
		
		if ((box = document.getElementById("car_model_engine")) != null) {
			this.car_model_engine = new ic_select_watch(box);
			this.car_model_engine.change_event = function() {
				self.changed();
			}
		}
		if ((box = document.getElementById("car_model_dest_car_fuel_ID")) != null) {
			this.car_model_dest_car_fuel_ID = new ic_select_watch(box);
			this.car_model_dest_car_fuel_ID.change_event = function() {
				self.changed();
			}
		}
		if ((box = document.getElementById("car_model_dest_car_transmission_ID")) != null) {
			this.car_model_dest_car_transmission_ID = new ic_select_watch(box);
			this.car_model_dest_car_transmission_ID.change_event = function() {
				self.changed();
			}
		}
		if ((box = document.getElementById("car_model_dest_car_air_condition_ID")) != null) {
			this.car_model_dest_car_air_condition_ID = new ic_select_watch(box);
			this.car_model_dest_car_air_condition_ID.change_event = function() {
				self.changed();
			}
		}
		if ((box = document.getElementById("car_model_dest_car_doors_ID")) != null) {
			this.car_model_dest_car_doors_ID = new ic_select_watch(box);
			this.car_model_dest_car_doors_ID.change_event = function() {
				self.changed();
			}
		}
		
		
		if ((box = document.getElementById("car_model_metallic")) != null) {
			this.car_model_metallic = new ic_multiple(box);
			this.car_model_metallic.change_event = function() {
				self.changed();
			}
		}
		if ((box = document.getElementById("car_model_equipment")) != null) {
			this.car_model_equipment = new ic_multiple(box);
			this.car_model_equipment.change_event = function() {
				self.changed();
			}
		}
		if ((box = document.getElementById("car_model_color")) != null) {
			this.car_model_color = new ic_multiple(box);
			this.car_model_color.change_event = function() {
				self.changed();
			}
		}
		
		this.constr_touch();
	}
	
	car_form_class.prototype.p_toggle = function() {
		if (this.p_container != null) {
			this.p_open = !this.p_open;
			this.p_mass = 0;
			this.p_top.className = this.p_open ? "top top_closed" : "top";
		}
	}
	
	car_form_class.prototype.constr_touch = function() {
		if (this.car_model_constr_toggle != null && this.car_model_constr != null && this.car_model_constr_toggle.base != null && this.car_model_constr.base != null) {
			var nd = this.car_model_constr.inputs[0].parentNode.parentNode.parentNode.parentNode.parentNode;
			var bn = this.car_model_constr_toggle.base.parentNode;
			
			if (this.car_model_constr_toggle.get_checked() == "all") {
				if (nd.className == "panel_dark panel_dark_active") nd.className = "panel_dark";
				if (bn.className == "panel_relative panel_relative_active") bn.className = "panel_relative";
				this.car_model_constr.enable(false);
			} else {
				if (nd.className == "panel_dark") nd.className = "panel_dark panel_dark_active";
				if (bn.className == "panel_relative") bn.className = "panel_relative panel_relative_active";
				this.car_model_constr.enable(true);
			}
		}
	}
	
	car_form_class.prototype.motion = function() {
		if (this.sr_size != null && this.sr_size > 0.2) {
			this.sr_size += - 0.1;
			if (this.sr_size <= 0.2) this.sr_size = 0.2;
			
			var f;
			for (f = 0; f < this.search_results_count.length; f++) {
				this.search_results_count[f].style.lineHeight = this.sr_size == 0.2 ? "" : (this.sr_size + "em");
				this.search_results_count[f].style.color = this.sr_size == 0.2 ? "" : "red";
				//this.search_results_count[f].style.fontSize = this.sr_size == 1.2 ? "" : (this.sr_size + "em");
				//this.search_results_count[f].style.position = this.sr_size == 1.2 ? "static" : "absolute";
			}
		}
		
		if (this.p_container != null) {
			var reach = this.p_open ? context.get_elementHeight(this.p_container.childNodes[0]) : 0;
			
			if (this.p_point > reach) this.p_mass += -1.8;
			else if (this.p_point < reach) this.p_mass += 1.8;
			else this.p_mass = 0.0;
			
			if (this.p_mass != 0) {
				this.p_point += this.p_mass;
				if (reach == 0) {
					if (this.p_point <= reach) this.p_point = reach;
				} else {
					if (this.p_point >= reach) this.p_point = reach;
				}
				
				this.p_container.style.height = Math.round(this.p_point) + "px";
			}
		}
	}
	
	car_form_class.prototype.mount = function(body, name, data, nocheck) {
		if (data != null) {
			if (typeof data == "string" || typeof data == "number") {
				data = "" + data;
				if (data != "" || nocheck != null) body.add_child(name, data);
				
			} else if (data.length > 0) {
				var f;
				for (f = 0; f < data.length; f++) {
					data[f] = "" + data[f];
					if (data[f] != "" || nocheck != null) body.add_child(name, data[f]);
				}
			}
		}
	}
	
	car_form_class.prototype.changed = function(ref) {
		var self = this, res, f, body, struct = new structure_class();
		
		if ((body = struct.map("body")) != null) {
			
			struct.map("head/major", "car_count");
			struct.map("head/lang", this.lang);
			if (this.filter_string != "") struct.map("head/filter_string", this.filter_string);
			
			if (this.car_model_constr_toggle != null) this.mount(body, "constr_toggle", this.car_model_constr_toggle.get_checked());
			if (this.car_model_constr != null) this.mount(body, "constr", this.car_model_constr.get_checked());
			
			if (this.car_model_producer != null) {
				res = this.car_model_producer.get_values();
				for (f = 0; f < res.length; f++)
					this.mount(body, "producer", res[f], true);
					
			} else if (this.car_model_producer_simple != null) {
				res = this.car_model_producer_simple.get_values();
				for (f = 0; f < res.length; f++)
					this.mount(body, "producer", res[f], true);
				this.mount(body, "producer", "", true);
			}
			
			if (this.car_model_price != null) this.mount(body, "price", this.car_model_price.get_values());
			if (this.car_model_year != null) this.mount(body, "year", this.car_model_year.get_values());
			if (this.car_model_km != null) this.mount(body, "km", this.car_model_km.get_values());
			if (this.car_model_kw != null) this.mount(body, "kw", this.car_model_kw.get_values());
			
			if (this.car_model_engine != null) this.mount(body, "engine", this.car_model_engine.get_value());
			if (this.car_model_dest_car_fuel_ID != null) this.mount(body, "dest_car_fuel_ID", this.car_model_dest_car_fuel_ID.get_value());
			if (this.car_model_dest_car_transmission_ID != null) this.mount(body, "dest_car_transmission_ID", this.car_model_dest_car_transmission_ID.get_value());
			if (this.car_model_dest_car_air_condition_ID != null) this.mount(body, "dest_car_air_condition_ID", this.car_model_dest_car_air_condition_ID.get_value());
			if (this.car_model_dest_car_doors_ID != null) this.mount(body, "dest_car_doors_ID", this.car_model_dest_car_doors_ID.get_value());
			
			if (this.car_model_metallic != null) this.mount(body, "metallic", this.car_model_metallic.get_checked());
			if (this.car_model_equipment != null) this.mount(body, "equipment", this.car_model_equipment.get_checked());
			if (this.car_model_color != null) this.mount(body, "color", this.car_model_color.get_checked());
			
			context.request("car_count", null, function(data, request) {
				if (self != null) self.evt_changed(data, request);
			}, struct);
		}
	}
	
	car_form_class.prototype.evt_changed = function(data, request) {
		var res;
		if ((res = request.get_response()) != null) {
			
			var head = res[0];
			var body = res[1];
			
			var f, count, el = head.getElementsByTagName("car_count");
			if (el.length > 0) {
				count = context.element_value(el[0]);
				
				if (this.search_results_href != null) this.search_results_href.style.display = "block";
				if (this.search_results_block != null) this.search_results_block.style.display = "block";
				
				for (f = 0; f < this.search_results_count.length; f++)
					this.search_results_count[f].innerHTML = count;
				this.sr_size = 1.2;
			}
			
		}
	}
	
	// --- selectors ---
	
	car_form_class.prototype.create_selector_from_multiple = function(input) {
		if (input != null) {
			var f, ref, tmp, tmpb, tmpc, founded, second;
			
			tmp = input.inputs[0].parentNode.parentNode;
			founded = null;
			f = 0;
			
			while (f < tmp.childNodes.length && founded == null)
				if (tmp.childNodes[f].nodeType == 1 && tmp.childNodes[f].tagName.toUpperCase() == "TD") founded = tmp.childNodes[f];
				else f++;
			
			if (founded != null) {
				second = document.createElement("TD");
				second.className = "second";
				founded.parentNode.insertBefore(second, founded.nextSibling);
				
				for (f = 0; f < input.inputs.length; f++) {
					tmp = input.inputs[f].parentNode.nextSibling;
					while (tmp != null && (tmp.nodeType != 1 || tmp.tagName.toUpperCase() != "TD"))
						tmp = tmp.nextSibling;
					
					tmpb = input.inputs[f].parentNode;
					
					if (f != 0) {
						tmpc = document.createElement("SPAN");
						tmpc.innerHTML = " &nbsp;|&nbsp; ";
						second.appendChild(tmpc);
					}
					
					ref = new car_form_selector(this, "checkbox", input.inputs[f], tmp);
					ref.container = second;
					this.selectors[this.selectors.length] = ref;
					ref.construct();
					
					context.structure_destroy(tmpb);
					if (tmp != null) context.structure_destroy(tmp);
				}
				
				input.base = null;
			}
		}
	}
	
	car_form_class.prototype.create_selector_from_select = function(input) {
		if (input != null) {
			var ref;
			
			ref = new car_form_selector(this, "select", input.base, "");
			ref.container = input.base.parentNode;
			this.selectors[this.selectors.length] = ref;
			ref.construct();
		}
	}
	
	car_form_class.prototype.create_selector_from_radio = function(input) {
		if (input != null) {
			var f, sf, ref, tmp, out, stack, current, captions = new Array();
			
			for (f = 0; f < input.inputs.length; f++) {
				tmp = input.inputs[f].parentNode.nextSibling;
				while (tmp != null && (tmp.nodeType != 1 || tmp.tagName.toUpperCase() != "TD"))
					tmp = tmp.nextSibling;
					
				out = "";
				stack = new Array();
				stack[0] = tmp;
				
				while (stack.length > 0) {
					current = stack.pop();
					
					if (current.nodeType == 1) {
						for (sf = current.childNodes.length - 1; sf >= 0; sf--)
							stack[stack.length] = current.childNodes[sf];
							
					} else if (current.nodeType == 3) out += current.nodeValue;
				}
				
				captions[captions.length] = out;
			}
			
			ref = new car_form_selector(this, "radio", input.inputs, captions);
			ref.container = input.base.parentNode;
			this.selectors[this.selectors.length] = ref;
			ref.construct();
			
			context.structure_destroy(input.base);
			input.base = null;
		}
	}
	
	car_form_class.prototype.build_result_selector = function(parent) {
		var self = this;
		
		if (this.car_model_producer != null) {
			var ref;
			ref = new car_form_selector(this, "producer", this.car_model_producer, "");
			this.selectors[this.selectors.length] = ref;
			ref.construct();
		}
		
		this.create_selector_from_multiple(this.car_model_constr);
		this.create_selector_from_multiple(this.car_model_equipment);
		this.create_selector_from_multiple(this.car_model_color);
		
		this.create_selector_from_select(this.car_model_engine);
		this.create_selector_from_select(this.car_model_dest_car_fuel_ID);
		this.create_selector_from_select(this.car_model_dest_car_transmission_ID);
		this.create_selector_from_select(this.car_model_dest_car_air_condition_ID);
		this.create_selector_from_select(this.car_model_dest_car_doors_ID);
		
		this.create_selector_from_radio(this.car_model_constr_toggle);
		this.create_selector_from_radio(this.car_model_metallic);
		
		this.changed_old = this.changed;
		this.changed = function(ref) {
			if (ref == null || (ref !== self.car_model_producer && ref.slide_size == null)) {
				self.search_form.submit();
			} else {
				self.changed_old(ref);
			}
		}
	}
	
