//to fix:
//--#23 items numbers handle - hidden and shown
//---min and free items
//add subitmes2 and 3
//deliver charge free above max
//
//presub - validate + presub

var taxtotal = 0


function ExpandSection(idVariable){

idVariable.style.display=""

/*
if (idVariable.style.display=="none")
	{
		idVariable.style.display="" ;

	}
else{
	idVariable.style.display="none" ;
   }

*/

}

function ContractSection(idVariable){

idVariable.style.display="none"

//if (idVariable.style.display==""){idVariable.style.display="none"}

}




function init()
{




	 if (isie > 1)
	  {
		n = parseInt(form.nadds.value)

	 	if (n > 0) ContractSection(t7)
	 	if (n > 1) ContractSection(t8)
	 	if (n > 2) ContractSection(t9)
  	  }

		 taxtotal = 0
		 if (document.form.currency.value.length == 0) document.form.currency.value = "$" ;

		 if (document.form.dodel.value != "1") document.form.dodel.value = "0" ;
		 if (document.form.dofut.value != "1") document.form.dofut.value = "0" ;



		 if (subtotal > 0)
		   {
			   taxrate = parseFloat(document.form.taxrate.value)
			   taxtotal = subtotal * taxrate *.01

	       }

         var a = new ToFmt(taxtotal)
         taxtotalf=a.fmtF(8,2);


 		 a = new ToFmt(subtotal)
         subf=a.fmtF(8,2);

 		 p = "Subtotal: " + document.form.currency.value + subf
 		 var newopt = new Option(p,p)
   		 document.form.totals.options[0]	= newopt

 		 p = "Tax:          " + document.form.currency.value + taxtotalf
 		 newopt = new Option(p,p)
   		 document.form.totals.options[1]	= newopt


          n = 3

          var d = 0 ;


 		 if (document.form.dodel.value == "1")
 		  {
 		 		n = 4 ;

				a = new ToFmt(d)
				df=a.fmtF(8,2);


				p = "Delivery:  " + document.form.currency.value + df
				var newopt = new Option(p,p)
				document.form.totals.options[2]	= newopt

  	      }


 	     total = total + d
 	     a = new ToFmt(total)
 		 totalf=a.fmtF(8,2);


  		 p = "Total:        " + document.form.currency.value + totalf
 		 newopt = new Option(p,p)



   		 document.form.totals.options[n] = newopt



if (document.form.order_detail.value.length)
  {

	  var a = document.form.order_detail.value
	  k = a.indexOf(":;")


	  while ((k > 0) && (a.length > 3))
	   {


		   var v = a.substr(0, k)
		   a = a.substr(k+2, a.length)


		   var p = v




		  if (document.form.hn.value == "1")
		  {
			  k2 = p.indexOf(" ") ;

			  p = p.substr(k2+1, p.length) ;

		  }


		     var newopt = new Option(p,v)
 		     document.form.order.options[document.form.order.options.length] = newopt ;

 		     k = a.indexOf(":;")



	   }


	if (document.form.dodel.value == "1")
	  {
	   if (document.form.deliver.checked)
	       {

				n = 4 ;
				var d = 0 ;

				if (parseFloat(document.form.delcharge.value) < 1) d = subtotal * parseFloat(document.form.delcharge.value) ;
				else d = parseFloat(document.form.delcharge.value) ;

				d2 = parseFloat(document.form.delmin.value)


				//alert(subtotal)
				if  (subtotal >= d2)
				  {
					d = 0 ;
					//alert(d)
				  }


				if (! document.form.deliver.checked) d = 0 ;

				a = new ToFmt(d)
				df=a.fmtF(8,2);


				p = "Delivery:  " + document.form.currency.value + df
				var newopt = new Option(p,p)
				document.form.totals.options[2]	= newopt

	       }
   		}


  }


}


function ToFmt(x){
 this.x=x;
 this.fmt00 = fmt00;
 this.fmtF = fmtF;
 this.fmtE=fmtE;
 this.fmtI=fmtI;
 this.spacer=" ";
 this.setSpacer=setSpacer;
}

function fmt00(){
 // fmt00: Tags leading zero onto numbers 0 - 9.
 // Particularly useful for displaying results from Date methods.
 //
 if (parseInt(this.x) < 0) var neg = true;
 if (Math.abs(parseInt(this.x)) < 10){
  this.x = "0"+ Math.abs(this.x);
 }
 if (neg) this.x = "-"+this.x;
 return this.x;
}

