/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@buy-addons.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author    Buy-addons    <contact@buy-addons.com>
* @copyright 2007-2020 Buy-addons
* @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
function priceformatNumber(price) {
	if (isNaN(price) || price == '') {
		price = 0;
	}
    price = parseFloat(price);
    var p = price.toFixed(3).split(".");
	return  p[0].split("").reverse().reduce(function(acc, price, i, orig) {
		return  price=="-" ? acc : price + (i && !(i % 3) ? "," : "") + acc;
	}, "") + "." + p[1];   
}
jQuery(document).ready(function(){
	$("#td_send_email_to_customer").click(function(){
		$( "body" ).append("<div class='header_style'></div>");
		var td_firstname = $(".td_firstname").val();
		var td_lastname = $(".td_lastname").val();
		var td_email = $(".td_email").val();
		var td_id_cart = $(".td_id_cart").val();
		var td_id_quote = jQuery('.td_id_quote').val();
		jQuery.ajax({
			type: 'POST',//phương thức gửi
			jscrossDomain: window.location.hostname,
			crossDomain: true,
			url: 'index.php?controller=AdminSendProcessPayment&token='+token_askaquotemodule+'',
			data: '&td_firstname=' + td_firstname 
			+ '&td_lastname=' + td_lastname 
			+ '&td_email=' + td_email 
			+ '&td_id_cart=' + td_id_cart 
			+ '&td_id_quote=' + td_id_quote 
			+ '&quote_token=' + token_askaquotemodule + '&ajax=1',
			success: function(jsonData1,textStatus,jqXHR)
			{
				var url = new URL(window.location.href);
				url.searchParams.set('sendmail', jsonData1);
				window.location.href = url.href;
			}	
		});
	});
	$(".ba_new_address_popup_background").click(function(){
		window.parent.$(".ba_new_address_popup_background").css("display", "none");
		window.parent.$(".td_new_address_popup").css("display", "none");
	});
	
	$(".make_an_order").click(function(){
		$( "body" ).append(showLoading());
		$("#td_add_new, #products_found, #products_err").css('display', 'none');
		$('.edited').val(1);
		make_order();
		displayFormOrder();
    });
    var myVar;
    myVar = setInterval(function () {
        var width = $(window).width();
        var width_content_style = $(".content_style").outerWidth();
		width_content_style = Math.round(width_content_style / 10 + 1) * 10;
        var left = (width - width_content_style) / 2;
        $(".content_style").css("left", left + "px");
        var height = $(window).height();
        var height_content_style = $(".content_style").outerHeight();
        var top = (height - height_content_style) / 2;
        $(".content_style").css("top", top + "px");
    }, 100);      
});
function getstate_popup_address(id_country)
{
    var id_country = id_country.value;
    var baseurl = window.location.hostname;
    jQuery.ajax({
        type: 'POST',//phương thức gửi
        jscrossDomain: window.location.hostname,
        crossDomain: true,
        url: '../index.php?controller=getstate&fc=module&module=askforaquotemodul',
        data: '&id_country=' + id_country + '&quote_token=' + token_askaquotemodule + '&ajax=1',
		beforeSend: function() {
			$('.load_check_order').css('display', 'block');
			$(".td_save_new_address").attr("disabled", true);
		},
        success: function(jsonData1,textStatus,jqXHR)
        {
            jsonData1 = JSON.parse(jsonData1);
            state_popup_address(jsonData1);
			$('.load_check_order').css('display', 'none');
			$(".td_save_new_address").attr("disabled", false);
        }
    });
}
function state_popup_address(jsonData1){
    var html_new = '';
	if ($.isEmptyObject(jsonData1)) {
		$('.showstate').css('display', 'none');
		$('.td_popup__address_state').prop('selectedIndex',0);
	} else {
		for(i=0;i<jsonData1.length;i++){
			html_new += '<option  value="'+ jsonData1[i]['id_state'] + '">'+jsonData1[i]['name']+'</option>';
		}
		window.parent.$(".td_popup__address_state").html(html_new);
		$('.showstate').css('display', 'block');
	}
}
function add_or_edit_address(check_add_or_edit, id_delivery = 0, id_invoice = 0) {
	var row_product = baquote_getProducts();
	var id_cart = jQuery('.td_id_cart').val();
	var td_popup__address_identi_num = jQuery('.td_popup__address_identi_num').val();
	var td_popup__address_alias = jQuery('.td_popup__address_alias').val();
	var td_popup__address_first_name = jQuery('.td_popup__address_first_name').val();
	var td_popup__address_last_name = jQuery('.td_popup__address_last_name').val();
	var td_popup__address_company = jQuery('.td_popup__address_company').val();
	var td_popup__address_vat_num = jQuery('.td_popup__address_vat_num').val();
	var td_popup__address_adres1 = jQuery('.td_popup__address_adres1').val();
	var td_popup__address_adres2 = jQuery('.td_popup__address_adres2').val();
	var td_popup__address_city = jQuery('.td_popup__address_city').val();
	var td_popup__address_zip_code = jQuery('.td_popup__address_zip_code').val();
	var td_popup__address_country = jQuery('.td_popup__address_country').val();
	var td_popup__address_state = jQuery('.td_popup__address_state').val();
	var td_popup__address_home_phone = jQuery('.td_popup__address_home_phone').val();
	var td_popup__address_mobile_phone = jQuery('.td_popup__address_mobile_phone').val();
	var td_popup__address_other = jQuery('.td_popup__address_other').val();
	var td_id_customer = jQuery('.td_id_customer').val();
	var address_ids = jQuery('.address_ids').attr('data-id-address');
	if (typeof (address_ids) === "undefined") {
		address_ids = '';
	}
	var check = 1;
	var home_phone = 1;
	var mobile_phone = 1;
	$(".check_popup_newaddress").each(function(){
		if ($(this).find(".td_newaddress_val").val().length === 0) {
			if ($(this).find(".td_newaddress_val.td_popup__address_home_phone").val() == '') {
				home_phone = 0;
				window.parent.$($(this).find(".alert_check_order")).css("display", "block");
			} else if ($(this).find(".td_newaddress_val.td_popup__address_mobile_phone").val() == '') {
				mobile_phone = 0;
				window.parent.$($(this).find(".alert_check_order")).css("display", "block");
			} else {
				check=0;
				window.parent.$($(this).find(".alert_check_order")).css("display", "block");
			}
		} else {
			window.parent.$($(this).find(".alert_check_order")).css("display", "none");
		}
	});
	if (check == 1 && (home_phone == 1 || mobile_phone == 1)) {
		check = 1;
	} else {
		check = 0;
	}
	if (check == 1) {
		$( "body" ).append(showLoading());
		jQuery.ajax({
			type: 'POST',//phương thức gửi
			jscrossDomain: window.location.hostname,
			crossDomain: true,
			url: '../index.php?controller=addeditaddress&fc=module&module=askforaquotemodul', // lấy link của controller mới
			data: 'td_popup__address_identi_num=' + td_popup__address_identi_num + 
				'&td_popup__address_alias=' + td_popup__address_alias +
				'&td_popup__address_first_name=' + td_popup__address_first_name +
				'&td_popup__address_last_name=' + td_popup__address_last_name +
				'&td_popup__address_company=' + td_popup__address_company +
				'&td_popup__address_vat_num=' + td_popup__address_vat_num +
				'&td_popup__address_adres1=' + td_popup__address_adres1 +
				'&td_popup__address_adres2=' + td_popup__address_adres2 +
				'&td_popup__address_city=' + td_popup__address_city +
				'&td_popup__address_zip_code=' + td_popup__address_zip_code +
				'&td_popup__address_country=' + td_popup__address_country +
				'&td_popup__address_state=' + td_popup__address_state +
				'&td_popup__address_home_phone=' + td_popup__address_home_phone +
				'&td_popup__address_mobile_phone=' + td_popup__address_mobile_phone +
				'&td_popup__address_other=' + td_popup__address_other +
				'&td_id_customer=' + td_id_customer +
				'&check_add_or_edit=' + check_add_or_edit +
				'&id_delivery=' + id_delivery +
				'&id_invoice=' + id_invoice +
				'&address_ids=' + address_ids +
				'&row_product=' + row_product +
				'&jsshopid=' + jsshopid +
				'&id_cart=' + id_cart +
				'&quote_token=' + token_askaquotemodule + '&ajax=1',  // lấy dữ liệu từ id product ở trên định nghĩa
			success: function(jsonData1, textStatus, jqXHR)
			{
				jsonData1 = JSON.parse(jsonData1);
				if (jsonData1['errorzipcode'] == 'incorrect') {
					$('.askforquoteerrorzipcode').remove();
					$( ".page-subheading.td_float_left" ).after(jsonData1['displayerror']);
					baquote_hideBackground();
				} else {
					$('#boxaddress').html(jsonData1['template']);
					window.parent.$(".ba_new_address_popup_background").css("display", "none");
					window.parent.$(".td_new_address_popup").css("display", "none");
				}
			},
			complete: function (data) {
				if (typeof (id_delivery) !== "undefined" && typeof (id_invoice) !== "undefined") {
					data = JSON.parse(data['responseText']);
					baquote_updateQuoteCart();
				}
			}
		});
	}
}
function rebuildSummaryBeforeShip(ob) {
	
	var sign = '';
	html = '<input type="hidden" value="'+ob['total_products']+'" class="td_total_pro_order_num" name="td_total_pro_order">';
	jQuery(".td_total_pro_order").html(html + (ob['total_products_format']) + sign);
	
	html = '<input type="hidden" value="'+ob['total_discounts']+'" class="td_total_coupon_order_num" name="td_coupon_code_order">';
	var v = ob['total_discounts_format'].charAt(0) == '-' ? ob['total_discounts_format'] : '-' + ob['total_discounts_format'];
	jQuery(".td_total_coupon_order").html(html + v + sign);
	
	html = '<input type="hidden" value="'+ob['total_shipping']+'" class="td_total_shipping_order_num" name="td_total_shipping_orderr">';
	jQuery(".td_total_shipping_order").html(html + (ob['total_shipping_format'])+sign);
	
	html = '<input type="hidden" value="'+ob['total_tax']+'" class="td_total_tax_order_num" name="td_total_tax_order">';
	jQuery(".td_total_tax_order").html(html + (ob['total_tax_format'])+sign);
	
	html = '<input type="hidden" value="'+ob['total_price_without_tax']+'" class="td_total_price_notax_order_num" name="td_total_price_notax_order">';
	jQuery(".td_total_price_notax_order").html(html + (ob['total_price_without_tax_format'])+sign);
	
	html = '<input type="hidden" value="'+ob['total_price']+'" class="td_total_price_tax_order_num" name="td_total_price_tax_order">';
	jQuery(".td_total_price_tax_order").html(html + (ob['total_price_format'])+sign);
}
function displayFormOrder() {
	if ($('.td_order_new').css('display') == 'none') {
		$(".td_shipping_price, .td_tax_price, .td_coupon_code, .edit_price, .edit_quantity, .edit_total_price, .del_product_view").attr("disabled", true);
		$(".td_shipping_price, .td_tax_price, .td_coupon_code, .edit_price, .edit_quantity, .edit_total_price, .del_product_view").css("opacity", "0.6");
		$("#td_auto_shipping, #td_auto_tax, #td_auto_coupon, .td_new_quote").addClass("badeactivate");
		$('.td_order_new').css('display', 'block');
	} else {
		$(".td_shipping_price, .td_tax_price, .td_coupon_code, .edit_price, .edit_quantity, .edit_total_price, .del_product_view").attr("disabled", false);
		$(".td_shipping_price, .td_tax_price, .td_coupon_code, .edit_price, .edit_quantity, .edit_total_price, .del_product_view").css("opacity", "1");
		$("#td_auto_shipping, #td_auto_tax, #td_auto_coupon, .td_new_quote").removeClass("badeactivate");
		$('.td_order_new').css('display', 'none');
	}
}
function baquote_getProducts() {
	var row_product = '';
	var edit_price_format, edit_total_price_format;
	$('#orderProducts tbody tr').each(function(){
		row_product += '|' + $(this).find('.row_product').attr('data-id-product') + '-' + $(this).find('.row_product').attr('data-id-combination');
		edit_price_format = $(this).find('.edit_price').val();
		edit_price_format = convertCurrencytoNumber(edit_price_format);
		row_product += '-' + edit_price_format;
		row_product += '-' + $(this).find('.edit_quantity').val();
		edit_total_price_format = $(this).find('.edit_total_price').val();
		edit_total_price_format = convertCurrencytoNumber(edit_total_price_format);
		row_product += '-' + edit_total_price_format;
	});
	return row_product;
}
function make_order() {
	
	var sign = jQuery('.qty_product_dbboo').attr('data-sign-dbboo');
    var id_delivery = $(".id_address_delivery").val();
    var id_invoice = $(".id_address_invoice").val();
	if (typeof (id_delivery) === "undefined") {
		id_delivery = 0;
	}
	if (typeof (id_invoice) === "undefined") {
		id_invoice = 0;
	}
	var td_id_quote = jQuery('.td_id_quote').val();
	var td_id_customer = jQuery('.td_id_customer').val();
	var edited = $('.edited').val();
	var row_product = '';
	if (edited == 1) {
		row_product = baquote_getProducts();
	}
	$('.edited_product').val(row_product);
	jQuery.ajax({
		type: 'POST',
		jscrossDomain: window.location.hostname,
		crossDomain: true,
		url: '../index.php?controller=createcart&fc=module&module=askforaquotemodul',
		data: 'td_id_quote=' + td_id_quote
			+ '&id_delivery=' + id_delivery
			+ '&id_invoice=' + id_invoice
			+ '&td_id_customer=' + td_id_customer
			+ '&edited=' + edited
			+ '&row_product=' + row_product
			+ '&jsshopid=' + jsshopid
			+ '&jslanguageid=' + jslanguageid
			+ '&quote_token=' + token_askaquotemodule
			+ '&ajax=1',
		success: function(jsonData1,textStatus,jqXHR)
		{
			jsonData1 = JSON.parse(jsonData1);
			if (parseInt(jsonData1.has_error) == 1) {
				baquote_hideBackground();
				$.each(jsonData1.errors, function(i, item) {
					$.growl.error({ title: "", message: item});
				});
				return true;
			} else {
				$('#boxaddress').html(jsonData1['template']);
				$('.td_id_cart').remove();
				$('.td_id_customer').val(jsonData1['args']['id_customer']);
				$('.td_order_new').append('<input type="hidden" class="td_id_cart" name="td_id_cart" value="'+jsonData1['args']['id_cart']+'">');
				rebuildSummaryBeforeShip(jsonData1['args']['obcart']);
				baquote_updateQuoteCart();
			}
		}
	});
}
function baquote_hideBackground(){
	$(".header_style").remove();
	$(".content_style").remove();
}
function baquote_updateQuoteCart() {
	$( "body" ).append(showLoading());
    var id_delivery = $(".id_address_delivery").val();
    var id_invoice = $(".id_address_invoice").val();
	var td_id_quote = jQuery('.td_id_quote').val();
	var td_id_customer = jQuery('.td_id_customer').val();
	var id_cart = jQuery('.td_id_cart').val();
	var selected_ship = jQuery('.td_delivery_option').val();
	var free_shipping = jQuery("input[name='free_shipping']:checked").val();
	var list_voucher = '';
	$('.td_list_voucher tr').each(function(){
		list_voucher += $(this).attr('data-voucher') + ',';
	});
	var row_product = baquote_getProducts();
	jQuery.ajax({
		type: 'POST',
		jscrossDomain: window.location.hostname,
		crossDomain: true,
		url: 'index.php?controller=AdminCheckDelivery&token='+token_askaquotemodule+'',
		data:   'id_delivery=' + id_delivery
				+'&id_invoice=' + id_invoice
				+'&td_id_customer=' + td_id_customer
				+'&td_id_quote=' + td_id_quote
				+'&id_cart=' + id_cart
				+'&row_product=' + row_product
				+'&list_voucher=' + list_voucher
				+'&selected_ship=' + selected_ship
				+'&jsshopid=' + jsshopid
				+'&quote_token=' + token_askaquotemodule 
				+'&free_shipping=' + free_shipping 
				+ '&ajax=1',
		success: function(jsonData1,textStatus,jqXHR)
		{
			jsonData1 = JSON.parse(jsonData1);
			$('#boxshipping').html(jsonData1['boxshipping']);
			$('#boxvoucher').html(jsonData1['boxvoucher']);	
			if (jsonData1['no_carrier'] == 1) {
				$('#td_send_email_to_customer').attr("disabled", true);
				$('.td_add_order').attr("disabled", true);
			} else {
				$('#td_send_email_to_customer').attr("disabled", false);
				$('.td_add_order').attr("disabled", false);
			}
			if (jsonData1['PS_GUEST_CHECKOUT_ENABLED'] == 0 && jsonData1['is_guest'] == 1) {
				$('#td_send_email_to_customer').css("display", "none");
			} else {
				$('#td_send_email_to_customer').css("display", "inline-block");
			}
			
			shipping_price = $('.shipping_price_selected').attr('data-price');
			shipping_price_format = $('.shipping_price_selected').attr('data-price-format');
			if (typeof (shipping_price) !== "undefined" && typeof (shipping_price_format) !== "undefined") {
				html = '<input type="hidden" value="'+shipping_price+'" class="td_total_shipping_order_num" name="td_total_shipping_orderr">';
				$('.td_total_shipping_order').html(html + shipping_price_format);
			}			
			rebuildSummaryBeforeShip(jsonData1['summary_quotecart']);
			baquote_hideBackground();
		}
	});
}

