// minimagic.js //--| // Copyright © 2000-2001, Hodgson Myers Associates Ltd. // All Rights Reserved // minimagic.js may be used freely in any licenced Shop@ssistant site, or offline for experimentation // Users of this script may use it in as many pages and sites as they wish. // Users may not otherwise distribute this script or the associated documentation. // This copyright block must appear in its entirety. // // Enquiries to Rodney Myers, Director // Hodgson Myers Associates Ltd P O Box 397 Oxford OX1 4AF United Kingdom // Tel 01865 200025 // Fax 01865 726545 // email rodney@aflyingstart.net // http://www.aflyingstart.net //--| // magic.js first released December 2000 course participants // minimagic.js created August 2001 // This version 10/2/01 added stripTrailingCRLF() // --| var outsideSystemHandler=0; var ProductName,ProductRef,Price,Weight,TaxCode,VARSLOT2; var productData=new Array(); var message; // To display if form is not passed OK (Set in function InputOK) // Quantity related variables var Qty,Inc,Min,Max; var pkey; var tab="\t"; var newline="\n"; var CRLF=unescape("%0D%0A"); var OK,multiQtyFound,productErrors; var Add2Price,Add2Ref,VARSLOT1; var multibossOp=false; // for column pricing var colPbar="|";var colPsemi=";"; function setvars(){ if(window.reValue){reValue();} // uses cookie restoration if cookie script present. } function notOptional(e){return(true);} function buy(form){ onebuy(form); } function onebuy(form){ if(top.INSASS || outsideSystemHandler >=2){onebuy1(form);} else if(outsideSystemHandler==1){nosass();} else if(outsideSystemHandler==0){alert("No shopping system loaded");} } function onebuy1(form){ pkey=null;Add2Price=0;Add2Ref=""; var VARSLOT1; message=""; var F_ok=InputOK(form); if( F_ok ) { VARSLOT1 = stripTrailingCRLF(getInputFrom(form)); while(VARSLOT1.length>=2 && "%0D%0A".indexOf(escape(VARSLOT1.charAt(VARSLOT1.length-1)))>-1) {VARSLOT1=VARSLOT1.substring(0,VARSLOT1.length-1)} setProductData(pkey); var QVAL; if(form.qlock) {QVAL=-Qty;} else if(form.noremove){QVAL=noremove(Qty);} else {QVAL=top.revQfix(Qty,Inc,Min,Max);} if(typeof(Price)!="string"){Price+=Add2Price;} else if(Price.indexOf(colPbar)>-1){Price=fix_price_string(Price,Qty)} top.newchoice(ProductName,ProductRef+Add2Ref,VARSLOT1,VARSLOT2,Price,QVAL,Weight,TaxCode) } else {alert(message);} } function noremove(V){return(""+-1*parseFloat(V))+"!";} function setQdefaults(form){// Defaults for Quantity related variables Qty=(form.multibuy)?0:1; Min=1; Max=999999; Inc=1; } function checkQfields(e){ var ret=false if(e.type=="hidden" && e.name.substring(0,4).toLowerCase()=="pkey"){pkey=e.value;ret=true;} else if(hQfld(e,'increment')){Inc=e.value;ret=true;} else if(hQfld(e,'minimum') ){Min=e.value;ret=true;} else if(hQfld(e,'maximum') ){Max=e.value;ret=true;} else if(e.type=="text" && e.name.substring(0,3).toLowerCase()=="qty"){Qty=e.value;ret=true;} else if(e.type=="select-one" && e.name.substring(0,3).toLowerCase()=="qty"){Qty=lv(e);ret=true;} return(ret); } function hQfld(e,tag){return(e.type=="hidden" && e.name.toLowerCase()==tag);} function magicQfix(qe){ var form=qe.form;var e; setQdefaults(form); for(var i=0 ; i