// magic.js
//--|
// Copyright © 2000-2003, Hodgson Myers Associates Ltd.
// All Rights Reserved
// Licences may be purchased separately or obtained as part of a training package.
// Licencees using this script may use it in as many pages and sites as they wish.
// Licencees 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
//--|

//--------------------------------------------------------------------------------------------
// History after first release to December 2000 course participants
// Dec 16
// Radio buttons may be unchecked, and are verified
// First examples of function customAddData. form object passed. call to setProductData(pkey) moved up.
// Jan 15 2001
// debugged calls for pkey
// Jan 18
// experimental multi version begun
// Jan 22
// outsideSystemHandler variable introduced to lod364.js in 3.6.4C, load_on_demand.js in MC4 and boss.js and multiboss.js
// with respective values of 1,2,3 buy() and multibuy() functions check this value.
// March 13 amendments to multibuy1() to prevent additions to basket of items preceding items with omissions in form

// April 19 2001 Modified isForm() and added BrowserCheck().
// Both functions and the two lines calling them may be deleted
// April 20 2001 Modified multibuy1() to make calls to newchoice outside system with MULTIBOSS loaded
// May 16 Support for checkboxes with price additions in their value  using $caption
// August Support in multibuy forms for common inputs, names end _common  eg Fabric_common
// Sept 04 qlock_common supported in multibuy forms
// Sept 05 checkbox and radio button support for $ prefix extended with ; delimited values option
// Oct 02 Trailing zeroes bug fixed. See message of this date in afs_magic
// 2002
// July 12 Fixed messaging for missing inputs in multiproduct forms.
// July 30 hook call to postScriptAdditions(form) on page
// July 31 In $ or _$ fields data may be two part with price addition followed by ref suffix ";" separated.
// August 2002 : Support for Group codes and Per pricing settings
// Support for multiboss and boss being included in frameset but not individual pages - which force load into frameset
// Jan 2003
// Support for adding to total price from checkboxes and radio buttons
// Support for minimum_common increment_common
// --|
var currencySymbol="£";
var outsideSystemHandler=0;
var ProductName,ProductRef,Price,Weight,TaxCode,VARSLOT2,Per,Group;
var productData=new Array();
var INSASS=false;

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=";";
// for custom pricing
customPriceDelimiter="[";
// To upgrade multi product messages
// 17 September 2002
var plsSpec = "Please Specify ";
var plsInpt = "Please Input ";

function setvars(){
if(window.reValue){reValue();} // uses cookie restoration if cookie script present.
}

function multibuy(form){
outsideSystemHandler=getOutsideSystemHandler();
     if(top.INSASS || outsideSystemHandler >=3){multibuy1(form);}
else if(outsideSystemHandler==2){if(!http_mode()){alert("MISSING COMPONENT\n\nmultiboss.js is required to handle\nthis page outside Shop@ssistant system.");}else{nosass();}}
else if(outsideSystemHandler==1){nosass();}
else if(outsideSystemHandler==0){alert("No shopping system loaded");}
}

function getOutsideSystemHandler(){
return (typeof(parent.outsideSystemHandler)=="number")?parent.outsideSystemHandler:window.outsideSystemHandler;
}


