currencyCode = new Array(1); currencyName = new Array(1); currencyDecimals = new Array(1); currencyPre = new Array(1); currencyMiddle = new Array(1); currencyPost = new Array(1);
currencyCode[1]='GBP'; currencyName[1]='GBP'; currencyDecimals[1]='2'; currencyPre[1]='£'; currencyMiddle[1]='.'; currencyPost[1]='';

today=new Date();
today.setTime(today.getTime() + (604800000));
today=today.toGMTString();
currentdate=new Date();
currentdate=currentdate.toLocaleString();

numFields=0;
function addFiller(curnum) {
    newnum=parseInt(curnum);
    if (newnum<10) return '00'+newnum;
    if (newnum<100) return '0'+newnum;
    return newnum;
}
function nextField() {
    numFields++;
    return addFiller(numFields)+'-';
}
shipping = new Array(60);
shippingcountries = new Array(3);
shipping[0] = 1;
shipping[1] = 10;
shipping[2] = "3.5~";
shipping[3] = 1;
shipping[4] = 10.01;
shipping[5] = 15;
shipping[6] = "4~";
shipping[7] = 1;
shipping[8] = 15.01;
shipping[9] = 20;
shipping[10] = "4.5~";
shipping[11] = 1;
shipping[12] = 20.01;
shipping[13] = 25;
shipping[14] = "5~";
shipping[15] = 1;
shipping[16] = 25.01;
shipping[17] = 500;
shipping[18] = "5.5~";
shipping[19] = 1;
shipping[20] = 1;
shipping[21] = 10;
shipping[22] = "2~";
shipping[23] = 2;
shipping[24] = 10.01;
shipping[25] = 15;
shipping[26] = "2.5~";
shipping[27] = 2;
shipping[28] = 15.01;
shipping[29] = 20;
shipping[30] = "3~";
shipping[31] = 2;
shipping[32] = 20.01;
shipping[33] = 25;
shipping[34] = "3.5~";
shipping[35] = 2;
shipping[36] = 25.01;
shipping[37] = 500;
shipping[38] = "4~";
shipping[39] = 2;
shipping[40] = 1;
shipping[41] = 10;
shipping[42] = "4.5~";
shipping[43] = 3;
shipping[44] = 10.01;
shipping[45] = 15;
shipping[46] = "5~";
shipping[47] = 3;
shipping[48] = 15.01;
shipping[49] = 20;
shipping[50] = "5.5~";
shipping[51] = 3;
shipping[52] = 20.01;
shipping[53] = 25;
shipping[54] = "6~";
shipping[55] = 3;
shipping[56] = 25.01;
shipping[57] = 500;
shipping[58] = "6.5~";
shipping[59] = 3;
shippingcountries[1] = "Europe";
shippingcountries[2] = "United Kingdom";
shippingcountries[3] = "Rest of the World";

    singleshipping='';
    function recalculateShipping() {
        found=false;
        thistotal=0;
            compfield=primaryfield;
        for(var i=0; i<= 59; i=i+4) {
            if(found==false) {
                countrylist=shippingcountries[shipping[i+3]]+',';
                countbegin=0;
                countend=countrylist.length;
                itemstart=0;
                for (var j=0; j<=countrylist.length;j++) {
                    if (countrylist.substring(j,j+1)==',') {
                        thiscountry=countrylist.substring(itemstart,j);
                        itemstart=j+1;
                        if (thiscountry.toLowerCase() == compfield.toLowerCase() && found==false) {
                            if(shipping[i] <= totalforshipping && shipping[i+1] >= totalforshipping) {
                                thistotal=getPrice(shipping[i+2]);
                                found=true;
                            }
                        }
                        if (thiscountry=='-others-' && compfield != 'none' && compfield != '') {
                            if(shipping[i] <= totalforshipping && shipping[i+1] >= totalforshipping) {
                                thistotal=getPrice(shipping[i+2]);
                            }
                        }
                    }
                }
            }
        }
        thistotal=eval(thistotal);
        document.basketform.showshipping.value = showPriceSingle(thistotal);
        document.basketform.ShippingTotal.value = showPricePlain(thistotal);
        shippingtotal=thistotal;
        document.basketform.showtotal.value = showPriceSingle(thistotal+totprice);
        document.basketform.ShippingTotal.value = showPricePlain(thistotal);
        document.basketform.amount.value = showPricePlain(thistotal+totprice);
        singleshipping=""+"";
	document.basketform.desc.value=singlefield+singletax+singleshipping;
	
    }

