//================= COMMON ===================
function getPosition(x) {
 var w = 0;
 var h = 0;
 var l = 0;
 var t = 0;
 if(x) {
   w = x.offsetWidth;
   h = x.offsetHeight;
   while (x) {
        l += x.offsetLeft;
        t += x.offsetTop;
        x = x.offsetParent;
   }
 }
 return {"left":l, "top":t, "width": w, "height":h};
}

function round2(v) {
 var wi = Math.floor(v);
 var wf = Math.round((v - wi) * 100, 2);
 var r = wi + wf / 100;
 return r;
}

function pause() {
var p = 0;
	while(!document.getElementById){
		p++;
		timeout(5);
	}
//	alert(p);
}
function timeout(aMs) {
 var t_out = window.setTimeout(pause, aMs);
}
/////////////////////////////////////////////////////////////////////////////////
var ct_out = 0;
var oO;
var ovid = '';
var ogid = '';
var omode = 'R';

function tooltipShow() {
 var vobj = document.getElementById(ovid);
 if(vobj) {
   var elem = document.getElementById(ogid);
//   var pos = getPosition(elem);
   var pos = getPosition(oO);
   
   var w = pos.width;
   var l = pos.left;
   var t = pos.top;
   if(omode == 'R') {
	oX = l + w - 10 + 12;
	oY = t + 2;
   }
   else {
	oX = l - 208 + 1;
	oY = t + 2;
   }
	vobj.style.left = oX+'px';
	vobj.style.top = oY+'px';
	vobj.style.display='';
 }
}
function tooltipHide(vid) {
 var vobj = document.getElementById(vid);
 if(vobj) {
 	vobj.style.display = 'none';
 }
}

function g_over(x, vid, gid, mode) {
 oO = x;
 ovid = vid;
 ogid = gid;
 omode = mode;
 var vobj = document.getElementById(ogid);
 if(vobj) {
	x.style.cursor="pointer";
 	vobj.className = 'good_select';
	ct_out = window.setTimeout(tooltipShow, 10);
 }
}
 
function g_out(x, vid) {
 if(ct_out)
 	window.clearTimeout(ct_out);
 x.style.cursor="";
 var vobj = document.getElementById(ogid);
 if(vobj) {
 	vobj.className = 'good_noselect';
 }
 var vobj = document.getElementById(vid);
 if(vobj) {
 	vobj.style.display = 'none';
 }
}
/////////////////////////////////////// BASKET ////////////////////////////////////////
function oBask() {
  this.cDelete = 0;
};
oBask.prototype.changeCheck = function(aO) {
	var nm = aO.id.substring(0, 4);
	var bid = aO.id.substring(5, aO.id.length);
	var aid = '';
	
	if(aO.checked == true) {
		if(nm == 'mode') {
			aid = 'dele_' + bid;
			if(this.cDelete > 0)
				this.cDelete = this.cDelete - 1;
		}
		if(nm == 'dele') {
			aid = 'mode_' + bid;
			this.cDelete = this.cDelete + 1;
		}
		var aao = document.getElementById(aid);
		aao.checked = false;
	}
//alert(nm + ' - ' + bid + ' - ' + aO.id + ' - ' + aid);
//alert(aO.checked + ' ' + this.cDelete);
	if(aO.checked == false) {
		if(nm == 'dele') {
			aid = 'dele_' + bid;
			if(this.cDelete > 0)
				this.cDelete = this.cDelete - 1;
		}
		var aao = document.getElementById(aid);
		aao.checked = false;
	}
};


oBask.prototype.reCalc = function(aFID) {
//alert('reCalc - ' + aFID);
	if(this.cDelete > 0) {
		var rr_del = confirm("Подтверждаете удаление товара(ов) из корзины ?'");
		if(rr_del)	{
			return true;
			
//			var fo = document.getElementById(aFID);
//			if(fo)
//				fo.submit();
		}
		else
			return false;
	}
	else {
		return true;
//		var fo = document.getElementById(aFID);
//		if(fo)
//			fo.submit();
	}
};


/////////////////////////////////////////////////////////////////
// goods card for wholesale==========================================
function oMGood_w(aID, aNm, aCompl) {  // main good
  this.c_error1 = '<strong style="color: #FF6701; ">ОШИБКА: допустимое количество - ';
  this.c_error2 = 'шт.</strong>';
  this.id = aID;
  this.nm = aNm;
  this.compl = aCompl;
  
  this.dprice = 0.0;

  this.aColors = [];
  this.aSizes = [];
  this.aGoods = [];
  this.aStocks = [];
  
  this.errid = '';
  this.oerrid;

  this.cntid = '';
  this.ocntid;
  this.sumid = '';
  this.osumid;
  
};

oMGood_w.prototype.inputValid = function() {
	alert('iValid');
//	this.aGoods[this.aGoods.length] = aOG;
};

oMGood_w.prototype.addG = function(aOG) {
	this.aGoods[this.aGoods.length] = aOG;
};

oMGood_w.prototype.addC = function(aOC) {
//alert(aOC.nm);
	var sw = true;
	for (var n = 0; n < this.aColors.length; n++) {
		if(this.aColors[n]) {
// alert(this.aGoods[n].id);
		  	if(this.aColors[n].id == aOC.id) {
		  		sw = false;
				n = this.aColors.length;	
		  	}
		}
	}
	if(sw)
		this.aColors[this.aColors.length] = aOC;
};

oMGood_w.prototype.addS = function(aOS) {
//alert(aOS.nm);
	var sw = true;
	for (var n = 0; n < this.aSizes.length; n++) {
		if(this.aSizes[n]) {
// alert(this.aGoods[n].id);
		  	if(this.aSizes[n].id == aOS.id) {
		  		sw = false;
				n = this.aSizes.length;	
		  	}
		}
	}
	if(sw)
		this.aSizes[this.aSizes.length] = aOS;
};

oMGood_w.prototype.addST = function(aOST) {
//alert(aOST.cntID);
	this.aStocks[this.aStocks.length] = aOST;
};

oMGood_w.prototype.validInput = function() {
	var rr = true;
	if(this.compl == 0) {  // одиночный
		this.clrError();
		for (var n = 0; n < this.aStocks.length; n++) {
			if(this.aStocks[n]) {
				if(this.aStocks[n].cntI > this.aStocks[n].cnt) {
					
					rr = false;
					if(!this.aStocks[n].ocntID)
						this.aStocks[n].ocntID = document.getElementById(oSTn.cntID);
					this.aStocks[n].ocntID.style.color = "#FE0736";	
					if(!this.oerrid)
						this.oerrid = document.getElementById(this.errid);
					this.oerrid.innerHTML = this.c_error1 + this.aStocks[n].cnt + this.c_error2;	
				}
			}
		}
	}
	else {  			   // комплект	
//alert("2");
		for (var m = 0; m < this.aGoods.length; m++) {
			if(this.aGoods[m])	{		
				var oG = this.aGoods[m];
				oG.clrError();
				for (var n = 0; n < oG.aStocks.length; n++) {
					if(oG.aStocks[n]) {
						if(oG.aStocks[n].cntI > oG.aStocks[n].cnt) {
							rr = false;
							if(!oG.aStocks[n].ocntID)
								oG.aStocks[n].ocntID = document.getElementById(oSTn.cntID);
							oG.aStocks[n].ocntID.style.color = "#FE0736";	
							if(!oG.oerrid)
								oG.oerrid = document.getElementById(oG.errid);
							oG.oerrid.innerHTML = oG.c_error1 + oG.aStocks[n].cnt + oG.c_error2;	
						}
					}
				}
			}
		}
	}
	return rr;
};
oMGood_w.prototype.clrError = function() {
	if(!this.oerrid)
		this.oerrid = document.getElementById(this.errid);
	this.oerrid.innerHTML = "";	
	for (var n = 0; n < this.aStocks.length; n++) {
		if(this.aStocks[n]) {
			var oSTn = this.aStocks[n];
			if(!oSTn.ocntID)
				oSTn.ocntID = document.getElementById(oSTn.cntID);
			oSTn.ocntID.style.color = "#000000";	
		}
	}
};
oMGood_w.prototype.recalcTotall = function() {
	if(!this.ocntid)
		this.ocntid = document.getElementById(this.cntid);
	if(!this.osumid)
		this.osumid = document.getElementById(this.sumid);
	if(this.ocntid && this.osumid) {
		var kk = 0;
		for (var n = 0; n < this.aStocks.length; n++) {
			if(this.aStocks[n]) {
				kk += this.aStocks[n].cntI;
			}
		}
		this.ocntid.innerHTML =  kk;	
		this.osumid.innerHTML =  round2(kk * parseFloat(this.dprice));	
	}
		
};


oMGood_w.prototype.setInput = function(aOInp) {
//alert(aOInp.value);
	var rr = true;
	aOInp.style.color = "#000000";
	if(this.compl == 0) {  // одиночный
//alert("1");
//alert(this.aStocks.length);
		for (var n = 0; n < this.aStocks.length; n++) {
			if(this.aStocks[n]) {
// alert(this.aGoods[n].id);
				if(this.aStocks[n].cntID == aOInp.id) {
//alert(this.aStocks[n].gid);
					if(parseInt(aOInp.value) > this.aStocks[n].cnt) {
						rr = false;
						aOInp.style.color = "#FE0736";
					}
		  			this.aStocks[n].cntI = parseInt(aOInp.value);
			  	}
			}
		}
	this.recalcTotall();
	}
	else {  			   // комплект	
//alert("2");
		for (var m = 0; m < this.aGoods.length; m++) {
			if(this.aGoods[m])	{		
				var oG = this.aGoods[m];
				for (var n = 0; n < oG.aStocks.length; n++) {
					if(oG.aStocks[n]) {
// alert(this.aGoods[n].id);
						if(oG.aStocks[n].cntID == aOInp.id) {
//alert(oG.aStocks[n].gid);
							if(parseInt(aOInp.value) > oG.aStocks[n].cnt) {
								rr = false;
								aOInp.style.color = "#FE0736";
							}
		  					oG.aStocks[n].cntI = parseInt(aOInp.value);
			  			}
					}
				}
				oG.recalcTotall();
			}
		}
	}
	return rr;
};

function oStock_w(aGID, aCID, aSID, aCnt, aCntID) {
  this.gid = aGID;
  this.cid = aCID;
  this.sid = aSID;
  this.cnt = aCnt;
  this.cntID = aCntID;
  this.ocntID;
  
  this.cntI = 0;
};

function oColor_w(aID, aNm) {
  this.id = aID;
  this.nm = aNm;
};

function oSize_w(aSID, aNm) {
  this.id = aSID;
  this.nm = aNm;
};