function multibuy1(form){
var qe;
var formErrors="";
var addchoice = new Array();
multiQtyFound=false; OK=true;
var cboxqty=false; // new July 31 2001
setProductArrayData();
for (var pkey in productData)
	{
	productErrors="";
	setQdefaults(form);
	Add2Price=0;Add2Ref="";
	if(form["qty_"+pkey])
		{
		qe=form["qty_"+pkey];
		// alert(pkey); //!!
		var QVAL;
		if(qe.type=="checkbox"){cboxqty=true;} // new July 31 2001

		if(qe.type=="text"){Qty=1*(0+qe.value);}
		else if(qe.type=="checkbox" && qe.checked){Qty=1;}
		else if(qe.type=="select-one"){Qty=lv(qe);}

		if(eval("form.qlock_"+pkey))   {QVAL=-1*Qty;}
		else if(form.qlock_common)   {QVAL=-1*Qty;}
		else if(eval("form.noremove_"+pkey)){QVAL=noremove(Qty);}
		else if(eval("form.noremove_common")){QVAL=noremove(Qty);}
		else                  {QVAL=top.revQfix(Qty,Inc,Min,Max);}

		if(Math.abs(Qty)>0)
			{
			multiQtyFound=true;
			VARSLOT1=getDataforPkey(form,pkey);
			VARSLOT1+=VARSLOT1.length>0?CRLF:"";
			VARSLOT1+=getDataforPkey(form,'common');
			VARSLOT1=stripTrailingCRLF(VARSLOT1);
			// end of new code
			if(OK)
				{
				multiSetProductData(pkey);
				/*
				Per=1;Group=0;
				if(eval("form.per_"+pkey)){Per=form["per_"+pkey].value; }
				if(eval("form.group_"+pkey)){Group=form["group_"+pkey].value; }
				*/
		    	if(typeof(Price)=="number") { Price+=Add2Price; }
				else if(typeof(Price)=="string" && Price.indexOf(colPbar)>-1){Price=fix_price_string(Price,Qty)}
				else if(typeof(Price)=="string" && Price.indexOf("[")>-1){/* do nothing */}
				else if (Add2Price>0){alert("Error : Cannot Add to Price")}
				addchoice[pkey]=new addObj(ProductName,ProductRef+Add2Ref,VARSLOT1,VARSLOT2,Price,QVAL,Weight,TaxCode,Per,Group)
				}
			else
				{
				productErrors=(productErrors.length>0) ? "\n"+productData[pkey].ProductName+productErrors+"\n" : "";
				formErrors += productErrors;
				}
			}
		}
	}

if(multiQtyFound && OK)
	{
	makeNewChoices(addchoice,form);  top.reviewbasket(true);
    top.multiproduct_end(); // July 30

	}
else if(!multiQtyFound)
	{
	var piqmsg=cboxqty?"Please check the box next to each item you wish buy.":"Please input a quantity for each item you wish buy.";
	alert(piqmsg); // new July 31 2001
	}
else if(!OK){alert("MISSING INPUTS\n"+formErrors);} 
}//

function addObj(D,R,V1,V2,P,Q,W,T,Per,Group){
this.D=D; this.R=R; this.V1=V1; this.V2=V2; this.P=P; this.Q=Q; this.W=W; this.T=T;this.Per=Per;this.Group=Group;
this.addNewChoice=addNewChoice;
}//

function makeNewChoices(addchoice,form){// July 30
multiproduct_start();
for(var pkey in addchoice){addchoice[pkey].addNewChoice();}
if(window.postScriptAdditions){postScriptAdditions(form);} // July 30
multiproduct_end();
}//

function addNewChoice() { // method of addObj
top.newchoice(this.D,this.R,this.V1,this.V2,this.P,this.Q,this.W,this.T,this.Per,this.Group);
}


function getDataforPkey(form,pkey) {
var last=form.elements.length;
var ret="";
var e,str,caption;
var atmp;
for(var i=0 ; i<last; i++)
 {
 e=form.elements[i];str="";
 multiCheckQfields(e,pkey);
 if(elementBelongs(e,pkey))
 	{
 	caption=fixCaptionMulti(e,pkey);
 	// alert(pkey+"\n"+caption);
	if(e.type=="select-one")
	 	{
	 	if(notOptional(e) && e.selectedIndex==0){OK=false;productErrors+="\n\t"+plsSpec+caption;} // Sept 2002
		if(e.name.charAt(0)=="$" || e.name.substring(0,2)=="_$")
			{
			if(lv(e).indexOf(";")>-1)// price and reference
				{
				// split data
				atmp=lv(e).split(";");
				Add2Price+=1*atmp[0];
				Add2Ref+=atmp[1];
				}
			else // just price
				{ Add2Price+=1*lv(e);}
			}
		if(e.name.charAt(0)=="#" || e.name.substring(0,2)=="_#")
			{Add2Ref+=lv(e);}
		str = stripUnderscores(lt(e));
		} // could use top.listtext()

 	if(e.type=="text")
 		{
	 	if(notOptional(e) && e.value.length==0){OK=false;productErrors+="\n\t"+plsInpt+caption}
 		str=e.value;
 		}

 	if(e.type=="textarea")
 		{
	 	if(notOptional(e) && e.value.length==0){OK=false;productErrors+="\n\t"+caption}
 		str=(e.value.length>0)?CRLF+e.value:"";
 		}

	 if((e.type=="checkbox" ) && e.checked)
	 	{
	 	if(e.name.charAt(0)=="$"){Add2Price+=1*e.value;str="YES"}
	 	else{str=e.value;str=(str.length==0 || str=="checkbox")?"YES":str;}
	 	}
	 if((e.type=="radio") && e.checked){str=e.value;}

	 if((e.type=="hidden") && e.name.toLowerCase().indexOf("group")==0){Group=e.value;}
	 if((e.type=="hidden") && e.name.toLowerCase().indexOf("per")==0){Per=e.value;}


 if(str.length>0)
   {
	caption=fixCaption(caption);
    ret+=caption.bold() + " : " +str+CRLF;
   }

 	}
 }

return(ret);
}

