function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

today=new Date();
today.setTime(today.getTime() + (900000));
today=today.toGMTString();
currentdate=new Date();
currentdate=currentdate.toLocaleString();
index = document.cookie.indexOf('TheBasketCode');
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='TheBasketCode=.; expires='+today;
   document.cookie='TheBasketName=.; expires='+today;
   document.cookie='TheBasketWeight=.; expires='+today;
   document.cookie='TheBasketTaxable=.; expires='+today;
   document.cookie='TheBasketPrice=.; expires='+today;
   document.cookie='TheBasketExtraFields=.; expires='+today;
   document.cookie='TheBasketAdvanced=.; expires='+today;
   document.cookie='TheBasketQuantity=.; 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() {
   sepchar='"';
   totprice=0;
   ppitems=0;
  
   for (var i=1;i<=retrieveCookieCount('TheBasketCode');i++) {
       theCode=retrieveCookie('TheBasketCode',i,0);
       theName=retrieveCookie('TheBasketName',i,0);
       theWeight=retrieveCookie('TheBasketWeight',i,0);
       theTaxable=retrieveCookie('TheBasketTaxable',i,0);
       thePrice=retrieveCookie('TheBasketPrice',i,0);
       theAP=retrieveCookie('TheBasketAdvanced',i,0);
       theQuantity=retrieveCookie('TheBasketQuantity',i,0);
       if (theAP!='none') {
           tempprice=getAdvanced(theAP,theQuantity);
           if (tempprice>'') { thePrice=tempprice; }
       }
       itemtotal=eval(theQuantity)*eval(getPrice(thePrice));
       totprice=totprice+itemtotal;
	   ppitems=ppitems+theQuantity+' x '+theName+' '+theCode+' '+theWeight+' &#8226 ';
     
   }
   
