
vgeneric = "2.26"

//
// --------- Temporary Functions --------------
//
function cusistat()
{
dbm("custinf['utype'] = " + custinf["utype"])
dbm("custinf['cusname'] = " + custinf["cusname"])
dbm("custinf['cusstreet'] = " + custinf["cusstreet"])
dbm("custinf['cusemail'] = " + custinf["cusemail"])
dbm("custinf['cusphone'] = " + custinf["cusphone"])
dbm("custinf['cuscity'] = " + custinf["cuscity"])
dbm("custinf['cusstate'] = " + custinf["cusstate"])
dbm("custinf['cuszip'] = " + custinf["cuszip"])
dbm("custinf['cusmsg'] = " + custinf["cusmsg"])

}
// ----------------- Cart/Basket Functions -------------------------------

function addtocart(acitmid,atcopt)  // selected item data to shopping cart record opt=1 for special window
{
var iadd = selecteditemno;
var qadd = 1
var padd = selitemprice
var nadd = selecteditemname
var sw = screen.width - 400
var sh = screen.height - 400

selitemqty = Number(CLBasketAdd(iadd,qadd,padd,nadd));

if (atcopt == 1)  //Code to open special window -- not now used
	{
	infwndw = window.open(rootdir + 'itemadded.htm','CLinfo','width=350,height=140,resizable,left=' + sw + ',top=' + sh);
	}
}

function rviewcart()
{

viewcart()

}
function ciaviewcart() // close item added window, then display cart
{
iwincls()
viewcart()
}
function viewcart()  // displays cart contents
{

var ckoww = 650
var ckowh = ush - 170
var ckowleft = usw - 700
if (usw < 650)
{
 ckoww = 550;
ckowleft = 50;
}



if (ckowndw && !ckowndw.closed)
	{
		if (ckowndw.close())
		{
		//  wait for window to close
		}
	}


if (cartwndw && !cartwndw.closed)
	{
	cartwndw.location.reload()
		// if (cartwndw.close())
		// {
		//  wait for cartwindow to close
		// }
	}
	

if (!cartwndw || cartwndw.closed) // Error here if this window is already open
	{
		cartwndw = window.open(rootdir + 'cloricart.htm','CLcart',
		'width=' + ckoww + ',height=' + ckowh + ',resizable,scrollbars,left=' + ckowleft + ',top=30');
	}
cartwndw.focus()
}

function CLBasketAdd(itid,qty,iprc,inam) 
{
	//  DatabaseLoadCookie() 
	var oldtq = Number(cartinf["tnit"])
	var oldnq = Number(cartinf["nit"])
	var quant = 0
	if (DBCookie.basket.Seek(itid) == true)
		{
		quant = Number(DBCookie.basket.qtyitm)
		quant = quant + qty - 0
		DBCookie.basket.UpdateField('qtyitm',quant)
		}
	else
		{
		quant = qty - 0
		DBCookie.basket.AddRec([itid,quant,iprc,inam])
		cartinf["nit"] = oldnq + 1
		}
	cartinf["tnit"] = Number(oldtq) + Number(qty)
	//  DatabaseSaveCookie()
	return quant
}

//  ------ Change Qty of Item in Cart -----------
function qychange(chv, chi, chn, where)  // chi = clitmid, chn ='qyxx'  chv = new qty value
{

// dbm("qty change: chv,chi,chn = " + chv + ", " + chi + ", " + chn)
	var origquant = 0
	var currprice
	var extdamt
	var extname 
	var foldextamt
	var oldextamt
	var newextamt
	var changeamt
	var totalamt
	var ftotalamt
	var newtotamt
	var fnewextamt
	var chnin = String(chn)
	var entryno
	var oldtq = Number(cartinf["tnit"])
	entryno = chnin.substr(2,chnin.length-1)  
	extname = 'xt' + entryno
	foldextamt = where.document.formcart.elements[extname].value
	ftotalamt = where.document.formcart.elements["totamt"].value
	
	oldextamt = Number(remvdollar(foldextamt))
	totalamt = Number(remvdollar(ftotalamt))
	if (chv <= 0)
		{
		chv = 0;
		cartinf["zqit"]++ ;
		}
	if (DBCookie.basket.Seek(chi) == true) 
		{
		origquant = Number(DBCookie.basket.qtyitm)
		if (origquant == 0) cartinf["zqit"]-- ;
		DBCookie.basket.UpdateField('qtyitm', chv)
		cartinf["tnit"] = Number(oldtq) + Number(chv) - Number(origquant)
	
		}
	else
		{
alert("Database Error -- please close CraftiLori windows and reload them.")
		return
		}
	if (CLDB.CLstoreitems.Seek(chi) == true) 
		{
		currprice = CLDB.CLstoreitems.price
		newextamt = currprice * chv
		changeamt = newextamt - oldextamt - 0
		newtotamt = totalamt + changeamt - 0
		fnewextamt = "$" + tofxd2(newextamt)
		fnewtotamt = "$" + tofxd2(newtotamt)
		
		where.document.formcart.elements[extname].value = fnewextamt
		where.document.formcart.elements["totamt"].value = fnewtotamt
		
		computeship(newtotamt)
		where.document.formcart.elements["shipamt"].value = fstotal
		where.document.formcart.elements["ototamt"].value = fovtotal
		
		cartinf["ptot"] = tofxd2(newtotamt)
		cartinf["stot"] = tofxd2(stotal)
		}
	else
		{
		return
		}
}

// --------------Display Cart or Order Form------------------------

// --ctsoptn = 1 to show cart, allow qty change;
//  2/3 to show prel/final order (no qty change), 4=send acknowl , 5/6 = contact info/return

