// <!-- 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=true;
var myFrame;


// 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()  {

	setLocation(); // cookie
	top.location.href =startup;
	
} //

// Common LOD/BOSS functions
function setLocation(){
var saveLoc;
myFrame=typeof(userMainFrame)=="string" ? eval("window."+userMainFrame+".document") : window;
/*
If introducing an iframe eg from uk.affiliates.com (and no other frames)
name is inaccessible 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 nosass(){ /* Used if system not loaded and functions in "For LOD" section are called */
 }//




// 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);}
var d=typeof(userMainFrame)=="string" ? eval("window."+userMainFrame+".document") : window.document;
d.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;

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()    { alert('not supported, you should be using a php call') }
function cChange()    { alert('not supported, contact matt') } // 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); }
// extra functions
function roundMoney(V){
V=parseFloat(""+V);
V=Math.floor(V*100)/100;
return V;
}//v3 compatible
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);}
// for MC4 frameset
waiting3=false;