function fmtF(w,d){

 // fmtF: formats in a style similar to Fortran's Fw.d, where w is the
 // width of the field and d is the number of figures after the decimal
 // point.
 // The result is aligned to the right of the field.  The default
 // padding character is a space " ". This can be modified using the
 // setSpacer(string) method of ToFmt.
 // If the result will not fit in the field , the field will be returned
 // containing w asterisks.
 var width=w;
 var dpls=d;
 var lt1=false;
 var len=this.x.toString().length;
 var junk;
 var res="";
// First check for valid format request
 if ( width < (dpls+2)){
  window.alert("Illegal format specified : w = " + d +
               " w = " + d +
                "\nUsage: [ToFmt].fmtF(w,d)" +
                "\nWidth (w) of field must be greater or equal to the number " +
                "\nof digits to the right of the decimal point (d) + 2");
  junk = filljunk(width);
  return junk;
 }
// Work with absolute value
 var absx=Math.abs(this.x);
// Nasty fix to deal with numbers < 1 and problems with leading zeros!
 if ((absx < 1) && (absx > 0)){
  lt1 = true;
  absx+=10;
 }
// Get postion of decimal point
 var pt_pos = absx.toString().indexOf(".");
 if ( pt_pos == -1){
  res+= absx;
  res+= ".";
  for (var i = 0; i < dpls; i++){
   res += 0;
  }
 }
 else{
  res = Math.round(absx * Math.pow(10,dpls));
  res=res.toString();
  if (res.length ==
      Math.round(Math.floor(absx * Math.pow(10,dpls))).toString().length){
   res = res.substring(0,pt_pos) + "." +
         res.substring(pt_pos,res.length);
  }
  else{
   pt_pos++;
   res = res.substring(0,pt_pos) + "." +
          res.substring(pt_pos,res.length);
  }
// Remove leading 1 from  numbers < 1 (Nasty fix!)
  if (lt1) {
   res=res.substring(1,res.length);
  }
 }
 // Final formatting statements
 // Reinsert - sign for negative numbers
 if (this.x < 0)res = "-"+res;
 // Check whether the result fits in the width of the field specified
 if (res.length > width){
  res=filljunk(width);
 }
 // If necessary, pad from the left with the spacer string
 else if (res.length < width){
  var res_bl="";
  for (var i = 0; i < (width - res.length); i++){
   res_bl += this.spacer ;
  }
  res = res_bl + res;
 }
 return res;
}

function fmtE(w,d){

 // fmtE: formats in a style similar to Fortran's Ew.d, where w is the
 // width of the field and d is the number of figures after the decimal
 // point.
 // The result is aligned to the right of the field.  The default
 // padding character is a space " ". This can be modified using the
 // setSpacer(string) method of ToFmt.
 // If the result will not fit in the field , the field will be returned
 // containing w asterisks.
 //
 var width=w;
 var dpls=d;
 var e="E+";
 var len=this.x.toString().length;
 var pow10;
 var xp10;
 var junk;
 var res="";
// First check for valid format request
 if ( width < (dpls+5)){
  window.alert("Illegal format specified : w = " + d +
               " w = " + d +
                "\nUsage: [ToFmt].fmtE(w,d)" +
                "\nWidth (w) of field must be greater or equal to the number " +
                "\nof digits to the right of the decimal point (d) + 6");
  junk = filljunk(w);
  return junk;
 }
// Work with absolute value
 var absx=Math.abs(this.x);
// Get postion of decimal point
 var pt_pos = absx.toString().indexOf(".");
// For x=0
 if (absx == 0){
  res +="0.";
  for (var i=0; i< dpls; i++){
   res += "0";
  }
  res  += "E+00";
 }
// For abs(x) >= 1
 else if (absx >= 1.0){
  pow10=1;
  xp10 = absx;
  while (xp10 >= 1.){
   pow10++;
   xp10 /= 10;
  }
  res = Math.round(xp10 * Math.pow(10,dpls));
  res=res.toString();
  if (res.length ==
      Math.round(Math.floor(xp10 * Math.pow(10,dpls))).toString().length){
    pow10--;
  }
  res = "0." + res.substring(0,dpls) + e + (new ToFmt(pow10)).fmt00();
 }
// For abs(x) < 1
 else if (absx < 1.0){
  pow10=1;
  xp10 = absx;
  while (xp10 < 1.){
   pow10--;
   xp10 *= 10;
  }
  res = Math.round(xp10/10 * Math.pow(10,dpls));
  res=res.toString();
  if (res.length !=
      Math.round(Math.floor(xp10/10 * Math.pow(10,dpls))).toString().length){
    pow10++;
  }
  if (pow10 < 0) e = "E-";
  res = "0." + res.substring(0,dpls) + e + (new ToFmt(Math.abs(pow10))).fmt00();
 }

 if (this.x < 0)res = "-"+res;
 if (res.length > width){
  res=filljunk(width);
 }
 else if (res.length < width){
  var res_bl="";
  for (var i = 0; i < (width - res.length); i++){
   res_bl += this.spacer ;
  }
  res = res_bl + res;
 }
 return res;

}

function fmtI(w){

 // fmtI: formats in a style similar to Fortran's Iw, where w is the
 // width of the field.
 // Floating point values are truncated (rounded down) for integer
 // representation.
 // The result is aligned to the right of the field.  The default
 // padding character is a space " ". This can be modified using the
 // setSpacer(string) method of ToFmt.
 // If the result will not fit in the field , the field will be returned
 // containing w asterisks.
 var width=w;
 var lt0=false;
 var len=this.x.toString().length;
 var junk;
 var res="";
// Work with absolute value
 var absx = Math.abs(this.x);

// Test for < 0
 if (parseInt(this.x) < 0){
  lt0 = true;
 }
 res = Math.round(Math.floor((absx))).toString();
 if (lt0){
  res = "-"+res;
 }
 if (res.length > width){
  res=filljunk(width);
 }
 else if (res.length < width){
  var res_bl="";
  for (var i = 0; i < (width - res.length); i++){
   res_bl += this.spacer ;
  }
  res = res_bl + res;
 }
 return res;
}

function filljunk(lenf){
 // Fills field of length lenf with asterisks
 var str="";
 for (var i=0; i < lenf; i++){
  str +="*";
 }
 return str;
}

