function PXAjax(url, onfunction, options, cache, method, onOptions) {
	var req = new Subsys_JsHttpRequest_Js();

	req.onreadystatechange = function() {
		if(req.readyState === 4) {
			if (typeof onfunction.call == 'undefined') {
				/* for IE 5.01 */
				req.responseJS.$call = onfunction;
				req.responseJS.$call(req, onOptions);
			} else {
				onfunction.call(req.responseJS, req, onOptions);
			}
		}
	};

	var cache  = (typeof cache  != 'undefined') ? cache  : true;
	var method = (typeof method != 'undefined') ? method : 'post';

	req.caching = cache;
	req.open(method, url, true);
	req.send(options);
}

// настройка телефонов
$(function() {
		var settingsForm = document.getElementById('phoneSettings');
		if(settingsForm == null) {
			return;
		}

		var selects = settingsForm.getElementsByTagName('select');
		var selectsIndex = {};

		var params = {'regid' : settingsForm.regid.value};
		for(var i=0; i<selects.length; i++) {
			var sel = selects[i];

			params[sel.name] = sel.options[sel.selectedIndex].value;

			sel.ind = i;
			selectsIndex[sel.name] = sel;
			sel.params = params;

			sel.Emptify = function() {
				if((this.ind + 1) === selects.length) {
					return;
				}

				var next = selects[this.ind+1];

				for(var i=next.childNodes.length; i>1; i--) {
					if(typeof next.childNodes[i] == 'object') {
						next.removeChild(next.childNodes[i]);
					}
				}

				this.params[next.name] = next.options[next.selectedIndex].value;
				next.disabled = true;

				next.Emptify();
			}

			sel.chooseNext = function() {
				val = this.options[this.selectedIndex].value;
				this.params[this.name] = val;

				if((this.ind + 1) === selects.length) {
					if(val != 0) {
						this.form.submit();
					}

					return;
				}

				var next = selects[this.ind+1];
				this.Emptify();

				if(val == '0') {
					next.chooseNext();
					return;
				}
				key = next.name;

				if(enums.hasOwnProperty(key) && enums[key].hasOwnProperty(val)) {
					_objs = enums[key][val];
				} else {
					_objs = [];

					return new PXAjax('/settings.json', this.onAjUpdate, this.params, true, 'get', this.params);
				}

				this.updateNext(next, _objs);
			}

			sel.onAjUpdate = function(req, params) {
				for(var i in params) {
					if(i == 'regid') {
						continue;
					}

					enums[i] = this[i];

					if(params[i] == '0') {
						sel = selectsIndex[i];
						return sel.updateNext(sel, enums[i][prev]);
					}

					prev = params[i];
				}
			}

			sel.updateNext = function(next, _objs) {
				for(var i in _objs) {
					var o = document.createElement('option');

					next.appendChild(o);

					_text = (window.xtype2title[i] !== undefined) ? xtype2title[i] : i;

					o.appendChild(document.createTextNode(_text))
					o.setAttribute('value', i);
				}

				if(next.options.length == 2) {
					next.selectedIndex = 1;
				} else {
					next.selectedIndex = 0;
				}

				next.disabled = false;
				next.chooseNext();
			}

			sel.onchange = function() {
					this.chooseNext();
			}
		}
	}
);