// goods card ==========================================
function oMGood(aID, aNm, aCompl) {  // main good
  this.c_minus = '<strong style="color: #FF6701; ">-</strong>';
  this.c_dpoint = ':';
  this.c_sel = '<strong style="color: #FF6701; ">выберите</strong>';
  	
  this.id = aID;
  this.nm = aNm;
  this.compl = aCompl;
  
  this.dprice = 0.0;
  
  this.trcid = '';
  
//  this.clr_seldivid = '';
//  this.oclr_seldivid;
  this.clr_shdivid = '';
  this.oclr_shdivid = '';
  this.clr_shimgid = '';
  this.oclr_shimgid;  
  this.clr_tdselid = '';
  this.oclr_tdselid;
  this.clr_oselid = '';
  this.oclr_oselid;
  
  this.vcountid = '';
  this.ovcountid;
  this.gcountid = '';
  this.ogcountid;

  this.vsummid = '';
  this.ovsummid;
  this.gsummid = '';
  this.ogsummid;
  
  this.trerrid = '';
  this.otrerrid;
  this.tderrid = '';
  this.otderrid;
  
  this.zoomid = '';
  this.d22 = '';
  
  this.ittl = '';
  this.i2 = '';
  this.i3 = '';
  this.d2 = '';
  this.d3 = '';
  
  this.aColors = [];
  this.aGoods = [];
  
//  this.ii = 0;
};

oMGood.prototype.addG = function(aOG) {
	this.aGoods[this.aGoods.length] = aOG;
};
oMGood.prototype.addC = function(aOC) {
	this.aColors[this.aColors.length] = aOC;
};
oMGood.prototype.getGood = function(aGID) {
	var rr;
	for (var n = 0; n < this.aGoods.length; n++) {
		if(this.aGoods[n]) {
// alert(this.aGoods[n].id);
		  	if(this.aGoods[n].id == aGID) {
		  		var rr = this.aGoods[n];
				n = this.aGoods.length;	
		  	}
		}
	}
	return rr;
};
oMGood.prototype.getColor = function(aCID) {
	var rr;
	for (var n = 0; n < this.aColors.length; n++) {
		if(this.aColors[n]) {
// alert(this.aGoods[n].id);
		  	if(this.aColors[n].id == aCID) {
		  		var rr = this.aColors[n];
				n = this.aColors.length;	
		  	}
		}
	}
	return rr;
};
oMGood.prototype.getColorSet = function() {
	for (var n = 0; n < this.aColors.length; n++) {
		if(this.aColors[n]) {
// alert(this.aGoods[n].id);
		  	if(this.aColors[n].status == 1) {
		  		var rr = this.aColors[n];
				n = this.aColors.length;	
				return rr;
		  	}
		}
	}
};

oMGood.prototype.iniErrID = function(aTrID, aTdID) {
	this.trerrid = aTrID;
	this.otrerrid = document.getElementById(this.trerrid);
	this.tderrid = aTdID;
	this.otderrid = document.getElementById(this.tderrid);
};

oMGood.prototype.iniSizeTdSel = function(aGID, aTdID) {
	var g = this.getGood(aGID);
	g.seltdid = aTdID;
	g.oseltdid = document.getElementById(g.seltdid);
};
oMGood.prototype.iniSizeTdSel = function(aGID, aTdID) {
	var g = this.getGood(aGID);
	g.seltdid = aTdID;
	g.oseltdid = document.getElementById(g.seltdid);
};
oMGood.prototype.iniColorTdSel = function(aTdID) {
	this.clr_tdselid = aTdID;
	this.oclr_tdselid = document.getElementById(this.clr_tdselid);
};
oMGood.prototype.iniSizeOSel = function(aGID, aSelID) {
//alert(aSelID);	
	var g = this.getGood(aGID);
	g.selid = aSelID;
	g.oselid = document.getElementById(g.selid);
};
oMGood.prototype.iniColorOSel = function(aSelID) {
	this.clr_oselid = aSelID;
	this.oclr_oselid = document.getElementById(this.clr_oselid);
};

oMGood.prototype.iniVCount = function(aVCountID) {
	this.vcountid = aVCountID;
	this.ovcountid = document.getElementById(this.vcountid);
};

oMGood.prototype.iniGCount = function(aGCountID) {
	this.gcountid = aGCountID;
	this.ogcountid = document.getElementById(this.gcountid);
};

oMGood.prototype.iniVSumm = function(aVSummID) {
	this.vsummid = aVSummID;
	this.ovsummid = document.getElementById(this.vsummid);
};

oMGood.prototype.iniGSumm = function(aGSummID) {
	this.gsummid = aGSummID;
	this.ogsummid = document.getElementById(this.gsummid);
};


oMGood.prototype.setSizeColor = function(aGID) {
//pause();	
	if(!is_complect) {
		if(sizes_i.length == 1) {
//		pause();
			this.sizeSet(aGID, sizes_i[0]);
		}
	}
	if(colors_i.length == 1) {
//	pause();
		this.colorSet(colors_i[0]);
	}
};

//--------------------------------------  ERROR  -------------------------------------------------------	
oMGood.prototype.errorHide = function() {
 if(!this.otrerrid)
 	this.otrerrid = document.getElementById(this.trerrid);
 this.otrerrid.style.display = 'none';	
}

oMGood.prototype.errorShow = function(aTxt) {
 if(!this.otderrid)
 	this.otderrid = document.getElementById(this.tderrid);
 this.otderrid.innerHTML = aTxt;	
 if(!this.otrerrid)
 	this.otrerrid = document.getElementById(this.trerrid);
 this.otrerrid.style.display = '';	
}



//--------------------------------------  COLOR  -------------------------------------------------------	
oMGood.prototype.colorOver = function(aCID) {
 var c = this.getColor(aCID);
 if(c) {
 	if(!c.otdid)
 		c.otdid = document.getElementById(c.tdid);
 	var pos = getPosition(c.otdid);
 	c.otdid.style.cursor="pointer";
 	if(c.otdid.className != 'color_selected')
 		c.otdid.className = 'color_select';
 	var ww = document.getElementById('selcolorid');
 	ww.innerHTML = this.c_dpoint + " " + c.nm;

 	if(c.bsrc != '') {
 		if(!this.oclr_shdivid)	
 			this.oclr_shdivid = document.getElementById(this.clr_shdivid);
 		var oX = pos.left;
	 	var oY = pos.top;
 		var oW = pos.width;
	 	var oH = pos.height;
	
	 	oX = oX - 25;
 		oY = oY + 5 + oH;
	 	this.oclr_shdivid.style.left = oX+'px';
 		this.oclr_shdivid.style.top = oY+'px';
	 	this.oclr_shdivid.style.display = '';
	
	 	if(!this.oclr_shimgid)	
 			this.oclr_shimgid = document.getElementById(this.clr_shimgid);
// 	alert(c.bsrc);
	 	this.oclr_shimgid.src = c.bsrc;
 	}
 }
 else {
alert("Error - color"); 	
 }
}

oMGood.prototype.colorOut = function(aCID) {
//function color_out(x, vid, cvid) {
 var c = this.getColor(aCID);
 var ca = this.getColorSet();
 var ww = document.getElementById('selcolorid');
 if(ca) {
 	ww.innerHTML = this.c_dpoint + " " + ca.nm;
 }
 else {
 	ww.innerHTML = " " + this.c_minus + " " + this.c_sel;
 }
 if(!c.otdid)
 	c.otdid = document.getElementById(c.tdid);
 if(c.otdid.className != 'color_selected') {
 	c.otdid.className = 'color_noselect';
 }
 if(!this.oclr_shdivid)	
 	this.oclr_shdivid = document.getElementById(this.clr_shdivid);
 this.oclr_shdivid.style.display = 'none';
}

oMGood.prototype.colorDeselect = function() {
 var ww = document.getElementById('selcolorid');
 ww.innerHTML = " " + this.c_minus + " " + this.c_sel;
 for (var n = 0; n < this.aColors.length; n++) {
 	var c = this.aColors[n];
	c.status = 0;
	if(!c.otdid)
 		c.otdid = document.getElementById(c.tdid);
 	c.otdid.className = 'color_noselect';
	if(!c.oimgid)
 		c.oimgid = document.getElementById(c.imgid);
 	c.oimgid.src = '/image/px.gif';

//	if(!this.oclr_seldivid)	
// 		this.oclr_seldivid = document.getElementById(this.clr_seldivid);
// 	this.oclr_seldivid.style.display = 'none';
 }
}

oMGood.prototype.colorSelect = function(aCID) {
//function color_select(x, vid) {
 var c = this.getColor(aCID);
 if(!c.otdid)
 	c.otdid = document.getElementById(c.tdid);
 	
// var pos = getPosition(c.otdid);
 
 c.otdid.style.cursor="pointer";
 c.otdid.className = 'color_selected';

 if(!c.oimgid)
 	c.oimgid = document.getElementById(c.imgid);
 c.oimgid.src = '/image/button/selected.gif';
 
 
// if(!this.oclr_seldivid)
// 	this.oclr_seldivid = document.getElementById(this.clr_seldivid);
//	var oX = pos.left;
//	var oY = pos.top;
//	var oW = pos.width;
//	var oH = pos.height;
//	oX = oX + oW - 9;
//	oY = oY + oH - 10;
//	this.oclr_seldivid.style.left = oX+'px';
//	this.oclr_seldivid.style.top = oY+'px';
// 	this.oclr_seldivid.style.display = '';
}

oMGood.prototype.colorSet = function(aCID, aM) {
	clrError();
//alert(round2(1234.125));	
	if(aCID != 0) {
		var c = this.getColor(aCID);
		if(!c.status) {
			this.colorDeselect();
			c.status = 1;
			var ww = document.getElementById('selcolorid');
			ww.innerHTML = this.c_dpoint + " " + c.nm;
			this.colorSelect(aCID);
			if(!this.oclr_tdselid)
 				this.oclr_tdselid = document.getElementById(this.clr_tdselid);
			this.oclr_tdselid.innerHTML = c.nm;
	
			if(!this.oclr_oselid)
 				this.oclr_oselid = document.getElementById(this.clr_oselid);
			var es_opt = this.oclr_oselid.options;
			for(var k = 0; k < es_opt.length; k++) {
				if(es_opt[k].value == aCID) {
//		alert(es_opt[k].value);
					es_opt[k].selected = true;
				}
				else {
					es_opt[k].selected = false;
				}
			}
			if(aM == 'V')
				validStock(this.oclr_oselid, 'V');
///ZOOM//////////
			if(c.gimg != 0) {
				var i2 = c.gimg.toString() + '-8.jpg';	
				var i3 = c.gimg.toString() + '.jpg';	
				this.changeZoomImage('n', i2, i3, c.nm);
			}
				
		}
		else {
			this.colorUnSet(aM);
//			this.colorOver(aCID);
///ZOOM//////////
			if(c.gimg != 0) {
				this.changeZoomImage('d', '', '', '');
			}
		}
	}
	else {
		this.colorUnSet(aM);
//		this.colorOver(aCID);
	}
	this.summSet();
}