function setSpacer(spc){
 var spc;
 this.spacer=spc;
 return this.spacer;
}

//********EMAIL CHECK

function emailCheck (emailStr) {



/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address.
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Please enter a valid email address.");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Please enter a valid email address.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Please enter a valid email address.");
return false;
   }
}

// See if "user" is valid

if (user.match(userPat)==null) {

// user is not valid

alert("Please enter a valid email address.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Please enter a valid email address.");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("Please enter a valid email address.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("Please enter a valid email address.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("Please enter a valid email address.");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}


//***************TAKE OUT************



function validate_phone(field) {


var valid = "()-+0123456789"

var ok = "yes";
var digits = 0
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
if (valid.indexOf(temp) > 3 ) digits++ ;

}

if (ok == "no") {
alert("Invalid phone number. Please enter a correct phone number with area code.");
field.focus();
field.select();
return false ;
   }


if (digits < 10) {
alert("Incomplete phone number. Please enter the full phone number with area code.");
field.focus();
field.select();
return false;
   }


return true ;
}




function presub()
{




 if (document.form.order.options.length < 2)
   {
	   alert ("You haven't ordered any items.") ;
	   document.form.menu.focus() ;
	   return false ;

   }

 if (document.form.name.value.length < 2)
    {

		alert ("Please enter your name.") ;
		document.form.name.focus() ;

		return false ;

     }

 /*if (document.form.phone.value.length < 2)
     {

		alert ("Please enter your phone number.") ;
		document.form.phone.focus() ;

		return false ;

     }
    */

if (!validate_phone(document.form.phone)) return false ;

if (document.form.nowopen.value == "0")
   {

     if (document.form.dofut.value != "0")
     {
	   if (! document.form.future.checked)
	     {

			 alert ("As we are currently closed, you must specify a specific date and time when you would like this order to be ready.")

			 document.form.future.checked = true
			 document.form.month.focus() ;
			 return false ;

	     }
      }

    }


  if (document.form.time.value == "-")
    {

		alert("Please select the time you want this order to be ready.")
		document.form.time.focus() ;


		return false ;
     }


  if (document.form.dofut.value != "0")
    {

		if (document.form.future.checked)
		  {


				if (document.form.month.value.substr(0,1) == "-")
				  {


				  		alert("You have indicated that you would like this order prepared in the future. Please choose the month.") ;
						document.form.month.focus() ;
				  		return false ;
			      }

				if (document.form.day.value.substr(0,1) == "-")
				  {

				  		alert("You have indicated that you would like this order prepared in the future. Please choose the day.") ;
						document.form.day.focus() ;
				  		return false ;
			      }


				if (document.form.time.value == "NOW")
				  {

				  		alert("You have indicated that you would like this order prepared in the future. Please choose the time that you want the order ready.") ;
				  		document.form.time.focus() ;
				  		return false ;
			      }



				var mon = new Array(12) ;

				mon[0] = "January"
				mon[1] = "February"
				mon[2] = "March"
				mon[3] = "April"
				mon[4] = "May"
				mon[5] = "June"
				mon[6] = "July"
				mon[7] = "August"
				mon[8] = "September"
				mon[9] = "October"
				mon[10] = "November"
				mon[11] = "December"



			    var t = new Date();
				var h = t.getMonth();
				var d = t.getUTCDate() ;


				if (document.form.month.value == mon[h])
				  {

					  if (document.form.day.value < d)
					     {
							 alert("The date you have selected is not valid.")
							 document.form.day.focus()
							 return false ;

					     }

			      }


	      }


     }



  if (document.form.dodel.value != "0")
      {

  		if (document.form.deliver.checked)
  		  {

  				if (document.form.del_street.value.length < 5)
  				  {

  				  		alert("You have indicated that you would like this order to be delivered. Please enter the street address with Apt/Suite # (if any).") ;
						document.form.del_street.focus() ;
  				  		return false ;
  			      }


  				if (document.form.del_city.value.length < 2)
  				  {
  				  		alert("You have indicated that you would like this order to be delivered. Please enter the city.") ;
						document.form.del_city.focus() ;
  				  		return false ;
  			      }

  	      }

       }




if (document.form.email.value.length > 0)
	 {


 		 if (! emailCheck (document.form.email.value) )
 		 	{
				document.form.email.focus() ;
 		 		return false ;
		    }

     }




var a = "" ;


  for (i=1; i < document.form.order.options.length; i++)
   {

	  a = a + document.form.order.options[i].value + ":;" ;

   }




  document.form.nadds.value = subtotal ;
  document.form.hn.value = total ;

if (document.form.dodel.value != "0")
  {
   if (document.form.deliver.checked)
 	    {

 				n = 4 ;
 				var d = 0 ;

 				if (parseFloat(document.form.delcharge.value) < 1) d = subtotal * parseFloat(document.form.delcharge.value) ;
 				else d = parseFloat(document.form.delcharge.value) ;

 				d2 = parseFloat(document.form.delmin.value)


 				if  (subtotal >= d2)
				  {
					d = 0 ;
 				  }


				if (! document.form.deliver.checked) d = 0 ;

 				document.form.delcharge.value = d ;


	     }
	 else document.form.delcharge.value = 0 ;
  }
 else document.form.delcharge.value = 0 ;



 document.form.dodel.value = a








  return true ;

}




function datechk()
{

	if (!document.form.future.checked)
	  {

		  alert("If you want this order prepared in the future, please check the box on the left first.") ;
      }


}

