<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>
<div id="wrapper">
	<div class="breadcrumb">
		<a href="<?php echo admin_url(); ?>"><?= _l('breadcrumb_dashboard'); ?></a>&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;<a href="<?php echo admin_url("estimates"); ?>"><?php echo _l('estimates'); ?></a>&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;<?php echo html_entity_decode($title); ?>
	</div>
	<div class="admin-title">
				<img src="<?php echo base_url("assets/images/favicon.png"); ?>" class="pull-left img-titlu" />
				<h1 style="margin-top:0px;"><?php echo html_entity_decode($title); ?></h1>
		</div>
	<div class="content">
		<div class="row">
			<?php
			echo form_open($this->uri->uri_string(),array('id'=>'estimate-form','class'=>'_transaction_form'));
			if(isset($estimate)){
				echo form_hidden('isedit');
			}
			?>
			<div class="col-md-12">
				<?php $this->load->view('admin/estimates/estimate_template'); ?>
			</div>
			<?php echo form_close(); ?>
			<?php $this->load->view('admin/invoice_items/item'); ?>
		</div>
	</div>

</div>
</div>
<?php show_footer(); ?><?php init_tail(); ?>
<script>
	$(function(){
		validate_estimate_form();
		// Init accountacy currency symbol
		init_currency();
		// Project ajax search
		init_ajax_project_search_by_customer_id();
		// Maybe items ajax search
	    init_ajax_search('items','#item_select.ajax-search',undefined,admin_url+'items/search');
	});

	function get_bcountry_states(el,state_id_selected = false){
			$.post(admin_url+'misc/get_country_states/'+$(el).val()).done(function(response){
					response = JSON.parse(response);
					if(response.success == true) {
							$('select[name="billing_state"]').html(response.html);
							if(state_id_selected){
								$('select[name=billing_state]').val(state_id_selected);
							}
							$('select[name="billing_state"]').selectpicker('refresh');

					}
			});
	}
	function get_scountry_states(el,state_id_selected = false){
			$.post(admin_url+'misc/get_country_states/'+$(el).val()).done(function(response){
					response = JSON.parse(response);
					if(response.success == true) {
							$('select[name="shipping_state"]').html(response.html);
							if(state_id_selected){
								$('select[name=shipping_state]').val(state_id_selected);
							}
							$('select[name="shipping_state"]').selectpicker('refresh');

					}
			});
	}

	$( document ).ready(function() {
			var billing_country = $('#billing_country');
			var state_id_selected = $('#billing_state').val();
			get_bcountry_states(billing_country,state_id_selected);

			var shipping_country = $('#shipping_country');
			var state_id_selected = $('#shipping_state').val();
			get_scountry_states(shipping_country,state_id_selected);
	});
</script>



</body>
</html>