function getCurrency() {
    index = document.cookie.indexOf('TheCurrency');
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    theCurrency=document.cookie.substring(countbegin,countend);
    if (theCurrency=='') { theCurrency=1; document.cookie='TheCurrency=1; expires=Friday, 31-Dec-2050 08:00:00 GMT';}
    return theCurrency;
}
function showPrice(pricestring) {
    index = document.cookie.indexOf('TheCurrency');
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    theCurrency=document.cookie.substring(countbegin,countend);
    if (theCurrency=='') { theCurrency=1; document.cookie='TheCurrency=1; expires=Friday, 31-Dec-2050 08:00:00 GMT';}
    thisitem=0;
    itemstart=0;
    theprice=0;
    for (var i=0; i<pricestring.length; i++) {
       if (pricestring.substring(i,i+1)=='~') {
          thisitem++;
          if (thisitem==eval(theCurrency)) {
             theprice=pricestring.substring(itemstart,i);
          }
          itemstart=i+1;
       }
    }
    return presentValue(theprice,currencyDecimals[theCurrency],currencyPre[theCurrency],currencyMiddle[theCurrency],currencyPost[theCurrency]);
}
function showPriceTax(pricestring,taxtype) {
    index = document.cookie.indexOf('TheCurrency');
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    theCurrency=document.cookie.substring(countbegin,countend);
    if (theCurrency=='') { theCurrency=1; document.cookie='TheCurrency=1; expires=Friday, 31-Dec-2050 08:00:00 GMT';}
    thisitem=0;
    itemstart=0;
    theprice=0;
    for (var i=0; i<pricestring.length; i++) {
       if (pricestring.substring(i,i+1)=='~') {
          thisitem++;
          if (thisitem==eval(theCurrency)) {
             theprice=pricestring.substring(itemstart,i);
          }
          itemstart=i+1;
       }
    }
    theprice=eval(theprice)+(theprice*(taxtype/100));    return presentValue(theprice,currencyDecimals[theCurrency],currencyPre[theCurrency],currencyMiddle[theCurrency],currencyPost[theCurrency]);
}
function showPriceSingle(pricestring) {
    index = document.cookie.indexOf('TheCurrency');
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    theCurrency=document.cookie.substring(countbegin,countend);
    if (theCurrency=='') { theCurrency=1; document.cookie='TheCurrency=1; expires=Friday, 31-Dec-2050 08:00:00 GMT';}
    return presentValue(pricestring,currencyDecimals[theCurrency],currencyPre[theCurrency],currencyMiddle[theCurrency],currencyPost[theCurrency]);
}
function showPriceSingleTax(pricestring,taxtype) {
    index = document.cookie.indexOf('TheCurrency');
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    theCurrency=document.cookie.substring(countbegin,countend);
    if (theCurrency=='') { theCurrency=1; document.cookie='TheCurrency=1; expires=Friday, 31-Dec-2050 08:00:00 GMT';}
    pricestring=eval(pricestring)+(pricestring*(taxtype/100));    return presentValue(pricestring,currencyDecimals[theCurrency],currencyPre[theCurrency],currencyMiddle[theCurrency],currencyPost[theCurrency]);
}
function showPricePlain(pricestring) {
    index = document.cookie.indexOf('TheCurrency');
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    theCurrency=document.cookie.substring(countbegin,countend);
    if (theCurrency=='') { theCurrency=1; document.cookie='TheCurrency=1; expires=Friday, 31-Dec-2050 08:00:00 GMT';}
    return presentValue(pricestring,currencyDecimals[theCurrency],'',currencyMiddle[theCurrency],'');
}
function getPrice(pricestring) {
    index = document.cookie.indexOf('TheCurrency');
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    theCurrency=document.cookie.substring(countbegin,countend);
    if (theCurrency=='') { theCurrency=1; document.cookie='TheCurrency=1; expires=Friday, 31-Dec-2050 08:00:00 GMT';}
    thisitem=0;
    itemstart=0;
    theprice=0;
    for (var i=0; i<pricestring.length; i++) {
       if (pricestring.substring(i,i+1)=='~') {
          thisitem++;
          if (thisitem==eval(theCurrency)) {
             theprice=pricestring.substring(itemstart,i);
          }
          itemstart=i+1;
       }
    }
    return theprice;
}
    function presentValue(value,dp,pt,mt,at) {
        if(value<=0.9999) {
            newPounds='0';
        } else {
            newPounds=parseInt(value);
        }
        dec='1';
        for (var i=1; i<=dp;i++) {
            dec=dec+'0';
        }
        if (value>0) {
            newPence=Math.round((eval(value)+.000008 - newPounds)*(eval(dec)));
        } else {
            newPence=0;
        }
        compstring='9';
        for (var i=1; i <=dp-1;i++) {
            if (eval(newPence) <= eval(compstring)) newPence='0'+newPence;
            compstring=compstring+'9';
        }
        if (dp>0) {
            if (newPence==eval(dec)) { newPounds++; newPence=0; }
            newString=pt+newPounds+mt+newPence+at;
        } else {
            newString=pt+newPounds+at;
        }
        return (newString);
    }

