var Color = {
	palette: {
		1:{1:'ffffcc', 2:'ffff66', 3:'ffcc66', 4:'f2984c', 5:'e1771e', 6:'b47b10', 7:'a9501b', 8:'6f3c1b', 9:'804000', 10:'cc0000', 11:'940f04', 12:'660000'},
		2:{1:'c3d9ff', 2:'99c9ff', 3:'66b5ff', 4:'3d81ee', 5:'0066cc', 6:'6c82b5', 7:'32527a', 8:'2d6e89', 9:'006699', 10:'215670', 11:'003366', 12:'000033'},
		3:{1:'caf99b', 2:'80ff00', 3:'00ff80', 4:'78b749', 5:'2ba94f', 6:'38b63c', 7:'0d8f63', 8:'2d8930', 9:'1b703a', 10:'11593c', 11:'063e3f', 12:'002e3f'},
		4:{1:'ffbbe8', 2:'e895cc', 3:'ff6fcf', 4:'c94093', 5:'9d1961', 6:'800040', 7:'800080', 8:'72179d', 9:'6728b2', 10:'6131bd', 11:'341473', 12:'400058'},
		5:{1:'ffffff', 2:'e6e6e6', 3:'cccccc', 4:'b3b3b3', 5:'999999', 6:'808080', 7:'7f7f7f', 8:'666666', 9:'4c4c4c', 10:'333333', 11:'191919', 12:'000000'}
	},

	Open: function(ob, id) {
		if (getElemByID('palette_' + id))
			return;


		var obColList = ob.appendChild(document.createElement('DIV'));
		obColList.className = 'palette';
		//obColList.style.display = 'none';

		HTML = '<table cellspacing="0" onClick="EVENTS.menuMulti()">';

		for (var tr in Color.palette) {
			HTML += '<tr>';
			for (var clr in Color.palette[tr]) {
				ColorID = Color.palette[tr][clr];
				HTML += '<td><div class="aclr" event="hover" onClick="Color.it(\''+id+'\', \''+ColorID+'\')" style="background:#'+ColorID+';"></div></td>';
			}
			HTML += '</tr>';
		}

		HTML += '</table>';
		obColList.innerHTML = HTML;


		obColList.id = 'palette_' + id;


		ob.removeAttribute('event');
		ob.setAttribute('event', 'menu');
		ob.setAttribute('list', 'ob');
		ob.setAttribute('ob', obColList.id);
		ob.setAttribute('closeOut', '2');


		ob.onclick = function() {};
		EVENTS.menu(ob);
		EVENTS.Search(ob);
		ob.onclick();
	},

	it: function (id, color) {
		getElemByID(id).value = color;
		getElemByID('anons_' + id).style.background = '#'+color;
	}
}







