/*
 * public class Alert
 *  Author: Matthew Copeland
 *  Versions:
 *   v1.0 (Nov 10, 2001)
 */

Alert . TIME = 5000 ;

/*
 * private static void kill ( )
 * Since: v1.0
 */

Alert . kill = function ( )
{ status = '' ;
} ;

/*
 * public Alert ( String message )
 * Since: v1.0
 */

function Alert ( message )
{ this . message = message ;
  status = message ;
  setTimeout ( 'Alert . kill ( ) ;' , Alert . TIME ) ;
  alert ( message ) ;
}

/*
 * public class Format
 * Author: Matthew Copeland
 * Versions:
 *  v1.0 (Nov 14, 2001)
 */

/*
 * public static String dollars ( float number )
 * Since: v1.0
 */

Format . dollars = function ( number )
{ number = Math . round ( number * 100 ) ;
  number = number . toString ( ) ;
  while ( number . length < 3 )
	{ number = '0' . concat ( number ) ;
	}
  var decimal = number . length - 2 ;
  number = number . substring ( 0 , decimal ) . concat ( '.' , number . substring ( decimal , number . length ) ) ;
  while ( ( decimal -= 3 ) > 0 )
	{ number = number . substring ( 0 , decimal ) . concat ( ',' , number . substring ( decimal , number . length ) ) ;
	}
  return '$' . concat ( number ) ;
} ;

/*
 * public static String pounds ( float number )
 * Since: v1.0
 */

Format . pounds = function ( number )
{ number = Math . round ( number * 10 ) ;
  number = number . toString ( ) ;
  while ( number . length < 2 )
	{ number = '0' . concat ( number ) ;
	}
  var decimal = number . length - 1 ;
  number = number . substring ( 0 , decimal ) . concat ( '.' , number . substring ( decimal , number . length ) ) ;
  while ( ( decimal -= 3 ) > 0 )
	{ number = number . substring ( 0 , decimal ) . concat ( ',' , number . substring ( decimal , number . length ) ) ;
	}
  return number . concat ( 'lbs' ) ;
} ;

/*
 * public Format ( )
 * Since: v1.0
 */

function Format ( )
{ this . dollars = Format . dollars ;
  this . pounds = Format . pounds ;
}

/*
 * public class HTMLBox
 *  Create a browser specific document node
 *  with DHTML capabilities.
 * Author: Matthew Copeland
 * Versions:
 *   v1.0 (Nov 2, 2001)
 */

/*
 * private static int IE , NN , XX
 *  Various browser document object models.
 * Since: v1.0
 */

HTMLBox . IE = 1 ;
HTMLBox . NN = 2 ;
HTMLBox . XX = 3 ;
HTMLBox . MZ = 4 ;

/*
 * private static int uniqueID
 * Since: v1.0
 */

HTMLBox . uniqueID = 0 ;

/*
 * private static string getUniqueID ( )
 *  Return a string unique
 *  to this HTMLBox object.
 * Since: v1.0
 */

HTMLBox . getUniqueID = function ( )
{ return 'ID' + HTMLBox . uniqueID ++ ;
};

/*
 * public HTMLBox ( int width , int height )
 * Since: v1.0
 */

function HTMLBox ( width , height )
{ this . width = width ;
  this . height = height ;
  this . DOM = document . getElementById ? HTMLBox . MZ : document . all ? HTMLBox . IE : document . layers ? HTMLBox . NN : HTMLBox . XX ;
  this . ID = HTMLBox . getUniqueID ( ) ;
  this . isWritten = false ;

/*
 * public void write ( )
 *  Write an identifiable
 *  node to the document.
 *  Since: v1.0
 */

  this . write = function ( )
	{ if ( this . isWritten ) { return ; }
	  var HTML = '' ;
	  if ( this . DOM == HTMLBox . MZ || this . DOM == HTMLBox . IE )
		{ HTML = '<div id="' + this . ID + '" style="width:' + this . width + 'px;height:' + this . height + 'px;"></div>' ;
		}
	  else if ( this . DOM == HTMLBox . NN )
		{ HTML = '<layer name="' + this . ID + '" width="' + this . width + '" height="' + this . height + '"></layer>' ;
		}
	  else
		{ HTML = 'Incompatible Browser' ;
		}
	  document . write ( HTML ) ;
	  this . isWritten = true ;
	};

/*
 * public void put ( string HTML )
 *  If the document node exists,
 *  replace the node's HTML.
 *  Since: v1.0
 */

  this . put = function ( HTML )
	{ if ( this . DOM == HTMLBox . MZ )
		{ if ( document . getElementById ( this . ID ) )
			{ document . getElementById ( this . ID ) . innerHTML = HTML ;
			}
		}
	  else if ( this . DOM == HTMLBox . IE )
		{ if ( document . all [ this . ID ] )
			{ document . all [ this . ID ] . innerHTML = HTML ;
			}
		}
	  else if ( this . DOM == HTMLBox . NN )
		{ if ( document . layers [ this . ID ] )
			{ document . layers [ this . ID ] . document . write ( HTML ) ;
			}
		}
	};
}

