﻿ function add2Fav (x){
        if (document.all  && !window.opera) {
             if (typeof window.external == "object") {
                window.external.AddFavorite (document.location, document.title);
                return true;
              }
              else return false;

        }
        else{
            x.href=document.location;
            x.title=document.title;
            x.rel = "sidebar";
            return true;
        }
    }

      function SearchInput(flag)
        {
           var  obj=document.getElementById("search_inp");
           		val=obj.value;

             if(flag==1)
             {
             	if (val=="введите название")
             	obj.value="";
             }
             else
             {
             	if (val=="")
             	obj.value="введите название";
             }
        }


function UpdateScrollDataStop(minVal,maxVal,SID,cPath)
{

  //alert('min='+minVal);
     if (request == null)
     alert("Error creating request object!");
    
     var url='index.php?filterminValue='+minVal+'&filtermaxValue='+maxVal+'&cPath='+cPath+'&'+SID;
     
    //alert('url='+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;
	
	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 OrderFormSubmit(url) // Заказать звонок
{
	alert('url='+url);

	var parameters='user_lname='+encodeURI(document.getElementById("user_lname").value)+'&user_name='+encodeURI(document.getElementById("user_name").value);	
	
	alert('url='+url+' param='+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 = GetFormOrderData;
      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 CallOrderSubmit(url) // Заказать звонок
{
	//alert('url='+url+'  params='+parameters);

	if (document.getElementById('call_order_capture_input')!=null)
	   var parameters='user_name='+encodeURI(document.getElementById("user_name").value)+'&user_phone='+encodeURI(document.getElementById("user_phone").value)+'&calltime='+encodeURI(document.getElementById("calltime").value)+'&edditinal='+encodeURI(document.getElementById("edditinal").value)+'&capture_input='+encodeURI(document.getElementById("call_order_capture_input").value);
	else 
	   var parameters='user_name='+encodeURI(document.getElementById("user_name").value)+'&user_phone='+encodeURI(document.getElementById("user_phone").value)+'&calltime='+encodeURI(document.getElementById("calltime").value)+'&edditinal='+encodeURI(document.getElementById("edditinal").value)+'&capture_input=0';	

 	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 = GetCallOrderData;
      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 GetCallOrderData()
{
   if (http_request.readyState != 4) 
   {
	
	document.getElementById('CallOrderAjaxloderImg').style.display='';     
   } 

    if (http_request.readyState == 4) 
        {
         if (http_request.status == 200) 
         {
            alert(http_request.responseText);
	    document.getElementById('CallOrderAjaxloderImg').style.display='none';   
            result = http_request.responseText;

		
//проверка на ошибки ввода информации
	var check_err=result.substr(0,6);
	if (check_err=='error=')
        {

	    
	  // обновление окна авторизации
		ind_start=6;
		ind_end=result.indexOf('[*@end@*]');
		//alert('start='+ind_start+'  end='+ind_end);
        	ind_end=ind_end-ind_start;

		UpdData=result.substr(ind_start,ind_end);
			document.getElementById('CallOrderData').innerHTML=UpdData; 
     
			document.getElementById('oc_capcha_img').src ='capcha_pages.php?page=callorder&rnd=+Math.random()';
	
	}
	else // удачная авторизация
	{
		
		//alert(result);
		//var redirect_url=result;
		document.getElementById('CallOrderData').innerHTML=result; 

		//window.location=redirect_url;
        }


        
         } 
         else 
         {
            alert('There was a problem with the request.');
	    //GetLoginData();
         }
	
	}
}


function GetFormOrderData()
{
   

    if (http_request.readyState == 4) 
        {
         if (http_request.status == 200) 
         {
            alert(http_request.responseText);
	    document.getElementById('CallOrderAjaxloderImg').style.display='none';   
            result = http_request.responseText;
	    window.open('http://localhost/svitmob/form_order.php');
/*
		
//проверка на ошибки ввода информации
	var check_err=result.substr(0,6);
	if (check_err=='error=')
        {

	    
	  // обновление окна авторизации
		ind_start=6;
		ind_end=result.indexOf('[*@end@*]');
		//alert('start='+ind_start+'  end='+ind_end);
        	ind_end=ind_end-ind_start;

		UpdData=result.substr(ind_start,ind_end);
			document.getElementById('CallOrderData').innerHTML=UpdData; 
     
			document.getElementById('oc_capcha_img').src ='capcha_pages.php?page=callorder&rnd=+Math.random()';
	
	}
	else // удачная авторизация
	{
		
		//alert(result);
		//var redirect_url=result;
		document.getElementById('CallOrderData').innerHTML=result; 

		//window.location=redirect_url;
        }
*/

        
         } 
         else 
         {
            alert('There was a problem with the request.');
	    //GetLoginData();
         }
	
	}
}




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) // чистка всей корзины
{
    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 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);
        
/* Обновление данных корзины */
       document.getElementById("cart_cur_sel").innerHTML = updatedCurTxt;
	box_data_end=updatedText.indexOf('<!-- EOFCartWinDiv -->');
	box_data_end=box_data_end-12;
	box_data_start=updatedText.indexOf('<div id="win_cart_data">');
	box_data_start=box_data_start+24;
	//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('start='+box_data_start+'  len='+box_data_end+'  txt='+BoxCurText);
document.getElementById("win_cart_data").innerHTML = BoxCurText;


      }
   }

}

