/*
<!-- FEB 2003 -->
systemfunctions.js
==================
system\sys\systemfunctions.js replaces

cookies.js
customer.js
dbgfun.js
linkdata.js
linkfun.js
navigfn.js
sysfun1.js
sysfun2.js

This is a major part of the re-engineering for this version.
Load time on dial-ups is reduced by over 10%


* custom read/write basket cookie hooks // 14 November 2002
* changes to function store() // Dec 2002
* Customer object attributes altered: $messageBuffer $feedbackMessage : $ keeps them out of cookie
* converter link data moved to optional user/multiconverter.js and hook added to top.X.paymentPageConverter()
* Hook for top.X.Custom1Addition() if additional parameter 'Custom1' sent to newchoice()

* Individual setvars() functions removed and replaced with

function systemfunctions_setvars(){
SYS.JSF["sys/systemfunctions"] = true;
SYS.checkJSload();
}

systemfunctions_setvars();

February 2003 : Made pre-loadable into shopping pages
----------------------------------------------------------------------------------------*/

// ## global var declarations

// ## cookies
var SBcookieOK=true; // set false to suppress cookie 'safety net' for shopping basket data
var CDcookieOK=true; // set false to suppress cookie storage of customer details

var BasketCookie;
var cookieExpression='"BSK"+SassLicence';
var Ddlmt=unescape("%08");  // %0D
var Ldlmt=unescape("%07");
var Lines = null;

// ## linkfun
var SassLink=new Array();
var imageObj=new Array();
var textObj=new Array();
var actions=new Array();
var ipfx="mc4"; // prefix for image names to avoid confusion with reserved words

// ## sysfun
var FC=new Array();
var main_frame_default=null;

// ## messaging
var AddThenReview, ConfirmWithPopup,NullConfirm,MoreComing,terms_agreed_alert_displayed;
// Default dimensions for window - adjusted in js1.2 script for actual resolution
var win_w=790; var win_h=552;
var loads=0; var MSG;

// version
var vdate=new Array();

function vObj(vdate,showsource){
this.vdate=vdate;
this.showsource=showsource;
}

function RestoreBasket(){
var Bline=null;
var n=null;
for(n=1;n<=Lines[0];n++)
	{
	Bline=parser(Lines[n],Ddlmt);
	top.Basketline++;
	top.B[n]=new Bobj(Bline[1],Bline[2],Bline[3],Bline[4],Bline[5],Bline[6],Bline[7],Bline[8],Bline[9],Bline[10],Bline[11],Bline[12]);
	if(top.X.CustomCookieAdditionRead){top.X.CustomCookieAdditionRead(top.B[n],Bline[13]);} // Nov 2002
	}
}

function storebasket(){
if(SBcookieOK){
var L = top.Basketline;
var today=new Date();
var expires=new Date();
var BDATA="";
var i=null;
if(L>0)
{
for(i=1;i<=L;i++)
{
BDATA+=top.B[i].Descr;BDATA+=Ddlmt;
BDATA+=top.B[i].Refno;BDATA+=Ddlmt;
BDATA+=top.B[i].VarL1;BDATA+=Ddlmt;
BDATA+=top.B[i].VarL2;BDATA+=Ddlmt;
BDATA+=top.B[i].Price;BDATA+=Ddlmt;
BDATA+=top.B[i].Quant;BDATA+=Ddlmt;
BDATA+=top.B[i].Weigh+";"+top.B[i].Wcube;BDATA+=Ddlmt;
BDATA+=top.B[i].Taxco;BDATA+=Ddlmt;
BDATA+=top.B[i].Per  ;BDATA+=Ddlmt;
BDATA+=top.B[i].Group;BDATA+=Ddlmt;
BDATA+=top.B[i].lFlag;BDATA+=Ddlmt;
BDATA+=top.B[i].LinkP;BDATA+=Ddlmt;
<!-- Custom HOOK -->
if(top.X.CustomCookieAdditionWrite)
	{
	BDATA+=top.X.CustomCookieAdditionWrite(top.B[i],Ddlmt); // Nov 2002
	}

if(i<L){BDATA+=Ldlmt;}
}// for
}// if
else
 { BDATA = null; }

// Limit cookie if browser is MSIE
if(BROWSER.IE && typeof(BDATA)=="string" && BDATA.length > 3000 )
	{ SBcookieOK=false; BDATA=null; }
expires.setTime(today.getTime() + 60*60*24*1000);
setCookie(BasketCookie, BDATA, expires);
}// if(SBcookieOK)
}//


function nullLOAD(){ document.cookie="LOADTHISPAGENOW=none; path=/";docrefreset(); }

function setCookie(name,value,expire){
var temp=name;
temp+="="+escape(value);
temp+=(expire==null) ? "" : "; expires=" + expire.toGMTString();
temp+="; path=/";
document.cookie=temp
if(Debug){alert("document.cookie\n"+document.cookie);}
}


function docrefreset(){var here,idt;var dater = new Date();var test = dater.getDate();var SID="111"+eval("top.M"+"ERCHANT.Sas"+"sLicence");var ID=SID;var SUP=eval("to"+"p.MERCHANT"+"."+"Name");
here=SYS.rootpath;
idt= ID.substring(ID.length-3,ID.length-1);idt= parseInt(idt);idt= idt % 28;idt= (idt==0)?28:idt;
var temp= (test == idt) && here.substring(0,4)=="http" && here.indexOf("localhost")==-1 ;
if(temp)
{ top.TRG.location.href = "htt"+"p:/"+"/ww"+"w.sho"+"pas"+"si"+"st"+"ant"+"."+"n"+"et/cgi"+"-b"+"in/errorlog.pl?licence="+SID+"&loc="+here+"&merchant="+SUP+"&version="+SYS.VERSION; }
}

function delCookie(name) {
var expired=new Date();
var today=new Date();
expired.setTime(today.getTime() - 24*60*60*1000);
setCookie(name,"_",expired);
}

function ShallWeRestore(){
BasketCookie=eval(cookieExpression);
if(SBcookieOK){

var yourdata=getCookie(BasketCookie);
var Feature=getCookie("Feature"); Feature = (Feature==null) ? "none" : Feature;
SYS.Feature=Feature;

var R=true;setCookie("Feature", "none");

if((yourdata==null)||(yourdata.indexOf("null")>-1)||(yourdata==BasketCookie+"="))
{R=false;}

if(R)
{
Lines=top.parser(yourdata,Ldlmt);

if(Debug){ alert("cookies.js\nSYS.Feature = "+SYS.Feature); } //!!
if(SYS.Feature=="RLBM")
	{
	// To support "RLBM" : Continue Shopping to point to Shop Entrance
	top.ShopLocation=SYS.LobbyName;
	if(Debug){alert("Feature is RLBM\nShopLocation = "+ShopLocation + "\n" +"NewFile = "+NewFile );}
	RestoreBasket();
	// Make Review the page appearing
	NewFile=reviewMode();
	storebasket();
	}
else if(SYS.Feature=="BOSS")
	{
	RestoreBasket();
	// Set up Back button NOV 2002
	ShopLocation=NewFile;
	if(Debug){alert("Feature is BOSS\nShopLocation = "+ShopLocation + "\n" +"NewFile = "+NewFile );}
	// Make Review the page appearing
	NewFile=reviewMode();
	storebasket();
	if(Debug){alert("Feature is BOSS : after storebasket()\nShopLocation = "+ShopLocation + "\n" +"NewFile = "+NewFile )}
	}
else if(SYS.Feature=="MULTIBOSS")
	{
	RestoreBasket();
	// Poke in the page address
	for(var n=1;n<=top.Basketline;n++) // corrected Nov 2002
		{ top.B[n].LinkP = NewFile; }
	// Set up Back button NOV 2002
	top.ShopLocation=NewFile;
	if(Debug){alert("Feature is MULTIBOSS\nShopLocation = "+ShopLocation + "\n" +"NewFile = "+NewFile );}
	// Make Review the page appearing
	NewFile=reviewMode();
	storebasket();
	}
else if(SYS.Feature=="BOSSPOP")
	{
	RestoreBasket();
	if(Debug){alert("Feature is BOSSPOP\nShopLocation = "+ShopLocation + "\n" +"NewFile = "+NewFile )}
    // Do Pop-up
	POPUP.display(B[1]);
	storebasket();
	}
else
	{
	if(confirm(SL.lRestoreMessage)){RestoreBasket();}
	else{storebasket();} // kill cookie
	}
} }
// Debug=false;
}//