function CLCartShow(where,ctsoptn)  
{
var nbrentries = DBCookie.basket.Count()
var nzqntries = 0
var cartdata = ""
var ntry = 0
var ctotal = 0
var ctotqty = Number(0)
var stotal = 0  // shipping amount
var ordheadline = "Order Number " + cartinf['ordn']
var orddate = todaystrng
var orderno =  cartinf['ordn']
var cartdinf = ""

cartblock:

if (nbrentries == 0 && ctsoptn < 5 )
{
cartinf["nit"] = 0
cartinf["tnit"] = 0
cartinf["zqit"] = 0 
cartinf["ordn"] = ""  
cartinf["ptot"] = 0  
cartinf["stot"] = 0 

cartdata = "<H3>Your Shopping Cart Is Empty</H3>"
}
else
{
// if (ctsoptn < 5) {DBCookie.basket.Sort('xidofitm','ascend');} // sort 'basket' recordset

// SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS


cartdata =	'<P>'
// one overall table container
cartdata += '<table width=90% align=center>'


if(ctsoptn > 2 && ctsoptn < 5)  // show order number and date
{
cartdata += '<TABLE class="clp" width=98% cellSpacing=0 cellPadding=0 align=center bgColor=#ccffcc border=1>'
+ '<col width=50%><col width=20%><col width=20%>' 

		+ '<TR><TD class="clh4" style="text-align:center;padding-left:3px;padding-right:3px;">' + ordheadline + '</TD>'
		+ '<TD class="clh4" style="border-right-width:0px;text-align:right;padding-left:3px;padding-right:3px;">Order Date</TD>'
		+ '<TD class="clh4" style="border-left-width:0px;text-align:left;padding-left:3px;padding-right:3px;">' + orddate + '</TD></TR></table>\n'

}

/*			
			
*/


// HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
		 
if (ctsoptn < 5)  // not just contact info
{
cartdata +=	'<table class="clp" width=98% cellSpacing=0 cellPadding=0 align=center bgColor=#ccffcc border=1>'
+ '<col width=10%><col width=50%><col width=20%><col width=20%>'
		+ '<TR style="background-color:#8cdf90;">'
		+ '<TD class="clh4" style="text-align:center;">Qty</TD>'
		+ '<TD class="clh4"  style="text-align:center;">Item</TD>'
		+ '<TD  class="clh4"  style="text-align:center;">Price</TD>'
		+ '<TD class="clh4"  style="text-align:center;">Amount</TD></TR>\n' ;



DBCookie.basket.MoveFirst()
	while(DBCookie.basket.RsetProperties.Eof==false)
	{
		ntry += 1
		var liitmno = DBCookie.basket.xidofitm
		var liqty = 0
		var liname = ""
		var liprice = 0
		var oldprice = 0
		// var oldqty = 0
		var liext = 0
		var lifprice = 0
		var lifextamt = 0
	 cartline:
	 if (1 == 1) // display a cart entry
	 {
		
		if (DBCookie.basket.qtyitm <= 0)
			{
			  nzqntries++ ;
				if (nbrentries - nzqntries != 0)
				{
				  if (ctsoptn == 1) break cartline;
				ntry-- ;  // only if doing checkout
				break cartline;
				}
				else
				{
					cartdata = "<H3>Your Shopping Cart Is Empty</H3>";
					break cartblock;
				}
			}  
		else
			{
			  liname = DBCookie.basket.nameitm
			  oldprice = DBCookie.basket.prcitm 
			  liqty = DBCookie.basket.qtyitm;
			  lionsale = ""
			  
			  if (CLDB.CLstoreitems.Seek(liitmno))  
				{
				 liprice = CLDB.CLstoreitems.price;
				 
				 if (oldprice != liprice)
					{
						lirprice = CLDB.CLstoreitems.rprice;
						if (oldprice == lirprice)
							{
								liprice = oldprice
								lionsale = '  <font color = "red"> &nbsp;Sale Price! </font>'
							}
						else
							{
								alert(liname + " price change from " + oldprice + " to " + liprice);
							}
					}
				 
				 liext = liprice * liqty;
				 ctotal += liext;
				 ctotqty = Number(ctotqty) + Number(liqty);
				 lifprice = tofxd2(liprice);
				 lifextamt = "$" + tofxd2(liext);
				 ftotal =  "$" + tofxd2(ctotal);
				}
				
			  else 
				{
				 alert(liname + " is no longer available");
				 DBCookie.basket.qtyitm = 0;
				 break cartline;
				}
			}
			
	// TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
		
	cartdata += '<TR><TD align=middle>'
		+ '<INPUT align=center value=' + liqty + ' id=' + liitmno 
		+ ' style="text-align: right;width:60%;'
		if (ctsoptn != 1) {cartdata += ' background-color:#d5ffd5;'}
		
		cartdata += '" size=4 name=qy' + ntry  + ' maxlength=2 '
		
		if (ctsoptn != 1)
		 {
		cartdata +=  ' readonly' + '></TD>'
		}
		else
		{
		cartdata += ' onChange="top.opener.qychange(this.value, this.id, this.name, self);"></TD>'
		}
	
// EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

		
	cartdata += '<TD style="text-align: left;padding-left:5%;">' + liname + lionsale +'</TD>'  // ITEM NAME
	
		+ '<TD class="clp"' // ITEM UNIT PRICE
		+ ' style="text-align: right;padding-right:3%; " >$' + lifprice + '</TD>'
		
		+ '<TD class="clh4"' // ITEM EXTENDED AMOUNT = QTY X PRICE
		+ ' style="text-align: right;padding-left:5%;padding-right:3px;background-color:#d5ffd5;" align=right> '
		
		+ '<INPUT size=9 align=right value= "' + lifextamt + '" id=x' + liitmno
		+  ' style="padding-left:5%;padding-right:3px;text-align:right; background-color:#d5ffd5;"'
		+ ' readonly name=xt' + ntry + '></TD>'
		
		+ '<INPUT type="hidden" name=num' + ntry + ' value= ' + liitmno +  '>'
		+ '<INPUT type="hidden" name=dsc' + ntry + ' value= "' + liname +  '">'
		
		+ '</TR>\n';
	} //  End display of cart entry
	
	DBCookie.basket.MoveNext();        
	}  //  end of while statement (last cart line item processed)
	
	
	
	computeship(ctotal)	

	cartdata += '<TR><TD></TD><TD></TD>'
	
		+ '<TD class="clh4"' // SUBTOTAL CAPTION
		+ ' style="text-align:right;padding-right:3% " align=right bgColor=#8cdf90 >Subtotal</TD>'
		
		+ '<TD class="clp"' // SUBOTOAL AMOUNT
		+ ' style="text-align: right;padding-left:5%; padding-right:3px;" align=right bgColor=#8cdf90>'
		+ '<INPUT size=9  align=right value= "' + ftotal + '"'
		+  ' style="padding-left:5%;padding-right:3px;text-align:right; background-color:#d5ffd5;"'
		+ ' name=totamt readonly></TD></TR>' 
		
		
		+ '<TR><TD></TD><TD></TD>' 
		+ '<TD class="clp"' // SHIPPING CAPTION
		+ ' style="text-align: right; padding-right:3%;" align=right bgColor=#ccffcc >Shipping</TD>'
		
		+ '<TD class="clp"'  // SHIPPING AMOUNT
		+ ' style="text-align: right;padding-left:5%; padding-right:3px;" align=right bgColor=#d5ffd5>'
		
		+ '<INPUT size=9 align=right value= "' + fstotal + '"'
		+  ' style="padding-left:5%;padding-right:3px; text-align:right; background-color:#d5ffd5;"'
		+ ' name=shipamt readonly></TD></TR>'
		
		
		+ '<TR><TD></TD><TD></TD>'
		+ '<TD class="clh4"' // TOTAL CAPTION
		+ ' style="text-align: right; padding-right:3%;"  align=right bgColor=#8cdf90 >Total</TD>'
		
		+ '<TD class="clh4"' // TOTAL AMOUNT
		+ ' style="text-align: right; padding-left:5%;padding-right:3px;" align=right bgColor=#8cdf90>'
		
		
		+ '<INPUT class="clh4" size=9 align=right value= "' + fovtotal + '"'
		+  '" style="padding-left:5%;padding-right:3px; text-align:right; background-color:#d5ffd5;"'
		
		+ ' name=ototamt readonly></TD></TR></table>\n'


}



		
// -------Show following in Order view or Contact Info Update -------

if(ctsoptn > 1)  // show order tail
{
     
cartdata += '<table class="clp" width=98% cellSpacing=0 cellPadding=0 align=center bgColor=#ccffcc border=1>'
+ '<col width=8%><col width=65%><col width=8%><col width=12%>' 
		+ '<TR style="background-color:#8cdf90;"><TD colspan = 4 class="clh4" align=left>'
	if (ctsoptn <4)
	{cartdata  += '&nbsp Please provide ship-to information below</TD></TR>'}
	if (ctsoptn == 5)
	{cartdata  += '&nbsp Please enter contact information below</TD></TR>'} 
	if (ctsoptn == 4)
	{cartdata  += '&nbsp Ship-to and Contact Information</TD></TR>'}
	if (ctsoptn == 6)
	{cartdata  += '&nbsp Contact Information</TD></TR>'}
	
			
	cartdata += '<tr style="background-color:#8cdf90;">' //  -------- Name, Email -------
		+ '<td class="clh4" style="BORDER-right-width: 0px;text-align:center;padding-left:3px;margin-right:2px;">Name</td>'
		
		+ '<td style="padding-right:1%;BORDER-left-width: 0px;">'
		
		+ '<INPUT type="text" name="cusname" align=left'
		+ ' style="padding-left:3px;text-align:left;" size = 45 maxlength=50'
		+ ' onChange="top.opener.simpchange(this.name, self)"></td>'
		
		+ '<td class="clh4" style="BORDER-right-width: 0px;text-align:center;padding-left:3px;margin-right:2px;">Email</td>'
		+ '<td style="padding-right:2px;BORDER-left-width: 0px;"><INPUT type="text" name="cusemail"  align=left'
		+ ' style="padding-left:3px;text-align: left;" size = 15 maxlength=30'
		+ ' onChange="top.opener.simpchange(this.name, self)" ></td></tr>'

	
		+ '<tr style="background-color:#8cdf90;">' //  --------Street, Phone --------
		+ '<td class="clh4" style="BORDER-right-width: 0px;text-align:center;padding-left:3px;padding-right:2px;">Street</td>'
		
		+ '<td style="padding-right:1%;BORDER-left-width: 0px;">'
		
		+ '<INPUT type="text" name="cusstreet" align=left'
		+ ' style="padding-left:3px;text-align:left;" size = 45 maxlength=50'
		+ ' onChange="top.opener.simpchange(this.name, self)"></td>'
		
		+ '<td class="clh4" style="BORDER-right-width: 0px;text-align:center;padding-left:3px;padding-right:3px;">Phone</td>'
		+ '<td style="padding-right:2px;BORDER-left-width: 0px;"><INPUT type="text" name="cusphone"  align=left'
		+ ' style="padding-left:3px;text-align: left;" size = 15 maxlength=18'
		+ ' onChange="top.opener.simpchange(this.name, self)" ></td></TR></table>\n'

		
		
cartdata += '<table class="clp" width=98% cellSpacing=0 cellPadding=0 align=center bgColor=#ccffcc border=1>'
+ '<col width=8%><col width=60%><col width=8%><col width=5% col width=8% col width = 11%>' 

		+ '<tr style="background-color:#8cdf90;">' //  -------- City, State, Zip ------------

		+ '<td class="clh4" style="BORDER-right-width: 0px;text-align:center;padding-left:3px;padding-right:3px; ">City</td>'
		
		+ '<td style="padding-right:1%;BORDER-left-width: 0px;"><INPUT type="text" name="cuscity" align=left'
		+ ' style="padding-left:3px;text-align: left;" size = 35 maxlength=50'
		+ ' onChange="top.opener.simpchange(this.name, self)" ></td>'
		+ '<td class="clh4" style="BORDER-right-width: 0px;text-align:center;padding-left:3px;padding-right:3px;">State</td>'
		
		+ '<td style="padding-right:1%;BORDER-left-width: 0px;"><INPUT type="text" name="cusstate"  align=left'
		+ ' style="padding-left:3px;text-align: left;" size = 2 maxlength=2'
		+ ' onChange="top.opener.simpchange(this.name, self)" ></td>'
		+ '<td class="clh4" style="BORDER-right-width: 0px;text-align:center;padding-left:3px;padding-right:3px;">Zip</td>'
		
		+ '<td style="padding-right:2px;BORDER-left-width: 0px;"><INPUT type="text" name="cuszip"  align=left'
		+ ' style="text-align: left;padding-left:3px;" size = 9 maxlength=10'
		+ ' onChange="top.opener.simpchange(this.name, self)" ></td></tr>'
		
		+ '<TR style="background-color:#8cdf90;"><TD colspan = 6 class="clh4" align=left>'
		if (ctsoptn <4 || ctsoptn == 5)
			{cartdata  += '&nbsp Please enter questions/comments below</TD></TR></table>'}
		else
			{cartdata  += '&nbsp Comments</TD></TR></table>'}
			

cartdata += '<table class="clp" width=98% cellSpacing=0 cellPadding=0 align=center bgColor=#ccffcc border=1>'
		
		+ '<TR><TD align=center class="clp">'
		+ ' <textarea rows="6" cols="80"  name="cusmsg" style="padding-left:3px" wrap="wrap"'
		+ ' onChange="top.opener.simpchange(this.name, self)" >'
		+ '</textarea></td></tr></table>'
		
		
	//  Email mailing list selection	
cartdata += '<table class="clp" width=98% cellSpacing=0 cellPadding=0 align=center bgColor=#ccffcc border=1>'
		+ '<col width=10%><col width=90%>' 
		+ '<TR style="background-color:#8cdf90;"><TD colspan = 2 class="clh4" align=left>'
		if (ctsoptn <4 || ctsoptn == 5)
			{cartdata  += '&nbsp Would you like to receive CraftiLori News (occasional emails)?</TD></TR>'}
		else
			{cartdata  += '&nbsp Your CraftiLori News email selection is as follows</TD></TR>'}
		
cartdata += '<TR><TD class="clh4" style="BORDER-right-width: 0px;border-bottom-width:0px;" align=center bgColor=#8cdf90 >'
		+ '<input type=radio name="emlopt" checked'
	if (ctsoptn == 2 || ctsoptn == 3 || ctsoptn == 5)
		{cartdata += ' onClick="emlclick()" ></td>'}
	else
		{cartdata +=  'readonly' + '></TD>'}
cartdata += '<td class="clh4" style="border-left-width:0px;border-bottom-width:0px;text-align:left;padding-left:3px;">'
		+ 'Yes, send me CraftiLori News emails</td></tr>'
		
		+ '<TR><TD class="clh4" style="BORDER-right-width: 0px;border-top-width:0px;" align=center bgColor=#8cdf90 >'
		+ '<input type=radio name="emlopt"'
	if (ctsoptn == 2 || ctsoptn == 3 || ctsoptn == 5)
		{cartdata += ' onClick="emlclick()" ></td>'}
	else
		{cartdata +=  'readonly' + '></TD>'}

cartdata += '<td class="clh4" style="border-left-width:0px;border-top-width:0px;text-align:left;padding-left:3px;">'
		+ 'No, do not send CraftiLori News emails</td></tr></table>'
		
} // End basic order tail

if(ctsoptn == 2)  // show pay options

{	    
cartdata += '<table class="clp" width=98% cellSpacing=0 cellPadding=0 align=center bgColor=#ccffcc border=1>'
		+ '<col width=10%><col width=90%>' 
		+ '<TR style="background-color:#8cdf90;"><TD colspan = 2 class="clh4" align=left>'
		+ '&nbsp Please choose payment method below</TD></TR>'

cartdata += '<TR><TD class="clh4" style="BORDER-right-width: 0px;border-bottom-width:0px;" align=center bgColor=#8cdf90 >'
		+ '<input type=radio name="payopt" checked'
		+ ' onClick="payclick()" ></td>'
		
cartdata += '<td class="clh4" style="border-left-width:0px;border-bottom-width:0px;text-align:left;padding-left:3px;">'
		+ 'Will Pay Online Now (via Visa, Mastercard, or PayPal)</td></tr>'
		
        + '<TR><TD class="clh4" style="BORDER-right-width: 0px;border-top-width:0px;" align=center bgColor=#8cdf90 >'
		+ '<input type=radio name="payopt"'
		+ ' onClick="payclick()" ></td>'
cartdata += '<td class="clh4" style="border-left-width:0px;border-top-width:0px;text-align:left;padding-left:3px;">'
		+ 'Will Pay Later (Online, or by Check or Money Order)</td></tr></table>'



}  //  End pay options  

// Send Button

var scapt = "Send Order"
var scapt2 = "order"
if 	(ctsoptn == 5) {scapt = "Send Info";scapt2 = "info";}
if(ctsoptn == 2 || ctsoptn == 3 || ctsoptn == 5 )  // show send button
{
cartdata += '<table id="subtbl" class="clp" width=98% cellSpacing=0 cellPadding=0 align=center bgColor=#ccffcc border=1>'
		+ '<col width=20%><col width=80%>' 

+ '<TR style="BORDER-BOTTOM-WIDTH: 1px; BACKGROUND-COLOR: #ccffcc">'
+ '<TD style= "BORDER-right-width: 0px;"  class="clh4" align=center>'          
            
+ '<INPUT class="clh4" style="BACKGROUND-COLOR: #deb589;" id=submit1 type=submit value='
+ scapt + ' name=submit1></TD>'

+ '<TD style= "BORDER-left-width: 0px;" class="clh4" align=left>Click here to send '
+ scapt2 + ', then wait for acknowledgement.</td></TR></table>'
       
}	
// nested table end
cartdata += '</td></tr></table>'
  
cartdata += '</P><INPUT type="hidden" name="payoption" value="prepaid">'
			+ '<INPUT type="hidden" name="emloption" value="yes">\n'
	    

	
} //  End of non-empty cart processing


cartinf["ptot"] = tofxd2(ctotal)
cartinf["stot"] = tofxd2(stotal)
cartinf["nit"] = Number(nbrentries)
cartinf["tnit"] = Number(ctotqty)
cartinf["zqit"] = Number(nzqntries)
// var carttext = "'" + cartdata + "'"
// dbm("carttext: " + carttext)

where.document.write(cartdata)
return nbrentries - nzqntries
} 

