// <!-- FEB 2003 -->
// boss.js
//  ===============================================================
//  "BOSS" SCRIPT
//  for Shop@ssistant Classic Version 3.6.4C+ by Rodney Myers
//  Copyright © 2000-2003, Hodgson Myers Associates Ltd
//  Version 2.21
//  An Add-On for Shop@ssistant Classic
//  rodney@aflyingstart.net                       Tel +44 (0)1865 200025
//  http://www.aflyingstart.net/addons/
//  Last Revised February 2003
//  ===============================================================
// LOD/BOSS
var INSASS=false;

// LOD vars
var currencyCode="£";
var colPbar="|";var colPsemi=";";

// BOSS Vars
var MAX_QTY=99999999;
var usePOP=false; // set usePOP=true on any page where you wish to use the feature
var outsideSystemHandler=2;

// BOSS Functions
function start_shop()  {
if(common_test() && !top.INSASS)
	{
	setLocation(); // cookie
	top.location.href =startup+"?loadnow";
	}
} //

// Common LOD/BOSS functions
function setLocation(){
var saveLoc;
/*
If introducing an iframe eg from uk.affiliates.com (and no other frames)
name is inaccesssible so no point in adding a name to the iframe
*/
if(window.frames.length==0 || window.frames.length==1)
		{saveLoc = window.location.href;}
else	{saveLoc = myFrame.location.href;}
/*
If using a framed site and encountering problems please
delete if else clauses above and revert to next line
*/
// saveLoc=(window.frames.length>0)?myFrame.location.href:window.location.href;
document.cookie = "LOADTHISPAGENOW" + "=" + escape(saveLoc)+"; path=/";
}

function pages_browser_test(){
/* Adapted from Ultimate client-side JavaScript client sniff. (C) Netscape Communications 1999.  Permission granted to reuse and distribute. */
var agt,is_major,is_nav,is_nav3up,is_ie3up;
 agt=navigator.userAgent.toLowerCase();
 is_major = parseInt(navigator.appVersion);
 is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1));
 is_nav3up = (is_nav && (is_major >=3));
 is_ie3up  = ((agt.indexOf("msie") != -1) && (is_major >=2));
 ////// Allow OPERA 6 : July 2002
 var is_opera6up=(is_major >= 4) && (agt.indexOf('opera 6')>-1);
 return(is_nav3up||is_ie3up||is_opera6up);
 }// end pages_browser_test

function common_test(){
var ret=pages_browser_test();
if(!ret){alert("Sorry, your browser is not supported");}
return(ret);
}

function nosass(){ /* Used if system not loaded and functions in "For LOD" section are called */
if(confirm("Load shopping system,then\nreturn to this page to continue?"))
{ start_shop(); } else {return(' ');} }//


// For LOD type operation
function ToLobby()      { nosass(); }
function reviewbasket() { nosass(); }
function terms()        { nosass(); }
function checkout()     { nosass(); }

// MC4 buttonbars and links (no action, no error)
function makeButtonBarH(){}
function makeButtonBarV(){}
function makeTextLinksH(){}
function makeTextLinksV(){}

// For display of prices
function MCP(V){
V=parseFloat(""+V);
V=Math.floor(V*100)/100;
if(V==Math.floor(V)){V+=".00";}else if(10*V==Math.floor(10*V)){V+="0";} return(currencyCode+V);}

function wMCP(V,Q,special){
if(typeof(special)=="string" && special=="p4q"){V=""+p4q(V,Q);}
document.write(MCP(V));
}

function wCMCP(V){wMCP(V);}
var MC=new MCF();
function MCF(){
this.MCPrice=MCP;
return(this);
}

function p4q(Pstring,Q){
var tmp=Pstring.split(colPbar);var min=tmp[0].split(colPsemi);
var prc=tmp[1].split(colPsemi);
for(var n=min.length-1;n>0;n--)
	{ if(Q>=1*min[n]){break;} }
return(""+prc[n]);
}


// For BOSS operation
function newchoice(d,r,v1,v2,p,q,w,t,per,group){
per=(per==null)?1:per;group=(group==null)?'0':group;
newchoice1(d,r,v1,v2,p,q,w,t,per,group);}

function newchoice1(d,r,v1,v2,p,q,w,t,per,group){
per=(per==null)?1:per;// for FromPop
group=(group==null)?'0':group;
if(common_test())
{
var loc=startup;
loc+="?";
loc+="d="+u(d)+"&";
loc+="r="+u(r)+"&";
loc+="v1="+u(v1)+"&";
loc+="v2="+u(v2)+"&";
loc+="p="+u(p)+"&";
loc+="q="+u(q)+"&";
loc+="w="+u(w)+"&";
var TAX_DEFAULT=1; // Match this with vars of same name in tax.htm and startup file 'root' index.html
t= (t==null) ? TAX_DEFAULT : t ;
loc+="t="+u(t)+"&";
loc+="per="+u(per)+"&";
loc+="group="+u(group);
// For Pop-up of basket addition
// set usePOP=true on any page where you wish to use the feature
loc+=usePOP?"&f=BOSSPOP":"";
setLocation();
loc+=(typeof(marketSetting)=="string")?"&market="+marketSetting:""; // 20 January 2003
window.location.href=loc;
}
}//

function dpw(d,p,w){ w=(w==null)?0:w; newchoice(d,"","","",p,1,w,null,1,0); }
function drpw(d,r,p,w){ w=(w==null)?0:w; newchoice(d,r,"","",p,1,w,null,1,0); }
function tempBuyConfirmation(LTR){if(LTR){LTR=LTR.toUpperCase();if(LTR=="P"){usePOP=true;} }}


// Make data into URL format
function u(str){ var ret="";var ch; str=escape(str); for(var i=0;i<str.length;i++){ch=str.charAt(i);ret+=(ch=="+")?"%2B":ch;} return(ret); }

// For quantity/remove checkbox features in Review
function noremove(V){return(""+-1*parseFloat(V))+"!";}
function revQfix(a,i,n,x){i=(i==null)?1:i;n=(n==null)?1:n;x=(x==null)?999999:x;return (""+a+";"+i+";"+n+";"+x);}
function qlock(V){return(-1*parseFloat(V));}

// for Quantity inputs
function qty_fix(elem,Increment,qMin,qMax) {
var ev=elem.value;
var permitted="1234567890";
permitted += Increment<1 ? "." : "";
ev=clean(ev,permitted);
if(ev<qMin){ev=qMin;}
else if(ev>qMax){ev=qMax;}
else if( (ev-qMin)/Increment != Math.ceil((ev-qMin)/Increment)){ev=1*qMin+Math.ceil((ev-qMin)/Increment)*Increment;}
elem.value=ev;
}//

function clean(str,permitted){
str=""+str;
var nchar,n;var out="";
for(n=0;n<str.length;n++)
	{
	nchar=str.charAt(n);
	out+=permitted.indexOf(nchar)>-1?nchar:"";
	}
return(out);
}

// for SELECT boxes
function listvalue(List){return(List.options[List.selectedIndex].value);}
function listtext(List){return(List.options[List.selectedIndex].text);}

// for currency change
function ChangeCurrency()    { nosass(); }
function cChange()    { nosass(); } // v3.x

// For splitting data
function parser(InString,Sep){ Sep=(Sep==null)?";":Sep; InString="_"+Sep+InString; var ARR=InString.split(Sep);ARR[0]=ARR.length-1; return(ARR); }

// for MC4 frameset
waiting3=false;

