function showForm_SendRequest (id, catid, quantity){
	if (quantity==''){
		alert ('Не указано количество!');
		$('f_quan2basket').focus();
		return;
	}
	quantity = 0+quantity;//преобразование в int
	if (quantity==0){
		if (confirm('Вы указали 0 единиц. При этом товар будет удален из заявки. Продолжить?')){
			go__add_toBasket(id, catid, quantity);
		} else {return}
	} else{
		go__add_toBasket(id, catid, quantity);
	}
}

function go__add_toBasket(id, catid, quantity){
	if (!jxs.x4) jxs.x4 = new jx();
	jxs.x4.jx.bind ({
		"url":	"/ajax/respondents/go__add_toBasket.php?session_id="+session_id+"&ann_id="+id+"&cat_id="+catid+"&quanToAdd="+quantity,
		"onSuccess":	function(a){
			if (a!='ok'){alert (a);
			} else {
				var q=Number($('f_quan2basket').value);
				if (q==0){
					$('quantity_current_ware').innerHTML = '&nbsp;нет&nbsp;';
					$('quantity_current_ware').className = 'quanEqual0';
				} else {
					$('quantity_current_ware').innerHTML = '&nbsp;'+q+'&nbsp;';
					$('quantity_current_ware').className = 'quanMoreThan0';
				}
				update_basket_text();
			}
		},
		"fomat":	"text",
		"method":	"post",
		"onError":	function (status) {
			//alert ("\"Ашипка\": "+status);
		}
	});
	$('a_basket_text').innerHTML = '<img src="/img/loadingAnimation/waiting_basket.gif" />';
}

function update_basket_text(){
	if (!jxs.x4) jxs.x4 = new jx();
	jxs.x4.jx.bind ({
		"url":	"/ajax/respondents/getQuanWareInBasket.php?session_id="+session_id,
		"onSuccess":	function(a){
			var b = a.substr(0,2);
			if (b!='ok'){
				alert ('Ошибка сервера');
				return;
			}
			quan = Number(a.replace(/^ok/, ''));
			if (quan==0){
				$('a_basket_text').innerHTML = 'Заявка ПУСТА';
			} else{
				var s = 'наименований';
				var quan_str = String(quan);
				var lastChar = quan_str.charAt(quan_str.length-1);
				if (lastChar=='1') s='наименование';
				if ((lastChar=='2')||(lastChar=='3')||(lastChar=='4')) s='наименования';
				$('a_basket_text').innerHTML = quan+' '+s;
			}
		},
		"fomat":	"text",
		"method":	"post",
		"onError":	function (status) {
			//alert ("\"Ашипка\": "+status);
		}
	});
	$('a_basket_text').innerHTML = '<img src="/img/loadingAnimation/waiting_basket.gif" />';
}

function AllowedForInputNumbers (keyCode){
	var k = keyCode;
	return ((k>=96)&&(k<=105))||(k==8)||(k==9)||(k==16)||(k==46)||((k>=37)&&(k<=40))||((k>=48)&&(k<=57))||(k==35)||(k==36)||(k==144);
}

function basketTableQuan_click(a){
	var id = /_(\d*$)/.exec(a.id)[1];
	$('span_quan_'+id).style.display='none';
	$('input_quan_'+id).value=$('span_quan_'+id).innerHTML;
	$('input_quan_'+id).style.display='';
	$('input_quan_'+id).focus();
	$('span_save_'+id).className='miniLink';
	$('span_cancel_'+id).className='miniLink';
}

function basketTableSave_click(a){
	var id = /_(\d*$)/.exec(a.id)[1];
	if (($('input_quan_'+id).value==0)||($('input_quan_'+id).value=='')){
		alert('Количество не может быть 0.\nЕсли хотите удалить эту позицию из Заявки, то кликните  "Удалить", расположенную правее в колонке "Операция".');
		return;
	}
	updateQuanForOneRow_basket(id, $('input_quan_'+id).value);
}

function basketTableCancel_click(a){
	var id = /_(\d*$)/.exec(a.id)[1];
	$('input_quan_'+id).value=$('span_quan_'+id).innerHTML;
	$('span_quan_'+id).style.display='';
	$('input_quan_'+id).style.display='none';
	$('span_save_'+id).className='miniLinkInactive';
	$('span_cancel_'+id).className='miniLinkInactive';
}

