function ajBasketSendDel (pw, pid) { // thisObj, // , activeArr//, quantity
	//alert('pw= '+pw+', pid= '+pid); // +', quantity= '+quantity
	return ajBasketSend(pw,[pid],'del');
}
function ajBasketSendErase (pw) { // thisObj, // , activeArr//, quantity
	//alert('pw= '+pw+', pid= '+pid); // +', quantity= '+quantity
	return ajBasketSend(pw,[],'erase'); // ,[pid]
}
function ajBasketSend (pw, idArr, modshop_action, objForm) {
	//alert('pw= '+pw+', idArr= '+idArr+', modshop_action= '+modshop_action+', objForm= '+objForm);
	if (pw!=undefined) { //  && objForm!=undefined
		//var ajData = {'pw':pw,'action':'edit','id':idArr};
		var ajData = {'pw':pw,'modshop_action':((modshop_action!=undefined && modshop_action!='')?modshop_action:'replace')}; // ,'action':'edit'
		if (idArr!=undefined) ajData['id'] = idArr;
		if (objForm!=undefined) ajData['fv'] = objForm;
		if (idArr!=undefined || modshop_action!=undefined) ajData['confirm'] = true;
		var ajParams = {callback:'ajBasketSendCallback',include:'modules/modshop/php/wlBasketShowModal.php',caching:false};
		//var ajParams = {'callback':'ajModalBoxSendCallback','backendPath':'/call/wlModalBox.php?pw='+pw+'&action=edit&include=wlModalBox'}; // ,'include':'wlModalBox'
		wlAjax(ajData,ajParams);
	}
}
function ajBasketSendCallback (result,errors) {
	if (result!=undefined) { // Write the answer
		basketFillTopPn(result);
		wlModal.setContent(result['modal']);
	}
}


function ajBasketOrderGo (pw, objForm) {
	//alert('pw= '+pw+', idArr= '+idArr+', modshop_action= '+modshop_action+', objForm= '+objForm);
	if (pw!=undefined) { //  && objForm!=undefined
		//var ajData = {'pw':pw,'action':'edit','id':idArr};
		var ajData = {'pw':pw}; // ,'action':'edit'
		if (objForm!=undefined) ajData['fv'] = objForm;
		var ajParams = {callback:'ajBasketOrderGoCallback',include:'modules/modshop/php/wlBasketOrderGoModal.php',caching:true};
		//var ajParams = {'callback':'ajModalBoxSendCallback','backendPath':'/call/wlModalBox.php?pw='+pw+'&action=edit&include=wlModalBox'}; // ,'include':'wlModalBox'
		wlAjax(ajData,ajParams);
	}
}
function ajBasketOrderGoCallback (result,errors) {
	if (result!=undefined) { // Write the answer
		//basketFillTopPn(result);
		if (result['urlSuccess']!=undefined) window.location = result['urlSuccess'];
		else wlModal.setContent(result['modal']);
	}
}