function getShippingcost(ob)
{
	baquote_updateQuoteCart();
}
function openPopupAddress(check_add_or_edit, id_delivery = 0, id_invoice = 0) {
	var firstname = $('#firstname').text();
	var lastname = $('#lastname').text();
	jQuery.ajax({
		type: 'POST',
		jscrossDomain: window.location.hostname,
		crossDomain: true,
		url: '../index.php?controller=popupaddress&fc=module&module=askforaquotemodul',
		data: 'check_add_or_edit=' + check_add_or_edit + '&id_delivery=' + id_delivery + '&id_invoice=' + id_invoice + '&firstname=' + firstname + '&lastname=' + lastname + '&quote_token=' + token_askaquotemodule + '&ajax=1',
		beforeSend: function() {
			if (check_add_or_edit == 'addnew') {
				$('.add_new_address').parent().append('<span class="loadicon_edita" style="display: inline-block; margin: 7px"><i class="icon-refresh icon-spin"></i></span>');
			} else {
				$('.edit_'+check_add_or_edit).parent().prepend('<span class="loadicon_edita" style="display: inline-block; margin: 7px; float: right !important;"><i class="icon-refresh icon-spin"></i></span>');
			}
		},
		success: function(jsonData1,textStatus,jqXHR)
		{
			$('.loadicon_edita').remove();
			$('#popupaddress').html(jsonData1);
			window.parent.$(".ba_new_address_popup_background").css("display", "block");
			window.parent.$(".td_new_address_popup").css("display", "block");
		}
	});
}
function saveAddress(check_add_or_edit, id_delivery = 0, id_invoice = 0) {
	add_or_edit_address(check_add_or_edit, id_delivery, id_invoice);
}
function closePopup() {
	window.parent.$(".ba_new_address_popup_background").css("display", "none");
	window.parent.$(".td_new_address_popup").css("display", "none");
}
function changeAddressID(typeaddress,ob) {
	$( "body" ).append(showLoading());
	var row_product = baquote_getProducts();
	var id_cart = jQuery('.td_id_cart').val();
	var id_address = $(ob).find('option:selected').val();
	jQuery.ajax({
		type: 'POST',
		jscrossDomain: window.location.hostname,
		crossDomain: true,
		url: '../index.php?controller=geninforaddress&fc=module&module=askforaquotemodul',
		data: 'id_address=' + id_address 
			+ '&typeaddress=' + typeaddress 
			+ '&jsshopid=' + jsshopid 
			+ '&id_cart=' + id_cart 
			+ '&quote_token=' 
			+ token_askaquotemodule + '&ajax=1',
		success: function(jsonData1,textStatus,jqXHR)
		{
			jsonData1 = JSON.parse(jsonData1);
			displayFormattedAddress(typeaddress,jsonData1['name_address'],id_address);
		},
		complete: function (data) {
			baquote_updateQuoteCart();
		}
	});
}
function displayFormattedAddress(typeaddress, ob, id_address) {
	var id_delivery = $('.id_address_delivery').val();
	var id_invoice = $('.id_address_invoice').val();
	if (typeaddress == 'delivery') {
		id_delivery = id_address;
	}
	if (typeaddress == 'invoice') {
		id_invoice = id_address;
	}
	$('.edit_delivery').attr('onClick', 'openPopupAddress("delivery","'+id_delivery+'","'+id_invoice+'")');
	$('.edit_invoice').attr('onClick', 'openPopupAddress("invoice","'+id_delivery+'","'+id_invoice+'")');
	
	var html = '';
	if (ob.length > 0) {
		html += '<input type="hidden" name="id_address_'+typeaddress+'" class="id_address_'+typeaddress+'" value="'+ob[0]['id_address']+'">';
		html += ob[0]['firstname'] + ' ' + ob[0]['lastname'];
		html += '<br>' + ob[0]['company'];
		html += '<br>' + ob[0]['address1'] + ' ' + ob[0]['address2'];
		html += '<br>' + ob[0]['city'] + ', ' + ob[0]['name_state'] + ' ' + ob[0]['postcode'];
		html += '<br>' + ob[0]['name_country'];
		html += '<br>' + ob[0]['phone'] + ', ' + ob[0]['phone_mobile'];
	}
	$('.td_address_'+typeaddress).html(html);
}
function search_voucher() {
    setTimeout(function(){
        var voucher_code = jQuery('.td_seach_voucher').val();
		var td_id_cart = jQuery('.td_id_cart').val();
        if(voucher_code.length >= '2'){
            window.parent.$("#searchLoader").css("display", "-webkit-inline-box");
            jQuery.ajax({
                type: 'POST',
                jscrossDomain: window.location.hostname,
                crossDomain: true,
                dataType: "json",
                url: '../index.php?controller=searchvoucher&fc=module&module=askforaquotemodul',
                data: 'td_seach_voucher=' + voucher_code + '&action=search' + '&td_id_cart=' + td_id_cart + '&quote_token=' + token_askaquotemodule + '&ajax=1',
                success: function(jsonData1,textStatus,jqXHR)
                {
					displayVoucherResult(jsonData1);
                    window.parent.$("#searchLoader").css("display", "none");
                }
                
            });
        }
    }, 1000);
}
var running = 0;
function baquote_addVoucher(id_voucher){
	$( "body" ).append(showLoading());
    var td_id_quote = document.querySelector('.td_id_quote').value;
    var td_id_cart = jQuery('.td_id_cart').val();
    window.parent.$("#select_voucher_Loader").css("display", "-webkit-inline-box");
	if (running == 0) {
		running = 1;
		jQuery.ajax({
			type: 'POST',
			jscrossDomain: window.location.hostname,
			crossDomain: true,
			url: '../index.php?controller=searchvoucher&fc=module&module=askforaquotemodul',
			data: 'id_voucher=' + id_voucher + '&td_id_cart=' + td_id_cart + '&action=add' + '&td_id_quote=' + td_id_quote + '&jsshopid=' + jsshopid + '&quote_token=' + token_askaquotemodule + '&ajax=1',
			success: function(data, textStatus, jqXHR)
			{	
				data = JSON.parse(data);
				if (parseInt(data.has_error) == 1) {
					baquote_hideBackground();
					$.each(data.errors, function(i, item) {
						$.growl.error({ title: "", message: item});
					});
				} else {
					baquote_updateQuoteCart();
				}	
				running = 0;
			}
		});
	}
}
function deletevoucher(ob,id_voucher){
	$( "body" ).append(showLoading());
    var td_id_cart = jQuery('.td_id_cart').val();
    jQuery.ajax({
        type: 'POST',
        jscrossDomain: window.location.hostname,
        crossDomain: true,
        dataType: "json",
        url: '../index.php?controller=searchvoucher&fc=module&module=askforaquotemodul',
        data: 'id_voucher=' + id_voucher + '&td_id_cart=' + td_id_cart +  '&action=delete&quote_token=' + token_askaquotemodule + '&ajax=1',
		beforeSend: function() {
			$(ob).parent().append('<span class="loadicon_delvoucher" style="display: inline-block; margin: 7px 0px 0px 0px;"><i class="icon-refresh icon-spin"></i></span>');
		},
        success: function(jsonData1,textStatus,jqXHR)
        {
            baquote_updateQuoteCart();
        }
    });
}
var counter_ajax_request = 0;
var keyup_timer;
function searchV(){
	var voucher_code = jQuery('.td_seach_voucher').val();
	if(voucher_code.length == 0){
		$(".td_show_search_voucher").html('');
	}
    counter_ajax_request = 0;
    clearInterval(keyup_timer);
    keyup_timer = setInterval("baquote_counterKeyup()", 100);     
}
function baquote_counterKeyup() {
    counter_ajax_request = counter_ajax_request + 100;
    if (counter_ajax_request >= 500) {
        clearInterval(keyup_timer);
        search_voucher();
    }
}
function displayVoucherResult(datacounpon){
	if (datacounpon.length == 0) {
		return true;
	}
    var html_ac_results = '';
    html_ac_results += '<div class="ac_results"><ul>';	
	$.each(datacounpon, function(i, item) {
		html_ac_results += '<li class="ac_even"><a onclick="baquote_addVoucher('+item.id_cart_rule+')">'+item.name;
		if (item.code) {
			html_ac_results += ' - ' + item.code;
		}
		html_ac_results +='</a></li>';
	});
    html_ac_results += '</ul></div>';
    window.parent.$(".td_show_search_voucher").html(html_ac_results);
}
function showLoading() {
	if ( !$( "body .header_style" ).length ) {
		$( "body" ).append("<div class='header_style'></div>");
		$( "body" ).append(popupLoading());
	}
	$(".content_style").delay(100).fadeIn(500);
}
function popupLoading() {
	var html = '';
	html += "<div class='content_style' style='display: none; background-color: #fff0;'>";
		html += "<img src='"+base_url+"modules/askforaquotemodul/views/img/load.gif' alt='load' width='100px' height='100px'>";
	html += "</div>";
	return html;
}