oMGood.prototype.colorUnSet = function(aM) {
	this.colorDeselect();
	if(!this.oclr_tdselid)
		this.oclr_tdselid = document.getElementById(this.clr_tdselid);
	this.oclr_tdselid.innerHTML = '';
	
	if(!this.oclr_oselid)
		this.oclr_oselid = document.getElementById(this.clr_oselid);
	var es_opt = this.oclr_oselid.options;
	for(var k = 0; k < es_opt.length; k++) {
		if(es_opt[k].value == 0) {
//		alert(es_opt[k].value);
			es_opt[k].selected = true;
		}
		else {
			es_opt[k].selected = false;
		}
	}
	if(aM == 'V')
		validStock(this.oclr_oselid, 'V');
}

oMGood.prototype.changeZoomImage = function(aM, aI2, aI3, aTtl) {
   var zoom = document.getElementById(this.zoomid);   //get the reference to our zoom object
   if(zoom) {
       if(aM != 'd') {
           zoom.title = aTtl; //change the small image
           MagicZoomPlus.update(zoom,'/' + this.d22 + aI3,'/' + this.d22 + aI2);
       }
       else {
           zoom.title = this.ittl; //change the small image
           MagicZoomPlus.update(zoom,'/' + this.d3 + this.i3,'/' + this.d2 + this.i2);

       }
   }
}

oMGood.prototype.OchangeZoomImage = function(aM, aI2, aI3, aTtl) {
    var zoom = document.getElementById(this.zoomid);   //get the reference to our zoom object
    if(zoom) {
    	if(aM != 'd') {
    		zoom.href = '/' + this.d22 + aI3; //change the big image
    		zoom.firstChild.src = '/' + this.d22 + aI2; //change the small image
    		zoom.title = aTtl; //change the small image
    	}
    	else {
//alert('/' + this.d3 + this.i3);    		
    		zoom.href = '/' + this.d3 + this.i3; //change the big image
    		zoom.firstChild.src = '/' + this.d2 + this.i2; //change the small image
    		zoom.title = this.ittl; //change the small image
    		
// TEST
/*
for(var prop in MagicZoomPlus) {
	alert('MagicZoomPlus[' + prop + '] = ' + MagicZoomPlus[prop]);
	alert("type =" + typeof prop);
	if(typeof prop == 'Object' ) {
		alert("OBJ");
	}
}
for(var pr in MagicZoomPlus.options) {
	alert('MagicZoomPlus.option[' + pr + '] = ' + MagicZoomPlus.options[pr]);
}
*/
// TEST    		
    	}
    	// refresh ALL zooms on the page
    	MagicZoomPlus.refresh();
    }
}


//--------------------------------------  SIZE  -------------------------------------------------------	
oMGood.prototype.sizeOver = function(aGID, aSID) {
 var g = this.getGood(aGID);	
 var s = g.getS(aSID);
 var tda = document.getElementById(s.tdid);
 if(s.otdid) {
 	s.otdid.style.cursor="pointer";
	if(s.otdid.className != 'size_selected')
 		s.otdid.className = 'size_select';
 }
}
oMGood.prototype.sizeOut = function(aGID, aSID) {
 var g = this.getGood(aGID);	
 var s = g.getS(aSID);
 if(s.otdid) {
 	s.otdid.style.cursor="";
	if(s.otdid.className != 'size_selected')
 		s.otdid.className = 'size_noselect';
 }
}
oMGood.prototype.sizeSelect = function(aGID, aSID) {
 var g = this.getGood(aGID);	
 var s = g.getS(aSID);
// if(s.otdid && s.odivsel) {
 if(s.otdid) {
//var pos = getPosition(s.otdid);
	s.otdid.style.cursor="pointer";
 	s.otdid.className = 'size_selected';
 	
//	var oX = pos.left;
//	var oY = pos.top;
//	var oW = pos.width;
//	var oH = pos.height;
//	oX = oX + oW - 9;
//	oY = oY + oH - 10;
//	s.odivsel.style.left = oX+'px';
//	s.odivsel.style.top = oY+'px';
// 	s.odivsel.style.display = '';
 }
}
oMGood.prototype.sizeDeselect = function(aGID) {
 var g = this.getGood(aGID);
 var ww = document.getElementById('selsizeid_' + aGID);
 ww.innerHTML = " " + this.c_minus + " " + this.c_sel;
 for (var n = 0; n < g.aSizes.length; n++) {
 	var s = g.aSizes[n];
	s.otdid.className = 'size_noselect';
	s.status = 0;
// 	if(!s.odivsel)
//	 	s.odivsel = document.getElementById(s.divsel);
// 	s.odivsel.style.display = 'none';
 }
}
oMGood.prototype.sizeSet = function(aGID, aSID, aM) {
	clrError();
	var g = this.getGood(aGID);
	if(aSID != 0) {
	var s = g.getS(aSID);
//alert(s.status);	
	if(!s.status) {
		this.sizeDeselect(aGID);
		s.status = 1;
		var ww = document.getElementById('selsizeid_' + aGID);
		ww.innerHTML = this.c_dpoint;
		this.sizeSelect(aGID, aSID);
		g.oseltdid.innerHTML = s.nm + " - ";
//alert(s.status);	
//alert(g.oselid.id);
		if(!g.oselid)
			g.oselid = document.getElementById(g.selid);
		var es_opt = g.oselid.options;
		for(var k = 0; k < es_opt.length; k++) {
			if(es_opt[k].value == aSID) {
				es_opt[k].selected = true;
			}
			else {
				es_opt[k].selected = false;
			}
		}
		if(aM == 'V')
			validStock(g.oselid, 'V');
	}
	else {
		this.sizeUnSet(aGID, aM);
	}
	}
	else {
		this.sizeUnSet(aGID, aM);
	}
	this.summSet();
}
oMGood.prototype.sizeUnSet = function(aGID, aM) {
	var g = this.getGood(aGID);
		this.sizeDeselect(aGID);
		g.oseltdid.innerHTML = '';
//alert(g.selid);	
//alert(g.oselid.id);
		if(!g.oselid)
			g.oselid = document.getElementById(g.selid);
		var es_opt = g.oselid.options;
		for(var k = 0; k < es_opt.length; k++) {
			if(es_opt[k].value == 0) {
				es_opt[k].selected = true;
			}
			else {
				es_opt[k].selected = false;
			}
		}
		if(aM == 'V')
			validStock(g.oselid, 'V');
}
//================================= COUNT ===================
oMGood.prototype.countSet = function(aCnt, aM) {
	clrError();
	if(!this.ovcountid)
			this.ovcountid = document.getElementById(this.vcountid);
//	var vcount = this.ovcountid.value;
	this.ovcountid.value = aCnt;
	if(!this.ogcountid)
			this.ogcountid = document.getElementById(this.gcountid);
	this.ogcountid.value = aCnt;
	this.summSet();
	if(aM == 'V')
		validStock(this.ogcountid, 'V');
}

oMGood.prototype.summSet = function() {
	var szSet = true;
	var clSet = true;
	var cntSet = 0;
	var smmSet = 0.0;
//alert(this.aGoods.length);
	if(!this.ovcountid)
			this.ovcountid = document.getElementById(this.vcountid);
	cntSet = this.ovcountid.value;
	smmSet = round2(this.dprice * cntSet);
	
//alert(szSet + "-" + clSet + "-" + cntSet);	
	if(!this.ovsummid)
			this.ovsummid = document.getElementById(this.vsummid);
	this.ovsummid.innerHTML = smmSet;
	
	cntSet = getGCount();		
	smmSet = round2(this.dprice * cntSet);
	if(!this.ogsummid)
			this.ogsummid = document.getElementById(this.gsummid);
	this.ogsummid.innerHTML = smmSet;		
}


function oGood(aID, aNm, aTrID) {  // good
  this.id = aID;
  this.nm = aNm;
//  this.trid = aTrID;
//  this.otrid = document.getElementById(this.trid);
  this.selid = '';
  this.oselid;
  this.aSizes = [];
  this.aStocks = [];
};
oGood.prototype.addC = function(aOC) {
	this.aColors[this.aColors.length] = aOC;
};
oGood.prototype.addS = function(aOS) {
	this.aSizes[this.aSizes.length] = aOS;
};
oGood.prototype.addSt= function(aOSt) {
	this.aStocks[this.aStocks.length] = aOSt;
};
oGood.prototype.getS= function(aSID) {
//alert(this.aSizes.length);
	for (var n = 0; n < this.aSizes.length; n++) {
		if(this.aSizes[n]) {
 //alert(this.aSizes[n].id);
		  	if(this.aSizes[n].id == aSID) {
		  		var rr = this.aSizes[n];
				n = this.aSizes.length;	
				return rr;
		  	}
		}
	}
};

function oColor(aID, aNm, aBSrc, aGImg, aTdID, aImgID) {
  this.id = aID;
  this.nm = aNm;
  this.bsrc = aBSrc;
  this.gimg = aGImg;
  this.tdid = aTdID;
  this.otdid = document.getElementById(this.tdid);
  this.imgid = aImgID;
  this.oimgid = document.getElementById(this.imgid);
  this.status = 0;
};

function oSize(aSID, aNm, aTdID) {
//alert(aDivSel);	
  this.id = aSID;
  this.nm = aNm;
  this.status = 0;
  this.tdid = aTdID;
  this.otdid = document.getElementById(this.tdid);
  
//  this.seltdid = '';
//  this.oseltdid;
};

function oStock(aGID, aCID, aSID, aCnt) {
  this.gid = aGID;
  this.cid = aCID;
  this.sid = aSID;
  this.cnt = aCnt;
};

