function PopUp(filename)
{
newwindow = window.open("http://www.bandstand.ca/bandmusic/"+filename,"","resizable=1,scrollbars=1, menubar=0,toolbar=0,location=0, directories=0, top=75,left=175,width=475,height=475");
}

function Monify(value)
{
  var str = "" + Math.round(value*100);
  var len = str.length;
  return (str=="0")?"0.00":(str.substring(0,len-2)+"."+str.substring(len-2,len));
}

function InsertInArray (i, qty, price, name)
{
      top.theQty[i]       = qty;
      top.thePrice[i]     = price;
      top.theName[i]      = name;
	itemsubtotal = Monify(top.theQty[i]*top.thePrice[i]);
      top.theDisplay[i]   = top.theName[i]+" - "+top.theQty[i]+" x "+top.thePrice[i]+" = "+itemsubtotal +"\r\n";
}

function CheckTheProduct (qty, price, name)
{
   price = Monify (price);
   var i = 0;
   while (i < top.totalItemsInArray)
   {
	if (top.theName[i] == name)
      {
         InsertInArray (i, qty, price, name);
         return;
      }
      i++;
   }
   // If adding a new item, its qty must be more than 0
   if (qty > 0)
   {
      InsertInArray (i, qty, price, name);
      top.totalItemsInArray++;
   }
  if (qty == 0)
   {
      InsertInArray (i, qty, price, name);
      top.totalItemsInArray--;
   }
}

function PrepareProductsList (form)
{
   var tax = 5
   var display  = "";
   var i = 0;
   var sub = 0;
   while (i < top.totalItemsInArray)
   {
      // CONSTRUCT THE PRODUCTS LIST
      if (top.theDisplay[i])
      {
         display  += top.theDisplay[i];
         sub += top.theQty[i]*top.thePrice[i];
      }
      i++;
     }
   top.SHOPPINGBASKET.document.BasketForm.ShoppingBasketList.value = display;
   top.SHOPPINGBASKET.document.BasketForm.SUBTOTAL.value = Monify(sub);
   // Get the tax charge. The value is converted from string to intger
   // Calculate the tax
   // Do not add the tax if the sub total is 0
   if (sub > 0) { top.SHOPPINGBASKET.document.BasketForm.TOTAL.value    = Monify(sub + sub * tax/100); }
   else { top.SHOPPINGBASKET.document.BasketForm.TOTAL.value    = "0.00"; }
   top.SHOPPINGBASKET.document.BasketForm.GST.value=Monify(top.SHOPPINGBASKET.document.BasketForm.TOTAL.value-top.SHOPPINGBASKET.document.BasketForm.SUBTOTAL.value)
}

function loadQuantities(arrayName)
{
	for (var i=1;i<=arrayName.length-1;i++)
		{
		if (arrayName[i]==null)
			{
			quantity=0;
		}else{
			quantity = arrayName[i];
		}
		parent.MAIN.document.forms[0].elements[i-1].value=quantity;
		}
}

function CompleteOrderForm()
{
top.shoppinglist=top.SHOPPINGBASKET.document.BasketForm.ShoppingBasketList.value;
top.subtotal=top.SHOPPINGBASKET.document.BasketForm.SUBTOTAL.value;
top.gst=top.SHOPPINGBASKET.document.BasketForm.GST.value;
top.total=top.SHOPPINGBASKET.document.BasketForm.TOTAL.value;

parent.parent.MAIN.location.href="http://www.bandstand.ca/orders/checkout.html";
}
function UpdateTopArrays()
{
top.shoppinglist=top.SHOPPINGBASKET.document.BasketForm.ShoppingBasketList.value;
top.subtotal=top.SHOPPINGBASKET.document.BasketForm.SUBTOTAL.value;
top.gst=top.SHOPPINGBASKET.document.BasketForm.GST.value;
top.total=top.SHOPPINGBASKET.document.BasketForm.TOTAL.value;
	
}
function listitems()
{
top.MAIN.document.forms[0].ShoppingList.value = top.shoppinglist;
top.MAIN.document.forms[0].SubTotal.value = top.subtotal;
top.MAIN.document.forms[0].Gst.value = top.gst;
top.MAIN.document.forms[0].Total.value = top.total;
}
function ReloadBasket()
{
top.SHOPPINGBASKET.document.BasketForm.ShoppingBasketList.value=top.shoppinglist;
top.SHOPPINGBASKET.document.BasketForm.SUBTOTAL.value=top.subtotal;
top.SHOPPINGBASKET.document.BasketForm.GST.value=top.gst;
top.SHOPPINGBASKET.document.BasketForm.TOTAL.value=top.total;
}
function confirmAction()
{

	CompleteOrderForm();

}

