function mousePos(evt, id){

if(window.event){
var X = window.event.x;
var Y = window.event.y;
}
else{
var X = evt.clientX;
var Y = evt.clientY;
}

if(id == "x") return X;
if(id == "y") return Y;

}

function tobasket(evt, Price, Name){
var topPosition = $('body').scrollTop();

var posY = mousePos(evt, 'y')+topPosition-200;
var posX = mousePos(evt, 'x')-100;

$('<div id="qtywindow" class="popup" style="position: fixed;top:150px; right:283px;"><div style="margin:10px 20px 10px;"><h1>Укажите количество</h1><input type="text" id="qty" value="1" style="width:150px; margin:3px;" /><br /><input type="button" onclick="add(\''+Price+'\', \''+Name+'\')" value="Добавить" style="width:45%" />&nbsp;&nbsp;&nbsp;<input type="button" onclick="$(\'#qtywindow\').animate({height:\'hide\', opacity: \'hide\'}, 400, 0, function(){$(\'#qtywindow\').remove()});" value="Отмена"  style="width:45%"/></div></div>').appendTo('body').animate({height:'show', opacity:'show'}, 500);

}

function add(Price, Name){

var Qty = $('#qty').val();

$.post(
'/req/tobasket.php',
{
price:Price,
name:Name,
qty:Qty
},
addResult
);

$('#qtywindow').html('<b>Загрузка...</b>');

}

function addResult(result){
if(result){
$('#basketmess').html(result);
$('#qtywindow').animate({height:'hide', opacity: 'hide'}, 400, 0, function(){$('#qtywindow').remove()});
}
else alert('Ошибка, попробуйте ещё раз...');
}