function basketFillTopPn (result) { // thisObj, // , activeArr//, quantity
	//alert('pw= '+pw+', pid= '+pid); // +', quantity= '+quantity
	var bskM = $('basketTopMessage');
	var bskO = $('basketTopOrderLink');
	if (bskM!=undefined && bskO!=undefined) {
		if (result["data"]!=undefined) {
			bskM.innerHTML = result["data"]["QuantityF"]+': '+result["data"]["QuantityV"]+'<br>'+result["data"]["SummF"]+': '+result["data"]["SummV"]+' '+result["data"]["RateV"];
			/*var el = document.getElementById("new_f");
			var bskOA = document.createElement('a');
			bskOA.href = result["data"]["OrderHref"];
			bskOA.innerHTML = result["data"]["OrderText"];
			bskOA.title = 'alert("hello");'; 
			bskO.innerHTML = '';
			bskO.appendChild(bskOA);*/
			
			//bskO.innerHTML = '<a href="'+result["data"]["OrderHref"]+'">'+result["data"]["OrderText"]+'</a>';
			//bskO.innerHTML = '<a onclick="alert(\'В разработке\');return false" href="#">'+result["data"]["OrderText"]+'</a>';
			if (result["data"]["OrderHref"]!=undefined) bskO.href = result["data"]["OrderHref"];
			if (result["data"]["OrderText"]!=undefined) bskO.innerHTML = result["data"]["OrderText"];
			if (result["data"]["OrderOnclick"]!=undefined) bskO.onclick = result["data"]["OrderOnclick"];
			
		} else {
			bskM.innerHTML = result["message"];
			//bskO.innerHTML = '';
		}
	}
	var bskM = $('basketPnMessage');
	var bskO = $('basketPnOrderLink');
	var bskL = $('basketPnList');
	//var quo = '';
	if (bskM!=undefined && bskO!=undefined) {
		if (result["data"]!=undefined) {
			bskM.innerHTML = result["data"]["QuantityF"]+': '+result["data"]["QuantityV"]+'<br>'+result["data"]["SummF"]+': '+result["data"]["SummV"]+' '+result["data"]["RateV"];
			
			//bskO.innerHTML = '<a href="'+result["data"]["OrderHref"]+'">'+result["data"]["OrderText"]+'</a>';
			if (result["data"]["OrderHref"]!=undefined) bskO.href = result["data"]["OrderHref"];
			if (result["data"]["OrderText"]!=undefined) bskO.innerHTML = result["data"]["OrderText"];
			if (result["data"]["OrderOnclick"]!=undefined) bskO.onclick = result["data"]["OrderOnclick"];
			
			if (result["data"]["array"]!=undefined) {
				bskL.innerHTML = '';
				for (var p in result["data"]["array"]) {
					//alert('p= '+p+', p["title"]= '+p["title"]+', p["quantity"]= '+p["quantity"]);
					bskL.innerHTML += result["data"]["array"][p]["title"]+' - '+result["data"]["array"][p]["quantity"]+'<br>';
				}
			}
		} else {
			bskM.innerHTML = result["message"];
			//bskO.innerHTML = bskL.innerHTML = '';
			bskL.innerHTML = '';
		}
	}
}










function ajBasket_old (pw, idArr, modshop_action) { // thisObj, // , activeArr//, quantity
	//alert('pw= '+pw+', idArr= '+idArr+', idArr.length= '+idArr.length+', modshop_action= '+modshop_action); // +', quantity= '+quantity
	var dataArr = new Array();
	if (idArr!=undefined && idArr.length!=undefined) {
		for (var i=0; i<idArr.length; i++) {
			var quantityObj = $('quantity['+idArr[i]+']');
			//alert('quantityObj.value.match(/^[\d]+$/)= '+quantityObj.value.match(/^[\d]+$/));
			var quantity = (quantityObj!=undefined && quantityObj.value!='' && quantityObj.value.match(/^[\d]+$/)!=null) ? quantityObj.value : 1 ;
			//alert('idArr['+i+']= `'+idArr[i]+'`, quantity= `'+quantity); // ', pid= '+pid+
			dataArr.push({'quantity':quantity});
		}
	} else var idArr = new Array();
	//var ajData = {'pw':'modshop', 'id':idArr, 'fv':dataArr, 'modshop_action': ((modshop_action!=undefined)?modshop_action:''}; // ,'action':'active'
	var ajData = {'pw':'modshop','id':idArr,'fv':dataArr,'modshop_action':((modshop_action!=undefined)?modshop_action:'add')};
	var ajParams = {callback:'ajBasketCallback',include:'modules/modshop/php/wlBasket.php',   caching:false   }; // ,caching:false
	wlAjax(ajData,ajParams);
}
function ajBasketCallback_old (result) {
	if (result!=undefined) { // Write the answer
		//if (result["data"]!=undefined) basketFillTopPn(result["data"]);
		//else basketFillTopPn();
		basketFillTopPn(result);
	}
}