function updateQuanForOneRow_basket(id, quan){
	if (!jxs.x4) jxs.x4 = new jx();
	jxs.x4.jx.bind ({
		"url":	"/ajax/respondents/updateQuanForOneRow_basket.php?id="+id+"&quan="+quan+"&session_id="+session_id,
		"onSuccess":	function(a){
			if (a=='ok'){
				$('img_quan_animation_'+id).style.display='none';
				$('span_quan_'+id).innerHTML=$('input_quan_'+id).value;
				$('span_quan_'+id).style.display='';
				$('input_quan_'+id).style.display='none';
				$('span_save_'+id).className='miniLinkInactive';
				$('span_cancel_'+id).className='miniLinkInactive';
			} else {
				alert('Произошла ошибка сохранения.');
				$('img_quan_animation_'+id).style.display='none';
			}
		},
		"fomat":	"text",
		"method":	"post",
		"onError":	function (status) {
			//alert ("\"Ашипка\": "+status);
			$('img_quan_animation_'+id).style.display='none';
		}
	});
	$('img_quan_animation_'+id).style.display='';
}

function deleteItemFromBasket(a){
	var id = /_(\d*$)/.exec(a.id)[1];
	if (!confirm('Действительно удалить из заявки следующую позицию?? \n'+$('td_a_name_'+id).innerHTML)) return;
	jxs.x4.jx.bind ({
		"url":	"/ajax/respondents/deleteOneRow_FromBasket.php?id="+id+"&session_id="+session_id,
		"onSuccess":	function(a){
			if (a=='ok'){
				document.location.href="/order.php";
			} else {
				alert('Произошла ошибка сохранения.');
				$('img_quan_animation_'+id).style.display='none';
			}
		},
		"fomat":	"text",
		"method":	"post",
		"onError":	function (status) {
			//alert ("\"Ашипка\": "+status);
			$('img_quan_animation_'+id).style.display='none';
		}
	});
	$('img_quan_animation_'+id).style.display='';
}



function show_formWithContactData(){
	$('div_group001').style.display='none';
	$('table_formWithContactData').style.display='';
	$('f_fio').focus();
}

function hide_formWithContactData(){
	$('div_group001').style.display='';
	$('table_formWithContactData').style.display='none';
}

function sendMyOrder(){
	var f_fio = $('f_fio').value;
	var f_tel = $('f_tel').value;
	var f_fax = $('f_fax').value;
	var f_email = $('f_email').value;
	var f_organization = $('f_organization').value;
	var f_city = $('f_city').value;
	var f_comment = $('f_comment').value;

	if ((f_fio=='')||(f_tel=='')||(f_fax=='')||(f_email=='')){
		alert('Заполните обязательные поля');
		return;
	}

	f_fio = escape2(f_fio);
	f_tel = escape2(f_tel);
	f_fax = escape2(f_fax);
	f_email = escape2(f_email);
	f_organization = escape2(f_organization);
	f_city = escape2(f_city);
	f_comment = escape2(f_comment);

	jxs.x4.jx.bind ({
		"url":	"/ajax/respondents/sendMyOrder.php?&session_id="+session_id+"&f_fio="+f_fio+"&f_tel="+f_tel+"&f_fax="+f_fax+"&f_email="+f_email+"&f_organization="+f_organization+"&f_city="+f_city+"&f_comment="+f_comment,
		"onSuccess":	function(a){
			if (a=='ok'){
				alert ('Ваша заявка успешно отправлена.\nСпециалисты ООО "Снабспецтехника" обработают ее в ближайшее время и свяжутся с Вами.\n\nЕсли Вы что-то забыли указать - ничего страшного. Можете прямо сейчас внести изменения с дополнениями и отправить Заявку повторно.\n\nСпасибо!');
				document.location.href='/order.php';
			} else {
				alert('Произошла ошибка отправки.');
				hide_formWithContactData();
			}
		},
		"fomat":	"text",
		"method":	"post",
		"onError":	function (status) {
			//alert ("\"Ашипка\": "+status);
		}
	});
}


function clearBasket(){
	if (!confirm('Действительно очистить текущую заявку и создать новую?'))return;
	jxs.x4.jx.bind ({
		"url":	"/ajax/respondents/clearAllBasket.php?&session_id="+session_id,
		"onSuccess":	function(a){
			if (a=='ok'){
				document.location.href="/order.php";
			} else {
				alert('Произошла ошибка отправки.');
			}
		},
		"fomat":	"text",
		"method":	"post",
		"onError":	function (status) {
			//alert ("\"Ашипка\": "+status);
		}
	});
}