/* author: WebLink4u Limited */
/* Creation date: 15/10/2005 */
today=new Date();
today.setTime(today.getTime() + (3600000));
today=today.toGMTString();
currentdate=new Date();
currentdate=currentdate.toLocaleString();
index = document.cookie.indexOf('AlwynGlName');
if (index > -1) {
   countbegin=(document.cookie.indexOf('=',index)+1);
   countend=document.cookie.indexOf(';',index);
   if(countend==-1) {
      fulllist='';
   } else {
      fulllist=document.cookie.substring(countbegin,countend);
   }
} else {
   fulllist='';
}
if(fulllist.length < 1) {
   document.cookie='AlwynGlCode=.; expires='+today;
   document.cookie='AlwynGlName=.; expires='+today;
   document.cookie='AlwynGlWeight=.; expires='+today;
   document.cookie='AlwynGlTaxable=.; expires='+today;
   document.cookie='AlwynGlPrice=.; expires='+today;
   document.cookie='AlwynGlExtraFields=.; expires='+today;
   document.cookie='AlwynGlAdvanced=.; expires='+today;
   document.cookie='AlwynGlQuantity=.; expires='+today;
   document.cookie='TheCurrency=1; expires=Friday, 31-Dec-2010 08:00:00 GMT';
   document.cookie='JShopReferrer=.; expires='+today;
}

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]='United Kingdom Pounds'; currencyDecimals[1]='2'; currencyPre[1]='£'; currencyMiddle[1]='.'; currencyPost[1]='';  
    function goBuy() {
        ilist='';
        ilist=ilist+retrieveCookie('AlwynGlCode',0,0)+'^';
        ilist=ilist+retrieveCookie('AlwynGlName',0,0)+'^';
        ilist=ilist+retrieveCookie('AlwynGlWeight',0,0)+'^';
        ilist=ilist+retrieveCookie('AlwynGlTaxable',0,0)+'^';
        ilist=ilist+retrieveCookie('AlwynGlPrice',0,0)+'^';
        ilist=ilist+retrieveCookie('AlwynGlExtraFields',0,0)+'^';
        ilist=ilist+retrieveCookie('AlwynGlAdvanced',0,0)+'^';
        ilist=ilist+retrieveCookie('AlwynGlQuantity',0,0)+'^';
        ilist=ilist+retrieveCookie('TheCurrency',0,0)+'^';
        ilist=ilist+retrieveCookie('JShopReferrer',0,0)+'^';
        ilist=changeUnwanted(ilist);
        ilist=escape(ilist);
        ilist=changePercent(ilist);
        if (top.name != '') {
             window.open('buy.php',ilist);
        } else {
             top.name=ilist;
             top.location='buy.php';
        }
    }

function changeUnwanted(tstring) {
    nstring='';
    for (var i=0; i <= tstring.length; i++) {
        nchar=tstring.charAt(i);
        if (nchar=='*') { nchar='!&1'; }
        if (nchar=='+') { nchar='!&2'; }
        if (nchar=='@') { nchar='!&3'; }
        if (nchar=='.') { nchar='!&4'; }
        if (nchar=='/') { nchar='!&5'; }
        if (nchar=='-') { nchar='!&6'; }
        nstring=nstring+nchar;
    }
    return nstring;
}
function changePercent(tstring) {
    nstring='';
    for (var i=0; i <= tstring.length; i++) {
        nchar=tstring.charAt(i);
        if (nchar=='%') { nchar='_'; }
        nstring=nstring+nchar;
    }
    return nstring;
}