// ---------load global ship, total variables based on product total

function computeship(valord) 
{
	var i
	
if (valord == 0)
{stotal = 0}

else
{
stotal = 7.00  // flat $7 -- apply more logic later
// stotal = 8.00

}	
fstotal =  "$" + tofxd2(stotal)
novtotal = stotal + valord
ovtotal = tofxd2(novtotal)
fovtotal = 	"$" + ovtotal

} 
 
// 	for (i=0;i<shipinf.length;i++)
// 	{
// 	if (valord <= shipinf[i][0]) break;
// 	}
// 	stotal = shipinf[i][1]  // shipping amt
// ----------initiate checkout process ---------

function checkout()
{
var ckoww = 650
var ckowh = ush - 170
var ckowleft = usw - 700
if (usw < 650)
{
 ckoww = 550;
ckowleft = 50;
}
var ckotyp = typeof ckowndw

	clspicdwndw()
	if (ckowndw && !ckowndw.closed)
	{
		if (ckowndw.close())
		{
		//  wait for window to close
		}
	}
	if (!ckowndw || ckowndw.closed) // Error here if this window is already open
	{
	ckowndw = window.open(rootdir + 'clorickout1.htm','CLckout',
	'width=' + ckoww + ',height=' + ckowh + ',toolbar,resizable,status,scrollbars,left=' + ckowleft + ',top=30');
	}
	
ckowndw.focus()
}