//add 3.99 postafe and 17.5% VAT
	if (totprice<=20) {vamount=(totprice*1.175)+1.50}
	else {vamount=(totprice*1.175)+3.99};
	
		if(vamount <6.5)	{ var answer = confirm("Our minimum order value is £5.00 inc VAT\r\rIf you wish to continue and pay the minimum price\rPlease Click OK\r\rTo stop this order and continue shopping\rPlease click Cancel");
				if (answer !=0) {vamount = 6.50}
				else
				return false;}
				
	if(vamount >=6.5){
				var totprice, vamount;
				totprice = Math.round( vamount * 100) / 100 ;


//window.location.href="https://www.paypal.com/xclick/business=paypal%402fi.sh&item_name='+ppitems+'&item_number=logos&amount='+totprice+'&no_note=1&currency_code=GBP&lc=GB&tax=0.00";
       
//old code 
window.open('https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal%402fi.sh&item_number=logos&amount='+totprice+'&no_note=1&currency_code=GBP&lc=GB&tax=0.00&item_name='+ppitems+'','', 'width=800,height=640,scrollbars=yes,status=yes,location=yes') ;

  
    }}
	
								//!nochex payment
	function goBuynochex() {
   sepchar='"';
   totprice=0;
   ppitems=0;
  
   for (var i=1;i<=retrieveCookieCount('TheBasketCode');i++) {
       theCode=retrieveCookie('TheBasketCode',i,0);
       theName=retrieveCookie('TheBasketName',i,0);
       theWeight=retrieveCookie('TheBasketWeight',i,0);
       theTaxable=retrieveCookie('TheBasketTaxable',i,0);
       thePrice=retrieveCookie('TheBasketPrice',i,0);
       theAP=retrieveCookie('TheBasketAdvanced',i,0);
       theQuantity=retrieveCookie('TheBasketQuantity',i,0);
       if (theAP!='none') {
           tempprice=getAdvanced(theAP,theQuantity);
           if (tempprice>'') { thePrice=tempprice; }
       }
       itemtotal=eval(theQuantity)*eval(getPrice(thePrice));
	   			
       totprice=totprice+itemtotal;
	   
	  
				
	   ppitems=ppitems+theQuantity+' x '+theName+' - ';
     
   }
   
       //! top.location='https://www.paypal.com/xclick/business=paypal%402fi.sh&item_name='+ppitems+'&item_number=logos&amount='+totprice+'&no_note=1&currency_code=GBP&lc=GB';
	   
 //  top.location = "https://www.nochex.com/nochex.dll/checkout?email=nochex@idealvideo.co.uk&amount="+totprice+"&ordernumber=Ideal Video DVDs&description="+ppitems+"&logo=https://secure.2fishproductions.com/~idealvid/images/idealvideo_header.gif" ;
   
   
   theUrl = 'https://www.nochex.com/nochex.dll/checkout?email=nochex@idealvideo.co.uk &amount='+totprice+'&ordernumber=Ideal Video DVDs&description='+ppitems+'&logo=http://www.idealvideo.co.uk/images/idealvideo_header.gif';

 window.location.href=theUrl;
   
   }
	
	
	

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 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 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) advFrom=adv.substring(advstart,j);
            if (thisadv== 2) advTo=adv.substring(advstart,j);
            thisadv++;advstart=j+1;
        }
    }
    return advnewprice;
}
function showBasket() {
   sepchar='"';
   totprice=0;
  document.writeln('<table bordercolor=FFFFFF border=1 width=500 cellpadding=5 cellspacing=5 align="center">');
document.writeln('<tr>');

   document.writeln("<td bgcolor=dddddd align=center><font face='Arial, Helvetica, sans-serif' size=3 color=000000><b>Name</b></font></td>");
   document.writeln("<td bgcolor=dddddd align=center><font face='Arial, Helvetica, sans-serif' size=3 color=000000><b>Quantity</b></font></td>");
   document.writeln("<td bgcolor=dddddd align=center><font face='Arial, Helvetica, sans-serif' size=3 color=000000><b>Cost Each</b></font></td>");
   document.writeln("<td bgcolor=dddddd align=center><font face='Arial, Helvetica, sans-serif' size=3 color=000000><b>Total Cost</b></font></td>");
   document.writeln("<td bgcolor=dddddd align=center><font face='Arial, Helvetica, sans-serif' size=3 color=000000><b>Action</b></font></td>");
   document.writeln("</tr>");
   for (var i=1;i<=retrieveCookieCount('TheBasketCode');i++) {
       theCode=retrieveCookie('TheBasketCode',i,0);
       theName=retrieveCookie('TheBasketName',i,0);
       theWeight=retrieveCookie('TheBasketWeight',i,0);
       theTaxable=retrieveCookie('TheBasketTaxable',i,0);
       thePrice=retrieveCookie('TheBasketPrice',i,0);
       theAP=retrieveCookie('TheBasketAdvanced',i,0);
       theQuantity=retrieveCookie('TheBasketQuantity',i,0);
       if (theAP!='none') {
           tempprice=getAdvanced(theAP,theQuantity);
           if (tempprice>'') { thePrice=tempprice; }
       }
       itemtotal=eval(theQuantity)*eval(getPrice(thePrice));
       totprice=totprice+itemtotal;

       document.writeln("<td bgcolor=EEEEEE align=center><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000>"+theName+"</font></td>");
	        
       document.writeln("<td bgcolor=EEEEEE align=center><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000><input type=text name='quant"+i+"' value='"+theQuantity+"' size=3></font></td>");
       document.writeln("<td bgcolor=EEEEEE align=center><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000>"+showPrice(thePrice)+"</font></td>");
       document.writeln("<td bgcolor=EEEEEE align=center><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000>"+showPriceSingle(itemtotal)+"</font></td>");
       document.writeln("<td bgcolor=EEEEEE align=center><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000><input type=button name='add"+i+"' onClick='removeItem("+i+");' value='Remove'></font></td>");
      document.writeln("</tr>")
   }
document.writeln("<tr>");
   document.writeln("<td bgcolor=EEEEEE align='right' colspan=3><font face='Arial, Helvetica, sans-serif' size=3 color=CC0000><b>Total Goods (inc Delivery)</b></font></td>");
   document.writeln("<td bgcolor=EEEEEE align=center><font face='Verdana, Arial, Helvetica, sans-serif' size=3 color=000000><b>"+showPriceSingle(totprice)+"</b></font></td>");
   document.writeln("<td bgcolor=EEEEEE align=center><font face='Verdana, Arial, Helvetica, sans-serif' size=2 color=000000>&nbsp;</font></td>");
   document.writeln("</tr>");
   document.writeln("</table><br>");
   document.writeln("<input type=button name='clearbasket' onClick='clearBasket();' value='Empty Basket'>&nbsp;");
   document.writeln("<input type=button name='updatebasket' onClick='updateBasket();' value='Update Basket'>");
   
   //variables to add record to db
   
   sepchar='"';
   totprice=0;
   ppitems=0;
  
   for (var i=1;i<=retrieveCookieCount('TheBasketCode');i++) {
       theCode=retrieveCookie('TheBasketCode',i,0);
       theName=retrieveCookie('TheBasketName',i,0);
       theWeight=retrieveCookie('TheBasketWeight',i,0);
       theTaxable=retrieveCookie('TheBasketTaxable',i,0);
       thePrice=retrieveCookie('TheBasketPrice',i,0);
       theAP=retrieveCookie('TheBasketAdvanced',i,0);
       theQuantity=retrieveCookie('TheBasketQuantity',i,0);
       if (theAP!='none') {
           tempprice=getAdvanced(theAP,theQuantity);
           if (tempprice>'') { thePrice=tempprice; }
       }
       itemtotal=eval(theQuantity)*eval(getPrice(thePrice));
       totprice=totprice+itemtotal;
	   ppitems=ppitems+theQuantity+' x '+theName+' '+theCode+' '+theWeight+' &#8226 ';
     
   }
   
       //ensures 2 decimal places
	   			vamount=(totprice*1.175);
				var totprice, vamount;
				totprice = Math.round( vamount * 100) / 100 ;

    document.writeln("<input name='order' type='hidden' id='order' value='"+ppitems+"'>");
	document.writeln("<input name='price' type='hidden' id='price' value='"+totprice+"'>");
	   //window.open('https://www.paypal.com/xclick/business=paypal%402fi.sh&item_name='+ppitems+'&item_number=logos&amount='+totprice+'&no_note=1&currency_code=GBP&lc=GB&tax=0.00','', 'width=800,height=640,scrollbars=yes,status=yes,location=yes') ;
    
   
}