function modshop_ajax_ordered (thisis, pid) { // thisObj, // , activeArr//, quantity
	var objAjaxResult = $('ajresult');
	//alert('pw= '+pw+', pid= '+pid); // +', quantity= '+quantity
	JsHttpRequest.query(
			'/modules/modshop/ajax_ordered.php', // backend
			{
				'pw': 'modshop',
				'pid': pid
				//'fv': [{ "id": idArr, "id2": idArr }],
				//,[{\''.$params['row']['id'].'\')}]
			},
			function(result, errors) { // Function is called when an answer arrives
				if (errors!=undefined && errors!='') { // Write errors to the debug div
					if (objAjaxResult!=undefined) {
						//window.scroll(0,0);
						scrollToObj(objAjaxResult);
						objAjaxResult.className = 'ajresulterror';
						objAjaxResult.innerHTML = errors;
					} else {
						alert('Не найден слой для вывода отчета/ошибок\n------------------------------\n'+errors+'\n------------------------------');
					}
				} else {
					if (objAjaxResult!=undefined) objAjaxResult.className = 'ajresult';
				}
				if (result!=undefined && result['value']!=undefined && result['value']!='') { // Write the answer
					thisis.parentNode.innerHTML = result['value'];
				} //else document.getElementById("ajax_reports").style.display = 'none';
			},
			false  // do not disable caching
			//true // надо что бы данные всегда обновлялись, когда люди вкл/выкл пункты...
	);
}


function modshopprn (pid) { // thisObj, // , activeArr//, quantity
	//alert('pw= '+pw+', pid= '+pid); // +', quantity= '+quantity
	newWin('/modules/modshop/call_bill.php?pid='+pid,'BILL',800,600,'menubar');
	//newWin('blank','BILL',800,600,'menubar');
	//printit();
	//return false;
}

































function ajax_basket_add (pw, pid) { // thisObj, // , activeArr//, quantity
	//alert('pw= '+pw+', pid= '+pid); // +', quantity= '+quantity
	return ajax_basket(pw,[pid],'add');
}
function ajax_basket_del (pw, pid) { // thisObj, // , activeArr//, quantity
	//alert('pw= '+pw+', pid= '+pid); // +', quantity= '+quantity
	return ajax_basket(pw,[pid],'del');
}
function ajax_basket_erase (pw) { // thisObj, // , activeArr//, quantity
	//alert('pw= '+pw+', pid= '+pid); // +', quantity= '+quantity
	return ajax_basket(pw,[],'erase'); // ,[pid]
}