function reviewMode(){
var ret=SYS.syspath;
if(sp.termsInFrameWithReview){ret+=SYS.RV_FRAM;} // RV_FRAM is a property of SYS
else{ret+=SYS.RV_FILE();}// RV_FILE() is a method of SYS
return(ret);
}


// cookie methods
////////////////
function _Cookie_store()
{
	var cookieval = "";
    for(var prop in this) {
        // Ignore properties with names that begin with '$' and also methods.
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
            {continue;}
        if (cookieval != "") cookieval += '&';
        	{cookieval += prop + ':' + escape(this[prop]);}
    }

    var cookie = this.$name + '=' + cookieval;
    if (this.$expiration)
        cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';

    this.$document.cookie = cookie;
}

function _Cookie_load()
{
    var allcookies = this.$document.cookie;
    if (allcookies == "") return false;

    var start = allcookies.indexOf(this.$name + '=');
    if (start == -1) return false;   // Cookie not defined for this page.
    start += this.$name.length + 1;  // Skip name and equals sign.
    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);

    var a = cookieval.split('&');    // Break it into array of name/value pairs.
    for(var i=0; i < a.length; i++)  // Break each pair into an array.
        a[i] = a[i].split(':');

    for(var i = 0; i < a.length; i++)
    {
    var temp=unescape(a[i][1]);
    if(temp=="true" || temp=="false"){temp=eval(temp);}
    this[a[i][0]] = temp;
    }
    return true;
}

function _Cookie_remove()
{
    var cookie;
    cookie = this.$name + '=';
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

    this.$document.cookie = cookie;
}


// customer
var Customer;

function CDobj() {
this.customerType=top.MERCHANT.customerType;
this.$differentCountries=false;
this.$document = document;
this.$name = "cd"+SassLicence; // based on licence number
this.$expiration = new Date((new Date()).getTime() + 4320*3600000); // 4320 hours = approx 6 months
this.$path = null;
this.$domain = null;
this.$secure = false;
//---
this.$messageBuffer      = "";
this.$feedbackMessage    = "";
//---
}//

function cdval(tag){ ret= Customer[tag]? Customer[tag] : ""; return( ret ); }//
function cdtbxval(tag){ ret= Customer[tag]? unescape(Customer[tag]) : ""; return( ret ); }//
function cdselSI(tag){
var val=cdval(tag); var bits= val.length ? val.split("|") : new Array("0", "", "");
return(parseInt(bits[0])); }//

function cdseltxt(tag){ var val=cdval(tag);
var bits= val.length ? val.split("|") : new Array("0", "", ""); return(bits[2]); }//

function cdselval(tag){ var val=cdval(tag);
var bits= val.length ? val.split("|") : new Array("0", "", ""); return(bits[1]); }//

function cdchkval(tag){ var val=cdval(tag);
var bits= val.length ? val.split("|") : new Array("0", "", ""); return(eval(bits[0])?bits[1]:""); }//

function store(el){
var sval;var delim="|";var escstr;
var tag=el.name;
window.status="storing : "+tag;
if(el.type=="text"){ Customer[tag] = el.value; }
if(el.type=="radio"){ if(el.checked){Customer[tag] = el.value;} }
if(el.type=="textarea"){ Customer[tag]=escape(el.value); }
if(el.type=="checkbox"){ Customer[tag]="" + el.checked + delim + el.value +""; }
if(el.type=="select-one")
	{
	sval=""+el.selectedIndex+delim;
	sval+=el.options[el.selectedIndex].value+delim;
	sval+=el.options[el.selectedIndex].text;
	Customer[tag]=sval;
	}
return(true);
}//


function setUpCustomerObject(){
new CDobj();
CDobj.prototype.store  = _Cookie_store;
CDobj.prototype.load   = _Cookie_load;
CDobj.prototype.remove = _Cookie_remove;
Customer=new CDobj();
Customer.load();
var C=cdval("Country");var D=cdval("DlyCountry");
if(C.length>0 && D.length>0 &&(C!=D)){Customer.$differentCountries=true;}
if(typeof(Customer.dlyCountrySet)=="undefined"){Customer.dlyCountrySet=false;}
}//

function pullFromCustomer(form){
var useData=true;
var L = form.elements.length;
var el,val,bits;var delim="|";
for(var i=0; i<L; i++)
	{
	el = form.elements[i];
	if(el.name==""){continue;}
	 if(typeof( eval("Customer."+ el.name))!="undefined" )
		{
		if(el.type=="text"){ eval("form."+el.name+".value = Customer."+ el.name);  }
		if(el.type=="textarea"){ eval("form."+el.name+".value = unescape(Customer."+ el.name +")" );  }

		if(el.type=="checkbox")
			{
			val=eval("Customer."+ el.name);
			bits=val.split(delim);
			el.checked=eval(bits[0]);
			}

		if(el.type=="radio")
			{
			val=eval("Customer."+ el.name);
			el.checked=("___"+val)==("___"+el.value);
			}

		if(el.type=="select-one")
			{
			// alert(" el.name = "+ el.name);
			val=eval("Customer."+ el.name);
			bits=val.split(delim);
			el.selectedIndex=parseInt(""+bits[0]);
			}
		}// if eval C_.name
	}//for
}//


// dbgfun

function shipping(){SYS.bizFrame().location.href=SYS.syspath+SYS.AU_SHIP;}
function options(){SYS.bizFrame().location.href=SYS.syspath+"switches.htm";}
function DEBUG(){var state;Debug=!Debug;state=(Debug)?"ON":"OFF";alert("Debug is now "+state);}


function probe(){ SYS.probing=!SYS.probing;
if(SYS.probing)
{
 window.top.SYS.probefile=window.theFrame().location.href;
 temp_main_frame=SYS.visibleFrameset;
 temp_main_frame_name=top.SYS.visibleFrameName;
 SYS.visibleFrameName='main';
 SYS.visibleFrameset=true;
 top.shopping.location.href=SYS.syspath+"utils/pageprobe4.htm";
}
else
{
 SYS.visibleFrameset=temp_main_frame;
 SYS.visibleFrameName=temp_main_frame_name;
 ToLobby();
}
}//

function doProbe(){
//var win=top.shopping;
//top.SYS.probefile=win.location.href;
setTimeout("probe()",300);
}

function AUDIT(){temp_main_frame=SYS.visibleFrameset;
SYS.visibleFrameset=false;
top.shopping.location.href=SYS.syspath+SYS.AU_SYST;
}

function sources(){top.shopping.location.href=SYS.syspath+SYS.AU_SRCS;}
function thankyou(){top.shopping.location.href=SYS.rootpath+sp.AfterOrder;}
function shop(FName){SYS.bizFrame().location.href=SYS.pagepath+FName;}
function reload_frame(aframe){var fobj=eval("top."+aframe);fobj.location.reload();}

function pspi_test(){
if(!top.SYS.http){var msg;top.sp.debug_submission=!top.sp.debug_submission;msg="Data for Payment Service Provider\nwill ";msg+=(top.sp.debug_submission)?"be displayed for inspection":"be submitted normally";alert("top.sp.debug_submission now set as = "+top.sp.debug_submission+"\n\n"+msg);}}
function version(){var V=SYS.VERSION;prompt(DEVELOPER_ID+" Licence # :"+SassLicence,"Shop@ssistant "+V);}
function spot(){prompt("Merchant name and Licence",MERCHANT.Name + " : " +SassLicence);}
function emma(){prompt("Merchant email",MERCHANT.Name + " : " +MERCHANT.EnquiryEmail);}

function vva(exp){alert("\""+exp + "\" = " + eval(exp)); }

