{!--
Site:          chrysalis-designs.com
Page:          promotion/valentines-day.php
Created:       Jan 27 2007
Last Modified: Jul 19 2012
=================================================
ryan masuga, masugadesign.com
ryan@masugadesign.com | Copyright 2007-20012
================================================= --}
{snip_global_header}
{exp:stash:set name="stash_body_class"}promotion{/exp:stash:set}

{exp:switchee variable = "{segment_3}" parse="inward"}

{case value="checkout"}
	{exp:stash:set name="stash_page_title"}Valentine's Day Checkout{/exp:stash:set}

	{exp:store:checkout next="/" return="/" payment_method="manual" require="name|email|phone|address1|region" error_handling="inline" error_delimiters='<span class="errors">|</span>' form_class="validation"}
		{if no_items}
			<h3>Valentine's Day Checkout</h3>
        	<h4>Your cart is empty!</h4>
    	{/if}
    	<style type="text/css">
    	.item_list {width: 100%;}
		.item_header {width: 100%; border-bottom: 1px solid #000;}
			.item_header td {font-weight: bold;}
		.item_title {width: 75%;}
		.item_qty {width: 10%;}
		.item_total {width: 15%; text-align: right;}
		.cart_total {width: 25%; text-align: right;}

		#shipping_info {width: 100%;}
		#shipping_info .row {width: 100%; clear: both; padding: 10px 0 0 30px;}
		#shipping_info .row .label {float: left; width: 100px; text-align: right; margin: 0 20px 0 0;}
		#shipping_info .row .input {float: left; width: 300px; margin: 0 20px 0 0;}
		#shipping_info .row .error {width: 300px; float: left;}
		#place_order input {
			width: 100px;
			margin: 0 30px 0 0;
		}
    	</style>
		<h3>Valentine's Day Checkout</h3>
		<hr />
			<table class="item_list">
				<tr class="item_header">
					<td class="item_title">Item</td>
					<td class="item_qty">Qty</td>
					<td class="item_total">Total (Tax inc)</td>
				</tr>
				{items}
				<tr class="item">
					<td class="item_title">{title}</td>
					<td class="item_qty">{item_qty}</td>
					<td class="item_total">{item_total}</td>
				</tr>
				{/items}
			</table>
			<hr />
			<table class="item_list">
				<tr class="item_header">
					<td class="item_title"></td>
					<td class="cart_total">Totals: {order_qty} items - {order_total}</td>
				</tr>
			</table>
		<div id="shipping_info">
			<div class="row">
    			<div class="label"><label for="">* Your Name</label></div>
    			<div class="input"><input type="text" name="shipping_name" value="{shipping_name}" class="validate[required]"/></div>
    			<div class="error">{error:shipping_name}</div>
    		</div>
    		<div class="row">
		    	<div class="label"><label for="">* Email Address</label></div>
		    	<div class="input"><input type="text" name="order_email" value="{order_email}" class="validate[required,custom[email]]"/></div>
		    	<div class="error">{error:order_email}</div>
    		</div>
    		<div class="row">
		    	<div class="label"><label for="">* Phone</label></div>
		    	<div class="input"><input type="text" name="shipping_phone" value="{shipping_phone}" class="validate[required,custom[phone]]"/></div>
		    	<div class="error">{error:shipping_phone}</div>
		    </div>
    		<div class="row">
		    	<div class="label"><label for="">Alt Phone</label></div>
		    	<div class="input"><input type="text" name="order_custom2" value="{order_custom2}" /></div>
		    </div>
    		<div class="row">
		    	<div class="label"><label for="">* Fulfillment</label></div>
		    	<div class="input">
		    		{if lv_valen_deliver_before}<input type="radio" class="radio deliver" name="order_custom1" value="Delivery - {lv_valen_deliver_before}"> Delivery - {lv_valen_deliver_before}<br>{/if}
					{if lv_valen_pickup_before}<input type="radio" class="radio" name="order_custom1" value="Pick Up - {lv_valen_pickup_before}" checked="checked"> Pick Up - {lv_valen_pickup_before}<br>{/if}
					{if lv_valen_deliver_day_of}<input type="radio" class="radio deliver" name="order_custom1" value="Delivery - {lv_valen_deliver_day_of}"> Delivery - {lv_valen_deliver_day_of}<br />{/if}
					{if lv_valen_pickup_day_of}<input type="radio" class="radio" name="order_custom1" value="Pick Up - {lv_valen_pickup_day_of}"> Pick Up - {lv_valen_pickup_day_of}<br>{/if}
		    	</div>

		    </div>
		    <div><div></div><div><hr /></div></div>
    		<div class="row">
		    	<div class="label"><label for="">Additional Info</label></div>
		    	<div class="input">{lv_additional_info}</div>
		    </div>
    		<div class="row">
		    	<div class="label"><label for="">Company</label></div>
		    	<div class="input"><input type="text" name="order_custom3" value="{order_custom3}" /></div>
		    </div>
    		<div class="row">
		    	<div class="label"><label for="">* Address</label></div>
		    	<div class="input"><input type="text" name="shipping_address1" value="{shipping_address1}" id="shipping_address1"/></div>
		    	<div class="error">{error:shipping_address1}</div>
		    </div>
    		<div class="row">
		    	<div class="label"><label for="">Address 2</label></div>
		    	<div class="input"><input type="text" name="shipping_address2" value="{shipping_address2}" /></div>
		    </div>
    		<div class="row">
		    	<div class="label"><label for="">* City</label></div>
		    	<div class="input"><input type="text" name="shipping_address3" value="{shipping_address3}" id="shipping_address3"/></div>
		    	<div class="error">{if error:shipping_address3}<span class="errors">The Shipping City field is required.</span>{/if}</div>
		    </div>
    		<div class="row">
		    	<div class="label"><label for="">* State</label></div>
		    	<div class="input">
		    		<select name="shipping_region" disabled="disabled">
						{shipping_region_options}
					</select>
				</div>
		    	<div class="error">{error:shipping_region}</div>
		    </div>
    		<div class="row">
		    	<div class="label"><label for="">* Zipcode</label></div>
		    	<div class="input"><input type="text" name="shipping_postcode" value="{shipping_postcode}" maxlength="5" id="shipping_postcode"/></div>
		    	<div class="error">{error:shipping_postcode}</div>
		    </div>
    		<div class="row">
		    	<div class="label"><label for="">Additional Instructions</label></div>
		    	<div class="input"><textarea type="text" name="order_custom4" value="{order_custom4}"></textarea></div>
		    </div>
		    <input type="hidden" name="payment_method" value="manual">
    		<input type="hidden" name="shipping_method" value="included">
    		<input type="hidden" name="billing_same_as_shipping" value="1"/>
    		<div class="row">
    			<p id="place_order"><input type="submit" name="submit" value="Place Order"/></p>
    		</div>
    	</div>
	{/exp:store:checkout}

	{exp:stash:set name="close_footer"}no{/exp:stash:set}
	{snip_global_footer}
	<script type="text/javascript">
	$(document).ready(function() {
		// Start validationEngine
	    $(".validation").validationEngine();
	    //In case the page gets reloaded and inputs stay, require specific fields
	    if($('input.delivery').is(':checked')) {
			$("#shipping_address1").addClass("validate[required]");
			$("#shipping_address3").addClass("validate[required]");
			$("#shipping_postcode").addClass("validate[required,custom[number]]");
		}
	    //Switch requirement based on fulfillment
	    $("input[name=order_custom1]").click(function() {
	    	if($(this).attr('class') == "radio deliver") {
				$("#shipping_address1").addClass("validate[required]");
				$("#shipping_address3").addClass("validate[required]");
				$("#shipping_postcode").addClass("validate[required,custom[number]]");
			}else{
				$("#shipping_address1").removeClass("validate[required]").validationEngine('hide');
				$("#shipping_address3").removeClass("validate[required]").validationEngine('hide');
				$("#shipping_postcode").removeClass("validate[required,custom[number]]").validationEngine('hide');
			}
	    });
	});
	</script>
	</body>
	</html>
{/case}

