var ajax=null;

// без изменений
function getAjax(){
if (window.ActiveXObject) // для IE
   return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest)
   return new XMLHttpRequest();
else {
   alert("Browser does not support AJAX.");
   return null;
  }
}

function FilterMouseOver(flag)
{

  f_name=document.getElementById('filter_name').innerHTML;

 if (f_name=='Развернуть фильтры')
 {
	document.getElementById('filter_name').className +='_hover';
	document.getElementById('filter_icon').className +='_hover';
	document.getElementById('down_show_b1').className ='down_show_hover';
	document.getElementById('down_show_b2').className ='down_show_hover';
 }
 else
 {

	document.getElementById('down_show_b1').className ='up_show_b_hover';
	document.getElementById('down_show_b2').className ='up_show_b_hover';
	document.getElementById('filter_name').className +='_hover';
	document.getElementById('filter_icon').className +='_hover';
 }


}

function FilterMouseOut()
{

 f_name=document.getElementById('filter_name').innerHTML;
 if (f_name=='Развернуть фильтры')
 {
	document.getElementById('filter_name').className ='filter_name';
	document.getElementById('filter_icon').className = 'filter_icon';
	document.getElementById('down_show_b1').className ='down_show';
	document.getElementById('down_show_b2').className ='down_show';
 }
 else
 {
	document.getElementById('down_show_b1').className ='up_show_b';
	document.getElementById('down_show_b2').className ='up_show_b';
	document.getElementById('filter_name').className ='filter_name';
	document.getElementById('filter_icon').className = 'filter_icon';
 }

}


function FilterCMPMouseOver(flag)
{

  f_name=document.getElementById('filter_comp_name').innerHTML;
//alert(f_name);

 if (f_name=='Развернуть сравнения')
 {
	document.getElementById('filter_comp_name').className  +='_hover';
	document.getElementById('filter_comp_icon').className +='_hover';
	document.getElementById('down_show_b3').className ='down_show_hover';
	document.getElementById('down_show_b4').className ='down_show_hover';
 }
 else
 {

	document.getElementById('down_show_b3').className ='up_show_b_hover';
	document.getElementById('down_show_b4').className ='up_show_b_hover';
	document.getElementById('filter_comp_name').className +='_hover';
	document.getElementById('filter_comp_icon').className ='filter_icon_cmp_hover';
 }


}

function FilterCMPMouseOut()
{

 f_name=document.getElementById('filter_comp_name').innerHTML;
	//alert(f_name);
 if (f_name=='Развернуть сравнения')
 {
	//alert(document.getElementById('down_show_b3').className);
	document.getElementById('filter_comp_name').className ='filter_name';
	document.getElementById('filter_comp_icon').className = 'filter_icon_cmp';
	document.getElementById('down_show_b3').className ='down_show';
	document.getElementById('down_show_b4').className ='down_show';
	return;
 }
 else
 {
	//alert('here='+f_name);
	document.getElementById('down_show_b3').className ='up_show_b';
	document.getElementById('down_show_b4').className ='up_show_b';
	document.getElementById('filter_comp_name').className ='filter_name';
	document.getElementById('filter_comp_icon').className ='filter_icon_cmp';
	return;
 }

}


function Option_Expand(url)
{
	//alert('url='+url);
     request.open("GET",url,true);
     request.onreadystatechange =  Option_ExpandResult;
     request.send(null);

}

function Option_ExpandResult()
  {

    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       //var updatedText = request.responseText;
	//alert(updatedText);


      }
    }
  }


function CPM_PRINT()
{
	printIt(document.getElementById('CompareWindowData').innerHTML);
}
function CPM_DEL_ALL()
{
	var url=document.getElementById('CMP_DELL_ALL').value;
	InstreamCompareDelAll(url);
}

function CPM_DEL_CLICK(obj)
{
	var add_id=obj.id;
	var prod_id=add_id+'_PROD';
	var url=add_id+'_URL';

	prod_id=document.getElementById(prod_id).value;
	url=document.getElementById(url).value;

	InstreamCompareDel(prod_id,url);

}

function CPM_CART_CLICK(obj)
{

	//alert('here');
	var add_id=obj.id;
	var prod_id=add_id+'_PROD';
	var url=add_id+'_URL';
	var item_name=add_id+'_NAME';



	prod_id=document.getElementById(prod_id).value;
	url=document.getElementById(url).value;
	item_name=document.getElementById(item_name).value;
//	alert('id='+add_id+'        prod='+prod_id+'          url='+url+'      name='+item_name);

	InstreamCartAdd(prod_id,url,item_name);

}



function FilterSlideChange(change_type,SID)
{

	//alert(change_type+'  SID='+SID);
	url="index.php?change_slidertype="+change_type+"&isID="+SID;
	//alert(url);
	request.open("GET",url,true);
     request.onreadystatechange =  Change_SlidertypeResult;
     request.send(null);
}

function  Change_SlidertypeResult()
{
 if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	//alert(updatedText);

      }
    }

}


function CompareTypeChanged(obj)
{
	$("#compare_loader").fadeIn(1000);
	$("#CompareWindowData").fadeOut(1000);


	var url=document.getElementById('CMP_change_url').value;
	//var SID=document.getElementById('CMP_change_SID').value;
	url=url+'compare_type='+obj.value+'&CMPWin=1';


	//alert('url='+url);
	  window.location =url;
	 exit();
	 /*
	 request.open("GET",url,true);
     request.onreadystatechange =  CompareTypeChangedResult;
     request.send(null);
     */
}

function CompareTypeChangedResult()
  {

    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
	document.getElementById('CompareWindowData').style.display='none';
     	document.getElementById('compare_loader').style.display='';
						$("#CompareWindowData").fadeIn(1000);
						$("#compare_loader").fadeOut(1000);
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	//alert(updatedText);



/* 5. Обновление блока товара */
	ind_start=updatedText.indexOf('<!-- PRODUCTS DISPLAY BLOCK  //-->');
	ind_end=updatedText.indexOf('<!-- EOF PRODUCTS DISPLAY BLOCK  //-->');
        ind_end=ind_end-ind_start;

	UPDData=updatedText.substr(ind_start,ind_end);
	//alert('here='+UPDData);
	document.getElementById('products').innerHTML=UPDData;

	//document.getElementById('CompareWindowData').innerHTML=document.getElementById('CompareWinBoxDiv').innerHTML;
		ind_start=updatedText.indexOf('<!-- ComparetDivData -->');
		ind_end=updatedText.indexOf('<!-- EOFCompareDivData -->');
		//alert('start='+ind_start+' end='+ind_end);
	        ind_end=ind_end-ind_start;

		CPWinData=updatedText.substr(ind_start,ind_end);
		//alert(CPData);

		document.getElementById('CompareWindowData').innerHTML =CPWinData;



      }
    }
  }





function PCCartAdd(obj_id,SID)
{
	//alert('id='+obj_id+' | sid='+SID);
	obj=document.getElementById(obj_id);
	obj_val=obj.value;
	//alert(obj_val);
	all_arr=obj_val.split(",");

			var res='';
			for(var i=0; i<all_arr.length; i++)
                               {


                                	el='sel'+all_arr[i];

                                	el_val=document.getElementById(el).value;


					if(el_val>0)
					{
						 if (request == null)
						     alert("Error creating request object!");

						if(res=='') res=el_val;
						else res=res+','+el_val;

					}

                               }
							 //var url='index.php?cart_add_item='+el_val+'&isID='+SID;
					//alert('res='+res);
					if(res!='')
					{
							var url='index.php?cart_add_item='+res;

    							//alert('url='+url);


     							request.open("GET",url,true);
							request.onreadystatechange =  function() {UpdatePCFields('show');}
							     request.send(null);
							/**/
					}




}




