// (C) Netlogic, 2003

function Createbase() {
	base = document.createElement('DIV');
	base.setAttribute('id', 'base');

	baseHeader = document.createElement('DIV');
	baseHeader.setAttribute('id', 'baseHeader');
	baseHeader.setAttribute('class', 'direct');

	baseBody   = document.createElement('DIV');
	baseBody.setAttribute('id', 'baseBody');

	baseFooter = document.createElement('DIV');
	baseFooter.setAttribute('id', 'baseFooter');

	baseBody.innerText = 'base';

	base.appendChild(baseHeader);
	base.appendChild(baseBody);
	base.appendChild(baseFooter);

	base.onmouseover   = function(e) { this.style.filter = "Alpha(Opacity='100')"; this.style.cursor = 'pointer'; this.style.MozOpacity = '1';}
	base.onmouseout    = function(e) { this.style.filter = "Alpha(Opacity='75')";  this.style.cursor = 'auto'; this.style.MozOpacity = '0.75'; }
	base.onselectstart = function(e) { return false; }
	base.onclick       = function(e) { this.style.display = 'none'; }

	document.body.appendChild(base);

	window.onresize      = function(e) { document.getElementById('base').style.display = 'none'; }
}

function Showbase(i) {
	base = document.getElementById('base');

	document.getElementById('baseBody').innerHTML = i.getAttribute('notice') && i.getAttribute('notice').length ? i.getAttribute('notice') : 'ERROR';
	base.style.display = 'block';

	var xleft=0;
	var xtop=0;
	o = i;

	do {
		xleft += o.offsetLeft;
		xtop  += o.offsetTop;

	} while (o=o.offsetParent);

	xwidth  = i.offsetWidth  ? i.offsetWidth  : i.style.pixelWidth;
	xheight = i.offsetHeight ? i.offsetHeight : i.style.pixelHeight;

	bwidth =  base.offsetWidth  ? base.offsetWidth  : base.style.pixelWidth;

	w = window;

	xbody  = document.compatMode=='CSS1Compat' ? w.document.documentElement : w.document.body;
	dwidth = xbody.clientWidth  ? xbody.clientWidth   : w.innerWidth;
	bwidth = base.offsetWidth ? base.offsetWidth  : base.style.pixelWidth;

	flip = !(xwidth - 10 + xleft + bwidth < dwidth);

	base.style.top  = xheight - 10 + xtop + 'px';
	base.style.left = (xleft + xwidth - (flip ? bwidth : 0)  - 25) + 'px';

	document.getElementById('baseHeader').className = flip ? 'baseHeaderFlip' : 'baseHeaderDirect';

	i.focus();
	return false;
}

function submitBasket(prizn) {
	if(prizn==1) {
	var prizn_str=document.getElementsByTagName("input");
	var checksum=0;
	checksum=checksum+0;  	
		for(var i=0;i<prizn_str.length;i++) {
		  if(prizn_str[i].className=='prizn') {
			if ( !isNaN( parseInt(prizn_str[i].value))) {
				checksum +=parseInt(prizn_str[i].value);
			} 
		  }
		}
		if(checksum==0) {
		  alert('Необходимо указать количество товара для заказа.');
		  return false;
		}
	}
	document.forms.prodForm.submit();		
}

function submitBasket_common(id,prizn) {
	if(prizn==1) {
	var prizn_str=document.getElementsByTagName("input");
	var checksum=0;
	checksum=checksum+0;
		for(var i=0;i<prizn_str.length;i++) {
		  if(prizn_str[i].className=='prizn '+id) {
			if ( !isNaN( parseInt(prizn_str[i].value))) {
				checksum +=parseInt(prizn_str[i].value);
			} 
		  }
		}
		if(checksum==0) {
		  alert('Необходимо указать количество товара для заказа.');
		  return false;
		}
	}
	document.getElementById('prodForm_'+id).submit();
}

function isNumberKey(evt){
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57))
  return false;

 return true;
}

var d = document;
function openPrizn(what) {
	d.getElementById("mainMessageWindow").style.filter = "alpha(opacity=40)";
	d.getElementById("mainMessageWindow").style.opacity = 0.4;
	d.getElementById("mainMessageWindow").style.display = "block";
	d.getElementById("mainMessageWindow").style.height = getDocumentHeight()+'px';
	d.getElementById(what).style.display="block";
}

function closePrizn(what) {
  d.getElementById("mainMessageWindow").style.display = "none";
  d.getElementById(what).style.display='none';
}

var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf('opera')  > -1);
var isIE = (!isOpera && ua.indexOf('msie') > -1);
	 
function getDocumentHeight() {
  return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight, getViewportHeight());
}
 
function getViewportHeight() {
  return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
}