<?php
global $wpsc_cart, $wpdb, $wpsc_checkout, $wpsc_gateway, $wpsc_coupons;
$wpsc_checkout = new wpsc_checkout();
$wpsc_gateway = new wpsc_gateways();
$wpsc_coupons = new wpsc_coupons($_SESSION['coupon_numbers']);
//echo "<pre>".print_r($wpsc_cart,true)."</pre>";
//echo "<pre>".print_r($_SESSION,true)."</pre>";
//echo "<pre>".print_r($wpsc_checkout,true)."</pre>";

if(wpsc_cart_item_count() > 0) :
?>
<div style="float:left"><?php echo TXT_WPSC_REVIEW_YOUR_ORDER; ?></div>
<div style="float:right"><a href="<?php echo get_settings('home'); ?>/products-page"><u>Click here to continue shopping</u></a></div>
<div style="clear:both"></div>

<table class="productcart">
	<tr class="firstrow">
		<td class='firstcol'></td>
		<td><?php echo TXT_WPSC_PRODUCT; ?>:</td>
	  <td><?php echo TXT_WPSC_QUANTITY; ?>:</td>
	  <td><?php echo TXT_WPSC_PRICE; ?>:</td>
	  <td></td>
	</tr>
    
	<?php while (wpsc_have_cart_items()) : wpsc_the_cart_item(); ?>
	
	<?php  //this displays the confirm your order html	?>
		
		<tr class="product_row">
			<td class="firstcol"><img src='<?php echo wpsc_cart_item_image(48,48); ?>' alt='<?php echo wpsc_cart_item_name(); ?>' title='<?php echo wpsc_cart_item_name(); ?>' /></td>
			<td class="firstcol">
			<a href='<?php echo wpsc_cart_item_url();?>'><?php echo wpsc_cart_item_name(); ?></a>
			</td>
			<td>
				<form action="<?php echo get_option('shopping_cart_url'); ?>" method="post" class="adjustform">
					<input type="text" name="quantity" size="2" value="<?php echo wpsc_cart_item_quantity(); ?>"/>
					<input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>"/>
					<input type="hidden" name="wpsc_update_quantity" value="true"/>
					<input type="submit" value="<?php echo TXT_WPSC_APPLY; ?>" name="submit"/>
				</form>
			</td>
			<td><span class="pricedisplay"><?php echo wpsc_cart_item_price(); ?></span></td>
			<td>
			
				<form action="<?php echo get_option('shopping_cart_url'); ?>" method="post" class="adjustform">
					<input type="hidden" name="quantity" value="0"/>
					<input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>"/>
					<input type="hidden" name="wpsc_update_quantity" value="true"/>
					<button class='remove_button' type="submit"><span><?php echo TXT_WPSC_REMOVE; ?></span></button>
				</form>
			</td>
		</tr>
	<?php endwhile; ?>
	<?php //this HTML displays coupons if there are any active coupons to use ?>
