var redirect_url;
var group;
if(window.location.hostname == 'localhost')
{
	var base_url = 'http://'+window.location.hostname+'/eversmartnew/';
}
if( window.location.hostname == '54.218.78.31' )
{
	var base_url = 'http://'+window.location.hostname+'/';
}
if( window.location.hostname == '13.58.101.121' )
{
	var base_url = 'http://'+window.location.hostname+'/eversmartnew/';
}

$(document).ready(function()
{

  //postcode quotation page
  $.ajax({
      url: base_url+'index.php/quotation/postcode',
      type: 'get',
      success:function(response)
      {
        $('#response').html(response);
      }
  });

  $(document).on('submit','#form-postcode-simple',function(e)
  {
		e.preventDefault();
		var form_postcode = $('#form-postcode').val();
		$.ajax({
				url: base_url+'index.php/quotation/quotefor',
				type: 'post',
				data: { postcode: form_postcode },
				success:function(response)
				{
					//console.log(response);
					if( response == '2000' ) {
						$('#error_message').text('Input postcode did not match validation regex');
						$('.error_msg').show();
					}
					else {
						$('#quotation_form #quotation_postcode').val( form_postcode );
						$('#response').html(response);
					}
				},
      error: function(jqXHR, textStatus, errorThrown){
          alert(textStatus);
      }
		});
  });

	$(document).on( 'click', '#back_postcode', function(){
		//alert($('#quotation_postcode').val());
		//return false;
		var postcode = $('#quotation_postcode').val();
		$.ajax({
				url: base_url+'index.php/quotation/postcode',
				type: 'get',
				success:function(response)
				{
					$('#response').html(response);
					$('.md-form label').addClass('active');
					$('#form-postcode').val( postcode );
				}
		});
	});


	$(document).on('click', '.quotefor', function(){

			var select_quote = $(this).data('quotefor');

			$.ajax({
					url: base_url+'index.php/quotation/address_list',
					type: 'get',
					success:function(response)
					{
						$('#quotation_form #quotation_for').val( select_quote );
						$('#response').html(response);
					}
			});
	});


	// BACK TO QUOTE FOR SECTION
	$(document).on( 'click', '#back_quotefor', function(){
		var form_postcode = $('#quotation_postcode').val();
		$.ajax({
				url: base_url+'index.php/quotation/quotefor',
				type: 'post',
				data: { postcode: form_postcode },
				success:function(response)
				{
						$('#response').html(response);
				}
				});
	});

});
