//<!--
var flag_spacer = 0;
function createXmlHttpRequestObject()
{
var xmlHttp = false;

try 
{ xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) 
 {
  try 
  {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
  catch(e2) {xmlHttp = false; }
 }
 
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

return xmlHttp;
}

var URL = 'js/firms_search.php'; // путь к обработчику пхп
var xmlHttpObj = createXmlHttpRequestObject();

function start_search_full()
{ 
 var search_full_hidden_Obj = document.getElementById('search_full_hidden');
 var Search_Full_Obj = document.getElementById('Search_Full');
 if(search_full_hidden_Obj && Search_Full_Obj)
 {
  search_full_hidden_Obj.value = Search_Full_Obj.value;
  start_search();
 }
 return;
}

function start_search()
{
  hid_Articles();
  if (xmlHttpObj.readyState == 4 || xmlHttpObj.readyState ==0 )
  {
	var Region_Obj = document.getElementById('Region');
	var Sity_Obj = document.getElementById('Sity');
	var Industry_Obj = document.getElementById('Industry');
	var Tovar_num_Obj = document.getElementById('tovars_num');
	var search_full_hidden_Obj = document.getElementById('search_full_hidden');
	
   	params = "mode=firm_form_search" +
	"&start_row=" + document.getElementById('start_row').value;
	if(Region_Obj)   {params = params + "&Region=" + encodeURIComponent(Region_Obj.value);}
	if(Sity_Obj)     {params = params + "&Sity=" + encodeURIComponent(Sity_Obj.value);}
	if(Industry_Obj) {params = params + "&Industry=" + encodeURIComponent(Industry_Obj.value);}
	if(Tovar_num_Obj) 
	 {
		 Tovar_str = new String();
		 for (i=0; i<Tovar_num_Obj.value; i++)
		 {
			 Tovar_next_Obj = document.getElementById('Tovar_' + i);
			 if(Tovar_next_Obj)
			 {
				 if(Tovar_next_Obj.checked==true)
					{Tovar_str = Tovar_str + '(**)~' + Tovar_next_Obj.value + '_';}
			 }
		 }
		params = params + "&Tovars=" + encodeURIComponent(Tovar_str);
	 }
	 if(Industry_Obj) 
	 {params = params + "&Search_Full=" + encodeURIComponent(search_full_hidden_Obj.value);}
	 
	xmlHttpObj.open("POST",URL, true);
	xmlHttpObj.setRequestHeader("Host", "localhost");
	xmlHttpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttpObj.onreadystatechange = output_firm_search;
	xmlHttpObj.send(params);
	$('#firms_div').animate({height: 'toggle'}, 800, 'swing');
	loader_activate();
  }
}

function page_roll(start_row)
{
	start_row_Obj = document.getElementById('start_row');
	if(start_row_Obj)
	{
		start_row_Obj.value = start_row;
		start_search();
	}
}

function output_firm_search()
{
	
rubrik_out_Obj = document.getElementById('industry_div');
if(rubrik_out_Obj)
{ 
  /*$('#industry_div').animate({height: 'hide', opacity:'hide'}, 400, 'swing');*/
  rubrik_out_Obj.style.display ='none';
}

if (xmlHttpObj.readyState == 4)
 {
  if (xmlHttpObj.status == 200)
  { 
	response = xmlHttpObj.responseText;
	firms_out_Obj = document.getElementById('firms_div');
	
	tovars_div_Obj = document.getElementById('tovars_div');
		
	 /*firms_out_Obj.innerHTML = response; */
	 if(tovars_div_Obj)
	  {
		 $('#tovars_div').animate({height: 'hide'}, 800, 'swing');
		 /*tovars_div_Obj.style.display ='none';*/ 
	  }

	 $('#firms_div').animate({height: 'toggle'}, 900, 'swing');
	 if (firms_out_Obj) 
	 { var timeout_out = setTimeout("handle_firm_output();", 800);}
	 loader_deactivate();
  }
 }
}

function handle_firm_output()
{
 response = xmlHttpObj.responseText;
 firms_out_Obj = document.getElementById('firms_div');	
 if (firms_out_Obj) 
 {firms_out_Obj.innerHTML = response;}
 
}
 
function tovar_list(id_industry)
{
  if (xmlHttpObj.readyState == 4 || xmlHttpObj.readyState ==0 )
  {
    industry_id_Obj = document.getElementById('id_industry');
    if(industry_id_Obj){industry_id_Obj.value = id_industry;}
	params = "mode=retriveTovarList&id_industry=" + id_industry;
	xmlHttpObj.open("POST",URL, true);
	xmlHttpObj.setRequestHeader("Host", "localhost");
	xmlHttpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttpObj.onreadystatechange = output_tovar_list;
	xmlHttpObj.send(params);
	loader_activate();
  }
}
function return_industry_list()
{
	industry_div_Obj = document.getElementById('industry_div');
	tovars_div_Obj = document.getElementById('tovars_div');
	if (industry_div_Obj) 
	{ industry_div_Obj.style.display = ''; }
	
	if(tovars_div_Obj)
	{tovars_div_Obj.style.display = 'none';	}
}

function output_tovar_list()
{
if (xmlHttpObj.readyState == 4)
 {
  if (xmlHttpObj.status == 200)
  { 
	response = xmlHttpObj.responseText;
	industry_div_Obj = document.getElementById('industry_div');
	tovars_div_Obj = document.getElementById('tovars_div');
	if(industry_div_Obj) 
	{ industry_div_Obj.style.display = 'none'; }
	if(tovars_div_Obj)
	{tovars_div_Obj.style.display = ''; 
	 tovars_div_Obj.innerHTML = response;}
  }
  loader_deactivate();
 }
}

function hid_Articles()
{
	art_column_Obj = document.getElementById('main_table').rows[0].cells[2];
	firm_spacer_Obj = document.getElementById('spacer_firm');
	articles_anonse_Obj = document.getElementById('articles_anonse_div');
	if(art_column_Obj)
	{
	 href_main_Obj = document.getElementById('href_main');
	 if(href_main_Obj)
	  {
	   href_main_Obj.style.cursor = 'pointer';
	   href_main_Obj.onclick = function(){window.location.href='index.php';}
	  }
	  
	 $('#right_block_div').animate({width: 'hide', height:'hide'}, 700, 'swing');
	 $('#firms_div').animate({width: '710'}, 700, 'swing');
	 art_column_Obj.innerHTML = '&nbsp';
	 //art_column_Obj.style.width = '0';
	 if(firm_spacer_Obj && flag_spacer == 0)
	  {
		 flag_spacer = 1;
		// firm_spacer_Obj.innerHTML = '<img src="images/Spacer.gif" width="710" height="1"/>';
	  }
//	 art_column_Obj.style.visibility = 'hidden';
	}
	
	if(articles_anonse_Obj)
	{ $('#articles_anonse_div').animate({height: 'hide'}, 550, 'swing'); }
}
//-->