function ajax_basket (pw, idArr, modshop_action) { // thisObj, // , activeArr//, quantity
	//alert('pw= '+pw+', idArr= '+idArr+', modshop_action= '+modshop_action); // +', quantity= '+quantity
	var objAjaxResult = $('ajresult');
	var dataArr = new Array();
	var modshop_action = (modshop_action!=undefined && modshop_action!='') ? modshop_action : '' ;
	//if (pid!=undefined) {
	if (idArr!=undefined && idArr.length!=undefined) {
		for (var i=0; i<idArr.length; i++) {
			var quantityObj = $('quantity['+idArr[i]+']');
			//alert('quantityObj.value.match(/^[\d]+$/)= '+quantityObj.value.match(/^[\d]+$/));
			var quantity = (quantityObj!=undefined && quantityObj.value!='' && quantityObj.value.match(/^[\d]+$/)!=null) ? quantityObj.value : 1 ;
			dataArr.push({'quantity':quantity});
			//alert('pw= `'+pw+'`, idArr= `'+idArr+'`, quantity= `'+quantity+'`, modshop_action= `'+modshop_action+'`'); // ', pid= '+pid+
		}
	} else {
		var idArr = new Array();
	}
	
	//mdbSM('ajax_updating','250','35'); // Уже работает ;-) ////// НЕ работает бля, из-за бля выпадающей бля менюхи
	JsHttpRequest.query(
			'/modules/modshop/ajax_basket.php', // backend
			{
				'pw': pw,
				//'action': action,
				'modshop_action': modshop_action,
				//'pid': pid,
				'id': idArr,
				//'fv': [{ "id": idArr, "id2": idArr }],
				//,[{\''.$params['row']['id'].'\')}]
				'fv': dataArr
				//'quantity': quantity
			},
			function(result, errors) { // Function is called when an answer arrives
				if (errors!=undefined && errors!='') { // Write errors to the debug div
					if (objAjaxResult!=undefined) {
						//window.scroll(0,0);
						scrollToObj(objAjaxResult);
						objAjaxResult.className = 'ajresulterror';
						objAjaxResult.innerHTML = errors;
					} else {
						alert('Не найден слой для вывода отчета/ошибок\n------------------------------\n'+errors+'\n------------------------------');
					}
				} else {
					if (objAjaxResult!=undefined) objAjaxResult.className = 'ajresult';
				}
				if (result!=undefined) { // Write the answer
					
					var modshopBasketTop = $('modshopBasketTop');
					var modshopBasketPn = $('modshopBasketPn');
					//alert('modshopBasketPnDiv= '+modshopBasketPnDiv);
					if (modshopBasketTop!=undefined && result["modshopBasketTop"]!=undefined && result["modshopBasketTop"]!='') {
						modshopBasketTop.innerHTML = result["modshopBasketTop"];
					}
					if (modshopBasketPn!=undefined && result["modshopBasketPn"]!=undefined && result["modshopBasketPn"]!='') {
						modshopBasketPn.innerHTML = result["modshopBasketPn"];
					}
					/*var modshopBasketTopDiv1 = $("modshopBasketTopDiv1");
					var modshopBasketTopDiv2 = $("modshopBasketTopDiv2");
					var modshopBasketPnDiv = $("modshopBasketPnDiv");
					//alert('modshopBasketPnDiv= '+modshopBasketPnDiv);
					if (modshopBasketTopDiv1!=undefined && result["modshopBasketTopDiv1"]!=undefined && result["modshopBasketTopDiv1"]!='') {
						modshopBasketTopDiv1.innerHTML = result["modshopBasketTopDiv1"];
					}
					if (modshopBasketTopDiv2!=undefined && result["modshopBasketTopDiv2"]!=undefined && result["modshopBasketTopDiv2"]!='') {
						modshopBasketTopDiv2.innerHTML = result["modshopBasketTopDiv2"];
					}
					if (modshopBasketPnDiv!=undefined && result["modshopBasketPnDiv"]!=undefined && result["modshopBasketPnDiv"]!='') {
						modshopBasketPnDiv.innerHTML = result["modshopBasketPnDiv"];
					}*/
					//var modshopBasketPnDiv = $("modshopBasketPnDiv");
					//if (modshopBasketPnDiv!=undefined && result["modshopBasketPnDiv"]!=undefined && result["modshopBasketPnDiv"]!='') {
						//modshopBasketPnDiv.innerHTML = result["modshopBasketPnDiv"];
					//}
					
					var modshopBasketPriceFieldName = $("priceFieldName");
					if (modshopBasketPriceFieldName!=undefined && result["priceFieldName"]!=undefined && result["priceFieldName"]!='') {
						modshopBasketPriceFieldName.innerHTML = result["priceFieldName"];
					}
					
					var BasketSummTotal = $("summTotal");
					if (BasketSummTotal!=undefined && result["summTotal"]!=undefined && result["summTotal"]!='') {
						BasketSummTotal.innerHTML = result["summTotal"];
					}
					
					//alert('modshop_action= '+modshop_action);
					if (modshop_action!=undefined && (modshop_action=='del' || modshop_action=='erase')) {
						//alert('modshop_action= '+modshop_action);
						if (idArr!=undefined && idArr.length!=undefined) {
							//alert('idArr= '+idArr+', idArr.length= '+idArr.length);
							for (var i=0; i<idArr.length; i++) {
								var trObj = $('tr['+idArr[i]+']');
								//alert('trObj= '+trObj+', trObj.id= '+trObj.id+', trObj.name= '+trObj.name+', trObj.tagName= '+trObj.tagName);
								if (trObj!=undefined && trObj.parentNode!=undefined) {
									//trObj.style.visible = false;
									trObj.parentNode.removeChild(trObj);
								}
							}
						}
						//alert('result["modshopBasket"]= '+result["modshopBasket"]);
						var modshopBasket = $("modshopBasket");
						if (modshopBasket!=undefined && result["modshopBasket"]!=undefined && result["modshopBasket"]!='') {
							modshopBasket.innerHTML = result["modshopBasket"];
						}
					}
					
				} //else $("ajax_reports").style.display = 'none';
			},
			//false  // do not disable caching
			true // надо что бы данные всегда обновлялись, когда люди вкл/выкл пункты...
	);
}