<?php //exit('<pre>'.print_r($wpsc_coupons, true).'</pre>'); ?>
	<?php if(wpsc_uses_coupons()): ?>
		
		<?php if(wpsc_coupons_error()): ?>
			<tr><td><?php echo TXT_WPSC_COUPONSINVALID; ?></td></tr>
		<?php endif; ?>
		<tr>
		
		<td colspan="2"><?php _e('Enter your coupon number'); ?> :</td>
		<td  colspan="3" align='left'>
		<form  method='post' action="<?php echo get_option('shopping_cart_url'); ?>">
			<input type='text' name='coupon_num' id='coupon_num' value='<?php echo $wpsc_cart->coupons_name; ?>' />
			<input type='submit' value='<?php echo TXT_WPSC_APPLY ?>' />
		</form>
		</td>
		</tr>
	<?php endif; ?>	
	</table>
	<?php  //this HTML dispalys the calculate your order HTML	?>

	<?php if(isset($_SESSION['nocamsg']) && isset($_GET['noca']) && $_GET['noca'] == 'confirm'): ?>
		<p class='validation-error'><?php echo $_SESSION['nocamsg']; ?></p>
	<?php endif; ?>
	<?php do_action('wpsc_before_shipping_of_shopping_cart'); ?>
	<div id='wpsc_shopping_cart_container'>
	
    <table class="productcart" cellpadding="0" cellspacing="0">
        <tr class="total_price">		  	
            <td colspan="3" style="width:100%;"><b><?php echo TXT_WPSC_SUBTOTAL; ?>:</b></td>
            <td colspan="2" style="text-align:right"><b><?php echo wpsc_cart_subtotal(); ?></b></td>
        </tr>
    </table>
    
	<table class="productcart">   
    
    <?php if(wpsc_cart_has_shipping() && !wpsc_cart_show_plus_postage()){ ?>
    	<tr>		  	
			<td colspan="3" style="width:100%;"><b><?php echo TXT_WPSC_SHIPPING; ?>:</b></td>
            <td colspan="2" style="text-align:right"><b><?php echo wpsc_cart_shipping(); ?></b></td>
        </tr>
	<?php }else{ ?>
		<tr>		  	
			<td colspan="3" style="width:100%;"><b><?php echo TXT_WPSC_SHIPPING; ?>:</b></td>
            <td colspan="2" style="text-align:right"><b style="color:#FF0000">FREE</b></td>
        </tr>
	<?php } ?>
    
    <tr class="total_price">		  	
			<td colspan="3" style="width:100%;"><b><?php echo TXT_WPSC_HANDLING; ?>:</b></td>
            <td colspan="2" style="text-align:right"><b><?php echo wpsc_cart_handling(); ?></b></td>
    </tr>
    
    
	<tr class="total_price total_tax">
		<td colspan="3">
			<?php echo TXT_WPSC_TAX; ?>:
		</td>
		<td colspan="2">
			<span id="checkout_tax" class="pricedisplay checkout-tax"><?php echo wpsc_cart_tax(); ?></span>
	  </td>
	</tr>
	  <?php if(wpsc_uses_coupons() && (wpsc_coupon_amount() != 0)): ?>
	<tr class="total_price">
		<td colspan="3">
			<?php echo TXT_WPSC_COUPONS; ?>:
		</td>
		<td colspan="2">
			<span id="coupons_amount" class="pricedisplay"><?php echo wpsc_coupon_amount(); ?></span>
	  </td>
    </tr>
	  <?php endif ?>
	
		
	
	<tr class='total_price' style="background:#FFFFCC">
		<td colspan='3'>
		<?php echo TXT_WPSC_TOTALPRICE; ?>:
		</td>
		<td colspan='2'>
			<span id='checkout_total' class="pricedisplay checkout-total"><?php echo wpsc_cart_total(); ?></span>
		</td>
	</tr>
	
	
	</table>
    
    <!--notice-->
    <div>
    	<p style="color:#900;">Please Note: Spas and Hot Tubs are delivered to the NJ &amp; NY metro only. <a href="JavaScript:newPopup1('/wp-content/themes/revolution-30/images/shipping-map-spa.jpg');"><u>Please see map</u></a>. We currently do not ship or deliver Hot Tubs to other areas.</p>
    </div>

		<?php do_action('wpsc_before_form_of_shopping_cart'); ?>
	
	<form class='wpsc_checkout_forms' action='' method='post' enctype="multipart/form-data">
	
	   <?php 
	   /**  
	    * Both the registration forms and the checkout details forms must be in the same form element as they are submitted together, you cannot have two form elements submit together without the use of JavaScript.
	   */
	   ?>

	 <?php if(!is_user_logged_in() && get_option('users_can_register') && get_option('require_register')) : ?>		
		<?php	if(count($_SESSION['wpsc_checkout_user_error_messages']) > 0) : ?>
			<div class="login_error"> 
				<?php		  
				foreach($_SESSION['wpsc_checkout_user_error_messages'] as $user_error ) {
				  echo $user_error."<br />\n";
				}
				$_SESSION['wpsc_checkout_user_error_messages'] = array();
				?>			
		  </div>
		<?php endif; ?>
		
	  <div class="registerLeft">
	  	<fieldset>
				<label><?php _e('Username'); ?>:</label><input type="text" name="log" id="log" value="" size="20"/><br />
				<label><?php _e('Password'); ?>:</label><input type="password" name="pwd" id="pwd" value="" size="20" /><br />
				<label><?php _e('E-mail'); ?>:</label><input type="text" name="user_email" id="user_email" value="<?php echo attribute_escape(stripslashes($user_email)); ?>" size="20" />
		</fieldset>
      </div>
      <div class="registerRight">
      		<a href="<?php echo get_settings('home'); ?>/products-page/your-account"><img src="/wp-content/uploads/wpsc/themes/poolfactory/images/checkout-right.jpg" alt="Click here to login" border="0" /></a>
      </div>
      <div style="clear:both"></div>
	<?php endif; ?>

	<h2><?php echo TXT_WPSC_CONTACTDETAILS; ?></h2>
	<?php/* echo TXT_WPSC_CREDITCARDHANDY; <br /> */?>
	<p><?php echo TXT_WPSC_ASTERISK; ?></p>
	<?php
	  if(count($_SESSION['wpsc_checkout_misc_error_messages']) > 0) {
			echo "<div class='login_error'>\n\r";
			foreach((array)$_SESSION['wpsc_checkout_misc_error_messages'] as $user_error ) {
				echo $user_error."<br />\n";
			}
			echo "</div>\n\r";
		}
		$_SESSION['wpsc_checkout_misc_error_messages'] =array();
	?>
    
	<table class='wpsc_checkout_table' border="0">
        
        <?php while (wpsc_have_checkout_items()) : wpsc_the_checkout_item(); ?>
		<?php if( wpsc_is_shipping_details()) : ?>
			<tr>
				<td colspan ='2'>
					<br />
					<input type='checkbox' value='true' name='shippingSameBilling' id='shippingSameBilling' />
					<label for='shippingSameBilling'>Shipping Address same as Billing Address?</label>
				</td>
			</tr>
		<?php endif; ?>
            
		<tr <?php echo wpsc_shipping_details(); ?>>
		  <?php if(wpsc_checkout_form_is_header() == true) : ?>
                    <td <?php if(wpsc_is_shipping_details()) echo "class='wpsc_shipping_forms'"; ?> colspan='2'>
                        <h4 class="wpsc_shipping_form_name">
                            <?php echo wpsc_checkout_form_name();?>
                        </h4>
                    </td>
                        
                  <?php else: ?>
                          <?php if((!wpsc_uses_shipping()) && $wpsc_checkout->checkout_item->unique_name == 'shippingstate'): ?>
                          <?php else : ?>
                          
                            <td>
                                <label for='<?php echo wpsc_checkout_form_element_id(); ?>'>
                                <?php echo wpsc_checkout_form_name();?>:
                                </label>
                            </td>
                            <td>
                                <?php echo wpsc_checkout_form_field();?>
                                
                                    <?php if(wpsc_the_checkout_item_error() != ''): ?>
                                    <p class='validation-error'><?php echo wpsc_the_checkout_item_error(); ?></p>
                                    
                                    <?php endif; ?>
                            <?php endif; ?>
                            </td>
                  <?php endif; ?>
		</tr>
		<?php endwhile; ?>
        <tr>
		    <td colspan ='2' style="padding-top: 15px;">
                <input type='checkbox' name='In-StorePick-up' id='In-StorePick-up' />
                <label for='In-StorePick-up'>In-Store Pick-up (Pool purchases only)</label>
                <br />
            </td>
        </tr>
		<?php if (get_option('display_find_us') == '1') : ?>
		<tr>
			<td>How did you find us:</td>
			<td>
				<select name='how_find_us'>
					<option value='Word of Mouth'>Word of mouth</option>
					<option value='Advertisement'>Advertising</option>
					<option value='Internet'>Internet</option>
					<option value='Customer'>Existing Customer</option>
				</select>
			</td>
		</tr>
		<?php endif; ?>		
		<tr>
			<td colspan='2'>
			
			<?php  //this HTML displays activated payment gateways?>
			  
				<?php if(wpsc_gateway_count() > 1): // if we have more than one gateway enabled, offer the user a choice ?>
					<h3><?php echo TXT_WPSC_SELECTGATEWAY;?></h3>
					<?php while (wpsc_have_gateways()) : wpsc_the_gateway(); ?>
						<div class="custom_gateway">
							<?php if(wpsc_gateway_internal_name() == 'noca'){ ?>
								<label><input type="radio" id='noca_gateway' value="<?php echo wpsc_gateway_internal_name();?>" <?php echo wpsc_gateway_is_checked(); ?> name="custom_gateway" class="custom_gateway"/><?php echo wpsc_gateway_name();?></label>
							<?php }else{ ?>
								<label><input type="radio" value="<?php echo wpsc_gateway_internal_name();?>" <?php echo wpsc_gateway_is_checked(); ?> name="custom_gateway" class="custom_gateway"/><?php echo wpsc_gateway_name();?></label>
							<?php } ?>

							
							<?php if(wpsc_gateway_form_fields()): ?> 
								<table class='<?php echo wpsc_gateway_form_field_style();?>'>
									<?php echo wpsc_gateway_form_fields();?> 
								</table>		
							<?php endif; ?>			
						</div>
					<?php endwhile; ?>
				<?php else: // otherwise, there is no choice, stick in a hidden form ?>
					<?php while (wpsc_have_gateways()) : wpsc_the_gateway(); ?>
						<input name='custom_gateway' value='<?php echo wpsc_gateway_internal_name();?>' type='hidden' />
						
							<?php if(wpsc_gateway_form_fields()): ?> 
								<table>
									<?php echo wpsc_gateway_form_fields();?> 
								</table>		
							<?php endif; ?>	
					<?php endwhile; ?>				
				<?php endif; ?>				
				
			</td>
		</tr>
		<?php if(get_option('terms_and_conditions') != '') : ?>
		<tr>
			<td colspan='2'>
      <input type='checkbox' value='yes' name='agree' /> <?php echo TXT_WPSC_TERMS1;?><a class='thickbox' target='_blank' href='https://www.sipoolandspa.com/?termsandconds=true&amp;width=360&amp;height=400' class='termsandconds'><?php echo TXT_WPSC_TERMS2;?></a>
      </td>
    </tr>
		<?php endif; ?>	
		<tr>
			<td colspan='2'>
				<?php if(get_option('terms_and_conditions') == '') : ?>
					<input type='hidden' value='yes' name='agree' />
				<?php endif; ?>	
				<?php //exit('<pre>'.print_r($wpsc_gateway->wpsc_gateways[0]['name'], true).'</pre>');
				 if(count($wpsc_gateway->wpsc_gateways) == 1 && $wpsc_gateway->wpsc_gateways[0]['name'] == 'Noca'){}else{?>
					<input type='hidden' value='submit_checkout' name='wpsc_action' />
					<input type='submit' value='<?php echo TXT_WPSC_MAKEPURCHASE;?>' name='submit' class='make_purchase' />
				<?php }/* else: ?>
				
				<br /><strong><?php echo TXT_WPSC_PLEASE_LOGIN;?></strong><br />
				<?php echo TXT_WPSC_IF_JUST_REGISTERED;?>
				</td>
				<?php endif;  */?>				
			</td>
		</tr>
	</table>
</form>
</div>
<div style="width:280px; margin:10px auto;">


</div>

<?php
else:
	echo TXT_WPSC_BUYPRODUCTS;
endif;
do_action('wpsc_bottom_of_shopping_cart');
?>