function UpdatePCFields(flag)
  {
	//alert(flag);

    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	//alert(updatedText);


/* 1. Получаем id продукта  */

	//alert('upd_txt'+updatedText);
	//alert(updatedText.indexOf('sel[1]_126'));
		var ind_start=updatedText.indexOf('updfield_id=');
		var ind_end=updatedText.indexOf('[*-&cq-*]');
		ind_start=ind_start+12;
		ind_end=ind_end-ind_start;
		UpdatFieldID=updatedText.substr(ind_start,ind_end);

/* 2. Общее кол-во и сумма в корзине */

		ind_start=updatedText.indexOf('total=');
			ind_start=ind_start+6;

		ind_end=updatedText.indexOf('[*-&tc-*]');
			ind_end=ind_end-ind_start;
		UpdatTotal=updatedText.substr(ind_start,ind_end);
		var Check_UpdatFieldID='cart_count_box';
		  UpdateElement(Check_UpdatFieldID,UpdatTotal,1);

			ind_start=updatedText.indexOf('total_sum=');
			ind_start=ind_start+10;

			ind_end=updatedText.indexOf('[*-&ts-*]');
			ind_end=ind_end-ind_start;
			UpdatTotal=updatedText.substr(ind_start,ind_end);
			var Check_UpdatFieldID='cart_summ_box';
			float_val=parseInt(UpdatTotal);
			//float_val=float_val.toFixed(2);

			  UpdateElement(Check_UpdatFieldID,float_val,1);

/*  3. Обновляем данные в окне корзины */


		ind_start=updatedText.indexOf('cart_win=');
			ind_start=ind_start+9;

		ind_end=updatedText.indexOf('[*-&cw-*]');
			ind_end=ind_end-ind_start;
		UpdatWinData=updatedText.substr(ind_start,ind_end);
			UpdateElement('Cart_Window',UpdatWinData,1);



/*  4. Текущее кол-во выбранного продукта в корзине + обновление кол-ва на кнопках */

		ind_start=updatedText.indexOf('cur_count=');
			ind_start=ind_start+10;

		ind_end=updatedText.indexOf('[*-&cc-*]');
			ind_end=ind_end-ind_start;
		UpdatFieldCount=updatedText.substr(ind_start,ind_end);
		//alert('reset id='+UpdatFieldID+'  count='+UpdatFieldCount);
		ResestCartFields(UpdatFieldID,UpdatFieldCount);

if(flag=='show')
{
obj=document.getElementById('windowOpen'); fireEvent(obj,'click');
}


jQuery('.pc_select').each(function() {
	$(this)[0].selectedIndex = 0;
});

jQuery('.pc_element_div').each(function() {
	$(this).html('');
});

document.getElementById('pc_total_price').innerHTML='Итого стоимость компьютера:';


      }
    }
  }




function UpdateScrollDataStop(minVal,maxVal,SID,cPath,brand,brand_cat)
{

     $("#load_div").fadeIn(1000);

     if (request == null)
     alert("Error creating request object!");

   if(brand!='')
     var url='brand_prod.php?filterminValue='+minVal+'&filtermaxValue='+maxVal+'&brand='+brand+'&cPath='+brand_cat;
   else
     var url='index.php?filterminValue='+minVal+'&filtermaxValue='+maxVal+'&cPath='+cPath;

    //alert(url);

     request.open("GET",url,true);
     request.onreadystatechange = DisplayScrollResult;
     request.send(null);


}

function DisplayScrollResult()
{

   if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	//alert('result='+updatedText);



	var ind_start=updatedText.indexOf('<!-- PRODUCTS DISPLAY BLOCK  //-->');
	    ind_start=ind_start+34;

	ind_end=updatedText.indexOf('<!-- EOF PRODUCTS DISPLAY BLOCK  //-->');
	ind_end=ind_end-ind_start;
	updatedProdTxt=updatedText.substr(ind_start,ind_end);

	       //alert(updatedProdTxt);
      	document.getElementById("products").innerHTML = updatedProdTxt;

	var filtered_empty=false;

	if(updatedProdTxt.indexOf('<h3>По заданным критериям ничего не найдено</h3>')>-1)
	{
		filtered_empty=true;
		//alert('empty');
		//$('.brandLo').attr('class','brandSt');
		//$('.brandHi').attr('class','brandSt');
		//alert('done');

	}

    //if(!filtered_empty)
    //{
	ind_start=updatedText.indexOf('<!-- instream_filterbrand_block_start //-->');
	    ind_start=ind_start+43;

	ind_end=updatedText.indexOf('<!-- instream_filterbrand_block_end //-->');
	ind_end=ind_end-ind_start;
	updatedBrandTxt=updatedText.substr(ind_start,ind_end);

	     //alert(updatedBrandTxt);
      	document.getElementById("brandfilter").innerHTML = updatedBrandTxt;

	////////// для кнопок "дальше" и "скрыть" в фильтрах ////////////////////

	spanList=document.getElementsByTagName('span');
	for (t=0; t<spanList.length; t++) with (spanList[t]) if (id.indexOf('_sControl')!=-1)
	{
		innerHTML='<a href="#" onclick="toggleShrink(this,\''+id.replace(/_sControl/,'')+'\'); return false" class="sControl"><b></b>'+innerHTML+'</a>';
	}


	//////////////////////////////////////////////////////////////////////////

     //}
	// обновляем кол-во результатов пункта ВСЕГО
	    ind_start=updatedText.indexOf('<div id="total_count_bcrumb">');
	    ind_start=ind_start+29;

	tot_count=updatedText.substr(ind_start,100);
	//alert(tot_count);
	ind_end=tot_count.indexOf('</div>');

	tot_count=tot_count.substr(0,ind_end);
	//alert(tot_count);
	document.getElementById("total_count_bcrumb").innerHTML = tot_count;

        $("#load_div").fadeOut(1000);


      }
   }
   else
   {
	//obj=document.getElementById("products_load");
	//obj.style.display = '';
   }

}



function UpdateFilterData(url)
{


	//alert(url);

	//var url='index.php?'+url;
	//alert(url);

	$("#load_div").fadeIn(1000);


	if (request == null)
     	alert("Error creating request object!");



     request.open("GET",url,true);
     request.onreadystatechange = DisplayFilterResult;
     request.send(null);

}


function UpdateFilterBrandData(brand_id,url)
{

  //alert('url='+url);

if (request == null)
     alert("Error creating request object!");

     var url_new='index.php?'+brand_id+'&'+url;

    //alert('url_new='+url_new);

     request.open("GET",url_new,true);
     request.onreadystatechange = DisplayFilterBrandResult;
     request.send(null);


}

function UpdateFilterTechData(opt_id,url)
{

  //alert('url='+url);

if (request == null)
     alert("Error creating request object!");

     var url_new='index.php?'+opt_id+'&'+url;

     //alert('url_new='+url_new);

     request.open("GET",url_new,true);
     request.onreadystatechange = DisplayFilterBrandResult;
     request.send(null);


}


function DisplayFilterBrandResult()
{
 //alert('here');

   if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
      	alert('text='+updatedText);

	var ind_start=updatedText.indexOf('<!-- PRODUCTS DISPLAY BLOCK  //-->');
	    ind_start=ind_start+34;

	ind_end=updatedText.indexOf(' <!-- EOF PRODUCTS DISPLAY BLOCK  //-->');
	ind_end=ind_end-ind_start;
	updatedProdTxt=updatedText.substr(ind_start,ind_end);

	       //alert(updatedProdTxt);
      	document.getElementById("products").innerHTML = updatedProdTxt;

	ind_start=updatedText.indexOf('<!-- instream_filterbrand_block_start //-->');
	    ind_start=ind_start+43;

	ind_end=updatedText.indexOf('<!-- instream_filterbrand_block_end //-->');
	ind_end=ind_end-ind_start;
	updatedBrandTxt=updatedText.substr(ind_start,ind_end);

	     //alert(updatedBrandTxt);
      	document.getElementById("brandfilter").innerHTML = updatedBrandTxt;




      }
   }
   else
   {
	//obj=document.getElementById("products_load");
	//obj.style.display = '';
   }

}