/*
 * public class Item
 * Author: Matthew Copeland
 * Versions:
 *  v2.0 (Nov 16, 2001)
 */

/*
 * public Item ( String name [ , float price [ , float weight [ , String smallImageSource [ , String largeImageSource [ , String description [ , String [ ] images ] ] ] ] ] ] )
 */

function Item ( )
{ var a = Item . arguments ;
  this . name = a [ 0 ] ;
  this . price = a [ 1 ] ? a [ 1 ] : 0.00 ;
  this . weight = a [ 2 ] ? a [ 2 ] : 0.0 ;
  this . smallImageSource = a [ 3 ] ? a [ 3 ] : 'noSmallImage.gif' ;
  this . largeImageSource = a [ 4 ] ? a [ 4 ] : 'noLargeImage.gif' ;
  this . description = a [ 5 ] ? a [ 5 ] : '' ;
  this . images = a [ 6 ] ? a [ 6 ] : [ ] ;
  this . storeID = 0 ;
  this . attributes = [ ] ;
  this . addAttribute = function ( attribute )
	{ this . attributes [ this . attributes . length ] = attribute ;
	} ;
  this . getAttributesHTML = function ( )
	{ var HTML = [ ] ;
	  for ( var x = 0 ; x < this . attributes . length ; x ++ )
		{ HTML [ x ] = this . attributes [ x ] . getHTML ( ) ;
		}
	  return HTML ;
	} ;
  this . getValues = function ( root )
	{ var values = [ ] ;
	  for ( var x = 0 ; x < this . attributes . length ; x ++ )
		{ values [ x ] = this . attributes [ x ] . getValues ( root ) ;
		}
	  return values ;
	} ;
  this . setValues = function ( values )
	{ for ( var x = 0 ; x < this . attributes . length ; x ++ )
		{ this . attributes [ x ] . setValues ( values [ x ] ) ;
		}
	} ;
  this . getPrice = function ( values )
	{ var price = this . price ;
	  for ( var x = 0 ; x < this . attributes . length ; x ++ )
		{ price += this . attributes [ x ] . getPrice ( values [ x ] ) ;
		}
	  return price ;	
	} ;
  this . getWeight = function ( values )
	{ var weight = this . weight ;
	  for ( var x = 0 ; x < this . attributes . length ; x ++ )
		{ weight += this . attributes [ x ] . getWeight ( values [ x ] ) ;
		}
	  return weight ;	
	} ;
  this . getDescription = function ( values )
	{ var description = this . name ;
	  for ( var x = 0 ; x < this . attributes . length ; x ++ )
		{ description += this . attributes [ x ] . getDescription ( values [ x ] ) ;
		}
	  return description ;
	} ;
}

/*
 * public interface Attribute
 * public String getHTML ( )
 * public String [ ] getValues ( String root )
 * public void setValues ( String root , String [ ] values )
 * public float getPrice ( String [ ] values )
 * public float getWeight ( String [ ] values )
 * public String getDescription ( String [ ] values )
 */

/*
 * public Text ( String label [ , int length [ , String value [ , Strin name [ , RegExp regExp [ , float price [ , float weight ] ] ] ] ] ] )
 */