function delchk()
{

	if (!document.form.deliver.checked)
	  {

		  alert("If you would like this order to be delivered, please check the box above first.") ;
      }


}



function cleard()
{

  document.getElementById("t1").innerHTML = " "
  document.getElementById("t2").innerHTML = " "

}

function menusel()
{


if (document.form.currency.value.length == 0) document.form.currency.value = "" + document.form.currency.value ;




var line = document.form.menu.value



document.form.qty.value = "1"
numitems = 0
minitems = 0
maxitems = 0
numitems2 = 0
minitems2 = 0
maxitems2 = 0
numitems3 = 0
minitems3 = 0
maxitems3 = 0


for(i = document.form.size.length - 1; i >= 0; i--)

			document.form.size.options[i]	= null;


n = parseInt(document.form.nadds.value)




if (n > 0)
 {
  for(i = document.form.items.length - 1; i >= 0; i--)

			document.form.items.options[i]	= null;

  document.form.items.size.length = 0
  document.form.items.options.length = 0

  if (isie > 1) ContractSection(t7)

 }


if (n > 1)
 {
  for(i = document.form.items2.length - 1; i >= 0; i--)

			document.form.items2.options[i]	= null;

  document.form.items2.size.length = 0
  document.form.items2.options.length = 0

  if (isie > 1) ContractSection(t8)

 }

if (n > 2)
 {


  for(i = document.form.items3.length - 1; i >= 0; i--)

			document.form.items3.options[i]	= null;

  document.form.items3.size.length = 0
  document.form.items3.options.length = 0

  if (isie > 1) ContractSection(t9)

 }



cleard() ;
numb = ""

if (line.substr(0, 1) == "-")
  {
	document.form.additem.value = "-- Please select an item from the menu above --   " ;
	return ;
  }



if (document.form.hn.value == "1")
  {
	  k = line.indexOf(" ") ;

	  numb = line.substr(0, k) + " "

	  line = line.substr(k+1, line.length) ;


  }


f = ":;"
k = line.indexOf(f)

var des = ""

if (k > 4 )
  {
	  des = line.substring(k+2, line.length)
	  line = line.substring(0, k)
  }


f = "---"
k = line.indexOf(f)

pline = line.substr(k+3, line.length)

var itemline = ""

k2 = k




//ITEM3

k = pline.indexOf("++3")

if (k >= 0)
 {

    if (isie > 1) ExpandSection(t9)

	itemline = pline.substr(k+3, pline.length)
	pline = pline.substr(0, k)



	k = itemline.indexOf(":")
   ilabel3 = itemline.substr(0, k)
   itemline = itemline.substr(k+1, itemline.length )

   fritems3 = 0 ;
   minitems3 = 0 ;
   k = itemline.indexOf("<")

   if (k < 0)
     {

		 k = itemline.indexOf("=")
		 if (k >= 0) minitems3 = 1

     }


   if (k >=0)
    {
		maxitems3 = parseInt(itemline.substr(k+1, 4))
		fritems3 = maxitems3 ;
		peritem3 = 0 ;
		iprice3 = 0 ;

		if (minitems3 == 1) minitems3 = maxitems3 ;
	 }


	k = itemline.indexOf(document.form.currency.value)

	if (k >= 0)
	 {
    	maxitems3 = 100
		if (k >= 0)
        {
			iprice3 = parseFloat(itemline.substr(k+1, 8))
			//k = document.form.size.value.indexOf(form.currency.value)
			//baseprice = parseFloat(form.size.value.substr(k+1, form.size.value.length))
			//alert(form.size.value)

		 }

 	  }



	k = itemline.indexOf(":")
   itemline = itemline.substr(k+1, itemline.length)

 f = ","
 k = itemline.indexOf(f)
 found = 0


while (k > 1)
{

   p = itemline.substr(0, k)

   while (p.substr(0,1) == " ") p = p.substr(1, p.length) ;

   if (found == 0)
    {
      found = 1
      if (peritem3 > 0)
       {

			a = new ToFmt(peritem3)
          perf=a.fmtF(4,3);


          p3 = "- " + ilabel3 + " -"
       }
      else
       {
          p3 = "- " + ilabel3 + " -"
       }

       var newopt = new Option(p3,p3)
	   //document.form.items3.add(newopt, document.form.items3.length)



	   document.form.items3.options[document.form.items3.options.length] = newopt ;
    }


	var newopt = new Option(p,p)
	//document.form.items3.add(newopt, document.form.items3.length)
	document.form.items3.options[document.form.items3.options.length] = newopt ;

   itemline = itemline.substr(k+1, itemline.length) ;

   k = itemline.indexOf(f)


   if (k < 1) {


			var newopt = new Option(itemline,itemline)
			//document.form.items3.add(newopt, document.form.items3.length)
			document.form.items3.options[document.form.items3.options.length] = newopt ;
   }

}


 }
else   //no items
  {

	  n = parseInt(document.form.nadds.value)

	  if (n > 2)
	    {

			var newopt = new Option("--- N/A ---", "--- N/A ---")
			document.form.items3.options[document.form.items3.options.length] = newopt ;
	}

   }







//ITEM2

k = pline.indexOf("++2")

if (k >= 0)
 {

    if (isie > 1) ExpandSection(t8)

	itemline = pline.substr(k+3, pline.length)
	pline = pline.substr(0, k)



	k = itemline.indexOf(":")
   ilabel2 = itemline.substr(0, k)
   itemline = itemline.substr(k+1, itemline.length )

   fritems2 = 0 ;
   minitems2 = 0 ;
   k = itemline.indexOf("<")

   if (k < 0)
     {

		 k = itemline.indexOf("=")
		 if (k >= 0) minitems2 = 1

     }


   if (k >=0)
    {
		maxitems2 = parseInt(itemline.substr(k+1, 4))
		fritems2 = maxitems2 ;
		peritem2 = 0 ;
		iprice2 = 0 ;

		if (minitems2 == 1) minitems2 = maxitems2 ;
	 }


	k = itemline.indexOf(document.form.currency.value)

	//alert("k" + k)

	if (k >= 0)
	 {
    	maxitems2 = 100
		if (k >= 0)
        {
			iprice2 = parseFloat(itemline.substr(k+1, 8))
			//k = document.form.size.value.indexOf(form.currency.value)
			//baseprice = parseFloat(form.size.value.substr(k+1, form.size.value.length))
			//alert(form.size.value)

		 }

 	  }



	k = itemline.indexOf(":")
   itemline = itemline.substr(k+1, itemline.length)

 f = ","
 k = itemline.indexOf(f)
 found = 0


while (k > 1)
{

	p = itemline.substr(0, k)

	while (p.substr(0,1) == " ") p = p.substr(1, p.length) ;


   if (found == 0)
    {
      found = 1
      if (peritem2 > 0)
       {

			a = new ToFmt(peritem2)
          perf=a.fmtF(4,2);


          p2 = "- " + ilabel2 + " -"
       }
      else
       {
          p2 = "- " + ilabel2 + " -"
       }

       var newopt = new Option(p2,p2)
	   //document.form.items2.add(newopt, document.form.items2.length)

	   document.form.items2.options[document.form.items2.options.length] = newopt ;
    }


	var newopt = new Option(p,p)
	//document.form.items2.add(newopt, document.form.items2.length)
	document.form.items2.options[document.form.items2.options.length] = newopt ;

   itemline = itemline.substr(k+1, itemline.length) ;

   k = itemline.indexOf(f)


   if (k < 1) {

			var newopt = new Option(itemline,itemline)
			//document.form.items2.add(newopt, document.form.items2.length)
			document.form.items2.options[document.form.items2.options.length] = newopt ;
   }

}


 }
else   //no items
  {


	  	  n = parseInt(document.form.nadds.value)

	  	  if (n > 1)
            {

			var newopt = new Option("--- N/A ---", "--- N/A ---")
			//document.form.items2.add(newopt, document.form.items2.length)
			document.form.items2.options[document.form.items2.options.length] = newopt ;
		   }

   }





//ITEM1



k = pline.indexOf("++")

if (k >= 0)
 {

    if (isie > 1) ExpandSection(t7)

	itemline = pline.substr(k+2, pline.length)
	pline = pline.substr(0, k)



	k = itemline.indexOf(":")
   ilabel = itemline.substr(0, k)
   itemline = itemline.substr(k+1, itemline.length )

   fritems = 0 ;
   minitems = 0 ;
   k = itemline.indexOf("<")

   if (k < 0)
     {

		 k = itemline.indexOf("=")
		 if (k >= 0) minitems = 1

     }


   if (k >=0)
    {
		maxitems = parseInt(itemline.substr(k+1, 4))
		fritems = maxitems ;
		peritem = 0 ;
		iprice = 0 ;

		if (minitems == 1) minitems = maxitems ;
	 }


	k = itemline.indexOf(document.form.currency.value)

	if (k >= 0)
	 {
    	maxitems = 100
		if (k >= 0)
        {
			iprice = parseFloat(itemline.substr(k+1, 8))
			//k = document.form.size.value.indexOf(form.currency.value)
			//baseprice = parseFloat(form.size.value.substr(k+1, form.size.value.length))
			//alert(form.size.value)

		 }

 	  }



	k = itemline.indexOf(":")
   itemline = itemline.substr(k+1, itemline.length)

 f = ","
 k = itemline.indexOf(f)
 found = 0


while (k > 1)
{

	p = itemline.substr(0, k)

	while (p.substr(0,1) == " ") p = p.substr(1, p.length) ;


   if (found == 0)
    {
      found = 1
      if (peritem > 0)
       {

			a = new ToFmt(peritem)
          perf=a.fmtF(4,2);


          p2 = "- " + ilabel + " -"
       }
      else
       {
          p2 = "- " + ilabel + " -"
       }

       var newopt = new Option(p2,p2)
	   //document.form.items.add(newopt, document.form.items.length)

	   document.form.items.options[document.form.items.options.length] = newopt ;
    }


	var newopt = new Option(p,p)
	//document.form.items.add(newopt, document.form.items.length)
	document.form.items.options[document.form.items.options.length] = newopt ;

   itemline = itemline.substr(k+1, itemline.length) ;

   k = itemline.indexOf(f)


   if (k < 1) {

			var newopt = new Option(itemline,itemline)
			//document.form.items.add(newopt, document.form.items.length)
			document.form.items.options[document.form.items.options.length] = newopt ;
   }

}


 }
else   //no items
  {

    	  n = parseInt(document.form.nadds.value)

		  if (n > 0)
		   {

			var newopt = new Option("--- N/A ---", "--- N/A ---")
			//document.form.items.add(newopt, document.form.items.length)
			document.form.items.options[document.form.items.options.length] = newopt ;
	   }

   }







document.form.additem.value = line.substr(0, k2-1)

f = "/" ;

var x = ""

k = pline.indexOf(f)
var found = 0


while (k > 1)
{

	p = pline.substr(0, k)

   if (found == 0)
    {
      found = 1
      p2 = document.form.selsize.value
      var newopt = new Option(p2,p2)
	   //document.form.size.add(newopt, document.form.size.length)
	   document.form.size.options[document.form.size.options.length] = newopt ;
    }

    if (p.substr(0,1) == " ") p = p.substr(1,p.length)

	var newopt = new Option(p,p)
	//document.form.size.add(newopt, document.form.size.length)
	document.form.size.options[document.form.size.options.length] = newopt ;

	x = x + "," + p ;
   pline = pline.substr(k+1, pline.length) ;

   k = pline.indexOf(f)


   if (k < 1) {

			var newopt = new Option(pline,pline)
			//document.form.size.add(newopt, document.form.size.length)
			document.form.size.options[document.form.size.options.length] = newopt ;
   }

}




if (found == 0)
 {


			var newopt = new Option(pline,pline)


			//document.form.size.add(newopt, 0)

			document.form.size.options[document.form.size.options.length] = newopt ;



 }


if (des.length > 5)
 {

  document.getElementById("t1").innerHTML = "<b>" + document.form.additem.value + "</b>"
  document.getElementById("t2").innerHTML = "<p>" + des + "</p>"

}




return ;

}