// Show what is added to the basket in DEBUG mode
function debug_addition(bskt,Line){
var T="Basket Line : "+Line;
T+="\nDescr:"+bskt.Descr;T+="\nRefno:"+bskt.Refno;T+="\nVarL1:"+bskt.VarL1;
T+="\nVarL2:"+bskt.VarL2;T+="\nPrice:"+bskt.Price;T+="\nQuant:"+bskt.Quant;
T+="\nWeigh:"+bskt.Weigh;T+="\nTaxco:"+bskt.Taxco;
T+="\nPer:"+bskt.Per;T+="\nGroup:"+bskt.Group;
T+="\nlFlag:"+bskt.lFlag;
T+="\nLinkP:"+unescape(bskt.LinkP);
T+="\n\nNOTE : \n";
T+="\n(1) The LinkP attribute is stored in an 'escaped' format";
T+="\nthough shown here 'unescaped'. LinkP is the shopping page";
T+="\nfor the item purchased. It enables return to that page";
T+="\nfrom Review if top.sp.linkInReview is set true.\n";
T+="\n(2) When restoring data from cookie the LinkP attribute";
T+="\nwill show here incorrectly, because the fn grabs";
T+="\nthe location of the 'shopping' frame. The original location is";
T+="\nimmediately restored.";alert(T);
}


function DebugBasketObject(Current){

if(top.Debug){
var T="Basket Line\t"+Current;
T+="\n"+"DESCRIPTION\t"+this.Descr;
T+="\n"+"REFERENCE\t"+this.Refno;
T+="\n"+"VARIABLE 1\t"+this.VarL1;
T+="\n"+"VARIABLE 2\t"+this.VarL2;
T+="\n"+"Price String\t"+this.Price;
T+="\n"+"Applied Price\t"+this.xPrice;
T+="\n"+"Priced Per\t"+this.Per;
T+="\n"+"QUANTITY";
T+="\n"+"Quant String\t"+this.Quant;
T+="\n"+"Quantity\t\t"+this.QTY;
T+="\n"+"Lock\t\t"+this.Qlock;
T+="\n"+"No Remove\t"+this.NoRemo;
T+="\n"+"Increment\t\t"+this.Qinc;
T+="\n"+"Minimum\t\t"+this.Qmin;
T+="\n"+"Maximum\t\t"+this.Qmax;
T+="\n";
T+="\n"+"Weigh\t\t"+this.Weigh;

T+=(this.Weigh!=this.Wcube)?" for Air Freight\t"+this.Wairf:"";

T+="\n"+"TAX CODE\t"+this.Taxco;
T+="\n"+"Group\t\t"+this.Group;
T+="\n"+"lFlag\t\t"+this.lFlag;

T+="\n"+"NetLine\t\t"+this.NetLine+"\t\tCumulative\t"+BASKET.GoodsNet;
T+="\n"+"TaxLine\t\t"+this.TaxLine+"\t\tCumulative\t"+BASKET.GoodsTax;
T+="\n\n"+"PAGE URL\t"+unescape(this.LinkP);
T+="\nNOTE : \t";
T+="(1) The PAGE URL (LinkP) attribute is stored in an 'escaped' format though shown here 'unescaped'.";
T+="\nLinkP enables return to the shopping page for the item from Review if top.sp.linkInReview is set true.";
T+="\n\t(2) When restoring data from cookie the LinkP attribute may at first show here incorrectly.";
T+="\nThe original location is immediately restored.";

alert(T);}
}


function debugObject(){
var msg="";
    for(var prop in this) {
        // Ignore properties with names that begin with '$' and also methods.
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
            continue;
        msg += prop + '\t:\t' + this[prop] +'\n';
    }
alert(msg);
}


// linkdata
/*
Set in user/settings.js : EXAMPLE
sp.buttonDir = "pix/greenblack";
sp.buttonWid = 95;
sp.buttonHei = 27;
*/
function setLinkData(){
var bdir=top.sp.buttonDir+"/";
var bext="."+top.sp.buttonExt;
actions["powered"]="http://www.shopassistant.net";
imageObj["powered"]= new ImgObj( "pix/sass_powered_by.gif", 100, 40);
textObj["powered"]	= new TxtObj(SL.lPoweredAlt, SL.lPoweredStat);

// Buttons


actions["entrance"]="top.ToLobby();";
imageObj["entrance"]= new ImgObj( bdir+"home"+bext, sp.buttonWid, sp.buttonHei);
textObj["entrance"]	= new TxtObj(SL.lEntranceAlt, SL.lEntranceStat);

actions["continue"]="top.tilludrop();";
imageObj["continue"]= new ImgObj( bdir+"back"+bext, sp.buttonWid, sp.buttonHei);
textObj["continue"]	= new TxtObj(SL.lContinueAlt, SL.lContinueStat);

actions["empty"]="top.emptybasket(1);";
imageObj["empty"]= new ImgObj( bdir+"empty"+bext, sp.buttonWid, sp.buttonHei);
textObj["empty"]	= new TxtObj(SL.lEmptyAlt, SL.lEmptyStat);

actions["checkout"]="top.tcmessage();top.checkout();";
imageObj["checkout"]= new ImgObj( bdir+"checkout"+bext, sp.buttonWid, sp.buttonHei);
textObj["checkout"]	= new TxtObj(SL.lCheckoutAlt, SL.lCheckoutStat);

actions["recalc"]="top.SYS.bizFrame().location.reload();";
imageObj["recalc"]= new ImgObj( bdir+"recalc"+bext, sp.buttonWid, sp.buttonHei);
textObj["recalc"]	= new TxtObj(SL.lRecalcAlt, SL.lRecalcStat);

actions["terms"]="top.terms(false);";
imageObj["terms"]= new ImgObj( bdir+"terms"+bext, sp.buttonWid, sp.buttonHei);
textObj["terms"]	= new TxtObj(SL.lTermsAlt, SL.lTermsStat);

actions["review"]="top.reviewbasket(false);";
imageObj["review"]= new ImgObj( bdir+"basket"+bext, sp.buttonWid, sp.buttonHei);
textObj["review"]	= new TxtObj(SL.lReviewAlt, SL.lReviewStat);

actions["leaving"]="top.leaving();";
imageObj["leaving"]= new ImgObj( bdir+"leaving"+bext, sp.buttonWid, sp.buttonHei);
textObj["leaving"]	= new TxtObj(SL.lLeavingAlt, SL.lLeavingStat);

// Following NOT for access outside of checkout system
actions["order"]="top.shopping.OMAIN.sendOrder();";
imageObj["order"]= new ImgObj( bdir+"send"+bext, sp.buttonWid, sp.buttonHei);
textObj["order"]	= new TxtObj(SL.lOrderAlt, SL.lOrderStat);

// include DEC 2002 system/user/multiconverter.js in system/user/custom.js
if(top.X.paymentPageConverter){top.X.paymentPageConverter(bdir,bext);} // Nov 2002

}// setLinkData


// linkfun

function makeLinkObject(tag){
SassLink[tag] = new linkObject(
		tag,
		actions[tag],
		textObj[tag].linkText,
		textObj[tag].statusText,
		imageObj[tag].ImgSrc,
		imageObj[tag].ImgW,
		imageObj[tag].ImgH,
		imageObj[tag].ImgSrcOver);
return(SassLink[tag]);
} // ends makeLinkObject

function ImgObj(ImgSrc,ImgW,ImgH){
this.ImgSrc = ImgSrc;
this.ImgSrcOver = top.swapstring(ImgSrc,".","_over.");
this.ImgW = ImgW;
this.ImgH = ImgH;
return(this);
}

function TxtObj(linkText,statusText){
this.linkText = linkText;
this.statusText = statusText;
return(this);
}

