// DEFINE CONFIGURATION VARIABLES
var offColor = "#AAAAAA";
var onColor = "#FFFFFF";
var basePath = "/media/images/trikotgenerator";
var pageUri = "/index.php?page=bb_tgdata";
// PRE-DEFINE OTHER VARIABLES
// This will be filled by script
var optionPrices = [];
var freePlayers = [];
var optionBuffer = [];
optionBuffer['optionNbg'] = false;
optionBuffer['optionBuli'] = false;
optionBuffer['optionHermes'] = false;
optionBuffer['size'] = "";
var tricots = [];
var sizes = [];
var sizesBySize = [];
var sizesByID = [];
var namesBySize = [];
var priceTricot = parseInt(0);
var priceFlock = parseInt(0);
var priceSum = parseInt(0);
var mlp = 0;
var mlpc = 0;
var maxLengthPlayer = 0;
var allowedChars = "";
var deniedWords = [];
var maxAmount = 0;
var defaultTricot = "";
var preSelection = [];
var getKeepers = 0;
var players = [];
var stockInfos = [];
var shippingTimes = [];
var setName = "spielerset";
var pquant = [];
var pgalleryTG = {};
var currentTricot = [];
// Formatting-Options for prices
Number.prototype.format = function(n, x, s, c) {
var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\D' : '$') + ')',
num = this.toFixed(Math.max(0, ~~n));
return (c ? num.replace('.', c) : num).replace(new RegExp(re, 'g'), '$&' + (s || ','));
};
// SLEEP
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
// GET PLAYERS DEPENDING ON TYPE OF TRICOT
function getPlayers(getType) {
var txtLbl = "";
// CONSTRUCT URI
var p = [];
var playerUri = pageUri + "&r=players";
if (getType != "") {
playerUri += "&getType=" + getType;
}
// EMPTY SELECT
if (getType != "a") {
$("#iptPlayer").empty().append('');
}
// GET PLAYER NAMES
$.getJSON(playerUri, function( data ) {
$.each( data, function( key, val ) {
//if (getType == "a") {
p[val[1]] = val;
//}
if (getType != "a") {
txtLbl = val[1] + " " + val[2];
txtLbl = txtLbl.replace("8M","8").replace("8D","8");
$("").val(val[1]).text(txtLbl).appendTo("#iptPlayer");
}
});
});
//if (getType == "a") {
return p;
//}
}
// SHOW ERRORMESSAGE WHEN ERROR IN PLAYER NAME
function showErrorMessage(errMsg) {
$("#alertMsg").html(errMsg);
$("#alertMsg").css("display","block");
setTimeout(function(){
$("#alertMsg").fadeOut(200,function() {
$('#alertMsg').html("");
});
}, 1500);
}
// GET SLAVES & OTHER THINGS WHEN MASTER CHANGES
function changedMaster(masterID) {
//var masterID = $(this).val();
var mData = tricots[masterID];
currentTricot = mData;
var sizeCount = 0;
var oldSize = "";
var uri = pageUri + "&r=slaves&masterID=" + masterID;
var setPriceBtnPreset = "";
// Reset Playername and remove them etc. if Short and vice versa
//SHORT
if (mData[5] == "1") {
optionBuffer["number"] = "";
$('#iptPlayer').each(
function() {
$(this).removeProp('selected');
}
);
$("#iptPlayer option:first").prop('selected','selected');
$("#iptFreetext").val("");
$("#tricotPlayer").html("");
$("#tricotNumber").html("");
$("#tricotSubline").html("");
$("#editPlayer").css("display","none");
$("#editFreetext").css("display","none");
$("#optionBuliView").css("display","none");
$("#optionHermesView").css("display","none");
$("#optionNbg").prop("checked",false);
$("#optionBuli").prop("checked",false);
$("#optionHermes").prop("checked",false);
} else {
// TRICOT
optionBuffer["number"] = "";
$("#shortNumber").html("");
$("#editPlayer").css("display","block");
$("#editFreetext").css("display","block");
$("#optionBuliView").css("display","block");
$("#optionHermesView").css("display","block");
$("#trOptionNbg").css("display","block");
$("#trOptionBuli").css("display","block");
$("#trOptionHermes").css("display","block");
if (mData[6] == "1") {
var playerTypes = "k";
} else if (mData[9] == "1") {
var playerTypes = "e";
} else if (mData[10] == "1") {
var playerTypes = "w";
} else {
var playerTypes = "p";
}
console.log("get players 1");
console.log(mData);
players = getPlayers(playerTypes);
}
// Set maximum player length
if(mData[9] == "1")
{
maxLengthPlayer = mlpc;
} else
{
maxLengthPlayer = mlp;
}
// Get new Slaves for selected Tricot
$.getJSON( pageUri + "&r=slaves&masterID=" + masterID, function( data ) {
// Save currently selected size
if (optionBuffer["size"] != "") {
oldSize = sizes[optionBuffer["size"]][0]
}
// Empty Size-Selector
$("#productSizes").empty();
$.each( data, function( key, val ) {
sizes[key] = val;
sizesBySize[val[0]] = key;
sizesByID[val[2]] = key;
namesBySize[key] = val[9];
quantArr = val[6].split(".");
if(quantArr[0] < 1) {
quantArr[0] = 0;
}
pquant[key] = quantArr[0];
sizeCount++;
var ac = '';
var id = '#id_'+val[0];
var initialProductsID = $("input[name='product']").val();
var thisSize = val[0];
var iptValue = key;
var radioLbl = '';
$("#productSizes").append(radioLbl+radioIpt+radioVal+radioLblEnd);
stockInfos[key] = "
" + val[7];
shippingTimes[key] = val[10];
// Reset Slave
if (optionBuffer["size"] == "") {
// Preset when called by user
if (preSelection["s"] == val["2"]) {
optionBuffer["size"] = key;
$("#articleNumber").html(key);
$(id).addClass('active');
$("#stockInfo").html("
" + val[7]);
} else {
console.log("OPTION B");
// Preset first if none called
if (sizeCount == 1) {
optionBuffer["size"] = key;
$("#articleNumber").html(key);
$("#stockInfo").html("
" + val[7]);
}
}
} else {
if(sizeCount == 1) {
optionBuffer["size"] = key;
$("#articleNumber").html(key);
$(id).addClass('active');
$("#stockInfo").html("
" + val[7]);
}
}
});
// Set Size to formerly selected value
if (optionBuffer["size"] != "") {
$('#productSizes label.active input').val(sizesBySize[oldSize]);
$("#articleNumber").html(sizesBySize[oldSize]);
} else {
$('#productSizes label.active input').val(optionBuffer["size"]);
$("#articleNumber").html(optionBuffer["size"]);
}
if ($("#iptPlayer").val() != "") {
$("#iptNumber").val("").select2({
templateResult: formatState,
dropdownCssClass: "bigdrop"
});
} else {
$("#iptNumber").val(optionBuffer["number"]).select2();
}
reArrange(mData);
calcPrices();
if (setPriceBtnPreset != ""){
$(setPriceBtnPreset).addClass("active");
setPriceBtnPreset = "";
}
});
}
// CHECK PLAYER-STRING
function checkPlayerString(playerStr) {
var emsg = "";
var playerStrLen = playerStr.length;
// Convert Playername to uppercase
playerStr = playerStr.toUpperCase();
// Check Length
if (playerStrLen > maxLengthPlayer) {
playerStr = playerStr.substr(0,maxLengthPlayer);
$("#iptFreetext").val(playerStr);
showErrorMessage("Name zu lang! Es sind maximal " + maxLengthPlayer + " Zeichen möglich!");
return;
}
// Check single characters
for(i=0;i";
playerStr = playerStr.replace(thisChar,"");
$("#iptFreetext").val(playerStr);
showErrorMessage(emsg);
return;
}
}
// Check for denied words
$.each( deniedWords, function( key, word ) {
word = word.toUpperCase();
if(playerStr.indexOf(word) > -1) {
emsg += "Das Wort '" + word + "' ist nicht erlaubt! Diese Eingabe wird protokolliert.";
$("#iptFreetext").val("");
$("#tricotPlayer").html(" ");
logUserInputs("word",word);
showErrorMessage(emsg);
playerStr = "";
return playerStr;
}
});
return playerStr;
}
// Log dirty user-inputs
function logUserInputs(type,value) {
}
// CHANGE ALL ELEMENTS WHEN CHANGING TRICOT
function reArrange(modelData) {
var model = modelData[1];
var tricotImage = tricots[modelData[0]][4];
var thumbImgs = new Array();
var imgElement = "";
for(i=1;i<=5;i++) {
if (tricots[modelData[0]]["thumb_" + i]) {
thumbImgs[i] = tricots[modelData[0]]["thumb_" + i];
}
}
// Change tricot image
var bguri = basePath + "/flock/" + tricotImage;
$("#viewMainWrapper").css("background-image","url('" + bguri + "')");
// Different behaviour when is Short
if (modelData["5"] == "1") {
for(i=1;i<=5;i++) {
$("#thumbView" + i).html("");
$("#thumbView" + i).css("display","none");
}
} else {
// Switch color of players name & number
var freetextVal = $("#iptFreetext").val();
var playerVal = $("#iptPlayer").val();
var tp = $( "input[name='product']" ).val();
if (playerVal != "") {
imgPlayerName(playerVal,modelData[3],modelData[7],tp);
optionsLogic("players");
imgNumber(players[playerVal][1],modelData[3]);
} else {
imgPlayerNameFree(freetextVal,modelData[3],modelData[7],tp);
optionsLogic("free");
$("#iptPlayer").val("");
imgNumber(optionBuffer["number"],modelData[3]);
}
// Switch color of subline
if (optionBuffer["optionNbg"]) {
imgSubline("1fcn",modelData[3]);
}
}
// Change thumbnail images
/* var bguri = */
// Set Prices
calcPrices();
}
// CHANGE PLAYER NAME FROM DROPDOWN
function imgPlayerName(v,col,bgcol,tp) {
if (v != "") {
$("#tricotPlayer").html("
");
} else {
$("#tricotPlayer").html("");
}
}
// CHANGE PLAYER NAME FROM FREETEXT
function imgPlayerNameFree(v,col,bgcol,tp) {
$("#tricotPlayer").html("");
if (v) {
$("#tricotPlayer").html("
");
}
}
// CHANGE SUBLINE
function imgSubline(type,col) {
var psuffix = $( "input[name='psuffix']" ).val();
var sublineImg = "
";
$("#tricotSubline").html(sublineImg);
}
// CHANGE OPTION-IMAGES
function imgOptions(optionID,optionState) {
optionName = "#" + optionID;
if(optionState == true) {
$(optionName).css("visibility","visible");
} else {
$(optionName).css("visibility","hidden");
}
}
// CHANGE NUMBER
function imgNumber(nrval,col,isShort) {
var psuffix = $( "input[name='psuffix']" ).val();
if (isShort=="1") {
divID = "#shortNumber";
} else {
divID = "#tricotNumber";
}
if (nrval) {
var nrs = "";
for(i=0;i";
}
console.log(nrs);
$(divID).html(nrs);
} else {
$(divID).html("");
}
}
function previewImage() {
var t = $("#iptTricot").val();
var productId = sizes[optionBuffer["size"]][2];
var playerNameNum = $("#iptPlayer").val().replace("E","");
var playerNameFree = $("#iptFreetext").val();
var playerNumber = $("#iptNumber").val();
var optionNbg = $("#optionNbg").prop("checked");
var optionBuLi = $("#optionBuli").prop("checked");
var optionHermes = $("#optionHermes").prop("checked");
var optionGodel = $("#optionGodelmann").prop("checked");
var num = '';
var col = tricots[t][3];
var bgcol = tricots[t][7];
var imgUrl = "index.php?page=bb_tgdata&r=preview&tp=" + t + "&col=" + col + "&bgcol=" + bgcol;;
if (playerNameNum != '') {
imgUrl += "&str=" + players[playerNameNum][2];
var num = playerNameNum;
} else if (playerNameFree != "") {
imgUrl += "&str=" + playerNameFree;
var num = playerNumber;
}
if (playerNumber > 0) {
var num = playerNumber;
}
if (num != '') {
imgUrl += "&num=" + num;
}
if (optionNbg) {
imgUrl += "&fcn=1";
}
if (optionBuLi) {
imgUrl += "&buli=1";
}
// Change gallery preview image
$(".lSGallery li:last-child").find("a").find("img").prop("src",imgUrl + "&size=thumb");
pgalleryTG.goToSlide(pgalleryTG.getTotalSlideCount());
// Change image sources
$("#productGalleryTG li.active").attr("data-src",imgUrl + "&size=zoom");
$("#productGalleryTG li.active").attr("data-thumb",imgUrl + "&size=thumb");
$("#productGalleryTG li.active img").prop("src",imgUrl);
}
function toggleTricotView(v) {
if(v == 'tricot') {
if($('#viewMainWrapper').hasClass('display-none')) {
$('#mainImageWrapper').removeClass('display-block').addClass('display-none');
$('#viewMainWrapper').removeClass('display-none').addClass('display-block');
$('.zoomContainer').remove();
}
}
else if(v == 'image') {
if($('#mainImageWrapper').hasClass('display-none')) {
$('#viewMainWrapper').removeClass('display-block').addClass('display-none');
$('#mainImageWrapper').removeClass('display-none').addClass('display-block');
$('.zoomContainer').remove();
}
}
};
function toggleHermes(click) {
if(click == 'hermes') {
if($('#optionHermes').is(':checked') == true) {
$('#optionBuli').prop('checked', true);
$('#optionHermes').prop('checked', true);
imgOptions("optionBuliView",true);
imgOptions("optionHermesView",true);
$('#optionBuliButton').addClass('active');
$('#optionHermesButton').addClass('active');
calcPrices();
}
}
else if(click == 'buli') {
if($('#optionBulil').is(':checked') == false) {
$('#optionHermes').prop('checked', false);
imgOptions("optionHermesView",false);
$('#optionHermesButton').removeClass('active');
calcPrices();
}
}
};
// CHANGE OPTIONS
function optionsLogic(flockType) {
if (flockType == "players") {
$(".optionLblNbg").css("color",offColor);
imgSubline("1fcn",tricots[$("#iptTricot").val()][3]);
$("#optionBuli").prop("checked",true);
imgOptions("optionBuliView",true);
$("#optionHermes").prop("checked",true);
imgOptions("optionHermesView",true);
$("#optionBuliButton").addClass('active');
$("#optionHermesButton").addClass('active');
$("#optionNbgButton")
.addClass('active')
.addClass('btn-disabled')
.addClass('disabled')
.attr('disabled', true);
$("#optionNbg").prop("checked",true);
$("#optionNbg").attr('disabled', true);
$("#optionGodelmannButton")
.addClass('active')
.addClass('btn-disabled')
.addClass('disabled')
.attr('disabled', true);
$("#optionGodelmann").prop("checked",true);
$("#optionGodelmann").attr('disabled', true);
imgOptions("optionGodelmannView",true);
}
else if (flockType == "free") {
$("#optionNbg").removeAttr('disabled');
$("#optionNbg").removeAttr('readonly');
$(".optionLblNbg").css("color",onColor);
// Check Option-Checkboxes
$("#optionNbg").prop("checked",optionBuffer["optionNbg"]);
$("#optionBuli").prop("checked",optionBuffer["optionBuli"]);
$("#optionGodelmannButton")
.addClass('active')
.addClass('btn-disabled')
.addClass('disabled')
.attr('disabled', true);
$("#optionGodelmann").prop("checked",true);
$("#optionGodelmann").attr('disabled', true);
imgOptions("optionGodelmannView",true);
$("#optionBuliButton").removeClass('active');
$("#optionHermesButton").removeClass('active');
$("#optionNbgButton")
.removeClass('active')
.removeClass('btn-disabled')
.removeClass('disabled')
.attr('disabled', false);
// Option-Logos
imgOptions("optionBuliView",optionBuffer["optionBuli"]);
imgOptions("optionHermesView",optionBuffer["optionHermes"]);
if (optionBuffer["optionNbg"]) {
imgSubline("1fcn",tricots[$("#iptTricot").val()][3]);
//$("#optionNbg").prop("checked",true);
} else {
$("#tricotSubline").html("");
}
}
$("#optionGodelmannButton")
.addClass('active')
.addClass('btn-disabled')
.addClass('disabled')
.attr('disabled', true);
$("#optionGodelmann").prop("checked",true);
$("#optionGodelmann").attr('disabled', true);
imgOptions("optionGodelmannView",true);
var flockColor = tricots[$("#iptTricot").val()][3];
if(flockColor == 'black') {
$('#optionGodelmannView').html('
');
$('#trikotLogos').css('left', '350px');
}
}
// SEND ORDER TO CART
function sendToCart(flockType) {
//console.log("SEND TO CART");
if(flockType == "") {
flockType = "players";
}
var t = $("#iptTricot").val();
var s = sizes[optionBuffer["size"]][2];
var p = $("#iptPlayer").val();
var f = $("#iptFreetext").val();
var n = $("#iptNumber").val();
var a = $("#iptAmount").val();
var oN = $("#optionNbg").prop("checked");
var oB = $("#optionBuli").prop("checked");
var oH = $("#optionHermes").prop("checked");
var oG = $("#optionGodelmann").prop("checked");
var cartUri = "/index.php?page=product&action=add_product&info=" + s + "&product=" + s + "&qty=" + a;
if (p != "") {
//console.log("OPTION 1");
// Add Player-Name to Uri
cartUri += "&products_info[8_13]=" + players[p][2];
// Add Set-ID to Uri
playerNumber = players[p][1];
var setID = 5;
//console.log("SETNAME TO WK : " + setName);
if (setName == "set_0") {
setID = 3;
}
cartUri += "&products_info[2_SELECT]=" + setID;
// Option Bundesliga
if (oB == true) {
cartUri += "&products_info[6_34]=34";
}
} else {
if(f != "") {
//console.log("OPTION 2");
var setID = 4;
cartUri += "&products_info[2_SELECT]=" + setID;
// Freetext -> Add Player-Name to Uri
if (f != "") {
fCleared = f.replace(/ /g,"");
cartUri += "&products_info[8_13]=" + f;
}
if(n != "") {
cartUri += "&products_info[9_29]=" + n;
}
// Option Nürnberg
if (oN == true) {
cartUri += "&products_info[6_30]=30";
}
// Option Bundesliga
if (oB == true) {
cartUri += "&products_info[6_34]=34";
}
}
else
{
//console.log("OPTION 3");
// Freetext -> Add Player-Number to Uri
if (n != "") {
if (n.length < 2) {
numberSetName = "ziffern_1_9";
} else {
numberSetName = "ziffern_10_38";
}
optionID = optionPrices[numberSetName]["id"];
cartUri += "&products_info[9_29]=" + n;
cartUri += "&products_info[7_SELECT]=" + optionID;
}
// Option Nürnberg
if (oN == true) {
cartUri += "&products_info[6_9]=9";
}
// Option Bundesliga
if (oB == true) {
cartUri += "&products_info[6_10]=10";
}
}
}
// Option Hermes
if (oH == true) {
cartUri += "&products_info[6_36]=36";
}
// Option Godelmann
if (oG == true) {
cartUri += "&products_info[6_30]=30";
}
///index.php?page=product&action=add_product&info=8624&product=8624&qty=1&products_info[8_13]=tester&products_info[2_SELECT]=2&products_info[9_29]=24
///index.php?page=product&action=add_product&info=8624&product=8624&qty=1&products_info[8_13]=ALUSHI&products_info[2_SELECT]=5&products_info[6_34]=34
//console.log(cartUri);
var uri = encodeURI(cartUri);
window.location = uri;
}
// REDIRECT TO PAGE OF CHOSEN TRICOT
function backToTricot() {
var t = $("#iptTricot").val();
$("#actionToTricot").click(function() {
});
}
// CALCULATE + SHOW TRICOT PRICE
function calcPrices() {
$("#priceTricot").html("0,00");
$("#priceFlock").html("0,00");
$("#priceSum").html("0,00");
var priceTricot = parseInt(0);
var priceType = "default";
var priceFlock = parseInt(0);
var priceSum = parseInt(0);
//alert(optionPrices["buchstabe_1"]["preis"]);
var t = $("#iptTricot").val();
var s = optionBuffer["size"];
var p = $("#iptPlayer").val();
var f = $("#iptFreetext").val();
var n = $("#iptNumber").val();
var a = $("#iptAmount").val();
var oN = $("#optionNbg").prop("checked");
var oB = $("#optionBuli").prop("checked");
var oH = $("#optionHermes").prop("checked");
var oG = $("#optionGodelmann").prop("checked");
if (s) {
priceTricot = parseInt(sizes[s][1]);
priceType = sizes[s][4];
} else {
priceTricot = parseInt(sizes[$('input[name="size"]:checked').val()][1]);
priceType = sizes[$('input[name="size"]:checked').val()][4];
}
//console.log("OPTION PRICES");
//console.log(optionPrices[setName]);
// Calculate when Set is required
if (p != "" ) {
//var setName = "set_0";
if(optionPrices[setName]['status'] == 0) {
setName = "spielerset";
}
//console.log("PLAYER NUMBER " + p);
//console.log(freePlayers);
//console.log("SET NAME : " + setName);
if($.inArray(p,freePlayers) !== -1) {
setName = "set_0";
} else {
setName = "spielerset";
}
//console.log("SET NAME : " + setName);
priceFlock += parseInt(optionPrices[setName]["preis"]);
//console.log("PRICE FLOCK " + priceFlock);
} else {
if(f != "") {
// Add price for Freetext-Playername
setName = 'eigenname';
priceFlock = parseInt(optionPrices[setName]["preis"]);
// Add price for Nuremberg-Line
if (oN == true) {
priceFlock += parseInt(optionPrices["schriftzug_nuernberg_kostenlos"]["preis"]);
}
// Add price for Hermes-Logo
if (oH == true) {
priceFlock += parseInt(0);
}
// Add price for Godelmann Logo
if (oG == true) {
priceFlock += parseInt(0);
}
//if (oB == true) {
// priceFlock += parseInt(optionPrices["bundesliga_logo"]["preis"]);
// console.log("Z899" + optionPrices["bundesliga_logo"]["preis"]);
//}
}
else {
priceFlock = 0.00;
// Add price for Number
if (n != "") {
if (n.length < 2) {
numberSetName = "ziffern_1_9";
} else {
numberSetName = "ziffern_10_38";
}
priceFlock += parseInt(optionPrices[numberSetName]["preis"]);
}
// Add price for Nuremberg-Line
if (oN == true) {
priceFlock += parseInt(optionPrices["schriftzug_nuernberg"]["preis"]);
}
//if (oB == true) {
// priceFlock += parseInt(optionPrices["bundesliga_logo"]["preis"]);
// console.log("Z926" + optionPrices["bundesliga_logo"]["preis"]);
//}
}
}
// Add price for Bundesliga-Logo
if (oB == true) {
priceFlock += parseInt(optionPrices["bundesliga_logo"]["preis"]);
console.log("Z937" + optionPrices["bundesliga_logo"]["preis"]);
}
priceSum = (priceTricot + priceFlock) * a;
$("#priceTricot").html( (priceTricot/100).format(2,3,".",",") );
$("#priceFlock").html( (priceFlock/100).format(2,3,".",",") );
$("#priceSum").html( (priceSum/100).format(2,3,".",",") );
if (priceType == "special") {
$("#prices").addClass("priceViewDiscount");
$("#priceValueTricot").addClass("red bold");
$("#priceTricotLbl").html("Preis Trikot: Sonderpreis");
} else {
$("#prices").removeClass("priceViewDiscount");
$("#priceValueTricot").removeClass("red bold");
$("#priceTricotLbl").html("Preis Trikot:");
}
}
function getUriParams() {
var vars = [], hash;
var hashes = window.location.href.slice(
window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
function formatState (state) {
var imgID = state.id;
var txtLbl = state.text;
var imgExt = "";
var subPath = "p";
if (imgID == "8D" || imgID == "8M") {
imgID = state.text.replace("8M","").replace("8D","").replace(" ","_");
txtLbl = state.text;
}
if (currentTricot[6] == 1) {
subPath = "k";
}
if (currentTricot[9] == 1) {
subPath = "e";
}
if (currentTricot[10] == 1) {
subPath = "w";
}
if (!state.id) { return state.text; }
var $state = $('
' + txtLbl + '');
return $state;
};
// JQUERY SUPERVISION
$(document).ready(function() {
var preSelection;
var currSlide = 0;
var pgalleryDiv = $('#productGalleryTG');
pgalleryTG = pgalleryDiv.lightSlider({
gallery:true,
item:1,
loop:true,
thumbItem:9,
slideMargin:0,
enableDrag: 0,
height: '500px',
width: '500px',
currentPagerPosition:'center',
onSliderLoad: function(el) {
el.lightGallery({
selector: '#productGalleryTG .lslide',
download: false,
share: false,
rotate: false
});
$("ul.lSPager li").on("mouseover", function() {
if (currSlide != $(this).index()+1 ) {
el.goToSlide( $(this).index()+1 );
currSlide = $(this).index()+1;
}
});
}
});
$.getJSON( pageUri + "&r=getMaster&slaveId=" + 14813, function( data ) {
preSelection = data;
//console.log(preSelection);
});
// GET CONFIG & PRICES FOR FLOCK-OPTIONS
$.getJSON( pageUri + "&r=config", function( data ) {
//console.log(data);
optionPrices = data["OPTION_PRICES"];
freePlayers = (data['ZERO_FLOCK_PLAYERS'] !== null) ? data['ZERO_FLOCK_PLAYERS'].split(',') : null;
deniedWords = data["DENIED_WORDS"];
allowedChars = data["ALLOWED_CHARS"].toUpperCase() + " ";
mlp = parseInt(data["MAX_LENGTH_PLAYER_NAME"]);
mlpc = parseInt(data["MAX_LENGTH_PLAYER_NAME_CHILDREN"]);
maxLengthPlayer = mlp;
maxAmount = parseInt(data["MAX_ORDERABLE_TRICOTS"]);
defaultTricot = data["DEFAULT_TRICOT"];
// GET TRICOTS
$.getJSON( pageUri + "&r=masters", function( data ) {
$.each( data, function( key, val ) {
tricots[val[0]] = val;
$("").val(val[0]).text(val[2]).appendTo("#iptTricot");
});
// GET ALL PLAYERS IN GLOBAL VARIABLE
console.log("get players 2");
players = getPlayers("a");
// Preselect Master if requested
if (preSelection) {
$('#iptTricot option[value="' + preSelection+ '"]').prop('selected',true);
changedMaster(preSelection);
}
else {
//console.log("no preselection");
$('#iptTricot option[value="14813"]').prop('selected',true);
changedMaster('14813');
}
// GET NUMBERS
$.getJSON( pageUri + "&r=numbers", function( data ) {
$.each( data, function( key, val ) {
$("").val(val).text(val).appendTo("#iptNumber");
});
});
// CHANGE MASTER
$("#iptTricot").change(function(){
changedMaster($(this).val());
});
// RECEIVE & PROCESS FREETEXT-REQUESTS
var timeout = null;
$("#iptFreetext").keyup(function() {
var v = $(this).val();
var t = $("#iptTricot").val();
var tp = $( "input[name='product']" ).val();
clearTimeout(timeout);
timeout = setTimeout(function() {
v = checkPlayerString(v);
if (v != "" && t != "") {
$("#iptPlayer").val("").select2({
templateResult: formatState,
dropdownCssClass: "bigdrop"
});
$("#iptNumber").val(optionBuffer["number"]);
$("#optionBuli").prop("checked",false);
$("#optionHermes").prop("checked",true);
optionsLogic("free");
} else {
$("#tricotPlayer").html(" ");
}
optionBuffer["flockType"] = "free";
previewImage();
calcPrices();
}, 600);
});
// RECEIVE & PROCESS PLAYER-NAMES
$("#iptPlayer").change(function() {
var v = $(this).val();
var t = $("#iptTricot").val();
var tp = $( "input[name='product']" ).val();
if (v != "" && t != "") {
var col = tricots[t][3];
var bgcol = tricots[t][7];
$("#iptFreetext").val("");
$("#iptNumber").val("").select2();
optionsLogic("players");
optionBuffer["flockType"] = "players";
previewImage();
}
else {
$("#tricotPlayer").html("");
$("#iptFreetext").val("");
$("#tricotPlayer").html("");
$("#tricotNumber").html("");
$("#tricotSubline").html("");
$("#optionNbg").prop("checked",false);
$("#optionBuli").prop("checked",false);
$("#optionHermes").prop("checked",true);
$("#iptPlayer").val("").select2({
templateResult: formatState,
dropdownCssClass: "bigdrop"
});
optionsLogic("free");
optionBuffer["flockType"] = "free";
previewImage();
}
calcPrices();
});
// RECEIVE & PROCESS NUMBER-REQUESTS
$("#iptNumber").change(function() {
optionBuffer["number"] = $(this).val();
if ($("#iptPlayer").val() != "") {
$("#tricotPlayer").html("");
$("#iptPlayer").val("").select2({
templateResult: formatState,
dropdownCssClass: "bigdrop"
});
optionsLogic("free");
}
previewImage();
calcPrices();
});
// RECEIVE & PROCESS OPTION-REQUESTS
$("#optionGodelmannButton").click(function(e) {
e.stopPropagation();
e.preventDefault();
});
$("#optionNbgButton").click(function(e) {
if($(this).hasClass('disabled')) {
e.stopPropagation();
e.preventDefault();
}
else {
$("#optionNbg").change(function() {
previewImage();
optionBuffer["optionNbg"] = $("#optionNbg").prop("checked");
calcPrices();
});
}
});
// Option Bundesliga-Logo
$("#optionBuli").change(function() {
optionBuffer["optionBuli"] = $(this).prop("checked");
previewImage();
calcPrices();
});
// Option Hermes
$("#optionHermes").change(function() {
optionBuffer["optionHermes"] = $(this).prop("checked");
previewImage();
calcPrices();
});
// Count Amount Up
$("#amountUp").click(function(){
var currAmount = parseInt($("#iptAmount").val());
if(currAmount < maxAmount) {
$("#iptAmount").val((currAmount+1));
}
calcPrices();
});
// Count Amount Down
$("#amountDwn").click(function(){
var currAmount = parseInt($("#iptAmount").val());
if(currAmount > 1) {
$("#iptAmount").val((currAmount - 1));
}
calcPrices();
});
// SUBMIT ORDER TO CART
$("#actionToCart").click(function(e) {
e.preventDefault();
sendToCart(optionBuffer["flockType"]);
});
});
})
.fail(function(jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
});
});