function doadd()
{



if (document.form.size.selectedIndex >= document.form.size.options.length)

	document.form.size.selectedIndex = 0 ;

if (document.form.size.selectedIndex < 0)

	document.form.size.selectedIndex = 0 ;



if (document.form.additem.value.substr(0, 1) == "-")
  {
	return ;
  }



var q = parseInt(document.form.qty.value)

 if (q < 1)
  {

	alert("Please enter a valid quantity")
    return ;

  }



 if (document.form.size.value.substr(0, 1) == "-")
  {
	alert(document.form.sizeprompt.value)
	document.form.size.focus() ;
	return ;
  }


 if (numitems < minitems)
   {

	  alert(ilabel) ;
	  document.form.items.focus() ;
	  return ;
   }


 if (numitems2 < minitems2)
   {

	  alert(ilabel2) ;
	  document.form.items2.focus() ;
	  return ;
   }

 if (numitems3 < minitems3)
   {

	  alert(ilabel3) ;
	  document.form.items3.focus() ;
	  return ;
   }


   var v = "" ;

   if (q == 1)
     {
      p = document.form.additem.value + " --- " + document.form.size.value
      v = numb + p ;
	 }
   else
     {
      p = document.form.additem.value + " --- " + document.form.qty.value + " @ " + document.form.size.value
      v = numb + p
     }


   var newopt = new Option(p,v)
   //document.form.order.add(newopt, document.form.size.length)
   document.form.order.options[document.form.order.options.length] = newopt ;

   document.form.order.selectedIndex = document.form.order.options.length-1



	k = document.form.size.value.indexOf(document.form.currency.value)

   if (k >=0)
     {
        amt = 0
        p = document.form.size.value.substr(k+1, document.form.size.value.length )

		 amt = parseFloat(p)
        amt = amt * q
        tax = parseFloat(document.form.taxrate.value)

   		 subtotal = subtotal + amt
         taxtotal = subtotal * tax * .01
		 total = subtotal + taxtotal

        var a = new ToFmt(taxtotal)
        taxtotalf=a.fmtF(8,2);


		 a = new ToFmt(subtotal)
        subf=a.fmtF(8,2);

		 p = "Subtotal: " + document.form.currency.value + subf
		 var newopt = new Option(p,p)
  		 document.form.totals.options[0]	= newopt

		 p = "Tax:          " + document.form.currency.value + taxtotalf
		 newopt = new Option(p,p)
  		 document.form.totals.options[1]	= newopt


         n = 3

         var d = 0 ;


		 if (document.form.dodel.value == "1")
		  {
		 		n = 4 ;


		 		if (document.form.deliver.checked)
		 		  {

 							if (parseFloat(form.delcharge.value) < 1) d = subtotal * parseFloat(form.delcharge.value) ;
							else d = parseFloat(form.delcharge.value) ;

							d2 = parseFloat(document.form.delmin.value)


							//alert(subtotal)
							if  (subtotal >= d2)
							  {
								d = 0 ;
								//alert(d)
						      }

							a = new ToFmt(d)
        					df=a.fmtF(8,2);


        					p = "Delivery:  " + document.form.currency.value + df
							var newopt = new Option(p,p)
							document.form.totals.options[2]	= newopt


			      }

	      }


	     total = total + d
	     a = new ToFmt(total)
		 totalf=a.fmtF(8,2);


 		 p = "Total:        " + document.form.currency.value + totalf
		 newopt = new Option(p,p)



  		 document.form.totals.options[n] = newopt



        //alert (subf + "+" + taxtotalf + "=" + totalf)



	  }

   	document.form.additem.value = "-- Please select an item from the menu above --   " ;
   document.form.qty.value = "1"
   numitems = 0

for(i = document.form.size.length - 1; i >= 0; i--)

			document.form.size.options[i]	= null;

for(i = document.form.items.length - 1; i >= 0; i--)

			document.form.items.options[i]	= null;

if (isie > 1) ContractSection(t7)

document.form.menu.selectedIndex = -1 ;
cleard()
numb = ""
minitems = 0 ;

}