function UpdateCartWindowClear()
{
  if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	if (updatedText.length>0) 
	{
		while(updatedText.indexOf(',')>0) // очистка значений на кнопках	
		{
			UpdatFieldID=updatedText.substr(0,updatedText.indexOf(','));
			updatedText=updatedText.substr( (updatedText.indexOf(','))+1);
			ResestCartFields(UpdatFieldID,'0');
		}

	}

       document.getElementById("Cart_Window").innerHTML = '<center>Корзина пуста</center>';
       document.getElementById("cart_count_box").innerHTML = 0;
	document.getElementById("cart_summ_box").innerHTML = 0;

      }
    }	

}


function InstreamCartAdd(prod_id,url,upd_field_id) // добавление в корзину
 {
 
//alert('here');
	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('old_url='+url+'  new_url='+url_new);


   if (request == null)
     alert("Error creating request object!");
     request.open("GET",url_new,true);
     request.onreadystatechange = UpdateCartFields;
     request.send(null);


 }

function InstreamWishListAdd(prod_id,url)
{
	//alert('url='+url);
	if (request == null)
     	alert("Error creating request object!");
     	//alert('url1='+url);	
     	request.open("GET",url,true);
     	request.onreadystatechange = UpdateWLData;
     	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 InstreamCompareAdd(prod_id,url)
{
	//alert('url='+url);
	if (request == null)
     	alert("Error creating request object!");
     	//alert('url1='+url);	
     	request.open("GET",url,true);
     	request.onreadystatechange = UpdateCompareData;
     	request.send(null);
		
}



function InstreamCompareDel(prod_id,url)
{
	//alert('url='+url);
	if (request == null)
     	alert("Error creating request object!");
     	//alert('url1='+url);	
     	request.open("GET",url,true);
     	request.onreadystatechange = DelCPData;
     	request.send(null);
		
}





function InStreamLogin(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 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)
{

   if(type==1)
   {		
		
	if (document.getElementById(obj)!=null)
			document.getElementById(obj).innerHTML=obj_value;
   }
   else if(type==0)
   {
	if (document.getElementById(obj)!=null)
			document.getElementById(obj).value = 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)  document.getElementById(obj).className = 'prod_btn prod_btn_infavourite';
			else		document.getElementById(obj).className = 'prod_btn prod_btn_favourite';
			//alert('2in_list='+in_list+'class='+document.getElementById(obj).className);
			
		}
		
	}
	
}