function popupImage(imagename,imagewidth,imageheight) {
   apopup=window.open(imagename,'jsppopupimage','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=550,height=500,left=20,top=10');
}
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);
    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 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);
    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);
    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);
    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 checkAdvanced(adv,advField0,advField1,advField2,advField3,advField4,advField5,advField6,advField7,advField8,advField9,advField10) {
     newAdv='';advlist=0;
    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 (field0!='none' && advField0 != field0) applicable=false;
            if (field1!='none' && advField1 != field1) applicable=false;
            if (field2!='none' && advField2 != field2) applicable=false;
            if (field3!='none' && advField3 != field3) applicable=false;
            if (field4!='none' && advField4 != field4) applicable=false;
            if (field5!='none' && advField5 != field5) applicable=false;
            if (field6!='none' && advField6 != field6) applicable=false;
            if (field7!='none' && advField7 != field7) applicable=false;
            if (field8!='none' && advField8 != field8) applicable=false;
            if (field9!='none' && advField9 != field9) applicable=false;
            if (field10!='none' && advField10 != field10) applicable=false;
            if (applicable==true) {
                newAdv = newAdv+ '{'+field0+'!'+field1+'!'+field2+'!'+field3+'!'+field4+'!'+field5+'!'+field6+'!'+field7+'!'+field8+'!'+field9+'!'+field10+'!'+advFrom+'!'+advTo+'!'+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) field2 = adv.substring(advstart, j);
            if (thisadv==4) field3 = adv.substring(advstart, j);
            if (thisadv==5) field4 = adv.substring(advstart, j);
            if (thisadv==6) field5 = adv.substring(advstart, j);
            if (thisadv==7) field6 = adv.substring(advstart, j);
            if (thisadv==8) field7 = adv.substring(advstart, j);
            if (thisadv==9) field8 = adv.substring(advstart, j);
            if (thisadv==10) field9 = adv.substring(advstart, j);
            if (thisadv==11) field10 = adv.substring(advstart, j);
            if (thisadv== 12) advFrom=adv.substring(advstart,j);
            if (thisadv== 13) advTo=adv.substring(advstart,j);
            thisadv++;advstart=j+1;
        }
    }
    if (newAdv=='') newAdv='none';
    return newAdv;
}
    function buyItem(newCode,newItem,newPrice,newTaxable,newWeight,newField0,newField1,newField2,newField3,newField4,newField5,newField6,newField7,newField8,newField9,newField10,newAP,newQuantity) {
        if(newQuantity<=0) {
            rc = alert('The quantity entered is incorrect');
        } else {
            if (confirm('Add '+newQuantity+' x '+newItem+' to basket? ')) {
                 if (newAP!='none') {
                     newAP=checkAdvanced(newAP,newField0,newField1,newField2,newField3,newField4,newField5,newField6,newField7,newField8,newField9,newField10);
                 }
                 amended = false;
                 newItemList=''; itemlist=0;
                 for (var i=1;i<=retrieveCookieCount('AlwynGlCode');i++) {
                      theCode=retrieveCookie('AlwynGlCode',i,0);
                      theItem=retrieveCookie('AlwynGlName',i,0);
                      theQuantity=retrieveCookie('AlwynGlQuantity',i,0);
                              theField0 = retrieveCookie('AlwynGlExtraFields',i,1);
                              theField1 = retrieveCookie('AlwynGlExtraFields',i,2);
                              theField2 = retrieveCookie('AlwynGlExtraFields',i,3);
                              theField3 = retrieveCookie('AlwynGlExtraFields',i,4);
                              theField4 = retrieveCookie('AlwynGlExtraFields',i,5);
                              theField5 = retrieveCookie('AlwynGlExtraFields',i,6);
                              theField6 = retrieveCookie('AlwynGlExtraFields',i,7);
                              theField7 = retrieveCookie('AlwynGlExtraFields',i,8);
                              theField8 = retrieveCookie('AlwynGlExtraFields',i,9);
                              theField9 = retrieveCookie('AlwynGlExtraFields',i,10);
                              theField10 = retrieveCookie('AlwynGlExtraFields',i,11);
                      if (theCode==newCode && theItem==newItem  && theField0 == newField0 && theField1 == newField1 && theField2 == newField2 && theField3 == newField3 && theField4 == newField4 && theField5 == newField5 && theField6 == newField6 && theField7 == newField7 && theField8 == newField8 && theField9 == newField9 && theField10 == newField10) {
                           amended=true;
                           tempquantity=eval(theQuantity)+eval(newQuantity);
                           changeCookieValue('AlwynGlQuantity',i,tempquantity);
                      }
                 }
                 if (amended==false) {
                    addToCookie('AlwynGlCode',newCode);
                    addToCookie('AlwynGlName',newItem);
                    addToCookie('AlwynGlPrice',newPrice);
                    addToCookie('AlwynGlWeight',newWeight);
                    addToCookie('AlwynGlTaxable',newTaxable);
                    addToCookie('AlwynGlExtraFields',newField0+'~'+newField1+'~'+newField2+'~'+newField3+'~'+newField4+'~'+newField5+'~'+newField6+'~'+newField7+'~'+newField8+'~'+newField9+'~'+newField10+'~');
                    addToCookie('AlwynGlAdvanced',newAP);
                    addToCookie('AlwynGlQuantity',newQuantity);
                 }
             }
         }
     }

function flipImage(imgname,imgsrc) {
    document.images[imgname].src=imgsrc;
}