function notOptional(e){return(e.name.charAt(0)!="_");}

function fixCaptionMulti(e,pkey){
ret=e.name.substring(0,e.name.lastIndexOf("_"+pkey));

return(fixCaption(ret));
}


function elementBelongs(e,pkey){
var n=e.name;
var ret=n.substr(0,3)!="qty";
if(ret)
	{
	p=n.lastIndexOf("_"+pkey);
	ret= (p==(n.length-pkey.length-1));
	}
return(ret);
}

function buy(form){

if(form.multibuy)
	{multibuy(form); }
else
	{ onebuy(form); }
return(false); //!!??
}

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));
	if(typeof setProductArrayData == "function"){setProductArrayData();multiSetProductData(pkey)}else{setProductData(pkey);}
	VARSLOT1 = stripTrailingCRLF(getInputFrom(form)); // moved
    var QVAL;
         if(form.qlock)   {QVAL=-Qty;}
    else if(form.noremove){QVAL=noremove(Qty);}
    else                  {QVAL=top.revQfix(Qty,Inc,Min,Max);}
    Group=0;Per=1;
    if(form.Group){Group=form.Group.value;}  // Input name must be exact. Aug 2002
    if(form.group){Group=form.group.value;}  // Input name must be exact. Aug 2002
    if(form.Per){Per=form.Per.value;}  // Input name must be exact. Aug 2002
    if(form.per){Per=form.per.value;}  // Input name must be exact. Aug 2002

    if(typeof(Price)=="number"){Price+=Add2Price;}
	else if(typeof(Price)=="string" && Price.indexOf(colPbar)>-1){Price=fix_price_string(Price,Qty)}
	else if(typeof(Price)=="string" && Price.indexOf("[")>-1){/* do nothing */}
    else if (Add2Price>0){alert("Error : Cannot Add to Price\nPrice is not numeric")}
	top.newchoice(ProductName,ProductRef+Add2Ref,VARSLOT1,VARSLOT2,Price,QVAL,Weight,TaxCode,Per,Group)
	}
else
	{alert(message);}
}

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 noremove(V){return(""+-1*parseFloat(V))+"!";}

function setQdefaults(form){// Defaults for Quantity related variables
Qty=(form.multibuy)?0:1; Min=1; Max=99999999; 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;}
 else	if(e.name.substring(0,2)=="__" ){ret=true;}
return(ret);
}

function hQfld(e,tag){return(e.type=="hidden" && e.name.toLowerCase()==tag);}


function multiQfix(qe){
var form=qe.form;var e;
var pkey = qe.name.substring(qe.name.lastIndexOf("_")+1);
setQdefaults(form);

for(var i=0 ; i<form.elements.length; i++)
 {
 e=form.elements[i];
 multiCheckQfields(e,pkey);
 multiCheckQfields(e,"common");
 }

qtyFix(qe,Inc,Min,Max);
}

function multiCheckQfields(e,pkey){
if(mhQfld(e,pkey,'increment')){Inc=e.value;}
if(mhQfld(e,pkey,'minimum')  ){Min=e.value;}
if(mhQfld(e,pkey,'maximum')  ){Max=e.value;}
}

function mhQfld(e,pkey,tag){return(e.type=="hidden" && e.name==tag+"_"+pkey);}


function magicQfix(qe){
var form=qe.form;var e;
setQdefaults(form);
for(var i=0 ; i<form.elements.length; i++)
 {
 e=form.elements[i];
 checkQfields(e);
 }
qtyFix(qe,Inc,Min,Max);
}

function show__Total(form){
var e,N;
Add2Price=0;
for(var i=0 ; i<form.elements.length; i++)
 {
 e=form.elements[i];
 checkQfields(e);
  if(e.type=="select-one")
  	{
	N=e.name;
	if(N.charAt(0)=="$" || N.charAt(1)=="$" )
			if(lv(e).indexOf(";")>-1)// price and reference
			{
			// split data
			atmp=lv(e).split(";");
			Add2Price+=1*atmp[0];
			// Add2Ref+=atmp[1];
			}
			else // just price
			{ Add2Price+=1*lv(e);}
	}
  if(e.type=="checkbox" && e.checked)
  	{
	N=e.name;
	if(N.charAt(0)=="$")
		{ Add2Price+=1*e.value; }
	}
  if(e.type=="radio" && e.checked)
  	{
	N=e.name;
	if(N.charAt(0)=="$")
		{ Add2Price+=1*parseFloat(e.value); }
	}
 }
// setProductData(pkey);
if(window.setProductData)
	{
	setProductData(pkey);
	}
else if(window.setProductArrayData)
	{
	if(typeof(productData[form.pkey.value])=="undefined"){ setProductArrayData();}
	Price=productData[form.pkey.value].Price;
	}


if(form.__Total)
	{
    if(typeof(Price)=="number"){Price+=Add2Price}else{alert("ERROR : Price is not a number!")}

 	form.__Total.value=top.INSASS ? top.MC.MCPrice(top.adjust(Price)) : currencySymbol+moneyPlain(Price);
	}
else
	{
	alert("Form needs a text type input named __Total\nAnd that's TWO leading underscores");
	}
}


