function loadCO(step)
{
if(ID('zwindow').style.display=='none')
zwindow("Składanie Zamówienia");
setCookie('step', step);
var ax = ax_init('/ax.php?main=createOrder');
ax.onCompletion = function(){ID('zbody').innerHTML = ax.response; pos_korektor(); /*pageLoad();*/}
ax.runAJAX();
}
function selectPaymentType(v)
{
setCookie('paymentType', v);
ID('pt1').className = v == 1 ? 'opt1':'opt0';
ID('pt2').className = v == 2 ? 'opt1':'opt0';
ID('nxtbtn').style.display = '';
}
function selectShipper(v)
{
setCookie('shipper', v);
ID('sh1').className = v == 1 ? 'opt1':'opt0';
ID('sh2').className = v == 2 ? 'opt1':'opt0';
ID('nxtbtn').style.display = '';
}
function selectPoste(v)
{
setCookie('poster', v);
ID('pr1').className = v == 1 ? 'opt1':'opt0';
ID('pr2').className = v == 2 ? 'opt1':'opt0';
ID('poste_up').style.display = v==2?'':'none';
if(v == 2 && !ID('urzad_pocztowy').value)
ID('urzad_pocztowy').focus();
if(v == 1 || (v == 2 && ID('urzad_pocztowy').value))
ID('nxtbtn').style.display = '';
else
ID('nxtbtn').style.display = 'none';
}
function COPrev(step)
{
var prev = '';
ID('prev_loader').style.display='';
if(step == 'paymentType') prev = 'country';
if(step == 'shipper') prev = 'paymentType';
if(step == 'poste') prev = 'shipper';
if(step == 'contact' && getCookie('shipper') == '1') prev = 'poste';
if(step == 'contact' && getCookie('shipper') == '2') prev = 'shipper';
if(step == 'adres') prev = 'contact';
if(step == 'gift') prev = 'adres';
if(step == 'adds' && getCookie('paymentType') == 1) prev = 'gift';
if(step == 'adds' && getCookie('paymentType') == 2) prev = 'adres';
if(step == 'summary') prev = 'adds';
loadCO(prev);
}
function CONext(step)
{
var next = '';
ID('next_loader').style.display='';
if(step == 'country') next = 'paymentType';
if(step == 'paymentType') next = 'shipper';
if(step == 'shipper' && getCookie('shipper') == '1') next = 'poste';
if(step == 'shipper' && getCookie('shipper') == '2') next = 'contact';
if(step == 'poste') next = 'contact';
if(step == 'contact')
{
if(!checkEmail(ID('co_email').value)){showErr("Proszę podać adres email"); ID('co_email').focus(); return;}
if(!ID('co_telefon').value){showErr("Proszę podać numer telefonu"); ID('co_telefon').focus(); return;}
next = 'adres';
}
if(step == 'adres')
{
if(!ID('co_imie').value){showErr("Proszę podać imię"); ID('co_imie').focus(); return;}
if(!ID('co_nazwisko').value){showErr("Proszę podać nazwisko"); ID('co_nazwisko').focus(); return;}
if(!ID('co_ulica').value){showErr("Proszę podać nazwę ulicy"); ID('co_ulica').focus(); return;}
if(!ID('co_dom').value){showErr("Proszę podać numer domu"); ID('co_dom').focus(); return;}
if(!ID('co_miasto').value){showErr("Proszę podać nazwę miejscowości"); ID('co_miasto').focus(); return;}
if(!ID('co_kod').value){showErr("Proszę podać kod pocztowy miejscowości"); ID('co_kod').focus(); return;}
}
if(step == 'adres' && getCookie('paymentType') == 1) next = 'gift';
if(step == 'adres' && getCookie('paymentType') == 2) next = 'adds';
if(step == 'gift') next = 'adds';
if(step == 'adds') next = 'summary';
if(step == 'summary') location.href="/store/createOrder/";
if(next) loadCO(next);
}
function poste(change)
{
if(change)
ID('poste_restante').checked ^= 1;
setCookie('poste_restante', ID('poste_restante').checked?'TAK':'');
ID('poste_up').style.display = ID('poste_restante').checked?'':'none';
}
function gift(change)
{
if(change)
ID('gift').checked ^= 1;
setCookie('gift', ID('gift').checked?'TAK':'');
ID('gift_adres').style.display = ID('gift').checked?'':'none';
}
function kupTeraz(pid)
{
if(ID('zwindow').style.display=='none')
zwindow("Składanie Zamówienia");
setCookie('step', 'country');
var ax = ax_init('/ax.php?main=kupteraz');
ax.setVar('pid', pid);
ax.onCompletion = function()
{
ID('zbody').innerHTML = ax.response;
pos_korektor();
}
ax.runAJAX();
}
var ppselected = null;
function selectTab(t)
{
if(ppselected){
if(ID(ppselected))
ID(ppselected).className = 'off';
ID(ppselected+'_body').style.display='none';
}
if(ID(t))
ID(t).className='on';
ID(t+'_body').style.display='';
ppselected = t;
}
var storeSearch_url = null;
function storeSearch(v)
{
storeSearch_url = null;
if(v.length && v.length < 3) $('#min3').removeClass('hidden_elem'); else $('#min3').addClass('hidden_elem');
if(v.length < 3){$('#ss_results').addClass('hidden_elem');return};
var re = [];
var stre = v.split(' ');
for(var i in stre)
re[i] = new RegExp(stre[i], 'i');
var out='';
var z=0;
var cnt=0;
for(var g in storeSearch_arr)
{
for(var i in storeSearch_arr[g])
{
var o = storeSearch_arr[g][i];
o = o.split('|');
var ok = true;
for(var r in re) if(o[0].match(re[r]) == null) ok=false;
if(ok)
{
var t = o[0];
var add = null;
var url = '';
for(var ss in stre) if(stre[ss]) t=highlight(t, stre[ss]);
t = t.split('}').join('</strong>').split('{').join('<strong style="background:#e6e6e6;">');
if(g == 'cats'){
url = '/store/'+o[1]+'/?src=search';
add = 'kategoria';
}
if(g == 'producers'){
url = '/store/products/prid:'+o[1]+'/?src=search';
add = 'producent';
}
if(g == 'products'){
url = '/store/product/'+o[1]+'/?src=search';
tipz[o[1]] = '<img src="'+o[2]+'/c80.jpg" style="width:80px;height:80px;border: 2px solid #eeb;float:left;margin-right:4px;"><div style="min-width:240px; max-width:360px;"><strong>'+o[0]+'</strong><br>'+o[4]+'<br><strong>'+o[3]+'</strong></div>';
add = o[3];
}
var bg = (z^=1)?'#f1f1f1':'#fff';
out += '<div style="padding:1px;background:'+bg+'"><a href="'+url+'"'+(g == 'products' ? 'onmouseover="ddrivetip(\'i:'+o[1]+'\');" onmouseout="hideddrivetip();"':'')+'>'+t+'</a>'+(add?'<span class="dsc"> - '+add+'</span>':'')+'</div>';
if(!storeSearch_url) storeSearch_url = url;
cnt++;
}
}
}
$('#ss_results').removeClass('hidden_elem');
if(!out) out = 'No nic nie znaleziono...';
ID('ss_results').innerHTML = out;
}
function highlight(value, term){
return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "{$1}");
}
var storeSearch_arr = null;
function storeProductsLoad()
{
if(storeSearch_arr) return true;
var ax = ax_init('/ax.php?main=loadProducts');
ax.onCompletion = function()
{
if(ax.response.substring(0, 3) == 'ok!')
{
var a = ax.response.substring(3).split('|||');
storeSearch_arr = [];
storeSearch_arr['cats'] = a[0].split('||');
storeSearch_arr['producers'] = a[1].split('||');
storeSearch_arr['products'] = a[2].split('||');
}
else
showErr(ax.response);
$('#ssearch_loader').addClass('hidden_elem');
}
$('#ssearch_loader').removeClass('hidden_elem');
ax.runAJAX();
}
var storeRB = [];
function cartAction(m, v, mi, cnt)
{
btns('lock');
if(ID('cartloading')) ID('cartloading').style.display='';
var ax = ax_init('/ax/cart.php');
ax.setVar('ci', cartid);
ax.setVar('m', m);
ax.setVar('v', v);
if(mi) ax.setVar('mi', mi);
if(cnt) ax.setVar('cnt', cnt);
ax.setVar('sign', cart_sign);
ax.onCompletion = function()
{
btns('unlock');
if(ID('cartloading')) ID('cartloading').style.display='none';
if(ax.response.substring(0, 3) == 'ok!')
{
if(ID('cart')) cartRefresh(ax.response.substring(3));
}
else
{
if(ax.response == 'empty')
{
if(ID('cart'))
{
ID('cart').innerHTML = '<span class="dsc">Tw&#243;j koszyk jest pusty.</span>';
if(ID('cartVis'))
ID('cartVis').style.display='none';
}
var a = document.getElementsByTagName('a');
for(i=0; i<a.length; i++)
if(a[i].id.substring(0, 8) == 'pdbtnsub' || a[i].id.substring(0, 8) == 'pdbtnord')
a[i].style.display='none';
a = document.getElementsByTagName('span');
for(i=0; i<a.length; i++)
if(a[i].id.substring(0, 5) == 'pdinf')
a[i].innerHTML='';
}
else
showErr(ax.response);
}
var e = location.href.split('/');
if(e[4] == 'cart')
location.reload();
}
ax.runAJAX();
}
function cartRefresh(input)
{
var a = document.getElementsByTagName('a');
for(var i=0; i<a.length; i++){
if(a[i].id.substring(0, 8) == 'pdbtnsub' || a[i].id.substring(0, 8) == 'pdbtnord')
a[i].style.display='none';
}
var tpl = [];
var c=1;
tpl['products'] = php2js(input);
tpl['sum'] = 0;
for(var i in tpl['products']){
var o = tpl['products'][i];
o['nr'] = c++;
o['price'] = Number(o['brutto'].split(',').join('.')) * Number(o['cnt']);
o['price'] = o['price'];
tpl['sum'] += o['price'];
o['price'] = o['price'].toFixed(2);
if(o['rabat'] && !tpl['rabat']) tpl['rabat'] = Number(o['rabat']);
o['tooltip'] = tipzc;
tipz[tipzc++] = parseTpl(o, tpls['cart_tt']);
var he = ID('pdbtnsub'+o['id']);
if(he) he.style.display='';
var he = ID('pdbtnord'+o['id']);
if(he) he.style.display='';
}
if(tpl['rabat']) tpl['sum'] = tpl['sum']*(100-tpl['rabat'])/100;
tpl['sum'] = tpl['sum'].toFixed(2);
ID('cart').innerHTML = parseTpl(tpl, tpls['cart']);
if(ID('cartVis'))
ID('cartVis').style.display='';
}
function btns(m)
{
var btns = document.getElementsByTagName('button');
for(i=0; i<btns.length; i++)
{
if(btns[i].id.substring(0, 2) == 'pd')
btns[i].disabled=m=='lock';
}
}
function cartItem(id, state)
{
ID('crtsub'+id).style.display=state?'':'none';
ID('crtr'+id+'_1').style.background = ID('crtr'+id+'_2').style.background = state?'#f0f0f0':'#fff';
}
function vipujkoda(){
var s = ID('vipcode').value;
if(!s){showErr("Nie ma kodu! Nie ma kodu! Gdzie kod?"); return!1;}
stora_on('ax');
var ax = ax_init('/ax/storevip.php');
ax.setVar('code', s);
ax.onCompletion = function()
{
if(ax.response.substring(0, 3) == 'ok!')
showMsg(ax.response.substring(3));
else
showErr(ax.response);
ID('vipcode').value='';
stora_off();
}
ax.runAJAX();
}
function productVideo(id)
{
win('/ax/productVideo.php', 'ProductVideo', ['id'], [id], "productVideoStart();");
}
function productVideoStart()
{
for(var i=0; i<5; i++)
{
if(ID('video_flv_'+i))
{
swfobject.embedSWF("/miniplayer.swf", 'player_'+i, "400", "224", "9.0.0", null, {file:'video_flv_'+i});
}
}
}
function switchCat(cid)
{
if(ID('st_'+cid).className.indexOf('plus')!=-1){
ID('st_'+cid).className = 'store_tree st_minus1';
ID('dvc_'+cid).className = 'sidebox';
}
else{
ID('st_'+cid).className = 'store_tree st_plus1';
ID('dvc_'+cid).className = 'sidebox hidden_elem';
}
}
tpls['cart'] = "<table width=\"100%\" style=\"margin-bottom:4px;\">\n{mask:products}\n<tr id=\"crtr{nr}_1\" valign=\"top\" onmouseover=\"cartItem({nr}, 1)\" onmouseout=\"cartItem({nr}, 0)\">\n <td style=\"width:24px;padding: 2px 0 0 2px;\"><strong>{cnt} x</strong></td>\n <td style=\"padding:2px 0 2px 4px;\">\n  <a href=\"{url}\" onmouseover=\"ddrivetip('i:{tooltip}')\" onmouseout=\"hideddrivetip()\"><strong>{title}</strong>{set:model}<br><span class=\"dsc\">{model}</span>{/set}</a>\n </td>\n <td align=\"right\" nowrap style=\"padding: 2px 2px 0 8px;\">{price}z&#x0142;</td>\n</tr>\n<tr id=\"crtr{nr}_2\" onmouseover=\"cartItem({nr}, 1)\" onmouseout=\"cartItem({nr}, 0)\">\n <td></td>\n <td style=\"padding-left:4px;height:18px;padding-bottom:2px;\" colspan=\"2\">\n  <div id=\"crtsub{nr}\" style=\"display:none;\">\n   <a href=\"\" onclick=\"cartAction('add', '{id}'{set:modelid}, '{modelid}'{/set});return!1;\" class=\"crtbtn s1\">&nbsp;DODAJ&nbsp;</a>\n   <a href=\"\" onclick=\"cartAction('sub', '{id}'{set:modelid}, '{modelid}'{/set});return!1;\" class=\"crtbtn s1\">&nbsp;USU&#323;&nbsp;</a>\n  </div>\n </td>\n</tr>\n<tr><td></td><td colspan=\"4\"><div style=\"height:1px;margin: 2px 0;background:#f1f1f1;\"></div></td></tr>\n{/mask}\n</table>\n<div class=\"clearfix\">\n <div style=\"float:left;padding-left:26px;\">\n  <button onclick=\"loadCO('country');return!1;\" class=\"btn\">Do Kasy &raquo;</button>\n  <button onclick=\"if(confirm(\'Jestes pewien, ze chcesz usunac koszyk?\'))cartAction(\'del\', 0);return!1;\" class=\"btn2\">Skasuj</button>\n </div>\n <div style=\"float:right;margin-top:2px;text-align:right;\">\n  {set:rabat}<a href=\"/store/cards/\" class=\"dsc\">Rabat:</a> -<strong>{rabat}%</strong><br>{/set}\n  <span class=\"dsc\">Suma: </span><strong>{sum}</strong>z&#x0142;\n </div>\n</div>\n\n";
tpls['cart_tt'] = "<img src=\"{ppath}/c120.jpg\" style=\"width:120px;display:block;float:left; border: 2px solid #eeb;margin-right:8px;\">\n<strong>{title}{set:model} ({model}){/set}</strong>\n<br>{subtitle}\n";