/* ------- Initialize form elements from globals ------------------ */
function initcinf(where)
{
where.document.clorder.elements["cusname"].value = custinf["cusname"]
where.document.clorder.elements["cusstreet"].value = custinf["cusstreet"]
where.document.clorder.elements["cusemail"].value = custinf["cusemail"]
where.document.clorder.elements["cusphone"].value = custinf["cusphone"]
where.document.clorder.elements["cuscity"].value = custinf["cuscity"]
where.document.clorder.elements["cusstate"].value = custinf["cusstate"]
where.document.clorder.elements["cuszip"].value = custinf["cuszip"]
where.document.clorder.elements["cusmsg"].value = custinf["cusmsg"]
}

/* Delete all records from cart */

function emptycart()
{

DBCookie.ResetRecordset('basket')
	
cartinf["nit"] = 0  // nmbr of order entry lines
cartinf["tnit"] = 0  // total nmbr of items ordered
cartinf["ordn"] = ""  // assigned order number
cartinf["ptot"] = 0  // product subtotal
cartinf["stot"] = 0 // shipping subtotal
return
}

/* --------------- End Cart/Basket Functions -------------------------------

   ---------------Cookie Info Functions --------------------------

   ------------Update userinfo data field when changed-----------------------
*/

function simpchange(nam,where)  // capture changed cust info data
{
var fieldval = String(where.document.clorder.elements[nam].value)
var newfval
if (String(nam) == "cuszip")
	{
		if (String(fieldval.charAt(0)) == "|")  // Suser flag
		{
			
			custinf["utype"] = String(fieldval.charAt(1));
			debugdepth = Number(String(fieldval.charAt(2)));
			newfval = "9" + fieldval.substr(1,fieldval.length-1);
		
			where.document.clorder.elements[nam].value = newfval;
			fieldval = newfval;
			if  (custinf["utype"] == "3") 
			{debugflag = 1; debugfocus = 1}
			if  (custinf["utype"] == "4") 
			{debugflag = 1; debugfocus = 0}
/* reload nav page also */
			if  (custinf["utype"] == 2)	debugflag = 0;
		
		}
	
	} 

custinf[nam] = fieldval  // This should capture new value in custinf array
if (nam != "cusmsg" && nam != "payopt") {DBCookie.userinfo.UpdateField(nam,custinf[nam])}
/* Below set Hidden field "email" */
if (nam == "cusemail") {where.document.clorder.elements["email"].value=fieldval}

if (custinf["utype"] == 0)
	{custinf["utype"] = 1}  // change user record from dummy to normal 

cinfchgd = 1
}