function UpdateCPElement(obj,obj_status,in_list)
{
	
	if (document.getElementById(obj)!=null)
	{
		if (obj_status==1) 
		{
			
			if (in_list==0)  document.getElementById(obj).className = 'prod_btn prod_btn_incompare';
			else		document.getElementById(obj).className = 'prod_btn prod_btn_compare';
			
		}
		
	}
	
}




function ResestCartFields(UpdatFieldID,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);
}

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 ResestCPFields(UpdatFieldID,ActiveStatus,InWL)
{
   var Check_UpdatFieldID='comp_hits'+UpdatFieldID;
   UpdateCPElement(Check_UpdatFieldID,ActiveStatus,InWL);

   Check_UpdatFieldID='comp_act'+UpdatFieldID;
   UpdateCPElement(Check_UpdatFieldID,ActiveStatus,InWL);

   Check_UpdatFieldID='comp_new_p'+UpdatFieldID;
   UpdateCPElement(Check_UpdatFieldID,ActiveStatus,InWL);

   Check_UpdatFieldID='comp_'+UpdatFieldID;
   UpdateCPElement(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);
	
	document.getElementById('fav_count_box').innerHTML =WLTotal;


/* 2. Обновление данный стр. wishlist.php */
	 ind_start=updatedText.indexOf('<!-- WishListDataBox -->');
	 ind_start=ind_start+24;
	ind_end=updatedText.indexOf('<!-- EOFWishListDataBox -->');
        ind_end=ind_end-ind_start;
	WLData=updatedText.substr(ind_start,ind_end);
	
	if (WLData.length<3)
	{
	 	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);
	}
	
	 
	document.getElementById('WishListData').innerHTML =WLData;


	
      }
    }
  }


function DelCPData()
  {

    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	alert(updatedText);


/* 2. Обновление данный стр. wishlist.php 
	 ind_start=updatedText.indexOf('<!-- WishListDataBox -->');
	 ind_start=ind_start+24;
	ind_end=updatedText.indexOf('<!-- EOFWishListDataBox -->');
        ind_end=ind_end-ind_start;
	WLData=updatedText.substr(ind_start,ind_end);
	
	if (WLData.length<3)
	{
	 	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);
	}
	
	 
	document.getElementById('WishListData').innerHTML =WLData;
*/

	
      }
    }
  }





function UpdateWLData()
  {

    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);
	 
	document.getElementById('fav_count_box').innerHTML =WLTotal;

	

/* 2. Активна кнопка или нет */

	// получаем ID элемента
	 ind_start=updatedText.indexOf('updfield_id=');
	 ind_start=ind_start+12;
	ind_end=updatedText.indexOf('[*-&uf-*]');
        ind_end=ind_end-ind_start;
	WLItemID=updatedText.substr(ind_start,ind_end);

	//получаем статус кнопки
	 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('item_id='+WLItemID+'  WLActive='+WLActive+'   In List='+InWL);
	ResestWLFields(WLItemID,WLActive,InWL);
	
      }
    }
  }



function UpdateCompareData()
  {

    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	//alert(updatedText);

/* 2. Активна кнопка или нет */

	// получаем ID элемента
	 ind_start=updatedText.indexOf('updfield_id=');
	 ind_start=ind_start+12;
	ind_end=updatedText.indexOf('[*-&uf-*]');
        ind_end=ind_end-ind_start;
	WLItemID=updatedText.substr(ind_start,ind_end);
	
	//alert('ID='+WLItemID);

	//получаем статус кнопки
	 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);

	//alert('Active='+WLActive);

/* 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('item_id='+WLItemID+'  WLActive='+WLActive+'   In List='+InWL);
	ResestCPFields(WLItemID,WLActive,InWL);

      }
    }
  }






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);
		
		//alert('text='+UpdTabTxt);
	 
	document.getElementById('InStreamActionTab').innerHTML = '<div>'+UpdTabTxt;

		
      }
    }
  }




function UpdateCartFields()
  {

    if (request.readyState == 4)
    {

      if (request.status == 200)
      {
       /* Получение ответа от сервера */
       var updatedText = request.responseText;
	//alert(updatedText);


