var obj = {
4: { url: '/Ajax/Visitor', name: 'Lượt truy cập' },
0: {
title: 'Information', close: 'Schließen',
urlTypeHead: '/Filter/TypeHead'
},
1: { url: '', name: 'chưa biết' },
2: { controller: 'webpart' },
3: { url: '/Product/quickview' },
5: { url: '/WebPart/SendFriend', name: 'Per E-Mail weiterempfehlen' },
6: { url: '/Gutschein/Detail', name: 'Gutschein' },
7: { url: '/Deal/Detail', name: 'Deals' }
};
var clipboardModal;
function ViewGutschein(id, title) {
Loading();
$.ajax({
url: obj[6].url + '?ran=' + Math.random(),
type: 'POST',
data: { id: id },
cache: false,
success: function (data) {
RemoveLoading();
$('#myModal .modal-title').html(title);
$('#myModal .modal-body').html(data);
$('#myModal').modal({
keyboard: false
});
clipboardModal = new Clipboard('#btn-copy-modal');
clipboardModal.on('success', function (e) {
$('#btn-copy-modal').addClass('btn-disabled');
$('#btn-copy-modal').html('Code wurde kopiert');
});
$("#Gutscheincode.hasCopy").focus(function () { $(this).select(); });
},
error: function (jqXHR, textStatus, errorThrown) {
RemoveLoading();
}
});
return false;
}
function ViewDeal(id, title) {
Loading();
$.ajax({
url: obj[7].url + '?ran=' + Math.random(),
type: 'POST',
data: { id: id },
cache: false,
success: function (data) {
RemoveLoading();
$('#myModal .modal-title').html(title);
$('#myModal .modal-body').html(data);
$('#myModal').modal({
keyboard: false
});
clipboardModal = new Clipboard('#btn-copy-modal');
clipboardModal.on('success', function (e) {
$('#btn-copy-modal').addClass('btn-disabled');
$('#btn-copy-modal').html('Code wurde kopiert');
});
$("#Gutscheincode.hasCopy").focus(function () { $(this).select(); });
},
error: function (jqXHR, textStatus, errorThrown) {
RemoveLoading();
}
});
return false;
}
function SendMail(url) {
if (url == '') {
url = document.location.href;
}
Loading();
$.ajax({
url: obj[5].url + '?ran=' + Math.random(),
type: 'POST',
data: { url: url },
cache: false,
success: function (data) {
RemoveLoading();
$('#myModal .modal-title').html(obj[5].name);
$('#myModal .modal-body').html(data);
$('#myModal').modal({
keyboard: false
});
$("#frmSendFreind").validate({
errorClass: "help-block animation-slideDown",
errorElement: "div",
errorPlacement: function (e, a) {
a.parents(".form-group > div").append(e)
},
highlight: function (e) {
$(e).closest(".form-group").removeClass("has-success has-error").addClass("has-error"),
$(e).closest(".help-block").remove()
},
success: function (e) {
e.closest(".form-group").removeClass("has-success has-error"),
e.closest(".help-block").remove()
},
submitHandler: function (form) {
Loading();
$.ajax({
url: $(form).attr('action') + '?ran=' + Math.random(),
type: 'POST',
data: $(form).serialize(),
dataType: 'json',
cache: false,
success: function (data) {
RemoveLoading();
if (data.status == true) {
$('#myModal').modal('hide');
ShowMsg(data.msg, 'success');
} else {
ShowMsg(data.msg, 'error');
}
},
error: function (jqXHR, textStatus, errorThrown) {
RemoveLoading();
ShowMsg(errorThrown, 'error');
}
});
return false;
}
});
},
error: function (jqXHR, textStatus, errorThrown) {
RemoveLoading();
}
});
return false;
}
$scrollPosition = 0;
function companyScroll(value) {
$scrollPosition += value;
if ($scrollPosition < 0) {
$scrollPosition = 0;
}
$('.companyList').scrollLeft($scrollPosition);
}
function resizeCompany() {
$w = 0;
$('.companyList ul li').each(function () {
$w += $(this).width() + 6;
});
$('.companyList ul').css('min-width', $w);
$wWin = $(window).width();
if ($w > $wWin) {
$('#company .btnLeft,#company .brnRight').removeClass('hidden');
} else {
$('#company .btnLeft,#company .brnRight').addClass('hidden');
}
}
$(function () {
resizeCompany();
$(window).resize(function () {
resizeCompany();
});
setTimeout("resizeCompany()", 2000);
SearchTypeHead();
});
function highlight(text, html) {
var src_str = html;
var term = text;
term = term.replace(/(\s+)/, "(<[^>]+>)*$1(<[^>]+>)*");
var pattern = new RegExp("(" + term + ")", "gi");
src_str = src_str.replace(pattern, "$1");
src_str = src_str.replace(/([^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/, "$1$2$4");
return src_str;
}
var callBackTypeHeadTimeouts = null;
function SearchTypeHead() {
var $request;
$("input#txtSearch").keyup(function () {
if ($request != null) {
$request.abort();
$request = null;
}
if (callBackTypeHeadTimeouts != null) {
clearTimeout(callBackTypeHeadTimeouts);
}
callBackTypeHeadTimeouts = setTimeout(function () {
$ulTypeHead = $('ul.box-typehead-list');
var keySearch = $("input#txtSearch").val();
if ($("input#txtSearch").val().length == 0) {
$ulTypeHead.empty();
} else {
$ulTypeHead.html('');
$request = $.ajax({
url: obj[0].urlTypeHead,
type: 'GET',
dataType: 'JSON',
data: {
search: keySearch
},
success: function (data) {
$ulTypeHead.empty();
$.each(data, function (i, v) {
var key = '{1}';
$ulTypeHead.append(key.f(v.name, highlight(keySearch, v.name)));
});
}
});
}
}, 500);
});
$(document).on('click', 'ul.box-typehead-list li a', function () {
$("input#txtSearch").val($(this).data('name'));
$('#btnSearch').click();
return false;
})
}