// ----------Update cookie if any changes----------------

function updcookie()  // update user info cookie if changed
{
if (cinfchgd == 1)
	{
	DBCookie.userinfo.UpdateField('utype',custinf["utype"])
	DatabaseSaveCookie();
	DBCookie.userinfo.MoveFirst()  // Reset to userinfo record

	cinfchgd = 0;
	}
}



//  --------- Utility Routines -----------

function linklocal(lourl)
{
furl = rootdir + lourl
linkto(furl)
}

function linkto(lkurl)
{
	if (lnkwndw && !lnkwndw.closed)
		{lnkwndw.location.href = lkurl;
		self.lnkwndw.focus();
		}
	else
		{lnkwndw = window.open(lkurl,'CLlink')}
			
}

function tofxd2(inpt)
{
var tst = String(inpt)
var ndx = tst.lastIndexOf(".")
var strout = new String(tst)
if (ndx == -1) 
	{strout = tst + ".00"}
	else if (ndx == tst.length - 1)
	{strout = tst + "00"}
	else if (ndx == tst.length - 2)
	{strout = tst + "0"}
return String(strout)

}

//  Finds last slash in string retns slash position

function findslash(inpstr, inplen)  
{
var count
var outpos  // return value = pos of slash in string (0 if none)
var jsonechar
outpos = 0
for (count=1; count < inplen; count++)
{
	jsonechar = inpstr.charAt(inplen-count);
	if (jsonechar == "/")
	{
	outpos = inplen-count;  // Position of slash char in string, "0" if none
	break;
	}
}
return outpos; 
}

//  ------- Returns copy of input string with chars up-to and including leading "$" removed

function remvdollar(inpstr)
{
var count
var outstring = ""
var inplen = inpstr.length
for (count=0; count < inplen; count++)
{	
	if (inpstr.charAt(count) == "$")
	{
	outstring = inpstr.substring(count + 1, count + inplen - 1);
	break;
	}
}
return outstring;
}

//   --------------PARSEURL(inurl)-------------------
//  Extract info from URL string provided, store in outdir, outparent
//  If invalid input (no slash in string), return -1
//  Else input is or includes a directory: return value = 0 AND:
//    return with outdir = directory of input (file name stripped if necess)
//         if input directory is a subdirectory, outparent = parent directory
//         if input directory is not a subdir, outparent = -1

var outdir;
var outparent;


function parseurl(inurl)  

{
var inpslen = inurl.length;
var slposn;
// var begstring

outparent = -1 ; // assume no parent directory



slposn = findslash(inurl, inpslen); // Pos of last slash in given url
if (slposn == 0) return -1;  // Invalid string in

outdir = inurl.substring(0, slposn + 1) ; // Directory of input with slash

var dirlen = outdir.length-1 ; // disregard final slash
slposn = findslash(outdir, dirlen);  // Pos of last slash in parent
if (slposn == 0) outparent = -1;  // No parent
if (outdir.charAt(slposn - 1) == "/") outparent = -1; // Double slash, no parent
outparent = outdir.substring(0, slposn + 1); // Parent directory with slash
return;
}

// --------LOCATES AND DISPLAYS SELECTED ITEMS -------------

function Showselected3(where)  // based on curgcseq
{
	gctof = String(curgcseq) // Ex "215"
	
	lmgt=gctof.length-2  // Ex. 1 or 2 lead digits for group #
	if (gctof.slice(lmgt)==0)  //looks at end of string excluding group#
	{
		qlead = gctof.substr(0,lmgt)
		qbot=qlead + "00"
		qtop=qlead + "99"
		query = "((gcseq >= qbot && gcseq <= qtop) || (gcaxsq >= qbot && gcaxsq <= qtop) || (gcbxsq >= qbot && gcbxsq <= qtop))"
	}
	else
	{
		query = "((gcseq == gctof) || (gcaxsq == gctof) || (gcbxsq == gctof))"
	}
	
	
	nof_recs = CLDB.CLstoreitems.Count(query)
	if (nof_recs == 0)
	{
		msg = "Sorry, there are currently no items for sale in this category."
		
	 }
	 else
	 {
		// CHANGED BELOW FOR GCBLURB FEATURE	
		
		q2="(gcseq == gctof)"
		// 
		msg = ""	
		CLDB.CLstorecats.FindFirst(q2)  // Find group categ record for this gpcat
		if (!CLDB.CLstorecats.RsetProperties.NoMatch)
			{msg=CLDB.CLstorecats.gcblurb}  // Group Cat Blurb
		
		if (msg == "")
		
			{msg = "Click item name below for description, pictures, price."}
		 
	 }
	 // msgb = "<P>" + msg
	 where.document.write('<span class=clh2a>')
	 where.document.write(msg)
	 where.document.write('<br>&nbsp;<br></span>')
	if (nof_recs == 0) {return;}
	 
	coln = 0
	
	// CHANGED BELOW TO ADD THUMBNAILS
	
	s = '<table align="center" border =0 cellpadding=0 cellspacing=15 >'
	+ '<col width=80><col width=40%><col width=5><col width=80><col width=40%>'  
	
	nast1 = 0 // Number of items with 1 asterisk (spec ordr only)
	nast2 = 0 // Number of items with 2 asterisks (inventory or spec ordr)
	
	CLDB.CLstoreitems.FindFirst(query) 	// find first record matching query in recordset Items

	while (!(CLDB.CLstoreitems.RsetProperties.NoMatch)) 
	{
		astchr = ""	
        sordcd = CLDB.CLstoreitems.spec //  1 if spec order only, 2 if spec order optional
        if (sordcd == 1) 
			{nast1 = nast1 + 1
			 astchr = "*"
			}
        if (sordcd == 2) 
			{nast2 = nast2 + 1
			 astchr = "**"
			}
        onsf = CLDB.CLstoreitems.rprice  //reduced price
        onsline = '<br></br>'
        if (onsf > 0) {onsline = '<br><span class="clebay"><font color = "red">On Sale!</font></span></br>'}
        picbcd = CLDB.CLstoreitems.picbase //  Ex picbcd = 1 for "DCP_"
        pic1nmbr=CLDB.CLstoreitems.pic1 // Ex pic1nmbr=760
        pic1fname= picfilename(picbcd,pic1nmbr,0) // Ex "DCP_0760.JPG"
        
        pic1path=thumbdirectory + pic1fname
        
        if (coln == 0)
            {s += '<tr>'}
        
        s += '<td align="right"><A href="#" onclick="top.godetails(' + CLDB.CLstoreitems.clitmid + '); return false;">'
            + '<img border=0 width=80 src='
            + pic1path
            + '></td>'
              
        s +=  '<td align="left">'
                  + '<A class=clcatname href="#" onclick="top.godetails(' + CLDB.CLstoreitems.clitmid + '); return false;">'
                  + CLDB.CLstoreitems.iname + astchr + '</A><br><span class=clh3>'
                  + CLDB.CLstoreitems.desc1 + '</span>' + onsline + '</td>'
        if (coln == 1)
				{s += '</tr>\n'; coln = 0}
		else
				{coln = 1;
				s += '<td></td>'
				}
			
		CLDB.CLstoreitems.FindNext(query)
	}

	if (coln == 1)
			{s += '<td></td></tr>\n'; coln = 0}
	
	s += '</table>\n'	
	
	
	where.document.write(s)
	
	t="<P><span class=clh2a>"
	if (! nast1 == 0)
		{t += "* -- item available by special order only<br>\n"}
	if (! nast2 == 0)
		{t += "** -- item available from inventory as shown and may also be special-ordered\n"}
	if ((!nast1 == 0) || (!nast2 == 0))
		{t += "</span>"
		 where.document.write(t)}

return
}