//============================FILTER for CATALOG =======================================
//**************************************************************************************
function oFLTR(aM, aFID, aTID, aSLID, aCLID, aBLID) {  
  this.mode = aM;
  this.tpid = aTID;
  this.fid = aFID;
  this.ofid = document.getElementById(this.fid);
  this.slid = aSLID;
  this.oslid = document.getElementById(this.slid);
  this.clid = aCLID;
  if(this.clid)
  	this.oclid = document.getElementById(this.clid);
  this.blid = aBLID;
  if(this.blid)
	  this.oblid = document.getElementById(this.blid);
  this.slist = '';
  this.clist = '';
  this.blist = '';
  this.aSZNs = [];
  
  this.aCLRs = [];
//  this.sCLRid = '';
//  this.tCLR = '';
//  this.hCLRid = '';
  
  this.aBRNs = [];
//  this.sBRNid = '';
//  this.tBRN = '';
//  this.hBRNid = '';
  
  this.fttip_id = '';
  this.fttip_o;
  this.filter_o;
  this.findic_id = '';
  this.findic_o;
  this.fdata_id = '';
  this.fdata_o;
  
  
};

oFLTR.prototype.Go = function() {
 this.getSzSet();
 this.getClSet();
 this.getBrSet();
 var ret = false;
//alert(this.slist.length) ;
 var sret = false;
 if(this.slist.length > 0)	{	 
// 	if(!this.ofid) 
// 		this.ofid = document.getElementById(this.fid);
// 	if(this.ofid) 	{
		if(!this.oslid) 
 			this.oslid = document.getElementById(this.slid);
 		if(this.oslid) 	{
 			this.oslid.value = this.slist;
 		}
//alert('go> ' + ss );
		sret = true;	
 }
 var cret = false;
 if(this.clist.length > 0)	{	 
// 	if(!this.ofid) 
// 		this.ofid = document.getElementById(this.fid);
// 	if(this.ofid) 	{
		if(!this.oclid) 
 			this.oclid = document.getElementById(this.clid);
 		if(this.oclid) 	{
 			this.oclid.value = this.clist;
 		}
//alert('go> ' + ss );
		cret = true;	
 }
 var bret = false;
 if(this.blist.length > 0)	{	 
// 	if(!this.ofid) 
// 		this.ofid = document.getElementById(this.fid);
// 	if(this.ofid) 	{
		if(!this.oblid) 
 			this.oblid = document.getElementById(this.blid);
 		if(this.oblid) 	{
 			this.oblid.value = this.blist;
 		}
//alert('go> ' + ss );
		bret = true;	
 }
// if(sret || cret || bret)
 	ret = true;
// return ret; 
  	if(!this.ofid)	
  		this.ofid = document.getElementById(this.fid);
  	this.ofid.submit();	
 
}
oFLTR.prototype.overF = function(x) {
	this.filter_o = x;
	if(!this.fttip_o)
		this.fttip_o = document.getElementById(this.fttip_id);
	if(this.fttip_o) {
		var tpos = getPosition(x);	
	   	var w = tpos.width;
   		var l = tpos.left;
	   	var t = tpos.top;
		oX = l - 2 - this.fttip_o.offsetWidth;
		oY = t + 2;
		this.fttip_o.style.left = oX+'px';
		this.fttip_o.style.top = oY+'px';
		this.fttip_o.style.display='';	
    	x.onmousemove=positiontip;
	}
	
}
oFLTR.prototype.outFF = function(x) {
	x.style.cursor="";
	if(!this.fttip_o)
		this.fttip_o = document.getElementById(this.fttip_id);
	if(this.fttip_o) {
	this.fttip_o.style.display='none';	
	if(this.filter_o)
    	this.filter_o.onmousemove='';
	}
	
}
oFLTR.prototype.overFF = function(x) {
	x.style.cursor="pointer";
	if(this.filter_o)
    	this.filter_o.onmousemove='';
}
oFLTR.prototype.closeFF = function(x) {
	x.style.cursor="";
	if(this.fttip_o) {
		this.fttip_o.style.display='none';	
	}
}

/*
oFLTR.prototype.positiontip = function(e) {
	alert(this.tpid);
	if(!this.fttip_o)
		this.fttip_o = document.getElementById(this.fttip_id);
//	if(this.fttip_o)  {
		var tpos = getPosition(this.filter_o);	
   		var w = tpos.width;
   		var l = tpos.left;
   		var t = tpos.top;
		oX = l - 20;
		oY = t + 2 + e.clientY;
		this.fttip_o.style.left = oX+'px';
		this.fttip_o.style.top = oY+'px';
//	}
	
}
*/
function positiontip(e) {
//	alert(oCfilter.tpid);
	var ie=document.all && !window.opera;
	var ns6=document.getElementById && !document.all;
	if(!oCfilter.fttip_o)
		oCfilter.fttip_o = document.getElementById(oCfilter.fttip_id);
//	if(this.fttip_o)  {
		var tpos = getPosition(oCfilter.filter_o);	
   		var w = tpos.width;
   		var l = tpos.left;
   		var t = tpos.top;
		var oX = l - oCfilter.fttip_o.offsetWidth - 2;
//		oY = t + 2 + e.clientY;
    	var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;

//		oY = e.pageY;
		var oY = curY;
		oCfilter.fttip_o.style.left = oX+'px';
		oCfilter.fttip_o.style.top = oY+'px';
//	}
	
}
function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


oFLTR.prototype.getSzSet = function() {
	this.slist = '';
	for (var n = 0; n < this.aSZNs.length; n++) {
		oSZNn = this.aSZNs[n];
		if(oSZNn) {
			for (var m = 0; m < oSZNn.aSZs.length; m++) {
				oSZm = oSZNn.aSZs[m];
				if(oSZm) {
				  	if(oSZm.status == 1) {
				  		if(this.slist.length > 0)
					  		this.slist = this.slist + '~|~';
		  					this.slist = this.slist + oSZm.id.toString();
				  	}
				}
			}
		}
	}
//alert(this.slist);
};

oFLTR.prototype.getClSet = function() {
	this.clist = '';
	for (var m = 0; m < this.aCLRs.length; m++) {
		oCLm = this.aCLRs[m];
		if(oCLm) {
		  	if(oCLm.status == 1) {
		  		if(this.clist.length > 0)
			  		this.clist = this.clist + '~|~';
  				this.clist = this.clist + oCLm.id.toString();
		  	}
		}
	}
//alert(this.slist);
};

oFLTR.prototype.getBrSet = function() {
	this.blist = '';
	for (var m = 0; m < this.aBRNs.length; m++) {
		oBRm = this.aBRNs[m];
		if(oBRm) {
		  	if(oBRm.status == 1) {
		  		if(this.blist.length > 0)
			  		this.blist = this.blist + '~|~';
  				this.blist = this.blist + oBRm.id.toString();
		  	}
		}
	}
//alert(this.slist);
};

oFLTR.prototype.addSN = function(aOSN) {
	this.aSZNs[this.aSZNs.length] = aOSN;
};
oFLTR.prototype.getSZN = function(aSNID) {
	var rr;
	for (var n = 0; n < this.aSZNs.length; n++) {
		if(this.aSZNs[n]) {
		  	if(this.aSZNs[n].id == aSNID) {
		  		rr = this.aSZNs[n];
//alert(rr.id);	
				n = this.aSZNs.length;	
		  	}
		}
	}
	return rr;
};
/////////////
oFLTR.prototype.szOver = function(aSNID, aSID) {
 var szn = this.getSZN(aSNID);
 if(szn) {
	 var s = szn.getSz(aSID);	
	 if(s) {
		 if(!s.otdid)
 			s.otdid = document.getElementById(s.tdid);
 		s.otdid.style.cursor="pointer";
 		if(s.otdid.className != 'sizes_selected')
 			s.otdid.className = 'sizes_select';
	 }
 }
}

oFLTR.prototype.szOut = function(aSNID, aSID) {
 var szn = this.getSZN(aSNID);
 if(szn) {
	 var s = szn.getSz(aSID);	
	 if(s) {
		if(!s.otdid) 
 			s.otdid = document.getElementById(s.tdid);
 		if(s.otdid) {
 			s.otdid.style.cursor="";
		if(s.otdid.className != 'sizes_selected')
 			s.otdid.className = 'sizes_noselect';
 		}
	}
 }
}

oFLTR.prototype.szSelect = function(aS) {
 var s = aS;	
 if(!s.otdid) 
 	s.otdid = document.getElementById(s.tdid);
 if(s.otdid) {
 	s.otdid.className = 'sizes_selected';
 }
}
oFLTR.prototype.szDeselect = function(aS) {
 var s = aS;	
 if(!s.otdid) 
 	s.otdid = document.getElementById(s.tdid);
 if(s.otdid) {
	s.otdid.className = 'sizes_noselect';
 }
}
oFLTR.prototype.szSet = function(aSNID, aSID, aM) {
//alert(typeof aSNID);
 if(typeof aSNID == 'number') 	
	var szn = this.getSZN(aSNID);
 else
	var szn = aSNID;
 if(szn) {
	 var s = szn.getSz(aSID);	
	 if(s) {
		if(!s.status) {
			s.status = 1;
			this.szSelect(s);
 		}
 		else {
			s.status = 0;
			this.szDeselect(s);
 		}
 		this.getSzSet();
 		this.getClSet();
 		this.getBrSet();
//alert(this.tpid + "-" + this.slist + "-" + this.clist + "-" + this.blist ) 		
//	sz = x.value;
//	mr = '0';
//alert(tp + " - " + sz);
		if(aM == 1) {
			var srchb =  null;
			srchb =  new msgetContent();
			srchb.mode = 'HTML';
			srchb.ini('HTML', this.findic_id, this.fdata_id);
//alert("/filetrs.php?ch_mode=catalog&ch_parms=" + this.tpid + "~||~" + this.slist + "~||~" + this.clist + "~||~" + this.blist);
			srchb.run("/filters.php?ch_type=" + this.mode + "&ch_mode=size&ch_parms=" + this.tpid + "~||~" + this.slist + "~||~" + this.clist + "~||~" + this.blist);
//	srchb.run("/filters.php?ch_mode=catalog&ch_parms=11111");
		}
	}
 }
}

