<h1 class="underline">Check Out</h1>
<br />
{if !$user->isLoggedIn()}
<p>Please <a href="?pg=signup">Sign Up</a> or Log In.</p>
{else}
{select_query assign="userInfo" return="row"}
	firstName, lastName, address1, address2, city, state, country, zip
	FROM _users	
	WHERE id = '{$user->id}'
{/select_query}
{/if}
{include_php file="shared_handle:cart"}{include_php file="shared_handle:checkout"}
{if $cart.items|@count gt 0}
<p>Below is a preview list of the selected products and the sub total associated.</p>
<blockquote>
{foreach from=$cart.items key="productCode" item="lineItem"}
	<small>{$lineItem.title|truncate:20:"..."}</small>
	{$lineItem.quantity} @ 
	${$lineItem.each|number_format:"2"} 
	= ${$lineItem.subtotal|number_format:"2"}<br />
{/foreach}</blockquote>
<br />
<div class="underline pixel"></div>

<p>Once you have entered your shipping and billing address, click the Continue button and the forms will be verified for required fields, afterwhich a credit card form will show at the bottom of this page.</p>

<form name="checkoutForm" method="post" action="index.php">
<input type="hidden" name="pg" value="{$page.name}" />
<input type="hidden" name="cAction" value="{if $success.billIsValid}shipProcess{else}validateShippingBilling{/if}" />
<table width="100%"><tr><td>
<div class="chunk300">
<h2 class="withBG">
	<div class="topRight hideShow"><a href="javascript:toggle('shipInfo', '', 'showHide');"><img id="inComps_img" src="./img/blank.gif" class="showHide_on" alt="show/hide" border="0" /></a></div>
	Shipping Information</h2>

	<p>Enter the address for the location where you would like these products shipped to.</p>
	
	<div id="shipInfo" style="display:{if $success.shipIsValid}none{else}block{/if};">
	First Name:
	<input type="text" name="ship[firstname]" value="{$smarty.request.ship.firstname|default:$userInfo.firstName}" class="textInput" style="width:200px;" /><br />
	Last Name:
	<input type="text" name="ship[lastname]" value="{$smarty.request.ship.lastname|default:$userInfo.lastName}" class="textInput" style="width:200px;" /><br />

	Address:
	<input type="text" name="ship[address1]" value="{$smarty.request.ship.address1|default:$userInfo.address1}" class="textInput" style="width:200px;" /><br />
	Line 2:
	<input type="text" name="ship[address2]" value="{$smarty.request.ship.address2|default:$userInfo.address2}" class="textInput" style="width:200px;" /><br />

	City:
	<input type="text" name="ship[city]" value="{$smarty.request.ship.city|default:$userInfo.city}" class="textInput" style="width:200px;" /><br />

	State, Zip:
	<input type="text" name="ship[state]" value="{$smarty.request.ship.state|default:$userInfo.state}" class="textInput" style="width:30px;" maxlength="2" />
	<input type="text" name="ship[zip]" value="{$smarty.request.ship.zip|default:$userInfo.zip}" class="textInput" style="width:50px;" /><br />
	
	Country:
	<input type="text" name="ship[country]" value="{$smarty.request.ship.country|default:$userInfo.country}" class="textInput" style="width:200px;" maxlength="30" /><br />

	Email:
	<input type="text" name="bill[email]" value="{$smarty.request.bill.email|default:$userInfo.email}" class="textInput" style="width:200px;" maxlength="80" /><br />
	</div>
</div>

