function select_count(key,cnt) {
cnt = cnt.replace(",",".");
cnt = cnt.replace(/\.+/g,".");
cnt = cnt.replace(/\,+/g,".");
cnt = cnt.replace(/\s+/g, '');
var ed = document.formgoods['edizm'+key+''].value;
	if(ed > 0) {
	var prc = document.formgoods['prc'+key+'_'+ed+''].value
	var bnd = document.formgoods['bnd'+key+'_'+ed+''].value
	prc = prc.split(',')
	bnd = bnd.split(',')
	var st = 1
	var cn = 0
		if(bnd.length > 0) {
			for (var i=0;i<bnd.length;i++) {
				if(st == 1) {
					if(i >= (bnd.length - 1)) {
					cn = prc[i]
					st = 2
					}
					else if (cnt < (bnd[i]*100)/100) {
					cn = prc[i]
					st = 2
					}
				}
			}
		}
	document.getElementById("cena" + key).innerHTML = Math.round(cn)
	var stoim = ''+Math.round(cn*cnt*100)/100+''
		if(isNaN(stoim) == true) {
		document.formgoods['count'+key+''].value = '1';
		document.getElementById("stoim" + key).innerHTML = ''+Math.round(cn*100)/100+''
		}
		else {
		stoim = stoim.replace(".",",")
		document.formgoods['count'+key+''].value = cnt;
		document.getElementById("stoim" + key).innerHTML = stoim
		}
	}
}
function send_order(i) {
var c = document.formgoods['count'+i+''].value;
c = c.replace(",",".");
c = c.replace(/\s+/g, '');
var e = document.formgoods['edizm'+i+''].value;
var u = document.formgoods['url'].value;
var link = '/send_order.php?a=1&c='+c+'&e='+e+'&i='+i+'&u='+u+'';
window.location.href=link;
//document.getElementById('zak1').innerHTML = "<font color=red>странице заказа</font>";
//document.getElementById('sendorderifr').src = '/send_order.php?a=1&c='+c+'&e='+e+'&i='+i+'&u='+u+'';
}

function del_order(i) {
var u = document.formgoods['url'].value;
var link = '/send_order.php?a=2&i='+i+'&u='+u+'';
window.location.href=link;
//document.getElementById('sendorderifr').src = link;
}
function getXmlHttp() {
var xmlhttp;
try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } }
	if(!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); }