oFLTR.prototype.addBRNs = function(aBID, aSt, aCtrlID) {
	this.aBRNs[this.aBRNs.length] = new oBrn(aBID, aSt, aCtrlID);
};
oFLTR.prototype.brOver = function(aBID) {
	var brn = this.getBrn(aBID);	
	 if(brn) {
		 if(!brn.octrlid)
 			brn.octrlid = document.getElementById(brn.ctrlid);
 		brn.octrlid.style.cursor="pointer";
 		if(brn.octrlid.className != 'brand_selected')
 			brn.octrlid.className = 'brand_select';
	 }
}
oFLTR.prototype.brOut = function(aBID) {
	 var brn = this.getBrn(aBID);	
	 if(brn) {
		if(!brn.octrlid) 
 			brn.octrlid = document.getElementById(brn.ctrlid);
 		if(brn.octrlid) {
			if(brn.octrlid.className != 'brand_selected') {
 				brn.octrlid.className = 'brand_noselect';
			}
 		}
	}
}
oFLTR.prototype.brSelect = function(aB) {
 var brn = aB;	
 if(!brn.octrlid) 
 	brn.octrlid = document.getElementById(brn.ctrlid);
 if(brn.octrlid) {
 	brn.octrlid.className = 'brand_selected';
 }
}
oFLTR.prototype.brDeselect = function(aB) {
 var brn = aB;	
 if(!brn.octrlid) 
 	brn.octrlid = document.getElementById(brn.ctrlid);
 if(brn.octrlid) {
	brn.octrlid.className = 'brand_noselect';
 }
}
oFLTR.prototype.brSet = function(aBID, aM) {
//alert(typeof aSNID);
 var brn = this.getBrn(aBID);
 if(brn) {
		if(!brn.status) {
			brn.status = 1;
			this.brSelect(brn);
 		}
 		else {
			brn.status = 0;
			this.brDeselect(brn);
 		}
 		this.getSzSet();
 		this.getClSet();
 		this.getBrSet();
		if(aM == 1) {
			var srchb =  null;
			srchb =  new msgetContent();
			srchb.mode = 'HTML';
//	srchb.ini('HTML', this.sBRNid, this.tBRN, this.hBRNid);
			srchb.ini('HTML', this.findic_id, this.fdata_id);
//alert("/filetrs.php?ch_mode=catalog&ch_parms=" + this.tpid + "~||~" + this.slist + "~||~" + this.clist + "~||~" + this.blist);
			srchb.run("/filters.php?ch_type=" + this.mode + "&ch_mode=brand&ch_parms=" + this.tpid + "~||~" + this.slist + "~||~" + this.clist + "~||~" + this.blist);
//	srchb.run("/filters.php?ch_mode=catalog&ch_parms=11111");
		}
 }
}
oFLTR.prototype.getBrn = function(aBID) {
	var rr;
	for (var n = 0; n < this.aBRNs.length; n++) {
		if(this.aBRNs[n]) {
		  	if(this.aBRNs[n].id == aBID) {
		  		rr = this.aBRNs[n];
//alert(rr.id);	
				n = this.aBRNs.length;	
		  	}
		}
	}
	return rr;
};


oFLTR.prototype.addC = function(aOClr) {
	this.aCLRs[this.aCLRs.length] = aOClr;
};
oFLTR.prototype.addCLRs = function(aCID, aNm, aSt, aTdID, aTdIID, aTdSID) {
	this.aCLRs[this.aCLRs.length] = new oClr(aCID, aNm, aSt, aTdID, aTdIID, aTdSID);
};
oFLTR.prototype.clOver = function(aCID) {
	var clr = this.getClr(aCID);	
	 if(clr) {
		 if(!clr.otdid)
 			clr.otdid = document.getElementById(clr.tdid);
		 if(!clr.otdiid)
 			clr.otdiid = document.getElementById(clr.tdiid);
 		clr.otdiid.style.cursor="pointer";
 		if(clr.otdiid.className != 'colorsi_selected')
 			clr.otdiid.className = 'colorsi_select';
 		if(clr.otdid.className != 'colors_selected')
 			clr.otdid.className = 'colors_select';
//		clr.otdid.innerHTML = clr.nm;
	 }
}
oFLTR.prototype.clOut = function(aCID) {
	 var clr = this.getClr(aCID);	
	 if(clr) {
		if(!clr.otdid) 
 			clr.otdid = document.getElementById(clr.tdid);
		if(!clr.otdiid) 
 			clr.otdiid = document.getElementById(clr.tdiid);
 		if(clr.otdid) {
			if(clr.otdid.className != 'colors_selected') {
 				clr.otdid.className = 'colors_noselect';
//	 			clr.otdid.innerHTML = "&nbsp;";
			}
 		}
 		if(clr.otdiid) {
 			clr.otdiid.style.cursor="";
			if(clr.otdiid.className != 'colorsi_selected')
 				clr.otdiid.className = 'colorsi_noselect';
 		}
	}
}
oFLTR.prototype.clSelect = function(aC) {
 var clr = aC;	
 if(!clr.otdid) 
 	clr.otdid = document.getElementById(clr.tdid);
 if(!clr.otdiid) 
 	clr.otdiid = document.getElementById(clr.tdiid);
 if(!clr.otdsid) 
 	clr.otdsid = document.getElementById(clr.tdsid);
 if(clr.otdid && clr.otdiid && clr.otdsid) {
 	clr.otdid.className = 'colors_selected';
 	clr.otdiid.className = 'colorsi_selected';
 	clr.otdsid.src = '/image/button/selected.gif';
// 	clr.otdiid.style.opacity = 0.5;
//	clr.otdid.innerHTML = clr.nm;
 }
}
oFLTR.prototype.clDeselect = function(aC) {
 var clr = aC;	
 if(!clr.otdid) 
 	clr.otdid = document.getElementById(clr.tdid);
 if(!clr.otdiid) 
 	clr.otdiid = document.getElementById(clr.tdiid);
 if(!clr.otdsid) 
 	clr.otdsid = document.getElementById(clr.tdsid);
 if(clr.otdid && clr.otdiid && clr.otdsid) {
	clr.otdid.className = 'colors_noselect';
	clr.otdiid.className = 'colorsi_noselect';
	clr.otdsid.src = '/image/px.gif';
// 	clr.otdiid.style.opacity = 1;
 }
}
oFLTR.prototype.clSet = function(aCID, aM) {
//alert(typeof aSNID);
 var clr = this.getClr(aCID);
 if(clr) {
		if(!clr.status) {
			clr.status = 1;
			this.clSelect(clr);
 		}
 		else {
			clr.status = 0;
			this.clDeselect(clr);
 		}
 		this.getSzSet();
 		this.getClSet();
 		this.getBrSet();
//alert(this.tpid + "-" + this.slist + "-" + this.clist + "-" + this.blist ) 		
//	sz = x.value;
//	mr = '0';
//alert(tp + " - " + sz);
		if(aM == 1) {
			var srchb =  null;
			srchb =  new msgetContent();
			srchb.mode = 'HTML';
//	srchb.ini('HTML', this.sBRNid, this.tBRN, this.hBRNid);
			srchb.ini('HTML', this.findic_id, this.fdata_id);
//alert("/filetrs.php?ch_mode=catalog&ch_parms=" + this.tpid + "~||~" + this.slist + "~||~" + this.clist + "~||~" + this.blist);
			srchb.run("/filters.php?ch_type=" + this.mode + "&ch_mode=color&ch_parms=" + this.tpid + "~||~" + this.slist + "~||~" + this.clist + "~||~" + this.blist);
//	srchb.run("/filters.php?ch_mode=catalog&ch_parms=11111");
		}
 }
}
oFLTR.prototype.getClr = function(aCID) {
	var rr;
	for (var n = 0; n < this.aCLRs.length; n++) {
		if(this.aCLRs[n]) {
		  	if(this.aCLRs[n].id == aCID) {
		  		rr = this.aCLRs[n];
//alert(rr.id);	
				n = this.aCLRs.length;	
		  	}
		}
	}
	return rr;
};



function oSZN(aID, aSpID) {
  this.id = aID;
  this.spid = aSpID;
  if(aSpID) 
  	this.ospid = document.getElementById(this.spid);
  this.aSZs = [];
 
};
oSZN.prototype.addS = function(aOSz) {
	this.aSZs[this.aSZs.length] = aOSz;
};
oSZN.prototype.addSz = function(aSID, aNm, aSt, aTdID) {
	this.aSZs[this.aSZs.length] = new oSz(aSID, aNm, aSt, aTdID);
};
oSZN.prototype.getSz = function(aSID) {
	var rr;
	for (var n = 0; n < this.aSZs.length; n++) {
		if(this.aSZs[n]) {
		  	if(this.aSZs[n].id == aSID) {
		  		rr = this.aSZs[n];
//alert(rr.id);	
				n = this.aSZs.length;	
		  	}
		}
	}
	return rr;
};

oSZN.prototype.isSet = function() {
	var c = 0;
	for (var n = 0; n < this.aSZs.length; n++) {
		if(this.aSZs[n]) {
		  	if(this.aSZs[n].status == 1) {
		  		c++;
		  	}
		}
	}
	if(c > 0)
		return true;
	else	
		return false;
};


function oSz(aSID, aNm, aSt, aTdID) {
//alert(aDivSel);	
  this.id = aSID;
  this.nm = aNm;
  this.status = aSt;
  this.tdid = aTdID;
  this.otdid = document.getElementById(this.tdid);
};
function oClr(aCID, aNm, aSt, aTdID, aTdIID, aTdSID) {
//alert(aDivSel);	
  this.id = aCID;
  this.nm = aNm;
  this.status = aSt;
  this.tdid = aTdID;
  this.otdid = document.getElementById(this.tdid);
  this.tdiid = aTdIID;
  this.otdiid = document.getElementById(this.tdiid);
  this.tdsid = aTdSID;
  this.otdsid = document.getElementById(this.tdsid);
};

function oBrn(aBID, aSt, aCtrlID) {
//alert(aDivSel);	
  this.id = aBID;
  this.status = aSt;
  this.ctrlid = aCtrlID;
  this.octrlid = document.getElementById(this.ctrlid);
};


///////////////////////////////////////  from GOODS.PHP ////////////////////////////////////////////////
function mlCheckForLast () {
	if (document.getElementById) {
		var btns = document.getElementsByName('drop_kgood');
		for (var i = 0; i < btns.length; i ++) {
			btns[i].disabled = (btns.length == 1) ? true : false;
//alert(btns[i].id);			
		}
		var btns = document.getElementsByName('insert_kgood');
		for (var i = 0; i < btns.length; i ++) {
			if(i == 0) 
				btns[i].disabled = false;
			else
				btns[i].disabled = true;
//alert(btns[i].id);			
		}
///////////////////////// activ  complectation ////////////////////////////////////////////////////
		var tra = document.getElementById('tr_anch');
		if(tra) {
//alert("current " + tra.tagName);
			var trn = tra.nextSibling;
			if(trn) {
				var sw = 1;
				while(sw && trn) {
					if(trn.tagName && trn.tagName.toLowerCase() == 'tr' && trn.id.substr(0,8) == 'tr_kgood') {
//						alert("next " + trn.tagName + " " + trn.id.substr(0,8));
						var tr = trn;
						sw = 0;
					}
					trn = trn.nextSibling;
				}
			}
//alert("tr = " + tr.id);
			if(!fi)
				var first = true;
			var es_select = tr.getElementsByTagName('select');
			for(var m = 0; m < es_select.length; m++) {
				if(es_select[m].id == 'colorid') {
				  if(oMG) {	
					oMG.oclr_oselid = es_select[m];
					if(!first)
						oMG.colorSet(es_select[m].value, 'C');
				  }
//alert(es_select[m].value);					
				}
				if(es_select[m].id.substr(0,6) == 'sizeid') {
					var gid = es_select[m].id.substr(7,es_select[m].id.length - 7);
//alert(es_select[m].id + " " + es_select[m].id.length + " " + gid);
				  if(oMG) {	
					oMG.iniSizeOSel(gid, es_select[m].id);
					if(!first)
						oMG.sizeSet(gid, es_select[m].value, 'C');
				  }					
				}
//				m = es_select.length;
			}
			
			var es_input = tr.getElementsByTagName('input');
			for(var m = 0; m < es_input.length; m++) {
				if(es_input[m].id == 'gcount') {
				  if(oMG) {	
					oMG.ogcountid = es_input[m];
					if(!first)
						oMG.countSet(es_input[m].value, 'C');
				  }				}
			}
			
			if(first)
				fi = 1;
		}
/////////////////////////////////////////////////////////////////////////////
		
		
	}
}