function DisplayFilterResult()
{

   if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
       var allTxt = request.responseText;
	//alert(updatedText);

       var ind_start=updatedText.indexOf('red_url=');
       if(ind_start>0)
       {
	 ind_start=ind_start+8;
	 var red_url=updatedText.substr(ind_start,500);
	 //alert('url='+red_url);
	 window.location =red_url;
	 exit();

       }
         //alert('text='+updatedText);


	ind_start=updatedText.indexOf('<!-- PRODUCTS DISPLAY BLOCK  //-->');
	    ind_start=ind_start;

	ind_end=updatedText.indexOf(' <!-- EOF PRODUCTS DISPLAY BLOCK  //-->');
	//alert('ind_start='+ind_start+' len='+ind_end);
	ind_end=ind_end-ind_start;
	updatedProdTxt=updatedText.substr(ind_start,ind_end);

	       //alert('text='+updatedProdTxt);
      	document.getElementById("products").innerHTML = updatedProdTxt;


	ind_start=updatedText.indexOf('<!-- instream_filterbrand_block_start //-->');
	    ind_start=ind_start+43;

	ind_end=updatedText.indexOf('<!-- instream_filterbrand_block_end //-->');
	ind_end=ind_end-ind_start;
	updatedBrandTxt=updatedText.substr(ind_start,ind_end);

	price_filtered=false;
	pos=updatedText.indexOf('ispriceflds[');
	if(pos>1)// если фильтровалось по цене
	{		price_filtered=true;
		pos1=updatedText.indexOf(']ispriceflde');
		pos2=pos1-(pos+12);
        price_string=updatedText.substr((pos+12),pos2);
        minmax_arr=price_string.split('|');

	}

       pos1=updatedText.indexOf('instreamfiltermin=')+18;
       pos2=updatedText.indexOf('instreamfiltermax=');
       pos3=updatedText.indexOf('instreamfilterend');
       posdif=pos2-pos1;

       minfilterval=parseInt(updatedText.substr(pos1,posdif));

       posdif=pos3-(pos2+18);
       maxfilterval=parseInt(updatedText.substr((pos2+18),posdif));

      	document.getElementById("brandfilter").innerHTML = updatedBrandTxt;
       $slider.slider( "option", "max", maxfilterval);
       $slider.slider('values',1, maxfilterval);

// update цены слайдера
    if(price_filtered)
    {       // alert(parseInt(minmax_arr[0]));


        $slider.slider( "option", "min", parseInt(minmax_arr[0]));
        amount_html_1=$amount1.html();
     	amount_arr= amount_html_1.split(' ');

        $amount1.text(minfilterval+' '+amount_arr[1]);
     	$slider.slider('values',0, minfilterval);    }
    else
    {
    	$slider.slider( "option", "min", minfilterval);
    	amount_html_1=$amount1.html();
     	amount_arr= amount_html_1.split(' ');
     		 $amount1.text(minfilterval+' '+amount_arr[1]);
     		 $slider.slider('values',0, minfilterval);

    }
     	amount_html_2=$amount2.html();
     	amount_arr= amount_html_2.split(' ');
     	$amount2.text(maxfilterval+' '+amount_arr[1]);
       // alert('1='+amount_html_1+' | 2='+amount_html_2);


// добавляем ссылки "детальнее"


spanList=document.getElementsByTagName('span');
for (t=0; t<spanList.length; t++) with (spanList[t]) if (id.indexOf('_sControl')!=-1)
{

	innerHTML='<a href="#" onclick="toggleShrink(this,\''+id.replace(/_sControl/,'')+'\'); return false" class="sControl"><b></b>'+innerHTML+'</a>';
}

	// обновляем кол-во результатов пункта ВСЕГО
	tot_count=updatedText.indexOf('id="total_count_bcrumb"');
	//alert('count='+tot_count);
		tot_count_txt=updatedText.substr(tot_count);
	tot_count2=tot_count_txt.indexOf('</div>');
	//alert(tot_count_txt);
	tot_count=tot_count2-24;

		tot_count_txt=tot_count_txt.substr(24,tot_count);
	//alert(tot_count_txt);
	//alert(document.getElementById("total_count_bcrumb").innerHTML);
	document.getElementById("total_count_bcrumb").innerHTML = tot_count_txt;
	//alert(document.getElementById("total_count_bcrumb").innerHTML);

	//alert(document.getElementById("hidden_scroll_fdata").innerHTML);
	//document.getElementById("slider_content").innerHTML=document.getElementById("hidden_scroll_fdata").innerHTML;

	//////// Проверка слайдера цены /////////////////////////////////////
		ind_start=allTxt.indexOf("document.getElementById('leftSlider').style.display='none';");
		if (ind_start>0)
			document.getElementById('leftSlider').style.display='none';
		else
			document.getElementById('leftSlider').style.display='';
	/////////////////////////////////////////////////////////////////////
	document.getElementById("brandfilter").innerHTML=document.getElementById("hidden_brand_fdata").innerHTML;

	$("#load_div").fadeOut(1000);



      }
   }


}







function PassReminderShow() // Password Reminder
{
   if (request == null)
     alert("Error creating request object!");
     var input_data=document.getElementById("pr_email_address").value;
     var url='pass_reminder.php?mail='+input_data;
     //alert('url='+url);

     request.open("GET",url,true);
     request.onreadystatechange = UpdatePass;
     request.send(null);

}

function UpdatePass()
{
   if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
       //alert(updatedText);
       document.getElementById("PassReminderData").innerHTML = updatedText;


      }
   }

}



function PassReminderBasic() // Password Reminder Basic Window
{
   if (request == null)
     alert("Error creating request object!");
     var url='pass_reminder_base.php';
     request.open("GET",url,true);
     request.onreadystatechange = BasicPass;
     request.send(null);
}

function BasicPass()
{
   if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
       //alert(updatedText);
       document.getElementById("PassReminderData").innerHTML = updatedText;


      }
   }

}








function InstreamCartDel(del_id,url) // удаление продукта из корзины
 {
   if (request == null)
     alert("Error creating request object!");
    	//alert('url1='+url);
     request.open("GET",url,true);
     request.onreadystatechange = UpdateCartWindow;
     request.send(null);
 }



function ShoppingCartClear(url,SID) // чистка всей корзины
{

	//alert('url2='+url);

/**/
    if (request == null)
     alert("Error creating request object!");

     request.open("GET",url,true);
     request.onreadystatechange = UpdateCartWindowClear;
     request.send(null);


}

function CartCurencyChange(url,cur_val)
{

     var ind_start=url.indexOf('[cur_here]');
     var url_part1=url.substr(0,ind_start);

	var url_part2=url.substr( (ind_start+10), url.length);
	url=url_part1+cur_val+url_part2;
        //alert(url);

     if (request == null)
     alert("Error creating request object!");
     request.open("GET",url,true);
     request.onreadystatechange = UpdateCartCurrency;
     request.send(null);

}


function CartWinCurencyChange(url,cur_val)
{

     var ind_start=url.indexOf('[cur_here]');
     var url_part1=url.substr(0,ind_start);

	var url_part2=url.substr( (ind_start+10), url.length);
	url=url_part1+cur_val+'&CartWin=true'+url_part2;
        //alert(url);
	window.location = url;


}

function UpdateCartCurrency()
{
   if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
       //alert(updatedText);
	ind_start=updatedText.indexOf('<!-- CartWinCur -->');
         ind_start=ind_start+19;
	ind_end=updatedText.indexOf('<!-- EOFCartWinCur -->');
	ind_end=ind_end-ind_start;
	updatedCurTxt=updatedText.substr(ind_start,ind_end);
	//alert('st='+ind_start+' end='+ind_end+'  text='+updatedCurTxt);

/* Обновление данных корзины */

       document.getElementById("cart_cur_sel").innerHTML = updatedCurTxt;
	box_data_end=updatedText.indexOf('<!-- EOFCartWinDivInner -->');
	box_data_end=box_data_end;
	box_data_start=updatedText.indexOf('<!-- CartWinDivInner -->');
	box_data_start=box_data_start;
	//alert('st='+box_data_start+' end='+box_data_end);
	box_data_end=box_data_end-box_data_start;
	BoxCurText=updatedText.substr(box_data_start,box_data_end);
	//alert(BoxCurText);
	document.getElementById("win_cart_data").innerHTML = BoxCurText;

/* Обновление всей страницы
	ind_start=updatedText.indexOf('<!-- Instream Shop Body -->');
	ind_end=updatedText.indexOf('<!-- EOF Instream Shop Body -->');
	ind_end=ind_end-ind_start;
	BodyTxt=updatedText.substr(ind_start,ind_end);
	document.getElementById("shop_body").innerHTML = BodyTxt;


*/

      }
   }

}