//SUBITEM1

function addsubitem()
{
	if (document.form.items.selectedIndex < 0) return ;

if (document.form.items.value.substr(0, 1) == "-")
  {
	return ;
  }



	if (numitems >= maxitems)
     {
	   alert("You have already added the maximum number of items.")
       return ;
     }

    peritem = 0 ;
    if (numitems >= fritems) peritem = iprice ;

	numitems++ ;
	document.form.additem.value = document.form.additem.value + " + " + document.form.items.value

	if (peritem > 0)
     {

			for(i = document.form.size.length - 1; i >= 0; i--)
            {


					k = document.form.size.options[i].value.indexOf(document.form.currency.value)

   					if (k >=0)
     				{
        				amt = 0
        				p = document.form.size.options[i].value.substr(k+1, document.form.size.options[i].value.length )
		 				amt = parseFloat(p)

						amt = amt + peritem ;

						a = new ToFmt(amt)
        				amtf=a.fmtF(5,2);


						newval = document.form.size.options[i].value.substr(0, k+1) + amtf

						//alert(newval)

						newopt = new Option(newval,newval)
  		 				document.form.size.options[i]	= newopt

           		 }

				}


     }

}






function removesubitem()
{
	if (document.form.items.selectedIndex < 0) return ;

if (document.form.items.value.substr(0, 1) == "-")
  {
	return ;
  }

   if (numitems <=0) return ;

	f = "+ " + document.form.items.value


	k = document.form.additem.value.indexOf(f)

	if (k < 1) return ;

   document.form.additem.value = document.form.additem.value.substr(0, k-1) + document.form.additem.value.substr(k + f.length, 1000)

	numitems-- ;

	peritem = 0 ;
    if (numitems >= fritems) peritem = iprice ;


	if (peritem > 0)
     {

			for(i = document.form.size.length - 1; i >= 0; i--)
            {


					k = document.form.size.options[i].value.indexOf(document.form.currency.value)

   					if (k >=0)
     				{
        				amt = 0
        				p = document.form.size.options[i].value.substr(k+1, document.form.size.options[i].value.length )
		 				amt = parseFloat(p)

						amt = amt - peritem ;

						a = new ToFmt(amt)
        				amtf=a.fmtF(5,2);


						newval = document.form.size.options[i].value.substr(0, k+1) + amtf


						newopt = new Option(newval,newval)
  		 				document.form.size.options[i]	= newopt

           		 }

				}


     }

}