function CopyMe(me)
{
TempVariable = me.value;
}

function PasteMe(me)
{
me.value = TempVariable;
}

function ClearArray(arrayname)
{
	var top=arrayname.length
	for (var i=0;i<top;i++)
		{
		arrayname[i]=0;
		}
}

function UPDATE(form_element, price, name)
{
   var qty = Math.abs(form_element.value);
   CheckTheProduct (qty, price, name);
   PrepareProductsList ();
   SetArray(form_element, qty);
   UpdateTopArrays();
}

function SetArray(form_element, qty)
{
var splitter = form_element.name.indexOf('_');
var variablename = form_element.name.substring(0,splitter);
var variablelength = form_element.name.length
var variableindex = form_element.name.substring(splitter+1,form_element.name.length);

//
//SUPPLIES
//

if (variablename=="supplies") {
	top.suppliesArray[variableindex]=qty;
	}
	
if (variablename=="DblReeds") {
	top.DblReedsArray[variableindex]=qty;
	}
	
//
//METHOD BOOKS
//

if (variablename=="accentonachievement") {
top.accentonachievementArray[variableindex]=qty;
}
if (variablename=="bandexpr") {
top.bandexprArray[variableindex]=qty;
}
if (variablename=="bandtoday") {
top.bandtodayArray[variableindex]=qty;
}
if (variablename=="bestinclass") {
top.bestinclassArray[variableindex]=qty;
}
if (variablename=="comprehensivebandmethod") {
top.comprehensivebandmethodArray[variableindex]=qty;
}
if (variablename=="essentialelements") {
top.essentialelementsArray[variableindex]=qty;
}
if (variablename=="essentialelementstwothousand") {
top.essentialelementstwothousandArray[variableindex]=qty;
}
if (variablename=="essentialelementstwothousanddvd") {
top.essentialelementstwothousanddvdArray[variableindex]=qty;
}
if (variablename=="essentialelementsjazzensemble") {
top.essentialelementsjazzensembleArray[variableindex]=qty;
}
if (variablename=="firstdivision") {
top.firstdivisionArray[variableindex]=qty;
}
if (variablename=="learningunlimited") {
top.learningunlimitedArray[variableindex]=qty;
}
if (variablename=="medalist") {
top.medalistArray[variableindex]=qty;
}
if (variablename=="standardofexcellence") {
top.standardofexcellenceArray[variableindex]=qty;
}
if (variablename=="standardofexcellenceenhanced") {
top.standardofexcellenceenhancedArray[variableindex]=qty;
}
if (variablename=="standardofexcellencejazz") {
top.standardofexcellencejazzArray[variableindex]=qty;
}
if (variablename=="totalmusicianship") {
top.totalmusicianshipArray[variableindex]=qty;
}
if (variablename=="yamahabandstudent") {
top.yamahabandstudentArray[variableindex]=qty;
}


//
//GREAT BEGINNINGS
//
if (variablename=="sofeenhanced") {
top.sofeenhancedArray[variableindex]=qty;
}
if (variablename=="sofesoundsoftheseason") {
top.sofesoundsoftheseasonArray[variableindex]=qty;
}
if (variablename=="sofefirstperformance") {
top.sofefirstperformanceArray[variableindex]=qty;
}
if (variablename=="festivalensembles") {
top.festivalensemblesArray[variableindex]=qty;
}
if (variablename=="festivalsolos") {
top.festivalsolosArray[variableindex]=qty;
}
if (variablename=="brucepearsonother") {
top.brucepearsonotherArray[variableindex]=qty;
}




//
//CONCERT BOOKS
//
if (variablename=="accentonensembles") {
top.accentonensemblesArray[variableindex]=qty;
}
if (variablename=="awaywego") {
top.awaywegoArray[variableindex]=qty;
}
if (variablename=="bachandbefore") {
top.bachandbeforeArray[variableindex]=qty;
}
if (variablename=="bandsembles") {
top.bandsemblesArray[variableindex]=qty;
}
if (variablename=="bestinclasschristmas") {
top.bestinclasschristmasArray[variableindex]=qty;
}
if (variablename=="bestinclassshowcase") {
top.bestinclassshowcaseArray[variableindex]=qty;
}
if (variablename=="classicchristmascarolsforband") {
top.classicchristmascarolsforbandArray[variableindex]=qty;
}
if (variablename=="commandperformance") {
top.commandperformanceArray[variableindex]=qty;
}
if (variablename=="concerttoday") {
top.concerttodayArray[variableindex]=qty;
}
if (variablename=="ensemblessoundspectacular") {
top.ensemblessoundspectacularArray[variableindex]=qty;
}
if (variablename=="essentialelementsbroadwayfavorites") {
top.essentialelementsbroadwayfavoritesArray[variableindex]=qty;
}
if (variablename=="essentialelementschristmasfavorites") {
top.essentialelementschristmasfavoritesArray[variableindex]=qty;
}
if (variablename=="essentialelementsmoviefavorites") {
top.essentialelementsmoviefavoritesArray[variableindex]=qty;
}
if (variablename=="essentialelementsfilmfavorites") {
top.essentialelementsfilmfavoritesArray[variableindex]=qty;
}
if (variablename=="festivalensembles") {
top.festivalensemblesArray[variableindex]=qty;
}
if (variablename=="sixtysixfamousandfestivechorales") {
top.sixtysixfamousandfestivechoralesArray[variableindex]=qty;
}
if (variablename=="goforensembles") {
top.goforensemblesArray[variableindex]=qty;
}
if (variablename=="queenwoodbeginningband") {
top.queenwoodbeginningbandArray[variableindex]=qty;
}
if (variablename=="queenwooddevelopingband") {
top.queenwooddevelopingbandArray[variableindex]=qty;
}
if (variablename=="sofefirstperformance") {
top.sofefirstperformanceArray[variableindex]=qty;
}
if (variablename=="sofesoundsoftheseason") {
top.sofesoundsoftheseasonArray[variableindex]=qty;
}
if (variablename=="yamahabandensembles") {
top.yamahabandensemblesArray[variableindex]=qty;
}


//
//SUPPLEMENTARY TECHNIQUE BOOKS
//

if (variablename=="onehundredandonerhythmicrestpatterns") {
top.onehundredandonerhythmicrestpatternsArray[variableindex]=qty;
}
if (variablename=="threedbandbook") {
top.threedbandbookArray[variableindex]=qty;
}
if (variablename=="artistryoffundamentals") {
top.artistryoffundamentalsArray[variableindex]=qty;
}
if (variablename=="bandtechniquestepbystep") {
top.bandtechniquestepbystepArray[variableindex]=qty;
}
if (variablename=="encore") {
top.encoreArray[variableindex]=qty;
}
if (variablename=="essentialmusicianship") {
top.essentialmusicianshipArray[variableindex]=qty;
}
if (variablename=="essentialtechnique") {
top.essentialtechniqueArray[variableindex]=qty;
}
if (variablename=="essentialtechnique2000") {
top.essentialtechnique2000Array[variableindex]=qty;
}
if (variablename=="foundationsforsuperiorperformance") {
top.foundationsforsuperiorperformanceArray[variableindex]=qty;
}
if (variablename=="fussellsensembledrill") {
top.fussellsensembledrillArray[variableindex]=qty;
}
if (variablename=="gofortechnic") {
top.gofortechnicArray[variableindex]=qty;
}
if (variablename=="irecommend") {
top.irecommendArray[variableindex]=qty;
}
if (variablename=="instantsuccess") {
top.instantsuccessArray[variableindex]=qty;
}
if (variablename=="symphonicbandtechnique") {
top.symphonicbandtechniqueArray[variableindex]=qty;
}
if (variablename=="rhythmsandrests") {
top.rhythmsandrestsArray[variableindex]=qty;
}
if (variablename=="technictoday") {
top.technictodayArray[variableindex]=qty;
}
if (variablename=="techniquethroughperformance") {
top.techniquethroughperformanceArray[variableindex]=qty;
}
if (variablename=="toneandtechnique") {
top.toneandtechniqueArray[variableindex]=qty;
}
if (variablename=="treasuryofscales") {
top.treasuryofscalesArray[variableindex]=qty;
}


//
//THEORY BOOKS
//


if (variablename=="essentialsofmusictheory") {
top.essentialsofmusictheoryArray[variableindex]=qty;
}
if (variablename=="goforfundamentals") {
top.goforfundamentalsArray[variableindex]=qty;
}
if (variablename=="mastertheory") {
top.mastertheoryArray[variableindex]=qty;
}
if (variablename=="practicaltheory") {
top.practicaltheoryArray[variableindex]=qty;
}
if (variablename=="sofetheoryandhistory") {
top.sofetheoryandhistoryArray[variableindex]=qty;
}



//
//JAZZ ENSEMBLE BOOKS
//

if (variablename=="bestdiscoveryjazz") {
top.bestdiscoveryjazzArray[variableindex]=qty;
}
if (variablename=="discoveryjazzcollection") {
top.discoveryjazzcollectionArray[variableindex]=qty;
}
if (variablename=="discoveryjazzfavorites") {
top.discoveryjazzfavoritesArray[variableindex]=qty;
}
if (variablename=="easyjazzclassics") {
top.easyjazzclassicsArray[variableindex]=qty;
}
if (variablename=="firstyearchartscollectionforjazzensemble") {
top.firstyearchartscollectionforjazzensembleArray[variableindex]=qty;
}
if (variablename=="swingclassicsforjazzensemble") {
top.swingclassicsforjazzensembleArray[variableindex]=qty;
}
if (variablename=="sofejazzcombosession") {
top.sofejazzcombosessionArray[variableindex]=qty;
}



//
//STRING BOOKS
//

if (variablename=="allforstrings") {
top.allforstringsArray[variableindex]=qty;
}
if (variablename=="strictlystrings") {
top.strictlystringsArray[variableindex]=qty;
}
if (variablename=="stringbuilder") {
top.stringbuilderArray[variableindex]=qty;
}
if (variablename=="notesforstrings") {
top.notesforstringsArray[variableindex]=qty;
}
if (variablename=="orchestraexpressions") {
top.orchestraexpressionsArray[variableindex]=qty;
}




//
//REEDS
//

if (variablename=="alexandersuperial") {
top.alexandersuperialArray[variableindex]=qty;
}
if (variablename=="alexandersuperialdc") {
top.alexandersuperialdcArray[variableindex]=qty;
}
if (variablename=="alexanderclassique") {
top.alexanderclassiqueArray[variableindex]=qty;
}
if (variablename=="hemke") {
top.hemkeArray[variableindex]=qty;
}
if (variablename=="lavoz") {
top.lavozArray[variableindex]=qty;
}
if (variablename=="mitchelllurie") {
top.mitchelllurieArray[variableindex]=qty;
}
if (variablename=="ricoroyal") {
top.ricoroyalArray[variableindex]=qty;
}
if (variablename=="ricoselectjazz") {
top.ricoselectjazzArray[variableindex]=qty;
}
if (variablename=="ricosax") {
top.ricosaxArray[variableindex]=qty;
}
if (variablename=="ricoclarinet") {
top.ricoclarinetArray[variableindex]=qty;
}
if (variablename=="rigottigold") {
top.rigottigoldArray[variableindex]=qty;
}
if (variablename=="symmetricut") {
top.symmetricutArray[variableindex]=qty;
}
if (variablename=="vandorenclarinettraditional") {
top.vandorenclarinettraditionalArray[variableindex]=qty;
}
if (variablename=="vandorenclarinetmisc") {
top.vandorenclarinetmiscArray[variableindex]=qty;
}
if (variablename=="vandorensaxtraditional") {
top.vandorensaxtraditionalArray[variableindex]=qty;
}
if (variablename=="vandorensaxjava") {
top.vandorensaxjavaArray[variableindex]=qty;
}
if (variablename=="vandorensaxv16") {
top.vandorensaxv16Array[variableindex]=qty;
}
if (variablename=="vandorensaxjazz") {
top.vandorensaxjazzArray[variableindex]=qty;
}



//
//TEACHING MUSIC THROUGH PERFORMANCE
//


if (variablename=="tmtp") {
top.tmtpArray[variableindex]=qty;
}




}