function Calendar ()
{
	var $this = this;
	this.ob = false;
	this.noClose = false;

	this.DWeek = {			// Дни недели
		1:'Пн',
		2:'Вт',
		3:'Ср',
		4:'Чт',
		5:'Пт',
		6:'Сб',
		0:'Вс'
	};
	this.Month = {			// Месяцы
		00:'Январь',
		01:'Февраль',
		02:'Март',
		03:'Апрель',
		04:'Май',
		05:'Июнь',
		06:'Июль',
		07:'Август',
		08:'Сентябрь',
		09:'Октябрь',
		10:'Ноябрь',
		11:'Декабрь'
	};


	this.CDate = '';

	this.PDate = {'YY':'', 'MM':''};


	this.start = function (pCLD, id, dNull, TIME) {
		if ($this.ob) {
			if ($this.ob.getAttribute('date_id') == id) {
				return;
			} else {
				CLD.noClose = false;
				CLD.close();
			}
		}


		$this.CDate = new Date();


		$this.ob = pCLD.insertAdjacentElement('afterBegin', document.createElement('DIV'));
		$this.ob.onclick = function () {
			CLD.noClose = true;
			setTimeout("CLD.noClose = false", 0);
		};
		$this.ob.className = 'cld';
		$this.ob.setAttribute('date_id', id);
		$this.ob.setAttribute('dNull', dNull);
		$this.ob.setAttribute('time', TIME);




		DATE = getElemByID(id).value;
		if (DATE) {
			if ($this.ob.getAttribute('time') == 'Y') {
				var arDateTime = unescape(DATE).split(' ');

				var arDate = unescape(arDateTime['0']).split('.');

				var arTime = unescape(arDateTime['1']).split(':');


				cHH = parseInt(arTime['0']);
				cMI = parseInt(arTime['1']);
				cSS = parseInt(arTime['2']);

				$this.CDate.setHours(cHH);
				$this.CDate.setMinutes(cMI);
				$this.CDate.setSeconds(cSS);
			} else {
				var arDate = unescape(DATE).split('.');
			}


			cDD = parseInt(arDate['0']);
			cMM = parseInt(arDate['1']) - 1;
			cYY = parseInt(arDate['2']);

			$this.CDate.setFullYear(cYY);
			$this.CDate.setMonth(cMM);
			$this.CDate.setDate(cDD);

		} else {
			cDD = $this.CDate.getDate();
			cMM = $this.CDate.getMonth();
			cYY = $this.CDate.getFullYear();
		}




		$this.PDate['YY'] = cYY;
		$this.PDate['MM'] = cMM;


		HTML = $this.MakeList();
		$this.ob.innerHTML = HTML['MMYY'] + '<div id="calendar">' + HTML['CLD'] + '</div>' + HTML['OTHER'];


		setTimeout("EVENT.Add(document, 'click', CLD.close)", 0);

		EVENTS.Search($this.ob);
	};

		// Отмечаем дату
	this.mark = function (cYY, cMM, cDD, ob) {


		YY = this.CDate.getFullYear();
		MM = this.CDate.getMonth();	// Внимание!!! Отсчет начинаеться с 0
		DD = this.CDate.getDate();


		OldID = 'date_'+YY+MM+DD;
		if (getElemByID(OldID)) {
			var OldDay = getElemByID(OldID);
			OldDay.className = OldDay.className.replace(' choose', '')
		}

		this.CDate.setFullYear(cYY);
		this.CDate.setMonth(cMM);
		this.CDate.setDate(cDD);


		Month = '';




		if (parseInt(this.CDate.getMonth()) < 10)
			D_NEW = this.CDate.getFullYear() + '0' + this.CDate.getMonth();
		else
			D_NEW = this.CDate.getFullYear() + '' + this.CDate.getMonth();



		if (parseInt(MM) < 10)
			D_OLD = this.PDate['YY'] + '0' + this.PDate['MM'];
		else
			D_OLD = this.PDate['YY'] + '' + this.PDate['MM'];



		if (parseInt(D_NEW) < parseInt(D_OLD))
			Month = 'next';
		else if (parseInt(D_NEW) > parseInt(D_OLD))
			Month = 'back';




		getElemByID('date_MM').innerHTML = this.Month[this.CDate.getMonth()];
		getElemByID('date_YY').innerHTML = this.CDate.getFullYear();


		if (Month) {


			OldIDList = 'dey_week_list';


			HTML = this.MakeList();
			var obCalendar = getElemByID('calendar');
			obCalendar.innerHTML += HTML['CLD'];


			obListOld = getElemByID(OldIDList);
			obListOld.style.overflow = 'hidden';
			obListOld.style.position = 'absolute';
			obListOld.style.zIndex = '9501';



			var obTbl = obListOld.getElementsByTagName('table');

			if (Month == 'back') {
				obListOld.style.right = 0;
				obTbl[0].style.borderLeft = '1px solid #9b9b9b';
			} else {
				obTbl[0].setAttribute('align', 'right');
				obTbl[0].style.borderRight = '1px solid #9b9b9b';
			}





			var sizeOld = new Effect();
			sizeOld.final = function (ob) {
				ob.parentNode.removeChild(ob);

				var obCLD = getElemByID('calendar');
				EVENTS.Search(obCLD);
			}

			var sizeNew = new Effect();
			sizeNew.final = function (ob) {}



			sizeOld.start(obListOld, {width:0}, 0.2);
		} else {
			ob.className += ' choose';
		}

			// Указываем даты которые печатаем на странице
		this.PDate['YY'] = this.CDate.getFullYear();
		this.PDate['MM'] = this.CDate.getMonth();





		if (this.ob.getAttribute('time') == 'Y')
			DATE = DATA['FORMAT_DATETIME'];
		else
			DATE = DATA['FORMAT_DATE'];

		if (cDD <= 9)
			cDD = '0' + cDD;

		cMM = parseInt(cMM) + 1;
		if (cMM <= 9)
			cMM = '0' + cMM;

		DATE = DATE.replace('YYYY', cYY);
		DATE = DATE.replace('MM', cMM);
		DATE = DATE.replace('DD', cDD);


		if (this.ob.getAttribute('time') == 'Y') {
			tHH = getElemByID('cld_time_hh').value;
			tMI = getElemByID('cld_time_mi').value;
			tSS = getElemByID('cld_time_ss').value;

			if (!tHH) tHH = '00';
			if (!tMI) tMI = '00';
			if (!tSS) tSS = '00';


			DATE = DATE.replace('HH', tHH);
			DATE = DATE.replace('MI', tMI);
			DATE = DATE.replace('SS', tSS);
		}

		date_id = this.ob.getAttribute('date_id');

		getElemByID(date_id).value = DATE;

	};


		// Устанавливаем сегодняшнюю дату
	this.GoTD = function () {
		if (this.ob.getAttribute('time') == 'Y')
			DATE = DATA['FORMAT_DATETIME'];
		else
			DATE = DATA['FORMAT_DATE'];



		var CDateTD = new Date();

		tDD = CDateTD.getDate();
		tMM = CDateTD.getMonth();
		tYY = CDateTD.getFullYear();

		if (tDD <= 9)
			tDD = '0' + tDD;

		tMM = parseInt(tMM) + 1;
		if (tMM <= 9)
			tMM = '0' + tMM;

		DATE = DATE.replace('YYYY', tYY);
		DATE = DATE.replace('MM', tMM);
		DATE = DATE.replace('DD', tDD);

		if (this.ob.getAttribute('time') == 'Y') {
			tHH = CDateTD.getHours();
			tMI = CDateTD.getMinutes();
			tSS = CDateTD.getSeconds();

			if (tHH <= 9) tHH = '0' + tHH;
			if (tMI <= 9) tMI = '0' + tMI;
			if (tSS <= 9) tSS = '0' + tSS;

			DATE = DATE.replace('HH', tHH);
			DATE = DATE.replace('MI', tMI);
			DATE = DATE.replace('SS', tSS);
		}

		date_id = this.ob.getAttribute('date_id');

		getElemByID(date_id).value = DATE;


		setTimeout("CLD.noClose = false; CLD.close()", 0)
	}

		// Устанавливаем текущее время
	this.GoTDTime = function () {
		DATE = DATA['FORMAT_DATE'];



		var CDateTD = new Date();

		tHH = CDateTD.getHours();
		tMI = CDateTD.getMinutes();
		tSS = CDateTD.getSeconds();


		if (tMI <= 9)
			tMI = '0' + tMI;

		if (tSS <= 9)
			tSS = '0' + tSS;


		getElemByID('cld_time_hh').value = tHH;
		getElemByID('cld_time_mi').value = tMI;
		getElemByID('cld_time_ss').value = tSS;
	}

		// Очишаем дату
	this.dNull = function () {
		date_id = this.ob.getAttribute('date_id');
		getElemByID(date_id).value = '';
		setTimeout("CLD.noClose = false; CLD.close()", 0)
	}



		// Функция Сменяет месяц
	this.ReplaceMMYY = function (YY, MM) {


		if (YY)
			YY = parseInt(YY);
		else
			YY = this.PDate['YY'];




		if (MM)
			MM = parseInt(MM);
		else
			MM = this.PDate['MM'];







		if (parseInt(this.CDate.getMonth()) < 10)
			D_OLD = this.PDate['YY'] + '0' + this.PDate['MM'];
		else
			D_OLD = this.PDate['YY'] + '' + this.PDate['MM'];



		if (parseInt(MM) < 10)
			D_NEW = YY + '0' + MM;
		else
			D_NEW = YY + '' + MM;


		Month = '';

		if (parseInt(D_NEW) < parseInt(D_OLD))
			Month = 'next';
		else if (parseInt(D_NEW) > parseInt(D_OLD))
			Month = 'back';



		//ech (Month);


		EVENTS.closeMenu();
		getElemByID('date_MM').innerHTML = this.Month[MM];
		getElemByID('date_YY').innerHTML = YY;


		if (Month) {
			OldIDList = 'dey_week_list';

			HTML = this.MakeList(YY, MM);
			var obCalendar = getElemByID('calendar');
			obCalendar.innerHTML += HTML['CLD'];


			obListOld = getElemByID(OldIDList);
			obListOld.style.overflow = 'hidden';
			obListOld.style.position = 'absolute';
			obListOld.style.zIndex = '9501';



			var obTbl = obListOld.getElementsByTagName('table');

			if (Month == 'back') {
				obListOld.style.right = 0;
				obTbl[0].style.borderLeft = '1px solid #9b9b9b';
			} else {
				obTbl[0].setAttribute('align', 'right');
				obTbl[0].style.borderRight = '1px solid #9b9b9b';
			}





			var sizeOld = new Effect();
			sizeOld.final = function (ob) {
				ob.parentNode.removeChild(ob);

				EVENTS.Search(CLD.ob);
			}

			var sizeNew = new Effect();
			sizeNew.final = function (ob) {}



			sizeOld.start(obListOld, {width:0}, 0.2);
		}


		this.PDate['YY'] = YY;
		this.PDate['MM'] = MM;
	},








		// Возврашает Год, месяц, и Количество дней
	this.MonthInfo = function (YY, MM) {
		var d = new Date(
			YY,
			MM + 1,
			0
		);
		return {
			'YY':d.getFullYear(),
			'MM':d.getMonth(),
			'DD_CNT':d.getDate()
		};
	};

		// Определяем день недели первого числя
	this.DeffDayWeek = function (YY, MM) {
		var d = new Date(
			YY,
			MM,
			1
		);
		return d.getDay();
	};

		// Функция генерирует календарь
	this.MakeList = function (pYY, pMM) {

		// ВНИМАНИЕ!!! приставки к датам означают:
		// "t" Сегодняшняя дата
		// "c" Выбранная дата
		// "p" Показывать дату

			// Сегоднешняя дата
		var CTD = new Date();
		tYY = CTD.getFullYear();
		tMM = CTD.getMonth();	// Внимание!!! Отсчет начинаеться с 0
		tDD = CTD.getDate();





		cYY = this.CDate.getFullYear();
		cMM = this.CDate.getMonth();	// Внимание!!! Отсчет начинаеться с 0
		cDD = this.CDate.getDate();


		if (!pYY)
			pYY = this.CDate.getFullYear();
		if (!pMM)
			pMM = this.CDate.getMonth();	// Внимание!!! Отсчет начинаеться с 0



			// Определяем количество дней в месяце
		CURRENT = this.MonthInfo(pYY, pMM);
		//ech (CURRENT);


			// День недели первого числа
		DayWeek = this.DeffDayWeek(pYY, pMM);	// отсчет начинается с 0


			// Количество дней предыдушего месяца
		if (DayWeek == 0)	   DeyBack = 6;
		else if (DayWeek == 1) DeyBack = 5;
						  else DeyBack = DayWeek - 1;


			// Количество дней следующего месяца
			// (42 - общее количество дней в окне календаря)
		DeyNext = 42 - CURRENT['DD_CNT'] - DeyBack;


		DAY_LIST = {};	// Список дней (дат)
		D = 0;

			// Если нужны дни предыдушего месяца
		if (DeyBack > 0) {
				// Определяем количество дней в предедущем месяце
			BACK = this.MonthInfo(pYY, pMM - 1);


				// Генерируем даты передыдушего месяца
			day = BACK['DD_CNT'] - DeyBack + 1;
			for (day; day <= BACK['DD_CNT']; day++) {
				D++;
				DAY_LIST[D] = {
					'YY':BACK['YY'],	// Год
					'MM':BACK['MM'],	// Месяц
					'DD':day,			// День
					'MONTH':'back'	// Метка что менсяц предыдуший
				};
			}
		}



			// Генерируем даты выбранного месяца
		for (day = 1; day <= CURRENT['DD_CNT']; day++) {
			D++;
			DAY_LIST[D] = {
				'YY':pYY,			// Год
				'MM':pMM,			// Месяц
				'DD':day,			// День
				'MONTH':'chose'	// Метка что менсяц выбранный
			};
		}

		if (DeyNext > 0) {
				// Рабтаем со следуюшим месяцем
			NEXT = this.MonthInfo(pYY, pMM + 1);


				// Генерируем даты будушего месяца
			for (day = 1; day <= DeyNext; day++) {
				D++;
				DAY_LIST[D] = {
					'YY':NEXT['YY'],	// Год
					'MM':NEXT['MM'],	// Месяц
					'DD':day,			// День
					'MONTH':'next'		// Метка что менсяц будущий
				};
			}


				// Возврашаем текуший месяц
			this.CDate.setMonth(cMM);
		}

		eMM = 'event="menu"  pos="v" closeOut="0.2" list="js" ob="MM_LIST"'; // Событие для месяца
		eYY = 'event="menu"  pos="h" closeOut="0.2" list="js" ob="YY_LIST"'; // Событие для года

		MMYY = '';
		HTML_CLD = '';



			// Для вызова меню со всеми месяцами
			DATA['MENU']['MM_LIST'] = {};
			for (var MenuMM in this.Month)
			{
				DATA['MENU']['MM_LIST'][MenuMM] = {
					'NAME':this.Month[MenuMM],
					'JS':'CLD.ReplaceMMYY(false, \''+MenuMM+'\')',
					'ICO':''
				}
			}

			// Для вызова меню со списком годов
		DATA['MENU']['YY_LIST'] = {};
		for (MenuYY = pYY - 6; MenuYY <= pYY + 6; MenuYY++)
		{
			DATA['MENU']['YY_LIST'][MenuYY] = {
				'NAME':MenuYY,
				'JS':'CLD.ReplaceMMYY(\''+MenuYY+'\', false)',
				'ICO':''
			}
		}




			// Месяц и год
		MMYY += '<table cellspacing="0" class="MMYY">';
			MMYY += '<tr>';
				MMYY += '<td width="90" '+eMM+' class="MY"><div class="MY" id="date_MM">'+this.Month[pMM]+'</div></td>';
				MMYY += '<td '+eYY+' class="MY"><div class="MY" id="date_YY">'+pYY+'</div></td>';
				MMYY += '<td width="17" align="center" event="hover" onClick="setTimeout(\'CLD.noClose = false; CLD.close()\', 0)" class="MY" title="Закрыть"><img src="/agvay/admin/icons/form/cld_close.png" width="12" height="12"></td>';
			MMYY += '</tr>';
		MMYY += '</table>';


			// Дни недели
		HTML_CLD += '<div id="dey_week_list" class="date_list"><table cellspacing="0">';
			HTML_CLD += '<tr>';
			for (var D in this.DWeek)
				if (D >= 1)
					HTML_CLD += '<td class="dweek">' + this.DWeek[D] + '</td>';

				HTML_CLD += '<td class="dweek">' + this.DWeek[0] + '</td>';
			HTML_CLD += '</tr>';
			HTML_CLD += '<tr>';


			// Создаем список дат
		W = 1;
		for (var D in DAY_LIST)
		{
			DAY = DAY_LIST[D];

			if (DAY['MONTH'] == 'chose')
				HTML_CLD += '<td>';
			else
				HTML_CLD += '<td class="other">';


			c = '';

				// Если данная дата выбранна
			if (DAY['DD'] == cDD && DAY['MM'] == cMM && DAY['YY'] == cYY)
				c += ' choose';

				// Если данная дата сегодня
			if (DAY['DD'] == tDD && DAY['MM'] == tMM && DAY['YY'] == tYY)
				c += ' today';


			FParam = "'"+DAY['YY']+"', '"+DAY['MM']+"', '"+DAY['DD']+"', this";

			param = 'event="hover"';
			param += ' id="date_'+DAY['YY']+DAY['MM']+DAY['DD']+'"';
			param += ' onClick="CLD.mark('+FParam+')"';
			param += ' OnDblClick="setTimeout(\'CLD.noClose = false; CLD.close()\', 0)"';

			HTML_CLD += '<div class="D'+c+'" '+param+'>' + DAY['DD'] + '</div>';
			HTML_CLD += '</td>';

			W++;
			if (W > 7) {
				HTML_CLD += '</tr><tr>';
				W = 1;
			}
		}
			HTML_CLD += '</tr>';
		HTML_CLD += '</table></div>';











			// Прочее (время - если нужно, кнопка "сегодня", и кнопка "очистить")
		OTHER = '';
		OTHER += '<table cellspacing="0" class="other">';
			OTHER += '<tr>';
				OTHER += '<td class="o" event="hover" onClick="CLD.GoTD()" width="24" align="center" title="Сегодняшняя дата"><img src="/agvay/admin/icons/form/cld_td.png" width="18" height="18"></td>';





				if (this.ob.getAttribute('time') == 'Y') {


					cHH = $this.CDate.getHours();
					cMI = $this.CDate.getMinutes();
					cSS = $this.CDate.getSeconds();


					if (cHH <= 9) cHH = '0' + cHH;
					if (cMI <= 9) cMI = '0' + cMI;
					if (cSS <= 9) cSS = '0' + cSS;


					OTHER += '<td align="center">';
						OTHER += '<input id="cld_time_hh" class="itime" type="text" value="'+cHH+'">:';
						OTHER += '<input id="cld_time_mi" class="itime" type="text" value="'+cMI+'">:';
						OTHER += '<input id="cld_time_ss" class="itime" type="text" value="'+cSS+'">';
					OTHER += '</td>';

					OTHER += '<td class="o" event="hover" onClick="CLD.GoTDTime()" width="24" align="center" title="Текущее время"><img src="/agvay/admin/icons/form/cld_time.png" width="18" height="18"></td>';
				} else {
					OTHER += '<td>&nbsp;</td>';
				}







				if (this.ob.getAttribute('dNull') == 'Y') {
					OTHER += '<td class="o" event="hover" onClick="CLD.dNull()" width="24" align="center" title="Очистить дату"><img src="/agvay/admin/icons/form/cld_del.png" width="18" height="18"></td>';
				} else {
					OTHER += '<td>&nbsp;</td>';
				}
			OTHER += '</tr>';
		OTHER += '</table>';





		return {'MMYY':MMYY, 'CLD':HTML_CLD, 'OTHER':OTHER};
	};


	this.close = function () {

		if ($this.noClose)
			return;


		date_id = $this.ob.getAttribute('date_id');
		getElemByID('p_'+date_id).className = 'c';

		$this.ob.parentNode.removeChild($this.ob);
		EVENT.Del(document, 'click', CLD.close);
		$this.ob = false;
	};
}
var CLD = new Calendar();

















	// Осушествояем поиск товара вводя его название