function Text ( )
{ var a = Text . arguments ;
  this . label = a [ 0 ] ;
  this . length = a [ 1 ] > 0 ? a [ 1 ] : 255 ;
  this . value = a [ 2 ] ? a [ 2 ] : '' ;
  this . name = a [ 3 ] ? a [ 3 ] : a [ 0 ] ;
  this . regExp = a [ 4 ] ? a [ 4 ] : /^[\w\W]*$/ ;
  this . price = a [ 5 ] ? a [ 5 ] : 0 ; // per character
  this . weight = a [ 6 ] ? a [ 6 ] : 0 ; // per character

  this . getHTML = function ( )
	{ return this . label + ': <input name="' + this . name + '" type="text" maxlength="' + this . length + '" value="' + this . value + '" />' ; 
	} ;
  this . getValues = function ( root )
	{ var v = root [ this . name ] . value ;
	  if ( v . match ( this . regExp ) == null )
		{ new Alert ( 'The text field "' + this . label + '" is not properly formatted.  Please try again.' ) ;
		  return [ ] ;
		}
	  return [ v ] ;
	} ;
  this . setValues = function ( values )
	{ this . value = values [ 0 ] ;
	} ;
  this . getPrice = function ( values )
	{ return this . price * values [ 0 ] . length ;
	} ;
  this . getWeight = function ( values )
	{ return this . weight * values [ 0 ] . length ;
	} ;
  this . getDescription = function ( values )
	{ return values [ 0 ] ? '[' + this . name + ':' + values [ 0 ] + ']' : '' ;
	} ;
}

/*
 * public Textarea ( String label [ , int length [ , String value [ , String name [ , RegExp regExp [ , float price [ , float weight ] ] ] ] ] ] )
 */

function Textarea ( )
{ var a = Textarea . arguments ;
  this . label = a [ 0 ] ;
  this . length = a [ 1 ] > 0 ? a [ 1 ] : 65536 ;
  this . value = a [ 2 ] ? a [ 2 ] : '' ;
  this . name = a [ 3 ] ? a [ 3 ] : a [ 0 ] ;
  this . regExp = a [ 4 ] ? a [ 4 ] : /^[\w\W]*$/ ;
  this . price = a [ 5 ] ? a [ 5 ] : 0 ; // per character
  this . weight = a [ 6 ] ? a [ 6 ] : 0 ; // per character

  this . getHTML = function ( )
	{ return this . label + ': <textarea name="' + this . name + '">' + this . value + '</textarea>' ;
	} ;
  this . getValues = function ( root )
	{ var v = root [ this . name ] . value ;
	  if ( v . match ( this . regExp ) == null )
		{ new Alert ( 'The text field "' + this . label + '" is not properly formatted.  Please try again.' ) ;
		  return [ ] ;
		}
	  return [ v . substring ( 0 , this . length > v . length ? this . length : v . length ) ] ;
	} ;
  this . setValues = function ( root , values )
	{ this . value = values [ 0 ] ;
	} ;
  this . getPrice = function ( values )
	{ return this . price * values [ 0 ] . length ;
	} ;
  this . getWeight = function ( values )
	{ return this . weight * values [ 0 ] . length ;
	} ;
  this . getDescription = function ( values )
	{ return values [ 0 ] ? '[' + this . name + ':' + values [ 0 ] + ']' : '' ;
	} ;
}

/*
 * public Select ( String label , Option [ ] options [ , int length [ , String name ] ] )
 */

function Select ( )
{ var a = Select . arguments ;
  this . label = a [ 0 ] ;
  this . options = a [ 1 ] ;
  this . length = a [ 2 ] > 1 ? a [ 2 ] : 1 ;
  this . name = a [ 3 ] ? a [ 3 ] : a [ 0 ] ;

  this . getHTML = function ( )
	{ var HTML = this . label + ': <select name="' + this . name + '"' + ( this . length > 1 ? ' multiple="multiple"' : '' ) + '>' ;
	  var imagesHTML = '' ;
	  for ( var x = 0 ; x < this . options . length ; x ++ )
		{ HTML += '<option value="' + this . options [ x ] . value + '"' + ( this . options [ x ] . selected ? ' selected="selected"' : '' ) + '>' + this . options [ x ] . label + '</option>' ;
		  for ( var y = 0 ; y < this . options [ x ] . images . length ; y ++ )
			{ imagesHTML += '<br />' + this . options [ x ] . label + '<br /><img src="' + this . options [ x ] . images [ y ] + '" alt="' + this . options [ x ] . label + '" />' ;
			}
		}
	  return HTML + '</select>' + imagesHTML ;
	} ;
  this . getValues = function ( root )
	{ var length = 0 ;
	  var values = [ ] ;
	  for ( var x = 0 ; x < this . options . length ; x ++ )
		{ var s = root [ this . name ] . options [ x ] . selected ;
		  values [ x ] = s && length < this . length ? 1 : 0 ;
		  if ( s ) { length ++ ; }
		}
	  return values ;
	} ;
  this . setValues = function ( values )
	{ for ( var x = 0 ; x < this . options . length ; x ++ )
		{ this . options [ x ] . selected = values [ x ] ? true : false ;
		}
	} ;
  this . getPrice = function ( values )
	{ var price = 0 ;
	  for ( var x = 0 ; x < this . options . length ; x ++ )
		{ if ( values [ x ] )
			{ price += this . options [ x ] . price ;
			}
		}
	  return price ;
	} ;
  this . getWeight = function ( values )
	{ var weight = 0 ;
	  for ( var x = 0 ; x < this . options . length ; x ++ )
		{ if ( values [ x ] )
			{ weight += this . options [ x ] . weight ;
			}
		}
	  return weight ;
	} ;

  this . getDescription = function ( values )
	{ var description = '' ;
	  for ( var x = 0 ; x < this . options . length ; x ++ )
		{ if ( values [ x ] )
			{ description += '[' + this . name + ':' + this . options [ x ] . value + ']' ;
			}
		}
	  return description ;
	} ;
}