function mlAddVal (btn) {
	if (document.getElementById) {
	clrError();
		var tr = btn;
		while (tr.tagName.toLowerCase() != 'table') {
			tr = tr.parentNode;
		}
		while (tr.tagName.toLowerCase() != 'tr') {
			tr = tr.parentNode;
		}
		
//		tr = document.getElementById('tr_kgood');
//alert(tr.parentNode.tagName);
		var tr_new = tr.cloneNode(true);
		var tra = document.getElementById('tr_anch');
		var tr_new = tr.parentNode.insertBefore(tr.cloneNode(true),tra.nextSibling);
///////////////////////////////////////////////////////////////////////////////////////////
//		oMG.ii = oMG.ii + 1;
		ii = ii + 1;
		
		var es_inp = tr_new.getElementsByTagName('input');
		for(var m = 0; m < es_inp.length; m++) {
			if(es_inp[m].id == 'gcount') {
//alert(es_inp[m].value);
				es_inp[m].value = "1";
				m = es_inp.length;
			}
		}
		
		tr_new.id = 'tr_kgood_' + ii;
//alert(tr_new.id);		
		var k = new kompl(tr_new);
		idata.addK(k);
		mlCheckForLast();
	}
}

function mlDropVal (btn) {
	if (document.getElementById) {
		var tr = btn;
		while (tr.tagName.toLowerCase() != 'table') {
			tr = tr.parentNode;
		}
		while (tr.tagName.toLowerCase() != 'tr') {
			tr = tr.parentNode;
		}
//alert(tr.id);
		idata.delR(tr);
		tr.parentNode.removeChild(tr);
		mlCheckForLast();
	}
}

function clrError () {
	for(var i = 0; i < idata.aKompl.length; i++) {
		var Ki = idata.aKompl[i];
		if(Ki) {
			var es_td = Ki.row.getElementsByTagName('td');
			for(var m = 0; m < es_td.length; m++) {
				if(es_td[m].id == 'td_err') {
					es_td[m].innerHTML = "&nbsp;";
					m = es_td.length;
				}
			}
		}
	}
}
function getGoodName(aGID) {
	var rr = '';
	for(var i = 0; i < goods.length; i++) {
		if(goods[i][aGID]) {
			rr = goods[i][aGID];
			i < goods.length;
		}
	}
	return rr;
}
function validKInput (aM) {
	for(var i = 0; i < idata.aKompl.length; i++) {
		var cl_val_i = '';
		var cn_val_i = '';
		var sz_val_i = '';
		if(is_complect) {
			var gg_i = [];
			var gv_i = [];
		}
		var Ki = idata.aKompl[i];
		if(Ki) {
//alert("0 > " + Ki.row.id);
			var es_sel = Ki.row.getElementsByTagName('select');
			for (var j = 0; j < es_sel.length; j ++) {
				if(es_sel[j].name.substr(0,7) == 'colorid') {
					cl_val_i = es_sel[j].value;
//alert("1" + es_sel[j].name + '=' + cl_val);			
				}
				if(es_sel[j].name.substr(0,6) == 'sizeid') {
//var v = '';
					if(is_complect) {
						var b = es_sel[j].name.indexOf('[');
						var e = es_sel[j].name.indexOf(']');
						gg_i[gg_i.length] = es_sel[j].name.substring(b+1,e);
						gv_i[gv_i.length] = es_sel[j].value;
//for(var n = 0; n < gg.length; n++) {
//	v = v + " " + gg[n] + "=" + gv[n];
//}
					}
					else {
						sz_val_i = es_sel[j].value;;
//v = sz_val
					}
//alert("4 " + es_sel[j].name + " > " + v);
				}
			}
			var key_i = cl_val_i;
			if(is_complect) {
				for(var n = 0; n < gg_i.length; n++) {
					key_i = key_i + "_" + gg_i[n] + "_" + gv_i[n];
				}
			}
			else {
					key_i = key_i + "_" + sz_val_i;
			}
			
////////////////////////
			
			for(var m = 0; m < idata.aKompl.length; m++) {
				var cl_val_m = '';
				var cn_val_m = '';
				var sz_val_m = '';
				if(is_complect) {
					var gg_m = [];
					var gv_m = [];
				}
				var Km = idata.aKompl[m];
				var elf = null;
				if(Km && m != i) {
//alert("0 > " + Ki.row.id);
					var es_sel = Km.row.getElementsByTagName('select');
					for (var j = 0; j < es_sel.length; j ++) {
						if(es_sel[j].name.substr(0,7) == 'colorid') {
							cl_val_m = es_sel[j].value;
							elf = es_sel[j];
//alert("1" + es_sel[j].name + '=' + cl_val);			
						}
						if(es_sel[j].name.substr(0,6) == 'sizeid') {
//var v = '';
							if(is_complect) {
								var b = es_sel[j].name.indexOf('[');
								var e = es_sel[j].name.indexOf(']');
								gg_m[gg_m.length] = es_sel[j].name.substring(b+1,e);
								gv_m[gv_m.length] = es_sel[j].value;
//for(var n = 0; n < gg.length; n++) {
//	v = v + " " + gg[n] + "=" + gv[n];
//}
							}
							else {
								sz_val_m = es_sel[j].value;;
//v = sz_val
							}
//alert("4 " + es_sel[j].name + " > " + v);
						}
					}
					var key_m = cl_val_m;
					if(is_complect) {
						for(var n = 0; n < gg_m.length; n++) {
							key_m = key_m + "_" + gg_m[n] + "_" + gv_m[n];
						}
					}
					else {
						key_m = key_m + "_" + sz_val_m;
					}
//!!!!!!!!!!!!!!!!!!!!!!!!!!дублирование комплектации
					if(key_i == key_m)	{
						var es_td = Km.row.getElementsByTagName('td');
						for(var k = 0; k < es_td.length; k++) {
							if(es_td[k].id == 'td_err') {
								es_td[k].innerHTML = "<strong style=\"color:RED;\">ОШИБКА: Дублирование комплектации</strong>";
							  if(oMG) {	
								oMG.errorShow('<strong style="color:RED;">ОШИБКА: Дублирование комплектации</strong>');
							  }
								if(aM == 'C')
									elf.focus();
								k = es_td.length;
							}
						}
						return false;
					}
//!!!!!!!!!!!!!!!!!!!!!!!!!!дублирование комплектации
				}
			}
			
///////////////			
		}
	}
	return true;
}
function rendStock() {
	var str = '<p class="citem">Вы можете заказать:</p>';
	if(is_complect) {
    	for (var z=0; z<goods.length; z++) {
    		str += '<p><strong>'+goods[z][1]+'</strong><table class="tbl-info" border="0" cellpadding="2" cellspacing="1" width="100%">';
    	    str += '<tr align="center"><td width="40%">&nbsp;</td>';
	        for (var i=0; i<colors_i.length; i++) {
        		str += '<td>'+colors[colors_i[i]]+'</td>';
        	}
    	    str += '</tr>';
                
	        good_i = goods[z][0];
        	for (var j=0; j<sizes_j[good_i].length; j++) {
    	    	size_i = sizes_j[good_i][j];
	            str += '<tr><td>'+sizes[size_i]+'</td>';
            	for (var i=0; i<colors_i.length; i++) {
            		cnt = stock[good_i][colors_i[i]][size_i];
        	        str += '<td align="center" class="'+(cnt > 0 ? 'plus">+' : 'minus">продано')+'</td>';
    	        }
	            str += '</tr>';
        	}
        	str += '</table></p>';
    	}
	}
	else {
		str = '<table class="tbl-info" border="0" cellpadding="2" cellspacing="1" width="100%">';
        str += '<tr align="center"><td width="35%">&nbsp;</td>';
        for (var i=0; i<colors_i.length; i++) {
            str += '<td>'+colors[colors_i[i]]+'</td>';
        }
        str += '</tr>';
        for (var j=0; j<sizes_i.length; j++) {
			str += '<tr><td>'+sizes[sizes_i[j]]+'</td>';
            for (var i=0; i<colors_i.length; i++) {
            	cnt = stock[colors_i[i]][sizes_i[j]];
                str += '<td align="center" class="'+(cnt > 0 ? 'plus">+' : 'minus">продано')+'</td>';
            }
            str += '</tr>';
        }
        str += '</table>';
	}
    return str;
}

function getGCount() {
	var count = 0;
	for(var i = 0; i < idata.aKompl.length; i++) {
		var cn_val = '';
		var Ki = idata.aKompl[i];
		if(Ki) {
//alert("0 > " + Ki.row.id);
			var es_inp = Ki.row.getElementsByTagName('input');
			for (var j = 0; j < es_inp.length; j ++) {
				if(es_inp[j].name.substr(0,11) == 'goods_count') {
					count += parseInt(es_inp[j].value);
//alert("5 " + es_inp[j].name + "=" + cn_val);
				}
			}
		}
	}
	return count;
}


