<!--
/* ======================================================================
Cookies 980715 (removed ordercookies and  check load)
====================================================================== */
var sourceOK="OK";

if (self.location.hostname != 'www.dustygroove.com' && self.location.hostname != null) setTimeout("self.location.hostname = 'www.dustygroove.com';", 1300);

var isLoaded=0; 

function replaceString(oldS,newS,fullS) 
{	var tind=fullS.indexOf(oldS,1);
	while (tind != -1)
	{	fullS = fullS.substring(0,parseInt(tind)) + newS + fullS.substring(parseInt(tind)+1);
		tind = fullS.indexOf(oldS,parseInt(tind))
	}
	return fullS;
}

function doEscape (txtEsc)
{	var txtHold = txtEsc;
	txtHold = replaceString(" ","-",txtHold);
	txtHold = replaceString("|","_",txtHold);
	return escape(txtHold);
}

function doUnescape (txtEsc)
{	var txtHold = unescape(txtEsc);
//	txtHold = replaceString("-"," ",txtHold);
	txtHold = replaceString("_","|",txtHold);
	return txtHold;
}


function getCookie(NAME)
{  var VHOLD ="0|";  
	NAME=NAME + "=";
   if (document.cookie.length > 0)
   {	VSTART=document.cookie.indexOf(NAME,0);
      if (VSTART > -1)
  		{	VSTART=VSTART + NAME.length;
			VEND=document.cookie.indexOf(";",VSTART);
         if (VEND == -1) VEND=document.cookie.length;
         VHOLD=doUnescape(document.cookie.substring(parseInt(VSTART),parseInt(VEND)));
    	} else VHOLD= "0|";
 	} else VHOLD= "0|";
   return(VHOLD);
} 

function createItemCookie2(cName, iStart, iEnd, hours)
{	var CV=0;
	var i= 0;
	CV=parseInt(itemCount);
	for (i=iStart; i<iEnd; i++) 
   {  CV=CV + "|" + ID[i];
      CV=CV + "|" + Quant[i];
      CV=CV + "|" + Price[i];
      CV=CV + "|" + Ship[i];
      CV=CV + "|" + Item[i];
      CV=CV + "|" + Format[i];
	} 
	CV=CV + "|";
// alert (cName+"=" + CV + "; expires="); 
   CV=doEscape(CV); 
	var EXPIRES = new Date();
   EXPIRES.setTime (EXPIRES.getTime() + hours*3600000);
   EXPIRES=EXPIRES.toGMTString();
   document.cookie=cName +"="+ CV + "; expires=" + EXPIRES + "; path=/; domain=www.dustygroove.com"; 
// alert(cName + CV + "; expires=" + EXPIRES + "/"); 
} 

function createItemCookie(hours)
{	if (parseInt(itemCount)<=50)
	{	createItemCookie2("dustygroove1", 0 ,itemCount, hours);
	}
} 

function decodeCookie()
{	var VLIST = getCookie("dustygroove1");
	var VSTART=0;
	var VEND=VLIST.indexOf("|",VSTART);
	var j = 0;
	var i = 0;
	
//	alert('dc1');
	itemCount=VLIST.substring(VSTART,VEND);
//	alert('dc2');

	// get itemdetails
   for (i=0; i<itemCount; i++)
	{	
//		alert('dc2_a_beffor');

	for (j=0; j<6; j++)
		{	
//		alert('dc2_a_a_');
		VSTART=VEND + 1;
//		alert('dc2_a_b_');

			VEND=VLIST.indexOf("|",VSTART);
//		alert('dc2_a_c)');
			CartArray[j][i]=VLIST.substring(VSTART,VEND);
//					alert('dc2_b_');

		}
	}
//	alert('dc3');

}

