// Copyright © At Hand Creations

olc+='SetShop();';

var ate="@ath";
ate+="and.org";
var Currs= new Array(
"GBP","&pound;","Pounds sterling",
"EUR","&euro;","Euros",
"USD","$","US dollars",
"CAD","CA$","Canadian dollars",
"AUD","AU$","Australian dollars",
"JPY","&yen;","Japanese yen"
);
var MAX_ITMS=9999;
var SNTRY=7;
var Stock=new Array(
"TJOY","POSH Joy Tags 12pk",125,0,25,1,"main",
"TJBX","Box of 36* POSH Joy Tags 12pk",3400,0,700,1,"main",
"TSNO","Snowflake 12pk tags",115,0,15,1,"ppjoy",
"CEA2","Alive Easter card twin pack",165,0,40,1,"easter",
"CCB6","Celebrate Christmas 6pk cards",250,0,125,1,"christmas",
"CPP5","Christmas for Paper People 5pk cards",250,0,125,1,"ppjoy",
"FUN3","Funster Frog birthday cards 3pk",225,0,25,1,"funcards",
"CP33","Psalm 33 Encouragement card",110,0,15,1,"psalm",
"PPP2",'Light for the World / Church Restoration pictures',3500,0,500,1,"pictures",
//"GMAT","Funster Grace Mat",250,0,0,1,"main",
//"AWVD","At Hand worship visuals disc",3950,0,0,1,"worship",
//"WV3C","At Hand worship visuals disc - with discount",3950,0,395,1,"3google/"
"CCGB","Christmas cards and envelopes for distribution",40,0,22,100,"emanuel",
"CCGP","Christmas cards and envelopes with overprinting",68,0,38,100,"emanuel"
)

var citm="";
var itg=0;
var vbm=0;
var cpm=0;
var gx=0;

var cur=GetV("cury");
if(cur=="") cur=0;
var v=1;
var p=xrate[1];
xrate[1]=v;
if(cur) v=xrate[cur]/p;
var i=0;
var s= cur==5?100:1;
v/=s;
while(i<Stock.length)
{
 Stock[i+3]=Math.ceil((Stock[i+2]-Stock[i+4])*v)*s;
 i+=SNTRY;
}
cur*=3;
var pp10ps=28;
if(cur) v*=1.2; 
else pp10ps=29;
var pp=new Array(pp10ps*10,0,5000);
pp[1]=Math.ceil(v*pp10ps)*10*s;
pp[3]=Math.ceil(v*50)*100*s;

function SetShop()
{
 ICache(shopfiles);
 SetVbm(0);
 GetSty("bsktb").zIndex=GetSty("bskto").zIndex=GetSty("bsktc").zIndex=GetSty("sinf").zIndex=GetSty("ethic").zIndex=5;
 GetSty("curd").zIndex=6;
 ShowBskt();
}

function Num2Let(v)
{
 var i=0;
 var n=0;
 var l="";
 while(v)
 {
  var c=v%62;
  v=(v-c)/62;
  if(c>35) c+=6;
  if(c>9) c+=7;
  l+=String.fromCharCode(c+48);
 }
 return l;
}

function Let2Num(v)
{
 var i=v.length;
 var n=0;
 while(i)
 {
  var c=v.charCodeAt(--i)-48;
  if(c>9) c-=7;
  if(c>35) c-=6;
  n=n*62+c;
 }
 return n;
}

function GetItm(c)
{
 var v=new Array();
 var i;
 var b="bskt";
 var i=GetV(b);
 var n;
 if(i=="")
 {
  v[0]=0;
  v[1]=b;
  v[2]=b;
  return v;
 }
 while((n=i.substring(0,4))!="bskt")
 {
  if(n==c)
  {
   c=GetV(c);
   v[0]=Let2Num(c.substring(4));
   v[1]=b;
   v[2]=c.substring(0,4);
   return v;
  }
  else if(n=="bskt") break;
  b=n;
  i=GetV(b);
 }
 v[0]=0;
 v[1]=b;
 v[2]=n;
 return v;
}