var CatSearch =
{
	id_block: '',			// ID рабочего блока
	key_event: false,		// Добавленно событие для выбора стрелками
	input_val: '',			// Текушее значение строки ввода





	reg: function(ob)
	{
		CatSearch.input_val = ob.value;
	},

		// Посылаем запрос по имени товара
	go_cat: function (e, ob) {
		if(!e) e = window.event

		//confirm(e.keyCode);

			// Нажатие стрелок вверх, вниз
		if (e.keyCode == '38' || e.keyCode == '40') {
			CatSearch.drag_key_res(e);
			return false;
		}

		if (ob.value == CatSearch.input_val) {
			return false;
		}

		CatSearch.input_val = ob.value;


		id = ob.id.replace('_name', '');
		CatSearch.id_block = id;

		document.getElementById(id + '_wr_id').innerHTML = '';
		document.getElementById(id + '_id').value = '';
		document.getElementById(id + '_img').innerHTML = '';

		if (document.getElementById(id + '_pr_wr'))
			document.getElementById(id + '_pr_wr').innerHTML = '';
		if (document.getElementById(id + '_pr'))
			document.getElementById(id + '_pr').value = '';
		if (document.getElementById(id + '_wh'))
			document.getElementById(id + '_wh').innerHTML = '';
		if (document.getElementById(id + '_unit'))
			document.getElementById(id + '_unit').innerHTML = '';


		if (!ob.value) {
			document.getElementById(id + '_res').innerHTML = '';
			return;
		}

		post = {};
		post = {'AJAX_MODE' : 'Y', 'CATALOG_NAME' : ob.value};

		ID = CAjax.makeInquiry('/agvay/tools/catalog_search.php', false, post, this.res_go_cat)
		CAjax.Inquiry(ID);

	},


	stop: function (ob) {
		id = ob.id.replace('_name', '');
		CatSearch.id_block = id;
		document.getElementById(id + '_res').innerHTML = '';
		document.getElementById(id + '_img').innerHTML = '';
		CatSearch.input_val = '';
	},

	res_go_cat: function(p) {
		if (!CatSearch.id_block)
			return;

		id = CatSearch.id_block;


		Cheek = AdminAjax.CheekAnswer(p.data);	// Проверяем результат на предмет стандартного ответа сервера


		if (!Cheek)
			return;

		if (p.data.substr(0, 1) != '{')		// Проверяем коректность ответа
			return;



		HTML_CATALOG = '';
		data = {};
		eval('data = ' + p.data + ';');

		if (data['value'] != CatSearch.input_val)
			return;



		cat = data['catalog'];


		for (var key in cat)
		{
			HTML_CATALOG += '<div class="mp" price='+cat[key]['PRICE']+' wh='+cat[key]['WAREHOUSE_Q']+' un='+cat[key]['UN']+' img='+cat[key]['IMG']+' imgw='+cat[key]['IMG_W']+' id="search_catalog_' + cat[key]['ID'] + '">' + cat[key]['NAME'] + '</div>';
		}

		HTML_CATALOG += '<div class="mp" style="text-align:center;"><i><b>Открыть окно со списком</b></i></div>';


		var obCatMenu = document.getElementById(id + '_res');
		if (!HTML_CATALOG) {
			obCatMenu.innerHTML = '';
			return;
		}


		HTML = '';
		HTML += '<table cellspacing="0" class="catalog_search_menu">';
			HTML += '<tr><td class="t_b" colspan="3"></td></tr>';
			HTML += '<tr><td class="b"></td><td class="list">';
				HTML += HTML_CATALOG;
			HTML += '</td><td class="b"></td></tr>';
			HTML += '<tr><td class="lb_b"></td><td class="b"></td><td class="rb_b"></td></tr>';
		HTML += '</table>';

		obCatMenu.innerHTML = HTML;




			// Мутим события
		var obMp = obCatMenu.getElementsByTagName('div');
		for (var i=0; i<obMp.length; i++)
		{
			if (obMp[i].className == 'mp') {
					// При наведении
				obMp[i].onmouseover = function() {
					if (!CatSearch.id_block)
						return;

					if (this.id) {
						id = CatSearch.id_block;
						cat_id = this.id.replace('search_catalog_', '');

						document.getElementById(id + '_name').value = this.innerHTML;
						CatSearch.input_val = document.getElementById(id + '_name').value;

						document.getElementById(id + '_id').value = cat_id;
						document.getElementById(id + '_wr_id').innerHTML = '[<a href="/agvay/admin/ca_catalog.php?ID='+cat_id+'" title="'+this.innerHTML+'" target="balank">' + cat_id + '</a>]';

						if (this.getAttribute('img'))
							document.getElementById(id + '_img').innerHTML = '<div style="margin-left:-'+this.getAttribute('imgw')+'px;"><img src="'+this.getAttribute('img')+'"></div>';


						if (document.getElementById(id + '_pr_wr'))
							document.getElementById(id + '_pr_wr').innerHTML = this.getAttribute('price') + '&nbsp;руб.';
						if (document.getElementById(id + '_pr'))
							document.getElementById(id + '_pr').value = this.getAttribute('price');
						if (document.getElementById(id + '_wh'))
							document.getElementById(id + '_wh').innerHTML = this.getAttribute('wh');
						if (document.getElementById(id + '_unit')) {
							if (this.getAttribute('un') == '!!!') {
								document.getElementById(id + '_unit').innerHTML = '&nbsp;<span style="color:#7d0000;" title="Нет единицы измерения, движение не будет проведено">!!!</span>';
							} else {
								document.getElementById(id + '_unit').innerHTML = '&nbsp;' + this.getAttribute('un');
							}
						}
					} else {
						document.getElementById(id + '_name').value = '';
						document.getElementById(id + '_id').value = '';
						document.getElementById(id + '_wr_id').innerHTML = '';
						document.getElementById(id + '_img').innerHTML = '';

						if (document.getElementById(id + '_pr_wr'))
							document.getElementById(id + '_pr_wr').innerHTML = '';
						if (document.getElementById(id + '_pr'))
							document.getElementById(id + '_pr').value = '';
						if (document.getElementById(id + '_wh'))
							document.getElementById(id + '_wh').innerHTML = '';
						if (document.getElementById(id + '_unit'))
							document.getElementById(id + '_unit').innerHTML = '';
					}

					this.className += ' mp_hover'
				}
					// Снятие наведения
				obMp[i].onmouseout = function() {
					this.className = 'mp'
				}
					// Нажатие
				obMp[i].onmousedown = function() {
					if (!CatSearch.id_block)
						return;

					id = CatSearch.id_block;
					document.getElementById(id + '_res').innerHTML = '';

					if (!this.id) {
						ChoiceWin('/agvay/admin/ca_catalog_list.php?choice=Y&id='+id);
					}
				}
			}
		}
	},


		// Выделение результата кнопками
		// 38 - стрелка вверх
		// 40 - стрелка вниз
	drag_key_res: function(e) {
		if (!CatSearch.id_block)
			return;

		if(!e) e = window.event

		//confirm(window.event.keyCode);
		if (e.keyCode == '38' || e.keyCode == '40') {
			if (!CatSearch.id_block)
				return;

			id = CatSearch.id_block;
			if (!document.getElementById(id + '_res'))
				return;

			var obCatMenu = document.getElementById(id + '_res');

				// начинаем искать
			var obMp = obCatMenu.getElementsByTagName('div');
			for (var i=0; i<obMp.length; i++) {
				if (obMp[i].className == 'mp mp_hover') {
					obMp[i].className = 'mp';

						// Если вверх
					if (e.keyCode == '38' && typeof(obMp[i-1]) == 'object') {
						obMp[i-1].onmouseover();
						return false;
					}

						// Если вниз
					if (e.keyCode == '40' && typeof(obMp[i+1]) == 'object' && obMp[i+1].id) {
						obMp[i+1].onmouseover();
						return false;
					}
				}
			}

			if (e.keyCode == '38')
				obMp[obMp.length-2].onmouseover();

			if (e.keyCode == '40')
				obMp[0].onmouseover();

			return false;
		}
	}
}