/* 1. Получаем id продукта  */

	//alert('upd_txt'+updatedText);
		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);
		UpdateField='cart_quantity_'+UpdatFieldID;
		
		document.getElementById(UpdateField).value = UpdatFieldCount;
		
		
/**/
alert('Товар добавлен в корзину');

      }
    }
  }




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=updatedText.substr(ind_start,ind_end);


        if (updatedCount=='') {updatedCount=0;}
         ind_start=ind_start+52;
	updatedText=updatedText.substr(ind_start);
	//alert(updatedText);	
/* Обновление формы */
       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;
           }
        }
   }


/***  MENU ***/
var expandFirstItemAutomatically = false;	// Expand first menu item automatically ?
var initMenuIdToExpand = false;	// Id of menu item that should be initially expanded. the id is defined in the <li> tag.
var expandMenuItemByUrl = true;	// Menu will automatically expand by url - i.e. if the href of the menu item is in the current location, it will expand


var initialMenuItemAlwaysExpanded = true;	// NOT IMPLEMENTED YET

var dhtmlgoodies_slmenuObj;
var divToScroll = false;
var ulToScroll = false;
var divCounter = 1;
var otherDivsToScroll = new Array();
var divToHide = false;
var parentDivToHide = new Array();
var ulToHide = false;
var offsetOpera = 0;
if(navigator.userAgent.indexOf('Opera')>=0)offsetOpera=1;
var slideMenuHeightOfCurrentBox = 0;
var objectsToExpand = new Array();
var initExpandIndex = 0;
var alwaysExpanedItems = new Array();

function popMenusToShow()
{
	var obj = divToScroll;
	var endArray = new Array();
	while(obj && obj.tagName!='BODY'){
		if(obj.tagName=='DIV' && obj.id.indexOf('slideDiv')>=0){
			var objFound = -1;
			for(var no=0;no<otherDivsToScroll.length;no++){
				if(otherDivsToScroll[no]==obj){
					objFound = no;
				}
			}
			if(objFound>=0){
				otherDivsToScroll.splice(objFound,1);
			}
		}
		obj = obj.parentNode;
	}
}

function showSubMenu(e,inputObj)
{
	redirect_link=false;
  //alert('e='+e+'  obj='+inputObj);
	if(this && this.tagName)inputObj = this.parentNode;
	if(inputObj && inputObj.tagName=='LI')
	{
		divToScroll = inputObj.getElementsByTagName('DIV')[0];
		for(var no=0;no<otherDivsToScroll.length;no++)
		{
			if(otherDivsToScroll[no]==divToScroll)return;
		}
	}
	hidingInProcess = false;
	if(otherDivsToScroll.length>0)
	{// alert('H1');
		if(divToScroll)
		{
			//alert('H1_1');
			if(otherDivsToScroll.length>0){
				popMenusToShow();
			}
			if(otherDivsToScroll.length>0){
				autoHideMenus();
				hidingInProcess = true;
			}
			redirect_link=false;
		}
		else
		{
         	//alert('H1_2');
         	redirect_link=true;
		}
	}
	if(divToScroll && !hidingInProcess)
	{
		//alert('H2')
		divToScroll.style.display='';
		otherDivsToScroll.length = 0;
		otherDivToScroll = divToScroll.parentNode;
		otherDivsToScroll.push(divToScroll);
		while(otherDivToScroll && otherDivToScroll.tagName!='BODY'){
			if(otherDivToScroll.tagName=='DIV' && otherDivToScroll.id.indexOf('slideDiv')>=0){
				otherDivsToScroll.push(otherDivToScroll);

			}
			otherDivToScroll = otherDivToScroll.parentNode;
		}
		ulToScroll = divToScroll.getElementsByTagName('UL')[0];
		if(divToScroll.style.height.replace('px','')/1<=1)scrollDownSub();
	}


	if (redirect_link==false)
	{
		return false;
	}

}