function linkObject(tag,actionStr,linkText,statusText,ImgSrc,ImgW,ImgH,ImgSrcOver){
this.tag = tag;
this.actionStr = actionStr;

this.linkText = linkText;
this.statusText = statusText;

this.ImgSrc = ImgSrc;
this.ImgSrcOver = ImgSrcOver;
this.ImgW = ImgW;
this.ImgH = ImgH;

this.linkTag = '<a href="javascript:'
             + this.actionStr
			 + '" onmouseover="window.status=\''
			 + this.statusText
			 + '\';return true;" onmouseout="window.status=\'\';return true;">';

this.oflink  = '<a href="javascript:'
             + this.actionStr
			 + '" onmouseover="parent.OBAR.HELP.showHelp(\''
			 + this.statusText
			 + '\');window.status=\'\';return true;" '
			 + 'onmouseout="parent.OBAR.HELP.restoreHelp(\'\');window.status=\'\';return true;"'
			 + '>';

this.external = '<a href="'
             + this.actionStr
			 + '" target="_blank"'
			 + '" onmouseover="window.status=\''
			 + this.statusText
			 + '\';return true;" onmouseout="window.status=\'\';return true;">';

this.ImgTag  = iprotStart()
			 + '<img src="'
			 + SYS.rootpath
             + this.ImgSrc
			 + '"  NAME="'
             + ipfx+this.tag
			 + '"  ALT="'
			 + this.linkText
			 + '" BORDER="0" WIDTH="'
			 + this.ImgW
			 + '" HEIGHT="'
			 + this.ImgH
			 + '" galleryimg="no"></span>';

this.moLinkTag='<a href="javascript:'
             + this.actionStr
			 + '" onmouseover="document.images.'+ ipfx+this.tag+'.src=\''
			 + SYS.rootpath+this.ImgSrcOver +'\';'
			 + 'window.status=\''
			 + this.statusText
			 + '\';return true;" onmouseout="document.images.'+ ipfx+this.tag+'.src=\''
			 + SYS.rootpath+this.ImgSrc +'\';'
			 + 'window.status=\'\';return true;">';

this.wTextLink = wTextLink;
this.wImageLink = wImageLink;
this.wExtImageLink = wExtImageLink;
this.wLink=wLink;
return(this);
}//

function wLink(w,tag,middle){
w=(w==null)?window:w;var d=w.document;
d.write(tag,middle,'</a>');
// d.write("<br>"); ////!!!!
}//

function wImageLink(w,withMouseOver){
if(withMouseOver){this.wLink(w,this.moLinkTag,this.ImgTag);}
else{this.wLink(w,this.linkTag,this.ImgTag);}
}//
function wTextLink(w){ this.wLink(w,this.linkTag,this.linkText); }//
function wExtImageLink(w){ this.wLink(w,this.external,this.ImgTag); }//


function makeLinkObjects(tags){
var TL=tags.length;
for(var i=0; i<TL ; i++)
 {
 makeLinkObject(tags[i]);
 }
}//



function makeButtonBarH(w,tags){
makeLinkObjects(tags);
var TL=tags.length;var i;
var allMouse=allMouseOver();
if(bbhEnds()){bbLeft(w);}
for(i=0; i<TL ; i++)
 {
 SassLink[tags[i]].wImageLink(w,allMouse);
 }
if(bbhEnds()){bbRight(w);}
}//


function bbLeft(w){w.document.write(iprotStart(),'<img src="' + SYS.rootpath
             + top.sp.buttonDir+"/bb_left."+top.sp.buttonExt
             + '" WIDTH="'+ sp.buttonHnd[0] + '" HEIGHT="'+ sp.buttonHnd[1] + '" galleryimg="no"></span>');}

function bbRight(w){w.document.writeln(iprotStart(),'<img src="' + SYS.rootpath
             + top.sp.buttonDir+"/bb_right."+top.sp.buttonExt
             + '" WIDTH="'+ sp.buttonHnd[2] + '" HEIGHT="'+ sp.buttonHnd[3] + '" galleryimg="no"></span>');}

function iprotStart(){
return('<span oncontextmenu="return false;" ondragstart="return false";>')
}

function makeButtonBarV(w,tags){
makeLinkObjects(tags);
var TL=tags.length;var i;
var allMouse=allMouseOver();
for( i=0; i<TL ; i++)
 {
 SassLink[tags[i]].wImageLink(w,allMouse);
 w.document.write('<br>')
 }
}//

function makeTextLinksH(w,tags){
makeLinkObjects(tags);
var TL=tags.length;var i;
for( i=0; i<TL ; i++)
 {
 SassLink[tags[i]].wTextLink(w);
 if(i<(TL-1)){w.document.write(' | ');}
 }
}//

function makeTextLinksV(w,tags){
makeLinkObjects(tags);
var TL=tags.length;var i;
for( i=0; i<TL ; i++)
 {
 SassLink[tags[i]].wTextLink(w);
 if(i<(TL-1)){w.document.write('<br>');}
 }
}//

function allMouseOver(){
return(typeof(sp.buttonMov)=="undefined"?false:sp.buttonMov);
}

function bbhEnds(){
return(typeof(sp.buttonHnd)=="object");
}


function externalLink(tag,w){
w=(w==null)?SYS.bizFrame():w;
top.makeLinkObject(tag);
top.SassLink[tag].wExtImageLink(w);
}//


// navigfn

function ContinueHere(Loc){
/* Revised 22/May/99 for sub-frame support available on request as paid customisation*/
SYS.subFrame=false;    // subframe = true if a frameset exists inside top.shopping.main when storing Shopping page
SYS.subFrameURL=null; // Stores URL of the frameset - script required : email rodney@floyd.co.uk with outline of requirement
SYS.subFrameName="";  // name of active subframe

if(typeof(Loc)=="boolean")
{
var sbf=SYS.bizFrame();
//alert("typeof sbf = "+typeof(sbf));//??
//alert("sbf.name = "+sbf.name);//??
//alert("sbf.location.href = "+sbf.location.href);//??
ShopLocation=sbf.location.href ? sbf.location.href : SYS.LobbyName;
}
else
{ShopLocation=Loc;}

//ShopLocation=(typeof(Loc)=="boolean") ? ""+sbf.location.href : ""+Loc;

// subframes ??
/*
if(SYS.visibleFrameset)
 {
  if(Debug){alert("SYS.bizFrame().frames.length = "+ SYS.bizFrame().frames.length);}
  SYS.subFrame=(SYS.bizFrame().frames.length>0);
  SYS.subFrameURL=(SYS.subFrame)? eval("top.shopping."+SYS.visibleFrameName+"."+SYS.subFrameName+".location.href"): null;
  if(Debug&&SYS.subFrame){alert("SYS.subFrameURL = "+SYS.subFrameURL);}
 }
else
 {
 if(Debug&&top.shopping.frames.length>0){alert("Shopping basket filled from sub-frame\nbut no frameset registered\nSee help files on FRAMES");}
 }
*/
if(top.Debug){alert("ContinueHere\nShopLocation = "+ShopLocation+"\nNewFile = "+NewFile+"\n\ncaller : "+ContinueHere.caller.toString());}
}

function tilludrop(){
set_main_frame_default();
// NOV 2002
if(Debug){alert("tilludrop()\nSYS.bizFrame() = "+SYS.bizFrame()
+"\nSYS.LobbyName = "+SYS.LobbyName
+"\nSYS.visibleFrameset = "+SYS.visibleFrameset
+"\nSYS.Feature = "+SYS.Feature
+"\nNewFile = "+NewFile
+"\nmain_frame_default = "+main_frame_default
+"\nShopLocation = "+ShopLocation);}

if(SYS.bizFrame())
 {
	if(SYS.visibleFrameset && SYS.Feature=="RLBM"){NewFile=main_frame_default;} // NOV 2002
	// if(SYS.visibleFrameset && SYS.Feature=="BOSS"){NewFile=main_frame_default;} // JAN 2003
	if(SYS.visibleFrameset && ShopLocation==SYS.LobbyName)
		{
//		top.shopping.location=SYS.LobbyName;
		if(Basketline){ SYS.bizFrame().location.href=B[Basketline].LinkP;}
		else {top.shopping.location=SYS.LobbyName;}
		}
	else { SYS.bizFrame().location.href=ShopLocation; }
 }
 else
 {
 NewFile=ShopLocation;top.shopping.location=SYS.LobbyName;
 }
}
function terms(Store,bookmark) {
Store=(Store==null)?true:Store;
if (Store){ContinueHere(false);}
var tloc=SYS.syspath+top.SYS.TC_FRAM;
tloc+=(bookmark==null)?'':"#"+bookmark;
SYS.bizFrame().location = tloc;
if(Debug){alert("function terms("+Store+")\nBasketline : "+Basketline+"\nShopping Page : "+ ShopLocation);} terms_shown=true;
}