function testCookie()
{	  	var VLIST = getCookie("dustygroove1");
//	alert(VLIST);
     	var VSTART=0;
     	var VEND=VLIST.indexOf("|",VSTART);
		var txtAlert = "";
     	itemCount=VLIST.substring(VSTART,VEND);
		if (itemCount == 0)
		{	txtAlert += "Please note:  The item you selected was not added to your shopping cart.\n\n";
			txtAlert += "- It is necessary to use 'cookies' to use the shopping cart.\n\n";
			txtAlert += "- If you have any questions about cookies, please see the Cookies section ";
			txtAlert += "on the Ordering Info Page (look in the directory at the top or bottom of this page.)\n\n";
			txtAlert += "- The Dusty Groove shopping cart on these pages is a lot more convenient than the ";
			txtAlert += "Alternate version, so for best results, we recommend using cookies.\n\n";
			txtAlert += "- If you still don't want to use cookies, or don't know what we're talking about, ";
			txtAlert += "you can use the Alternate shopping cart by going to:  www.dustygroove.com/alt\n ";
			alert(txtAlert);
			return 0;
		}
		return 1;
}


		
/* ======================================================================
ITEMPAGES  
====================================================================== */

     // set arrays
     var ID = new Array(2);
     var Quant = new Array(2);
     var Price = new Array(2);
     var Ship = new Array(2);
     var Item = new Array(2);
     var Format = new Array(2);
     var CartArray = new Array(ID, Quant, Price, Ship, Item, Format);
     var itemCount = 0;

function formatConfirm(newItem, newFormat, newPrice)
{	var txtResult = "";
	var txtHold = newItem;
	var vSplit = -1;
	txtHold = replaceString(".",", ",txtHold);
	vSplit = txtHold.indexOf(":",0);  
	txtResult = txtHold.substring(0,parseInt(vSplit));
	txtResult += " -- " + txtHold.substring(parseInt(vSplit)+1, parseInt(txtHold.length));
	txtResult += " -- " + newFormat;
	return txtResult;
}


/*======================================================================
     buyItem(newItem, newFormat, newPrice, newID, newShip)   980715
====================================================================== */
function buyItem(newItem, newFormat, newPrice, newID, newShip) 
{	var cookieLen=0;
	var txtConfirm = formatConfirm(newItem, newFormat, newPrice);
	var isAdded = 0;
	var i = 0;
//	alert('bc10_a');
 	decodeCookie();
//	alert('bc10_b');
	if (document.cookie.length>0) cookieLen = document.cookie.length;
//  	   	alert(cookieLen);
  	for (i=0; i<itemCount; i++) { 	
//  	   	alert('bc12');

		if (parseInt(ID[i]) == parseInt(newID)) {	
			Quant[i]=parseInt(Quant[i]) + 1;
         isAdded = 1;
			createItemCookie(24);
      }
   }
//   	alert('bc20');

	if (isAdded == 0) {
   	if (itemCount>39) {
			var txtAlert = "YOUR CART IS FULL. \n \n";
			txtAlert += txtConfirm+" has not been added. \n\n";
			txtAlert += "The maximum capacity of the shopping cart is 40 items. \n \n";
			txtAlert += "If you would like to order more than 40 items: \n";
			txtAlert += "       - Submit the order for the items you have already selected. \n";
			txtAlert += "       - Then submit another order for any more items you want to order. \n \n";
			txtAlert += "We will combine all your orders into one and adjust the shipping charges \n";
			txtAlert += "so you get the reduced shipping rates for large orders.\n\n";
			txtAlert += "Sorry for the inconvenience!";
			alert(txtAlert);
			return 0;
		}
		if ((itemCount > 29 && cookieLen > 3100) || cookieLen > 3400) {
			var txtAlert = "YOUR CART IS FULL. \n \n";
			txtAlert += txtConfirm+" has not been added. \n\n";
			txtAlert += "The maximum capacity of the shopping cart is "+itemCount+" items. \n \n";
			txtAlert += "If you would like to order more than "+itemCount+" items: \n";
			txtAlert += "       - Submit the order for the items you have already selected. \n";
			txtAlert += "       - Then submit another order for any more items you want to order. \n \n";
			txtAlert += "We will combine all your orders into one and adjust the shipping charges \n";
			txtAlert += "so you get the reduced shipping rates for large orders.\n\n";
			txtAlert += "Sorry for the inconvenience!";
			alert(txtAlert);
			return 0;
		}
		ID[itemCount]=newID;
		Quant[itemCount]=1;
		Price[itemCount]=newPrice;
		Ship[itemCount]=newShip;
		Item[itemCount]=newItem;
		Format[itemCount]=newFormat;
		itemCount = parseInt(itemCount)+1;
		createItemCookie(24);
		if (testCookie() == 0) {
			return 0;
		}
		else {
			isAdded = 1;	
		}
	}
	if (isAdded == 1 ) {
		alert (txtConfirm + "\n\nAdded to cart"); 
	}	
	return 1;
}
//-->
