var d = document;
var winIE = (navigator.userAgent.indexOf('Opera')==-1 && (d.getElementById && d.documentElement.behaviorUrns)) ? true : false;
function bodySize(){
if(winIE && d.documentElement.clientWidth) {
		sObj = d.getElementsByTagName('body')[0].style;
		wid = d.documentElement.clientWidth;
		sObj.width = (d.documentElement.clientWidth<1000) ? "1000px" : "100%";
	}
}
function init(){
	if(winIE) { bodySize(); }
}
onload = init;

if(winIE) { onresize = bodySize; }

		var wnd;
		function popup(url) {
			wnd=window.open(url,'Акция','height=686,width=794');
			if (window.focus) {wnd.focus()}
		}
		function frm_chk() {
			
			if (!$('name').value) {
				alert('Ошибка: Вы не указали имя!')
				return false;
			}
			
			if (!$('address').value) {
				alert('Ошибка: Вы должны указать Ваш адрес!')
				return false;
			}

			if (!$('email').value && !$('phone').value) {
				alert('Ошибка: Вы должны указать Ваши контактные данные!')
				return false;
			}			
			
			return true;
		}

	function compare(action,id){
		$ajax=new Ajax.Request('/compare/'+action+'/'+id+'/', {
  				method: 'get',
  			onComplete: function(req) {
  				
  				var item=document.getElementById("t"+id);
  				//alert(req.responseText);
  				if (req.responseText>0) {
					item.checked=!item.checked;
					getCompareList();
				} else {
					alert('Ошибка: выбрано слишком много товаров для сравнения.');
				}
  			}
		});
		
		return false;
	}	
	
	function clearCompare() {
		new Ajax.Request('/compare/clear');
		document.location=window.location.href;
		//return false;
	}
	
	function del_from_compare(id){
		new Ajax.Request('/compare/del/'+id+'/', {
			method:'get',
			onSuccess: function(transport){
				var response = transport.responseText;
				if (response==2) {
					document.location='?'+Math.random();
				}
			}
		});
	}
	
	function getCompareList() {
		new Ajax.Request('/compare/get/', {
			method:'get',
			onSuccess: function(transport){
				var response = transport.responseText;
				if (response) {
					$('compare-list').innerHTML=response;
					$('compare-list-wrap').show();
				} else $('compare-list-wrap').hide();
			}
		});
	}