<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
	<div class="breadcrumb">
		<?php foreach ($breadcrumbs as $breadcrumb) { ?>
		<?php echo $breadcrumb['separator']; ?>
		<a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?>
		</a>
		<?php } ?>
	</div>
	<div class="osc-block">
		<div class="osc-content" style="<?php echo (!empty($style_div))? $style_div : '' ;?>">
			<div class="osc-header">
				<h1><?php echo $text_express_checkout; ?></h1>
				<h2><?php echo $text_header_info; ?></h2>
				<?php if (!$is_logged) {?>
				<a class="osc-log-link" href="#osc-login"><?php echo $text_alredy_registred; ?>
				</a>
				<?php }?>
			</div>
			<div class="osc-blocks">
				<div class="osc-left">
					<h1>
						<?php echo $text_your_details; ?>
					</h1>
					<div class="osc-personal" id="osc-personal">
						<div class="osc-two-inp">
							<div class="inp-1">
								<label><span class="required">*</span> <?php echo $entry_firstname; ?>
								</label><input type="text" value="<?php echo $firstname; ?>"
									name="firstname"
								/>
							</div>
							<div class="inp-2">
								<label><span class="required">*</span> <?php echo $entry_lastname; ?>
								</label> <input type="text" value="<?php echo $lastname; ?>"
									name="lastname"
								/>
							</div>
							<div class="clear"></div>
						</div>
						<div class="osc-two-inp">
							<div class="inp-1">
								<label><span class="required">*</span> <?php echo $entry_email_address; ?>
								</label> <input type="text" name="email"
									value="<?php echo $email; ?>"
								/>
							</div>
							<div class="inp-2">
								<label><span class="required">*</span> <?php echo $entry_telephone; ?>
								</label> <input type="text" name="telephone"
									value="<?php echo $telephone; ?>"
								/>
							</div>
							<div class="clear"></div>
						</div>
						<div class="osc-one-inp">
							<label><span class="required">*</span> <?php echo $entry_address_1; ?>
							</label> <input type="text" name="address_1"
								value="<?php echo $address_1; ?>"
							/>
						</div>
						<div class="osc-two-inp">
							<div class="inp-1">
								<label><?php echo $entry_address_2; ?> </label> <input
									type="text" name="address_2" value="<?php echo $address_2; ?>"
								/>
							</div>
							<div class="inp-2">
								<label><?php echo $entry_fax; ?> </label> <input type="text"
									name="fax" value="<?php echo $fax; ?>"
								/>
							</div>
							<div class="clear"></div>
						</div>
						<div class="osc-two-inp">
							<div class="inp-1">
								<label><span class="required">*</span> <?php echo $entry_city; ?>
								</label> <input type="text" name="city"
									value="<?php echo $city; ?>"
								/>
							</div>
							<div class="inp-2">
								<label><span class="required">*</span> <?php echo $entry_postcode; ?> </label> <input
									type="text" name="postcode" value="<?php echo $postcode; ?>"
								/>
							</div>
							<div class="clear"></div>
						</div>
						<div class="osc-one-inp">
							<label><?php echo $entry_company; ?> </label> <input type="text"
								name="company" value="<?php echo $company; ?>"
							/>
						</div>
						<div class="osc-check-manage" style="display: <?php echo (count($customer_groups) > 1 ? 'block' : 'none'); ?>;"> <?php echo $entry_customer_group; ?>
						<?php foreach ($customer_groups as $customer_group) { ?>
								    <?php if ($customer_group['customer_group_id'] == $customer_group_id) { ?>
								  <div>
								    <input type="radio" name="customer_group_id" value="<?php echo $customer_group['customer_group_id']; ?>" id="customer_group_id<?php echo $customer_group['customer_group_id']; ?>" checked="checked" />
								    <label for="customer_group_id<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></label>
								    <div class="clear"></div>
								  </div>
								    <?php } else { ?>
								  <div>
								    <input type="radio" name="customer_group_id" value="<?php echo $customer_group['customer_group_id']; ?>" id="customer_group_id<?php echo $customer_group['customer_group_id']; ?>" />
								    <label for="customer_group_id<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></label>
								    <div class="clear"></div>
								  </div>
								    <?php } ?>

								    <?php } ?>
				   	</div>
					<div class="osc-two-inp">
							<div id="company-id-display" class="inp-1">
								<label><span id="company-id-required" class="required">* </span><?php echo $entry_company_id; ?> </label>
								 <input type="text" name="company_id" value="<?php echo $company_id; ?>" />
							</div>
							<div id="tax-id-display" class="inp-2">
								<label><span id="tax-id-required" class="required">* </span><?php echo $entry_tax_id; ?> </label>
								<input type="text" name="tax_id" value="<?php echo $tax_id; ?>" />
							</div>
							<div class="clear"></div>
						</div>
						<div class="osc-one-inp">
							<label><span class="required">*</span> <?php echo $entry_country; ?>
							</label> <select name="country_id">
								<option value="">
									<?php echo $text_select; ?>
								</option>
								<?php foreach ($countries as $country) { ?>
								<?php if ($country['country_id'] == $country_id) { ?>
								<option value="<?php echo $country['country_id']; ?>"
									selected="selected"
								>
									<?php echo $country['name']; ?>
								</option>
								<?php } else { ?>
								<option value="<?php echo $country['country_id']; ?>">
									<?php echo $country['name']; ?>
								</option>
								<?php } ?>
								<?php } ?>
							</select>
						</div>
						<div class="osc-one-inp">
							<label><span class="required">*</span> <?php echo $entry_zone; ?>
							</label> <select name="zone_id">
								<?php echo $zone_html; ?>
							</select>
						</div>
						<div class="osc-check-manage">
							<div>
								<input type="checkbox" name="use_ship" checked="checked"
									value="1"
								/> <span><?php echo $text_ckb_delivery; ?> </span>
                                                             
							</div>
							<div class="osc-one-inp use-ship-sel">
								<span class="title"><span class="required">*</span> <?php echo $text_delivery_addresses; ?>
								</span> <select name="address_delivery_id">
									<option value="---">
										<?php echo $text_select; ?>
									</option>
									<?php if($shipping_addresses) { ?>
									<?php foreach ($shipping_addresses as $key => $address) { ?>
									<?php if ($key == $selected_shipping ) { ?>
									<option value="<?php echo $key; ?>" selected="selected">
										<?php echo $address['name']; ?>
									</option>
									<?php } else { ?>
									<option value="<?php echo $key; ?>">
										<?php echo $address['name']; ?>
									</option>
									<?php } ?>
									<?php } ?>
									<?php } ?>
									<option value="0">
										<?php echo $text_address_new; ?>
									</option>
								</select>
							</div>
							<div>
								<input type="checkbox" name="use_bill" checked="checked"
									value="1"
								/> <span><?php echo $text_ckb_billing; ?> </span>
                                                                
							</div>
							<div class="osc-one-inp use-bill-sel">
								<span class="title"><span class="required">*</span> <?php echo $text_billing_adresses; ?>
								</span> <select name="address_billing_id">
									<option value="---">
										<?php echo $text_select; ?>
									</option>
									<?php if($payment_addresses) { ?>
									<?php foreach ($payment_addresses as $key => $address) { ?>
									<?php if ($key == $selected_payment) { ?>
									<option value="<?php echo $key; ?>" selected="selected">
										<?php echo $address['name']; ?>
									</option>
									<?php } else { ?>
									<option value="<?php echo $key; ?>">
										<?php echo $address['name']; ?>
									</option>
									<?php } ?>
									<?php } ?>
									<?php } ?>
									<option value="0">
										<?php echo $text_address_new; ?>
									</option>
								</select>
							</div>
							<?php if (!$is_logged) { ?>
							 <div>
								<input type="checkbox" name="new_account" value="0" /><span><?php echo $text_create_account; ?>
								</span>
                                                                  
							</div>
							<div style="display: none;" id="new_account_form">
								<div class="osc-two-inp">
									<div class="inp-1">
										<label><?php echo $entry_password; ?> </label> <input
											type="password" name="password"
										/>
									</div>
									<div class="inp-2">
										<label><?php echo $entry_confirm; ?> </label> <input
											type="password" name="confirm"
										/>
									</div>
									<div class="clear" ></div>
								</div>
								<div class="osc-check-manage">
									<div>
										<input type="checkbox" name="newsletter" value="0"
											id="newsletter"
										/> <label for="newsletter"><?php echo $entry_newsletter; ?> </label>
									</div>
									<div class="osc-account-agree" >
										<?php if ($account_text_agree) { ?>
										<?php if ($account_agree) { ?>
										<input type="checkbox" name="account_agree" value="1" checked="checked" />
										<?php } else { ?>
										<input type="checkbox" name="account_agree" value="0" />
										<?php } ?>
										<label><?php echo $account_text_agree; ?> </label>
										<?php } ?>
								    </div>
								</div>
							</div>
							<?php }?>
						</div>
					</div>
				</div>

				<div class="osc-right">
					<div class="ship_payment_block">
					    <div class="inRL">
					        <h1 class="osc-step-2">
									<?php echo $text_shipping_meth;?>
								</h1>
								<div id="osc-shipping-data">
									<span class="osc-load"></span>
									<div class="content_shipping_meth"></div>
								</div>
					    </div>
					    <div class="rightInTwo">
					       <h1>
									<?php echo $text_payment_meth; ?>
								</h1>
								<div id="osc-payment-data">
									<span class="osc-load"></span>
									<div class="content_payment_meth"></div>
								</div>
					    </div>
					    <div class="clear" ></div>
				   </div >
					<div class="twoCol">
						   	<h1>
									<?php echo $text_confirm_order; ?>
								</h1>
								<div id="osc-summary-data">
									<span class="osc-load"></span>
									<div class="content_summary_meth"></div>
								</div>
								<div class="colCh osc-block-comment">
								<input type="checkbox" name="osc-use-comment" value="0" /><label><?php echo $text_comments; ?>
								</label>
								<div class="clear" ></div>
								 <div class="osc-comment" >
								     <textarea id="osc-comment" name="comment" rows="8" style="width: 98%;"><?php echo $comment; ?></textarea>
								   </div>
							     </div>
								 <?php if ($coupon_status) { ?>
								<div class="colCh">
									<input type="checkbox" name="osc-use-coupon" /> <label><?php echo $text_use_coupon; ?>
									</label>
									
									<div class="osc-coupon">
										<span><?php echo $entry_coupon; ?> </span> <input type="text"
											name="coupon" value="<?php echo $coupon; ?>"
										/> <input id="osc-coupon-btn" class="osc-btn" type="button"
											value="Apply Coupon"
										/>
									</div>
								</div> <?php } ?> <?php if ($voucher_status) { ?>
								<div class="colCh">
									<input type="checkbox" name="osc-use-voucher" /> <label><?php echo $text_use_voucher; ?>
									</label>
									<div class="osc-voucher">
										<span><?php echo $entry_voucher; ?> </span> <input type="text"
											name="voucher" value="<?php echo $voucher; ?>"
										/> <input id="osc-voucher-btn" class="osc-btn" type="button"
											value="Apply Voucher"
										/>
									</div>
								</div> <?php } ?> <?php if ($reward_status) { ?>
								<div class="colCh">
									<input type="checkbox" name="osc-use-reward" /> <label><?php echo $text_use_reward; ?>
									</label>
									<div class="osc-reward">
										<span><?php echo $entry_reward; ?> </span> <input type="text"
											name="reward" value="<?php echo $reward; ?>"
										/> <input id="osc-reward-btn" class="osc-btn" type="button"
											value="Apply Reward"
										/>
									</div>
								</div> <?php } ?>
								<div class="colCh osc-terms-link">
									<?php if ($checkout_text_agree) { ?>
									<?php if ($checkout_agree) { ?>
									<input id="checkout_agree"  type="checkbox" name="checkout_agree" value="1" checked="checked" />
									<?php } else { ?>
									<input type="checkbox" name="checkout_agree" value="0" />
									<?php } ?>
									<label for="checkout_agree"><?php echo $checkout_text_agree; ?> </label>
									<?php } ?>
								</div>

								 <!--                                        <a class="osc-new-delivery" href="#osc-new-delivery">New address.</a>-->
								<div id="osc-pay-btn">
									<span class="osc-wait" style="float: left;"></span>
									<a class="osc-btn" href="#"><?php echo $order_now; ?></a>
									
									<div class="clear" ></div>
								</div>
				      </div>
				</div>
				<div class="clear" ></div>

			</div>
		 </div>

		</div>
		<!--------------------------------------------------->
		<div style="display: none">
			<div id="payment_html"></div>
			<div id="osc-login">
				<h2>LOGIN</h2>
				<div>
					<div class="osc-log-item">
						<label><?php echo $entry_email; ?> </label> <input type="text"
							name="email" value=""
						/>
					</div>
					<div class="osc-log-item">
						<label><?php echo $entry_password; ?> </label> <input
							type="password" name="password" value=""
						/>
					</div>
					<div class="osc-log-btn">
						<a class="osc-forg-link" href="#osc-forgoten"><?php echo $text_forgotten; ?>
						</a> <input type="button" value="<?php echo $button_login; ?>"
							id="osc-login-btn" class="osc-btn"
						/>
					</div>
				</div>
			</div>
			<div id="osc-forgoten">
				<form action="<?php echo $action; ?>" method="post"
					enctype="multipart/form-data"
				>
					<h2>
						<?php echo $text_your_email; ?>
					</h2>
					<div>
						<p>
							<?php echo $text_email; ?>
						</p>
						<div class="osc-log-item">
							<label><?php echo $entry_email; ?> </label> <input type="text"
								name="email" value=""
							/>
						</div>
					</div>
					<div class="osc-forg-btn">
						<a href="#osc-login" class="osc-btn" id="osc-back-btn"><?php echo $button_back; ?>
						</a> <input type="submit" value="<?php echo $button_continue; ?>"
							id="osc-forg-btn" class="osc-btn"
						/>
					</div>
				</form>
			</div>
			<div id="osc-new-delivery">
				<h2>
					<?php echo $text_delivery_addresses; ?>
				</h2>
				<div class="osc-two-inp">
					<div class="inp-1"><label><span class="required">*</span> <?php echo $entry_firstname; ?>
							</label><input type="text" name="shipping[firstname]" />
					</div>
					 <div class="inp-2"><label><span class="required">*</span> <?php echo $entry_lastname; ?>
							</label> <input type="text" name="shipping[lastname]" />
					</div>
				    <div class="clear" ></div>
				</div>
				<div class="osc-two-inp">
					<div class="inp-1"><label><span class="required">*</span> <?php echo $entry_email_address; ?>
							</label> <input type="text" name="shipping[email]" />
					</div>
					<div class="inp-2"><label><span class="required">*</span> <?php echo $entry_telephone; ?>
							</label> <input type="text" name="shipping[telephone]" />
					</div>
					<div class="clear" ></div>
				</div>
				<div class="osc-one-inp">
					<label><span class="required">*</span> <?php echo $entry_address_1; ?>
					</label> <input type="text" name="shipping[address_1]" />
				</div>
				<div class="osc-one-inp">
					<label><?php echo $entry_address_2; ?> </label> <input type="text"
						name="shipping[address_2]"
					/>
				</div>
				<div class="osc-two-inp">
					<div class="inp-1"><label><span class="required">*</span> <?php echo $entry_city; ?>
							</label> <input type="text" name="shipping[city]" />
				    </div>
					<div class="inp-2"><label><?php echo $entry_postcode; ?> </label>
								<input type="text" name="shipping[postcode]" />
					</div>
					<div class="clear" ></div>
				</div>
				<div class="osc-one-inp">
					<label><?php echo $entry_company; ?> </label> <input type="text"
						name="shipping[company]"
					/>
				</div>
				<div class="osc-one-inp">
					<label><span class="required">*</span> <?php echo $entry_country; ?>
					</label> <select name="shipping[country_id]">
						<option value="">
							<?php echo $text_select; ?>
						</option>
						<?php foreach ($countries as $country) { ?>
						<?php if ($country['country_id'] == $country_id) { ?>
						<option value="<?php echo $country['country_id']; ?>"
							selected="selected"
						>
							<?php echo $country['name']; ?>
						</option>
						<?php } else { ?>
						<option value="<?php echo $country['country_id']; ?>">
							<?php echo $country['name']; ?>
						</option>
						<?php } ?>
						<?php } ?>
					</select>
				</div>
				<div class="osc-one-inp">
					<label><span class="required">*</span> <?php echo $entry_zone; ?> </label>
					<select name="shipping[zone_id]"></select>
				</div>
				<input id="osc-new-delivery-btn" class="osc-btn" type="button"
					value="<?php echo $button_continue; ?>"
				/><span class="osc-wait"></span>
				<div style="clear: both;"></div>
			</div>
			<div id="osc-new-billing">
				<h2>
					<?php echo $text_billing_adresses; ?>
				</h2>
				<div class="osc-two-inp">
					<div class="inp-1"><label><span class="required">*</span> <?php echo $entry_firstname; ?>
							</label><input type="text" name="payment[firstname]" />
					</div>
					<div class="inp-2"><label><span class="required">*</span> <?php echo $entry_lastname; ?>
							</label> <input type="text" name="payment[lastname]" />
					</div>
					<div class="clear" ></div>
				</div>
				<div class="osc-two-inp">
					<div class="inp-1"><label><span class="required">*</span> <?php echo $entry_email_address; ?>
							</label> <input type="text" name="payment[email]" />
					</div>
					<div class="inp-2"><label><span class="required">*</span> <?php echo $entry_telephone; ?>
							</label> <input type="text" name="payment[telephone]" />
					</div>
					<div class="clear" ></div>
				</div>
				<div class="osc-one-inp">
					<label><span class="required">*</span> <?php echo $entry_address_1; ?>
					</label> <input type="text" name="payment[address_1]" />
				</div>
				<div class="osc-one-inp">
					<label><?php echo $entry_address_2; ?> </label> <input type="text"
						name="payment[address_2]"
					/>
				</div>
				<div class="osc-two-inp">
					<div class="inp-1"><label><span class="required">*</span> <?php echo $entry_city; ?>
							</label> <input type="text" name="payment[city]" />
				    </div>
					<div class="inp-2"><label><?php echo $entry_postcode; ?> </label>
								<input type="text" name="payment[postcode]" />
					</div>
					<div class="clear" ></div>
				</div>
				<div class="osc-one-inp">
					<label><?php echo $entry_company; ?> </label> <input type="text"
						name="payment[company]"
					/>
				</div>
				<div class="osc-one-inp">
					<label><span class="required">*</span> <?php echo $entry_country; ?>
					</label> <select name="payment[country_id]">
						<option value="">
							<?php echo $text_select; ?>
						</option>
						<?php foreach ($countries as $country) { ?>
						<?php if ($country['country_id'] == $country_id) { ?>
						<option value="<?php echo $country['country_id']; ?>"
							selected="selected"
						>
							<?php echo $country['name']; ?>
						</option>
						<?php } else { ?>
						<option value="<?php echo $country['country_id']; ?>">
							<?php echo $country['name']; ?>
						</option>
						<?php } ?>
						<?php } ?>
					</select>
				</div>
				<div class="osc-one-inp">
					<label><span class="required">*</span> <?php echo $entry_zone; ?> </label>
					<select name="payment[zone_id]"></select>
				</div>
				<input id="osc-new-billing-btn" class="osc-btn" type="button"
					value="<?php echo $button_continue; ?>"
				/><span class="osc-wait"></span>
				<div style="clear: both;"></div>
			</div>
		</div>
		<!--------------------------------->
                  <?php echo $content_bottom; ?>
	</div>
	<?php echo $footer; ?>
	<script type="text/javascript">
	var form_delivery = <?php echo $form_dell; ?>;
	var count_dell = Object.keys(form_delivery).length;

    console.log(count_dell)

    var form_billing = <?php echo $form_bill; ?>;
    var count_bill=Object.keys(form_billing).length;;

    function update_three_block(type){

			var  post_data = {
	                        'country_id': $('select[name=\'country_id\']').val(),
	                        'zone_id' :$('select[name=\'zone_id\']').val(),
                                'postcode' : $('input[name=\'postcode\']').val()
	                         }


			if(!$('input[name=\'use_ship\']').is(':checked')){
		    	 if (($('select[name="address_delivery_id"]').val()!=null)&&($('select[name="address_delivery_id"]').val()!="---")&&($('select[name="address_delivery_id"]').val()!='0')){
		    		 post_data["address_delivery_id"] = $('select[name="address_delivery_id"]').val();
		    	      }
			}

			 if(!$('input[name=\'use_bill\']').is(':checked')){
			     if (($('select[name="address_billing_id"]').val()!=null)&&($('select[name="address_billing_id"]').val()!="---")&&($('select[name="address_billing_id"]').val()!='0')){
			    	  post_data["address_billing_id"] = $('select[name="address_billing_id"]').val();
			       }
			 }



                                  post_data["type"] = type;
                                  post_data["shipping_method"] =  $('#osc-shipping-data input[type=\'radio\']:checked').val();
                                  post_data["payment_method"] =  $('#osc-payment-data input[type=\'radio\']:checked').val();


                $.ajax({
                    url: 'index.php?route=checkout/checkout/get_methods',
                    type: 'post',
                    data: post_data,
                    dataType: 'json',
                    beforeSend: function() {


                        if (type==2){
                        $('#osc-payment-data .osc-load').show();
                        $('#osc-summary-data .osc-load').show();
                        $('#osc-payment-data .content_payment_meth').html("");
                        $('#osc-summary-data .content_summary_meth').html("");
                        } else {
                            if (type==1){
                              $('#osc-summary-data .osc-load').show();
                              $('#osc-summary-data .content_summary_meth').html("");
                            } else {
                             $('#osc-shipping-data .osc-load').show();
                             $('#osc-payment-data .osc-load').show();
                             $('#osc-summary-data .osc-load').show();
                             $('#osc-shipping-data .content_shipping_meth').html("");
                             $('#osc-payment-data .content_payment_meth').html("");
                             $('#osc-summary-data .content_summary_meth').html("");
                         }
                        }


                        $('.osc-error').remove();

                    },
                    complete: function() {
                        $('#osc-shipping-data .osc-load').hide();
                        $('#osc-payment-data .osc-load').hide();
                        $('#osc-summary-data .osc-load').hide();
                    },
                    success: function(json) {
                     if (type==2){
                        $('#osc-payment-data .content_payment_meth').html(json['payment_method']);
                           $('#osc-summary-data .content_summary_meth').html(json['confirm_order']);
                     }
                     else {
                      if (type==1){
                            $('#osc-summary-data .content_summary_meth').html(json['confirm_order']);
                          } else {
                           $('#osc-shipping-data .content_shipping_meth').html(json['shipping_method']);
                           $('#osc-payment-data .content_payment_meth').html(json['payment_method']);
                           $('#osc-summary-data .content_summary_meth').html(json['confirm_order']);
                          }
                         }

                    },
                    error: function(xhr, ajaxOptions, thrownError) {
//                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });

     	   }
  	   function country_select(country_obj,sel_obj,refresh_blocks){
  		   if (this.value == ''){
                  html = '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
                  sel_obj.html(html);

                  return
              }

              $.ajax({
                  url: 'index.php?route=checkout/checkout/country&country_id=' + country_obj.value,
                  dataType: 'json',
                  beforeSend: function() {
                      $(this).after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
                      $('#osc-new-delivery span.osc-wait').show();
                      $('#osc-new-billing span.osc-wait').show();
                   },
                  complete: function() {
                      $('.wait').remove();
                      $('#osc-new-delivery span.osc-wait').hide();
                      $('#osc-new-billing span.osc-wait').hide();
                  },
                  success: function(json) {
                      if (json['postcode_required'] == '1') {
                          $('#payment-postcode-required').show();
                      } else {
                          $('#payment-postcode-required').hide();
                      }

                      if (json['zone'] != '') {
                          //  html = '<option value=""><?php echo $text_select; ?></option>';
                          html = '<option value="' + json['zone'][0]['zone_id'] + '"';
                          html += ' selected="selected"';
                          for (i = 1; i < json['zone'].length; i++) {
                              html += '<option value="' + json['zone'][i]['zone_id'] + '"';

                              if (json['zone'][i]['zone_id'] == '<?php echo $zone_id; ?>') {
                                  html += ' selected="selected"';
                              }

                              html += '>' + json['zone'][i]['name'] + '</option>';
                          }
                      } else {
                          html = '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
                      }

                      sel_obj.html(html);
                      if(refresh_blocks){
                          update_three_block();
                      }
                  },
                  error: function(xhr, ajaxOptions, thrownError) {
//                      alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                  }
              });
//              if(refresh_blocks){
//                          update_three_block();
//                      }
          }

			  function closePopup(type){
                          $('#osc-new-delivery .osc-error').remove();
                         $('#osc-new-billing .osc-error').remove();
				 	if(type=="dell"){
			    	   if (form_delivery !=null){

			    		 html =' <option value="---" selected="selected"><?php echo $text_select; ?></option>';
						  		 for(var key in form_delivery){
						  			if (count_dell==Object.keys(form_delivery).length){
						          	 html += "<option value='" + key + "' >" + form_delivery[key] +"</option>";
						  			 } else {
						  				 html += "<option value='" + key + "' selected='selected' >" + form_delivery[key] +"</option>";
							  			 }
						  		     }
				  		 html +='<option value="0"><?php echo $text_address_new; ?></option>';
				  		 $('select[name="address_delivery_id"]').html(html);
				  		// console.log(count_dell);
					  		if (count_dell!=Object.keys(form_delivery).length){
						  			count_dell = Object.keys(form_delivery).length;
						  			$('select[name="address_delivery_id"]').trigger('change');
						  		}
				  		    }else{
				  		    	$('select[name="address_delivery_id"]').val('---');
				  		   		 }

				 	} else if(type=="bill") {
			           if (form_billing !=null){
			      		 html =' <option value="---"><?php echo $text_select; ?></option>';

					  	  		 for(var key in form_billing){
					  	  			if (count_dell==Object.keys(form_billing).length){
					  	      		 html += "<option value='" + key + "'>" + form_billing[key] + "</option>";
					  	  			} else {
					  	  			 html += "<option value='" + key + "' selected='selected'>" + form_billing[key] + "</option>";
					  	  	  			}
					  	  		   }
			    	  		 html +='<option value="0"><?php echo $text_address_new; ?></option>';
			 	  	         $('select[name="address_billing_id"]').html(html);

			 	  	      if (count_bill!=Object.keys(form_billing).length){

			 	  	    		count_bill = Object.keys(form_billing).length;

			 		  			$('select[name="address_billing_id"]').trigger('change');
			 			  		}

			             	}else{
			             		$('select[name="address_billing_id"]').val('---');
			             		}
				 	    }

			           }

        $(document).ready(function() {
            $(".osc-log-link, .osc-forg-link, #osc-back-btn").colorbox({
                inline : true,
                width : 350,
                opacity : "0.5"
            });

            $(".colorbox").colorbox({
                width : 500,
                opacity: "0.5"
            });
            // Login
            $('#osc-login-btn').on('click', function() {
                $.ajax({
                    url: 'index.php?route=checkout/login/validate',
                    type: 'post',
                    data: $('#osc-login :input'),
                    dataType: 'json',
                    beforeSend: function() {
                        $('#osc-login-btn').attr('disabled', true);
                        $('#osc-login-btn').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
                    },
                    complete: function() {
                        $('#osc-login-btn').attr('disabled', false);
                        $('.wait').remove();
                    },
                    success: function(json) {
                        $('.warning, .error').remove();

                        if (json['redirect']) {
                            location = json['redirect'];
                        } else if (json['error']) {
                            $('#osc-login > div').prepend('<div class="warning" style="display: none;">' + json['error']['warning'] + '</div>');

                            $('.warning').fadeIn('slow');
                           
                           $.colorbox({opacity : "0.5", inline:true, href:"#osc-login"});
                           }
                        
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
//                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });

          /* $('select[name=\'zone_id\']').bind('change', function() {
                    $('select[name=\'country_id\']').trigger('change');
            });
*/



            $('select[name=\'country_id\']').bind('change', function() {
                var flag = false;
               if(($('input[name=\'use_ship\']').is(':checked'))||($('input[name=\'use_bill\']').is(':checked'))){
  			    	flag = true;
  					  } else {
  				     if(($('select[name="address_billing_id"]').val()=="---")||($('select[name="address_delivery_id"]').val()=="---")){
					        	flag = true;
						        }
  	  					  }

            	country_select(this,$('select[name=\'zone_id\']'),flag);
            	});

            $('select[name=\'shipping[country_id]\']').bind('change', function() {
            	country_select(this,$('select[name=\'shipping[zone_id]\']'));
            	});
            $('select[name=\'payment[country_id]\']').bind('change', function() {
            	country_select(this,$('select[name=\'payment[zone_id]\']'));

            	});

            $('input[name="new_account"]').on('click', function(){
                if(this.checked)
                {
                	$(this).val("1");
                    $('div#new_account_form').show();
                }
                else{
                	   $(this).val("0");
                       $('div#new_account_form').hide();
                }
            });

            $('input[name="use_ship"]').on('change', function(){
                if(this.checked){
                	$(this).val("1");
                    $('div.use-ship-sel').hide();
                    update_three_block();
                }
                else {
                	$(this).val("0");
                	$('select[name="address_delivery_id"]').val("---");
                     $('div.use-ship-sel').show();
                }
            });
            $('input[name="use_bill"]').on('click', function(){
                if(this.checked){
                	$(this).val("1");
                     $('div.use-bill-sel').hide();
                     update_three_block();
                }
                else {
                	$(this).val("0");
                	$('select[name="address_billing_id"]').val("---");
                    $('div.use-bill-sel').show();
                }
            });

            $('select[name="address_delivery_id"]').on('change',function(){
               if($(this).val() == '0'){
                	$('#osc-new-delivery input[type=\'text\']').val("");
                    $.colorbox({opacity : "0.5", inline:true, href:function(){
                            return '#osc-new-delivery';
                        },
                        onClosed: function(){
                        	closePopup("dell");
                            }
                    });
                }
                if ($(this).val() != '0'){
                	update_three_block();
                    }
            });
            $('select[name="address_billing_id"]').on('change',function(){

                if($(this).val() == '0'){
                	$('#osc-new-billing input[type=\'text\']').val("");
                    $.colorbox({opacity : "0.5", inline:true, href:function(){
                            return '#osc-new-billing';
                        },
                        onClosed: function(){
                        	closePopup("bill");
                            }
                    });
                }
                if ($(this).val() != '0'){
                	update_three_block();
                    }
            });

            $('input#osc-new-delivery-btn').click(function(){
                $('select[name=\'shipping[country_id]\']').trigger('change');

                $.ajax({
                    url: 'index.php?route=checkout/checkout/validate',
                    type: 'post',
                    data: $('#osc-new-delivery :input,#osc-new-delivery select'),
                    dataType: 'json',
                    beforeSend: function() {
                        $('#osc-new-delivery span.osc-wait').show();
                    },
                    complete: function() {
                        $('#osc-new-delivery span.osc-wait').hide();
                    },
                    success: function(json) {
                        $('#osc-new-delivery .osc-error').remove();
                        

                        if (json['redirect']) {
                            location = json['redirect'];
                        } else if (json['error']) {
                            for(var key in json['error']){
                                $('#osc-new-delivery input[name=\'shipping[' + key + ']\']').after('<span class="osc-error">' + json['error'][key] + '</span>');
                                $('#osc-new-delivery select[name=\'shipping[' + key + ']\']').after('<span class="osc-error">' + json['error'][key] + '</span>');
                            }
                            $.colorbox({opacity : "0.5", inline:true, href:function(){
                                    return '#osc-new-delivery';
                                },
                                onClosed: function(){
                                	closePopup("dell");
                                    }
                            });
                        }else if (json['post']) {
                        	 for(var key in json['post']){
                            	 if (key != "active")
                        	form_delivery[key]=json['post'][key]['name'];
                        	 }
                        	 $.colorbox.close();

                        }
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
//                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });
            $('input#osc-new-billing-btn').click(function(){
               // $('select[name=\'payment[country_id]\']').trigger('change');

                $.ajax({
                    url: 'index.php?route=checkout/checkout/validate',
                    type: 'post',
                    data: $('#osc-new-billing :input,#osc-new-billing select'),
                    dataType: 'json',
                    beforeSend: function() {
                        $('#osc-new-billing span.osc-wait').show();
                    },
                    complete: function() {
                        $('#osc-new-billing span.osc-wait').hide();
                    },
                    success: function(json) {
                        $('#osc-new-billing .osc-error').remove();

                        if (json['redirect']) {
                            location = json['redirect'];
                        } else if (json['error']) {
                            for(var key in json['error']){
                                $('#osc-new-billing input[name=\'payment[' + key + ']\']').after('<span class="osc-error">' + json['error'][key] + '</span>');
                                $('#osc-new-billing select[name=\'payment[' + key + ']\']').after('<span class="osc-error">' + json['error'][key] + '</span>');
                            }
                            $.colorbox({opacity : "0.5", inline:true, href:function(){
                                    return '#osc-new-billing';
                                },
                                onClosed: function(){
                                	closePopup("bill");
                                    }
                            });
                        }else if (json['post']) {
                        	 for(var key in json['post']){
                            	 if (key != "active")
                            		 form_billing[key]=json['post'][key]['name'];
                        	 }
                          	 $.colorbox.close();
                        }
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
//                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });


            $('input[name="osc-use-coupon"]').click(function(){
                if(this.checked){
                    $(this).val("1");
                    $('div.osc-coupon').show();
                }
                else{
                    $(this).val("0");
                    $('div.osc-coupon').hide();
                }
            });

            $('input[name="osc-use-comment"]').click(function(){
                if(this.checked){
                    $(this).val("1");
                    $('div.osc-comment').show();
                }
                else{
                    $(this).val("0");
                    $('div.osc-comment').hide();
                }
            });


            $('input[name="osc-use-voucher"]').click(function(){
                if(this.checked){
                    $(this).val("1");
                    $('div.osc-voucher').show();
                }
                else{
                    $(this).val("0");
                    $('div.osc-voucher').hide();
                }
            });

            $('input[name="osc-use-reward"]').click(function(){
                if(this.checked){
                    $(this).val("1");
                    $('div.osc-reward').show();
                }
                else{
                    $(this).val("0");
                    $('div.osc-reward').hide();
                }
            });
            $('#newsletter').click(function(){
                if(this.checked){
                    $(this).val("1");
                }
                else{
                    $(this).val("0");
               }
            });

            $('input[name="account_agree"]').click(function(){
                if(this.checked){
                    $(this).val("1");
                }
                else{
                    $(this).val("0");
               }
            });

            $('input[name="checkout_agree"]').click(function(){
                if(this.checked){
                    $(this).val("1");
                }
                else{
                    $(this).val("0");
               }
            });
            $('input[type="checkbox"]:checked').val(1);



            $('#osc-coupon-btn').click(function(){

                   $.ajax({
                    url: 'index.php?route=checkout/checkout/validateCoupon',
                    type: 'post',
                    data: $('.osc-coupon input[name="coupon"]'),
                    dataType: 'json',
                    beforeSend: function() {
                           $('.osc-coupon .osc-error, .osc-coupon .osc-success').remove();
                           $('#osc-coupon-btn').before('<span class="osc-wait"></span>');
                    },
                    complete: function() {
                           $('.osc-coupon .osc-wait').remove();
                    },
                    success: function(json) {
                            if (json["success"]){
                                  update_three_block(1);
                                  $('#osc-coupon-btn').after('<span class="osc-success">'+json["success"]+'</span>');
                            }
                            else if(json["error"]){
                                  $('#osc-coupon-btn').after('<span class="osc-error">'+json["error"]+'</span>');
                            }
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
//                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });
                 $('#osc-voucher-btn').click(function(){
                  $.ajax({
                    url: 'index.php?route=checkout/checkout/validateVoucher',
                    type: 'post',
                    data: $('.osc-voucher input[name="voucher"]'),
                    dataType: 'json',
                    beforeSend: function() {
                        $('.osc-voucher .osc-error, .osc-voucher .osc-success').remove();
                        $('#osc-voucher-btn').before('<span class="osc-wait"></span>');
                    },
                    complete: function() {
                        $('.osc-voucher .osc-wait').remove();
                    },
                    success: function(json) {
                            if (json["success"]){
                                  update_three_block(1);
                                  $('#osc-voucher-btn').after('<span class="osc-success">'+json["success"]+'</span>');
                            }
                            else if(json["error"]){
                                  $('#osc-voucher-btn').after('<span class="osc-error">'+json["error"]+'</span>');
                            }
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
//                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });
              $('#osc-reward-btn').click(function(){
                  $.ajax({
                    url: 'index.php?route=checkout/checkout/validateReward',
                    type: 'post',
                    data: $('.osc-reward input[name="reward"]'),
                    dataType: 'json',
                    beforeSend: function() {
                        $('.osc-reward .osc-error, .osc-reward .osc-success').remove();
                        $('#osc-reward-btn').before('<span class="osc-wait"></span>');
                    },
                    complete: function() {
                        $('.osc-reward .osc-wait').remove();
                    },
                    success: function(json) {
                                 if (json["success"]){
                                    update_three_block(1);
                                    $('#osc-reward-btn').after('<span class="osc-success">'+json["success"]+'</span>');
                                 }
                                 else if(json["error"]){
                                    $('#osc-reward-btn').after('<span class="osc-error">'+json["error"]+'</span>');
                                 }
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
//                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            });

            $('#osc-pay-btn').click(function(){
             $.ajax({
                    url: 'index.php?route=checkout/checkout/validate',
                    type: 'post',
                    data: $('#osc-personal input[type=\'text\'], #osc-personal input[type=\'password\'],#osc-personal input[type=\'radio\']:checked,#osc-personal select,#osc-personal input[type=\'checkbox\']:checked,#osc-shipping-data input[type=\'radio\']:checked,#osc-payment-data input[type=\'radio\']:checked,#osc-comment, .osc-terms-link :input'),
                    dataType: 'json',
                      beforeSend: function() {
                        $('.osc-error').remove();
                            $('#osc-pay-btn span.osc-wait').show();
                          $("#payment_html").html("");
                           },
                    complete: function() {
                    	// $('#osc-pay-btn span.osc-wait').hide();
                    },
                    success: function(json) {
                        $('.osc-error').remove();

                        if (json['redirect']) {
                            location = json['redirect'];
                        } else if (json['error']) {
                        $('#osc-pay-btn span.osc-wait').hide();
                            for(var key in json['error']){
                                $('input[name=\'' + key + '\'][type=\'text\']').after('<span class="osc-error">' + json['error'][key] + '</span>');
                                $('input[name=\'' + key + '\'][type=\'password\']').after('<span class="osc-error">' + json['error'][key] + '</span>');
                                $('input[name=\'' + key + '\'][type=\'checkbox\'] + label').after('<span class="osc-error">' + json['error'][key] + '</span>');
                                $('select[name=\'' + key + '\']').after('<span class="osc-error">' + json['error'][key] + '</span>');

                            }
                        } else if(json['status']=="success"){
                            $('#osc-pay-btn span.osc-wait').show();
				$("#payment_html").html(json["payment_html"]);
                                
                                	
				$('#osc-pay-btn span.osc-wait').hide();
				
				if(/<.*?select|<input type=.?text.?.*?>/m.test( json["payment_html"]) ){
				          $.colorbox({opacity : "0.5", inline:true, href:"#payment_html"});
                                           console.log(json["payment_html"]);
						  } else {
						$('#payment_html input[value="<?php echo $button_confirm; ?>"]').trigger('click');
				           	$('#payment_html #button-confirm').trigger('click');	
                                            }
                        /*	$('#payment_html input[value="<?php echo $button_confirm; ?>"]').trigger('click');*/
                                   
                            }

                    },
                    error: function(xhr, ajaxOptions, thrownError) {
//                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });



            });
            $('input[name=\'customer_group_id\']').on('change', function() {
            	var customer_group = [];
console.log("este");
            <?php foreach ($customer_groups as $customer_group) { ?>
            	customer_group[<?php echo $customer_group['customer_group_id']; ?>] = [];
            	customer_group[<?php echo $customer_group['customer_group_id']; ?>]['company_id_display'] = '<?php echo $customer_group['company_id_display']; ?>';
            	customer_group[<?php echo $customer_group['customer_group_id']; ?>]['company_id_required'] = '<?php echo $customer_group['company_id_required']; ?>';
            	customer_group[<?php echo $customer_group['customer_group_id']; ?>]['tax_id_display'] = '<?php echo $customer_group['tax_id_display']; ?>';
            	customer_group[<?php echo $customer_group['customer_group_id']; ?>]['tax_id_required'] = '<?php echo $customer_group['tax_id_required']; ?>';
            <?php } ?>

            	if (customer_group[this.value]) {
            		if (customer_group[this.value]['company_id_display'] == '1') {
            			$('#company-id-display').show();
            		} else {
            			$('#company-id-display').hide();
            		}

            		if (customer_group[this.value]['company_id_required'] == '1') {
            			$('#company-id-required').show();
            		} else {
            			$('#company-id-required').hide();
            		}

            		if (customer_group[this.value]['tax_id_display'] == '1') {
            			$('#tax-id-display').show();
            		} else {
            			$('#tax-id-display').hide();
            		}

            		if (customer_group[this.value]['tax_id_required'] == '1') {
            			$('#tax-id-required').show();
            		} else {
            			$('#tax-id-required').hide();
            		}
            	}
            });

             $('select[name=\'country_id\']').trigger('change');
             $('select[name=\'shipping[country_id]\']').trigger('change');
             $('select[name=\'payment[country_id]\']').trigger('change');
             $('input[name=\'customer_group_id\']:checked').trigger('change');
             //alert($("#content").width());
        });


</script>