	var globalHintInterval=0;
	var globalCloseInterval=0;

	function clearResult(){
		var prod_table=d.getElementById('globalSearchProductTable');
		var prod_body=prod_table.getElementsByTagName('tbody')[0];
		var rows=prod_body.getElementsByTagName('tr');
		var cnt=rows.length;
		for (i=0;i<cnt;i++){
			prod_body.removeChild(rows[0]);
		}

		var prod_table=d.getElementById('globalSearchCatTable');
		var prod_body=prod_table.getElementsByTagName('tbody')[0];
		var rows=prod_body.getElementsByTagName('tr');
		var cnt=rows.length;
		for (i=0;i<cnt;i++){
			prod_body.removeChild(rows[0]);
		}
		
		d.getElementById('globalSearchTable').style.display='none';
		
		if (d.getElementById('prodHintDiv'))
				d.getElementsByTagName('body')[0].removeChild(d.getElementById('prodHintDiv'))
		
	}
	
	
	function globalSearch(){
		var str=d.getElementById('globalSearchString').value;
		if (str) {
			req.open(null, '/jscript/common.php', true);
			req.send({
				param: str,
				query: 'showSearchResult',
				callback: 'globalSearchOut'
			})
		}
		else	
			clearResult();
		
	}
	
	function globalSearchOut(callback){
		clearResult();
		var prod_table=d.getElementById('globalSearchCatTable');
		var prod_body=prod_table.getElementsByTagName('tbody')[0];

		if (callback.categories.length) {
			for (i = 0; i < callback.categories.length; i++) {
				var tr = d.createElement('tr');
				var td = d.createElement('td');
				var a = d.createElement('a');
				a.innerHTML = callback.categories[i].name;
				a.href = '/catalog/' + callback.categories[i].url + '/';
				td.appendChild(a);
				tr.appendChild(td);
				prod_body.appendChild(tr);
			}
		}
		else {
				var tr = d.createElement('tr');
				var td = d.createElement('td');
				td.innerHTML='Ничего не найдено';
				tr.appendChild(td);
				prod_body.appendChild(tr);
		}

		var prod_table=d.getElementById('globalSearchProductTable');
		var prod_body=prod_table.getElementsByTagName('tbody')[0];

		if (callback.products.length) {
			for (i = 0; i < callback.products.length; i++) {
				if (i == 15) {
					var tr = d.createElement('tr');
					var td = d.createElement('td');
					td.style.textAlign='center';
					var a = d.createElement('a');
					a.innerHTML = 'Посмотреть весь список';
					a.href = 'javascript:showSearchPage();';
					td.appendChild(a);					
					tr.appendChild(td);
					prod_body.appendChild(tr);
				}
				else {
					var tr = d.createElement('tr');
					var td = d.createElement('td');
					var a = d.createElement('a');
					a.innerHTML = callback.products[i].brand_name + ' ' + callback.products[i].name;
					a.href = '/catalog/' + callback.products[i].cat_url + '/' + callback.products[i].brand_url + '/' + callback.products[i].url + '/';
					a.id = callback.products[i].id;
					a.onmouseover = function(){
						globalHintInterval = setTimeout('showProdHint(' + this.id + ')', 500);
					}
					a.onmouseout = function(){
						clearTimeout(globalHintInterval);
						globalCloseInterval = setTimeout('closeProdHint()', 400);
					}
					td.appendChild(a);
					tr.appendChild(td);
					prod_body.appendChild(tr);
				}
			}
		}
		else {
				var tr = d.createElement('tr');
				var td = d.createElement('td');
				td.innerHTML='Ничего не найдено';
				tr.appendChild(td);
				prod_body.appendChild(tr);
		}
		d.getElementById('globalSearchTable').style.position='absolute';		
		d.getElementById('globalSearchProdTitle').innerHTML='Совпадения товаров "'+callback.searchstring+'"';
		d.getElementById('globalSearchCatTitle').innerHTML='Совпадения категорий "'+callback.searchstring+'"';
		d.getElementById('globalSearchTable').style.display='block';
		d.getElementById('globalSearchTable').style.left=(getOffsetSum(d.getElementById('tableSearchAnchor')).left*1+1)+'px';
		d.getElementById('globalSearchTable').style.top=(getOffsetSum(d.getElementById('tableSearchAnchor')).top*1+60)+'px';
		
		//getOffsetSum(d.getElementById(callback.prod_param.id)).top+'px';
		
	}
	
		
	function showProdHint(id){
			req.open(null, '/jscript/common.php', true);
			req.send({
				param: id,
				query: 'showProdHint',
				callback: 'showProdHintOut'
			})
	}
	
	
	
	function showProdHintOut(callback){
//		alert('f');
		if (d.getElementById('prodHintDiv'))
				d.getElementsByTagName('body')[0].removeChild(d.getElementById('prodHintDiv'))
			
		if (callback){
			var div=d.createElement('div');
			div.className='div20';
			div.id='prodHintDiv';
			var root_table=d.createElement('table');
			root_table.cellPadding=0;
			root_table.cellSpacing=0;
			root_table.border=0;
			root_table.width=500;
			var root_body=d.createElement('tbody');
			var root_row=d.createElement('tr');
			var root_left_cell=d.createElement('td');
			root_left_cell.width=50;
			root_left_cell.vAlign='top';			
		//	root_left_cell.innerHTML='<a href="/catalog/'+callback.prod_param.cat_url+'/">'+callback.prod_param.cat_name+'</a>&nbsp;'			
		//	root_left_cell.innerHTML+='<a href="/catalog/'+callback.prod_param.cat_url+'/'+callback.prod_param.brand_url+'/">'+callback.prod_param.brand_name+'</a><br><br>'
			root_left_cell.innerHTML+='<br><a href="/catalog/'+callback.prod_param.cat_url+'/'+callback.prod_param.brand_url+'/'+callback.prod_param.url+'/">'+callback.prod_param.brand_name+' '+callback.prod_param.name+'</a><br>';
			root_left_cell.innerHTML+='<a style="font-size:10px;font-weight:normal" href="/catalog/'+callback.prod_param.cat_url+'/">'+callback.prod_param.cat_name+'</a><br><br>';

			if (callback.prod_param.image){
				var img_a=d.createElement('a');
				img_a.href='/catalog/'+callback.prod_param.cat_url+'/'+callback.prod_param.brand_url+'/'+callback.prod_param.url+'/';
				var img=new Image();
				img.src='/admin/_files/catalog/'+callback.prod_param.image;
				img.style.maxHeight='240px';
				img.style.maxWidth='200px';
				img_a.appendChild(img);
				root_left_cell.appendChild(img_a);
			}
			
			
			var root_right_cell=d.createElement('td');
			//root_right_cell.className='td43';
			root_right_cell.style.verticalAlign='top';
			root_right_cell.style.paddingTop='20px';
	
					
			var table_params=d.createElement('table');
			table_params.cellPadding='3'
			table_params.cellSpacing='0';
			table_params.className='table11';
			table_params.border=0;
			var body_params=d.createElement('tbody');
			
			for (i=0;i<callback.prod_fields.length;i++){
				var tr_param=d.createElement('tr');
				var td_param=d.createElement('td');
				td_param.className='td95';
				td_param.style.textAlign='left';
				td_param.innerHTML=callback.prod_fields[i].name;
				
				var td_param2=d.createElement('td');
				td_param2.className='td29';
				
				var td_param3=d.createElement('td');
				td_param3.className='td96';
				td_param3.style.textAlign='left';
				
				var value='';
				
					if (callback.prod_fields[i].ext_value)
						value=callback.prod_fields[i].ext_value;
					else {
						if (callback.prod_fields[i].type == 'isBool') {							
							if (callback.prod_fields[i].int_value=='1') 
								value = '<img src="/images/plus-2.gif">';
							else 
								value = '<img src="/images/minus-2.gif">';
							}
						else {
							value = callback.prod_fields[i].int_value;
						}
					}	
				
				td_param3.innerHTML=value;
				
				var tr_param_sep=d.createElement('tr');
				var td_param_1_sep=d.createElement('td');
				td_param_1_sep.className='td95';
				var td_param_2_sep=d.createElement('td');
				var td_param_3_sep=d.createElement('td');
				td_param_3_sep.className='td96';
				
				tr_param.appendChild(td_param);
				//tr_param.appendChild(td_param2);
				tr_param.appendChild(td_param3);
				
				body_params.appendChild(tr_param);
				
				tr_param_sep.appendChild(td_param_1_sep);
				tr_param_sep.appendChild(td_param_2_sep);
				tr_param_sep.appendChild(td_param_3_sep);				
				//body_params.appendChild(tr_param_sep);
			}			
			table_params.appendChild(body_params);						
			root_right_cell.appendChild(table_params);			
			
			if (callback.prod_param.price != 0) {
				var table_price = d.createElement('table');
				table_price.cellPadding = 0;
				table_price.cellSpacing = 0;
				table_price.border = 0;
				var body_price=d.createElement('tbody');
				var row_table_price=d.createElement('tr');
				
				var cell_table_price_1=d.createElement('td');
				cell_table_price_1.innerHTML='&nbsp;&nbsp;&nbsp;&nbsp;<span class="t14">'+callback.prod_param.price+' </span><span class="t15">'+callback.prod_param.price_ext+'</span>';
				
				var cell_table_price_2=d.createElement('td');
				cell_table_price_2.innerHTML='&nbsp;&nbsp;&nbsp;&nbsp;<a href="#"><img src="/images/img-basket.gif" alt="" onclick="addProductInBracket(\''+callback.prod_param.id+'\',1)"></a>';
				
				row_table_price.appendChild(cell_table_price_1);
				row_table_price.appendChild(cell_table_price_2);
				body_price.appendChild(row_table_price);
				table_price.appendChild(body_price);
				root_right_cell.appendChild(table_price);
			}
			

			root_row.appendChild(root_left_cell);
			root_row.appendChild(root_right_cell);
			root_body.appendChild(root_row);
			root_table.appendChild(root_body);
			div.onclick=closeProdHint;
			div.onmouseout=startDelayCloseProdHint;
			div.onmouseover=clearDelayCloseProdHint;
			div.style.top=getOffsetSum(d.getElementById(callback.prod_param.id)).top+'px';
			div.style.left=(getOffsetSum(d.getElementById(callback.prod_param.id)).left*1+150)+'px';
			div.appendChild(root_table);
			
			d.getElementsByTagName('body')[0].appendChild(div);
			

		}
	}
	
	function clearDelayCloseProdHint(){
		clearTimeout(globalCloseInterval);
	}
	
	function startDelayCloseProdHint(){
		globalCloseInterval=setTimeout('closeProdHint()',300);					
	}
	
	function closeProdHint(){
		if (d.getElementById('prodHintDiv'))
			d.getElementsByTagName('body')[0].removeChild(d.getElementById('prodHintDiv'))
	}
	
	function showSearchPage(){
		var str=d.getElementById('globalSearchString').value;
		req.open(null, '/jscript/common.php', true);
		req.send({
			param: str,
			query: 'setSearchWord',
			callback: 'setSearchWordOut'
		})
	}
	
	function setSearchWordOut(callback){
		if (callback==1)
			window.location='/catalog/search';
		else	
			alert('Ошибка передачи параметров поиска');
	}
	