function retrieveCookie(thecookie,thenumber,theadditional) {
    index = document.cookie.indexOf(thecookie);
    countbegin=(document.cookie.indexOf('=',index)+1);
    countend=document.cookie.indexOf(';',index);
    if(countend==-1) { countend=document.cookie.length; }
    fulllist=document.cookie.substring(countbegin,countend);
    if (thenumber==0) { return fulllist; }
    thisitem=0;
    newcookie='';
    itemstart=0;
    for(var i=0; i<fulllist.length;i++) {
        if (fulllist.substring(i,i+1)=='|') {
            thisitem++;
           itemvalue=fulllist.substring(itemstart,i);
           if (thisitem==thenumber) {
                if (theadditional==0) {
                    return itemvalue;
                } else {
                    itemstarttwo=0;
                    thisitemtwo=0;
                    for (var j=0; j<itemvalue.length; j++) {
                        if (itemvalue.substring(j,j+1)=='~') {
                            thisitemtwo++;
                            itemvaluetwo=itemvalue.substring(itemstarttwo,j);
                            if (thisitemtwo==theadditional) {
                                return itemvaluetwo;
                            }
                            itemstarttwo=j+1;
                        }
                    }
                }
            }
            itemstart=i+1;
        }
    }
    return '';
}
function addToCookie(thecookie,thevalue) {
    fulllist=retrieveCookie(thecookie,0,0);
    if (fulllist=='.') { fulllist=''; }
    fulllist=fulllist+thevalue+'|';
    document.cookie=thecookie+'='+fulllist+'; expires='+today;
}
function removeFromCookie(thecookie,thenumber) {
    fulllist=retrieveCookie(thecookie,0,0);
    thisitem=0;
    newcookie='';
    itemstart=0;
    for(var i=0; i<fulllist.length;i++) {
        if (fulllist.substring(i,i+1)=='|') {
            thisitem++;
            itemvalue=fulllist.substring(itemstart,i);
            if (thisitem!=thenumber) {
                newcookie=newcookie+itemvalue+'|';
            }
            itemstart=i+1;
        }
    }
    if (newcookie=='') { newcookie='.'; }
    document.cookie=thecookie+'='+newcookie+'; expires='+today;
}
function changeCookieValue(thecookie,thenumber,thevalue) {
    fulllist=retrieveCookie(thecookie,0,0);
    thisitem=0;
    newcookie='';
    itemstart=0;
    for(var i=0; i<fulllist.length;i++) {
        if (fulllist.substring(i,i+1)=='|') {
            thisitem++;
            itemvalue=fulllist.substring(itemstart,i);
            if (thisitem==thenumber) {
                itemvalue=thevalue;
            }
            newcookie=newcookie+itemvalue+'|';
            itemstart=i+1;
        }
    }
    document.cookie=thecookie+'='+newcookie+'; expires='+today;
}
function retrieveCookieCount(thecookie) {
   fulllist=retrieveCookie(thecookie,0,0);
   thisitem=0; newcookie=''; itemstart=0;
   for(var i=0; i<fulllist.length;i++) {
    if (fulllist.substring(i,i+1)=='|') {
        thisitem++;
        itemstart=i+1;
    }
   }
   return thisitem;
}
function showCurrency() {   index = document.cookie.indexOf('TheCurrency');   countbegin=(document.cookie.indexOf('=',index)+1);   countend=document.cookie.indexOf(';',index);   if(countend==-1) { countend=document.cookie.length; }   theCurrency=document.cookie.substring(countbegin,countend);   document.basketform.selectcurrency.selectedIndex=theCurrency-1;}function getAdvanced(adv,qty) {
     newAdv='';advlist=0;applicable=true;advnewprice='';
    for (var j=0;j<=adv.length;j++) {
            if (adv.substring(j,j+1) == '{') {
            thisadv=1;
            advstart=j+1;
        } else if (adv.substring(j,j+1) == '}') {
            advend=j;
            advPrice=adv.substring(advstart,advend);
            advlist++; applicable=true;
            if (applicable==true) {
                if (advFrom > 0 && advFrom > eval(qty)) applicable=false;
                if (advTo > 0 && advTo < eval(qty)) applicable=false;
                if (applicable==true) advnewprice=advPrice;
            }
        } else if (adv.substring(j,j+1)=='!') {
            if (thisadv==1) field0 = adv.substring(advstart, j);
            if (thisadv==2) field1 = adv.substring(advstart, j);
            if (thisadv== 3) advFrom=adv.substring(advstart,j);
            if (thisadv== 4) advTo=adv.substring(advstart,j);
            thisadv++;advstart=j+1;
        }
    }
    return advnewprice;
}
alltheitems=0;taxfield='';singletax='';singleshipping='';taxfield2='';shippingfile='';primaryfield='';secondaryfield='';singlefield='';
function showBasket() {
   totprice=0;shippingtotal=0;taxtotalone=0;taxtotaltwo=0;ordertotal=0;taxablestandard=0;taxablesecond=0;taxable=0;totalforshipping=0;
   document.writeln('<table width=600 bordercolor=C0C0C0 border=1 cellpadding=6 cellspacing=0>');
   document.writeln('<tr>');
   document.writeln("<th class=headerCode>Code</th>");
   document.writeln("<th class=headerItem>Item</th>");
   document.writeln("<th class=headerQty>Qty</th>");
   document.writeln("<th class=headerSummaryPrice>Cost Each</th>");
   document.writeln("<th class=headerSummaryPrice>Total Cost</th>");
   document.writeln("</tr>");
   for (var i=1;i<=retrieveCookieCount('MDMusicCode');i++) {
       theCode=retrieveCookie('MDMusicCode',i,0);
       theName=retrieveCookie('MDMusicName',i,0);
       theWeight=retrieveCookie('MDMusicWeight',i,0);
       theTaxable=retrieveCookie('MDMusicTaxable',i,0);
       thePrice=retrieveCookie('MDMusicPrice',i,0);
       theField1=retrieveCookie('MDMusicExtraFields',i,1);
       theField2=retrieveCookie('MDMusicExtraFields',i,2);
       theAP=retrieveCookie('MDMusicAdvanced',i,0);
       theQuantity=retrieveCookie('MDMusicQuantity',i,0);
       if (theAP!='none') {
           tempprice=getAdvanced(theAP,theQuantity);
           if (tempprice>'') { thePrice=tempprice; }
       }
       itemtotal=eval(theQuantity)*eval(getPrice(thePrice));
       totprice=totprice+itemtotal;
       if (theTaxable==0) taxablestandard=taxablestandard+itemtotal;
       if (theTaxable==1) taxablesecond=taxablesecond+itemtotal;
       totalforshipping=totalforshipping+itemtotal;
       singlefield=singlefield+""+theQuantity+"x"+theCode+".";
       document.writeln("<td class=itemProdCode>"+theCode+"</td>");
       document.writeln("<td class=itemName>"+theName+"</td>");
       document.writeln("<td class=itemQty>"+theQuantity+"</td>");
       document.writeln("<td class=itemSummaryPrice>"+showPrice(thePrice)+"</td>");
       document.writeln("<td class=itemSummaryPrice>"+showPriceSingle(itemtotal)+"<input type=hidden name='M_i"+i+"' value='"+theCode+", "+theName+", "+theQuantity+", "+getPrice(thePrice)+", "+showPricePlain(itemtotal)+"'></td>");
       document.writeln("</tr>");
   }
   alltheitems=i-1; 
   document.writeln("</table><br>");
   document.writeln("<input type=hidden name='item_number' value='"+singlefield+"'>");
   /*JB*/document.writeln('<table bordercolor=C0C0C0 border=0 width=600 cellpadding=0 cellspacing=0><tr><td align=right colspan=4>');
   /*JB*/document.writeln('<table bordercolor=C0C0C0 border=0 width=275 cellpadding=0 cellspacing=0>'); 
   document.writeln("<tr>");
   document.writeln("<td class=shipValue>Postage &amp; Packing <input type=text size=6 name=showshipping class=shipValue value="+showPriceSingle(0)+" onKeyPress='return false;' onKeyDown='return false;'><input type=hidden name='ShippingTotal'></td>");
   document.writeln("</tr>");
   document.writeln("<tr><td height=10></td></tr>");
   document.writeln("<tr>");
   document.writeln("<td class=totalValue>Total Due <input type=text size=10 name=showtotal class=totalValue value="+showPriceSingle(totprice)+" onKeyPress='return false;' onKeyDown='return false;'><input type=hidden name='amount' value='"+totprice+"'></td>");
   document.writeln("</tr>");
   document.writeln("</table>");
   /*JB*/document.writeln("</td></tr></table><br>");
}

function flipImage(imgname,imgsrc) {
    document.images[imgname].src=imgsrc;
}
function checkPurchaseFields() {
    return true;
}
function goSubmit() {    if (checkPurchaseFields()) { document.basketform.submit(); }}
function genid() {
 var ttime = 0;
 now = new Date();
 ttime = now.getTime();
 return ttime;
}