<div class="chunk300">
	<h2 class="withBG">
		<div class="topRight hideShow"><a href="javascript:toggle('billInfo', '', 'showHide');"><img id="inComps_img" src="./img/blank.gif" class="showHide_on" alt="show/hide" border="0" /></a></div>
		Billing Information</h2>
	<p>Enter the billing information for the credit card owner.</p>
	
	<div id="billInfo" style="display:{if $success.billIsValid}none{else}block{/if};">
	First Name:
	<input type="text" name="bill[firstname]" value="{$smarty.request.bill.firstname|default:$userInfo.firstName}" class="textInput" style="width:200px;" /><br />
	Last Name:
	<input type="text" name="bill[lastname]" value="{$smarty.request.bill.lastname|default:$userInfo.lastName}" class="textInput" style="width:200px;" /><br />

	Address:
	<input type="text" name="bill[address1]" value="{$smarty.request.bill.address1|default:$userInfo.address1}" class="textInput" style="width:200px;" /><br />
	Line 2:
	<input type="text" name="bill[address2]" value="{$smarty.request.bill.address2|default:$userInfo.address2}" class="textInput" style="width:200px;" /><br />

	City:
	<input type="text" name="bill[city]" value="{$smarty.request.bill.city|default:$userInfo.city}" class="textInput" style="width:200px;" /><br />

	State, Zip:
	<input type="text" name="bill[state]" value="{$smarty.request.bill.state|default:$userInfo.state}" class="textInput" style="width:30px;" maxlength="2" />
	<input type="text" name="bill[zip]" value="{$smarty.request.bill.zip|default:$userInfo.zip}" class="textInput" style="width:50px;" /><br />

	Country:
	<input type="text" name="bill[country]" value="{$smarty.request.bill.country|default:$userInfo.country}" class="textInput" style="width:200px;" maxlength="30" /><br />

	Phone:
	<input type="text" name="bill[phone]" value="{$smarty.request.bill.phone|default:$userInfo.phone}" class="textInput" style="width:200px;" maxlength="80" /><br />
	</div>
</div>

<div id="fMatches" class="xFloat" style="padding:3px; background-color:#FFFFFF; border:#666666 1px solid;"></div>