function UpdateCartWindowClear()
{
  if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	//alert('UpdateCartWindowClear='+updatedText);
	if (updatedText.length>0)
	{
		while(updatedText.indexOf(',')>0) // очистка значений на кнопках
		{
			UpdatFieldID=updatedText.substr(0,updatedText.indexOf(','));
			updatedText=updatedText.substr( (updatedText.indexOf(','))+1);
			ResestCartFields(UpdatFieldID,'0');
		}

	}


	// обнуление всех полей кол-ва на кнопках
    $('.Cart_InputFiled').each(function() {
  	this.value=0;
	})

     $('.Cart_InputFiledH').each(function() {
  	this.value=0;
	})



       document.getElementById("Cart_Window").innerHTML = '<center>Корзина пуста</center>';
       document.getElementById("cart_count_box").innerHTML = '';
	document.getElementById("cart_summ_box").innerHTML = '';
	document.getElementById("windowOpen").title='Корзина пуста';
	FloatWinClose('Window3');


      }
    }

}





function InstreamSpinClick(prod_id,url,upd_field_id,action_type) // добавление в корзину
 {


	//alert('here');
	var loader_id=upd_field_id;
	loader_id=loader_id.replace('cart_quantity_','loader_spin');
		$("#"+loader_id).fadeIn(1000);



  var ajax_flag=document.getElementById("ajax_work").value;
  if(ajax_flag>0)
  {
	window.setTimeout("InstreamCartAdd('"+prod_id+"','"+url+"','"+upd_field_id+"')", 400);
  }
  else
  {


	//alert('udp='+upd_field_id+'  loader='+loader_id);

	document.getElementById("ajax_work").value=1;
	item_count=parseInt(document.getElementById(upd_field_id).value);
	//alert('type='+action_type+' | count='+item_count);
	if( (action_type=='minus') && (item_count>=0) )
	{
		item_count=item_count-1;
	}
	else
	{
		item_count=item_count+1;
	}
	//alert('count='+item_count);

		var ind_start=url.indexOf('&count_item_id=');
		ind_start=ind_start+15;
		ind_end=url.indexOf('isID=');

		url1=url.substr(0,ind_start);
		url2=url.substr(ind_end,50);
		url_new=url1+item_count+'&'+url2;

	//alert('new_url='+url_new);

   if (request == null)
     alert("Error creating request object!");
     request.open("GET",url_new,true);
     request.onreadystatechange = function() { UpdateCartFields(loader_id); }
     request.send(null);
  }

 }




function InstreamCartAdd(prod_id,url,upd_field_id) // добавление в корзину
 {


	//alert('here');
	var loader_id=upd_field_id;
	loader_id=loader_id.replace('cart_quantity_','loader_');
		$("#"+loader_id).fadeIn(1000);



  var ajax_flag=document.getElementById("ajax_work").value;
  if(ajax_flag>0)
  {
	window.setTimeout("InstreamCartAdd('"+prod_id+"','"+url+"','"+upd_field_id+"')", 400);
  }
  else
  {


	//alert('udp='+upd_field_id+'  loader='+loader_id);

	document.getElementById("ajax_work").value=1;
	item_count=document.getElementById(upd_field_id).value;
		var ind_start=url.indexOf('&count_item_id=');
		ind_start=ind_start+15;
		ind_end=url.indexOf('isID=');

		url1=url.substr(0,ind_start);
		url2=url.substr(ind_end,50);
		url_new=url1+item_count;//+'&'+url2;

	//alert('new_url='+url_new);

   if (request == null)
     alert("Error creating request object!");
     request.open("GET",url_new,true);
     request.onreadystatechange = function() { UpdateCartFields(loader_id); }
     request.send(null);
  }

 }

function InstreamWishListAdd(prod_id,url,wl_id)
{

	var loader_id=wl_id;
	loader_id=loader_id.replace('wl_','wl_loader');
	$("#"+loader_id).fadeIn(1000);



  var ajax_flag=document.getElementById("ajax_work").value;
  if(ajax_flag>0)
  {
	window.setTimeout("InstreamWishListAdd('"+prod_id+"','"+url+"','"+wl_id+"')", 400);
  }
  else
  {

	document.getElementById("ajax_work").value=1;
	if (request == null)
     	alert("Error creating request object!");
     	request.open("GET",url,true);
     	request.onreadystatechange = function() {UpdateWLData(loader_id);}
     	request.send(null);
  }

}


function InstreamWishListDel(prod_id,url)
{
	//alert('url='+url);
	if (request == null)
     	alert("Error creating request object!");
     	//alert('url1='+url);
     	request.open("GET",url,true);
     	request.onreadystatechange = DelWLData;
     	request.send(null);

}









function InStreamLogin_Last(SID)
{

	var url='log_try.php?action=login&'+SID;
	//var url='log_try.php';
	var parameters='password='+encodeURI(document.getElementById("password").value)+'&email_address='+encodeURI(document.getElementById("email_address").value)+'&capture_input='+encodeURI(document.getElementById("capture_input").value);
	//alert('url='+url+'  params='+parameters);

 	http_request = false;

      	if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType)
		{
                	// set type accordingly to anticipated content type
               		http_request.overrideMimeType('text/html');
            	}
        }
	else if (window.ActiveXObject)
	{ // IE
         try
		{
            		http_request = new ActiveXObject("Msxml2.XMLHTTP");
         	}
		catch (e)
		{
            		try
			{
               			http_request = new ActiveXObject("Microsoft.XMLHTTP");
            		}
			catch (e) {}
         	}
        }

      if (!http_request)
	{
         alert('Cannot create XMLHTTP instance');
         return false;
      }

      http_request.onreadystatechange = GetLoginData;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);

}





function InStreamSendOrder(SID,clear_url)
{

	var url='instreamsend_order.php?';

if (document.getElementById("utype_status")!=null)
{

		var additional_param='&u_type='+encodeURI(document.getElementById("utype_status").value);
}
else
{
	var additional_param='';
}




	if (document.getElementById("form_order_capture_input")!=null)
		var parameters='order_last_name='+encodeURI(document.getElementById("order_last_name").value)+'&order_user_name='+encodeURI(document.getElementById("order_user_name").value)+'&order_given_name='+encodeURI(document.getElementById("order_given_name").value)+'&order_phone1='+encodeURIComponent(document.getElementById("order_phone1").value)+'&order_phone2='+encodeURIComponent(document.getElementById("order_phone2").value)+'&base_mail='+encodeURI(document.getElementById("base_mail").value)+'&other_mail='+encodeURI(document.getElementById("other_mail").value)+'&deliver_type='+encodeURI(document.getElementById("deliver_type").value)+'&user_region='+encodeURI(document.getElementById("user_region").value)+'&user_street='+encodeURI(document.getElementById("user_street").value)+'&user_house='+encodeURI(document.getElementById("user_house").value)+'&user_office='+encodeURI(document.getElementById("user_office").value)+'&user_floor='+encodeURI(document.getElementById("user_floor").value)+'&customer_note='+encodeURI(document.getElementById("customer_note").value)+'&capture_input='+encodeURI(document.getElementById("form_order_capture_input").value)+additional_param;
	else
		var parameters='order_last_name='+encodeURI(document.getElementById("order_last_name").value)+'&order_user_name='+encodeURI(document.getElementById("order_user_name").value)+'&order_given_name='+encodeURI(document.getElementById("order_given_name").value)+'&order_phone1='+encodeURIComponent(document.getElementById("order_phone1").value)+'&order_phone2='+encodeURIComponent(document.getElementById("order_phone2").value)+'&base_mail='+encodeURI(document.getElementById("base_mail").value)+'&other_mail='+encodeURI(document.getElementById("other_mail").value)+'&deliver_type='+encodeURI(document.getElementById("deliver_type").value)+'&user_region='+encodeURI(document.getElementById("user_region").value)+'&user_street='+encodeURI(document.getElementById("user_street").value)+'&user_house='+encodeURI(document.getElementById("user_house").value)+'&user_office='+encodeURI(document.getElementById("user_office").value)+'&user_floor='+encodeURI(document.getElementById("user_floor").value)+'&customer_note='+encodeURI(document.getElementById("customer_note").value)+additional_param;
	//alert('url='+url+'  params='+parameters);
	//alert('add='+additional_param);


 	http_request = false;

      	if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType)
		{
                	// set type accordingly to anticipated content type
               		http_request.overrideMimeType('text/html');
            	}
        }
	else if (window.ActiveXObject)
	{ // IE
         try
		{
            		http_request = new ActiveXObject("Msxml2.XMLHTTP");
         	}
		catch (e)
		{
            		try
			{
               			http_request = new ActiveXObject("Microsoft.XMLHTTP");
            		}
			catch (e) {}
         	}
        }

      if (!http_request)
	{
         alert('Cannot create XMLHTTP instance');
         return false;
      }

      http_request.onreadystatechange = function(){InStreamSendOrderRes(clear_url,SID);}
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
/**/
}