function ClearAndReset()
{
top.totalItemsInArray = 0;

//
//SUPPLIES
//

ClearArray(top.suppliesArray);
ClearArray(top.DblReedsArray);



//
//METHOD BOOKS
//
ClearArray(top.accentonachievementArray);
ClearArray(top.bandexprArray);
ClearArray(top.bandtodayArray);
ClearArray(top.bestinclassArray);
ClearArray(top.comprehensivebandmethodArray);
ClearArray(top.essentialelementsArray);
ClearArray(top.essentialelementstwothousandArray);
ClearArray(top.essentialelementstwothousanddvdArray);
ClearArray(top.essentialelementsjazzensembleArray);
ClearArray(top.firstdivisionArray);
ClearArray(top.learningunlimitedArray);
ClearArray(top.medalistArray);
ClearArray(top.standardofexcellenceArray);
ClearArray(top.standardofexcellenceenhancedArray);
ClearArray(top.standardofexcellencejazzArray);
ClearArray(top.totalmusicianshipArray);
ClearArray(top.yamahabandstudentArray);



//
//STRING BOOKS
//
ClearArray(top.allforstringsArray);
ClearArray(top.strictlystringsArray);
ClearArray(top.stringbuilderArray);
ClearArray(top.notesforstringsArray);
ClearArray(top.orchestraexpressionsArray);



//
//GREAT BEGINNINGS
//
ClearArray(top.sofeenhancedArray);
ClearArray(top.sofesoundsoftheseasonArray);
ClearArray(top.sofefirstperformanceArray);
ClearArray(top.festivalensemblesArray);
ClearArray(top.festivalsolosArray);
ClearArray(top.brucepearsonotherArray);



//
//CONCERT BOOKS
//

ClearArray(top.accentonensemblesArray);
ClearArray(top.awaywegoArray);
ClearArray(top.bachandbeforeArray);
ClearArray(top.bandsemblesArray);
ClearArray(top.bestinclasschristmasArray);
ClearArray(top.bestinclassshowcaseArray);
ClearArray(top.classicchristmascarolsforbandArray);
ClearArray(top.commandperformanceArray);
ClearArray(top.concerttodayArray);
ClearArray(top.ensemblessoundspectacularArray);
ClearArray(top.essentialelementsbroadwayfavoritesArray);
ClearArray(top.essentialelementschristmasfavoritesArray);
ClearArray(top.essentialelementsmoviefavoritesArray);
ClearArray(top.essentialelementsfilmfavoritesArray);
ClearArray(top.festivalensemblesArray);
ClearArray(top.sixtysixfamousandfestivechoralesArray);
ClearArray(top.goforensemblesArray);
ClearArray(top.queenwoodbeginningbandArray);
ClearArray(top.queenwooddevelopingbandArray);
ClearArray(top.sofefirstperformanceArray);
ClearArray(top.sofesoundsoftheseasonArray);
ClearArray(top.yamahabandensemblesArray);






//
//SUPPLEMENTARY TECHNIQUE BOOKS
//


ClearArray(top.onehundredandonerhythmicrestpatternsArray);
ClearArray(top.threedbandbookArray);
ClearArray(top.artistryoffundamentalsArray);
ClearArray(top.bandtechniquestepbystepArray);
ClearArray(top.encoreArray);
ClearArray(top.essentialmusicianshipArray);
ClearArray(top.essentialtechniqueArray);
ClearArray(top.essentialtechnique2000Array);
ClearArray(top.foundationsforsuperiorperformanceArray);
ClearArray(top.fussellsensembledrillArray);
ClearArray(top.gofortechnicArray);
ClearArray(top.irecommendArray);
ClearArray(top.instantsuccessArray);
ClearArray(top.symphonicbandtechniqueArray);
ClearArray(top.rhythmsandrestsArray);
ClearArray(top.technictodayArray);
ClearArray(top.techniquethroughperformanceArray);
ClearArray(top.toneandtechniqueArray);
ClearArray(top.treasuryofscalesArray);







//
//THEORY BOOKS
//

ClearArray(top.essentialsofmusictheoryArray);
ClearArray(top.goforfundamentalsArray);
ClearArray(top.mastertheoryArray);
ClearArray(top.practicaltheoryArray);
ClearArray(top.sofetheoryandhistoryArray);






//
//JAZZ ENSEMBLE BOOKS
//
ClearArray(top.bestdiscoveryjazzArray);
ClearArray(top.discoveryjazzcollectionArray);
ClearArray(top.discoveryjazzfavoritesArray);
ClearArray(top.easyjazzclassicsArray);
ClearArray(top.firstyearchartscollectionforjazzensembleArray);
ClearArray(top.swingclassicsforjazzensembleArray);
ClearArray(top.sofejazzcombosessionArray);






//
//REEDS
//
ClearArray(top.alexandersuperialArray);
ClearArray(top.alexandersuperialdcArray);
ClearArray(top.alexanderclassiqueArray);
ClearArray(top.hemkeArray);
ClearArray(top.lavozArray);
ClearArray(top.mitchelllurieArray);
ClearArray(top.ricoroyalArray);
ClearArray(top.ricoselectjazzArray);
ClearArray(top.ricosaxArray);
ClearArray(top.ricoclarinetArray);
ClearArray(top.rigottigoldArray);
ClearArray(top.symmetricutArray);
ClearArray(top.vandorenclarinettraditionalArray);
ClearArray(top.vandorenclarinetmiscArray);
ClearArray(top.vandorensaxtraditionalArray);
ClearArray(top.vandorensaxjavaArray);
ClearArray(top.vandorensaxv16Array);
ClearArray(top.vandorensaxjazzArray);
ClearArray(top.vandorenhandselectsaxArray);





//
//TEACHING MUSIC THROUGH PERFORMANCE
//

ClearArray(top.tmtpArray);


top.shoppinglist="Your Shopping Basket is Empty!";
top.subtotal="0";
top.gst="0";
top.total="0";
ReloadBasket();
	var i=0;
	while (i<=parent.MAIN.document.forms[0].elements.length-1)
		{
		parent.MAIN.document.forms[0].elements[i].value="0";
		++i;
		}

}


