function addToCart(id)
{
	var oXmlHttp = zXmlHttp.createRequest();
	var price = '';
	if (document.getElementById('dvd').checked) {
       price = document.getElementById('dvd').value;
	}
	oXmlHttp.open("get", '/ajax.php?s=buy&id='+id + '&price=' + price, true);
	oXmlHttp.onreadystatechange = function ()
   		{
    		if (oXmlHttp.readyState == 4)
      		{
       			if (oXmlHttp.status == 200)
         		{
	  				ShowResult( oXmlHttp.responseText);
	 			} 
     		}
  		}
	oXmlHttp.send(null);
}
var d1=null;
var d2=null;
function ShowResult(txt)
{
	BuildDlg();
	var p1=txt.indexOf('ERR:::::');
	var sh=false;
	if(p1!=-1)
	{
		d2.innerHTML='<div class="dlg_error">Ошибка</div>'+txt.substring(p1+8, txt.length)+'<div class="dlg_btn"><input type="button" onclick="HideDlg()" value="Закрыть" /></div>';
		sh = true;
	}else
	{
		p1=txt.indexOf('OK::::::');
		if(p1!=-1)
		{
			d2.innerHTML=txt.substring(p1+8, txt.length)+'<div class="dlg_btn"><input type="button" onclick="HideDlg()" value="Закрыть" /></div>';
			sh = true;
		}
	}
	if(sh)
	{
		d2.style.display='';
		d1.style.display='';
	}
}
function BuildDlg()
{
	var aps=getPageSize();
	d1=document.createElement('div');
/*	d1.style.width=(aps[0]+'px');
	d1.style.zIndex="1000";
	d1.style.height = (aps[5]+'px');
	d1.style.position = 'absolute';
	d1.style.display = 'none';
	d1.style.top = 0;
	d1.style.left = ((778-aps[0])/2)+'px';
	d1.style.backgroundImage = 'url(/template/images/overlay.png)';*/
	document.body.appendChild(d1);
	d2=document.createElement('div');
	d2.className='dialog';
	d2.style.position = 'absolute';
	d2.style.display = 'none';
	d2.style.zIndex="1001";
	d2.style.top = ((self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop))+20)+'px';
	d2.style.left = '200px';
	document.body.appendChild(d2);
}
function HideDlg()
{
	d2.style.display='none';
	d1.style.display='none';
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,xScroll,yScroll)
	return arrayPageSize;
}
function freeCart()
{
	document.getElementById('cart_action').value='free';
	document.getElementById('cart_form').submit();
}
function updateCart()
{
	document.getElementById('cart_action').value='refresh';
	document.getElementById('cart_form').submit();
}
function rmFromCart(id)
{
	document.getElementById('cart_action').value='del';
	document.getElementById('cart_id').value=id;
	document.getElementById('cart_form').submit();
}