return xmlhttp;
}
function getBodyScrollTop() {
return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}
ftimeout = null
function ajgetxmlfopt(elem) {
var sa = document.otbor['selarr'].value
var pid2 = ''
var _pid2 = ''
var dicval = ''
var tca = document.otbor['tchbxarr'].value
var s_get = '';
tca = tca.split(',')
	if(tca.length > 0) {
	var tchbxarr = new Array()
		for (var i=0;i<tca.length;i++) {
		s_get += ''+tca[i]+','
		pid2 += '&dpid_'+tca[i]+'='
		tchbxarr[tca[i]] = document.otbor['tchbxarr_'+tca[i]+''].value
		tchbxarr[tca[i]] = tchbxarr[tca[i]].split(',')
			if(tchbxarr[tca[i]].length > 0) {
				for (var i2=0;i2<tchbxarr[tca[i]].length;i2++) {
				document.getElementById('cp-'+tca[i]+'_'+tchbxarr[tca[i]][i2]+'').className = 'bad';
					if(document.getElementById(''+tca[i]+'_'+tchbxarr[tca[i]][i2]+'').checked) {
						if(_pid2 != '')
						_pid2 += '_'
					pid2 += ''+tchbxarr[tca[i]][i2]+','
					_pid2 += tchbxarr[tca[i]][i2]
					}
				}
			}
		}
	}
var idg = document.otbor['idgroup'].value
var fid = document.otbor['form_id'].value
var saval = new Array()
var selid = new Array()
var selopt = new Array()
var selname = new Array()
var pid = ''
	if(sa != '') {
	sa = sa.split(',')
		if(sa.length > 0) {
			for (var i=0;i<sa.length;i++) {
			selopt[sa[i]] = document.getElementById('selopt_'+sa[i]+'');
			selid[sa[i]] = document.getElementById('selid_'+sa[i]+'');
			selname[sa[i]] = document.getElementById('seloptname_'+sa[i]+'');	
				if(selid[sa[i]].options[selid[sa[i]].selectedIndex].value != 'undefined') {	
				saval[sa[i]] = selid[sa[i]].options[selid[sa[i]].selectedIndex].value
					if(saval[sa[i]] != '') {
					saval[sa[i]] = selid[sa[i]].options[selid[sa[i]].selectedIndex].value
					pid += ''+saval[sa[i]]+','
					if(_pid2 != '')
					_pid2 += '_'
					_pid2 += ''+saval[sa[i]]+''
					}
				selname[sa[i]].className = 'bad seloptname';
				selopt[sa[i]].innerHTML = '<select id="selid_'+sa[i]+'" name="'+sa[i]+'" OnChange="javascript:ajgetxmlfopt(\'selid_'+sa[i]+'\');"><option value=""></option></select>';
				}
			}
		}
	}

var tflta = document.otbor['tfltarr'].value
tflta = tflta.split(',')
	if(tflta.length > 0) {
	dicval += '&dic='+document.otbor['tfltarr'].value+''
		for (var i=0;i<tflta.length;i++) {
			if(tflta[i] != '') {
				if(document.otbor['costfrom_'+tflta[i]+''].value != '') {
					if(_pid2 != '')
					_pid2 += '_'
				dicval += '&dic_'+tflta[i]+'='+document.otbor['costfrom_'+tflta[i]+''].value+';'+document.otbor['costto_'+tflta[i]+''].value+'';
				_pid2 += ''+tflta[i]+'::'+document.otbor['costfrom_'+tflta[i]+''].value+';'+document.otbor['costto_'+tflta[i]+''].value+''
				}
			}
		}
	}
	//if(sa != '' && idg != '' && fid != '') {
	if(idg != '' && fid != '') {
	var http = getXmlHttp();
	http.open('get', '/service/modules/ajgetxmlfopt.php?sa='+sa+'&sa2='+s_get+'&pid='+pid+'&idg='+idg+'&fid='+fid+''+pid2+''+dicval+'', true);
	//alert('/service/modules/ajgetxmlfopt.php?sa='+sa+'&sa2='+s_get+'&pid='+pid+'&idg='+idg+'&fid='+fid+''+pid2+''+dicval+'')
		http.onreadystatechange=function() {
			if(http.readyState != 4) {
			return
			}
		clearTimeout(timeout)
			if(http.readyState == 4 && http.status == 200) {
			var response=http.responseXML
			var feeditems=response.getElementsByTagName("item")
			var countitem=response.getElementsByTagName("countitem")
				if(countitem.length > 0) {
				var r = document.getElementById(elem).getBoundingClientRect()
				t = Math.round(r.top)+getBodyScrollTop();
				l = Math.round(r.left)-249;
				var hgfhfg = countitem[0].firstChild.nodeValue
				document.getElementById('getitem').innerHTML = '<p><input type="submit" name="getitem" value="Выбрать '+hgfhfg+' товаров"></p>';
				document.getElementById('searchitem').innerHTML = '<div style="width:220px;position:absolute;left:'+l+'px;top:'+t+'px;background-color:#fdd;border:1px solid #c90;padding:5px;">Найдено товаров: '+hgfhfg+'. <a href="'+document.otbor['urls'].value+''+_pid2+'/">Показать</a></div>';
				}
			var selindexval;
			var selindextxt;
				if(feeditems.length > 0) {
				var con = '';
				var s = '';
				selindexval = '';
				selindextxt = '';
				var seloptdicid;
				var sid;
					for (var i=0;i<feeditems.length;i++) {
					seloptdicid = feeditems[i].getElementsByTagName("seloptdicid")
						if(seloptdicid.length > 0) {
						sid = seloptdicid[0].firstChild.nodeValue
						selindexval = feeditems[i].getElementsByTagName("selindexval")
						selindextxt = feeditems[i].getElementsByTagName("selindextxt")
							if(selindexval.length > 0) {
							con = '<option value=""></option>'
								for (var j=0;j<selindexval.length;j++) {
								sval = selindexval[j].firstChild.nodeValue
								stxt = selindextxt[j].firstChild.nodeValue
									if(saval[sid] == sval) {
									con += '<option value="'+sval+'" selected>'+stxt+'</option>'
									}
									else {
									con += '<option value="'+sval+'">'+stxt+'</option>'
									}
								}
							}
						selopt[sid].innerHTML = '<select id="selid_'+sid+'" name="'+sid+'" OnChange="javascript:ajgetxmlfopt(\'selid_'+sid+'\');">'+con+'</select>'
						selname[sid].className = 'good seloptname';
						}
					selchbxicid = feeditems[i].getElementsByTagName("selchbxicid")
						if(selchbxicid.length > 0) {
						selindexval = feeditems[i].getElementsByTagName("selindexval")
							if(selindexval.length > 0) {
								for (var j=0;j<selindexval.length;j++) {
								document.getElementById(''+selindexval[j].firstChild.nodeValue+'').className = 'good';
								}
							}
						}	
					selfltid = feeditems[i].getElementsByTagName("selfltid")
						if(selfltid.length > 0) {
						sid = selfltid[0].firstChild.nodeValue
						selfltis = feeditems[i].getElementsByTagName("selfltis")
							if(selfltis.length > 0) {
								if(selfltis[0].firstChild.nodeValue == 2) {
								document.getElementById('seloptname_'+sid+'').className = 'bad seloptname';
								}
								else {
								document.getElementById('seloptname_'+sid+'').className = 'good seloptname';
								}
							}
						selfltfrom = feeditems[i].getElementsByTagName("selfltfrom")
							if(selfltfrom.length > 0) {

							}
						selfltto = feeditems[i].getElementsByTagName("selfltto")
							if(selfltto.length > 0) {
							}
						selfltfromgood = feeditems[i].getElementsByTagName("selfltfromgood")
							if(selfltfromgood.length > 0) {
							}
						selflttogood = feeditems[i].getElementsByTagName("selflttogood")
							if(selflttogood.length > 0) {
							}
						selfltlll = feeditems[i].getElementsByTagName("selfltlll")
							if(selfltlll.length > 0) {
							}
						selfltwww = feeditems[i].getElementsByTagName("selfltwww")
							if(selflttogood.length > 0) {
							document.getElementById('dvstn_'+sid+'').innerHTML = '<div style="position:relative;top:6px;left:'+selfltlll[0].firstChild.nodeValue+'%;width:'+selfltwww[0].firstChild.nodeValue+'%;height:4px;background:#008620;">&nbsp;</div>'
							}	
						}
					}
				}
			}
			else {
			handleError("Соединение отсутствует")
			}
		}
	if(ftimeout) clearTimeout(ftimeout)
	var ftimein = function() {
	ftimeout = setTimeout(function() {$("#searchitem").fadeOut("slow");}, 5000)
	}
	$("#searchitem").fadeIn("slow");
	ftimein()
	var timeout = setTimeout( function() {http.abort();}, 10000);
	http.send(null);
	}
}
function handleError(message) {
alert("Ошибка: "+message)
}
function sliderid(a, mn, mx, from, to, stp) {
$("#slider_"+a+"").slider({
	min: mn,
	max: mx,
	values: [from,to],
	range: true,
	step: stp,
	stop: function(event, ui) {
		$("input#costfrom_"+a+"").val($("#slider_"+a+"").slider("values",0));
		$("input#costto_"+a+"").val($("#slider_"+a+"").slider("values",1));
		if($("input#costfrom_"+a+"").val() != '' && $("input#costfrom_"+a+"").val() <= mn) { $("input#costfrom_"+a+"").val('') }
		if($("input#costto_"+a+"").val() != '' && $("input#costto_"+a+"").val() >= mx) { $("input#costto_"+a+"").val('') }
		ajgetxmlfopt('slider_'+a+'');
    },
    slide: function(event, ui){
		$("input#costfrom_"+a+"").val($("#slider_"+a+"").slider("values",0));
		$("input#costto_"+a+"").val($("#slider_"+a+"").slider("values",1));
    }
});
$("input#costfrom_"+a+"").change(function(){
	var value1=$("input#costfrom_"+a+"").val();
	var value2=$("input#costto_"+a+"").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		$("input#costfrom_"+a+"").val(value1);
	}
	$("#slider_"+a+"").slider("values",0,value1);	
});
$("input#costto_"+a+"").change(function(){
	var value1=$("input#costfrom_"+a+"").val();
	var value2=$("input#costto_"+a+"").val();
	if (value2 > mx) { value2 = mx; $("input#costto_"+a+"").val(mx)}

	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		$("input#costto_"+a+"").val(value2);
	}
	$("#slider_"+a+"").slider("values",1,value2);
});
$('input').keypress(function(event){
	var key, keyChar;
	if(!event) var event = window.event;
	if (event.keyCode) key = event.keyCode;
	else if(event.which) key = event.which;
	if(key==null || key==0 || key==8 || key==13 || key==9 || key==46 || key==37 || key==39 ) return true;
	keyChar=String.fromCharCode(key);
	if(!/\d/.test(keyChar))	return false;
});
}