function SetItm(c,q)
{
 var r=q>MAX_ITMS?0:1;
 var v=GetItm(c);
 if(q)
 {
  if(!v[0]) 
  {
   var b=GetV(v[1]);
   SetV(v[1],c+b.substring(4));
  }
  var l=Stock[GetStockI(c)+5];
  if(q<l) q=l;
  SetV(c,v[2]+Num2Let(r?q:MAX_ITMS)); 
 }
 else if(v[0])
 {
  var b=GetV(v[1]);
  SetV(c,"");
  SetV(v[1],v[2]+b.substring(4));  
 }
 return r;
}

function AddItm(c,q)
{
 SetItm(c,q+Let2Num(GetV(c).substring(4)));
 SetVbm(1);
 BsktI(0);
 ItmSel(c);
 scrollTo(0,0);
 return false;
}

function EmptyBskt()
{
 var b=GetV("bskt");
 if(b!="") do{
  var n=b.substring(0,4);
  b=GetV(n);
  SetV(n,"");
 } while(n!="bskt");
}

function GetStockI(n)
{
 var i=0
 while(i<Stock.length)
 {
  if(n==Stock[i]) return i;
  i+=SNTRY;
 }
 return -1;
}

function GetPrice(p)
{
 var q=p%100;
 p-=q;
 q="00"+q;
 p/=100;
 if(cur==15) return Currs[16]+p;
 return Currs[cur+1]+p+"."+q.substring(q.length-2);
}

function ItmSel(i)
{
 SetV("citm",i);
 ShowBskt();
 Qty().value="";
 Qty().select();
 return false;
}

function goStock(i)
{
 if(!gx) ItmSel(Stock[i]);
 return gTo(Stock[i+6]);
}

function gTo(v)
{
 if(gx) return false;
 IPg(0);
 var n=location.href;
 if(n.lastIndexOf("/")==n.lastIndexOf("/"+v)) return false;
 gx=ot=(op=0)+1;
 os='0';
 if(v.indexOf("/")<0) v+=".htm";
 else v+="index.html";
 Exit(v);
 return false;
}

function TxBskt()
{
 var n;
 var b=GetV("bskt");
 var t="<TD ALIGN=RIGHT>";
 var u="</TD>";
 var k=pp[1];
 var s=0;
 var x="";
 var l=GetV("citm");
 citm="";
 if(b!="") while((n=b.substring(0,4))!="bskt")
 {
  var i=GetStockI(n);
  var p=Stock[i+3];
  b=GetV(n);
  var q=Let2Num(b.substring(4));
  var o=Stock[i+5];
  x+="<TR BGCOLOR=#EFD8D8><TD><table><tr><td>"+hrf("Select item")+"'return ItmSel("+'"'+n+'");'+"'><img src='i/Itm00";
  if(l==n) 
  {
   citm=n;
   x+="1";
  }
  else x+="0";
  x+=".jpg' align='MIDDLE' border=0 width=20 height=20></a></td><td>"+hrf("View."+Stock[i+1])+"'goStock("+i+");return false'><FONT SIZE=-1>"+Stock[i+1]+"</FONT></a></td></tr></table>"+u;
  x+=t+q+"&nbsp;@"+u+t+GetPrice(p*o);
  s+=p*q;
  if(o!=1) x+="<FONT SIZE=-1>/"+o+"</FONT>";
  x+="&nbsp;="+u+t+GetPrice(p*q)+u;
  x+="</TR>";
 }
 b=u+"</TR>";
 if(s)
 {
  if(s>=pp[3]) k=0;
  s+=k;
  x+="<TR BGCOLOR=#EFE4E8>"+t+"P&amp;P:</TD><TD>&nbsp;</TD><TD>&nbsp;"+u+t+(k?GetPrice(k):"FREE")+b;
  x+="<TR BGCOLOR=#F0B08D>"+t+"TOTAL:</TD><TD>&nbsp;</TD><TD>&nbsp;"+u+t+"<B><FONT SIZE=+1>"+GetPrice(s)+"</FONT></B>"+b;
 }
 else x+="<TR ALIGN=CENTER BGCOLOR=#F0B08D><TD COLSPAN=4><B><FONT SIZE=+2>&nbsp;<br>Your&nbsp;basket&nbsp;is&nbsp;empty<br>&nbsp;</FONT>Click on Info... (above) for help."+b;
 return x;
}