/*
 * public Option ( String label [ , float price [ , float weight [ , boolean selected [ , String [ ] images [ , value ] ] ] ] ] )
 */

function Option ( )
{ var a = Option . arguments ;
  this . label = a [ 0 ] ;
  this . price = a [ 1 ] ? a [ 1 ] : 0.00 ;
  this . weight = a [ 2 ] ? a [ 2 ] : 0.0 ;
  this . selected = a [ 3 ] ? true : false ;
  this . images = a [ 4 ] ? a [ 4 ] : [ ] ;
  this . value = a [ 5 ] ? a [ 5 ] : a [ 0 ] ;
}

/*
 * public class Report
 * Author: Matthew Copeland
 * Versions:
 *  v1.0 (Nov 14, 2001)
 */

function Report ( store )
{ this . store = store ;
  this . price = 0 ;
  this . weight = 0 ;
  this . items = [ ] ; // name , quantity , description , weight , price , totweight , totprice
  this . run = function ( )
	{ this . price = 0 ;
	  this . weight = 0 ;
	  this . items = [ ] ;
	  for ( var x = 0 ; x < this . store . cart . items . length ; x ++ )
		{ this . items [ x ] = [ ] ;
		  var storeItem = this . store . getStoreItem ( this . store . cart . items [ x ] . storeID ) ;
		  if ( storeItem == null ) { continue ; }
		  this . items [ x ] [ 0 ] = storeItem . name ;
		  this . items [ x ] [ 1 ] = this . store . cart . items [ x ] . quantity ;
		  this . items [ x ] [ 2 ] = storeItem . getDescription ( this . store . cart . items [ x ] . values ) ;
		  this . items [ x ] [ 3 ] = storeItem . getWeight ( this . store . cart . items [ x ] . values ) ;
		  this . items [ x ] [ 4 ] = storeItem . getPrice ( this . store . cart . items [ x ] . values ) ;
		  this . weight += this . items [ x ] [ 1 ] * this . items [ x ] [ 3 ] ;
		  this . price += this . items [ x ] [ 1 ] * this . items [ x ] [ 4 ] ;
		}
	} ;
  this . getText = function ( )
	{ this . run ( ) ;
	  var text = '\n\nTotal Price: ' + Format . dollars ( this . price ) + '\nTotal Weight: ' + Format . pounds ( this . weight ) ;
	  for ( var x = 0 ; x < this . items . length ; x ++ )
		{ text += '\n\nItem ' + x + '\nName: ' + this . items [ x ] [ 0 ] + '\nPrice: ' +  Format . dollars ( this . items [ x ] [ 4 ] ) + '\nQuantity: ' + this . items [ x ] [ 1 ] + '\nDescription: ' + this . items [ x ] [ 2 ] ;
		}
	  return text + '\n\n' ;
	} ;
  this . getHTML = function ( )
	{ this . run ( ) ;
	  var HTML = '<div class="storeRight">Total Price: ' + Format . dollars ( this . price ) + '<br />Total weight: ' + Format . pounds ( this . weight ) ;
	  for ( var x = 0 ; x < this . items . length ; x ++ )
		{ HTML += '<br /><br /><span style="font-size:11px;">Name: ' + this . items [ x ] [ 0 ] + '<br />Price: ' + Format . dollars ( this . items [ x ] [ 4 ] ) + '<br />Quantity: ' + this . items [ x ] [ 1 ] + '<br />Description: ' + this . items [ x ] [ 2 ] + '</span>' ;
		}
	  return HTML + '</div>' ;
	} ;
}

