
function removeFromBasket(el_id, el_count, current_value, new_value) {
	jQuery("input[name='product[" + el_id + "][info][serials][]']").each(function(i, val) {
		if(i == el_count) jQuery(this).remove();
	});
}

function serialChange(form_selector) {
	jQuery(form_selector).find('.submitButton').hide();
}

function serialValid(resp, form_selector) {
	jQuery(form_selector).find('.serialErrorIcon').hide();
	jQuery(form_selector).find('.serialValidIcon').show();
	jQuery(form_selector).find('.submitButton').show();
	jQuery(form_selector).find('.shop_item_voucher_invalid').html('');
	jQuery(form_selector).find('.shop_item_voucher_invalid').hide();
	jQuery(form_selector).find('.shop_item_voucher_valid').css('display', 'table');
}

function serialInValid(resp, form_selector) {
	jQuery(form_selector).find('.shop_item_voucher_valid').hide();
	jQuery(form_selector).find('.serialValidIcon').hide();
	jQuery(form_selector).find('.serialErrorIcon').show();
	jQuery(form_selector).find('.shop_item_voucher_invalid').html( $(resp).find('#error-list').html() );
	jQuery(form_selector).find('.shop_item_voucher_invalid').css('display', 'table');
}

function showRates(url) {
	var b_url = cmsClient.host_url;
	if(typeof(url) != 'undefined') cmsClient.host_url = url;
	if(jQuery('select[name=call_from]').val().length > 0 && jQuery('select[name=call_to]').val().length > 0) {
		cmsClient.postForm('travelsim', 'rates', 'rates-find-form', '', function(response) {
			jQuery('.rates_box').html(response);
			jQuery('.rates_box').show();
		});
	} else {
		cmsClient.showError($t('err_travelsim.rates_select_country'));
	}
	if(typeof(url) != 'undefined') cmsClient.host_url = b_url;
}

function openForm(body, application, action, params, num, command) {
	var defalut_params = {show_loading: false};
	cmsClient.loadForm(application, action, body, jQuery.extend(defalut_params, params), function() { 
		jQuery(body).show(); 
		
		switch(command) {
			case 'activate':
				jQuery('#activatePosition' + num).hide();
			break;
			case 'details':
				jQuery('#openDetails' + num).hide();
				jQuery('#closeDetails' + num).show();
				jQuery('#openPosition' + num).show();
				jQuery('#closePosition' + num).hide();
			break;
			case 'position':
				jQuery('#openPosition' + num).hide();
				jQuery('#closePosition' + num).show();
				jQuery('#openDetails' + num).show();
				jQuery('#closeDetails' + num).hide();
			break;
		}
		
	}, 'html');
}

function closeForm(body, num, command) {
	jQuery(body).hide();
	switch(command) {
		case 'details':
			jQuery('#openDetails' + num).show();
			jQuery('#closeDetails' + num).hide();
		break;
		case 'position':
			jQuery('#openPosition' + num).show();
			jQuery('#closePosition' + num).hide();
		break;
	}
}

function doPositionActivate() {
    cmsClient.showConfirm($t('confirm_travelsim.positioning_activate', false, false), function() {
       jQuery('#positioning-activation-form').submit();
    });
}

$(document).ready( function (){
	jQuery('[title]').tooltip({position: {my: "left bottom", at: "left top", offset: "-3"}});

	if( jQuery('.attention').length > 0 ) {
		cmsClient.showMessage( jQuery('.attention').html() );
	}
});