function FetchBskt(v)
{
 var l="";
 var n;
 var c=1;
 var b=GetV("bskt");
 var t=0;
 if(b!=l) while((n=b.substring(0,4))!="bskt")
 {
  var i=GetStockI(n);
  var p=Stock[i+3-v];
  if(v) p-=Stock[i+4];
  b=GetV(n);
  var q=Let2Num(b.substring(4));
  l+="&item_name_"+c+"="+Stock[i+1];
  l+="&quantity_"+c+"="+q;
  t+=p*q;
  l+="&amount_"+c+"="+p/100;
  c++;
 }
 if(l=="") return l;
 if(t<pp[3-v])
 {
  l="&handling_cart="+pp[1-v]/100+l;
  t+=pp[1-v];
 }
 return l+"&t="+t/100;
}

function WLd(a,n,t)
{
 return window.open("goto.htm?"+t+"@"+a,n);
}

function SendBskt(p)
{
 var l=FetchBskt(p);
 if(l=="")
 {
  SetVbm(1);
  ShowBskt();
  return;
 }
 if(!p)
 {
  var i=0;
  l=l.substring(0,l.indexOf("&t="))+"&";
  while(i*SNTRY<Stock.length)
  {
    i++;
    document.forms[0].elements["item_name_"+i].value="";
    document.forms[0].elements["quantity_"+i].value="0";
  }

  WLd("$paypal.com","paypal","PayPal secure checkout");

  document.forms[0].elements["handling_cart"].value="0";
  i=0;
  while(l!="&")
  {
    var c=l.indexOf("=");
    var n=l.substr(1,c-1);
    l=l.substr(c+1);
    c=l.indexOf("&");
    document.forms[0].elements[n].value=l.substr(0,c);
    l=l.substr(c);
  }
  
  document.forms[0].elements["currency_code"].value=Currs[cur];
  document.forms[0].submit();
 }
 else
 {
  var q;
  var n="[insert your name]\n[insert your address and country]\n[insert your postcode or zip]\n\nPlease supply the following items to the above address:\n\n";
  var y=cur;
  cur=-1;
  Currs[0]+=" ";
  p="FREE";
  while(l.charAt(0)=="&")
  {
   var c=l.charAt(1);
   l=l.substring(l.indexOf("=")+1);
   var i=l.indexOf("&");
   if(i<0) i=l.length;
   var v=Math.floor(l.substring(0,i)*100);
   switch(c)
   {
   case 't':
    n+='P&P: '+p+'\n\nOnce I receive my order confirmation I will send a cheque / postal order for '+GetPrice(v)+' (with order code written on the back) made payable to "At Hand Creations".\nPlease send my order code and confirmation to this email address\n[insert if different to the one you are mailing from]';
    break;
   case 'h':
    p=GetPrice(v);
    break;
   case 'q':
    q=v/100;
    break;
   case 'a':
    n+=" *"+q+" = "+GetPrice(v*q)+"\n";
    break;
   default:
    n+=l.substring(0,i);
   }
   l=l.substring(i);
  }
  Currs[0]="GBP";
  cur=y;
  location="mailto:order@athand.org?subject=e-mail order&body="+escape(n);
 }
}

function Qty()
{
 return NS?d.bskto.document.forms[1][0]:d.forms[1][0];
}

function SetNewQty()
{
 var v=Qty().value;
 if(v!="")
 { 
  v=Number(v);
  if(v!=NaN&&v>=0&&v<=MAX_ITMS && citm!="")  
  {
   SetItm(citm,v);
   if(!v) SetV("citm","");
   ShowBskt();
  }
 }
 return false;
}