function autoHideMenus()
{
	if(otherDivsToScroll.length>0){
		divToHide = otherDivsToScroll[otherDivsToScroll.length-1];
		parentDivToHide.length=0;
		var obj = divToHide.parentNode.parentNode.parentNode;
		while(obj && obj.tagName=='DIV'){
			if(obj.id.indexOf('slideDiv')>=0)parentDivToHide.push(obj);
			obj = obj.parentNode.parentNode.parentNode;
		}
		var tmpHeight = (divToHide.style.height.replace('px','')/1 - slideMenuHeightOfCurrentBox);
		if(tmpHeight<0)tmpHeight=0;
		if(slideMenuHeightOfCurrentBox)divToHide.style.height = tmpHeight  + 'px';
		ulToHide = divToHide.getElementsByTagName('UL')[0];
		slideMenuHeightOfCurrentBox = ulToHide.offsetHeight;
		scrollUpMenu();
	}else{
		slideMenuHeightOfCurrentBox = 0;
		showSubMenu();
	}
}


function scrollUpMenu()
{

	var height = divToHide.offsetHeight;
	height-=5;
	if(height<0)height=0;
	divToHide.style.height = height + 'px';

	for(var no=0;no<parentDivToHide.length;no++){
		parentDivToHide[no].style.height = parentDivToHide[no].getElementsByTagName('UL')[0].offsetHeight + 'px';
	}
	if(height>0){
		setTimeout('scrollUpMenu()',5);
	}else{
		divToHide.style.display='none';
		otherDivsToScroll.length = otherDivsToScroll.length-1;
		autoHideMenus();
	}
}

function scrollDownSub()
{
	if(divToScroll){
		var height = divToScroll.offsetHeight/1;
		var offsetMove =Math.min(5,(ulToScroll.offsetHeight - height));
		height = height +offsetMove ;
		divToScroll.style.height = height + 'px';

		for(var no=1;no<otherDivsToScroll.length;no++){
			var tmpHeight = otherDivsToScroll[no].offsetHeight/1 + offsetMove;
			otherDivsToScroll[no].style.height = tmpHeight + 'px';
		}
		if(height<ulToScroll.offsetHeight)setTimeout('scrollDownSub()',5); else {
			divToScroll = false;
			ulToScroll = false;
			if(objectsToExpand.length>0 && initExpandIndex<(objectsToExpand.length-1)){
				initExpandIndex++;

				showSubMenu(false,objectsToExpand[initExpandIndex]);
			}
		}
	}
}

function initSubItems(inputObj,currentDepth)
{
	divCounter++;
	var div = document.createElement('DIV');	// Creating new div
	div.style.overflow = 'hidden';
	div.style.position = 'relative';
	div.style.display='none';
	div.style.height = '1px';
	div.id = 'slideDiv' + divCounter;
	div.className = 'slideMenuDiv' + currentDepth;
	inputObj.parentNode.appendChild(div);	// Appending DIV as child element of <LI> that is parent of input <UL>
	div.appendChild(inputObj);	// Appending <UL> to the div
	var menuItem = inputObj.getElementsByTagName('LI')[0];
	while(menuItem)
	{
		if(menuItem.tagName=='LI')
		{
			var aTag = menuItem.getElementsByTagName('A')[0];
			aTag.className='slMenuItem_depth'+currentDepth;
			var subUl = menuItem.getElementsByTagName('UL');
			if(subUl.length>0){
				initSubItems(subUl[0],currentDepth+1);
			}
			aTag.onclick = showSubMenu;
		}
		menuItem = menuItem.nextSibling;
	}
}