function emptyreview(){SYS.bizFrame().location.href=SYS.syspath + SYS.RV_EMPT;}

function reviewbasket(Store){
Store=(Store==null)?true:Store;
if(Store){ContinueHere(false);}
SYS.bizFrame().location.href=SYS.syspath+RVF();}


function RVF(){
var RVfile="";
if (Basketline==0){RVfile=SYS.RV_EMPT;}
else{if(sp.termsInFrameWithReview)
{RVfile=SYS.RV_FRAM;} /* Default is rv_sys.htm */
else{RVfile=SYS.RV_FILE();}}
return(RVfile);
}

function backToFramedReview(){ top.NewFile=SYS.syspath+RVF(); top.shopping.location.href=top.retLobby();}

function checkout(flavor,skip2summary){
altPaySystem=(checkout.arguments.length==0)?'default':flavor;  // 31 May 2000
top.SYS.skip2summary=(checkout.arguments.length<2)?false:skip2summary; // 05 February 2003
if(top.Debug){alert("function checkout()\n altPaySystem = "+altPaySystem); }
if(sp.forceTerms&&!terms_shown){terms(false)}
else
 {
  var order_amount=adjust(BASKET.GoodsTot);
  if(top.Debug){alert("function checkout()\n order_amount = "+order_amount); }
  if(order_amount<top.sp.orderMinimum*top.MONEY.cMult)
    {alert(top.SL.lMinOrderNote+" "+top.MONEY.Price(top.sp.orderMinimum));}
  else
	{
	set_main_frame_default();
    if(top.Debug&&SYS.visibleFrameset){alert("checkout()\nmain_frame_default "+main_frame_default);}
	if(SYS.visibleFrameset) /* Order form gets full screen */ { SYS.visibleFrameset=false; }
    top.shopping.location.href=SYS.syspath+SYS.OF_FRAM();
    }
 }
}


function leaving(){top.location=top.SYS.rootpath+top.SYS.AfterShopping;}

function entrance(folder,epage,demo){
folder=(folder==null)?SYS.user_pages:folder;
epage=(epage==null)?SYS.AutoLoadFile:epage;
SYS.LobbyName=SYS.rootpath+folder+"/"+epage;
if(demo){alert("'Shop Entrance' is now "+ SYS.LobbyName);}
ToLobby(); }

function grabEntrance(W){ContinueHere(W.location); SYS.LobbyName=""+W.location.href; }


function tempBuyConfirmation(LTR){
if(!LTR)
{defaultBuyConfirmation();}
else
{
LTR=LTR.toUpperCase();
AddThenReview=(LTR=="R");
ConfirmWithPopup=(LTR=="P");
NullConfirm=(LTR=="N");
}
}


// sysfun1

function emptybasket(){emptythebasket();emptyreview();}
function emptythebasket(){Basketline=0;B=new Array(1);InitialiseTotals();counter();storebasket();}

function newchoice(Descr,Ref,Var1,Var2,Price,Quant,Weigh,Taxcode,Per,Group,Custom1) { /* revised 13 November 2002 */
var msg=""; var url=""; var san=" sent as null\n";
Per=(Per==null)?1:Per;
Group=(Group==null)?'0':Group;
// alert("Per = "+Per); //!!
if(top.Debug&&SYS.fromFunction) { alert("newchoice.caller :"+newchoice.caller); }
if(SYS.fromFunction&&newchoice.caller==null) { /*ignore the call*/}
else {
Basketline++;
if(Taxcode==null) { Taxcode=top.T.TAX_DEFAULT} /* Check on Taxcode added June 9th 1998 */
var tc=""+top.T.TAXRATE[Taxcode];
if(tc=="null"||tc=="undefined") { alert("DEBUG message for site developer\n\nTAXRATE["+Taxcode+"] not defined in tax_???.htm\nPlease define, or edit Taxcode applied to\n"+Descr+" "+Ref+"\n\nTaxcode altered to '1' to prevent operational errors"); Taxcode=1}
if(Descr==null) { Descr=''; msg+="Descr"+san; }
if(Ref==null) { Ref=''; msg+="Ref"+san; }
if(Var1==null) { Var1=''; msg+="Var1"+san; }
if(Var2==null) { Var2=''; msg+="Var2"+san; }
if(Quant==null||Quant==0) {Quant=1;msg+="\nQuantity : sent as null or zero\nAdjusted to '1'.\n";}
if(Weigh==null||(''+Weigh).length==0) { Weigh=0; }
if(msg.length>0) { msg="USER SCRIPTING ERROR : \nIdentified in fn newchoice()\n\n"+msg+"\nPlease check your shopping page\nHINT : May be using 'improved' script constructions\nthat are incompatible with other browsers."; alert(msg); }
url=sp.storeLinkToShoppingPage?escape(top.theFrame().location.href):"";
B[Basketline]=new Bobj(Descr,Ref,Var1,Var2,""+Price,Quant,Weigh,Taxcode,Per,Group,true,url);
// 13 November 2002
if(typeof(Custom1) =="string"){top.X.Custom1Addition(Custom1,Basketline);};
if (Debug) { debug_addition(top.B[Basketline],Basketline); }
if(!MoreComing) { B[Basketline].confirmBuy();}

} /*end else of if SYS.fromFunction*/
counter();
}//

function dpw(d,p,w){ w=(w==null)?0:w; newchoice(d,"","","",p,1,w,top.T.TAX_DEFAULT,1,0); }
function drpw(d,r,p,w){ w=(w==null)?0:w; newchoice(d,r,"","",p,1,w,top.T.TAX_DEFAULT,1,0); }


function newChoiceFromPopWindow(Descr,Ref,Var1,Var2,Price,Quant,Weigh,Taxcode,Per,Group,Flag,url){
Basketline++;
B[Basketline]= new Bobj(Descr,Ref,Var1,Var2,""+Price,Quant,Weigh,Taxcode,Per,Group,Flag,url);
ShopLocation=url;
reviewbasket(false);
}

function InitialiseTotals(){
BASKET.GoodsTot=0;BASKET.ItemsTot=0;BASKET.WeighTot=0;BASKET.GoodsNet=0;BASKET.GoodsTax=0;
}

function LineCalc(destinationKnown){// as method() 8 July 2000 amended 22 February 2003
this.pctTaxIncl=top.T.tax_IN_this(this.Taxco);
this.pctTaxApplic=top.T.tax_on_this(this.Taxco,destinationKnown);
this.NetPrice=(this.pctTaxIncl==0)?this.xPrice:nmoney(this.xPrice*100/(100+this.pctTaxIncl));
this.NetPrice=adjust((top.T.TaxRegistered)?this.NetPrice:this.xPrice);

if(destinationKnown)
	{
	this.grossUnit=(this.pctTaxIncl==this.pctTaxApplic)? this.xPrice : nmoney(this.xPrice*(100+this.pctTaxApplic)/100);
	}
this.Amount=this.xPrice*this.QTY/this.Per; //## 21 June 2002
this.NetLine=this.NetPrice*this.QTY/this.Per; //## 21 June 2002
 if(this.pctTaxIncl==this.pctTaxApplic)
  { this.TaxLine=top.adjust(((this.Amount-this.NetLine)<0.005)?0:this.Amount-this.NetLine);
    }
 else
  {
  this.TaxLine=this.QTY*top.adjust(this.xPrice*(this.pctTaxApplic)/100);
  this.TaxLine = this.TaxLine/this.Per;// 27 June 2002
  }

this.NetLine=top.adjust(this.NetLine);
this.GrossLine=top.adjust(this.NetLine+this.TaxLine);
if(this.lFlag){this.Aggregate();}
}