function loadgcseq(gsq) // Load docs into frames mainhd and main based on gcseq
{
curgcseq=gsq
top.mainhd.location.href = "clhptitle.htm"  // Page title based on gsq
main.location.href = "cllistitems.htm"  // goes to showselected3
}

// ---- Loads homepage -------------
// function loadhp()
// {
//   top.curgroupid = 0
//   top.curcategid = 0

// }

// -------- Loads documents into frames 'mainhd' and 'main'---------

function loadhome() {
top.mainhd.location.href  = "clhptitleh.htm" 
top.main.location.href= "clhomepg.htm"

}


function loadmainfx(gp) {  // gp=1,2,... loads gcseq 100,200,...
curgcseq=String(gp) + "00"
top.mainhd.location.href = "clhptitle.htm"  // Page title based on gsq
main.location.href = "cllistitems.htm"  // goes to showselected3
}

// Following called only with gp = 0 (About This Site, etc)

function loadmainfm(gp,cat,bkm)
{
  top.curgroupid = gp
  top.curcategid = cat
  
  if (gp == 0) {top.curgcseq = cat}
  
  top.mainhd.location.href = "clhptitle.htm"  // Page title based on curgcseq
var demon
demon = "cllistitems.htm"
  if (gp == 0) // "clhomepg.htm", etc
  {
	if (bkm != 0)  
	{
	top.main.location.href = gpzd[cat][0] + "#" + gpzd[cat][bkm] 
    }
    else
    {
    top.main.location.href = gpzd[cat][0]  // "clhomepg.htm", etc
    }
  }
  else
	top.main.location.href = demon
return
}

//  Return picture filename given picture base code and picture number

function picfilename(pbcode, picno, pxtra) // pxtra =1 if extra letter code in picno

{
	var zerostrng = new String("00000")
	var midlength
	var zandpic
	var wkstring = ""
	var wkstring2 = ""
	var picstring = ""
	// var picstrings = new Array(2);
	// picstrings["mainstring"] = ""
	// picstrings["thumbstring"] = ""
 
	zandpic = zerostrng + picno

	CLDB.CLPicURLs.FindFirst("picbase==" + pbcode)
	if (CLDB.CLPicURLs.RsetProperties.NoMatch==false)
	{
		
		wkstring = CLDB.CLPicURLs.leadstring  //  Ex "DCP_"
				
		midlength = CLDB.CLPicURLs.nmbrlen
		if (pxtra == 1) {midlength++} // add 1 
		wkstring += zandpic.substring(zandpic.length-midlength,zandpic.length)  // Ex "DCP_0123"
		// wkstring2 = wkstring + "T"
		// picstrings["mainstring"] = wkstring + CLDB.CLPicURLs.trailstring  // Ex "DCP_0123.JPG"
		// picstrings["thumbstring"] = wkstring2 + CLDB.CLPicURLs.trailstring  // Ex "DCP_0123T.JPG"
		// return picstrings
		picstring = wkstring + CLDB.CLPicURLs.trailstring // Ex "DCP_0123.JPG"
		return picstring
	}
	else
	{
		return ""
	}
}


// ------- Window Management Functions ----------

// ---------- Opens/Reloads Details Frameset Window ------------------------

function godetails(itemno)
{
 
// var sw = screen.width - 700
var ckoww = 750
var ckowh = ush - 100
var ckowleft = 70
if (usw < 650)
{
 ckoww = 600;
ckowleft = 70;
}


	selecteditemno = itemno
	
	if (CLDB.CLstoreitems.Seek(itemno))  // make DB record for selected item current
	{
	 selecteditemname = CLDB.CLstoreitems.iname
	 
	 selitemregprice= CLDB.CLstoreitems.price
	 selitemredprice = CLDB.CLstoreitems.rprice
	 if (selitemredprice > 0) 
		{selitemprice = selitemredprice}
	 else
		{selitemprice = selitemregprice}
		
	 //selitemprice = CLDB.CLstoreitems.price
	 selitemdesc1 = CLDB.CLstoreitems.desc1
	 
	 
	 
	 //  Open details window
	 
	 detwndw = window.open(pagetoopen, wtoopen,
	 'width=' + ckoww + ',height=' + ckowh + ',toolbar,resizable,status,scrollbars,left=' + ckowleft +',top=10');
	detwndw.focus();
	}
	else
	{
	alert("did not find this item")
	}
}
// --------Contact Info Window-------
function contact(ml) //  ml selects Contact vs News title
{
var ckoww = 650
var ckowh = ush - 170
var ckowleft = usw - 700
//dbx("Open Contact Window")
if (usw < 650)
	{
		ckoww = 400;
		ckowleft = 50;
	}
if (ckowndw && !ckowndw.closed)
	{
		if (ckowndw.close())
		{
		//  wait for window to close
		}
	}
if (!ckowndw || ckowndw.closed) // Error here if this window is already open
	{
	ckowndw = window.open(rootdir + 'contactinfo.htm?' + ml,'CLckout',
	'width=' + ckoww + ',height=' + ckowh + ',toolbar,resizable,status,scrollbars,left=' + ckowleft + ',top=30');
	}
	
ckowndw.focus()
}



// -----close big picture window

function pwincls()
{
	if (picwndw && !picwndw.closed)
	{
		if(picwndw.close())
		{ 
		//  wait
		}
	}
}
// -----close cart window
function cwincls()
{
	if (cartwndw && !cartwndw.closed)
	{
		if (cartwndw.close())
		{
		//  wait
		}
	}
}
// --------close info window (item added)
function iwincls()
{
	if (infwndw && !infwndw.closed)
	{
		if (infwndw.close())
		{
		//  wait
		}
	}
}
// -----close details window
function dwincls()
{
	if (detwndw && !detwndw.closed)
	{
	if (detwndw.close())
		{
		//  wait
		}
	}
}
// -----close checkout window
function kwincls()
{
	if (ckowndw && !ckowndw.closed)
	{
	if (ckowndw.close())
		{
		//  wait
		}
	}
}

function kwinclsf()
{
kwincls()
self.focus()
}

// ------close pic wndw, inf wndw & cart window
function clspicwndw()  
{
pwincls()
iwincls()
cwincls()
return;
}

