function setPrice(obj) {
	var real_price=0;
	if(_books_count) {
		var i=0;
		var price=0;
		var c=0;
		for(i=0;i<_books_count;i++) {
			var ch=document.getElementById('ch_'+i);
			if(ch&&ch!=undefined) {
				if(!ch.checked) {
					continue;
				}
				var p=ch.getAttribute("price");
				if(!p) {
					continue;
				}
				p=parseFloat(p);
				if(isNaN(p)) {
					continue;
				}
				
				price+=p;
				c++;
			}
		}
		real_price=price;
		document.getElementById("book_count").value=c;
		if(_promo_price>0) {
			document.getElementById("price").value=_promo_price;
			price=_promo_price;
		}
		else {
			var p=(price*_promo_percent/100).toFixed(2);
			
			price-=p;
			document.getElementById("price").value=price.toFixed(2);
		}
		
		var save=real_price-price;
		if(isNaN(save)||save<0) {
			save=0;
		}
		
		document.getElementById('save_price').innerHTML=save.toFixed(2);
	}
}

function checkItemsCount() {
	if(!_max_books_count) {
		_max_books_count=0;
	}
	var c=parseInt(document.getElementById("book_count").value);
	if(isNaN(c)) {
		c=999;
	}
	if(c!=_max_books_count) {
		alert("Моля, изберете точно "+_max_books_count+" книги!");
		return false;
	}	
	return true;
	
}


function getParentFormElement(elem) {
  form_obj = elem;
  while (form_obj.tagName!='FORM') {
    form_obj = form_obj.parentNode;
    if (!form_obj) {
      alert('Form not found! Please put the list control in a form!'); return 0;
    }
  }
  return form_obj;
}

function getForm(elem) {
	return getParentFormElement(elem);
}

function ADivButton(d){
  var col = d.getElementsByTagName('A');
  if(col.length>0){
    col[0].click();
  }
}

function getWinHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }


  //return [ scrOfX, scrOfY ];
  return myHeight;
}

function setLinks(obj1,obj2) {
	
	var d=document.getElementById(obj1);
	var l=document.getElementById(obj2);
	if(!l||l=='undefined') {
		d.style.display='none';
		return;
	}
	if((l.offsetTop+10)>getWinHeight()) {
		d.style.display='inline';
	}
	else {
		d.style.display='none';
	}
}