function InStreamSendOrderRes(clear_url,SID)
{


    if (http_request.readyState == 4)
        {
         if (http_request.status == 200)
         {
            //alert(http_request.responseText);
		var ord_num=http_request.responseText;
		//alert('ind_of='+ord_num.indexOf('captcha_err'));

		if(ord_num.indexOf('captcha_err')>-1)
		{
			inp_obj=document.getElementById('form_order_capture_input');
			inp_obj.value='';
			InputChanged(inp_obj,'','order_last_name=3,order_user_name=2,order_phone1=10,deliver_type=1','order_submit_btn');
			CaptchaImgRefresh('fo_capcha_img','formorder','form_order_capture_input');

			alert('Ошибка!!! Неправильный код подтверждения. \r\n Заказ не был отправлен. \r\n Повторите попытку, указав правильный код подтверждения');
		}
		else if (ord_num.indexOf('err_empty_cart')>-1)
		{
			alert('Заказ не принят. В вашей корзине отсутствует товар для совершения покупки. ');
			document.getElementById('Window7').style.display='none';
			ShoppingCartClear(clear_url,SID);
		}
		else
		{
			alert('Ваш заказ успешно отправлен на рассмотрение.\r\nВ ближайшее время с Вами свяжется менеджер.\r\n'+ord_num);
			document.getElementById('Window7').style.display='none';
			ShoppingCartClear(clear_url,SID);
		}


         }
         else
         {
            alert('There was a problem with the request.');
	    //GetLoginData();
         }

	}
}


function InStreamSendOrderTerminal(SID,clear_url)
{

	//var url='instreamsend_order.php?'+SID;
	var url='instreamsend_order.php';
	//alert(url);
	//var url='log_try.php';


 	if (request == null)
     	alert("Error creating request object!");

	request.open("GET",url,true);
    	request.onreadystatechange = function(){InStreamSendOrderTerminalRes(clear_url,SID);}
     	request.send(null);
	//alert('done');

}




function InStreamSendOrderTerminalRes(clear_url,SID)
{
   if (request.readyState != 4)
   {

	document.getElementById('ajaxloderimg').style.display='';
   }

    if (request.readyState == 4)
        {
         if (request.status == 200)
         {
            //alert(request.responseText);
		var ord_num=request.responseText;
		//alert('ind_of='+ord_num.indexOf('captcha_err'));

		if(ord_num.indexOf('captcha_err')>-1)
		{
			inp_obj=document.getElementById('form_order_capture_input');
			inp_obj.value='';
			InputChanged(inp_obj,'','order_last_name=3,order_user_name=2,order_phone1=10,deliver_type=1','order_submit_btn');
			CaptchaImgRefresh('fo_capcha_img','formorder','form_order_capture_input');

			alert('Ошибка!!! Неправильный код подтверждения. \r\n Заказ не был отправлен. \r\n Повторите попытку, указав правильный код подтверждения');
		}
		else if (ord_num.indexOf('err_empty_cart')>-1)
		{
			alert('Заказ не принят. В вашей корзине отсутствует товар для совершения покупки. ');
			document.getElementById('Window7').style.display='none';
			ShoppingCartClear(clear_url,SID);
		}
		else
		{
			alert('Ваш заказ успешно отправлен на рассмотрение. Обратитесь к менеджеру для дальнейшего оформления заказа.\r\n '+ord_num+'\r\n Назовите номер заказа менеджеру.');
			document.getElementById('Window7').style.display='none';
			ShoppingCartClear(clear_url,SID);
		}


         }
         else
         {
            alert('There was a problem with the request.');
	    //GetLoginData();
         }

	}
}





function GetFromActionPage(url,sale_id) // для вкладки "Акции" на странице товара
{
     //alert('url='+url);
     if (request == null)
     alert("Error creating request object!");
     request.open("GET",url,true);
     request.onreadystatechange = UpdateSaleTab;
     request.send(null);
}


function UpdateElement(obj,obj_value,type)
{

  //alert('obj='+obj+' |  type='+type+' | val='+obj_value);

   if(type==1)
   {

	if (document.getElementById(obj)!=null)
			document.getElementById(obj).innerHTML=obj_value;
   }
   else if(type==0)
   {

	//alert('obj='+obj+' | val='+obj_value);
	if (document.getElementById(obj)!=null)
	{
		//alert('obj='+obj+'element is set val='+document.getElementById(obj).value+' | new_val='+obj_value);
		document.getElementById(obj).value = obj_value;
		if(obj.indexOf('cart_quantity_act_')==0)
			document.getElementById(obj+'_hid').value = obj_value;
		if(obj.indexOf('cart_quantity_hits_')==0)
			document.getElementById(obj+'_hid').value = obj_value;
		if(obj.indexOf('cart_quantity_new_p')==0)
			document.getElementById(obj+'_hid').value = obj_value;

		//alert('now val='+document.getElementById(obj).value);
	}
   }

}


function UpdateWLElement(obj,obj_status,in_list)
{

	if (document.getElementById(obj)!=null)
	{
		if (obj_status==1)
		{
			//alert('1 in_list='+in_list+'class='+document.getElementById(obj).className);

			if (in_list==0)
			{

				if(document.getElementById(obj).className=='prod_btn_big prod_btn_favourite_big')
					document.getElementById(obj).className = 'prod_btn_big prod_btn_infavourite_big';

				else if(document.getElementById(obj).className=='prod_btn_small prod_btn_favourite_small')
					document.getElementById(obj).className = 'prod_btn_small prod_btn_infavourite_small';

				else if(document.getElementById(obj).className=='prod_btn_mid prod_btn_favourite_mid')
					document.getElementById(obj).className = 'prod_btn_mid prod_btn_infavourite_mid';

				else
					document.getElementById(obj).className = 'prod_btn prod_btn_infavourite';
			}
			else
			{

				if(document.getElementById(obj).className=='prod_btn_big prod_btn_infavourite_big')
					document.getElementById(obj).className = 'prod_btn_big prod_btn_favourite_big';

				else if (document.getElementById(obj).className=='prod_btn_small prod_btn_infavourite_small')
					document.getElementById(obj).className = 'prod_btn_small prod_btn_favourite_small';


				else if (document.getElementById(obj).className=='prod_btn_mid prod_btn_infavourite_mid')
					document.getElementById(obj).className = 'prod_btn_mid prod_btn_favourite_mid';


				else
					document.getElementById(obj).className = 'prod_btn prod_btn_favourite';

			}

			//alert('2in_list='+in_list+'class='+document.getElementById(obj).className);

		}

	}

}







function ResestCartFields(UpdatFieldID,UpdatFieldCount)
{

   //alert('id='+UpdatFieldID+' | count='+UpdatFieldCount);
   var Check_UpdatFieldID='cart_quantity_hits_'+UpdatFieldID;
   UpdateElement(Check_UpdatFieldID,UpdatFieldCount,0);

   Check_UpdatFieldID='cart_quantity_act_'+UpdatFieldID;
   UpdateElement(Check_UpdatFieldID,UpdatFieldCount,0);

   Check_UpdatFieldID='cart_quantity_new_p_'+UpdatFieldID;
   UpdateElement(Check_UpdatFieldID,UpdatFieldCount,0);

   Check_UpdatFieldID='cart_quantity__'+UpdatFieldID;
   UpdateElement(Check_UpdatFieldID,UpdatFieldCount,0);

   Check_UpdatFieldID='cart_quantity__'+UpdatFieldID+'_hid';
   UpdateElement(Check_UpdatFieldID,UpdatFieldCount,0);

   Check_UpdatFieldID='cart_quantity_CMP_'+UpdatFieldID;
   UpdateElement(Check_UpdatFieldID,UpdatFieldCount,0);

   Check_UpdatFieldID='cart_quantity_CMP_'+UpdatFieldID+'_hid';
   UpdateElement(Check_UpdatFieldID,UpdatFieldCount,0);

}