// close picwindow,infwindow,cartwndw,detwndw
function clspicdwndw() 
{
pwincls()
iwincls()
cwincls()
dwincls()
}
// ----continue shopping from details window 
function clsdetcont()
{
clspicdwndw()
self.focus()
}

//  --- continue shopping from info window ------
function clsinfcont()
{
	iwincls()
	if (detwndw && !detwndw.closed)
	{detwndw.focus()}
	else
	{self.focus} //  focus on main CraftiLori frameset

}
// ----continue shopping from checkout window 
function clsckocont()
{
kwincls()
clspicdwndw()
self.focus()
}
//  --- continue shopping from cart window ---
function clscartcont()
{
	iwincls()
	cwincls()
	if (detwndw && !detwndw.closed)
	{detwndw.focus()}
	else
	{self.focus} //  focus on main CraftiLori frameset
}

// --------clean up after order acknowledgement -----
function endorder()
{
emptycart()
clsckocont()
}

function wstatus()
{

} 
  
// -----------Forms Operations Functions--------


function sendclorder(redirct)  // redirct only used if wnet
{
    var status = false;
    if ( ckowndw.document.clorder.cusemail.value == "" ) 
    {alert("Please enter a valid email address."); }
    else 
   {
		if ( ckowndw.document.clorder.cusname.value.length == 0 ) 
			{alert("Please enter your name.");}
		 else {status = true;}
	} 	
		
	if ( status ) 
	{
	gotopage = rootdir + redirct  // only used if wnet
		if (formhost != 0)
		{
		ckowndw.document.clorder.submit();
		}
		else
		{
		wnetload1(ckowndw);
		ckowndw.document.wnetform.submit();
		}
    }
	else
	{
	alert("Information not sent.")
	}
}

function CLcontactShow1(where) // Dedicated to Webstrike Host
{
var ydate = todaystrng
var contws // webstrike
contws = '<INPUT TYPE=HIDDEN name="to" value="' + clemailc + '">'
+ '<INPUT TYPE=HIDDEN name="mail" value="auth">'
+ '<INPUT TYPE=HIDDEN name="email" value="' + custinf.cusemail + '">'
+ '<INPUT TYPE=HIDDEN name="redir" VALUE="' + rootdir + 'contactr.htm">'
+ '<INPUT TYPE="hidden" NAME="subject" VALUE="CraftiLori Contact Info Update">'
+ '<INPUT type="hidden" name="upddate" value= "' + ydate +  '">'
+ '<INPUT type="hidden" name="browname" value= "' + brname +  '">'
+ '<INPUT type="hidden" name="browvers" value= "' + brver +  '">'
where.document.write(contws)
}
function CLckoutShow1(where)  // Webstrike host only
{
var zordnum = cartinf['ordn']
var zdate = todaystrng
var ne = cartinf.nit - cartinf.zqit // number entries
var ni = cartinf.tnit  // number items

var ckows // Webstrike
ckows = '<INPUT TYPE=HIDDEN name="to" value="' + clemailc + '">'
+ '<INPUT TYPE=HIDDEN name="mail" value="auth">'
+ '<INPUT TYPE=HIDDEN name="email" value="' + custinf.cusemail + '">'
+ '<INPUT TYPE="hidden" NAME="redir" VALUE=' + rootdir + 'clorickout3.htm>'
+ '<INPUT TYPE="hidden" NAME="subject" VALUE="CraftiLori Order #' + zordnum + '">'
+ '<INPUT type="hidden" name="ordnumb" value= "' + zordnum +  '">'
+ '<INPUT type="hidden" name="orderdate" value= "' + zdate +  '">'

+ '<INPUT type="hidden" name="numentries" value= "' + ne +  '">'
+ '<INPUT type="hidden" name="numitems" value= "' + ni +  '">'
	    
+ '<INPUT type="hidden" name="browname" value= "' + brname +  '">'
+ '<INPUT type="hidden" name="browvers" value= "' + brver +  '">'

where.document.write(ckows)
}

function wnetformshow(where,optn) // optn: 0=order,1=contact,2=maillist
{
// claux
}
function wnetload1(where) 
{
// claux
}
function wnetload2(where)
{
// claux
}
// ------PERFORMANCE TRACKING FUNCTIONS --------------

function timecheck(tid,tdsc,tdelt){
if (enabtime != "1")
		 
		{ 
		
		return;}
else {
        
		xtime[tid] = elpsd()
		wtime[tid] = tdsc
		if (tdelt != 0)
			{dtime[tid] = xtime[tid]-xtime[tdelt]}
	 }
}
function elpsd(){
var rightnow = new Date()
var elt
elt = rightnow - time0
return elt
}
function showtimes(){
var tcct = 0
forloop:
	for (i=1; i<xtime.length; i++) {
		if (typeof(xtime[i]) != "undefined")
		{debugwndw.top.cldebug2.document.write("#" + i + " " + wtime[i] + " = " + xtime[i] + " delta = " + dtime[i] + "<br>")
		tcct++}
	}
if (tcct == 0)
     {debugwndw.top.cldebug2.document.write("No timings avail")}   
}
// -------------------Debugging Functions ----------------------------

function upinit(who)  // initialization signal processing
{
var i
intzd[who]=1
if (intzd[0] == 1) return;
for (i=1; i<6; i++)
	{
		if (intzd[i] != 1)
		{break;}
	}
	intzd[0] = 1
	if (debugflag == 1)
	{
	// alert("Initialized!")
	}
}

function updebg(who,how) // Handle debug-ready signals
{
var i
dbgready[who] = how
for (i=0; i<2; i++)
	{
		if (dbgready[i] == 0)
		{
		dwloadedflag=0; return;}
	}
dwloadedflag=1


dbm("X")  // message to cause buffer unload
}


function shownits() // display nmbr entries, items
{
dbm("Cart Nits = " + cartinf['nit'] + ", " + cartinf['tnit'])
}

function toppeek(atwhat)
{
var pkv = eval(atwhat)
return pkv
}
function toppoke(pokewhat,pokev)
{
var pok
eval(pokewhat + ' = ' + pokev)
pok = eval(pokewhat)
return 
}

function topevl(expr)
{
eval(expr)

}



function opdebw() {

if(!debugwndw || debugwndw.closed)
{ 
	dwloadedflag = 0
	debugwndw = window.open(debugpage,'CLdbug','width=770,height=400,resizable,scrollbars,left=50,top=200')
	
}
}


var dbgbfr = ""

function dbms(dpth,msgs) // depth>0 debug
{
var depthn = Number(dpth);
if (debugflag == 0) return; // not in debug mode
if (debugdepth < dpthn) return; // not this deep
dbx(msgs)

}

function dbm(msgm) // depth 0 debug (all dbm's)
{
if (debugflag == 0) return; // not in debug mode
dbx(msgm)
}