function ShowBskt()
{
 var x='<TABLE BORDER=0 BGCOLOR=#FFFFFF CELLSPACING=0 CELLPADDING=0><TR><TD>';
 x+='<TABLE WIDTH=550 CELLPADDING=4 CELLSPACING=2 BORDERCOLOR=black BGCOLOR=#FFFFFF BORDER=1">';
 x+=TxBskt();
 x+='</TABLE></TD></TR></TABLE>';
 SetSrc(GetEle("bsktc"),x);
}

function BsktI(i)
{
 IChg("Bskt","ViewB00"+(i==1?2:vbm|i?0:1));
 IChg("ChkO","ViewB00"+(i==2?4:3));
 IChg("EOrd","ViewB00"+(i==3?7:6));
 IChg("vbskt",i?"w.gif":"ViewB005");
}

function SetVbm(i)
{
 var e=GetEle("bskto");
 var s=Sty(e);
 var c=GetSty("bsktc");
 if(gx) return;
 if(i)
 {
  cpm=0;
  Anim("curd",196,"0",1);
 }
 vbm=i;
 s.left=c.left=64;
 s.top=58;
 c.top=58+yh(e);
 s.visibility=c.visibility=i?show:hide;
}

function TxAdd(n,v,q,o)
{
 while(df(o))
 {
  if(GetView(o.substring(0,2))) v=o.substring(2,6);
  o=o.substring(6);
 }
 var i=GetStockI(v);
 if(i<0) return "Sorry: This item is <b>not currently available</b>";
 var x=Stock[i+1]+"&nbsp;@&nbsp;";
 var p=Stock[i+3];
 o=Stock[i+4]/Stock[i+2];
 i=Stock[i+5];
 p*=i;
 x+=GetPrice(p);
 if(o)
 {
  p=Math.round(p/(1-o));
  o=x.indexOf("@")+7;
  x=x.substring(0,o)+"<strike>"+GetPrice(p)+"</strike><font color=#E00000> "+x.substring(o);
 }
 if(i!=1) x+="<FONT SIZE=-1>/"+i+"</FONT>";
 x+="&nbsp;"+TxBox(n,"AddB000","Add to your basket",1,40,32,
  'AddItm("'+v+'",'+q+');', 'IChg("'+n+'","AddB001");','IChg("'+n+'","AddB000");');
 if(o) x+="<b>&nbsp;save!</b></font>";
 return "<FONT SIZE=+1>"+x+"</FONT>";
}

function CPg(p)
{
 if(gx) p=0;
 cpm=p;
 SetVbm(0);
 BsktI(0);
 Anim("curd",196,p?32:"0",14,196,p?"0":32);
}
function IPg(p)
{
 if(gx) p=0;
 SetVbm(0);
 BsktI(0);
 if(itg) Anim(itg==1?"sinf":"ethic",64,"0",14,64,58);
 itg=p;
 if(itg) Anim(itg==1?"sinf":"ethic",64,58,14,64,"0");
}

function Sat(n,x,y,w,s)
{
 var t="width:"+w+"px";
 var g=d_;
 if(s)
 {
  g='<div';
  if(NS) g+="><layer width="+w+" left="+x+" top="+y;
  else t+=";position:absolute;left:"+x+"px;top:"+y+"px";
  g+=" id=";
 }
 g+='"'+n+'"';
 if(!NS) g+=' style="'+t+'"';
 return g;
}