function Aggregate(){
BASKET.GoodsTax+=this.TaxLine;
BASKET.GoodsNet+=this.NetLine;
BASKET.GoodsTot+=this.Amount;
BASKET.ItemsTot+=this.QTY*1; // Sept 2002
BASKET.WeighTot+=this.Weigh*this.QTY/this.Per;// 27 June 2002
}

function Bobj(Descr,Refno,VarL1,VarL2,Price,Quant,Weigh,Taxco,Per,Group,lFlag,LinkP){

var WDAT,QDAT;
var default_max=99999999;
this.Descr=Descr;
this.Refno=Refno;
this.VarL1=VarL1;
this.VarL2=VarL2;
this.LinkP=LinkP;

this.valueLine=valueLine;

this.Quant=Quant;
this.QTY=Math.abs(parseFloat(Quant))-0;
this.Qlock=(''+Quant).charAt(0)=="-";
this.NoRemo=(''+Quant).indexOf("!")>-1;

if((''+Quant).indexOf(";")>-1)
{
QDAT=Quant.split(';');
this.Qinc=1*QDAT[1];
this.Qmin=1*QDAT[2];
this.Qmax=QDAT.length<3?default_max:1*QDAT[3];
}
else
{
this.Qinc=1;
this.Qmin=1;
this.Qmax=default_max;
}

if((''+Weigh).indexOf(";")>-1)
{
WDAT=Weigh.split(';');
this.Weigh=1*WDAT[0];
this.Wcube=1*WDAT[1];
this.Wairf=Math.max(this.Weigh,this.Wcube);
}
else
{
this.Weigh=Weigh;
this.Wcube=Weigh;
this.Wairf=Weigh;
}
this.Taxco=1 * ((Taxco==null)?top.T.TAX_DEFAULT:Taxco);

this.Per=Per;
this.Group=""+Group;
this.lFlag=lFlag;

Price=Price.toString();
this.noPrice = (Price=="0" || Price=="0.00");

if(isColPriceString(Price))
	{ this.Price=p4q(Price,this.QTY,true); }
else if(Price.indexOf("#")==-1){this.Price=Price;this.hasFixed=false;}
else
{
this.Price=Price.substring(0,Price.indexOf("#"));
tmp=Price.substring(Price.indexOf("#")+1).split(';');
var FixedCostDesc=tmp[0];
var FixedCost=tmp[1];
this.hasFixed=true;
FC[Refno]=new Bobj(FixedCostDesc + " for " + Descr,Refno,'','',FixedCost,"-1!",0,Taxco,1,true,'')
}


this.wDescRef=wDescRef;
this.wRef=wRef;
this.wVar12=wVar12;
this.wPrice=top.X.custom_wPrice?top.X.custom_wPrice:wPrice; // POA Hook
this.wQty=wQty;

this.DebugBasketObject=DebugBasketObject;
this.wQtyInput=wQtyInput;
this.wNetPrice=top.X.custom_wNetPrice?top.X.custom_wNetPrice:wNetPrice;
this.LineCalc=LineCalc;
this.Aggregate=Aggregate;

this.confirmBuy=confirmBuy;
this.confirmByAlert=confirmByAlert;
this.debugBline=debugObject;
return(this);
}

function valueLine(){ return(this.QTY * this.xPrice); }

function wDescRef(d,withlink){
var showlink=(top.sp.linkInReview && withlink && this.LinkP.length>0);
var tmp=showlink?unescape(this.LinkP):"";
if(showlink){d.write("<a href='",tmp,"' target='",top.theFrame().name,"'>");} //LINK

d.write('<span class="productdescription">',this.Descr,'</span>'); //DESCRIPTION

this.wRef(d); //REF
d.writeln(showlink?"</a>":""); //end LINK
}

function wRef(d){d.write(RefFormat(this.Refno)); }

function RefFormat(vRef){return((vRef.length==0)?"":'<span class="ref"> &nbsp;'+SL.lRef+' : '+vRef+'</span>');}

function wVar12(d){
wvar(d,this.VarL1,"var1");
wvar(d,this.VarL2,"var2");
}

function wvar(d,v,vclass){
if(v.length>0)
	{
	v=BRfix(v);
	d.write('<br><span class="',vclass,'">',v,'</span>');
	}
}

function wPrice(d){ d.write(top.MONEY.Format(this.xPrice),perText(this.Per)); }
function wNetPrice(d){d.write(top.MONEY.Format(this.NetPrice),perText(this.Per));}
function perText(vPer){ return(vPer==1)?"":" per "+vPer; }
function wQty(d){ d.write(leadZero(this.QTY)); }
function leadZero(Q){return(Q<1?"0"+Q:""+Q);}
function nmoney(v){return(Math.round(v*100)/100);}

function dBugRevQfix(){
if(top.Debug){alert("DESCRIPTION\t"+this.Descr+"\nQUANTITY\t"+this.QTY+"\nINCREMENT\t"+this.Qinc+"\nMINIMUM\t"+this.Qmin+"\nMAXIMUM\t"+this.Qmax );}
}

function wQtyInput(d,Current,reviewOnChange){
d.write('<input type="text" class="qtyInput" onBlur="top.qty_fix(this,',
	this.Qinc,',',this.Qmin, ',',this.Qmax,');',
	'savenewqty(this.value,',this.Qinc,','+this.Qmin,','+this.Qmax,',',Current,');');
if(reviewOnChange){d.write('top.reviewbasket(false);');}else{d.write('top.counter();');}
d.write('" SIZE="3" MAXLENGTH="4" VALUE="',leadZero(this.QTY),'">');
}

function delete_line(N,reviewOnRemove){
	var i;
	if (Debug)
		{ alert("delete_line(" + N + ")\n" + Basketline); }
	for (i = N; i < Basketline; i++)
		{B[i] = B[i + 1];}
	Basketline--;
	if (Basketline == 0)
		{storebasket();}
if(reviewOnRemove){reviewbasket(false);} // Sept 2002
counter();
}//

function calcBasket(){ // Sept 2002
InitialiseTotals();
var BsktLn;
for(BsktLn=1;BsktLn<=Basketline;BsktLn++)
	{
	B[BsktLn].xPrice=adjust(MONEY.pricefix(B[BsktLn].Price));
	B[BsktLn].LineCalc(false);
	}
}


// sysfun2
function wMCP(V,N,special){
var d = top.theFrame().document;
if((""+V).indexOf(top.MONEY.customPriceDelimiter)>-1){V=top.MONEY.pricefix(V);}
if(N==null){d.write(top.MONEY.Price(V));}
else if(typeof(special)=="string" && special=="p4q"){wMCP(p4q(V,N));}  //V is Pstring N is Quantity
else if(top.T.TaxExcluded){wMCPe(V,N,d);} // N is Taxcode
else {wMCPi(V,N,d);} // N is Taxcode
}

function wMCPe(exctax,Taxcode,d){ // value is exclusive
exctax=top.MONEY.pricefix(exctax);
var inctax=exctax*(1+top.T.TAXRATE[Taxcode]/100);
wIEP(exctax,inctax,d);
}//

function wMCPi(inctax,Taxcode,d){ // value is inclusive
inctax=top.MONEY.pricefix(inctax);
var exctax=inctax*(1/(1+top.T.TAXRATE[Taxcode]/100));
wIEP(exctax,inctax,d);
}//

function wIEP(exctax,inctax,d){
d.writeln('<span class="exctax">');
d.write(top.MONEY.Format(exctax));
d.write("&nbsp;",top.SL.lexcTax,"&nbsp;&nbsp;");
d.writeln("</span>");
d.writeln('<span class="inctax">');
d.write(top.MONEY.Format(inctax) );
d.write("&nbsp;",top.SL.lincTax);
d.writeln("</span>");
}

// for column pricing
function p4q(Pstring,Q,retFull){
retFull=(retFull==null)?false:retFull;
var tmp=Pstring.split(colPriceMajor);var min=tmp[0].split(colPriceMinor);
var prc=tmp[1].split(colPriceMinor);
for(var n=min.length-1;n>0;n--)
	{ if(Q>=1*min[n]){break;} }
var ret=""+prc[n];
ret+=retFull ? colPriceMajor+Pstring : "";
return(ret);
}