/*
 * public class Category
 * Author: Matthew Copeland
 * Versions:
 *  v1.0 (Oct 30, 2001)
 */

/*
 * public Category ( Item [ ] items )
 * Since: v1.0
 */

function Category ( name , items )
{ this . name = name ;
  this . items = items ;
  this . getStoreItemIDs = function ( )
	{ var itemIDs = [ ] ;
	  for ( var x = 0 ; x < this . items . length ; x ++ )
		{ itemIDs [ x ] = this . items [ x ] . storeID ;
		}
	  return itemIDs ;
	};
}

/*
 * public class CartItem
 * Author: Matthew Copeland
 * Versions:
 *  v1.0 (Oct 30, 2001)
 */

/*
 * CartItem ( string cartID , string storeID , string [ ] values , int quantity )
 * Since: v1.0
 */

function CartItem ( cartID , storeID , values , quantity )
{ this . cartID = cartID ;
  this . storeID = storeID ;
  this . values = values ;
  this . quantity = quantity ;
}

/*
 * public class Cart
 * Author: Matthew Copeland
 * Versions:
 *  v1.0 (Oct 30, 2001)
 */

/*
 * public Cart ( )
 */

function Cart ( )
{ this . items = [ ] ;
  this . uniqueID = 1 ;
  this . addCartItem = function ( storeID , values , quantity )
	{ this . items [ this . items . length ] = new CartItem ( this . uniqueID ++ , storeID , values , quantity ) ;
	};
  this . removeCartItem = function ( cartID )
	{ for ( var x = 0 ; x < this . items . length ; x ++ )
		{ if ( this . items [ x ] . cartID == cartID ) { break ; }
		}
	  if ( x == this . items . length ) { return ; }
	  while ( x < this . items . length - 1 )
		{ this . items [ x ] = this . items [ ++ x ] ;
		}
	  this . items . length -- ;
	};
  this . updateCartItem = function ( cartID , storeID , values , quantity )
	{ for ( var x = 0 ; x < this . items . length ; x ++ )
		{ if ( this . items [ x ] . cartID == cartID )
			{ this . items [ x ] . values = values ;
			  this . items [ x ] . quantity = quantity ;
			  return ;
			}
		}
	  this . addCartItem ( storeID , values , quantity ) ;
	};
  this . getCartItem = function ( cartID )
	{ for ( var x = 0 ; x < this . items . length ; x++ )
		{ if ( this . items [ x ] . cartID == cartID )
			{ return this . items [ x ] ;
			}
		}
	  return null ;
	};
}

/*
 * public class Store
 * Author: Matthew Copeland
 * Versions:
 *  v1.0 (Oct 30, 2001)
 */

/*
 * public Store ( Item [ ] items )
 *
 * Note: in this version, instantiations
 * of type Store must be named 'store'.
 */