function SetBskt()
{
 var x='"sinf">';
 x+="<TABLE WIDTH=550 BGCOLOR=#F3DACD BORDERCOLOR=BLACK BORDER=1 CELLSPACING=0 CELLPADDING=6><TR><TD>";
 x+="<B><U>Placing items in your basket</U></B><BR>Click on the <img src='i/AddB000.jpg' border=1 width=40 height=32> button of any item you want to order. It will be added to your basket. The contents of your basket will be displayed.";
 x+="<br>Click on <b>'view basket'</b> at any time to show or hide the contents. Items can be removed and their quantities changed while <b>'view basket'</b> is activated.";
 x+="<br>&nbsp;<br>Once you're ready to make a purchase, Choose <b>'check out'</b> or <b>'email order'</b>";
 x+="<br><TABLE CELLSPACING=0 CELLPADDING=4 BORDER=0><TR><TD><img src='i/ViewB003.jpg' border=1 width=64 height=56></TD><TD>Click on the <b>'check out'</b> button if you want to pay online using a credit or debit card or a PayPal account. Please wait while your are transfered to the secure PayPal site where these forms of online payment are handled.</TD></TR>";
 x+="<TR><TD><img src='i/ViewB006.jpg' border=1 width=64 height=56></TD><TD>Click on the <b>'email order'</b> button if you want to pay (&pound; only) by cheque or postal order, or you are placing an order for somebody else. Your basket's items will be listed in an email."+' Complete your details in the email and click to <b>send</b> it. We will return an order confirmation to you and supply an <b>order code.</b> Write the <b>order code</b> clearly on the back of a cheque made payable to "At Hand Creations" and post it to us. Once cleared, your items can be delivered.</TD></TR></TABLE>';
 x+="<P><B><U>Currencies</U></B> Click on the <font face='tahoma' color=#CFB000><b>&pound;&euro; select yours $&yen;</b></font> option (top) to select your currency. Posted orders are always in Pounds Sterling.";
 x+="<P><B><U>VAT</U></B> Where VAT is chargable it is included in the price so there's nothing extra to pay.";
 x+="<P><B><U>Delivery</U></B> Cost: currently "+GetPrice(pp[1])+", or FREE if your order is "+GetPrice(pp[3])+" or more.";
 x+="<BR>Time: Normally items will arrive within a week but please allow 2 weeks. We use the Royal Mail postal service.";
 x+="<P><B><U>Refunds</U></B> In 3 years, nobody has ever asked for one, so we're confident that you will appreciate the quality of At Hand creations. However, if any item you receive isn't what you thought it would be, please send it back within 16 days for a full refund";
 x+="<P><B><U>Ethical considerations</U></B> As a small Christian organisation, we apply ethics beyond a written code. For examples of our ethical practice, "+hrf("Ethical examples")+"'IPg(2);return false'>Click <b>here.</b></a>";
 x+="</TD></TR></TABLE>";
 d.write(d_+x+_d);
 
 x='"ethic"><TABLE WIDTH=550 BGCOLOR=#FBE7E0 BORDERCOLOR=BLACK BORDER=1 CELLSPACING=0 CELLPADDING=6><TR><TD><p align=center><B><U>Examples of ethics in practice</U></B>';
 x+="<p>The printing company we used for our first production commented on how well we had ensured minimal waste. Since then, our research and investment into new printing solutions has enabled us to print many things 'on demand'. Production is more expensive but it's <b>better for the environment,</b> which is more important!";
 x+="<p>We try to minimise packaging used for transportation. Packaging our suppliers use to transport materials to us is re-used by us as we transport items to our customers. Could you also <b>re-use</b> the packaging?";
 x+="<p>We use an eco-freindly supplier who, among other things, provide 100% <b>recycled</b> envelopes. We choose to use suppliers who put the <b>environment before money.</b>";
 x+="<p>We also choose to use suppliers and financial institutions who put <b>people before money:</b> that's why we chose to set up 'At Hand Creations' using a Building Society for our banking!";
 x+="<p>We strongly support <b>Fair Trade:</b> We avoid companies who we believe to be 'unfair' in the way they trade - oh, and we use Fair Trade tea and coffee! We create and promote initiatives that <b>aid the third world.</b> We want to make a positive impact.";
 x+="<p align=center>"+hrf("Shopping info")+"'IPg(1);return false'><b>&lt; Back</b></a></TD></TR></TABLE>";
 d.write(d_+x+_d);

 x=Sat("bsktb",64,0,550,GetView("iB"));
 x+='>'+TxBox("SInf","InfoB000","Show shopping info and ethics",1,64,56,
 'IPg(itg?0:1)','IChg("SInf","InfoB001");','IChg("SInf","InfoB000");');
 x+=TxBox("Bskt","ViewB001","View contents of your basket",1,64,56,
 'SetVbm(1-vbm)','BsktI(1);','BsktI(0);');
 x+=TxBox("","PayPal","Select currency of your card or Paypal account",1,284,56,
 'CPg(1-cpm)');
 x+=TxBox("ChkO","ViewB003","Take your basket to the checkout",1,64,56,
 'SendBskt(0)','BsktI(2);','BsktI(0);');
 x+=TxBox("EOrd","ViewB006","Email your order",1,64,56,
 'SendBskt(1)','BsktI(3);','BsktI(0);');
 x+=_d+d_+'"bskto">';
 x+='<TABLE BORDERCOLOR=BLACK BGCOLOR=#FFFFFF CELLPADDING=0 CELLSPACING=0 BORDER=1><TR><TD>';
 x+='<table width=546 cellpadding=0 cellspacing=0><tr><td align=center><img src="i/ViewB005.jpg" name="vbskt" width=64 height=56 border=0></td><td nowrap="nowrap">';
 x+="Click an item's name to View it<br>";
 x+="Click an item's button to Select it<FORM ONSUBMIT='return SetNewQty()'>";
 x+='Change its Quantity here:  <INPUT SIZE=4 MAXLENGTH=4 TYPE="TEXT" AUTOCOMPLETE="OFF" ONFOCUS="if(!vbm) this.blur();" ONCHANGE="SetNewQty();">(<b>0 removes</b> item)</FORM>';
 x+='</td></tr></table>';
 x+='</TD></TR></TABLE>';
 x+=_d+d_+'"bsktc">'+_d;

 x+=d_+'"curd">';
 x+='<TABLE WIDTH=286 BORDERCOLOR=BLACK BGCOLOR=#EFD8D8 CELLPADDING=6 CELLSPACING=0 BORDER=1>';
 x+='<TR><TD COLSPAN=2 BGCOLOR=#FFF8BF>Please select your currency then wait for the page to reload:</TR>';
 var i=0;
 while(i<Currs.length)
 {
  x+="<TR><TD>"+hrf("Select currency")+"'return CurChg("+i+")'><IMG SRC='i/Itm00"+(i==cur?1:0)+".jpg' align='MIDDLE' border=0 width=20 height=20></A>&nbsp;<B>"+Currs[i+1]+'</B></TD><TD>'+Currs[i+2]+'</TD></TR>';
  i+=3;
 }
 x+='<TR><TD COLSPAN=2 BGCOLOR=#FFFFFF>Prices in currencies other than Pounds Sterling can vary daily depending on exchange rates.</TR></TABLE>'+_d;
 d.write(x);
}