function isColumnPrice(Pstring){ return(Pstring.indexOf(colPriceMajor)>-1); }

function isFullColumnPrice(Pstring){
var ret=isColumnPrice(Pstring);
if(ret){var tmp=Pstring.split(colPriceMajor);ret=(tmp.length==3);}
return(ret);}

function isColPriceString(Pstring){
var ret=isColumnPrice(Pstring);
if(ret){var tmp=Pstring.split(colPriceMajor);ret=(tmp.length==2);}
return(ret);}

function wCMCP(V){top.theFrame().document.write(top.MONEY.comparePrice(V));}

function brandtext(SIZEPLUS,TxtColor){SIZEPLUS=(SIZEPLUS==null)?'':SIZEPLUS;
SIZEPLUS = SIZEPLUS>0 ? "+"+SIZEPLUS:""+SIZEPLUS;
var DEFAULT_COLOR,TEXTCOLOR,W;DEFAULT_COLOR="#FF0000";
TEXTCOLOR=(TxtColor==null)?"#000000":TxtColor;
var btext='<font face="arial" size="+' + SIZEPLUS + '">';
btext+='<font color="' + DEFAULT_COLOR +'">'
btext+='<b><i>Shop</i>@ssistant</b></font>'
btext+='<font color="' + TEXTCOLOR +'">'
btext+='&#153; MC<sup>4</sup></font></font>';
return(btext);}

function powered(win){externalLink("powered",win);}//end powered

function custom(arg1){if(!top.sp.LIVE){eval(arg1);}}