//SUBITEM2

function addsubitem2()
{
	if (document.form.items2.selectedIndex < 0) return ;

if (document.form.items2.value.substr(0, 1) == "-")
  {
	return ;
  }

	if (numitems2 >= maxitems2)
     {
	   alert("You have already added the maximum number of items.")
       return ;
     }

    peritem2 = 0 ;
    if (numitems2 >= fritems2) peritem2 = iprice2 ;

	numitems2++ ;
	document.form.additem.value = document.form.additem.value + " + " + document.form.items2.value

	if (peritem2 > 0)
     {

			for(i = document.form.size.length - 1; i >= 0; i--)
            {


					k = document.form.size.options[i].value.indexOf(document.form.currency.value)

   					if (k >=0)
     				{
        				amt = 0
        				p = document.form.size.options[i].value.substr(k+1, document.form.size.options[i].value.length )
		 				amt = parseFloat(p)

						amt = amt + peritem2 ;

						a = new ToFmt(amt)
        				amtf=a.fmtF(5,2);


						newval = document.form.size.options[i].value.substr(0, k+1) + amtf

						//alert(newval)

						newopt = new Option(newval,newval)
  		 				document.form.size.options[i]	= newopt

           		 }

				}


     }

}






function removesubitem2()
{
	if (document.form.items2.selectedIndex < 0) return ;

if (document.form.items2.value.substr(0, 1) == "-")
  {
	return ;
  }

   if (numitems2 <=0) return ;

	f = "+ " + document.form.items2.value


	k = document.form.additem.value.indexOf(f)

	if (k < 1) return ;

   document.form.additem.value = document.form.additem.value.substr(0, k-1) + document.form.additem.value.substr(k + f.length, 1000)

	numitems2-- ;

	peritem2 = 0 ;
    if (numitems2 >= fritems2) peritem2 = iprice2 ;


	if (peritem2 > 0)
     {

			for(i = document.form.size.length - 1; i >= 0; i--)
            {


					k = document.form.size.options[i].value.indexOf(document.form.currency.value)

   					if (k >=0)
     				{
        				amt = 0
        				p = document.form.size.options[i].value.substr(k+1, document.form.size.options[i].value.length )
		 				amt = parseFloat(p)

						amt = amt - peritem2 ;

						a = new ToFmt(amt)
        				amtf=a.fmtF(5,2);


						newval = document.form.size.options[i].value.substr(0, k+1) + amtf


						newopt = new Option(newval,newval)
  		 				document.form.size.options[i]	= newopt

           		 }

				}


     }

}






//SUBITEM3

