function getPageSize() {
	 var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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 = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

function basket_add(prod_id,quantity,redirect){
	if (prod_id > 0){
		if(quantity < 1){
			quantity = 1;
		}
		var url = 'EiFramework/Ajax/ajax_basket.asp';
		var date = new Date();
		date = date.getMinutes() +'' +date.getSeconds()
		var pars = 'q=' + quantity+'&p='+prod_id+'&d='+date;
		var org_pars =pars;
		var myXHR = new XHR({onSuccess:function(){
			if(!redirect){
				switch (this.response.text){
					case '#ATB#': 
					if(!$('decisionBox')){
						
						
						var box2 = new Element('div', {
							'class': 'decisionWrapper',
							'id': 'decisionWrapper'
						}).injectTop(document.body);
						
						var box = new Element('div', {
							'class': 'decisionBox',
							'id': 'decisionBox'
						}).injectTop(document.body);
						var a = getPageSize();
						$('decisionWrapper').setStyles({width:a[0],height:a[1]});
						var url = 'EiSP/decision_box.asp';
						setPosition();
						var myXHR = new XHR({onSuccess:function(){
							
							box.innerHTML=this.response.text;
							$$('#decisionBox #Login').addEvent('click', function(e){
								e = new Event(e).stop();
								var url = 'EiSP/decision_box_login.asp';
								var myXHR = new XHR({onSuccess:function(){
									box.innerHTML=this.response.text;
									var x = new EiJsValidate('form123');
								},method:'get',update:box}).send(url+'?'+pars);
							})
							
							$$('#decisionBox #Continue').addEvent('click', function(e){
								e = new Event(e).stop();
								var url = 'EiFramework/Ajax/ajax_basket_decision.asp';
								var myXHR = new XHR({onSuccess:function(){
									$('inBasket'+prod_id).innerHTML=this.response.text;
									$('decisionBox').remove();
									$('decisionWrapper').remove();
									showDropdowns();
								},method:'get',update:'inBasket'+prod_id}).send(url+'?'+pars);											 
							})
						},method:'get',async:true,update:box}).send(url+'?'+pars);
						}
					break;
					default:
						if(this.response.text.contains('##EiOutOfStock##')){
							var array = this.response.text.split('##EiOutOfStock##');
							$('inBasket'+prod_id).innerHTML=array[1];
							if(array[0]+'#'!='#'){
								alert(array[0]);
							}else{
								alert("Sorry, but we can't add more this product to the basket, because it is out of stock.");	
							}
						}else{
							$('inBasket'+prod_id).innerHTML=this.response.text;
						}
					break;
				}
				
			}
		},method:'get',async:true,update:$('inBasket'+prod_id)}).send(url+'?'+pars);
	}
	if(redirect){
		document.location.href='view_cart.asp';
	}
}
