// 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 ; i0) { caption=fixCaption(caption); ret+=caption.bold() + " : " +str+CRLF; } } return(ret); } function stripUnderscores(str){ while(str.charAt(0)=="_"){str=str.substring(1);} return(str); } function stripTrailingCRLF(str){ while(str.length>2 && "!$%0D!$%0A".indexOf("!$"+escape(str.charAt(str.length-1)))>-1) { str=str.substring(0,str.length-1) } return(str); } // function to be used for verifying form, if needed function InputOK(form){ var last=form.elements.length; var ret=true; var e; var str="";var custom_str="";var rb,rbv; var previous_rbname="+++"; var caption; for(var i=0 ; i-1){ret=ret.substring(0,ret.length-1);} // Strip trailing hash that protects required numbering if(ret.charAt(ret.length-1)=="#"){ret=ret.substring(0,ret.length-1);} // convert $ to slash ret=swapstring(ret,"$","/"); // convert underscore to space ret=swapstring(ret,"_"," "); return(ret); } function swapstring(T,X,Y){T=""+T; var mark="É_É";var ret=""; if(Y.indexOf(X)>-1) { ret=swaps(T,X,mark); ret=swaps(ret,mark,Y); } else{ret=swaps(T,X,Y);} return(ret); } function swaps(T,X,Y){ var P,n,l;l=X.length; while (T.indexOf(X)>-1){n=T.indexOf(X);P=T.substring(0,n)+Y+T.substring(n+l,T.length);T=P;} return(T);} function setCk(){} // Stub - overwritten by function in cookie script if used. function http_mode(){return("http"==(""+window.location).substring(0,4));} function lv(L){return(L.options[L.selectedIndex].value);} function lt(L){return(L.options[L.selectedIndex].text);} // for Quantity inputs function qty_fix(elem,Increment,qMin,qMax) { var ev=elem.value; ev=Math.abs(ev); if(ev=="NaN"){ev=qMin;} else if(evqMax){ev=qMax;} else if( (ev-qMin)/Increment != Math.ceil((ev-qMin)/Increment)){ev=1*qMin+Math.ceil((ev-qMin)/Increment)*Increment;} elem.value=ev; }// // for column price support function fix_price_string(Pstring,Q){ //Pstring breaks to break_mins|prices break_mins & prices are xxx;yyy;zzz if(Pstring.indexOf(colPbar)>-1){ var tmp=top.parser(Pstring,colPbar);var min=top.parser(tmp[1],colPsemi); var prc=top.parser(tmp[2],colPsemi); var n;for(n=min[0];n>0;n--){if(Q>=1*min[n]){break;}} return(""+prc[n]+colPbar+tmp[1]+colPbar+tmp[2]); }} function pObject(ProductName,ProductRef,Price,Weight,TaxCode,VARSLOT2){ this.ProductName = ProductName; this.ProductRef = ProductRef; this.Price = Price; this.Weight = Weight; this.TaxCode = TaxCode; this.VARSLOT2 = VARSLOT2; return(this); }//