function validStock(o, aM) {
	clrError();
  if(oMG) {	
	oMG.errorHide();
  }
	var chng = o.name.substr(0,4);
////////////// set  GRAPHIC  //////////////////////////////////////////////////////////////////////
//alert(o.id);	
		if(o.id == "colorid") {
		  if(oMG) {	
			if(aM == 'C')
				oMG.colorSet(o.value, 'C');
		  }
		}
		if(o.id.substr(0,6) == 'sizeid') {
//					oMG.oclr_oselid = es_select[m];
			var gid = o.id.substr(7,o.id.length - 7);
//alert(es_select[m].id + " " + es_select[m].id.length + " " + gid);
			if(aM == 'C')
			  if(oMG) {	
				oMG.sizeSet(gid, o.value, 'C');								
			  }
		}
		if(o.id == "gcount") {
			if(aM == 'C')
			  if(oMG) {	
				oMG.countSet(o.value, 'C');
			  }
		}
		
		
////////////////////////////////////////////////////////////////////////////////////		
//alert("0 > " + chng);
	var cl_val = '';
	var cn_val = '';
	var sz_val = '';
	if(is_complect) {
		var gg = [];
		var gv = [];
	}
	if (document.getElementById) {
		var tr = o;
		while (tr.tagName.toLowerCase() != 'table') {
			tr = tr.parentNode;
		}
		while (tr.tagName.toLowerCase() != 'tr') {
			tr = tr.parentNode;
		}
		if(is_complect && chng == 'size') {
			while (tr.tagName.toLowerCase() != 'table') {
				tr = tr.parentNode;
			}
			while (tr.tagName.toLowerCase() != 'tr') {
				tr = tr.parentNode;
			}
		}
//////////////////////////////////////////////////////////////////////////////////////
//		alert(tr.id);
		if(tr) {
//alert("0 > " + Ki.row.id);
			var elf_1 = null;
			var elf_2 = null;
			var es_sel = tr.getElementsByTagName('select');
			for (var j = 0; j < es_sel.length; j ++) {
				if(es_sel[j].name.substr(0,7) == 'colorid') {
					cl_val = es_sel[j].value;
					elf_1 = es_sel[j];
					if(cl_val == '0') {
						var ser = "<strong style=\"color:RED;\">Выберите цвет</strong>";
						var es_td = tr.getElementsByTagName('td');
						for(var m = 0; m < es_td.length; m++) {
							if(es_td[m].id == 'td_err') {
								es_td[m].innerHTML = ser;
//								oMG.errorShow(ser);
								if(aM == 'C')
									es_sel[j].focus();
								m = es_td.length;
							}
						}
						return false;
					}
//alert("1" + es_sel[j].name + '=' + cl_val);			
				}
				if(es_sel[j].name.substr(0,6) == 'sizeid') {
					if(es_sel[j].value == '0') {
						var ser = "<strong style=\"color:RED;\">Выберите размер</strong>";
						var es_td = tr.getElementsByTagName('td');
						for(var m = 0; m < es_td.length; m++) {
							if(es_td[m].id == 'td_err') {
								es_td[m].innerHTML = ser;
//								oMG.errorShow(ser);
								if(aM == 'C')
									es_sel[j].focus();
								m = es_td.length;
							}
						}
						return false;
					}
//var v = '';
					if(is_complect) {
						var b = es_sel[j].name.indexOf('[');
						var e = es_sel[j].name.indexOf(']');
						gg[gg.length] = es_sel[j].name.substring(b+1,e);
						gv[gv.length] = es_sel[j].value;
//for(var n = 0; n < gg.length; n++) {
//	v = v + " " + gg[n] + "=" + gv[n];
//}
					}
					else {
						sz_val = es_sel[j].value;;
//v = sz_val
					}
//alert("4 " + es_sel[j].name + " > " + v);
				}
			}
			var es_inp = tr.getElementsByTagName('input');
			for (var j = 0; j < es_inp.length; j ++) {
				if(es_inp[j].name.substr(0,11) == 'goods_count') {
					cn_val = es_inp[j].value;
					elf_2 = es_inp[j];
					if(es_inp[j].value == '0') {
						var ser = "<strong style=\"color:RED;\">Введите количество</strong>";
						var es_td = tr.getElementsByTagName('td');
						for(var m = 0; m < es_td.length; m++) {
							if(es_td[m].id == 'td_err') {
								es_td[m].innerHTML = ser;
							  if(oMG) {	
								oMG.errorShow(ser);
							  }
								if(aM == 'C')
									es_inp[j].focus();
								m = es_td.length;
							}
						}
						return false;
					}
//alert("5 " + es_inp[j].name + "=" + cn_val);
				}
			}
//var tt = '';		
			if(is_complect)	{
//for(var n = 0; n < gg.length; n++) {
//	tt = tt + cl_val + "-" + gg[n] + "-" + gv[n] + "------------" + stock[gg[n]][cl_val][gv[n]] + " * ";
//}
//alert("complecn: " + tt + "=" + cn_val );
				for(var n = 0; n < gg.length; n++) {
					var er = 0;
					var ser = '';
					if(stock[gg[n]][cl_val][gv[n]] == 0) {
						er = 1;
						ser = 'К сожалению составляющей комплекта "' + getGoodName(gg[n]) + '" цвета "' + colors[cl_val] + '" в размере "' + sizes[gv[n]] + '" нет в наличии.';
						ser += rendStock();
						if(aM == 'C')
							elf_1.focus();
						n = gg.length;
					}
					else {
						if(stock[gg[n]][cl_val][gv[n]] < cn_val) {
							er = 1;
							ser = 'Доступные для заказа комбинации цвета/размера не более '+ stock[gg[n]][cl_val][gv[n]] + ' единиц комплектов';
							elf_2.value = stock[gg[n]][cl_val][gv[n]];
							if(aM == 'C')						
								elf_2.focus();
							n = gg.length;
						}
					}
				}
				if(er) {
					ser = "<strong style=\"color:RED;\">" + ser + "</strong>";
					var es_td = tr.getElementsByTagName('td');
					for(var m = 0; m < es_td.length; m++) {
						if(es_td[m].id == 'td_err') {
							es_td[m].innerHTML = ser;
						  if(oMG) {	
							oMG.errorShow(ser);
						  }
							m = es_td.length;
						}
					}
					return false;
				}
			}
			else {
				var er = 0;
				var ser = '';
//				if(stock[cl_val][sz_val] == 0) {
				if(!stock[cl_val][sz_val] || stock[cl_val][sz_val] == 0) {
					er = 1;
					ser = 'К сожалению цвета "' + colors[cl_val] + '" в размере "' + sizes[sz_val] + '" нет в наличии.';
					ser += rendStock();
					if(aM == 'C')						
						elf_1.focus();
				}
				else {
					if(stock[cl_val][sz_val] < cn_val) {
						er = 1;
						ser = 'Доступные для заказа комбинации цвета/размера не более '+ stock[cl_val][sz_val] + ' единиц(ы) товара';
//						elf_2.value = stock[cl_val][sz_val];
////////////////////////////////////////////////////////////////////////////////////////////////////////////
					  if(oMG) {	
						oMG.countSet(stock[cl_val][sz_val], 'C');
					  }
						if(aM == 'C')						
							elf_2.focus();
					}
				}
				if(er) {
					ser = "<strong style=\"color:RED;\">" + ser + "</strong>";
					var es_td = tr.getElementsByTagName('td');
					for(var m = 0; m < es_td.length; m++) {
						if(es_td[m].id == 'td_err') {
							es_td[m].innerHTML = ser;
						  if(oMG) {	
							oMG.errorShow(ser);
						  }
							m = es_td.length;
						}
					}
					return false;
				}
			}
		}
//		idata.delR(tr);
//		tr.parentNode.removeChild(tr);
//		mlCheckForLast();
	}
}

function validInput (aM) {
	clrError();
	for(var i = 0; i < idata.aKompl.length; i++) {
		var cl_val = '';
		var cn_val = '';
		var sz_val = '';
		if(is_complect) {
			var gg = [];
			var gv = [];
		}
		var Ki = idata.aKompl[i];
		if(Ki) {
//alert("0 > " + Ki.row.id);
			var elf_1 = null;
			var elf_2 = null;
			var es_sel = Ki.row.getElementsByTagName('select');
			for (var j = 0; j < es_sel.length; j ++) {
				if(es_sel[j].name.substr(0,7) == 'colorid') {
					cl_val = es_sel[j].value;
					elf_1 = es_sel[j];
					if(cl_val == '0') {
						var es_td = Ki.row.getElementsByTagName('td');
						for(var m = 0; m < es_td.length; m++) {
							if(es_td[m].id == 'td_err') {
								es_td[m].innerHTML = "<strong style=\"color:RED;\">ОШИБКА: Выберите цвет</strong>";
							  if(oMG) {	
								oMG.errorShow('<strong style="color:RED;">ОШИБКА: Выберите цвет</strong>');
							  }
								if(aM == 'C')						
									es_sel[j].focus();
								m = es_td.length;
							}
						}
						return false;
					}
//alert("1" + es_sel[j].name + '=' + cl_val);			
				}
				if(es_sel[j].name.substr(0,6) == 'sizeid') {
					if(es_sel[j].value == '0') {
						var es_td = Ki.row.getElementsByTagName('td');
						for(var m = 0; m < es_td.length; m++) {
							if(es_td[m].id == 'td_err') {
								es_td[m].innerHTML = "<strong style=\"color:RED;\">ОШИБКА: Выберите размер</strong>";
							  if(oMG) {	
								oMG.errorShow('<strong style="color:RED;">ОШИБКА: Выберите размер</strong>');
							  }
								if(aM == 'C')						
									es_sel[j].focus();
								m = es_td.length;
							}
						}
						return false;
					}
//var v = '';
					if(is_complect) {
						var b = es_sel[j].name.indexOf('[');
						var e = es_sel[j].name.indexOf(']');
						gg[gg.length] = es_sel[j].name.substring(b+1,e);
						gv[gv.length] = es_sel[j].value;
//for(var n = 0; n < gg.length; n++) {
//	v = v + " " + gg[n] + "=" + gv[n];
//}
					}
					else {
						sz_val = es_sel[j].value;;
//v = sz_val
					}
//alert("4 " + es_sel[j].name + " > " + v);
				}
			}
			var es_inp = Ki.row.getElementsByTagName('input');
			for (var j = 0; j < es_inp.length; j ++) {
				if(es_inp[j].name.substr(0,11) == 'goods_count') {
					cn_val = es_inp[j].value;
					elf_2 = es_inp[j];
					if(es_inp[j].value == '0') {
						var es_td = Ki.row.getElementsByTagName('td');
						for(var m = 0; m < es_td.length; m++) {
							if(es_td[m].id == 'td_err') {
								es_td[m].innerHTML = "<strong style=\"color:RED;\">ОШИБКА: Введите количество</strong>";
							  if(oMG) {	
								oMG.errorShow('<strong style="color:RED;">ОШИБКА: Введите количество</strong>');
							  }
								if(aM == 'C')						
									es_inp[j].focus();
								m = es_td.length;
							}
						}
						return false;
					}
//alert("5 " + es_inp[j].name + "=" + cn_val);
				}
			}
//var tt = '';		
			if(is_complect)	{
//for(var n = 0; n < gg.length; n++) {
//	tt = tt + cl_val + "-" + gg[n] + "-" + gv[n] + "------------" + stock[gg[n]][cl_val][gv[n]] + " * ";
//}
//alert("complecn: " + tt + "=" + cn_val );
				for(var n = 0; n < gg.length; n++) {
					var er = 0;
					var ser = '';
					if(stock[gg[n]][cl_val][gv[n]] == 0) {
						er = 1;
						ser = 'К сожалению составляющей комплекта "' + getGoodName(gg[n]) + '" цвета "' + colors[cl_val] + '" в размере "' + sizes[gv[n]] + '" нет в наличии.';
						ser += rendStock();
						if(aM == 'C')						
							elf_1.focus();
						n = gg.length;
					}
					else {
						if(stock[gg[n]][cl_val][gv[n]] < cn_val) {
							er = 1;
							ser = 'Доступные для заказа комбинации цвета/размера не более '+ stock[gg[n]][cl_val][gv[n]] + ' единиц комплектов';
							elf_2.value = stock[gg[n]][cl_val][gv[n]];
							if(aM == 'C')						
								elf_2.focus();
							n = gg.length;
						}
					}
				}
				if(er) {
					var es_td = Ki.row.getElementsByTagName('td');
					for(var m = 0; m < es_td.length; m++) {
						if(es_td[m].id == 'td_err') {
							es_td[m].innerHTML = "<strong style=\"color:RED;\">" + ser + "</strong>";
						  if(oMG) {	
							oMG.errorShow('<strong style="color:RED;">' + ser + '</strong>');
						  }
							m = es_td.length;
						}
					}
					return false;
				}
			}
			else {
				var er = 0;
				var ser = '';
				if(stock[cl_val][sz_val] == 0) {
					er = 1;
					ser = 'К сожалению цвета "' + colors[cl_val] + '" в размере "' + sizes[sz_val] + '" нет в наличии.';
					ser += rendStock();
					if(aM == 'C')						
						elf_1.focus();
				}
				else {
					if(stock[cl_val][sz_val] < cn_val) {
						er = 1;
						ser = 'Доступные для заказа комбинации цвета/размера не более '+ stock[cl_val][sz_val] + ' единиц(ы) товара';
//						elf_2.value = stock[cl_val][sz_val];
////////////////////////////////////////////////////////////////////////////////////////////////////////////
					  if(oMG) {	
						oMG.countSet(stock[cl_val][sz_val]);						
					  }
						if(aM == 'C')						
							elf_2.focus();
					}
				}
				if(er) {
					var es_td = Ki.row.getElementsByTagName('td');
					for(var m = 0; m < es_td.length; m++) {
						if(es_td[m].id == 'td_err') {
							es_td[m].innerHTML = "<strong style=\"color:RED;\">" + ser + "</strong>";
						  if(oMG) {	
							oMG.errorShow('<strong style="color:RED;">' + ser + '</strong>');
						  }
							m = es_td.length;
						}
					}
					return false;
				}
			}
		}
	}
	if(validKInput (aM))
		return true;
	else
		return false;
}
function add2Personal () {
    if (validInput()) {
	    var the_frm = document.forms['frm_basket'];
    	document.getElementById('add2basket').value = 'personal';
        the_frm.submit();
    }
}

