{form->start name="formProductOptions" method="post" enctype="multipart/form-data" action="order/ajaxUpload/"}
{assign var="obj_prefix" value=$obj_prefix|default:''}
<div id="opt_{$obj_prefix}{$selectedProductID}" class="clearfix p-3">
	{foreach name="product_options" from=$customOption item="po"}
	{assign var="name" value=$po.inputType|cat:"_"}
	{assign var="selected_variant" value=""}
	<div class="opt-list clearfix" id="opt_{$obj_prefix}{$selectedProductID}_{$po.customOptionID}">
   
                                    <p class="label">
		{$po.customOptionName} {if $po.validateRule != ""}
		<span class="mndty">*</span>{/if}
		<span>{if $po.helpText}
		{include file="tooltip.tpl" tooltip=$po.helpText}{/if}</span></p>
		
		 <div class="custom-div">
		<!-- Color section start-->
		{if $po.inputType == "color"}{*color*}
			{if $po.variants}
			{assign var="option" value=""}
			{assign var="selected_variant" value=""}
			{foreach from=$po.variants item="vr" name=vars}
				{assign var="option" value=$option|cat:"~*"|cat:$vr.customOptionVariantID|cat:"->"|cat:$vr.value}
				{if $vr.priceDiff > 0}
					{assign var="priceDiff" value=$vr.priceDiff|price:'':$productDefaultCurrency:$productDefaultCurrency}
					{if $vr.priceDiffType == 'I'}
						{assign var="option" value=$option|cat:" ( + "|cat:$priceDiff|cat:" )"}
					{elseif $vr.priceDiffType == 'D'}
						{assign var="option" value=$option|cat:" ( - "|cat:$priceDiff|cat:" )"}
					{elseif $vr.priceDiffType == 'O'}
						{assign var="option" value=$option|cat:" ( "|cat:$priceDiff|cat:" )"}
					{/if}
				{/if}
				{if $vr.isDefault == 1}
					{assign var="selected_variant" value=$vr.customOptionVariantID}
				{/if}
			{/foreach}
			{if $selected_variant ==''}
				{assign var="option" value="->"|cat:$language.lblSelect|cat: $option}
			{else}
				{assign var="option" value=$option|substr:2}
			{/if}
			{assign var="customOptionID" value=$po.customOptionID}
			{if $po.validateRule != ""}
				{form->select 
					id="option_"|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
					class="listbox custom_option hide" 
					validate=$po.validateRule
					error=$po.validationMessage
					onchange="fn_change_options(this,'$selectedProductID', '$customOptionID','{$businessID}');"						
					options="$option"
					rel=$po.customOptionID
					validate_event="No"}
			{else}
				{form->select 
					id="option_"|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
					class="listbox custom_option hide" 
					onchange="fn_change_options(this,'$selectedProductID', '$customOptionID','{$businessID}');"						
					options="$option"
					rel=$po.customOptionID}
			{/if}
			{else}
				<input type="hidden" name="{$name}[{$selectedProductID}][product_options][{$po.customOptionID}]" value="{$po.customOptionVariantID}" id="option_{$obj_prefix}{$selectedProductID}_{$po.customOptionID}" />
				<span>-</span>
			{/if}
            <!-- color dropdown ends-->	
		{elseif $po.inputType == "select"} {*Selectbox*}
			{if $po.variants}
			{assign var="option" value=""}
			{assign var="selected_variant" value=""}
			{assign var="customOptionID" value=$po.customOptionID}
			{foreach from=$po.variants item="vr" name=vars}
				{assign var="option" value=$option|cat:"~*"|cat:$vr.customOptionVariantID|cat:"->"|cat:$vr.value}
				{if $vr.priceDiff > 0}
					{assign var="priceDiff" value=$vr.priceDiff|price:'':$productDefaultCurrency:$productDefaultCurrency}
					{if $vr.priceDiffType == 'I'}
						{assign var="option" value=$option|cat:" ( + "|cat:$priceDiff|cat:" )"}
					{elseif $vr.priceDiffType == 'D'}
						{assign var="option" value=$option|cat:" ( - "|cat:$priceDiff|cat:" )"}
					{elseif $vr.priceDiffType == 'O'}
						{assign var="option" value=$option|cat:" ( "|cat:$priceDiff|cat:" )"}
					{/if}
				{/if}
				{if $vr.isDefault == 1}
					{assign var="selected_variant" value=$vr.customOptionVariantID}
				{/if}
			{/foreach}
			{if $selected_variant ==''}
				{assign var="option" value="->"|cat:$language.lblSelect|cat: $option}
			{else}
				{assign var="option" value=$option|substr:2}
			{/if}
			
			{if $po.include_in_combination =='Yes'}
				{assign var="include_in_combination_class" value="inv_yes"}
			{else}
				{assign var="include_in_combination_class" value="inv_no"}
			{/if}
			
			{if $po.validateRule != ""}
				{form->select 
					id="option_"|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID  
					class="listbox custom_option $include_in_combination_class" 
					validate=$po.validateRule
					error=$po.validationMessage
					onchange="fn_change_options(this,'$selectedProductID', '$customOptionID','{$businessID}');"						
					options="$option"
					rel=$po.customOptionID
					validate_event="submit"}
			{else}
				{form->select 
					id="option_"|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
					class="listbox custom_option $include_in_combination_class" 
					onchange="fn_change_options(this,'$selectedProductID', '$customOptionID','{$businessID}');"						
					options="$option"
					rel=$po.customOptionID}
			{/if}
			{else}
				<input type="hidden" name="{$name}[{$selectedProductID}][product_options][{$po.customOptionID}]" value="{$po.customOptionVariantID}" id="option_{$obj_prefix}{$selectedProductID}_{$po.customOptionID}" />
				<span>-</span>
			{/if}
		{elseif $po.inputType == "multiselect"} {*Checkbox*}
		{assign var="customOptionID" value=$po.customOptionID}
			{if $po.variants}
					<ul id="option_{$obj_prefix}{$selectedProductID}_{$po.customOptionID}_group">
						{foreach from=$po.variants item="vr" key="key" name="vars"}
								<li><label id="option_description_{$obj_prefix}{$selectedProductID}_{$po.customOptionID}_{$vr.customOptionVariantID}" class="option-items">
								{if $po.validateRule != "" && $key==$po.variants|@count-1}
									{form->checkbox  
										name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
										id="option_"|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
										value=$vr.customOptionVariantID 
										class="checkbox custom_option"
										rel=$po.customOptionID
										onclick="fn_change_options(this,'$selectedProductID', '$customOptionID','{$businessID}');"
										validate=$po.validateRule
										error=$po.validationMessage
										validate_event="submit"}	
								{else}
									{form->checkbox  
										name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
										id="option_"|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
										value=$vr.customOptionVariantID 
										class="checkbox custom_option"
										rel=$po.customOptionID
										onclick="fn_change_options(this,'$selectedProductID', '$customOptionID','{$businessID}');"}
								{/if}
								{$vr.value}&nbsp;
								{if $vr.priceDiff > 0}
									{assign var="priceDiff" value=$vr.priceDiff|price:'':1:1}
									{if $vr.priceDiffType == 'I'}
										{" ( + "|cat:$priceDiff|cat:" )"}
									{elseif $vr.priceDiffType == 'D'}
										{" ( - "|cat:$priceDiff|cat:" )"}
									{elseif $vr.priceDiffType == 'O'}
										{" ( "|cat:$priceDiff|cat:" )"}
									{/if}
								{/if}
								</label>
								</li>
							{/foreach}
					</ul>
			{else}
				<input type="hidden" name="{$name}[{$selectedProductID}][product_options][{$po.customOptionID}]" value="{$vr.customOptionVariantID}" id="option_{$obj_prefix}{$selectedProductID}_{$po.customOptionID}" />
				<span>--</span>
			{/if}
		{elseif $po.inputType == "textbox"} {*Input*}
			{if $po.validateRule != ""}
				{form->textbox 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
					id="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
					validate=$po.validateRule
					error=$po.validationMessage
					class="custom_option textbox"
					rel=$po.customOptionID
					onblur="fn_change_options(this,'{$selectedProductID}', '{$po.customOptionID}','{$businessID}');"
					validate_event="submit"}
			{else}
				{form->textbox 
				name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
				id="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
				class="custom_option textbox"
				rel=$po.customOptionID
				onblur="fn_change_options(this,'{$selectedProductID}', '{$po.customOptionID}','{$businessID}');"}
			{/if}
			{if $po.priceDiff > 0}
				{assign var="priceDiff" value=$po.priceDiff|price:'':$productDefaultCurrency:$productDefaultCurrency}
				{if $po.priceDiffType == 'I'}
					{" ( + "|cat:$priceDiff|cat:" )"}
				{elseif $po.priceDiffType == 'D'}
					{" ( - "|cat:$priceDiff|cat:" )"}
				{elseif $po.priceDiffType == 'O'}
					{" ( "|cat:$priceDiff|cat:" )"}
				{/if}
			{/if}
		{elseif $po.inputType == "textarea"} {*Textarea*}
			{if $po.validateRule != ""}
				{form->textarea 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID  
					id="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
					rows="3" 
					cols="30"
					class="custom_option"
					validate=$po.validateRule
					error=$po.validationMessage
					rel=$po.customOptionID
					onblur="fn_change_options(this,'{$selectedProductID}', '{$po.customOptionID}','{$businessID}');"
					validate_event="submit"}
			{else}
				{form->textarea 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
					id="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
					rows="3" 
					cols="30"
					class="custom_option"
					rel=$po.customOptionID
					onblur="fn_change_options(this,'{$selectedProductID}', '{$po.customOptionID}','{$businessID}');"}

			{/if}
			{if $po.priceDiff > 0}
				{assign var="priceDiff" value=$po.priceDiff|price:'':$productDefaultCurrency:$productDefaultCurrency}
				{if $po.priceDiffType == 'I'}
					{" ( + "|cat:$priceDiff|cat:" )"}
				{elseif $po.priceDiffType == 'D'}
					{" ( - "|cat:$priceDiff|cat:" )"}
				{elseif $po.priceDiffType == 'O'}
					{" ( "|cat:$priceDiff|cat:" )"}
				{/if}
			{/if}
		{elseif $po.inputType == "file"} {*File*}
			{assign var="hasImageUpload" value=1}
			<div class="clearfix">
			{if $po.validateRule != ""}
				{form->upload 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
					id="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
					style="width:175px;" 
					validate_event="submit"
					class="custom_option fileUpload"
					rel=$po.customOptionID}
				{form->hidden class="hiddenField" name="fileUploadValidate_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID}
				{form->validate name="fileUploadValidate_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID validate="fileUploadValidate_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID|cat:"->"|cat:$po.validateRule error=$po.validationMessage}

			{else}
				{form->upload 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
					id="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
					style="width:175px;"
					class="custom_option fileUpload"
					rel=$po.customOptionID}
			{/if}
			{if $po.priceDiff > 0}
				{assign var="priceDiff" value=$po.priceDiff|price:'':$productDefaultCurrency:$productDefaultCurrency}
				{if $po.priceDiffType == 'I'}
					{" ( + "|cat:$priceDiff|cat:" )"}
				{elseif $po.priceDiffType == 'D'}
					{" ( - "|cat:$priceDiff|cat:" )"}
				{elseif $po.priceDiffType == 'O'}
					{" ( "|cat:$priceDiff|cat:" )"}
				{/if}
			{/if}
			{form->hidden name="uploadedImage_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID}
			<div id="file_name_option_{$obj_prefix}{$selectedProductID}_{$po.customOptionID}"></div>
			</div>
		{elseif $po.inputType == "datetime"} {*datetime*}
			{if $po.validateRule != ""}
				{form->textbox 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID  
					id="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
					readonly="readonly" 
					validate=$po.validateRule
					error=$po.validationMessage
					class="date_picker_field datetime_field custom_option "
					validate_event="submit"
					rel=$po.customOptionID
					onblur="fn_change_options(this,'{$selectedProductID}', '{$po.customOptionID}','{$businessID}');"}
			{else}
				{form->textbox 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
					id="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID  
					readonly="readonly" 
					rel=$po.customOptionID
					class="date_picker_field datetime_field custom_option"
					onblur="fn_change_options(this,'{$selectedProductID}', '{$po.customOptionID}','{$businessID}');"}
					
			{/if}
			{if $po.priceDiff > 0}
				{assign var="priceDiff" value=$po.priceDiff|price:'':$productDefaultCurrency:$productDefaultCurrency}
				{if $po.priceDiffType == 'I'}
					{" ( + "|cat:$priceDiff|cat:" )"}
				{elseif $po.priceDiffType == 'D'}
					{" ( - "|cat:$priceDiff|cat:" )"}
				{elseif $po.priceDiffType == 'O'}
					{" ( "|cat:$priceDiff|cat:" )"}
				{/if}
			{/if}
		{elseif $po.inputType == "date"} {*date*}
			{if $po.validateRule != ""}
				{form->textbox 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID  
					id="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
					readonly="readonly" 
					validate=$po.validateRule
					error=$po.validationMessage
					class="date_picker_field date_field custom_option"
					validate_event="submit"
					rel=$po.customOptionID
					onblur="fn_change_options(this,'{$selectedProductID}', '{$po.customOptionID}','{$businessID}');"}
			{else}
				{form->textbox 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
					id="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID  
					readonly="readonly" 
					rel=$po.customOptionID
					class="date_picker_field date_field custom_option"
					onblur="fn_change_options(this,'{$selectedProductID}', '{$po.customOptionID}','{$businessID}');"}
			{/if}
			{if $po.priceDiff > 0}
				{assign var="priceDiff" value=$po.priceDiff|price:'':$productDefaultCurrency:$productDefaultCurrency}
				{if $po.priceDiffType == 'I'}
					{" ( + "|cat:$priceDiff|cat:" )"}
				{elseif $po.priceDiffType == 'D'}
					{" ( - "|cat:$priceDiff|cat:" )"}
				{elseif $po.priceDiffType == 'O'}
					{" ( "|cat:$priceDiff|cat:" )"}
				{/if}
			{/if}
		{elseif $po.inputType == "time"} {*date*}
			{if $po.validateRule != ""}
				{form->textbox 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID  
					id="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID
					readonly="readonly" 
					validate=$po.validateRule
					error=$po.validationMessage
					class="date_picker_field time_field custom_option"
					validate_event="submit"
					rel=$po.customOptionID
					onblur="fn_change_options(this,'{$selectedProductID}', '{$po.customOptionID}','{$businessID}');"}
			{else}
				{form->textbox 
					name="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID 
					id="option_"|cat:$obj_prefix|cat:$selectedProductID|cat:"_"|cat:$po.customOptionID  
					readonly="readonly" 
					rel=$po.customOptionID
					class="date_picker_field time_field custom_option"
					onblur="fn_change_options(this,'{$selectedProductID}', '{$po.customOptionID}','{$businessID}');"}
			{/if}
			{if $po.priceDiff > 0}
				{assign var="priceDiff" value=$po.priceDiff|price:'':$productDefaultCurrency:$productDefaultCurrency}
				{if $po.priceDiffType == 'I'}
					{" ( + "|cat:$priceDiff|cat:" )"}
				{elseif $po.priceDiffType == 'D'}
					{" ( - "|cat:$priceDiff|cat:" )"}
				{elseif $po.priceDiffType == 'O'}
					{" ( "|cat:$priceDiff|cat:" )"}
				{/if}
			{/if}	
		{/if}
        {if $po.variants|@count>0}
			<div class="img-listing">
				{foreach from=$po.variants item="var"}
                	{if $var.variantThumbImage}
					<span class="custom-imag-list">	<img src="{$view_public_path}/uploads/catalog/custom-option-variant/{$var.variantThumbImage}" 
						width="20" height="20" alt="image"
						class="object-image hand"
						id="variant_thumb_image_{$var.customOptionVariantID}"
						onclick="fn_set_options(this,'{$selectedProductID}', '{$po.customOptionID}','{$var.customOptionVariantID}','{$businessID}');"
						/></span>
						{/if}
				{/foreach}
                </div>
                {/if}
			</div>
			{if $po.validateRule != ""}
				{if $po.inputType == "file"}
					<script type="text/javascript">	
						$(document).ready(function(){ 
						$('.add_to_cart_details').bindFirst('click', function ()
						{ 
							$('#option_{$obj_prefix}{$selectedProductID}_{$po.customOptionID}').validate( 
							{ form : "formProductOptions" , field : "fileUploadValidate_{$obj_prefix}{$selectedProductID}_{$po.customOptionID}" , key : "{$po.validateRule}" , error: "{$po.validationMessage}", inline:"1" , group: "", row: ""} );
							});
						});
					</script>				
				{else}
					<script type="text/javascript">	
						$(document).ready(function(){ 
						$('.add_to_cart_details').bindFirst('click', function ()
						{ 
							$('#option_{$obj_prefix}{$selectedProductID}_{$po.customOptionID}').validate( 
							{ form : "formProductOptions" , field : "option_{$obj_prefix}{$selectedProductID}_{$po.customOptionID}" , key : "{$po.validateRule}" , error: "{$po.validationMessage}", inline:"1" , group: "", row: ""} );
							});
						});
					</script>
				{/if}
			{/if}
	</div>{/foreach}
    <div class="opt-list clearfix"> <p class="label">&nbsp;</p>
     <div class="custom-div">
	{form->button name="add_to_cart_details" class="button04 add_to_cart_details buynow-btn" rel=$productOptionID id="add_to_cart_"|cat:$productOptionID value="Add" busid="{$businessID}"} </div>
	<span id="stock-not-avilable" class="stock-not-avilable" style="display:none;">No Stock</span>
	</div>




{form->submit name="productOptionsSubmit" class="hide"} 
{form->hidden name="currentTime"}
{form->hidden name="selectedProductOption" value=$productOptionID}

{if $hasImageUpload|default:0>0}
	{form->hidden name="hasImageUpload" value=1}
{else}
	{form->hidden name="hasImageUpload" value=0}
{/if}	
{form->close}
<script type="text/javascript">	
var encodedCustomOption = {$encodedCustomOption};
var selectedProductID = {$selectedProductID};
var productCurrency = {$productDefaultCurrency};
var encodedCombinations = {$encodedCombinations};
var optionBasePrice = {$optionBasePrice};
var InventoryTrackLevel = '{$InventoryTrackLevel}';

$(document).ready(function(){
fn_change_options('',{$selectedProductID},'',{$businessID});
var currDate = new Date;
	currDate.setHours(00);
	currDate.setMinutes(00);
	var tpEnd;
	var tpExpiry;
	tpEnd = currDate;
	$('.datetime_field').datetimepicker({
			minDate: tpEnd,
			dateFormat:datePickerDateFormat,
			currentText:lblCurrentMonth
		});
	$('.date_field').datepicker({
		minDate: tpEnd,
		showTime: false,
		dateFormat:datePickerDateFormat
	});
	$('.time_field').timepicker({
                ampm: false,
                stepMinute: 15,
                onSelect: function (dateText, inst) {
                }
            });
			
	$('#formProductOptions').ajaxForm({
		beforeSend: function() {
		},
		complete: function(xhr) {
			userUploadedImageArray = xhr.responseText;
			var JSONuserUploadedImageArray = JSON.parse(userUploadedImageArray);
			if(JSONuserUploadedImageArray.isError=='Yes' && typeof JSONuserUploadedImageArray != 'null')
			{
				jNotifyShow(JSONuserUploadedImageArray.errorMessage,"cart_message", "message_error");
				return true;
			}
			else
			{
				buynow_link(buyNoeButtonThisElm);
			}
		}
	});		
	
});
</script>