function ResestWLFields(UpdatFieldID,ActiveStatus,InWL)
{
   var Check_UpdatFieldID='wl_hits'+UpdatFieldID;
   UpdateWLElement(Check_UpdatFieldID,ActiveStatus,InWL);

   Check_UpdatFieldID='wl_act'+UpdatFieldID;
   UpdateWLElement(Check_UpdatFieldID,ActiveStatus,InWL);

   Check_UpdatFieldID='wl_new_p'+UpdatFieldID;
   UpdateWLElement(Check_UpdatFieldID,ActiveStatus,InWL);

   Check_UpdatFieldID='wl_'+UpdatFieldID;
   UpdateWLElement(Check_UpdatFieldID,ActiveStatus,InWL);


}



function GetLoginData()
{
   if (http_request.readyState != 4)
   {

	document.getElementById('ajaxloderimg').style.display='';
   }

    if (http_request.readyState == 4)
        {
         if (http_request.status == 200)
         {
            //alert(http_request.responseText);
	    document.getElementById('ajaxloderimg').style.display='none';
            result = http_request.responseText;

	//проверка на ошибки ввода информации
	var check_err=result.substr(0,5);
	if (check_err=='error')
        {

	    	var ind_start=result.indexOf('stream_check=');
		var ind_start=ind_start+13;
		ind_end=result.indexOf('[*@lt@*]');
		//alert('start='+ind_start+'  end='+ind_end);
        	ind_end=ind_end-ind_start;

		SCTotal=result.substr(ind_start,ind_end);

		if (SCTotal>2)
			document.getElementById('capture_box').style.display='';

	  // обновление окна авторизации
	  	ind_start=result.indexOf('box_data=');
		ind_start=ind_start+9;
		ind_end=result.indexOf('[*@bd@*]');
		//alert('start='+ind_start+'  end='+ind_end);
        	ind_end=ind_end-ind_start;

		UpdData=result.substr(ind_start,ind_end);
			document.getElementById('LogBlockData').innerHTML=UpdData;

			document.getElementById('capcha_img').src ='capcha.php?rnd='+Math.random();

	}
	else // удачная авторизация
	{

		//alert(result);
		var redirect_url=result;

		window.location=redirect_url;
        }


            	//document.getElementById('stream_check').value = SCTotal;
         }
         else
         {
            alert('There was a problem with the request.');
	    //GetLoginData();
         }

	}
}

function DelWLData()
  {

    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	//alert(updatedText);
	/* 1. Обновление общего кол-ва элементов */
	var ind_start=updatedText.indexOf('total=');
	var ind_start=ind_start+6;
	ind_end=updatedText.indexOf('[*-&tc-*]');
        ind_end=ind_end-ind_start;
	WLTotal=updatedText.substr(ind_start,ind_end);
    //alert(WLTotal);
	if(WLTotal>0)
		{
			if(document.getElementById('fav_count_box')!=null) document.getElementById('fav_count_box').innerHTML =WLTotal;
			if(document.getElementById('bc_fav')!=null) document.getElementById('bc_fav').innerHTML =WLTotal;
		}
	else
		{
			if(document.getElementById('fav_count_box')!=null) document.getElementById('fav_count_box').innerHTML ='';
			if(document.getElementById('bc_fav')!=null) document.getElementById('bc_fav').innerHTML =0;
		}


/* 2. Обновление данный стр. wishlist.php */
	 ind_start=updatedText.indexOf('<!-- WishListDataBox -->');
	 ind_start=ind_start+24;
	ind_end=updatedText.indexOf('<!-- EOFWishListDataBox -->');
        ind_end=ind_end-ind_start;
	//alert('start='+ind_start+' end='+ind_end);
	WLData=updatedText.substr(ind_start,ind_end);

	//alert(WLData);
	if (WLData.length<300)
	{
	 	ind_start=updatedText.indexOf('<!-- WishListNONE -->');
	 	ind_start=ind_start+21;
		ind_end=updatedText.indexOf('<!-- EOFWishListNONE -->');
        	ind_end=ind_end-ind_start;
		WLData=updatedText.substr(ind_start,ind_end);
	}
	//alert(WLData);

	document.getElementById('WishListData').innerHTML =WLData;
	document.getElementById('search_inp').value=WLData;



      }
    }
  }


function DelCPData()
  {

    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	//alert(updatedText);
	ind_start=updatedText.indexOf('<!-- CompareProductsData -->');
	ind_end=updatedText.indexOf('<!-- EOF CompareProductsData -->');
	    ind_end=ind_end-ind_start;

	CPData=updatedText.substr(ind_start,ind_end);
	document.getElementById('comparefilterdata').innerHTML =CPData;

	//alert('len='+CPData.length+CPData);
	if(CPData.length<50){FloatWinClose('CompareWindow');}


	ind_start=updatedText.indexOf('<!-- CompareProductsData -->');
	ind_end=updatedText.indexOf('<!-- EOF CompareProductsData -->');
	//alert('compare box='+updatedText.indexOf('<!-- eof banner box//-->'));

	//alert('start='+ind_start+' end='+ind_end);
        ind_end=ind_end-ind_start;

	CPData=updatedText.substr(ind_start,ind_end);
	//alert('data='+CPData);
	//document.getElementById('check_text').value =updatedText;
	document.getElementById('comparefilterdata').innerHTML=CPData;


//если фильтр пустой, то не показываем его

	var FilterLength=document.getElementById('comparefilter').innerHTML;
	//alert(FilterLength.length);
	if (FilterLength.length<1300)
	{
		document.getElementById('compare_data').style.display='none';
		//document.getElementById('CompareWindow').style.display='none'
         }
	else
		document.getElementById('compare_data').style.display='';


/* 5. Обновление блока товара */
	ind_start=updatedText.indexOf('<!-- PRODUCTS DISPLAY BLOCK  //-->');
	ind_end=updatedText.indexOf('<!-- EOF PRODUCTS DISPLAY BLOCK  //-->');
        ind_end=ind_end-ind_start;

	UPDData=updatedText.substr(ind_start,ind_end);
	//alert('here='+UPDData);
	document.getElementById('products').innerHTML=UPDData;

	if(document.getElementById('CompareWinBoxDiv')!=null)
	{

         /*
		ind_start=updatedText.indexOf('<!-- ComparetDivData -->');
		ind_end=updatedText.indexOf('<!-- EOFCompareDivData -->');

	        ind_end=ind_end-ind_start;

		CPWinData=updatedText.substr(ind_start,ind_end);
		CPWinData=str_replace('CompareWinBoxDiv_copy', 'CompareWinBoxDiv', CPWinData);
		CPWinData=str_replace('CompareWinBoxDivClass_copy', 'CompareWinBoxDivClass', CPWinData);

		document.getElementById('CompareWindowData').innerHTML =CPWinData;
		*/
		ind_start=updatedText.indexOf('<!-- MYCompareDivData -->');
		ind_end=updatedText.indexOf('<!-- MYCompareDivDataEOF -->');

	        ind_end=ind_end-ind_start;

		CPWinData=updatedText.substr(ind_start,ind_end);
		CPWinData=str_replace('CompareWinBoxDiv_copy', 'CompareWinBoxDiv', CPWinData);
		CPWinData=str_replace('CompareWinBoxDivClass_copy', 'CompareWinBoxDivClass', CPWinData);

		document.getElementById('CompareWinBoxDiv').innerHTML =CPWinData;


	}
	else
	{
		alert('here2');
		document.getElementById('CompareWindowData').innerHTML='';
		//document.getElementById('compare_data').style.display='none';
	}

      }
    }
  }