function initSlideDownMenu()
{
	dhtmlgoodies_slmenuObj = document.getElementById('dhtmlgoodies_slidedown_menu');
	dhtmlgoodies_slmenuObj.style.visibility='visible';
	var mainUl = dhtmlgoodies_slmenuObj.getElementsByTagName('UL')[0];
	var mainMenuItem = mainUl.getElementsByTagName('LI')[0];
	mainItemCounter = 1;
	while(mainMenuItem)
	{
		if(mainMenuItem.tagName=='LI')
		{
			var aTag = mainMenuItem.getElementsByTagName('A')[0];
			aTag.className='slMenuItem_depth1';
			var subUl = mainMenuItem.getElementsByTagName('UL');
			if(subUl.length>0)
			{
				mainMenuItem.id = 'mainMenuItem' + mainItemCounter;
				initSubItems(subUl[0],2);
				aTag.onclick = showSubMenu;
				mainItemCounter++;
			}
		}
		mainMenuItem = mainMenuItem.nextSibling;
	}

	if(location.search.indexOf('mainMenuItemToSlide')>=0)
	{   //alert('here1');
		var items = location.search.split('&');
		for(var no=0;no<items.length;no++)
		{
			if(items[no].indexOf('mainMenuItemToSlide')>=0){
				values = items[no].split('=');
				showSubMenu(false,document.getElementById('mainMenuItem' + values[1]));
				initMenuIdToExpand = false;
			}
		}
	}
	else if(expandFirstItemAutomatically>0)
	{   //alert('here2');
		if(document.getElementById('mainMenuItem' + expandFirstItemAutomatically)){
			showSubMenu(false,document.getElementById('mainMenuItem' + expandFirstItemAutomatically));
			initMenuIdToExpand = false;
		}
	}

	if(expandMenuItemByUrl)
	{
		var aTags = dhtmlgoodies_slmenuObj.getElementsByTagName('A');
		for(var no=0;no<aTags.length;no++){
			var hrefToCheckOn = aTags[no].href;
			//alert(hrefToCheckOn);
			if(location.href.indexOf(hrefToCheckOn)>=0 && hrefToCheckOn.indexOf('#')<hrefToCheckOn.length-1)
			{
				initMenuIdToExpand = false;
				var obj = aTags[no].parentNode;
				while(obj && obj.id!='dhtmlgoodies_slidedown_menu')
				{
					if(obj.tagName=='LI'){
						var subUl = obj.getElementsByTagName('UL');
						if(initialMenuItemAlwaysExpanded)alwaysExpanedItems[obj.parentNode] = true;
						if(subUl.length>0){
							objectsToExpand.unshift(obj);
						}
					}
					obj = obj.parentNode;
				}
				showSubMenu(false,objectsToExpand[0]);
				break;
			}
		}
	}

	if(initMenuIdToExpand)
	{
		objectsToExpand = new Array();
		var obj = document.getElementById(initMenuIdToExpand)
		while(obj && obj.id!='dhtmlgoodies_slidedown_menu'){
			if(obj.tagName=='LI'){
				var subUl = obj.getElementsByTagName('UL');
				if(initialMenuItemAlwaysExpanded)alwaysExpanedItems[obj.parentNode] = true;
				if(subUl.length>0){
					objectsToExpand.unshift(obj);
				}
			}
			obj = obj.parentNode;
		}

		showSubMenu(false,objectsToExpand[0]);

	}



}



function nav(){
	$("div#nav ul li").mouseover(function() {
			$(this).find('ul:first').show();
	});

	$("div#nav ul li").mouseleave(function() {
		$("div#nav ul li ul").hide();
	});

	$("div#nav ul li ul").mouseleave(function() {
		$("div#nav ul li ul").hide();
	});

};
$(document).ready(function(){
	nav();
});


  $(document).ready(function()
      {
        $('#CartOpen').click(function()
        {
          $('#Window3').AeroWindow(
          {
            WindowTitle:        '<span style="color:#fff">&nbsp;КОРЗИНА ТОВАРОВ</span>',
            WindowPositionTop:  'center',
            WindowPositionLeft: 'center',
            WindowWidth:        650,
            WindowHeight:       400,
            WindowAnimation:    'easeInOutSine',
            WindowResizable:    true,
            WindowDraggable:    true,
            WindowMinimize:     true,
            WindowMaximize:     true,
            WindowClosable:     true
          });
        })
      });



 var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-18215981-2']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

   function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}

function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}
	


 