{if $modules.spadeAutoComplete}
	<script language="JavaScript" src="{$modules.x}"></script>
	<script language="JavaScript" src="{$modules.spadeAutoComplete}"></script>
	<script language="JavaScript">
		var states = new Array('AL','AK','AS','AZ','AR','CA','CO','CT','DE','DC','FL','GA','GU',
					'HI','ID','IL','IN','IA','KS','KY','LA','ME','MH','MD','MA',
					'MI','MN','MS','MO','MT','NE','NV','NH','NJ','NM','NY','NC',
					'ND','OH','OK','OR','PW','PA','PR','RI','SC','SD','TN','TX',
					'UT','VT','USVI','VA','WA','WV','WI','WY','AB','BC','LB','MB',
					'NB','NF','NT','NS','ON','PE','PQ','SK','YT');
		initAutoComplete('bill[state]', states, true);
		initAutoComplete('ship[state]', states, true);

		{* var countries = new Array ('United States of America', 'Canada', 'Germany', 'United Kingdom', 'India', '---------------------', 'Albania', 'Algeria', 'Andorra', 'Angola', 'Anguilla', 'Antarctica', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia and Herzegowina', 'Botswana', 'Bouvet Island', 'Brazil', 'British Ind. Ocean Terr', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Cape Verde', 'Cayman Islands', 'Central African Rep.', 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocoa (Keeling) Isl.', 'Colombia', 'Comoros', 'Congo', 'Cook Islands', 'Costa Rica', 'Cote Divoire', 'Hrvatska', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'East Timor', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Falkland Isl. (Malvinas)', 'Faroe Islands', 'Fiji', 'Finland', 'France', 'French Guiana', 'French Polynesia', 'French Southern Terr.', 'Gabon', 'Gambia', 'Georgia', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guatemala', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Heard & McDonald Isl.', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'Indonesia', 'Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Republic of Korea', 'Kuwait', 'Kyrgyzstan', 'Lao Peoples Dem. Rep.', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macau', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Micronesia: Fed. States of', 'Moldova: Republic of', 'Monaco', 'Mongolia', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'Netherlands Antilles', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Mariana Isl.', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn', 'Poland', 'Portugal', 'Qatar', 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', 'Saint Kitts and Nevis', 'Saint Lucia', 'St. Vincent & Grenadines', 'Samoa', 'San Marino', 'Sao Tome and Principe', 'Saudi Arabia', 'Senegal', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'S. Georgia & S. Sandwich Isl.', 'Spain', 'Sri Lanka', 'St. Helena', 'St. Pierre and Miquelon', 'Suriname', 'Svalbard & Jan Mayen Isl.', 'Swaziland', 'Sweden', 'Switzerland', 'Syrian Arab Republic', 'Taiwan', 'Tajikistan', 'Tanzania: United Rep. of', 'Thailand', 'Togo', 'Tokelau', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks and Caicos Islands', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'US Minor Outlying Isl.', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Vatican City (Holy See)', 'Venezuela', 'Vietnam', 'Virgin Islands (British)', 'Wallis and Futuna Islands', 'Western Sahara', 'Yemen', 'Yugoslavia', 'Zaire', 'Zambia', 'Zimbabwe', 'Not Listed'); *}
		var countries = new Array ('USA', 'Canada', 'Germany', 'UK', 'India', 'Albania', 'Algeria', 'Andorra', 'Angola', 'Anguilla', 'Antarctica', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia and Herzegowina', 'Botswana', 'Bouvet Island', 'Brazil', 'British Ind. Ocean Terr', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Cape Verde', 'Cayman Islands', 'Central African Rep.', 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocoa (Keeling) Isl.', 'Colombia', 'Comoros', 'Congo', 'Cook Islands', 'Costa Rica', 'Cote Divoire', 'Hrvatska', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'East Timor', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Falkland Isl. (Malvinas)', 'Faroe Islands', 'Fiji', 'Finland', 'France', 'French Guiana', 'French Polynesia', 'French Southern Terr.', 'Gabon', 'Gambia', 'Georgia', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guatemala', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Heard & McDonald Isl.', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'Indonesia', 'Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Republic of Korea', 'Kuwait', 'Kyrgyzstan', 'Lao Peoples Dem. Rep.', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macau', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Micronesia: Fed. States of', 'Moldova: Republic of', 'Monaco', 'Mongolia', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'Netherlands Antilles', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Mariana Isl.', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn', 'Poland', 'Portugal', 'Qatar', 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', 'Saint Kitts and Nevis', 'Saint Lucia', 'St. Vincent & Grenadines', 'Samoa', 'San Marino', 'Sao Tome and Principe', 'Saudi Arabia', 'Senegal', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'S. Georgia & S. Sandwich Isl.', 'Spain', 'Sri Lanka', 'St. Helena', 'St. Pierre and Miquelon', 'Suriname', 'Svalbard & Jan Mayen Isl.', 'Swaziland', 'Sweden', 'Switzerland', 'Syrian Arab Republic', 'Taiwan', 'Tajikistan', 'Tanzania: United Rep. of', 'Thailand', 'Togo', 'Tokelau', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks and Caicos Islands', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'US Minor Outlying Isl.', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Vatican City (Holy See)', 'Venezuela', 'Vietnam', 'Virgin Islands (British)', 'Wallis and Futuna Islands', 'Western Sahara', 'Yemen', 'Yugoslavia', 'Zaire', 'Zambia', 'Zimbabwe', 'Not Listed');
		
		initAutoComplete('bill[country]', countries, true);
		initAutoComplete('ship[country]', countries, true);
	</script>
{/if}

{if $success.shipIsValid AND $success.billIsValid}

<div class="chunk300">
<h2 class="withBG">Billing Summary</h2>
	Order Total = ${$order.total|default:"0"|number_format:"2"}<br />
	Shipping / Handling = ${$order.shipping|default:"0"|number_format:"2"}<br />
	Sales Tax = ${$order.tax|default:"0"|number_format:"2"}<br /><br />
	<div class="underline"></div>
	Total Amount Due: <em>${$order.grandTotal|default:"0"|number_format:"2"}</em>
</div>

<div class="chunk300">
<h2 class="withBG">Payment Information</h2>

	Payment Method:
	<select name="bill[paymentMethod]" size="1">
		<option value="visa"{if $smarty.request.bill.paymentMethod eq "visa"} selected{/if}>Visa</option>
		<option value="mastercard"{if $smarty.request.bill.paymentMethod eq "mastercard"} selected{/if}>Mastercard</option>
		<option value="american express"{if $smarty.request.bill.paymentMethod eq "american express"} selected{/if}>American Express</option>
		<option value="discover"{if $smarty.request.bill.paymentMethod eq "discover"} selected{/if}>Discover</option>
	</select><br />

	Card Number:
	<input type="text" name="bill[ccnum]" value="" class="textInput" style="width:200px;" /><br />

	Expiration Date: <small>(MMYY)</small>
	<input type="text" name="bill[ccexp]" value="" class="textInput" maxlength="4" style="width:50px;" /><br />
</div>
</td></tr></table>

<div class="hBox" style="text-align:right"><a href="javascript:document.checkoutForm.submit();" class="button"> Submit Payment </a></div>
{else}
</td></tr></table> 

<div class="hBox" style="text-align:right"><a href="javascript:document.checkoutForm.submit();" class="button"> Continue </a></div>
{/if}
</form>

{else}
	{redirect href="?pg=cart"}
{/if}