function UpdateWLData(loader_id)
  {


    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
	//alert(loader_id);
       var updatedText = request.responseText;

      /* Определяем обновляемый элемент */
		var ind_start=updatedText.indexOf('updfield_id=');
		var ind_end=updatedText.indexOf('[*-&uf-*]');
		ind_start=ind_start+12;
		ind_end=ind_end-ind_start;
		UpdatFieldID=updatedText.substr(ind_start,ind_end);

	//alert('field='+UpdatFieldID+' | text='+updatedText);

/* 1. Обновление общего кол-ва избранных товаров */
	var ind_start=updatedText.indexOf('total=');
	var ind_start=ind_start+6;
	ind_end=updatedText.indexOf('[*-&tc-*]');
        ind_end=ind_end-ind_start;
	WLTotal=parseInt(updatedText.substr(ind_start,ind_end));

 	if(WLTotal>0)
		document.getElementById('fav_count_box').innerHTML =WLTotal;
	else
		document.getElementById('fav_count_box').innerHTML ='';


/* 2. Активна кнопка или нет */

	/*
	 ind_start=updatedText.indexOf('updfield_id=');
	 ind_start=ind_start+12;
	ind_end=updatedText.indexOf('[*-&uf-*]');
        ind_end=ind_end-ind_start;
	*/
	WLItemID=UpdatFieldID;

	//получаем статус кнопки
	 ind_start=updatedText.indexOf('active_status=');
	 ind_start=ind_start+14;
	ind_end=updatedText.indexOf('[*-&as-*]');
        ind_end=ind_end-ind_start;
	WLActive=updatedText.substr(ind_start,ind_end);

/* 3. Находится ли элемент в списке */

	 ind_start=updatedText.indexOf('inlist=');
	 ind_start=ind_start+7;
	ind_end=updatedText.indexOf('[*-&il-*]');
        ind_end=ind_end-ind_start;
	InWL=updatedText.substr(ind_start,ind_end);



/* Обновление данных на странице  */
/*

	//alert(updatedText);
	ind_start=updatedText.indexOf('<!-- instream_prod_block_display //-->');
	//alert('ind_start='+ind_start);


    if(ind_start!=-1)
    {
	 //alert('IF');
	 ind_end=updatedText.indexOf('<!-- eof_instream_prod_block_display //-->');
		//alert('ind_st='+ind_start+'  ind_end='+ind_end);
	 ind_end=ind_end-ind_start;
 	 ProdDATA=updatedText.substr(ind_start,ind_end);
	 	ProdDATA=ProdDATA.replace('<div id="'+loader_id+'" class="prod_btn prod_btn_cart_load" style="margin-top:-26px; display:none">','<div id="'+loader_id+'" class="prod_btn prod_btn_cart_load" style="margin-top:-26px;"');
		ProdDATA=ProdDATA.replace('<div id="'+loader_id+'" class="prod_btn_big prod_btn_cart_big_loader" style="margin-top:-32px; display:none; ">','<div id="'+loader_id+'" class="prod_btn_big prod_btn_cart_big_loader" style="margin-top:-32px;">');
	 //alert(' prod_Data='+ProdDATA);
	 //if(document.getElementById('instream_prod_block_display')!=null)
	//	 document.getElementById('instream_prod_block_display').innerHTML=ProdDATA;

    }
    else
    {


	//alert('HERE');

	flag=false;

	ind_start=updatedText.indexOf('<!-- instream_actionprod_block_display //-->');
	if(ind_start!='-1')
	{
		flag=true;
		ind_end=updatedText.indexOf('<!-- eof_instream_actionprod_block_display //-->');
		ind_end=ind_end-ind_start;
 	 	ProdDATA=updatedText.substr(ind_start,ind_end);
			ProdDATA=ProdDATA.replace('<div id="'+loader_id+'" class="prod_btn prod_btn_cart_load" style="margin-top:-26px; display:none">','<div id="'+loader_id+'" class="prod_btn prod_btn_cart_load" style="margin-top:-26px;"');
			ProdDATA=ProdDATA.replace('<div id="'+loader_id+'" class="prod_btn_big prod_btn_cart_big_loader" style="margin-top:-32px; display:none; ">','<div id="'+loader_id+'" class="prod_btn_big prod_btn_cart_big_loader" style="margin-top:-32px;">');
		if(document.getElementById('instream_actionprod_block_ul')!=null)
		 	document.getElementById('instream_actionprod_block_ul').innerHTML=ProdDATA;

	}

	ind_start=updatedText.indexOf('<!-- instream_newprod_block_display //-->');
	if(ind_start!='-1')
	{
		flag=true;
		ind_end=updatedText.indexOf('<!-- eof_instream_newprod_block_display //-->');
		ind_end=ind_end-ind_start;
 	 	ProdDATA=updatedText.substr(ind_start,ind_end);
			ProdDATA=ProdDATA.replace('<div id="'+loader_id+'" class="prod_btn prod_btn_cart_load" style="margin-top:-26px; display:none">','<div id="'+loader_id+'" class="prod_btn prod_btn_cart_load" style="margin-top:-26px;"');
			ProdDATA=ProdDATA.replace('<div id="'+loader_id+'" class="prod_btn_big prod_btn_cart_big_loader" style="margin-top:-32px; display:none; ">','<div id="'+loader_id+'" class="prod_btn_big prod_btn_cart_big_loader" style="margin-top:-32px;">');
		if(document.getElementById('instream_newprod_block_ul')!=null)
		 	document.getElementById('instream_newprod_block_ul').innerHTML=ProdDATA;

	}

	ind_start=updatedText.indexOf('<!-- instream_hitprod_block_display //-->');
	if(ind_start!='-1')
	{
		flag=true;
		ind_end=updatedText.indexOf('<!-- eof_instream_hitprod_block_display //-->');
		ind_end=ind_end-ind_start;
 	 	ProdDATA=updatedText.substr(ind_start,ind_end);
			ProdDATA=ProdDATA.replace('<div id="'+loader_id+'" class="prod_btn prod_btn_cart_load" style="margin-top:-26px; display:none">','<div id="'+loader_id+'" class="prod_btn prod_btn_cart_load" style="margin-top:-26px;"');
			ProdDATA=ProdDATA.replace('<div id="'+loader_id+'" class="prod_btn_big prod_btn_cart_big_loader" style="margin-top:-32px; display:none; ">','<div id="'+loader_id+'" class="prod_btn_big prod_btn_cart_big_loader" style="margin-top:-32px;">');
		if(document.getElementById('instream_hitprod_block_ul')!=null)
		 	document.getElementById('instream_hitprod_block_ul').innerHTML=ProdDATA;

	}
	//alert(flag);


	ResestWLFields(WLItemID,WLActive,InWL);


    }
*/
	ResestWLFields(WLItemID,WLActive,InWL);

	//alert('passed');

	$("#"+loader_id).fadeOut(1000);
	document.getElementById("ajax_work").value=0;

      }
    }
  }



function UpdateCompareData(loader_id)
  {

    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	//alert(updatedText);


/* 4. Обновление фильтра */

	ind_start=updatedText.indexOf('<!-- CompareBoxData -->');
	ind_end=updatedText.indexOf('<!-- EOFCompareBoxData -->');
        ind_end=ind_end-ind_start;
	CPBOX=updatedText.substr(ind_start,ind_end);

		ind_start=updatedText.indexOf('<!-- CompareProductsData -->');
		ind_end=updatedText.indexOf('<!-- EOF CompareProductsData -->');
        	ind_end=ind_end-ind_start;

		CPData=updatedText.substr(ind_start,ind_end);
		//alert('here='+CPData);

		//alert(document.getElementById('filter_header_comp').innerHTML);
		document.getElementById('filter_header_comp').innerHTML=CPBOX;
		//alert(document.getElementById('filter_header_comp').innerHTML);
		document.getElementById('comparefilterdata').innerHTML=CPData;
	//document.getElementById('check_text').value=updatedText;

//если фильтр пустой, то не показываем его

	var FilterLength=document.getElementById('comparefilter').innerHTML;
	//alert('length='+FilterLength.length);
	if (FilterLength.length<1300)
		document.getElementById('compare_data').style.display='none';
	else
	{
		document.getElementById('compare_data').style.display='';

		document.getElementById('filter_box_comp').style.display='';

		//document.getElementById('filter_header_comp_bg').style.className='filter_header_bg';
		//alert(document.getElementById('filter_header_comp_bg').style.className);

	}


/* 5. Обновление блока товара */
	ind_start=updatedText.indexOf('<!-- PRODUCTS DISPLAY BLOCK  //-->');
	ind_end=updatedText.indexOf('<!-- EOF PRODUCTS DISPLAY BLOCK  //-->');
        ind_end=ind_end-ind_start;

	UPDData=updatedText.substr(ind_start,ind_end);
	//alert('here='+UPDData);

		UPDData=UPDData.replace('<div id="'+loader_id+'" class="prod_btn prod_btn_cart_load" style="margin-top:-26px; display:none">','<div id="'+loader_id+'" class="prod_btn prod_btn_cart_load" style="margin-top:-26px;"');
		UPDData=UPDData.replace('<div id="'+loader_id+'" class="prod_btn_big prod_btn_cart_big_loader" style="margin-top:-32px; display:none; ">','<div id="'+loader_id+'" class="prod_btn_big prod_btn_cart_big_loader" style="margin-top:-32px; ">');

	document.getElementById('products').innerHTML=UPDData;
//	document.getElementById('check_text').value=updatedText;

// Обновление окна
	ind_start=updatedText.indexOf('<!-- ComparetDivData -->');
	ind_end=updatedText.indexOf('<!-- EOFCompareDivData -->');
	//alert('start='+ind_start+' end='+ind_end);
        ind_end=ind_end-ind_start;

	CPWinData=updatedText.substr(ind_start,ind_end);
	//alert(CPData);

	CPWinData=str_replace('CompareWinBoxDiv_copy', 'CompareWinBoxDiv', CPWinData);
	CPWinData=str_replace('CompareWinBoxDivClass_copy', 'CompareWinBoxDivClass', CPWinData);

	//alert(CPData);

	document.getElementById('CompareWindowData').innerHTML =CPWinData;
	var CID=document.getElementById('sid_flag').value;
	var cPath=document.getElementById('path_flag').value;
	//BuildInStreamWin('Compare',CID,cPath);


	$("#"+loader_id).fadeOut(1000);
	document.getElementById("ajax_work").value=0;

      }
    }
  }