function getInputFrom(form,last){
var last=form.elements.length;
var extra=" : extra cost included"; //
setQdefaults(form);
var ret="";
var e,str;
var caption;
for(var i=0 ; i<last; i++)
 {
 e=form.elements[i];str="";
 caption=e.name;
 // remove leading underscore if any
 caption=(caption.charAt(0)=="_") ? caption.substring(1):caption;
 if(checkQfields(e)){continue;}


 if(e.type=="text"){str=e.value;}
 if(e.type=="textarea"){str=(e.value.length>0)?CRLF+e.value:"";}
 if(e.type=="select-one")
 	{
	if(caption.charAt(0)=="$")
		{
			if(lv(e).indexOf(";")>-1)// price and reference
			{
			// split data
			atmp=lv(e).split(";");
			Add2Price+=1*atmp[0];
			Add2Ref+=atmp[1];
			}
			else // just price
			{ Add2Price+=1*lv(e);}
		}
	if(caption.charAt(0)=="#")
		{Add2Ref+=lv(e);}
	str = stripUnderscores(lt(e));
	} //

 if(e.type=="radio" && e.checked)
 	{
	if(caption.charAt(0)=="$") //!! Sept 04
		{
		var bits=e.value.split(";")
		Add2Price+=1*bits[0];
		var priceAdded=(top.INSASS)?" @ "+top.MC.MCPrice(1*bits[0]):"";
		str=bits[1]
		str+=(1*bits[0]>0)?extra+priceAdded:"";
		}
	else{ str=e.value; }
 	}

 if(e.type=="checkbox" && e.checked)
 	{
	if(e.name.charAt(0)=="$")
		{
		if(e.value.indexOf(";")>-1)
			{
			var bits=e.value.split(";")
			Add2Price+=1*bits[0];
			str=bits[1];
			var priceAdded=(top.INSASS)?" @ "+top.MC.MCPrice(1*bits[0]):"";
			str+=(1*bits[0]>0)?extra+priceAdded:"";
			}
		else{Add2Price+=1*e.value;str="YES"+extra}
		}
	else{str=e.value;str=(str.length==0 || str=="checkbox")?"YES":str;}
 	}


 if(str.length>0)
   {
	caption=fixCaption(caption);
    ret+=caption.bold() + " : " +str+CRLF;
   }
 }

if(window.customAddData){ret+=customAddData(form)}
return(ret);
}


function stripUnderscores(str){
while(str.charAt(0)=="_"){str=str.substring(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<last; i++)
 {
 e=form.elements[i];
 // Text fields having names STARTING with underscore need not be filled
 // SELECTS having names STARTING with underscore may rest on option zero
 if(e.name.charAt(0)=="_"){continue;}
 if(checkQfields(e)){continue;}
 if(e.name==previous_rbname){continue;}
 else  if( (e.type=="text" || e.type=="textarea")  && e.value.length==0)
 	{
	ret=false;
	caption=fixCaption(e.name);
	str+=tab+caption+newline
	}
 else  if( e.type=="select-one"   && e.selectedIndex==0)
 	{
	ret=false;
	caption=fixCaption(e.name);
	str+=tab+caption+newline
	}
 else  if( e.type=="radio")
 	{
	rb=eval("form."+e.name);
	rbv=getRadioVal(rb);
	if(rbv.length==0)
		{
		ret=false;
		caption=fixCaption(e.name);
		str+=tab+caption+newline;
		previous_rbname=e.name
		}
	}
 }


if(window.customVerify){
	custom_str=customVerify(form);
	ret=(ret)?custom_str.length==0:ret;
// return value, if currently true, depends on length of custom_str
//               if false, it remains false
}
// custom message starting with newline overrides main message
// otherwise it just adds to the end

if(custom_str.length>0 && "%0A%0D".indexOf(escape(custom_str.charAt(0))) >-1)
	{
	message=custom_str;
	}
else
	{
	message="Please attend to :\n"+str+custom_str;
	}

return(ret);
}

function fixCaption(ret){
   // Remove trailing digits
   while("0123456789".indexOf(ret.charAt(ret.length-1))>-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);}

   // remove leading underscore if any
   ret=(ret.charAt(0)=="_") ? ret.substring(1):ret;

   // remove leading Dollar if any
   ret=(ret.charAt(0)=="$") ? ret.substring(1):ret;
   // remove leading hash if any
   ret=(ret.charAt(0)=="#") ? ret.substring(1):ret;

   // convert $ to slash
   ret=swapstring(ret,"$","/");
   // convert underscore to space
   ret=swapstring(ret,"_"," ");
return(ret);
}