function addsubitem3()
{
	if (document.form.items3.selectedIndex < 0) return ;

if (document.form.items3.value.substr(0, 1) == "-")
  {
	return ;
  }



	if (numitems3 >= maxitems3)
     {
	   alert("You have already added the maximum number of items.")
       return ;
     }

    peritem3 = 0 ;
    if (numitems3 >= fritems3) peritem3 = iprice3 ;

	numitems3++ ;
	document.form.additem.value = document.form.additem.value + " + " + document.form.items3.value

	if (peritem3 > 0)
     {

			for(i = document.form.size.length - 1; i >= 0; i--)
            {


					k = document.form.size.options[i].value.indexOf(document.form.currency.value)

   					if (k >=0)
     				{
        				amt = 0
        				p = document.form.size.options[i].value.substr(k+1, document.form.size.options[i].value.length )
		 				amt = parseFloat(p)

						amt = amt + peritem3 ;

						a = new ToFmt(amt)
        				amtf=a.fmtF(5,2);


						newval = document.form.size.options[i].value.substr(0, k+1) + amtf

						//alert(newval)

						newopt = new Option(newval,newval)
  		 				document.form.size.options[i]	= newopt

           		 }

				}


     }

}






function removesubitem3()
{
	if (document.form.items3.selectedIndex < 0) return ;

if (document.form.items3.value.substr(0, 1) == "-")
  {
	return ;
  }

   if (numitems3 <=0) return ;

	f = "+ " + document.form.items3.value


	k = document.form.additem.value.indexOf(f)

	if (k < 1) return ;

   document.form.additem.value = document.form.additem.value.substr(0, k-1) + document.form.additem.value.substr(k + f.length, 1000)

	numitems3-- ;

	peritem3 = 0 ;
    if (numitems3 >= fritems3) peritem3 = iprice3 ;


	if (peritem3 > 0)
     {

			for(i = document.form.size.length - 1; i >= 0; i--)
            {


					k = document.form.size.options[i].value.indexOf(document.form.currency.value)

   					if (k >=0)
     				{
        				amt = 0
        				p = document.form.size.options[i].value.substr(k+1, document.form.size.options[i].value.length )
		 				amt = parseFloat(p)

						amt = amt - peritem3 ;

						a = new ToFmt(amt)
        				amtf=a.fmtF(5,2);


						newval = document.form.size.options[i].value.substr(0, k+1) + amtf


						newopt = new Option(newval,newval)
  		 				document.form.size.options[i]	= newopt

           		 }

				}


     }

}








//REMOVE ENTIRE ITEM

function removeitem()
{

if (document.form.order.selectedIndex < 0)
 {
	return ;
 }

if (document.form.order.value.substr(0, 1) == "-")
  {
	return ;
  }

k = document.form.order.value.indexOf("---")

if (k > 0)
  {
	var amt ;
    p = document.form.order.value.substr(k+4, document.form.order.value.length )

	k = p.indexOf("@")



   if (k > 0)
    {

		qs = p.substr(0, k-1)
       ps = p.substr(k+1, p.length)

		k = ps.indexOf(document.form.currency.value)

   		if (k >= 0)
        {
          amt = 0
          p = ps.substr(k+1, ps.length )

		   amt = parseFloat(p)
		   q = parseFloat(qs)

			amt = amt * q
			alert(amt)

        }

    }
   else
    {
		ps = p
		k = ps.indexOf(document.form.currency.value)

   		if (k >= 0)
        {
          amt = 0
          p = ps.substr(k+1, ps.length )

		   amt = parseFloat(p)

			amt = amt

        }

    }


        tax = parseFloat(document.form.taxrate.value)

   		subtotal = subtotal - amt

   		if (subtotal <= .01) subtotal = 0



        taxtotal = subtotal * tax * .01
		 total = subtotal + taxtotal

        var a = new ToFmt(taxtotal)
        taxtotalf=a.fmtF(8,2);

		 a = new ToFmt(total)
        totalf=a.fmtF(8,2);

		 a = new ToFmt(subtotal)
        subf=a.fmtF(8,2);

		 p = "Subtotal: " + document.form.currency.value + subf
		 var newopt = new Option(p,p)
  		 document.form.totals.options[0]	= newopt

		 p = "Tax:          " + document.form.currency.value + taxtotalf
		 newopt = new Option(p,p)
  		 document.form.totals.options[1]	= newopt

 		 p = "Total:        " + document.form.currency.value + totalf
		 newopt = new Option(p,p)

         n = 3

         var d = 0 ;

		 if (document.form.dodel.value == "1")
		  {
		 		n = 4 ;


		 		if (document.form.deliver.checked)
		 		  {

 							if (parseFloat(form.delcharge.value) < 1) d = subtotal * parseFloat(form.delcharge.value) ;
							else d = parseFloat(form.delcharge.value) ;

							d2 = parseFloat(document.form.delmin.value)


							//alert(subtotal)
							if  (subtotal >= d2)
							  {
								d = 0 ;
								//alert(d)
						      }

							a = new ToFmt(d)
        					df=a.fmtF(8,2);


        					p = "Delivery:  " + document.form.currency.value + df
							var newopt = new Option(p,p)
							document.form.totals.options[2]	= newopt


			      }

	      }


	     total = total + d
	     a = new ToFmt(total)
		 totalf=a.fmtF(8,2);


 		 p = "Total:        " + document.form.currency.value + totalf
		 newopt = new Option(p,p)



  		 document.form.totals.options[n] = newopt



 }


	document.form.order.options[document.form.order.selectedIndex] = null ;

}




