{!--
Site:          chrysalis-designs.com
Page:          promotion/promor
=================================================
ryan masuga, masugadesign.com
ryan@masugadesign.com | Copyright 2007-2013
================================================= --}
{exp:query sql="SELECT title, entry_id FROM exp_channel_titles WHERE channel_id = 2 AND url_title = '{segment_2}'"}
	{exp:stash:set name="stash_page_title"}{title}{/exp:stash:set}
	{exp:stash:set name="stash_entry_id"}{entry_id}{/exp:stash:set}
{/exp:query}

{snip_global_header}
{exp:stash:set name="stash_body_class"}promotion{/exp:stash:set}

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

{case value="thanks"}
<h3>Thank You!</h3>
<p>Thank you for your order! You should receive a confirmation message to the email address you supplied.</p>

<p>{lv_email_info}</p>
{/case}


{case value="checkout"}


	{exp:store:checkout
	next="/"
	return="/{segment_1}/{segment_2}/thanks"
	payment_method="manual"
	require="name|email|phone"
	error_handling="inline"
	error_delimiters='<span class="errors">|</span>'
	form_class="validation"}
		{if no_items}
			<h3>{exp:stash:get name="stash_page_title"}- Place Order</h3>
        	<h4>Your cart is empty!</h4>
        	<p><a href="/{segment_1}/{segment_2}"><< Back</a></p>
    	{/if}
		<h3>{exp:stash:get name="stash_page_title"} - Place Order</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"><a href="/{segment_1}/{segment_2}"><< Back to promotion</a></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_{exp:stash:get name="stash_entry_id"}_deliver_before}<input type="radio" class="radio deliver" name="order_custom1" value="Delivery - {lv_{exp:stash:get name="stash_entry_id"}_deliver_before}"> Delivery - {lv_{exp:stash:get name="stash_entry_id"}_deliver_before}<br>{/if}
					{if lv_{exp:stash:get name="stash_entry_id"}_pickup_before}<input type="radio" class="radio" name="order_custom1" value="Pick Up - {lv_{exp:stash:get name="stash_entry_id"}_pickup_before}" checked="checked"> Pick Up - {lv_{exp:stash:get name="stash_entry_id"}_pickup_before}<br>{/if}
					{if lv_{exp:stash:get name="stash_entry_id"}_deliver_day_of}<input type="radio" class="radio deliver" name="order_custom1" value="Delivery - {lv_{exp:stash:get name="stash_entry_id"}_deliver_day_of}"> Delivery - {lv_{exp:stash:get name="stash_entry_id"}_deliver_day_of}<br />{/if}
					{if lv_{exp:stash:get name="stash_entry_id"}_pickup_day_of}<input type="radio" class="radio" name="order_custom1" value="Pick Up - {lv_{exp:stash:get name="stash_entry_id"}_pickup_day_of}"> Pick Up - {lv_{exp:stash:get name="stash_entry_id"}_pickup_day_of}<br>{/if}
		    	</div>
		    </div>
		     <div class="row">
		    	<div class="label"></div>
		    	<div class="input"><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>
		    <div class="row">
		    	<div class="label"><label for="">Gift Card Message</label></div>
		    	<div class="input"><textarea type="text" name="order_custom5" value="{order_custom5}"></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"/>
    		<input type="hidden" name="order_custom6" value="{exp:stash:get name="stash_page_title"}"/>
    		<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|categories|category_fields"}
		{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}

<h3>Fulfillment Options</h3>
<p>
You can select your fullfillment option when placing your order on the following page.
</p>
<ul style="margin-left: 20px;">
{if lv_{exp:stash:get name="stash_entry_id"}_deliver_before != ''}
<li>Delivery - {lv_{exp:stash:get name="stash_entry_id"}_deliver_before}</li>
{/if}
{if lv_{exp:stash:get name="stash_entry_id"}_pickup_before != ''}
<li>Pick Up - {lv_{exp:stash:get name="stash_entry_id"}_pickup_before}</li>
{/if}
{if lv_{exp:stash:get name="stash_entry_id"}_deliver_day_of != ''}
<li>Delivery - {lv_{exp:stash:get name="stash_entry_id"}_deliver_day_of}</li>
{/if}
{if lv_{exp:stash:get name="stash_entry_id"}_pickup_day_of != ''}
<li>Pick Up - {lv_{exp:stash:get name="stash_entry_id"}_pickup_day_of}</li>
{/if}
</ul>
<br clear="all" />
</div>

		<div id="items">
		{exp:playa:children field="promotional_listings" status="open|Sold Out"}
			{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">
						{exp:channel_images:images entry_id="{entry_id}" limit="1"}
							{if "{image:width:full}" <= '80' && "{image:height:full}" <= '80'}
								<img src="{image:url:full}" width="80px" height="80px" alt="{embed:title}"/>
							{if:else}
								<a class="imgLink" href="{image:url:large}" rel="gallery">
									<div class="enlargeImg"></div>
									<img src="{image:url:full}" width="80px" height="80px" alt="{embed:title}"/>
								</a>
							{/if}
							{if image:no_images}
								<div style="height:80px;width:80px;float:left;">&nbsp;</div>
							{/if}
						{/exp:channel_images:images}
					</dd>

					<dd class="desc">{promo_shortdesc} - <span class="price">{price}{if promo_price_txt}/{promo_price_txt}{/if}</span></dd>
					{if total_stock != "0"}
						<dd class="amt">
							{!-- <input type="text" name="item_qty" class="item_qty" size="3" value="" />  --}
							<select name="item_qty" class="item_qty" style="width:50px;">
								<option value=""></option>
								<option value="1">1</option>
								<option value="2">2</option>
								<option value="3">3</option>
								<option value="4">4</option>
								<option value="5">5</option>
								<option value="6">6</option>
								<option value="7">7</option>
								<option value="8">8</option>
								<option value="9">9</option>
								<option value="10">10</option>
								<option value="11">11</option>
								<option value="12">12</option>
								option
							</select> {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}
		{extended}
	{/exp:channel:entries}
		</div>

		<div class="sidebar">
		{snip_global_sidebar_cart}
	<p id="checkout"><a href="/{segment_1}/{segment_2}/checkout">Place Order</a></p>
</div>

	{exp:stash:set name="close_footer"}no{/exp:stash:set}
	{snip_global_footer}
	<script type="text/javascript">
	$(document).ready(function() {
		// On change, send the qty to the cart
		$('.item_qty').change(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, 200);
		});
		// 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);
			//alert('val:'+qty);
			var promoitem = $(this).parents('.store_product_form');
			var url = promoitem.attr('action');
			var data = promoitem.serialize();
			$.post(url, data+'-'+qty);
			$(this).parents('.amt').removeClass('disabled');
			$(this).hide();
			$(this).siblings('.item_qty').val("");
			setTimeout(refresh_cart, 300);
			return false;
		});
		// Empty cart button?
		$('#form_cart').submit(function() {
			setTimeout(refresh_cart, 300);
			return false;
		});
		function refresh_cart() {
			$.ajax({
				url: '/promotion/cart',
				data: {},
				success: function(data) {
					$('#sidebar_cart').html(data);
					$('span#empty_cart form').attr('action', window.location.pathname);
					$('span#empty_cart input[name=return_url]').val(window.location.pathname);
				}
			});
		};
	});
	</script>
	</body>
	</html>
{/case}
{/exp:switchee}