function getRadioVal(rb){
var L=rb.length;var ret="";
for (var i = 0 ; i< L ; i++)
 { if(rb[i].checked) { ret=rb[i].value; break; } }
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 qtyFix(elem,Increment,qMin,qMax) {
var ev=decimals(elem.value);
ev=Math.abs(ev);
if(""+ev=="NaN"){ev=qMin;} // 27 December 2002
else 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;
	if(Increment<1)
		{ev=qFormat(ev);}
	}
elem.value=ev;
}//

function decimals(str){ return(clean(str,"1234567890.")) }
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);
}
function qFormat(V){
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;
return(ret);
}

function moneyPlain(V){
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;
return(ret);
}


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);
}//

function multiSetProductData(pkey){
ProductName	= productData[pkey].ProductName;
ProductRef	= productData[pkey].ProductRef;
Price		= productData[pkey].Price;
Weight		= productData[pkey].Weight;
TaxCode		= productData[pkey].TaxCode;
VARSLOT2	= productData[pkey].VARSLOT2;
}//

// 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 magicPrice(pkey,n){
Price=getThePrice(pkey,n);
//alert(Price)
//var fmtPrice=top.INSASS ? top.MC.MCPrice(top.adjust(Price)) : currencySymbol+moneyPlain(Price);
//window.document.write(fmtPrice);
if(top.INSASS || outsideSystemHandler >=2){top.wMCP(Price);}
else{window.document.write(currencySymbol+moneyPlain(Price));}
}

function getThePrice(pkey,n){
if(window.setProductData)
	{
	setProductData(pkey);
		if(typeof(Price)=="string" && Price.indexOf(colPbar)>-1) // Column price format
			{Price=extractColPrice(Price,n);}
		if(typeof(Price)=="string" && Price.indexOf(customPriceDelimiter)>-1) // Custom price format
			{Price=extractCustomPrice(Price);}
	return(Price);
	}
else if(window.setProductArrayData)
	{
	if(typeof(productData[pkey])=="undefined"){ setProductArrayData();}
	var nPrice=productData[pkey].Price;
	if(typeof(nPrice)=="string" && nPrice.indexOf(colPbar)>-1) // Column price format
		{nPrice=extractColPrice(nPrice,n);}
	if(typeof(Price)=="string" && Price.indexOf(customPriceDelimiter)>-1) // Custom price format
		{nPrice=extractCustomPrice(nPrice);}
	return(nPrice);
	}
}



function magicTaxPrice(pkey,n){
var Price=getThePrice(pkey,n);
var TaxCode=getTheTaxCode(pkey);
if(window.setProductData)
	{
	setProductData(pkey);
	}
if(top.INSASS || outsideSystemHandler >=2){top.wMCP(Price,TaxCode);}
else{window.document.write(currencySymbol+moneyPlain(Price));}
}

function getTheTaxCode(pkey){
if(window.setProductData)
	{
	setProductData(pkey);
	return(TaxCode);
	}
else if(window.setProductArrayData)
	{
	if(typeof(productData[pkey])=="undefined"){ setProductArrayData();}
	return(productData[pkey].TaxCode);
	}
}

function extractColPrice(strPrice,column){
var cParts=strPrice.split(colPbar);
var pPart=cParts.length==2 ? 1 : 2;
var cPrices=cParts[pPart].split(colPsemi);
return(cPrices[column-1]);
}

function extractCustomPrice(strPrice){
var ret;
// Use whole string if INSASS or with BOSS
if(top.INSASS || outsideSystemHandler >=2){ret=strPrice;}
else{var cParts=strPrice.split(customPriceDelimiter);ret=cParts[0];}
return(ret);
}


function listtext(e){return lt(e);}
function listvalue(e){return lv(e);}