function CurChg(i)
{
 if(i!=cur)
 {
  SetV("cury",i/3);
  location.replace("r.php?"+location.href);
 }
 return false;
}

function BsktIn()
{
 if(!GetView("iB"))
 {
  Anim("bsktb",64,0,15,"0",-60);
  SetView("iB");
 }
}


document.write('<div style="display:none"><form target="paypal" '
+'action="https:\/\/www.paypal.com\/cgi-bin\/webscr" method="post">'
+'<input type="hidden" name="upload" value="1">'
+'<input type="hidden" name="cmd" value="_cart">'
+'<input type="hidden" name="business" value="pay@athand.org">'
+'<input type="hidden" name="no_shipping" value="2">'
+'<input type="hidden" name="no_note" value="1">'
+'<input type="hidden" name="lc" value="GB">'
+'<input type="hidden" name="return" value="http://www.athand.org/complete.htm">'
+'<input type="hidden" name="cancel_return" value="http://www.athand.org/cancel.htm">'
+'<input type="hidden" name="currency_code" value="GBP">'
+'<input type="hidden" name="cbt" value="Continue">'
+'<input type="hidden" name="handling_cart" value="0">');
var i=0;
while(i*SNTRY<Stock.length)
{
  i++;
  document.write('<input type="hidden" name="item_name_'+i+'" value="">'
+'<input type="hidden" name="quantity_'+i+'" value="0">'
+'<input type="hidden" name="amount_'+i+'" value="50.00">');
}
document.write('<\/form><\/div>');