function flipImage(imgname,imgsrc) {
    document.images[imgname].src=imgsrc;
}
    function removeItem(itemno) {
        if (confirm('Are you sure you want to remove this item?')) {
        removeFromCookie('TheBasketCode',itemno);
        removeFromCookie('TheBasketName',itemno);
        removeFromCookie('TheBasketWeight',itemno);
        removeFromCookie('TheBasketTaxable',itemno);
        removeFromCookie('TheBasketPrice',itemno);
        removeFromCookie('TheBasketExtraFields',itemno);
        removeFromCookie('TheBasketAdvanced',itemno);
        removeFromCookie('TheBasketQuantity',itemno);
        self.location = 'basket.php';
        }
    }

    function clearBasket() {
        if (confirm('Are you sure you wish to clear the basket?')) {
            index=document.cookie.indexOf('TheBasket');
            document.cookie='TheBasketCode=.; expires='+today;
            document.cookie='TheBasketName=.; expires='+today;
            document.cookie='TheBasketWeight=.; expires='+today;
            document.cookie='TheBasketTaxable=.; expires='+today;
            document.cookie='TheBasketPrice=.; expires='+today;
            document.cookie='TheBasketExtraFields=.; expires='+today;
            document.cookie='TheBasketAdvanced=.; expires='+today;
            document.cookie='TheBasketQuantity=.; expires='+today;
            self.location='basket.php';
        }
    }
    function changeCurrency(num) {
         index=document.cookie.indexOf('TheCurrency');
         document.cookie='TheCurrency='+(num+1)+'; expires=Friday, 31-Dec-2010 08:00:00 GMT';
         self.location='basket.php';
    }

    function updateBasket() {
        newItemList='';
        itemlist=0;
        for (var i=1;i<=retrieveCookieCount('TheBasketCode');i++) {
            if (!isNaN(document.basketform.elements['quant'+i].value)) {
                changeCookieValue('TheBasketQuantity',i,eval(document.basketform.elements['quant'+i].value));
            }
        }
        self.location='basket.php';
    }