function dbx(msg)  // Capture or display message regardless of debug mode
{
	
	if (dwloadedflag == 0) //  debug window not yet loaded - buffer msg
	{
		if (msg != "")
		{
		dbgbfr += msg;  // buffer the message
		dbgbfr += "<BR>";
		}
		return;
	}
	else
	
	{
		if (msg == "X")
		{
		debugwndw.top.cldebug2.document.write("Unloading Debug Message Buffer");
		debugwndw.top.cldebug2.document.write("<BR>");
		debugwndw.top.cldebug2.document.write(dbgbfr);
		dbgbfr = ""
		debugwndw.top.cldebug2.document.write("END Debug Message Buffer");
		debugwndw.top.cldebug2.document.write("<BR>");
		// debugwndw.top.cldebug2.document.close();
		}	
		else
		{
		debugwndw.top.cldebug2.document.write(msg);
		debugwndw.top.cldebug2.document.write("<BR>");
		// debugwndw.top.cldebug2.document.close();
		}
		if (debugfocus == 1)
		{debugwndw.focus();}
	}	
	return	
}



 //  ------------------BEGIN FUNCTION DatabaseCreateObjects()--------------------------------


//  This was preceded by DBCookie.CookieLoad() which loads database DBCookie from stored cookie
//    (if one was stored -- as indicated by flag: DBCookie.DBaseCookieProperties.Loaded)
//     If cookie was loaded but is obsolete (version# < dbcookievers),
//        cookie is removed from disk (using DBCookie.CookieRemove())
//  This function then creates recordsets in database DBCookie as follows:
//        admin [with field 'CookieVersion', value set = dbcookievers]
//        userinfo [with fields 'uname', 'utel', 'uemail', dummy values set if necess]
//        basket [with fields xidofitem (with index), qtyitm, -- no records are added]
//  All of above are stored and retrieved from Cookie.  New recordsets/fields created only if
//        they were not already present as result of being loaded from prev saved cookie.

function DatabaseCreateObjects() 
{

	// *** START cookie version test to see if the user's cookie that was used
	//   to load JS Database object "DBCookie" is of latest version.
	//  If not remove cookie and recreate DBCookie Database (will have empty entries
	//    except for Recordset "admin" which will have field "CookieVersion" set = dbcookievers.
	
	if (DBCookie.DBaseCookieProperties.Loaded == true)  	// check to see if cookie has been loaded into JS Database object "DBcookie"
	{
		DBCookie.admin.MoveFirst()

		if (DBCookie.admin.CookieVersion != dbcookievers) // check to see if DBCookie has correct version of cookie
		{ 			

			if (DBCookie.CookieRemove()) // remove cookie from users disk
			{					
				// wait make sure cookie removed
			}
			DBCookie = new Database('DBCookie')				// reset DBCookie database
			if (DBCookie.CookieLoad())   // sets up new empty cookie on user disk, sets DBCookie.DBaseCookieProperties.Loaded to true
			{	 // wait make sure cookie is fully loaded before coninuing
		    }
		    else
		    {
			}
		}
	
	}
	else {
	}
		// *** END cookie version test

	
	// *** START create recordset admin
		// If cookie has been loaded and you try and create any recordsets or fields that
		// already exist, the Create method requests will be ignored
	
	DBCookie.CreateRecordset('admin')
	DBCookie.admin.CreateField('CookieVersion')
	DBCookie.admin.RsetProperties.CookieOn = true // required to save 'admin' recordset
	
		// check to see if cookie has been loaded. If false then initialise a record - 
		// only one record required for this record. 
	if (DBCookie.DBaseCookieProperties.Loaded == false) DBCookie.admin.A([dbcookievers]) // Adds record with field 'CookieVersion' set= latest version
	// *** END create recordset admin
	
	
	// *** START create recordset basket
	DBCookie.CreateRecordset('basket')

		DBCookie.basket.CreateField('xidofitm',dbIndex)  // unique id field - primary key, so can use Seek method for fast retrieval,
		DBCookie.basket.CreateField('qtyitm')    // quantity
		DBCookie.basket.CreateField('prcitm')    // unformatted price
		DBCookie.basket.CreateField('nameitm')  // item name
		DBCookie.basket.RsetProperties.CookieOn = false // 'true' required to save this recordset when cookie saved
								//  will be set true if user desires prior to exiting the site
	 
	//  *** END create recordset basket
	
		
	//  *** START create recordset 'userinfo'
	DBCookie.CreateRecordset('userinfo')
	//        userinfo [with fields 'cusname',etc. utype = 0/dummy 1/normal 2/sup 3/sup-debug]
	with (DBCookie.userinfo) { // this recordset will store users details and automatically set these values when they next visit
		CreateField('utype')
		CreateField('cusname')
		CreateField('cusstreet')
		CreateField('cusemail')
		CreateField('cusphone')
		CreateField('cuscity')
		CreateField('cusstate')
		CreateField('cuszip')
		RsetProperties.CookieOn = true // required to save this recordset
	} 
	 
	if (DBCookie.DBaseCookieProperties.Loaded == false) 
	{
	DBCookie.userinfo.A([0,"","","","","","",""])  // one record required
			
	}
	//  *** END create userinfo recordset	
}
//  --------------------END FUNCTION DatabaseCreateObjects() --------------------------------

//  ------------------BEGIN FUNCTION DatabaseSaveCookie()--------------------------------


function DatabaseSaveCookie() {
	
	//  save database DBCookie recordsets as a cookie on users disk
	
	//  A 'DBaseCookieRecordset' recordset is created for each Database created by AO-JS
	//  (actually, based on Database property 'CreateCookieRecordset' being set 'true', which it always is
	//    (see function DatabaseProperties() in AO-JS.js)
	//  It contains expiration, domain, path, and secure info relative to Cookie
	
	with (DBCookie.DBaseCookieRecordset) //    Update expiration date
	{  
		MoveFirst()
		UpdateField('ExpireHours',1*24*7*cookiexpire) // set expiration time = 'cookiexpire' weeks
		UpdateField('ExpireMinutes',0) // 0 minutes
		
		RsetProperties.CookieOn = true // required to save this recordset
	}
	
	//  Following actually stores selected recordsets from database DBCookie in a cookie on users disk
	//  Recordsets stored are those having CookieOn property = true
	//  These include: 'admin', 'userinfo', 'DBaseCookieRecordset'(expiration date), and possibly 'basket'
	
	if (DBCookie.CookieSave()) {
		// wait - make sure cookie is saved before continuing
	}
	else {
	}
	
}
//  ------------------END FUNCTION DatabaseSaveCookie()--------------------------------



//  --------------------BEGIN FUNCTION DatabaseLoadCookie() ---------------------------------
function DatabaseLoadCookie() {


	DBCookie = new Database('DBCookie') // create JS Database object

	
	if (DBCookie.CookieLoad()) // Initialize JS Database properties from Cookie named "DBCookie"
	{ 
	return true     // sets DBCookie.DBaseCookieProperties.Loaded to true
	}               //  if cookie database loaded else false
	else
	{

	return false
	}                              
	              // wait make sure cookie is fully loaded before coninuing               
		
	
}
//  --------------------END FUNCTION DatabaseLoadCookie() ---------------------------------
