function chooseProdQty(id,price,page){var qty=0;var div_w=400;var div_h=120;var L_T_pos=getRim(div_w,div_h);var old_div=document.getElementById('div_qty');if(old_div){document.body.removeChild(old_div);}
var div=document.createElement('div');div.id='div_qty';div.style.zIndex=100;div.style.border='thin solid green';div.style.padding=10;div.style.position='absolute';div.style.top=L_T_pos[1];div.style.left=L_T_pos[0];div.style.width=div_w;div.style.height=div_h;div.style.backgroundColor='#ffffff';document.body.appendChild(div);var table=document.createElement('table');div.appendChild(table);table.style.width='100%';table.style.height='100%';var headRow=table.insertRow(0);var headCell=headRow.insertCell(0);headCell.style.backgroundColor='#00ad23';headCell.colSpan=2;headCell.style.fontWeight='bold';headCell.style.color='#ffffff';headCell.style.fontSize='10pt';headCell.style.height=30;headCell.style.textAlign='center';headCell.innerHTML="<img src='/images/gball.gif'>"+'&nbsp;&nbsp;Выберете количество';var qtyRow=table.insertRow(1);qtyRow.valign='middle';var qtyCell_1=qtyRow.insertCell(0);qtyCell_1.style.textAlign='right';qtyCell_1.width='50%';qtyCell_1.innerHTML='<b>Количество:</b>';var qtyCell_2=qtyRow.insertCell(1);qtyCell_2.style.textAlign='left';var txt_input=document.createElement('input');txt_input.type='text';txt_input.value=1;txt_input.size=2;txt_input.style.border='thin solid green';txt_input.id='qty_input_div';txt_input.onkeypress=function(e){return checkQtyPressEvent(e);};txt_input.onkeyup=function(e){return checkQtyUpEvent(e);};qtyCell_2.appendChild(txt_input);var footRow=table.insertRow(2);var footCell_1=footRow.insertCell(0);footCell_1.align='center';footCell_1.colSpan=2;footCell_1.style.padding=5;footCell_1.style.verticalAlign='bottom';var cancel_button=document.createElement('input');cancel_button.type='button';cancel_button.value='Отмена';cancel_button.style.width=100;cancel_button.style.margin=5;cancel_button.style.color='#006923';cancel_button.style.fontWeight='bold';cancel_button.onclick=function(){document.body.removeChild(div);};footCell_1.appendChild(cancel_button);var ok_button=document.createElement('input');ok_button.type='button';ok_button.value='OK';ok_button.disabled=false;ok_button.id='ok_button_div';ok_button.style.width=100;ok_button.style.margin=5;ok_button.style.color='#006923';ok_button.style.fontWeight='bold';ok_button.onclick=function(){qty=parseInt(txt_input.value)||1;document.body.removeChild(div);addToBasket(id,qty,page,price);};footCell_1.appendChild(ok_button);return false;}
function checkQtyUpEvent(evt){var ok_button=document.getElementById('ok_button_div');var qty_input=document.getElementById('qty_input_div');if(qty_input.value.length==0){ok_button.disabled=true;}
return true;}
function checkQtyPressEvent(evt){var ok_button=document.getElementById('ok_button_div');var qty_input=document.getElementById('qty_input_div');evt=(evt)?evt:event;var charCode=(evt.charCode)?evt.charCode:((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0));if(charCode==8||charCode==9||charCode==13||charCode==127||charCode==37||charCode==39){return true;}
if(charCode>31&&(charCode<48||charCode>57))return false;ok_button.disabled=false;return true;}
function addToBasket(prod_id,qty,page,amnt){if(!qty){qty=1;}
server_call('addToBasket',{prod:prod_id,qty:qty},function(resp){if(page){document.location.href=page;}else{var qq=document.getElementById('qty');var aa=document.getElementById('amnt');var QQTY=parseInt(document.getElementById('__Stack_Qty__').value);if(isNaN(QQTY)){QQTY=0;}
var AAMNT=parseFloat(document.getElementById('__Stack_Amnt__').value);if(isNaN(AAMNT)){AAMNT=0;}
dropKids(qq);dropKids(aa);QQTY+=qty;AAMNT+=amnt*qty;qq.appendChild(document.createTextNode(QQTY));aa.appendChild(document.createTextNode(roundM(AAMNT)));document.getElementById('__Stack_Qty__').value=QQTY;document.getElementById('__Stack_Amnt__').value=AAMNT;var prods_msg=(qty==1)?'Товар добавлен в корзину.':'Товары добавлены в корзину.';alertmsg(prods_msg);}},'/product/rpc.html');}
function dropKids(obj){var nodes=obj.childNodes;var nLen=nodes.length;if(nLen){for(var i=0;i<nLen;i++)
obj.removeChild(nodes[0]);}}
function roundM(ch){return((Math.round(ch*100))/100);}
function makeElement(document,tagName,parent,attrs,className,style,chld){var x=document.createElement(tagName);if(attrs){for(var i in attrs)x.setAttribute(i,attrs[i]);}
if(className){x.className=className;}
if(style){for(var i in style)x.style[i]=style[i];}
if(parent){parent.appendChild(x)}
if(chld){for(var i in chld)x.appendChild(chld[i]);}
return x;}
function getAbsPos(el){var x=0;var y=0;for(;el;el=el.offsetParent){x+=el.offsetLeft;y+=el.offsetTop;}
return{x:x,y:y};}
function createPopupDiv(document,parent,w,h,classname,style,fill,onclose){var popup=document.createElement('div');var body=document.body;popup.style.position='absolute';popup.style.zIndex=100;popup.className=classname;var ppos=getAbsPos(parent);popup.style.left=ppos.x;popup.style.top=ppos.y;popup.style.width=w;popup.style.height=h;popup.style.overflow='auto';for(var e in style)
popup.style[e]=style[e];body.appendChild(popup);var xbut=makeElement(document,'div',popup,null,null,{zIndex:popup.style.zIndex+1,position:'absolute',top:1,left:popup.clientWidth-20,width:20,height:20});var but=makeElement(document,'input',xbut,{type:'button',name:'x',value:'X'},null,{height:20,width:20,padding:'0 0 0 0',margin:'0 0 0 0',fontSize:10});but.value='X';xbut.onclick=function(){popup.parentNode.removeChild(popup);if(onclose){onclose();}}
if(fill)fill(popup,xbut,but);return popup;}
function getElementsByClass(searchClass,node,tag){var classElements=new Array();if(node==null)node=document;if(tag==null)tag='*';var els=node.getElementsByTagName(tag);var elsLen=els.length;var pattern=new RegExp("(^|\\s)"+searchClass+"(\\s|$)");for(i=0,j=0;i<elsLen;i++){if(pattern.test(els[i].className)){classElements[j]=els[i];j++;}}
return classElements;}
function tr_make_td(tr,attrs,style_attrs){var __document=(tr.ownerDocument&&tr.ownerDocument!=null&&tr.ownerDocument!=undefined)?tr.ownerDocument:document;var td=__document.createElement('td');if(attrs){for(var i in attrs){td.setAttribute(i,attrs[i]);switch(i){case'colspan':case'colSpan':td.colSpan=attrs[i];break;case'rowspan':case'rowSpan':td.rowSpan=attrs[i];break;case'nowrap':case'noWrap':td.noWrap=attrs[i];break;case'valign':case'vAlign':td.vAlign=attrs[i];break;case'bgcolor':case'bgColor':td.bgColor=attrs[i];break;case'align':td.align=attrs[i];break;default:break;}}}
if(style_attrs){for(var i in style_attrs)td.style[i]=style_attrs[i];}
tr.appendChild(td);return td;}
var popupCounter=0;var dragObject=null;var mouseOffset=null;function alertmsg(txt){var pupW=260;var pupH=110;var L_T_SCREEN=getRim(pupW,pupH);var pupStyles={border:"3px double #cccccc",backgroundColor:"#ffffff",textAlign:"center",padding:4,left:L_T_SCREEN[0],top:L_T_SCREEN[1]};createPopupDiv(document,document.body,pupW,pupH,'popupTextarea',pupStyles,function(popup,xbut,but){var self_id="popup_div_"+(popupCounter++);popup.id=self_id;var divs=new Array();divs=getElementsByClass("popupTextarea",null,"div");if(divs.length){for(var i=0;i<divs.length;i++){if(divs[i].id!=self_id)divs[i].parentNode.removeChild(divs[i]);}}
var header=makeElement(document,'div',popup,{},'msg_head',{cursor:'pointer',backgroundColor:'#00ad23',color:'#ffffff',textAlign:'left',paddingLeft:10,paddingTop:5,paddingBottom:5,fontSize:12,fontWeight:'bold'});header.setAttribute("id","popup_div_head");header.innerHTML="<img src='/images/gball.gif'> "+"Информационное сообщение";header.onmousedown=function(evt){dragObject=popup;mouseOffset=getMouseOffset(header,evt);}
header.onmousemove=mouseMove;header.onmouseup=function(){dragObject=null;}
var text=makeElement(document,'div',popup,{},'msg_div',{textAlign:'center',paddingTop:10,paddingBottom:5,fontSize:12,fontWeight:'bold'});text.innerHTML=txt;var ok=makeElement(document,'div',popup,{},'msg_ok',{textAlign:'center',paddingTop:10,paddingBottom:5,fontSize:12,fontWeight:'bold'});but.onclick=xbut.onclick;xbut.removeChild(but);ok.appendChild(but);but.value="OK";but.style.height="auto";but.style.width="auto";but.style.fontSize=12;but.style.padding=3;but.className="ok_button";xbut.parentNode.removeChild(xbut);});}
function getRim(w,h){w=w?w:0;h=h?h:0;var scroll=getScroll();return[Math.round((scroll.width-w)/2)+scroll.left,Math.round((scroll.height-h)/2)+scroll.top];}
function getScroll(){var T,L,W,H;var w=window;with(w.document){if(w.document.documentElement&&documentElement.scrollTop){T=documentElement.scrollTop;L=documentElement.scrollLeft;}else if(w.document.body){T=body.scrollTop;L=body.scrollLeft;}
if(w.innerWidth){W=w.innerWidth;H=w.innerHeight;}else if(w.document.documentElement&&documentElement.clientWidth){W=documentElement.clientWidth;H=documentElement.clientHeight;}else{W=body.offsetWidth;H=body.offsetHeight}}
return{top:T,left:L,width:W,height:H};}
function mouseCoords(ev){if(ev.pageX||ev.pageY){return{x:ev.pageX,y:ev.pageY};}
return{x:ev.clientX+document.body.scrollLeft-document.body.clientLeft,y:ev.clientY+document.body.scrollTop-document.body.clientTop};}
function getMouseOffset(target,ev){ev=ev||window.event;var docPos=getPosition(target);var mousePos=mouseCoords(ev);return{x:mousePos.x-docPos.x,y:mousePos.y-docPos.y};}
function getPosition(e){var left=0;var top=0;while(e.offsetParent){left+=e.offsetLeft;top+=e.offsetTop;e=e.offsetParent;}
left+=e.offsetLeft;top+=e.offsetTop;return{x:left,y:top};}
function mouseMove(ev){ev=ev||window.event;var mousePos=mouseCoords(ev);if(dragObject){dragObject.style.position='absolute';dragObject.style.top=mousePos.y-mouseOffset.y;dragObject.style.left=mousePos.x-mouseOffset.x;return false;}}
var rpc;RPC.READY_STATE_COMPLETE=4;function RPC(fe){if(window.XMLHttpRequest){this.req=new XMLHttpRequest();}else if(window.ActiveXObject){this.req=new ActiveXObject("Microsoft.XMLHTTP");}else{alert("RPC not available");}
this.url=fe?fe:"rpc_save.html";var req=this.req;var rpc=this;this.req.onreadystatechange=this.callback=function(){if(req.readyState==RPC.READY_STATE_COMPLETE){var httpStatus=req.status;if(httpStatus==200||httpStatus==0){var doc=req.responseXML;if(!doc){alert("Cannot parse server reply :\n"+req.responseText.substr(0,256));var cons=document.getElementById('__console');if(cons){cons.innerHTML+=req.responseText;}
return false;}
if(!doc){alert("Cannot parse server reply");return false;}
var response=doc.getElementsByTagName('response').item(0);if(!response){alert("Server reply has no response element "+"\n"+req.responseText);}
var more=response.getAttribute('waitmore');var qid=response.getAttribute('qid');var qn=response.getAttribute('qn');if(more){document.body.style.cursor="wait";setTimeout(function(){(new RPC(fe)).request('__wait',{q:qid,qn:qn},rpc.onOk)},parseInt(more));}else{var rc=response.getAttribute('rc');if(rc=='EXCEPTION'){var ex=xml_getObjectAttributes(response);var func_name='exception_'+ex.exceptionClass.replace(/::/g,'_');if(eval("window."+func_name)){eval(func_name+"(ex)");}else{alert(ex.text?ex.text:'произошла ошибка на сервере');}
document.body.style.cursor='default';return false;}
if(rc=='FAILED'){alert('произошла ошибка на сервере');document.body.style.cursor='default';return false;}
rpc.onOk(response,req);document.body.style.cursor='auto';}}else{rpc.onError(req);document.body.style.cursor='auto';}}};}
RPC.prototype.onError=function(req){alert("error fetching data!"
+"\n\nreadyState:"+req.readyState
+"\nstatus: "+req.status
+"\nheaders: "+req.getAllResponseHeaders());}
RPC.prototype.onOk=function(){alert("Done");}
RPC.prototype.request=function(proc,args,onOk,sync){this.req.open("POST",this.url,sync?false:true);this.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');var qs='_proc='+proc;for(var arg in args){var val=args[arg];if(typeof(val)=='object'){for(k in val){if(val[k]&&val[k].constructor!=Function)
qs+='&'+escape(arg)+'='+escape(val[k]);}}
else{qs+='&'+escape(arg)+'='+escape(val);}}
this.onOk=onOk;this.req.send(qs);if(sync)this.callback();}
function server_call(proc,args,onOk,fe,sync){rpc=new RPC(fe);rpc.request(proc,args,onOk,sync);}
function xml_getObjectAttribute(node,attrName){for(var i=0;i<node.childNodes.length;i++){var nn=node.childNodes[i];if(nn.nodeType==1){if(nn.tagName==attrName){return nn.childNodes[0]?nn.childNodes[0].data:null;}}}
return'KO';}
function xml_getObjectAttributes(node){var o={};if(!node){alert("Empty node got");return o;}
for(var i=0;i<node.attributes.length;i++){o[node.attributes[i].nodeName]=node.attributes[i].nodeValue;}
for(var i=0;i<node.childNodes.length;i++){var nn=node.childNodes[i];if(nn.nodeType==1){if(nn.getAttribute('class')=='subobject'){o[nn.tagName]=null;for(var j=0;j<nn.childNodes.length;j++){var nnn=nn.childNodes[j];if(nnn.nodeType==1){o[nn.tagName]=xml_getObjectAttributes(nnn);}
break;}}else
if(nn.getAttribute('class')=='subobjects'){o[nn.tagName]=[];for(var j=0;j<nn.childNodes.length;j++){var nnn=nn.childNodes[j];if(nnn.nodeType==1){o[nn.tagName][o[nn.tagName].length]=xml_getObjectAttributes(nnn);}}}else
if(nn.childNodes[0]){o[nn.tagName]=nn.childNodes[0].data;}else{o[nn.tagName]=null;}}}
return o;}
function xml_getObjectList(node){var l=new Array;for(var i=0;i<node.childNodes.length;i++){var nn=node.childNodes[i];if(nn.nodeType==1){l[l.length]=xml_getObjectAttributes(nn);}}
return l;}
var child_windows=new Array;function open_window(url,wnd_name,varname,x,y,props){if(!x){x=600;}
if(!y){y=400;}
if(!props){props=new Object();}
var wnd=window.open(url,wnd_name,'width='+x+',height='+y+',resizable='+(props["resizable"]?props["resizable"]:"yes")
+',toolbar='+(props["toolbar"]?props["toolbar"]:"no")
+',location='+(props["location"]?props["location"]:"no")
+',directories='+(props["directories"]?props["directories"]:"no")
+',status='+(props["status"]?props["status"]:"no")
+',scrollbars='+(props["scrollbars"]?props["scrollbars"]:"yes")
+',menubar='+(props["menubar"]?props["menubar"]:"no"));if(varname)eval(varname+'=wnd');if(varname){setTimeout('if('+varname+') if (!'+varname+'.closed) '+varname+'.focus()',200);}
wnd.focus();child_windows[child_windows.length+1]=wnd;return false;}