{case value="" default="Yes"}
	{exp:channel:entries url_title="{segment_2}" disable="trackbacks|pagination|member_data"}
		{exp:stash:set name="stash_body_id"}{url_title}{/exp:stash:set}
		{exp:stash:set name="stash_page_title"}{title}{/exp:stash:set}

		<div id="promo_body">
			{body}
		</div>

		<div id="items">
		{exp:playa:children field="promotional_listings"}
			{exp:store:product entry_id="{entry_id}" form_id="{url_title}" form_class="formfields promo_items"}
				<dl class="clearfix flowerblock">

					<dt><label for="{url_title}">{title}</label></dt>

					<dd class="img">
						{if promo_img}
							{exp:channel_images:images entry_id="{entry_id}" limit="1"}
								<a class="imgLink" href="{image:url:large}" rel="lightbox[valentines]">
									<div class="enlargeImg"></div>
									<img src="{image:url:full}" width="80px" height="80px" alt="{embed:title}"/>
								</a>
							{/exp:channel_images:images}
						{if:else}
						<div style="height:80px;width:80px;float:left;">&nbsp;</div>
						{/if}
					</dd>

					<dd class="desc">{promo_shortdesc} - <span class="price">{price}/{promo_price_txt}</span></dd>
					{if total_stock != "0"}
						<dd class="amt"><input type="text" name="item_qty" class="item_qty" size="3" value="" /> {promo_price_txt}<button class="reset" style="display: none;">Reset</button></dd>
					{if:else}
						<dd class="soldout">SOLD OUT</dd>
					{/if}

		 		</dl>
			{/exp:store:product}
		{/exp:playa:children}
	{/exp:channel:entries}
	{lv_footer_info}
		</div>
		{snip_global_sidebar_cart}

	{exp:stash:set name="close_footer"}no{/exp:stash:set}
	{snip_global_footer}
	<script type="text/javascript">
	$(document).ready(function() {
		// On blur, send the qty to the cart
		$('.item_qty').blur(function() {
			if($(this).val() != "") {
				var promoitem = $(this).parents('.store_product_form');
				var url = promoitem.attr('action');
				var data = promoitem.serialize();
				$.post(url, data);
				$(this).attr('disabled', 'disabled')
				$(this).parents('.amt').addClass('disabled');
				$(this).siblings('.reset').show();
			}
			setTimeout(refresh_cart, 500);
		});
		// On reset, remove item qty from cart
		$('.reset').click (function() {
			var qty = $(this).siblings('.item_qty').val()
			$(this).siblings('.item_qty').removeAttr('disabled').val('-'+ qty);
			var promoitem = $(this).parents('.store_product_form');
			var url = promoitem.attr('action');
			var data = promoitem.serialize();
			$.post(url, data);
			$(this).parents('.amt').removeClass('disabled');
			$(this).hide();
			$(this).siblings('.item_qty').val("");
			setTimeout(refresh_cart, 600);
			return false;
		});
		// Empty cart button?
		$('#form_cart').submit(function() {
			setTimeout(refresh_cart, 600);
			return false;
		});
		function refresh_cart() {
			$('#sidebar_cart').load('/promotion/cart');
		};
	});
	</script>
	</body>
	</html>
{/case}
{/exp:switchee}