var TixCom = TixCom || {};
var touchesInAction = {};
var current_spot;
TixCom.api = (function () {
var sess_id;
var head = document.getElementsByTagName('head')[0];
var tixcom_url = 'https://www.tixcom.de/';
var security_level = 2; // 0 = no SSL; 1 = use SSL only on SSL hosts (auto detection); 2 = like level 1 + some sensible requests always with SSL; 3 = SSL enabled
var local_storage = {};
var texts = {};
var req_nr = 0;
var callbacks = [];
var dynamic_elements = [];
var lang = 'de';
var event_id = 1043;
var schedule_id = 0;
var tixcom_container = null;
var price_category_id = 0;
var spot_clicked = false;
var is_in_iframe = (self != top);
var paypal_payment_method = false;
var payment_method = false;
var wnd_paypal = null;
var spots_type = 0;
var spots_w = 10;
var spots_h = 10;
var dealer_id = 15956;
function initialize() {
var cookie_name = 'sess_id_' + event_id;
var cookie_value = '696b6b781421f6786c5af225f0b24cc6';
sess_id = readCookie(cookie_name);
if (!sess_id) {
createCookie(cookie_name, cookie_value);
sess_id = readCookie(cookie_name);
}
if (document.location.protocol == 'https:' && (security_level == 1 || security_level == 2)) {
tixcom_url = tixcom_url.replace('http:', 'https:');
}
if (isIe()) {
var params = '';
var elems = document.getElementsByTagName('link');
for (var i = 0; i < elems.length; i++) {
if (elems[i].rel.toLowerCase() == 'stylesheet') {
params += 'f[]=' + encodeURI(elems[i].href) + '&';
}
}
var css_file = 'tixcom4ie.css?' + params;
} else {
var css_file = '../assets/build/widget_combine.min.css';
var css_file2 = '../assets/build/widget_custom.css';
}
var css_node = document.createElement('link');
css_node.type = 'text/css';
css_node.rel = 'stylesheet';
css_node.href = tixcom_url + css_file;
var css_node2 = document.createElement('link');
css_node2.type = 'text/css';
css_node2.rel = 'stylesheet';
css_node2.href = tixcom_url + css_file2;
if (head.childElementCount > 0) {
head.insertBefore(css_node, head.firstElementChild);
head.insertBefore(css_node2, head.firstElementChild);
} else {
head.appendChild(css_node);
head.appendChild(css_node2);
}
var jq_node = document.createElement('script');
jq_node.language = 'JavaScript';
jq_node.type = 'text/javascript';
if(typeof jQuery == "undefined" || window.location.hostname == 'www.afisha.de') {
jq_node.src = tixcom_url + '../assets/build/widget_scripts.min.js';
} else {
jq_node.src = tixcom_url + '../assets/build/widget_no_jq_scripts.min.js';
}
head.appendChild(jq_node);
/*
var jq_node_ms = document.createElement('script');
jq_node_ms.language = 'JavaScript';
jq_node_ms.type = 'text/javascript';
jq_node_ms.src = 'https://payment-test.maksekeskus.ee/checkout/dist/checkout.min.js';
head.appendChild(jq_node_ms);
*/
var jq_font = document.createElement('link');
jq_font.type = 'text/javascript';
css_node.rel = 'stylesheet';
jq_font.src = 'https://fonts.googleapis.com/css?family=Open+Sans';
head.appendChild(jq_font);
/*
var js_node = document.createElement('script');
js_node.language = 'JavaScript';
js_node.type = 'text/javascript';
js_node.src = tixcom_url + 'assets/js/e-smart-zoom-jquery.min.js';
head.appendChild(js_node);
*/
document.write('
'+
'
-'+
'
' +
'
+'+
'
'+
' €'+category.product_price+''+
'
'+
'';
}
//elemTR.appendChild(elemTD1);
//elemTR.appendChild(elemTD2);
//elemTR.appendChild(elemTD3);
tbody2.insertBefore(elemTR, last_child);
}
}
calculateTicketsCount();
} else {
if (response.error_message) {
document.getElementById('tixcom_error_message').innerHTML = response.error_message;
}
}
});
}
function handleSpotList(spot_list, refresh) {
if (!spot_list) {
return false;
}
var spot = null;
if (refresh) {
for (var i = 0; i < spot_list.length; i++) {
spot = spot_list[i];
// ignore currently self reserved spot
if (spot.self_reserved) {
continue;
}
var div = document.getElementById('tixcom_spot_' + spot.spot_id);
if (spot.free) {
div.style.cursor = 'pointer';
removeEvent(div, 'click', spotClicked);
removeEvent(div, 'touchstart', touchStartHandler);
removeEvent(div, 'touchend', spotClicked);
removeEvent(div, 'mouseover', spotOver);
removeEvent(div, 'mouseout', spotOut);
addEvent(div, 'click', spotClicked);
addEvent(div, 'touchstart', touchStartHandler);
addEvent(div, 'touchend', spotClicked);
addEvent(div, 'mouseover', spotOver);
addEvent(div, 'mouseout', spotOut);
div.setAttribute('color_id', spot.color_id);
} else {
div.style.cursor = 'auto';
removeEvent(div, 'click', spotClicked);
removeEvent(div, 'touchstart', touchStartHandler);
removeEvent(div, 'touchend', spotClicked);
removeEvent(div, 'mouseover', spotOver);
removeEvent(div, 'mouseout', spotOut);
div.setAttribute('color_id', 999);
}
setSpotColor(div);
}
} else {
var spot_layer = document.getElementById('tixcom_spot_layer');
if (spot_layer) {
spot_layer.parentNode.removeChild(spot_layer)
}
spot_layer = document.createElement('div');
spot_layer.id = 'tixcom_spot_layer';
for (i = 0; i < spot_list.length; i++) {
spot = spot_list[i];
var div = document.createElement('div');
div.id = 'tixcom_spot_' + spot.spot_id;
if (spot.spot_type == 2) {
div.className = 'spot spot_rect';
div.style.position = 'absolute';
div.style.width = spot.width + 'px';
div.style.height = spot.height + 'px';
div.style.top = spot.y + 'px';
div.style.left = spot.x + 'px';
div.style.cursor = 'pointer';
div.style.background = '#' + spot.code;
jQuery(div).html('
' + spot.row_name + '
');
div.style.webkitTransform = 'rotate(' + spot.rotate + 'deg)';
div.style.mozTransform = 'rotate(' + spot.rotate + 'deg)';
div.style.msTransform = 'rotate(' + spot.rotate + 'deg)';
div.style.oTransform = 'rotate(' + spot.rotate + 'deg)';
div.style.transform = 'rotate(' + spot.rotate + 'deg)';
} else {
div.className = 'spot' + ( (spots_type == 1) ? ' big_spot' : '' );
div.title = (spot.row_name.length > 0 ? spot.row_name + ': ' : '' ) + spot.row + ', ' + (spot.spot_name.length > 0 ? spot.spot_name + ': ' : '' ) + spot.spot + (spot.area.length > 0 ? ', ' + (spot.area_name.length > 0 ? (spot.area_name + ': ' + spot.area) : spot.area) : '') + ', ' + getText('event_price') + ': ' + spot.price + ' €';
div.style.top = (spots_type == 1) ? spot.y + 'px' : (spot.y - 5) + 'px';
div.style.left = (spots_type == 1) ? spot.x + 'px' : (spot.x - 5) + 'px';
}
div.setAttribute('spot_id', spot.spot_id);
div.setAttribute('spot_type', spot.spot_type);
div.setAttribute('row_name', spot.row_name);
div.setAttribute('row', spot.row);
div.setAttribute('area_name', spot.area_name);
div.setAttribute('area', spot.area);
div.setAttribute('spot_name', spot.spot_name);
div.setAttribute('price', spot.price);
div.setAttribute('amount', spot.amount);
div.setAttribute('price_category_id', spot.price_category_id);
div.setAttribute('color_id', spot.color_id);
div.setAttribute('color_code', spot.code);
if (spot.free || spot.self_reserved) {
if (spot.spot_type != 2) {
addEvent(div, 'click', spotClicked);
addEvent(div, 'touchstart', touchStartHandler);
addEvent(div, 'touchend', spotClicked);
}
addEvent(div, 'mouseover', spotOver);
addEvent(div, 'mouseout', spotOut);
} else {
div.style.cursor = 'auto';
div.setAttribute('color_id', 999);
}
if (spot.self_reserved) {
if (spot.spot_type != 2) {
div.setAttribute('checked', 'true');
}
setSpotColorTarget(div);
} else {
div.setAttribute('checked', '');
setSpotColor(div);
}
spot_layer.appendChild(div);
}
document.getElementById('tixcom_seating_div').appendChild(spot_layer);
var adiv = document.getElementsByClassName('tixplus');
for (var i = 0; i < adiv.length; i++) {
addEvent(adiv[i], 'click', plusClicked);
}
adiv = document.getElementsByClassName('tixminus');
for (var i = 0; i < adiv.length; i++) {
addEvent(adiv[i], 'click', minusClicked);
}
adiv = document.getElementsByClassName('spot_input');
for (var i = 0; i < adiv.length; i++) {
addEvent(adiv[i], 'change', checkTicketsSpot);
}
}
}
function setSpotColor(ele) {
var color_id = ele.getAttribute('color_id');
if (color_id > 0) {
if (ele.getAttribute('spot_type') == '2') {
ele.style.background = '#' + ele.getAttribute('color_code');
return;
}
if (color_id == 1) { // Rot
ele.style.backgroundPosition = '0px -' + (spots_w * 2) + 'px';
} else if (color_id == 2) { // Pink
ele.style.backgroundPosition = '0px -' + (spots_w * 5) + 'px';
} else if (color_id == 3) { // Orange
ele.style.backgroundPosition = '0px -' + (spots_w * 3) + 'px';
} else if (color_id == 4) { // Gelb
ele.style.backgroundPosition = '0px -' + (spots_w * 9) + 'px';
} else if (color_id == 5) { // Grün
ele.style.backgroundPosition = '0px -' + spots_w + 'px';
} else if (color_id == 6) { // Grüngelb
ele.style.backgroundPosition = '0px -' + (spots_w * 7) + 'px';
} else if (color_id == 7) { // Blaugrün
ele.style.backgroundPosition = '0px -' + (spots_w * 8) + 'px';
} else if (color_id == 8) { // Blau
ele.style.backgroundPosition = '0px 0px';
} else if (color_id == 9) { // Violett
ele.style.backgroundPosition = '0px -' + (spots_w * 6) + 'px';
} else if (color_id == 10) { // Braun
ele.style.backgroundPosition = '0px -' + (spots_w * 4) + 'px';
} else if (color_id == 999) { // Grau
ele.style.backgroundPosition = '0px -' + (spots_w * 10) + 'px';
}
} else {
ele.style.backgroundImage = '';
}
}
function setSpotColorTarget(ele) {
var color_id = ele.getAttribute('color_id');
if (color_id > 0) {
if (ele.getAttribute('spot_type') == '2') {
ele.style.background = '#' + ele.getAttribute('color_code');
return;
}
if (color_id == 1) { // Rot
ele.style.backgroundPosition = '0px -' + (spots_w * 15) + 'px';
} else if (color_id == 2) { // Pink
ele.style.backgroundPosition = '0px -' + (spots_w * 18) + 'px';
} else if (color_id == 3) { // Orange
ele.style.backgroundPosition = '0px -' + (spots_w * 16) + 'px';
} else if (color_id == 4) { // Gelb
ele.style.backgroundPosition = '0px -' + (spots_w * 22) + 'px';
} else if (color_id == 5) { // Grün
ele.style.backgroundPosition = '0px -' + (spots_w * 14) + 'px';
} else if (color_id == 6) { // Grüngelb
ele.style.backgroundPosition = '0px -' + (spots_w * 20) + 'px';
} else if (color_id == 7) { // Blaugrün
ele.style.backgroundPosition = '0px -' + (spots_w * 21) + 'px';
} else if (color_id == 8) { // Blau
ele.style.backgroundPosition = '0px -' + (spots_w * 13) + 'px';
} else if (color_id == 9) { // Violett
ele.style.backgroundPosition = '0px -' + (spots_w * 19) + 'px';
} else if (color_id == 10) { // Braun
ele.style.backgroundPosition = '0px -' + (spots_w * 17) + 'px';
}
} else {
ele.style.backgroundImage = '';
}
}
function spotClicked(event, amount) {
if (spot_clicked) {
return false;
}
var touches = event.changedTouches;
var moved = false;
if (touches) {
for (var j = 0; j < touches.length; j++) {
/* access stored touch info on touchend */
var theTouchInfo = touchesInAction["$" + touches[j].identifier];
theTouchInfo.dx = touches[j].pageX - theTouchInfo.pageX;
/* x-distance moved since touchstart */
theTouchInfo.dy = touches[j].pageY - theTouchInfo.pageY;
/* y-distance moved since touchstart */
if ((theTouchInfo.dx > 1 || theTouchInfo.dx < -1 ) || (theTouchInfo.dy > 1 || theTouchInfo.dy < -1 )) {
moved = true;
}
}
}
if (moved) {
return false;
}
var elem;
if (amount != undefined) {
elem = current_spot;
} else {
elem = this;
}
spot_clicked = true;
//var img = document.createElement('img');
//img.src = tixcom_url + '/img/ajax.gif';
//img.style.position = 'absolute';
//img.style.zIndex = 100;
//img.style.top = (this.offsetTop + 1) + 'px';
//img.style.left = (this.offsetLeft + 1) + 'px';
//document.getElementById('tixcom_seating_div').appendChild(img);
var spinner = document.getElementById('spinner_bg');
spinner.style.display = 'block';
if (amount == undefined) {
amount = 0;
}
var method = isOldBrowser() || is_in_iframe ? 'GET' : 'POST';
var reserve = elem.getAttribute('checked') ? '' : 'true';
var params = {
schedule_id: price_category_id,
spot_id: elem.getAttribute('spot_id'),
reserve: (elem.getAttribute('spot_type') == 2 && amount != 0) ? true : reserve,
dealer_id: dealer_id,
amount: amount,
spot_type: elem.getAttribute('spot_type')
};
request('set_spot_status.php', method, params, function (response) {
if (response.status == 'success') {
if (elem.getAttribute('spot_type') != 2) {
if (elem.getAttribute('checked')) {
elem.setAttribute('checked', '');
setSpotColor(elem);
} else {
elem.setAttribute('checked', 'true');
setSpotColorTarget(elem);
}
}
}
handleSpotList(response.spot_list, true);
checkTicketsReservedCount(response.tickets_reserved);
//img.parentNode.removeChild(img);
spinner.style.display = 'none';
spot_clicked = false;
});
}
function checkTicketsReservedCount(tickets_reserved) {
document.getElementById('tixcom_reserved_tickets_count').innerHTML = tickets_reserved.count + ' ' + getText('event_total_tix');
document.getElementById('tixcom_reserved_tickets_price_total').innerHTML = tickets_reserved.price_total + ' €';
if (tickets_reserved.count > 0) {
document.getElementById('tixcom_btn_load_shopping_cart').removeAttribute('disabled');
} else {
document.getElementById('tixcom_btn_load_shopping_cart').setAttribute('disabled', 'disabled');
}
}
function spotOver() {
if (this.getAttribute('checked')) {
setSpotColor(this);
} else {
setSpotColorTarget(this);
}
}
function spotOut() {
if (this.getAttribute('checked')) {
setSpotColorTarget(this);
} else {
setSpotColor(this);
}
}
function showCompleteScheduleList() {
document.getElementById('tixcom_error_message').style.display = 'none';
document.getElementById('tixcom_btn_add_to_shopping_cart').parentNode.insertBefore(document.getElementById('tixcom_btn_back'), document.getElementById('tixcom_btn_add_to_shopping_cart'));
document.getElementById('tixcom_category_table').style.display = 'none';
document.getElementById('tixcom_schedule_table').style.display = 'block';
document.getElementById('tix-widget-button-process-container').style.display = 'none';
document.getElementById('tixcom_changed_schedule').style.display = 'none';
//document.getElementById('tix-widget-plan').style.display = 'none';
document.getElementById('tixcom_seating_plan').style.display = 'none';
document.getElementById('tixcom_btn_load_shopping_cart').style.display = 'none';
document.getElementById('tix-widget-prices-block').style.display = 'none';
document.getElementById('tix-widget-ticket-total').style.display = 'none';
// http://www.webdeveloper.com/forum/showthread.php?t=197541
if (typeof document.getElementsByClassName != 'function') {
document.getElementsByClassName = function () {
var elms = document.getElementsByTagName('*');
var ei = new Array();
for (i = 0; i < elms.length; i++) {
if (elms[i].getAttribute('class')) {
if (typeof elms[i].getAttribute('class') == 'string') {
ecl = elms[i].getAttribute('class').split(' ');
for (j = 0; j < ecl.length; j++) {
if (ecl[j].toLowerCase() == arguments[0].toLowerCase()) {
ei.push(elms[i]);
}
}
}
} else if (elms[i].className) {
if (typeof elms[i].className == 'string') {
ecl = elms[i].className.split(' ');
for (j = 0; j < ecl.length; j++) {
if (ecl[j].toLowerCase() == arguments[0].toLowerCase()) {
ei.push(elms[i]);
}
}
}
}
}
return ei;
}
}
var elems = document.getElementsByClassName('tixcom_buy_tickets_btn');
for (var i = 0; i < elems.length; i++) {
elems[i].removeAttribute('disabled');
}
}
function plusClicked(event) {
var spot_id = this.getAttribute('spot_id');
current_spot = document.getElementById('tixcom_spot_' + spot_id);
increaseSpot(spot_id, 1, event);
}
function minusClicked(event) {
var spot_id = this.getAttribute('spot_id');
current_spot = document.getElementById('tixcom_spot_' + spot_id);
decreaseSpot(spot_id, 1, event);
}
function decreaseSpot(nr, min_order, event) {
var ele = document.getElementById('spot_input_' + nr);
if (parseInt(ele.value) - min_order >= 0) {
ele.value = parseInt(ele.value) - min_order;
}
spotClicked(event, ele.value);
}
function increaseSpot(nr, min_order, event) {
var ele = document.getElementById('spot_input_' + nr);
if (parseInt(ele.value) + min_order <= 99) {
ele.value = parseInt(ele.value) + min_order;
}
spotClicked(event, ele.value);
}
function checkTicketsSpot(event) {
var min_order = 1;
var nr = this.getAttribute('spot_id');
var ele = document.getElementById("spot_input_" + nr);
current_spot = document.getElementById('tixcom_spot_' + nr);
$('#tixcom_btn_load_shopping_cart').disabled = true;
if (parseInt(ele.value) % min_order != 0) {
ele.value = ele.value - (parseInt(ele.value) % min_order) + min_order;
}
if (parseInt(ele.value) < 0) {
ele.value = 0;
}
spotClicked(event, ele.value);
}
function getItems(action,price,min_order) {
var items = document.getElementById('tixcom_category_table').getElementsByTagName('input');
var total = 1;
var price_total = .0;
var total_data = 0;
var price_html = document.getElementById('tixcom_reserved_tickets_price_total');
var count_html = document.getElementById('tixcom_reserved_tickets_count');
if (price_html.dataset.price != 0) {
price_total = parseFloat(price_html.dataset.price);
}
if (count_html.dataset.count != 0) {
total_data = parseInt(count_html.dataset.count);
}
for (var i = 0; i < items.length; i++) {
if (action == 'plus') {
total += Number(items[i].value);
}
}
// КОСТЫЛИЩЕ при добавлении и удалении билетов
// TODO: надо этот пиздец привести к нормальномк виду!!!
// П.С такая же хуйня есть в templates\module\event.tpl
if (action == 'plus') {
if (min_order > 1){
price_total += price*min_order;
} else {
price_total += price;
}
} else {
if (price_total != 0) {
if (min_order > 1){
price_total -= price*min_order;
} else {
price_total -= price;
}
}
if (total_data != 0) {
if (min_order > 1){
total = total_data-min_order;
} else {
total = total_data-1;
}
} else {
total = 0;
}
}
price_html.setAttribute('data-price', (Math.round(price_total * 100) / 100).toFixed(2));
count_html.setAttribute('data-count', total);
price_html.innerHTML = '€'+ (Math.round(price_total * 100) / 100).toFixed(2);
count_html.innerHTML = total;
return total;
}
// простите ребята но это полный .... п.с. код не мой я просто дописовал
function increaseTicketsCount(id, max, min_order, price) {
var ele = document.getElementById('tixcom_category_input_' + id);
var value = parseInt(ele.value);
ele.value = Math.min(max, value + min_order - 1);
getItems('plus',price, min_order);
calculateTicketsCount();
}
function decreaseTicketsCount(id, min_order, price) {
var ele = document.getElementById('tixcom_category_input_' + id);
var value = parseInt(ele.value);
ele.value = Math.max(0, value - min_order);
if (value > 0){
getItems('minus', price, min_order);
}
calculateTicketsCount()
}
function checkTickets(id, max, min_order) {
//document.getElementById('tixcom_btn_add_to_shopping_cart').setAttribute('disabled', 'disabled');
window.setTimeout(function () {
var ele = document.getElementById('tixcom_category_input_' + id);
var value = parseInt(ele.value);
if (value % min_order != 0) {
value = value - (value % min_order) + min_order;
}
value = Math.min(max, value);
value = Math.max(0, value);
ele.value = value;
calculateTicketsCount()
}
, 2000);
}
function calculateTicketsCount() {
var elems = document.getElementById('tixcom_category_table').getElementsByTagName('input');
var tickets_ordered_count = 0;
for (var i = 0; i < elems.length; i++) {
if (elems[i].type == 'text') {
tickets_ordered_count += elems[i].value;
}
}
if (tickets_ordered_count > 0) {
document.getElementById('tixcom_btn_add_to_shopping_cart').removeAttribute('disabled');
} else {
//document.getElementById('tixcom_btn_add_to_shopping_cart').setAttribute('disabled', 'disabled');
}
}
function addToShoppingCart() {
var params = {};
var elems = document.getElementById('tixcom_category_table').getElementsByTagName('input');
for (var i = 0; i < elems.length; i++) {
if (elems[i].type == 'text' && parseInt(elems[i].value) >= 0) {
params[elems[i].name] = parseInt(elems[i].value);
}
}
params['dealer_id'] = dealer_id;
request('add_to_shopping_cart.php', 'GET', params, function (response) {
document.getElementById('tixcom_btn_add_to_shopping_cart').removeAttribute('disabled');
if (response.status == 'success') {
loadShopingCart();
}
});
}
function goToShoppingCart() {
loadShopingCart();
}
function login() {
var params = {};
var elems = document.getElementById('tixcom_login_table').getElementsByTagName('input');
for (var i = 0; i < elems.length; i++) {
if (elems[i].type == 'text' || elems[i].type == 'password') {
params[elems[i].name] = encodeURI(elems[i].value);
}
}
var method = isOldBrowser() || is_in_iframe ? 'GET' : 'POST';
request('login.php', method, params, function (response) {
document.getElementById('tixcom_btn_login').removeAttribute('disabled');
if (response.status == 'success') {
loadShopingCart();
}
}, true);
}
function logout() {
request('logout.php', 'GET', null, function (response) {
if (response.status == 'success') {
if (local_storage.address) {
local_storage.address = {};
}
getEvent();
}
});
}
function goBackToPriceCategory() {
getPriceCategoryList(price_category_id);
}
function checkout() {
var params = parseAddressFormToParams();
var method = isOldBrowser() || is_in_iframe ? 'GET' : 'POST';
request('check_data.php', method, params, function (response) {
document.getElementById('tixcom_btn_forward').removeAttribute('disabled');
if (response.status == 'success') {
request('checkout.php', 'GET', null, function (response) {
paypal_payment_method = response.paypal_payment_method;
payment_method = response.payment_method;
}, true);
}
}, true);
}
function parseAddressFormToParams() {
var params = {};
var elems = Array.prototype.slice.call(document.getElementById('tixcom_address_form').getElementsByTagName('input'));
elems = elems.concat(Array.prototype.slice.call(document.getElementById('tixcom_address_form').getElementsByTagName('textarea')))
for (var i = 0; i < elems.length; i++) {
if (elems[i].type == 'radio' && elems[i].checked) {
params[elems[i].name] = elems[i].value;
}
if (elems[i].type == 'checkbox' && elems[i].checked) {
params[elems[i].name] = elems[i].value;
}
if (elems[i].type == 'text' || elems[i].type == 'password') {
params[elems[i].name] = encodeURI(elems[i].value);
}
if (elems[i].tagName == 'TEXTAREA') {
params[elems[i].name] = encodeURI(elems[i].value);
}
}
return params;
}
function delFromShoppingCart(id, selected) {
selected = selected || false;
request('del_from_shopping_cart.php', 'GET', {id: id, selected: selected}, function (response) {
if (response.status == 'success') {
loadShopingCart();
}
});
}
function loadShopingCart() {
request('get_shopping_cart.php', 'GET', null, function (response) {
var elems;
if (response.status == 'success') {
if (response.is_empty) {
getEvent();
return;
}
var type;
elems = document.getElementById('tixcom_registertype_table').getElementsByTagName('input');
for (var i = 0; i < elems.length; i++) {
if (elems[i].type == 'radio' && elems[i].checked) {
type = elems[i].value;
}
}
if (type == 'guest') {
TixCom.api.switchTo('form');
} else if (type == 'login') {
TixCom.api.switchTo('login');
}
addEvent(document.getElementById('tixcom_inp_coupon'), 'keyup', onKeyUpAtCoupon);
elems = document.getElementById('tixcom_login_table').getElementsByTagName('input');
for (var i = 0; i < elems.length; i++) {
if (elems[i].type == 'text' || elems[i].type == 'password') {
addEvent(elems[i], 'keyup', function (evt) {
if (evt.keyCode == 13) {
TixCom.api.login();
}
});
}
}
if (document.getElementById('tixcom_inp_coupon').value.length == 4) {
onKeyUpAtCoupon();
}
}
// restore stored local data
if (local_storage.address) {
elems = document.getElementById('tixcom_address_form').getElementsByTagName('input');
for (var i = 0; i < elems.length; i++) {
if (elems[i].type == 'checkbox') {
if (local_storage.address[elems[i].name]) {
elems[i].setAttribute('checked', 'true');
} else {
elems[i].removeAttribute('checked');
}
if (elems[i].name == 'create_account') {
createAccount(elems[i]);
}
}
if (elems[i].type == 'text' || elems[i].type == 'password') {
if (local_storage.address[elems[i].name]) {
elems[i].value = decodeURI(local_storage.address[elems[i].name]);
}
}
}
}
}, true);
}
function onKeyUpAtCoupon() {
var elem = document.getElementById('tixcom_inp_coupon');
var voucher_code = elem.value;
if (voucher_code.length > 0) {
document.getElementById('tixcom_btn_forward').setAttribute('disabled', 'disabled');
} else if (voucher_code.length == 0) {
document.getElementById('tixcom_btn_forward').removeAttribute('disabled');
}
if (voucher_code.length == 4) {
request('check_coupon.php', 'GET', {event_id: event_id, code: voucher_code}, function (response) {
document.getElementById('tixcom_btn_forward').removeAttribute('disabled');
if (response.status == 'success') {
elem.className = 'coupon success';
//elem.setAttribute('disabled', 'disabled');
document.getElementById('tixcom_td_coupon').innerHTML = response.price + ' €';
document.getElementById('tixcom_td_total').innerHTML = response.total + ' €';
} else if (response.status == 'failed') {
elem.className = 'coupon fail';
}
});
} else {
elem.className = 'coupon';
}
}
function switchTo(type) {
var elem = document.getElementById('tixcom_error_message');
elem.style.display = 'none';
if (type == 'form') {
document.getElementById('tixcom_error_placeholder_form').appendChild(elem);
document.getElementById('tixcom_address_form').style.display = 'block';
document.getElementById('tixcom_login_table').style.display = 'none';
} else if (type == 'login') {
document.getElementById('tixcom_error_placeholder_login').appendChild(elem);
document.getElementById('tixcom_address_form').style.display = 'none';
document.getElementById('tixcom_login_table').style.display = 'block';
}
}
function switchShippingAddress(elem) {
if (elem.checked) {
document.getElementById('tixcom_shipping_address_table').style.display = 'block';
} else {
document.getElementById('tixcom_shipping_address_table').style.display = 'none';
}
}
function createAccount(elem) {
if (elem.checked) {
document.getElementById('tixcom_create_account_table').style.display = 'flex';
} else {
document.getElementById('tixcom_create_account_table').style.display = 'none';
}
}
function changedPaymentShipment() {
var params = {};
var elems = document.getElementById('tixcom_payment_and_shipment_form').getElementsByTagName('input');
local_storage['address'] = parseAddressFormToParams();
for (var i = 0; i < elems.length; i++) {
if (elems[i].type == 'radio' && elems[i].checked) {
params[elems[i].name] = elems[i].value;
}
}
request('changed_payment_shipment.php', 'GET', params, function (response) {
if (response.status == 'success') {
loadShopingCart();
}
});
}
function displayTermsAndConditions() {
var elem = document.getElementById('tixcom_terms_and_conditions');
document.getElementById('tixcom_privacy_policy').style.display = 'none';
if (elem.style.display == 'none') {
elem.style.display = 'block';
} else {
elem.style.display = 'none';
}
}
function displayPrivacy() {
var elem = document.getElementById('tixcom_privacy_policy');
document.getElementById('tixcom_terms_and_conditions').style.display = 'none';
if (elem.style.display == 'none') {
elem.style.display = 'block';
} else {
elem.style.display = 'none';
}
}
function createOrder() {
if (is_in_iframe && paypal_payment_method) {
wnd_paypal = window.open('', 'wnd_paypal', 'width=1000,height=800,scrollbars=yes');
}
request('create_order.php', 'GET', {is_in_iframe: is_in_iframe, location: window.location.href}, function (response) {
if (response.status == 'success' && response.paypal_data) {
payPal(response.paypal_data);
} else if (wnd_paypal) {
wnd_paypal.close();
} else if (response.status == 'success' && response.pay_data){
//maksekeskus(response.pay_data); // Надо рефракторить
var data = jQuery.parseJSON(response.pay_data);
window.location.href = data.url;
}
if (!paypal_payment_method || is_in_iframe) {
console.log(payment_method);
if (!payment_method) {
createOrderFinish();
}
}
});
}
function createOrderFinish(scroll_to) {
scroll_to = scroll_to || false;
request('create_order_finish.php', 'GET', null, function (response) {
if (response.status == 'success') {
if (response.redirect_url) {
location=response.redirect_url;
}else if (scroll_to){
window.scrollTo(0, tixcom_container.offsetTop);
}
}
});
}
/*
// надо рефракторить
function maksekeskus(data) {
//console.log(data);
window.cc_callback = function (data) {
alert('The CC dialog returned: \r\n \r\n' + data);
};
var data = JSON.parse(data);
window.Maksekeskus.Checkout.initialize(
{
'key': data.shop_publishablekey,
'transaction': data.transaction_id,
'amount': data.transaction_amount,
'currency': data.transaction_currency,
'email': data.transaction_email,
'clientName': data.transaction_client_name,
'locale': data.transaction_locale,
'name': data.transaction_name,
'description': data.transaction_description,
'completed': data.transaction_completed,
'cancelled': data.transaction_cancelled
}
);
window.Maksekeskus.Checkout.open();
}
*/
// https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_cart_upload
// https://www.paypalobjects.com/de_DE/html/IntegrationCenter/ic_std-variable-reference.html
// https://www.paypal.com/de/cgi-bin/webscr?cmd=p/pdn/howto_checkout-outside
function payPal(data) {
var form = document.createElement('form');
form.setAttribute('action', 'https://www.paypal.com/cgi-bin/webscr');
form.setAttribute('method', 'POST');
form.setAttribute('target', '_top');
form.setAttribute('accept-charset', 'utf-8');
form.style.display = 'none';
for (key in data.params) {
var value = data.params[key];
var input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', key);
input.setAttribute('value', value);
form.appendChild(input);
}
for (idx in data.items) {
var item = data.items[idx];
var input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', 'item_name_' + (parseInt(idx) + 1));
input.setAttribute('value', item.name);
form.appendChild(input);
var input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', 'quantity_' + (parseInt(idx) + 1));
input.setAttribute('value', item.quantity);
form.appendChild(input);
var input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', 'shipping_' + (parseInt(idx) + 1));
input.setAttribute('value', item.shipping);
form.appendChild(input);
var input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', 'handling_' + (parseInt(idx) + 1));
input.setAttribute('value', item.handling);
form.appendChild(input);
var input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', 'amount_' + (parseInt(idx) + 1));
input.setAttribute('value', item.price);
form.appendChild(input);
}
tixcom_container.appendChild(form);
if (is_in_iframe) {
form.setAttribute('target', 'wnd_paypal');
if (wnd_paypal) {
wnd_paypal.focus();
}
}
form.submit();
}
// main method to make calls
function request(url, method, params, callback, ssl) {
method = method || 'GET';
params = params || {};
callback = callback || function () {
};
ssl = ssl || false;
if (document.getElementById('tixcom_error_message')) {
document.getElementById('tixcom_error_message').style.display = 'none';
}
var request_url = tixcom_url;
if ((ssl && security_level == 2) || security_level == 3) {
request_url = request_url.replace('http:', 'https:');
}
if (method == 'GET') {
callbacks[req_nr] = callback;
var req_params = '';
for (param in params) {
req_params += '&' + param + '=' + escape(params[param]);
}
var elem = document.createElement('script');
elem.type = 'text/javascript';
elem.src = request_url + 'api/' + url + '?req_nr=' + req_nr + '&lang=' + lang + '&sess_id=' + sess_id + req_params;
elem.charset = 'utf-8';
head.appendChild(elem);
} else if (method == 'POST') {
var elem = document.createElement('div');
elem.style.display = 'none';
var form = document.createElement('form');
form.setAttribute('action', request_url + 'api/' + url + '?req_nr=' + req_nr + '&lang=' + lang + '&sess_id=' + sess_id);
form.setAttribute('method', 'POST');
form.setAttribute('accept-charset', 'utf-8');
form.setAttribute('target', 'tixcom_iframe_' + req_nr);
elem.appendChild(form);
for (param in params) {
var input = document.createElement('input');
input.setAttribute('type', 'text');
input.setAttribute('name', param);
input.setAttribute('value', params[param]);
form.appendChild(input);
}
var iframe = document.createElement('iframe');
iframe.setAttribute('name', 'tixcom_iframe_' + req_nr);
elem.appendChild(iframe);
var current_req_nr = req_nr;
callbacks[req_nr] = function (event) {
// http://help.dottoro.com/ljwgvhwh.php
// http://json.org/js.html
var data = JSON.parse(event.data);
if (data.req_nr != current_req_nr) {
return;
}
tixcom_container.removeChild(dynamic_elements[current_req_nr]);
top.window.onmessage = null;
callbacks[current_req_nr] = null;
handleResponse(data, callback);
};
// readme: http://help.dottoro.com/ljjqtjsj.php
top.window.onmessage = callbacks[req_nr];
tixcom_container.appendChild(elem);
form.submit();
}
dynamic_elements[req_nr] = elem;
req_nr++;
}
// method for handling response
function handleResponse(response, callback) {
if (response.status == 'error') {
var ele = document.getElementById('tixcom_error_message');
if (ele) {
ele.style.display = 'block';
ele.innerHTML = response.message;
}
document.getElementById('spinner_bg').style.display = 'none';
} else if (response.status == 'success') {
if (response.html) {
tixcom_container.innerHTML = response.html;
}
} else if (response.status == 'session_expired') {
sendInitializeRequest();
return;
} else {
// ... should not happen! Maybe in this case we should be contacted...
}
callback(response);
}
// translation method
function getText(key) {
return texts[key];
}
// http://www.mediaevent.de/javascript/event_listener.html
function addEvent(obj, type, fn) {
if (obj.addEventListener) {
obj.addEventListener(type, fn, false);
} else if (obj.attachEvent) {
obj['e' + type + fn] = fn;
obj[type + fn] = function () {
obj['e' + type + fn](window.event);
}
obj.attachEvent('on' + type, obj[type + fn]);
}
}
function removeEvent(obj, type, fn) {
if (obj.removeEventListener) {
obj.removeEventListener(type, fn, false);
} else if (obj.detachEvent) {
obj.detachEvent('on' + type, obj[type + fn]);
obj[type + fn] = null;
obj['e' + type + fn] = null;
}
}
function isOldBrowser() {
if (isIe()) {
var version = parseFloat(navigator.appVersion.split('MSIE')[1]);
return version < 9;
}
return false;
}
function isIe() {
return navigator.appVersion.indexOf('MSIE') != -1;
}
// http://www.quirksmode.org/js/cookies.html
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function touchStartHandler(event) {
var touches = event.changedTouches;
for (var j = 0; j < touches.length; j++) {
/* store touch info on touchstart */
touchesInAction["$" + touches[j].identifier] = {
identifier: touches[j].identifier,
pageX: touches[j].pageX,
pageY: touches[j].pageY
};
}
}
function zoomInOut(cmd) {
var cont = jQuery("#tixcom_seating_div");
if (!cont.smartZoom) {
return false;
}
switch (cmd) {
case 'in':
cont.smartZoom('zoom', 0.1);
break;
case 'out':
cont.smartZoom('zoom', -0.1);
break;
case 'left':
cont.smartZoom('pan', -100, 0);
break;
case 'right':
cont.smartZoom('pan', 100, 0);
break;
case 'up':
cont.smartZoom('pan', 0, -100);
break;
case 'down':
cont.smartZoom('pan', 0, 100);
break;
}
}
return {
initialize: function () {
initialize();
},
getPriceCategoryList: function (id) {
getPriceCategoryList(id);
},
showCompleteScheduleList: function () {
showCompleteScheduleList();
},
increaseTicketsCount: function (id, max, min_order, price) {
increaseTicketsCount(id, max, min_order, price);
},
decreaseTicketsCount: function (id, min_order, price) {
decreaseTicketsCount(id, min_order, price);
},
checkTickets: function (id, max, min_order) {
checkTickets(id, max, min_order);
},
calculateTicketsCount: function () {
calculateTicketsCount();
},
addToShoppingCart: function () {
addToShoppingCart();
},
goToShoppingCart: function () {
goToShoppingCart();
},
login: function () {
login();
},
logout: function () {
logout();
},
goBackToPriceCategory: function () {
goBackToPriceCategory();
},
checkout: function () {
checkout();
},
delFromShoppingCart: function (id, selected) {
delFromShoppingCart(id, selected);
},
loadShopingCart: function () {
loadShopingCart();
},
switchTo: function (type) {
switchTo(type);
},
switchShippingAddress: function (elem) {
switchShippingAddress(elem);
},
createAccount: function (elem) {
createAccount(elem);
},
changedPaymentShipment: function () {
changedPaymentShipment();
},
displayTermsAndConditions: function () {
displayTermsAndConditions();
},
displayPrivacy: function () {
displayPrivacy();
},
createOrder: function () {
createOrder();
},
callback: function (nr, params) { // will be used only for JSONP
head.removeChild(dynamic_elements[nr]);
handleResponse(params, callbacks[nr]);
callbacks[nr] = null;
}
};
})();
/*setTimeout(function(){
}, 1000);*/
TixCom.api.initialize();