function Store ( items )
{ this . items = items ;
  this . pagination = 10 ;
  this . categories = [ new Category ( "All Items" , this . items ) ] ;
  this . cart = new Cart ( ) ;
  this . HTMLBox = new HTMLBox ( 600 , 800 ) ;

/*
 * static code
 *  All items must be assigned a
 *  unique store ID
 */

	{ for ( var x = 0 ; x < this . items . length ; x ++ )
		{ this . items [ x ] . storeID = x ;
		}
	}

/*
 * public void addCatagory ( Category category )
 * Since: v1.0
 */

  this . addCategory = function ( category )
	{ this . categories [ this . categories . length ] = category ;
	};

/*
 * public void write ( )
 * Since: v1.0
 */

  this . write = function ( )
	{ this . HTMLBox . write ( ) ;
	};

/*
 * public void addToCart ( String storeID , String formName )
 * Since: v1.0
 */

  this . addToCart = function ( storeID , formName )
	{ var storeItem = this . getStoreItem ( storeID ) ;
	  if ( storeItem == null ) { return ; }
	  var values = storeItem . getValues ( document [ formName ] ) ;
	  var quantity = document [ formName ] . quantity . value ;
	  if ( quantity < 1 ) { return ; }
	  this . cart . addCartItem ( storeID , values , quantity ) ;
	  this . viewAllCartItems ( ) ;
	  new Alert ( quantity + ' ' + storeItem . name + '(s) added to your cart.' ) ;
	  this . viewAllCartItems ( ) ;
	};

/*
 * public void updateCartItem ( String cartID , String storeID , String formName )
 * Since: v1.0
 */

  this . updateCartItem = function ( cartID , storeID , formName )
	{ var cartItem = this . cart . getCartItem ( cartID ) ;
	  if ( cartItem == null ) { this . addToCart ( StoreID ) ; }
	  var storeItem = this . getStoreItem ( storeID ) ;
	  if ( storeItem == null ) { return '' ; }
	  values = storeItem . getValues ( document [ formName ] ) ;
	  var quantity = document [ formName ] . quantity . value ;
	  if ( quantity < 1 ) { return ; }
	  this . cart . updateCartItem ( cartID , storeID , values , quantity ) ;
	  new Alert ( storeItem . name + ' updated.' ) ;
	  this . viewAllCartItems ( ) ;
	};

/*
 * public void removeFromCart ( Strin cartID )
 * Since: v1.0
 */

  this . removeFromCart = function ( cartID )
	{ this . cart . removeCartItem ( cartID ) ;
	  new Alert ( 'Item removed from cart.' ) ;
	  this . viewAllCartItems ( ) ;
	};

/*
 * public void viewAllCartItems ( )
 * Since: v1.0
 */

  this . viewAllCartItems = function ( )
	{ var HTML = '' ;
	  for ( var x = this . cart . items . length - 1 ; x >= 0 ; x -- )
		{ HTML += this . getCartItemHTML ( this . cart . items [ x ] . cartID , this . cart . items [ x ] . storeID , 'f' + x ) ;
		}
	  if ( HTML == '' ) { HTML = 'You have no items in your shopping cart.' ; }
	  this . present ( HTML ) ;
	};

/*
 * public void viewStoreItem ( String storeID )
 * Since v1.0
 */

  this . viewStoreItem = function ( storeID )
	{ this . present ( this . getStoreItemHTML_long ( storeID , 'f' + storeID ) ) ;
	};

/*
 * public void viewStoreCategory ( int index , int start )
 * Since: v1.0
 */

  this . viewStoreCategory = function ( index , start )
	{ start = new Number ( start ) ;
	  var HTML = '' ;
	  var itemIDs = this . categories [ index ] . getStoreItemIDs ( ) ;
	  while ( start > itemIDs . length - 1 ) { start -= this . pagination ; }
	  if ( start < 0 ) { start = 0 ; }
	  var end = start + this . pagination ;
	  var nav = '<div style="text-align:right;">' ;
	  if ( end > itemIDs . length ) { end = itemIDs . length ; }
	  if ( start > 0 )
		{ nav += '<a class="command" href="javascript:store.viewStoreCategory(\'' + index + '\',\'' + ( start - this . pagination ) + '\')">previous</a>' ;
		}
	  if ( start > 0 && end < itemIDs . length ) { nav += ' | ' ; }
	  if ( end < itemIDs . length )
		{ nav +=' <a class="command" href="javascript:store.viewStoreCategory(\'' + index + '\',\'' + ( start + this . pagination ) + '\')">next</a>' ;
		}
	  nav += '</div>' ;
	  HTML += nav ;
	  for ( var x = start ; x < end ; x ++ )
		{ HTML += this . getStoreItemHTML_short ( itemIDs [ x ] , 'f' + x ) ;
		}
	  HTML += nav ;
	  this . present ( HTML ) ;
	};

/*
 * public void welcome ( )
 * Since: v1.0
 */

  this . welcome = function ( )
	{ var HTML = '<div class="storeRight" style="width:100%;height:100%;background-color:#ffffff;vertical-align:middle;text-align:center;padding:3px;"><span style="font-face:\'Arial\';font-size:20px;">Welcome to our</span><br /><img src="store/images/w1.gif" alt="Bible Bookstore" /><br /><span style="font-face:\'Arial\';font-size:10px;">Order online, or contact <a href="http://www.netservesales.com">net.serve.sales, inc.</a> at 888-367-6774.<br />Availability and pricing subject to change.</span></div>' ;
	  this . present ( HTML ) ; 
	};

/*
 * public void checkout ( )
 * Since: v1.0
 */

  this . checkOut = function ( )
	{ if ( this . cart . items . length == 0 )
		{ this . viewAllCartItems ( ) ;
		  return ;
		}
	  var report = new Report ( this ) ;
	  var HTML = 'Shipping will be charged at time of shipment.<br />' + report . getHTML ( ) + '<br /><br /><div class="storeRight" style="text-align:right;"><a class="command" href="javascript:store.sendOrder();">If this information is correct<br />you may continue with your purchase.<br />To continue click here.</a></div>' ;
	  this . present ( HTML ) ;
	} ;

  this . sendOrder = function ( )
	{ var report = new Report ( this ) ;
	  var HTML = '<div class="storeRight">To place an order online, please complete this form and submit your order.  To order by telephone, dial 888-367-6774 (9:00am-7:00pm CST).</div><form class="storeRight" action="store/order.php" method="post"><input type="hidden" name="report" value="' + report . getText ( ) + '">Email: <input type="text" name="email" /><br /><table style="width:100%;"><tr><td><div class="storeRight" style="font-weight:bold;">Shipping</div><table style="border-width:1px;border-style:solid;border-color:#000000;"><tr><td style="padding:3px;">Name:</td><td style="padding:3px;"><input type="text" name="shipping_name" /></td></tr><tr><td style="padding:3px;">Address:</td><td style="padding:3px;"><input type="text" name="shipping_address" /></td></tr><tr style="padding:3px;"><td style="padding:3px;">City:</td><td style="padding:3px;"><input type="text" name="shipping_city" /></td></tr><tr><td style="padding:3px;">State:</td><td style="padding:3px;"><input type="text" name="shipping_state" /></td></tr><tr><td style="padding:3px;">Zip Code:</td><td style="padding:3px;"><input type="text" name="shipping_zip" /></td></tr><tr><td style="padding:3px;">Phone:</td><td style="padding:3px;"><input type="text" name="shipping_phone" /></td></tr></table></td><td><div class="storeRight" style="font-weight:bold;">Billing-if different</div><table style="border-width:1px;border-style:solid;border-color:#000000;"><tr><td style="padding:3px;">Name:</td><td style="padding:3px;"><input type="text" name="billing_name" /></td></tr><tr><td style="padding:3px;">Address:</td><td style="padding:3px;"><input type="text" name="billing_address" /></td></tr><tr style="padding:3px;"><td style="padding:3px;">City:</td><td style="padding:3px;"><input type="text" name="billing_city" /></td></tr><tr><td style="padding:3px;">State:</td><td style="padding:3px;"><input type="text" name="billing_state" /></td></tr><tr><td style="padding:3px;">Zip Code:</td><td style="padding:3px;"><input type="text" name="billing_zip" /></td></tr><tr><td style="padding:3px;">Phone:</td><td style="padding:3px;"><input type="text" name="billing_phone" /></td></tr></table></td></tr></table><br /><br /><div style="text-align:right;">Credit Company: <select name="credit_company"><option>Visa</option><option>Master Card</option><option>American Express</option><option>Discover</option></select><br />Credit Card Number: <input type="text" name="credit_number" /><br />Expiration Date: <input type="text" name="credit_expires" /><br /><br /><input type="submit" value="place order"></div></form>' ;
	  this . present ( HTML ) ;
	} ;

/*
 * private void present ( String HTML )
 * Since v1.0
 */

  this . present = function ( HTML )
	{ var storeFront = '<table style="width:100%;height:100%;"><tr><td class="storeTop" style="vertical-align:text-middle;text-align:right;padding:3px;"><a class="storeTop" href="javascript:store.viewAllCartItems();">View Cart</a> | <a class="storeTop" href="javascript:store.checkOut();">Check Out</a></td></tr><tr><td style="height:100%;"><table style="width:100%;height:100%;"><tr><td class="storeLeft" style="width:100px;height:100%;vertical-align:text-top;text-align:left;padding:3px;"><div style="font-weight:bold;">Categories</div><div style="padding-left:8px;">' ;
	  for ( var x = 0 ; x < this . categories . length ; x ++ )
		{ storeFront += '<a class="storeLeft" href="javascript:store.viewStoreCategory(' + x + ',0);">' + this . categories [ x ] . name + '</a><br />' ;
		}
	  storeFront += '</div></td><td class="storeRight" style="height:100%;vertical-align:top;text-align:left;padding:10px;">' + HTML + '</td></tr></table></td></tr></table>' ;
	  this . HTMLBox . put ( storeFront ) ;
	  scrollTo ( 0 , 0 ) ;
	};

/*
 * private StoreItem getStoreItem ( String storeID )
 * Since: v1.0
 */

  this . getStoreItem = function ( storeID )
	{ for ( var x = 0 ; x < this . items . length ; x ++ )
		{ if ( this . items [ x ] . storeID == storeID )
			{ return this . items [ x ] ;
			}
		}
	  return null ;
	};

/*
 * private String getStoreItemHTML_long ( String storeID , String formName )
 * Since: v1.0
 */

  this . getStoreItemHTML_long = function ( storeID , formName )
	{ var storeItem = this . getStoreItem ( storeID ) ;
	  if ( storeItem == null ) { return '' ; }
	  var HTML = '<form name="' + formName + '"><table class="item" style="width:100%;"><tr><td><div class="itemTop" style="width:100%;padding:3px;text-align:left;">' + storeItem . name + '</div><table style="width:100%;border-collapse:collapse"><tr><td class="itemMiddle" style="text-align:center;vertical-align:text-top;padding:5px;"><img src="' + storeItem . largeImageSource + '" alt="' + storeItem . name + '"><br /><div style="text-align:left;">' + storeItem . description + '</div></td><td class="itemMiddle" style="vertical-align:text-top;text-align:left;padding:5px;"><br />' ;
	  var attributesHTML = storeItem . getAttributesHTML ( ) ;
	  for ( var x = 0 ; x < attributesHTML . length ; x ++ )
		{ HTML += attributesHTML [ x ] + '<br />' ;
		}
	  HTML += '</td></tr></table><div class="itemBottom" style="text-align:right;padding:3px;">Quantity: <input type="text" name="quantity" value="1"><br /><a class="command" href="javascript:store.addToCart(\'' + storeID + '\',\'' + formName + '\');">add to cart</a></div></td></tr></table></form>' ;
	  return HTML ;
	} ;


/*
 * private String getStoreItemHTML_short ( String storeID , String formName )
 * Since: v1.0
 */

  this . getStoreItemHTML_short = function ( storeID , formName )
	{ var storeItem = this . getStoreItem ( storeID ) ;
	  if ( storeItem == null ) { return '' ; }
	  return '<form name="' + formName + '"><table class="item" style="width:100%;"><tr><td><div class="itemTop" style="width:100%;padding:3px;">' + storeItem . name + '</div><table style="width:100%;"><tr><td class="itemMiddle" style="padding:3px;text-align:left;vertical-align:top;"><a class="itemMiddle" href="javascript:store.viewStoreItem(\'' + storeID + '\');"><img src="' + storeItem . smallImageSource + '" alt="' + storeItem . name + '"></td><td class="itemMiddle" style="padding:3px;text-align:left;vertical-align:top;"><a class="itemMiddle" href="javascript:store.viewStoreItem(\'' + storeID + '\');">' + storeItem . description + '</a></td></tr></table></td></tr></table></form>' ;
	};

/*
 * private String getCartItemHTML ( String cartID , String storeID , String formName )
 * Since: v1.0
 */

  this . getCartItemHTML = function ( cartID , storeID , formName )
	{ var storeItem = this . getStoreItem ( storeID ) ;
	  if ( storeItem == null ) { return '' ; }
	  storeItem . setValues ( this . cart . getCartItem ( cartID ) . values ) ;
	  var HTML = '<form name="' + formName + '"><table class="item" style="width:100%;"><tr><td><div class="itemTop" style="width:100%;padding:3px;text-align:left;">' + storeItem . name + '</div><table style="width:100%;border-collapse:collapse"><tr><td class="itemMiddle" style="text-align:center;vertical-align:text-top;padding:5px;"><img src="' + storeItem . largeImageSource + '" alt="' + storeItem . name + '"><br /><div style="text-align:left;">' + storeItem . description + '</div></td><td class="itemMiddle" style="vertical-align:text-top;text-align:left;padding:5px;"><br />' ;
	  var attributesHTML = storeItem . getAttributesHTML ( ) ;
	  for ( var x = 0 ; x < attributesHTML . length ; x ++ )
		{ HTML += attributesHTML [ x ] + '<br />' ;
		}
	  HTML += '</td></tr></table><div class="itemBottom" style="text-align:right;padding:3px;">Quantity: <input type="text" name="quantity" value="' + this . cart . getCartItem ( cartID ) . quantity + '"><br /><a class="command" href="javascript:store.updateCartItem(\'' + cartID + '\',\'' + storeID + '\',\'' + formName + '\');">update cart</a> | <a class="command" href="javascript:store.removeFromCart(\'' + cartID + '\');">remove from cart</a></div></td></tr></table></form>' ;
	  return HTML ;
	} ;
}