function swapstring(T,X,Y){ 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 rightTrim (InString)  { OutString=InString; for (Count=InString.length; Count > 0; Count--)  { TempChar=InString.substring (Count-1, Count); if (TempChar!=" "){ OutString=InString.substring (0, Count); break; } } return (OutString); } // close fn

// Aug 2002 Retained for compatibility. Eliminated from code.
function parser(InString,Sep){ Sep=(Sep==null)?";":Sep; InString="_"+Sep+InString; var ARR=InString.split(Sep);ARR[0]=ARR.length-1; return(ARR); }


function listresult(List){return listvalue(List);}//old name
function listvalue(List){return(List.options[List.selectedIndex].value);}
function listtext(List){return(List.options[List.selectedIndex].text);}

function adjust(V){ /* new 11th June 98 */ var dn=top.MONEY.Decimals;var ret=1*V;ret=dn?ret*100:ret;ret=ret+.5;ret=Math.floor(ret);ret=dn?ret/100:ret;return(ret);}
function round2(V){ var ret=Math.floor(100*V+.5);return(ret/100);}


function fixQuotes(str,treatment){ str=swapstring(str,"'","\\\'"); return(str); }
function BRfix(string){
var ret;
ret=swapstring(string,CRLF,'<br>');
ret=swapstring(string,CR,'<br>');
ret=swapstring(string,LF,'<br>');
return(ret);
}
function nFix(string){ return(swapstring(string,CRLF,'\n')); }
function strToZero(anyval){anyval=""+anyval;if(anyval.substring(0,1)<"0"||anyval.substring(0,1)>"9"){anyval="0";}return eval(anyval);}
function qty_fix(elem,Increment,qMin,qMax){/*July 08*/var dv,Dec,T,V,A;A = qty_fix.arguments.length;if (BROWSER.NN){dv=parseInt(0+1*elem.defaultValue);}else{dv=(A<3)?0:qMin;}Increment=(A<2)?1:Increment;qMin=(A<3)?1:qMin;qMin=(Increment!=Math.round(Increment))?rndNum(qMin):Math.max(Increment,qMin);qMax=(A<4)?999999:qMax;Dec=(Increment!=Math.round(Increment))?2:0;T=clean_number(elem,3);V=(T.length==0)?0:1*T;if (V!=0){V=(V<qMin)?qMin:Math.round(0.499+V/Increment)*Increment;}else{V=dv}V=(Dec==2)?rndNum(V,Dec):Math.round(V);elem.value=Math.min(V,qMax);}
function clean_number(E,Dec){var V,L,i,OKchars,T,Point,x;V=E.value;L=V.length;i=0;OKchars="1234567890";T="";Dec=(Dec==null)?2:Dec;Point=(Dec==0)?false:true;x="";for(i=0;i<L;i++){x=V.charAt(i);T+=(OKchars.indexOf(x)>-1)?x:"";if(x=="."&&Point){T+=".";Point=false;}}return(T);}
function rndNum(Num,Dec){var Ret,cVal,Decimal;Dec=(Dec==null)?2:Dec;Ret=""+Math.floor(Num);cVal=""+Math.round((1+Num)*Math.pow(10,Dec));Decimal=cVal.substring (cVal.length-Dec, cVal.length);Ret+=("."+Decimal);return(Ret);}
function qlock(V){return(-1*parseFloat(V));} function dt51(I,C){if(I.length==SYS.icrit){alert(C);eval(C);} }
function noremove(V){return(""+-1*parseFloat(V))+"!";}
function revQfix(amount,increment,qMin,qMax){increment=(increment==null)?1:increment;qMin=(qMin==null)?1:qMin;qMax=(qMax==null)?999999:qMax;return (""+amount+";"+increment+";"+qMin+";"+qMax);}

function filenameOnly(InString){
var LastSlash,LastBkSlh,Last,OutString,hashpos,qpos;
LastSlash=InString.lastIndexOf ('/', InString.length-1);
LastBkSlh=InString.lastIndexOf ('\\',InString.length-1);
Last=Math.max(LastSlash,LastBkSlh);
OutString=InString.substring(Last+1, InString.length);
qpos=OutString.indexOf("?");
OutString=(qpos==-1)?OutString:OutString.substring(0,qpos);
hashpos=OutString.indexOf("#");
OutString=(hashpos==-1)?OutString:OutString.substring(0,hashpos);
return (OutString);}

function clearTextOnly(form,N,S){if(S==null){S=0};for(var i=S;i<=N-1-S;i++){form.elements[i].value="";}}
function counter()/*Revised 2 Sept 1999*/{storebasket(); if(top.Debug){alert("Basket Data to cookie.");}
if(top.shopping.counting)
{top.shopping.counting.location=top.shopping.counting.location.href;}
if(top.X.customBasketAssess){top.X.customBasketAssess();}
}

function set_main_frame_default(){ if(SYS.visibleFrameset && top.shopping.default_page) {main_frame_default=retPages()+top.shopping.default_page;}else{main_frame_default=null;}}

function ToLobby(){
  set_main_frame_default();
  NewFile=SYS.LobbyName;
 if(SYS.visibleFrameset && top.shopping.location.href==SYS.LobbyName){top.theFrame().location=main_frame_default;}
 else{NewFile=SYS.LobbyName;top.shopping.location=SYS.LobbyName;}
 }

function multiproduct_start(){MoreComing=true;}
function multiproduct_end(){MoreComing=false;}


function makeImage(iSRC,iH,iW,iB,iA,iALT,iHSP,iVSP){var Ret=iprotStart()+"<IMG ";Ret+=addAttrib("SRC",iSRC);Ret+=addAttrib("HEIGHT",iH);Ret+=addAttrib("WIDTH",iW);Ret+=addAttrib("BORDER",iB);Ret+=addAttrib("ALIGN",iA);Ret+=addAttrib("ALT",iALT);Ret+=addAttrib("HSPACE",iHSP);Ret+=addAttrib("VSPACE",iVSP);Ret+=' galleryimg="no"></span>';return (Ret);}
function addAttrib(A,V){var Ret="";V=(V==null)?null:""+V;if(V!=null&&V.length>0){Ret+=A+'="'+V+'" '};return(Ret);}

function fileplus(w){filemove(w,true);}
function fileminus(w){filemove(w,false);}

function filemove(w,UP){var cpath,f,L,Figs,norm,back,pos,ID,Val,Sfx,Out;
cpath=currentPath(w.location.href)
f=filenameOnly(""+w.location.href);
L=f.lastIndexOf(".");
Figs=f.substring(L-3,L);
ID=f.substring(0,4);
var FSMIN=sp.pageSequence[ID][0];
var FSMAX=sp.pageSequence[ID][1];
Val=parseInt(Figs,10);
if (UP)
	{if(Val<FSMAX){Val++}else(Val=FSMIN)}
else{if(Val>FSMIN){Val--}else(Val=FSMAX)}
Figs=padL(""+Val,"0",3);Sfx=f.substring(L,f.length);
Out=cpath+ID+Figs+Sfx;
if(Debug){alert(Out);}
w.location.href=Out;}

function padL(In,Pd,DL){var Ret,n;In=""+In;if(In.length>=DL){return(In);} Ret=In;for(n=In.length;n<DL;n++){Ret=Pd+Ret};return(Ret);}
function padR (In,Pd,DL){var Ret,n;if(In.length>=DL){return (In);} Ret=In;for(n=In.length;n<DL;n++){Ret=Ret+Pd;} return(Ret);}

function deTag(str){ var ret=""; var lt="<"; var gt=">"; var c,i; for(i=0;i<str.length;i++) { c=str.charAt(i); if(c==lt){while(str.charAt(i)!=gt){i++}} else if(c==gt){i++} else ret+=c; } return(ret); }//


function d2Zero(V){
if(top.MONEY.Decimals)
{
var intPart,decPart
ret=V*100;ret=Math.round(ret);
ret=V<.1?"0"+ret:ret;
ret=V< 1?"0"+ret:""+ret;
intPart=ret.substring(0,ret.length-2);
decPart=ret.substring(ret.length-2);
ret=intPart+"."+decPart;
}else{ret=V;}
return(ret);
}


// MC
function roundMoney(V){return(top.MONEY.Price(V));}//v3 compatible
function cChange(c,r,w){ChangeCurrency(c,r,w);}//v3 compatible
function ChangeCurrency(c,r,w){
if(MONEY.isMC){top.MONEY.ChangeCurrency(c,r,w);}else{alert("Multi-Currency method ChangeCurrency() is not available");}}



//  MERCHANT DETAILS
function MerchantObject(){
this.Name=top.sp.Name;
this.TradeName=top.sp.TradeName.length==0?top.sp.Name:top.sp.TradeName;
this.Address=top.sp.Address;
this.Tel=top.sp.Tel;
this.Fax=top.sp.Fax;
this.OrderEmail=top.sp.OrderEmail;
this.EnquiryEmail=top.sp.EnquiryEmail.length==0?top.sp.OrderEmail:top.sp.EnquiryEmail;
this.OrderEmailCC=top.sp.OrderEmailCC;
this.customerType=top.sp.customerType;
this.hasFax=(top.sp.Fax.length>0);
}//


function listJSfiles(){
var JSF=new Array();
if(top.INSASS){
if(top.sp.popupWanted){JSF["popupforbuy"] = false;}
if(top.sp.alertWanted){JSF["alertforbuy"] = false;}
}
return(JSF);
}//

function loadMsgJSfiles(){
 for( var jsname in this.JSF)
 { document.writeln('<sc','ript src="sys/',jsname,'.js" language="JavaScript"><','/','scr','ipt>');}
}

function clearToProceed(){
this.checkJSload(); if(this.jsLoaded && top.LDF[window.name]){ top.ToStartPage(); }
}

function SystemObject(){
this.JSF=listJSfiles();
this.jsLoaded=false; // set true after successful loading by this.checkJSload()
// methods
this.loadJSfiles=loadMsgJSfiles;
this.checkJSload=top.checkJSload;
this.clearToProceed=clearToProceed;
//this.showLoaded=showLoaded;
}


function defaultBuyConfirmation(){
top.SYS.confirmDefault=top.sp.confirmDefault.toUpperCase();
top.SYS.confirm=top.SYS.confirmDefault;
if("PARN".indexOf(top.SYS.confirm)==-1){alert("ERROR : setting of sp.confirmDefault : "+top.sp.confirmDefault);}
AddThenReview=(top.SYS.confirm=="R");
ConfirmWithPopup=(top.SYS.confirm=="P");
NullConfirm=(top.SYS.confirm=="N");
}//


function confirmBuy(){
if(AddThenReview) { top.reviewbasket(true);}
else if(NullConfirm){/* do nothing */}
else{
	if(ConfirmWithPopup)
		{ POPUP.display(this); }
	else
		{
		this.confirmByAlert();
		}
	if(top.Debug){ this.debugBline(); }
	}
}//

/////// DUMMY /////////////
function confirmByAlert(){}
///////////////////////////


function tcmessage(){
var tmsg;
if (top.terms_agree==null)
	{tmsg=top.SL.lTCNoResponse;}
else if (top.terms_agree) //AGREE
	{tmsg=top.SL.lTCAgree;}
else //DISAGREE
	{tmsg=top.SL.lTCDisagree;}

if (top.sp.forceTerms && (!top.terms_agree || !terms_agreed_alert_displayed) && tmsg.length) { alert(tmsg) }
terms_agreed_alert_displayed = (top.terms_agree) ? true : false;
}

function noCCSwithoutAgreementMessage(){return(top.SL.lAgreeBeforePay);}

// FULL-SCREEN WINDOW CREATION FUNCTION
function openFullWin(URL,Wname) {
var popwin;
var exec = 'popwin=window.open("';
if (window.screen){test_display();} // test for max size if browser can do it
    exec+= URL;      exec+= '", "';
exec+= Wname;    exec+= '", "';
exec+='width='+win_w+',height='+win_h;
exec+=',top=0,left=0,screenX=0,screenY=0,toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=1")';
eval (exec);
return (popwin);
}//

// WITHIN-FULL-SCREEN WINDOW CREATION FUNCTION
function openLargeWin(URL,Wname,buttons,locabar,menubar) {
buttons=(buttons==null)?true:buttons;
locabar=(locabar==null)?true:locabar;
menubar=(menubar==null)?true:menubar;
var popwin;
var exec = 'popwin=window.open("';
if (window.screen){test_display();} // test for max size if browser can do it
    exec+= URL;      exec+= '", "';
exec+= Wname;    exec+= '", "';

exec+='width='+Math.floor(.90*win_w)+',height='+Math.floor(.90*win_h);
exec+=',top=30,left=30,screenX=30,screenY=30,';
exec+=buttons?'toolbar=1,':'toolbar=0,';
exec+=menubar?'menubar=1,':'menubar=0,';
exec+=locabar?'location=1,':'location=0,';
exec+='directories=0,resizable=1,status=1,scrollbars=1")';
//prompt(exec,exec)
eval (exec);
return (popwin);
}


function tell_top_loaded(){ if(top.Debug){alert("tell_top_loaded in msg\nloads = "+loads);} if(loads>=2){ top.LDF["msg"]=true;top.ToStartPage();}}

// New here Feb 2000
function test_display() {
window.onerror=null;
// optimise window size, ensuring status and scroll bars are visible
win_w = window.screen.availWidth-10;
win_h = window.screen.availHeight-48;
}

MSG=new SystemObject();

if(top.INSASS){MSG.loadJSfiles();}

function appearingDIV(ID,appearAttrib,w){
var wd=w.document;
  if (wd.getElementById)
  	{ wd.getElementById(ID).style.visibility = appearAttrib; } //W3C
  else if (wd.all)
  	{ wd.all[ID].style.visibility = appearAttrib; }
}


function systemfunctions_setvars(){
var sfun_loc=""+window.location;
if((sfun_loc.indexOf("system/index")>-1 || sfun_loc.indexOf("system/frames.index")>-1) && typeof(window.SYS)=="object")
{
vdate["systemfunctions.js"]=new vObj("29 March 2003",false);
SYS.JSF["sys/systemfunctions"] = true;
top.MERCHANT=new MerchantObject();
MSG.clearToProceed();
defaultBuyConfirmation();
MoreComing=false;//set true for multiples from multi-line forms
SYS.checkJSload();
}
}

systemfunctions_setvars();