function UpdateSaleTab()
  {

    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	//alert(updatedText);

/* Обновление данных на вкладке АКЦИИ */
	var ind_start=updatedText.indexOf('<!-- ActStart -->');
	var ind_start=ind_start+17;
	ind_end=updatedText.indexOf('<!-- ActEOF -->');
        ind_end=ind_end-ind_start;
	UpdTabTxt=updatedText.substr(ind_start,ind_end);

	document.getElementById('InStreamActionTab').innerHTML = '<div>'+UpdTabTxt;


      }
    }
  }




function UpdateCartFields(loader_id)
  {


    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	//alert(updatedText);


/* 1. Получаем id продукта  */

	//alert('upd_txt'+updatedText.substr(1000));
		var ind_start=updatedText.indexOf('updfield_id=');
		var ind_end=updatedText.indexOf('[*-&cq-*]');
		ind_start=ind_start+12;
		ind_end=ind_end-ind_start;
		UpdatFieldID=updatedText.substr(ind_start,ind_end);

/* 2. Общее кол-во и сумма в корзине */

		ind_start=updatedText.indexOf('total=');
			ind_start=ind_start+6;

		ind_end=updatedText.indexOf('[*-&tc-*]');
			ind_end=ind_end-ind_start;
		UpdatT=updatedText.substr(ind_start,ind_end);
		var Check_UpdatFieldID_COUNT='cart_count_box';
		  //UpdateElement(Check_UpdatFieldID,UpdatT,1);

			ind_start=updatedText.indexOf('total_sum=');
			ind_start=ind_start+10;

			ind_end=updatedText.indexOf('[*-&ts-*]');
			ind_end=ind_end-ind_start;
			UpdatTotal=updatedText.substr(ind_start,ind_end);
			var Check_UpdatFieldID_SUMM='cart_summ_box';
			float_val=parseInt(UpdatTotal);
			//float_val=float_val.toFixed(2);

			  //UpdateElement(Check_UpdatFieldID,float_val,1);
			//alert(document.getElementById("windowOpen").title);
			//alert(UpdatT);
			if(UpdatT>0)
			{
				var sumTot=Number(UpdatTotal);
				    sumTot=sumTot.toFixed(2);

				document.getElementById("windowOpen").title= 'В корзине товаров: '+UpdatT+'   на сумму: '+sumTot;
				UpdateElement(Check_UpdatFieldID_COUNT,UpdatT,1);
				UpdateElement(Check_UpdatFieldID_SUMM,float_val,1);


			}
			else
			{
				document.getElementById("windowOpen").title= 'Корзина пуста';
				UpdateElement(Check_UpdatFieldID_COUNT,'',1);
				UpdateElement(Check_UpdatFieldID_SUMM,'',1);
			}
			//alert(document.getElementById("windowOpen").title);

/*  3. Обновляем данные в окне корзины */

		ind_start=updatedText.indexOf('cart_win=');
			ind_start=ind_start+9;

		ind_end=updatedText.indexOf('[*-&cw-*]');
			ind_end=ind_end-ind_start;
		UpdatWinData=updatedText.substr(ind_start,ind_end);

		//alert(UpdatWinData);

					start=UpdatWinData.indexOf('<!--CartTotal[');
					end=UpdatWinData.indexOf(']//-->');
					tot_res=UpdatWinData.substr(start+14,(end-(start+14)));
					document.getElementById('CartWinTotal').innerHTML='Итого к оплате: '+tot_res;

			UpdateElement('Cart_Window',UpdatWinData,1);

		//alert(tot_res);

		if(UpdatT>0)
			{
				var sumTot=Number(UpdatTotal);
				    sumTot=sumTot.toFixed(2);

				document.getElementById("windowOpen").title= 'В корзине товаров: '+UpdatT+'   на сумму: '+tot_res;
				UpdateElement(Check_UpdatFieldID_COUNT,UpdatT,1);
				UpdateElement(Check_UpdatFieldID_SUMM,parseInt(tot_res),1);


			}
/*  4. Текущее кол-во выбранного продукта в корзине + обновление кол-ва на кнопках */

		ind_start=updatedText.indexOf('cur_count=');
			ind_start=ind_start+10;

		ind_end=updatedText.indexOf('[*-&cc-*]');
			ind_end=ind_end-ind_start;
		UpdatFieldCount=updatedText.substr(ind_start,ind_end);
		//alert('this reset id='+UpdatFieldID+'  count='+UpdatFieldCount);
		ResestCartFields(UpdatFieldID,UpdatFieldCount);

		$("#"+loader_id).fadeOut(1000);
		document.getElementById("ajax_work").value=0;



      }
    }
  }




function UpdateCartWindow()
  {

    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
		//alert(updatedText);

		/* Обновление данных на кнопках */
		var ind_start=updatedText.indexOf('item_id=');
		var ind_start=ind_start+8;
		ind_end=updatedText.indexOf('#$@$#');
	        ind_end=ind_end-ind_start;
		UpdIdProd=updatedText.substr(ind_start,ind_end);
		//alert('upd='+UpdIdProd+' start='+ind_start+'  end='+ind_end);

		ResestCartFields(UpdIdProd,0);

		ind_start=updatedText.indexOf('instream_cartdel_start');
		ind_end=updatedText.indexOf('instream_cartdel_end');
        var tot_c=updatedText.indexOf('#$@$#')+5;

		updatedText=updatedText.substr(0,ind_end);
        updatedCount=updatedText.substr(tot_c,(ind_start-tot_c));


	ind_start=updatedText.indexOf('total_sum=');
	ind_start=ind_start+10;
	ind_end=updatedText.indexOf('#$[tcs]$#');
	ind_end=ind_end-ind_start;
	updatedSum=parseInt(updatedText.substr(ind_start,ind_end));


        if (updatedCount=='') {updatedCount=0;}
	ind_start=updatedText.indexOf('<!-- CartWinTableData -->');
	updatedText=updatedText.substr(ind_start);

	start=updatedText.indexOf('<!--CartTotal[');
	end=updatedText.indexOf(']//-->');
	tot_res=updatedText.substr(start+14,(end-(start+14)));
	document.getElementById('CartWinTotal').innerHTML='Итого к оплате: '+tot_res;

	//alert(updatedText);
/* Обновление формы */
	if(updatedCount==0) updatedCount='';
	if(parseInt(tot_res)>0) updatedSum=parseInt(tot_res);
	else updatedSum='';
       document.getElementById("Cart_Window").innerHTML = updatedText;

	document.getElementById("cart_count_box").innerHTML = updatedCount;
	document.getElementById("cart_summ_box").innerHTML = updatedSum;

      }
    }
  }


var request = null;
   try
	{
     		request = new XMLHttpRequest();
   	}
   catch (trymicrosoft)
	{
     	try {
       		request = new ActiveXObject("Msxml2.XMLHTTP");
     	    }
        catch (othermicrosoft)
	   {
        try
	   {
         	request = new ActiveXObject("Microsoft.XMLHTTP");
       	   }
        catch (failed)
	   {
         request = null;
           }
        }
   }







