﻿function createReqObj()
{
 if (window.XMLHttpRequest)
 {
  try 
  {
   return new XMLHttpRequest;
  } catch (e) {}
 }
 else if (window.ActiveXObject)
 {
  try 
  {
   return new ActiveXObject('Msxml2.XMLHTTP');
  } catch (e) {}
  try 
  {
   return new ActiveXObject('Microsoft.XMLHTTP');
  } catch (e) {}
 }
 alert("This browser does not support XMLHttpRequest.");
 return null;
}


function ajx_basket_add(tp,tov_id,crtsel_id)
	{
	var ptr;
	var cur_num="";
	var cur_num2="";
	ptr=document.getElementById('crtsel_sel_'+crtsel_id);
	if (ptr!=null) cur_num=ptr.value;
	ptr=document.getElementById('crtsel_num_'+crtsel_id);
	if (ptr!=null) cur_num2=ptr.value;
	ptr=document.getElementById('tov_tr_'+tov_id);if (ptr!=null) ptr.style.display="";
	ptr=document.getElementById('tov_bsk_'+tov_id);if (ptr!=null) ptr.style.display="none";
	var req = createReqObj();
	var str = '/index.php?module=cart&action=aj_add&id='+tov_id+'&num='+cur_num+'&num2='+cur_num2+'&ttid='+(Math.random() * 1000000000);
	req.open('GET', str, true);
	req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 1980 00:00:00 GMT");
	req.onreadystatechange = function()
		{
  		try
	  		{
	  		if (req.readyState == 4)
	  			{
	   			if (req.status == 200) 
	   				{
	    				var r = req.responseText.length;
	    				if (r>0)
	    					{
	    					var txt=req.responseText;
	    					var ddt=txt.split("|",20);
						if (ddt[0]==1)
							{
							if (ddt[1]<=0)
								{
								ptr=document.getElementById('cart_dpl_yes');if (ptr!=null) ptr.style.display="none";
								ptr=document.getElementById('cart_dpl_no');if (ptr!=null) ptr.style.display="";
								ptr=document.getElementById('cart_dpl_mhref');if (ptr!=null) ptr.href="/cart-empty/";
								}
								else
								{
								ptr=document.getElementById('cart_dpl_mhref');if (ptr!=null) ptr.href="/cart/";
								ptr=document.getElementById('cart_dpl_no');if (ptr!=null) ptr.style.display="none";
								ptr=document.getElementById('cart_dpl_yes');if (ptr!=null) ptr.style.display="";
								ptr=document.getElementById('cart_dpl_num');if (ptr!=null) ptr.innerHTML=ddt[1];
								ptr=document.getElementById('cart_dpl_weight');if (ptr!=null) ptr.innerHTML=ddt[2];
								ptr=document.getElementById('cart_dpl_price');if (ptr!=null) ptr.innerHTML=ddt[3];
								ptr=document.getElementById('cart_dpl_val');if (ptr!=null) ptr.innerHTML=ddt[4];
								}
								
							ptr=document.getElementById('cart_info_dsc');
							if (ptr!=null)
								{
								var ddsc=ddt[5];
								if (ddsc<=0)
									{
									if (ddt[7]>0)
										{
										ddsc=ddt[7];
										ddt[6]=0;
										}
									}
								var aad="";
								if (ddsc>0)
									{
									aad='<div align="center"><font style="font-size:13px;" color="blue">Ваша скидка ';
									if (ddsc>0)
										{
										aad=aad+"<b>"+ddsc+"</b>";
										if (ddt[6]==1) aad=aad+" "+ddt[4]; else aad=aad+" %";
										}
									aad=aad+'<img src="/images/1px666699.gif" width="171" height="1"><br></div>';
									}
									else
									{
									aad='<div align="center"><font style="font-size:13px;color:#666699;">Ваша скидка</font></div>';
									}
								ptr.innerHTML=aad;
								} 
							
							}
						ptr=document.getElementById('tov_bsk_'+tov_id);if (ptr!=null) ptr.style.display="";
						ptr=document.getElementById('tov_tr_'+tov_id);if (ptr!=null) ptr.style.display="none";
	    					}
	    					else 
	    					{
						ptr=document.getElementById('tov_bsk_'+tov_id);if (ptr!=null) ptr.style.display="";
						ptr=document.getElementById('tov_tr_'+tov_id);if (ptr!=null) ptr.style.display="none";
	    					}
	   				}
	   				else
	   				{
					ptr=document.getElementById('tov_bsk_'+tov_id);if (ptr!=null) ptr.style.display="";
					ptr=document.getElementById('tov_tr_'+tov_id);if (ptr!=null) ptr.style.display="none";
	   				}
	   				
	   				
	   			}
	   		}
	   	catch (e)
	   		{
			ptr=document.getElementById('tov_bsk_'+tov_id);if (ptr!=null) ptr.style.display="";
			ptr=document.getElementById('tov_tr_'+tov_id);if (ptr!=null) ptr.style.display="none";
	   		}
   		}
  	req.send(null); 
	}