function kompl(rw) {
this.row = rw;
};

function inp(c) {
this.compl = c;
this.aKompl = [];
//alert(this.compl);
};

inp.prototype.addK = function(ok) {
	this.aKompl[this.aKompl.length] = ok;
};
inp.prototype.delR = function(or) {
	for(var i = 0; i < idata.aKompl.length; i++) {
		var Ki = idata.aKompl[i];
		if(Ki && Ki.row.id == or.id)
		 delete idata.aKompl[i];
//	alert(Ki.row.id);
	}
};

//+++++++++++++++++++++++   MSGETCONTENT   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//********* begin *****  
msREADY_STATE_UNINITIALIZED=0;
msREADY_STATE_LOADING=1;
msREADY_STATE_LOADED=2;
msREADY_STATE_INTERACTIVE=3;
msREADY_STATE_COMPLETE=4;

msgetContent=function(){
//  this.mid='groups';
//  this.id='groups';
//  this.vv='';
  var mode='';
  var mid='';
  var hid='';
  var p='';
  var vv='';
  var omid ;
  var ohid ;
  var owin ;
//  var uurl ;
  
  this.req=null;
  this.onload=this.FromNet;
  this.onerror=this.defaultError;
  this.toContent=this.ToContent;
//  this.ContentLoader(url,null,null,'application/x-www-form-urlencoded; text/xml; charset=windows-1251');
//  this.ContentLoader(url,null,null,'application/x-www-form-urlencoded; text/html; charset=windows-1251');
}

msgetContent.prototype.ini=function(m0, id1, id2) {
	this.mode = m0;
	this.mid = id1;
	this.hid = id2;
  	this.onload=this.FromNet;
  	this.onerror=this.defaultError;
}
msgetContent.prototype.run=function(url) {
//	this.uurl = url;
	switch(this.mode) {
	  case 'HTML':
	    if(this.mid != '')
  			this.omid =  document.getElementById(this.mid);
	    if(this.hid != '')
  			this.ohid =  document.getElementById(this.hid);
//	  	alert(url);
	  break;	
	}
  	this.ContentLoader(url,null,null,'application/x-www-form-urlencoded; text/xml; charset=windows-1251');
};

msgetContent.prototype.FromNet=function() {
	this.omid.src = '/image/px.gif';
//  this.omid.innerHTML = '';
  if(this.req.responseTEXT) {
//alert("AAAAAA");  
	this.vv = this.req.responseTEXT;
  }
  else {
  	if(this.req.responseXML) {
//alert("BBBBB");  
		this.vv = this.XmlToString(this.req.responseXML);
//alert(this.vv);		
  	}
  }
//  alert(this.vv);
//  this.ToContent();
  this.toContent();
};


msgetContent.prototype.ToContent=function() {
//  alert(this.vv);
  this.EvalJS(this.vv);
//  this.vv = 40;
  if(this.tp == 'E') {
//	this.omid.innerHTML = this.vv;
	this.ohid.innerHTML = this.vv;
  }
  else {
//	this.omid.innerHTML = this.vv;
	this.ohid.innerHTML = this.vv;
//  	this.omid.appendChild(this.vv);
  }
};


msgetContent.prototype.MLoading=function() {
//  x =  document.getElementById(this.mid);
//  x.innerHTML = 'Loading...';
	this.omid.src = '/image/indicator.gif';
};

msgetContent.prototype.EvalJS=function(s) {
  var x = new String(s);
  var b = 0;
  var e = 0;
  var sjs = '';
  b = x.indexOf("<script>");
  if(b > 0) {
  	b = b + 8;
  	e = x.indexOf("</script>", b);
  	if(e > 0) {
  		sjs = x.substring(b,e);
  		eval(sjs);
  	}
  }
};


msgetContent.prototype.ParsMSxml=function(s) {
//alert('PARS: ' + s);
  this.vv = "text > " + s;
};

msgetContent.prototype.XmlToString=function(o) {
//alert("1 > " + o.toString());

  var oo = o.documentElement;
//alert("11");
//if (oo.xml)
// alert("22" + oo.xml);
  var rr = xmlNodeToString(oo);
//alert(rr);
  return rr;
};

function xmlNodeToString(o) {
//alert("12 > " + o.tagName);
  var rr = '';
//alert("1 > " + o.nodeType);
 if(o.nodeType) {
  var tp = o.nodeType;
  if(tp == 1) 
  { // открыв.элементе тега
//alert("11 > " + o.tagName);
  	rr = rr + "<" + o.tagName;
  	var attrs = o.attributes;
  	if(attrs) {
  		var cAttrs = attrs.length;
//alert("2> " + cAttrs);
  		var i = 0;
  		while(i < cAttrs) {
  			attr = attrs[i];
  			if(attr) 
  				rr = rr + " " + attr.name + "=\"" + attr.value + "\"";
  			i++;
  		}
  	}
  	//дочерние элементы
  	if(o.hasChildNodes()) {
  		rr = rr + ">";
  		var childs = o.childNodes;
  		var cChilds = childs.length;
  		var j = 0;
  		while(j < cChilds) {
  			child = childs[j];
  			rr = rr + xmlNodeToString(child);
  			j++;
  		}
  		rr = rr + "</" + o.tagName + ">";
  	}
  	else {
  		rr = rr + "/>";
  	}
  }
  else if(tp == 3)
  { //фрагмент текста
  	rr = rr + o.data;
  } 
 }
//alert(">>" + rr);  
  return rr;
}


//<< begin   <<<<<<<<<<<<<<<<<<<< CONTLOADER >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

/*--- content loader object for cross-browser requests ---*/
msgetContent.prototype.ContentLoader=function(url,method,params,contentType,onerror){
  
  if (window.XMLHttpRequest){
    this.req=new XMLHttpRequest();
    this.tp = "M";
  }
  else if (window.ActiveXObject){
    this.req=new ActiveXObject("Msxml2.XMLHTTP.3.0");
    this.tp = "E";
  }
  
  this.loadXMLDoc(url,method,params,contentType);
};

msgetContent.prototype.loadXMLDoc=function(url,method,params,contentType){
  if (!method){
    method="GET";
  }
  if (!contentType && method=="POST"){
    contentType='application/x-www-form-urlencoded; text/xml; charset=windows-1251';
  }
  if (this.req){
    try{
      var loader=this;
      this.req.onreadystatechange=function(){
        msgetContent.onReadyState.call(loader);
      }
      this.req.open(method,url,true);
//      this.req.open(method,url,false);
      if (contentType){
        this.req.setRequestHeader('Content-Type', contentType);
      }
      this.req.send(params);
    }catch (err){
      this.onerror.call(this);
    }
  }
};
msgetContent.onReadyState=function(){
  if (this.req.readyState==msREADY_STATE_COMPLETE){
//    if (this.req.status==200 || this.req.status==0){
    if (this.req.status==200){
      this.onload.call(this);
    }else{
      this.onerror.call(this);
    }
  }
  else {
      this.MLoading();
  }
};

msgetContent.prototype.defaultError=function(){
  x =  document.getElementById(this.mid);
  x.innerHTML = '';
  alert("error fetching data!"
    +"\n\nreadyState:"+this.req.readyState
    +"\nstatus: "+this.req.status
    +"\nheaders: "+this.req.getAllResponseHeaders());
  this.req.abort();
};
//********* end   *****  MSGETCONTENT

