﻿var _tv = window.a; var tv = window.tv = function(selector, context) { return new tv.fn.init(selector, context) }; tv.DestinationInfo = new Array(); tv.DFrom = new Array(); tv.DCountry = new Array(); tv.DCarierList = new Array(); tv.DMonths = new Array(); tv.WSURL = "/Service.svc/"; tv.RURL = "/okazje/przekierowanie.html"; tv.SortBy = "Price"; tv.SortTyp = "asc"; tv.sessionID = ""; tv.KT = ""; tv.status = 0; tv.transType = 0; tv.CUR = 0; tv.CUC = "PLN"; tv.EX = 1; tv.air = null; tv.printAir = null; tv.DataAct = false; tv.ContenerID = '#offerts'; tv.ProgresBar = '#searching-in-progress-box'; tv.ListHdr = '#list-hdr'; tv.listSort = '#list-sort-box'; tv.listFtr = '#list-ftr'; tv.Paging = '#Paging'; tv.HMax = "#HMax"; tv.HCount = "#HCount"; tv.size = 15; tv.paginOffsetDown = 2; tv.paginOffsetUp = 2; tv.paginStartP = 1; tv.paginEndP = 1; tv.TimeOut = 2500; tv.realTime = 0; tv.ATime = 50; tv.SP = true; tv.Template = "Progres"; tv.isHandler = false; tv.HandlerSearch = 0; tv.PBStart = false; tv.HProgress = 0; tv.PBIndex = 0; tv.fn = tv.prototype = { init: function() { }, Avilability: function(CUR, Orginal, Destination, Lang, TransType) { $("#UpDate").show(); var d = new Date(); $.getJSON(tv.WSURL + "GetPromotionAir?sessionId=" + tv.sessionID + "&Status=" + tv.status + "&CUR=" + CUR + "&Orginal=" + Orginal + "&Dest=" + Destination + "&Lang=" + Lang + "&TransType=" + TransType + "&d=" + d.toLocaleString(), function(data) { var tmp = eval("(" + data.d + ")"); tv.fn.AddDate(tmp); tv.fn.SetStatus(tmp); tv.fn.Sort(); tv.SortBy = 'Special'; tv.fn.Sort(); tv.SortBy = 'Price'; tv.fn.printData(); if (!tv.isHandler) Addhandler(); $("#UpDate").hide() }, "json") }, AddDate: function(data) { if (tv.status == 0) tv.air = data.Pr; tv.DestinationInfo = data.Ci; tv.DCarierList = data.CC; tv.DCountry = data.Co; jQuery.each(tv.air, function(i, h) { h.isD = true; h.isC = true; h.apf = true; h.isM = true; h.apfPattern = ''; h.apfPatternV = ''; h.AirLine = tv.fn.GetCarier(h.Cr).N; h.country = tv.fn.GetCountry(tv.fn.GetCity(h.DI).C).N; h.countryCode = tv.fn.GetCity(h.DI).C; h.city = tv.fn.GetCity(h.DI).N; h.monthPattern = ''; h.month = true; var sds = null; if (h.Ds != null) { sds = eval("new " + h.Ds.replace('/', '').replace('/', '')); sde = eval("new " + h.De.replace('/', '').replace('/', '')); if (sds.getYear() == sde.getYear()) { for (var i = sds.getMonth(); i <= sde.getMonth(); i++) { h.monthPattern += '#' + i + '#,'; AddDMonth(i, sds.getYear()) } } else if (sds.getYear() < sde.getYear()) { for (var i = sds.getMonth(); i <= 11; i++) { h.monthPattern += '#' + i + '#,'; AddDMonth(i, sds.getYear()) } for (var i = 0; i < sde.getMonth(); i++) { h.monthPattern += '#' + i + '#,'; AddDMonth(i, sde.getYear()) } } } jQuery.each(h.OLI, function(i, d) { h.apfPattern += d + '|'; h.apfPatternV += d; if (tv.DFrom.length == 0) tv.DFrom = clone(h.OLI); var isAdd = true; jQuery.each(tv.DFrom, function(i, fr) { if (d == fr) isAdd = false }); if (isAdd) tv.DFrom.push(d) }) }); CreateCarier(); CreateDepartureMonth() }, Bind: function() { tv.printAir = new Array(); if (tv.air != null) { jQuery.each(tv.air, function(i, h) { if (h.isD && h.isC && h.apf && h.month) { tv.printAir.push(clone(h)) } }) } }, ShowPaging: function() { var count = 0; var html = ""; if (tv.printAir.length > 0) { if (tv.printAir.length / tv.size == 0) count = tse.printAir.length / tv.size; else count = Math.floor(tv.printAir.length / tv.size) + (tv.printAir.length % tv.size == 0 ? 0 : 1); if (tv.index >= count) tv.index = count - 1; else if (tv.index < 0) tv.index = 0; if ((tv.index - 1) >= 0) html += "<a class=\"arr \" href='javascript:void(0)' onclick=\"tv.fn.ShowPage(" + (tv.index - 1) + ")\">&laquo;</a>"; else html += "<span class=\"arr inact\" >&laquo;</span>"; var isS = false; var isE = false; for (var i = 0; i < count; i++) { if ((count > tv.paginStartP + tv.paginOffsetDown + tv.paginOffsetUp) && i >= (tv.paginStartP) && !isS && (tv.index > (tv.paginStartP + tv.paginOffsetDown))) { html += "<span>...</span>"; isS = true } if ((i <= (tv.index + tv.paginOffsetUp) && i >= (tv.index - tv.paginOffsetDown)) || ((i < tv.paginStartP + tv.paginOffsetDown + tv.paginOffsetUp) && tv.index < (tv.paginStartP + tv.paginOffsetDown)) || (tv.index > (count - tv.paginOffsetDown - tv.paginEndP - tv.paginOffsetUp) && i > (count - tv.paginOffsetDown - tv.paginEndP - tv.paginOffsetUp)) || (i < tv.paginStartP) || ((i >= (count - tv.paginEndP)))) html += "<a href='javascript:void(0)' " + (i == tv.index ? " class=\"sel \" " : " onclick=\"tv.fn.ShowPage(" + (i) + ")\" ") + " >" + (i + 1) + "</a>"; if (!isE && (i >= (tv.index + tv.paginOffsetUp + tv.paginEndP + (!isS ? 1 : 0))) && (i < (count - tv.paginEndP))) { html += "<span>...</span>"; isE = true } } if (tv.index < (count - 1)) html += "<a class=\"arr\" href='javascript:void(0)' onclick=\"tv.fn.ShowPage(" + (tv.index + 1) + ")\">&raquo;</a>" } $(tv.Paging).html(html) }, ShowPage: function(index) { tv.index = index; tv.fn.printData(); Jump() }, printData: function() { tv.fn.Bind(); var html = ""; if (tv.air != null) { if (tv.SP) tv.fn.ShowPaging(); switch (tv.Template) { case 'List': html = tv.tem.TListe(tv.printAir); break; case 'Progres': html = tv.tem.TProgres(tv.printAir); break; default: html = ""; break }; $(tv.ContenerID).html(html); if (tv.printAir.length == 0) { $(tv.ContenerID).html('<div class="cnt-list-warn clearfix">                        <div class="list-warn-in">	                            <div class="list-warn-in2">	                                <div class="list-warn-bdy">' + trKomunikat_promocje_1 + '</div>	                            </div>	                            </div>		                    </div>') }; if (tv.air.length == tv.printAir.length) $("#reset").hide(); else $("#reset").show(); $(tv.HMax).html(tv.air.length); $(tv.HCount).html(tv.printAir.length) } }, SetStatus: function(data) { tv.sessionID = data.IdS; if (data.K != null) tv.KT = data.K; tv.status = data.S; tv.transType = data.Ty; if (tv.status == 0 || tv.status == 1) { $(tv.listSort + '-progres').remove(); tv.Template = "List"; $(tv.ContenerID + '-sep').remove(); $(tv.ProgresBar).hide(); $(tv.ListHdr).show(); $(tv.listSort).show(); $(tv.listFtr).show(); $('.filter-box').show(); $('.sites-searched-box').hide(); $(tv.ContenerID).removeClass('item-list-searching-v2'); if (airportFrom != '') { SetDIO(null, airportFrom) } if (countryTo != '') { SetDesynation(countryTo) } if (airLine != '') { SetCCO(null, airLine) } if (airportTo != '') { SetDesynationCity(airportTo) } } }, Sort: function() { if (tv.air != null) tv.air.sort(tv.fn.SortAir) }, SortAir: function(x, y) { switch (tv.SortBy) { case "Special": return (tv.SortTyp == "asc" ? y.S - x.S : y.S - x.S); case "Price": return (tv.SortTyp == "asc" ? x.P - y.P : y.P - x.P); case "AirLine": return (tv.SortTyp == "asc" ? sortByNameAsc(x.AirLine, y.AirLine) : sortByNameDsc(x.AirLine, y.AirLine)); case "City": return (tv.SortTyp == "asc" ? sortByNameAsc(x.city, y.city) : sortByNameDsc(x.city, y.city)); case "Country": return (tv.SortTyp == "asc" ? sortByNameDsc(x.country, y.country) : sortByNameAsc(x.country, y.country)); case "FlightDate": return (tv.SortTyp == "asc" ? sortByDateAsc(x.Ds, y.Ds) : sortByDateDsc(x.Ds, y.Ds)) } }, GetCity: function(c) { var q = { Co: "N/A", C: "N/A", N: "N/A", Ap: "N/A" }; jQuery.each(tv.DestinationInfo, function(i, sci) { if (sci.Co == c) q = sci }); return q }, GetCountry: function(c) { var q = { C: "N/A", N: "N/A" }; jQuery.each(tv.DCountry, function(i, co) { if (co.C == c) q = co }); return q }, GetCarier: function(c) { var q = { Co: "N/A", N: "N/A" }; jQuery.each(tv.DCarierList, function(i, aci) { if (aci.C == c) q = aci }); return q } }; function AddDMonth(month, year) { var isMon = false; jQuery.each(tv.DMonths, function(i, m) { if (m.m == month) isMon = true }); if (!isMon) { var p = { m: month, y: year + '' + (month < 10 ? '0' : '') + month, a: true }; tv.DMonths.push(p) } } function sortByDateAsc(a, b) { var x = null; var y = null; if (a != null) x = eval("new " + a.replace('/', '').replace('/', '')); if (b != null) y = eval("new " + b.replace('/', '').replace('/', '')); return ((x < y) ? -1 : ((x > y) ? 1 : 0)) } function sortByDateDsc(a, b) { var x = null; var y = null; if (a != null) x = eval("new " + a.replace('/', '').replace('/', '')); if (b != null) y = eval("new " + b.replace('/', '').replace('/', '')); return ((x > y) ? -1 : ((x < y) ? 1 : 0)) } function sortByNameAsc(a, b) { var x = a.toLowerCase().replace(' ', ''); var y = b.toLowerCase().replace(' ', ''); return ((x < y) ? -1 : ((x > y) ? 1 : 0)) } function sortByNameDsc(a, b) { var x = a.toLowerCase().replace(" ", ""); var y = b.toLowerCase().replace(" ", ""); return ((x > y) ? -1 : ((x < y) ? 1 : 0)) } function Addhandler() { tv.isHandler = true; $("#reset").bind("click", function(e) { Reset() }); $("#RCAll").bind("click", function(e) { ResetAC('checked'); tv.fn.printData() }); $("#RCNAll").bind("click", function(e) { ResetAC(''); tv.fn.printData() }); $("#CarierAll").bind("click", function(e) { ResetCC('checked'); tv.fn.printData() }); $("#CarierClear").bind("click", function(e) { ResetCC(''); tv.fn.printData() }); $("#inp_items_per_page").bind("change", function(e) { tv.size = $("#inp_items_per_page").val(); tv.fn.printData() }); $("#inp_currency").bind("change", function(e) { tv.CUR = $("#inp_currency").val(); tv.CUC = tv.ArrCUR[tv.CUR].c; tv.EX = tv.ArrCUR[tv.CUR].e; tv.fn.printData() }); $("#Destination").bind("change", function(e) { SetDesynation($("#Destination").val()) }); $("#SortAirLine").bind("click", function(e) { SortBox("AirLine") }); $("#SortCity").bind("click", function(e) { SortBox("City") }); $("#SortCountry").bind("click", function(e) { SortBox("Country") }); $("#SortFlightDate").bind("click", function(e) { SortBox("FlightDate") }); $("#SortPrice").bind("click", function(e) { SortBox("Price") }) }; function SortBox(SortBy) { if (SortBy != tv.SortBy) { $("#Sort" + tv.SortBy).removeClass("sel-desc"); $("#Sort" + tv.SortBy).removeClass("sel-asc") } tv.SortBy = SortBy; tv.SortTyp = (tv.SortTyp == "asc" ? "dsc" : "asc"); tv.fn.Sort(); tv.fn.printData(); if (tv.SortTyp == "dsc") { $("#Sort" + tv.SortBy).removeClass("sel-asc"); $("#Sort" + tv.SortBy).addClass("sel-desc") } else { $("#Sort" + tv.SortBy).removeClass("sel-desc"); $("#Sort" + tv.SortBy).addClass("sel-asc") } } function Reset() { ResetAC('checked'); ResetCC('checked'); ResetM('checked'); $("#Destination option[value='null']").attr('selected', 'selected'); jQuery.each(tv.air, function(i, h) { h.isD = true }); tv.fn.printData() } function ResetAC(val) { jQuery.each(tv.DFrom, function(id, f) { $('#f_2_' + f).attr('checked', val) }); jQuery.each(tv.air, function(i, h) { if (val == 'checked') { jQuery.each(h.OLI, function(i, d) { h.apfPatternV += d }); h.apf = true } else { h.apf = false; h.apfPatternV = "" } }) } function ResetM(val) { jQuery.each(tv.DMonths, function(id, f) { $('#fm_3_' + f.m).attr('checked', val); f.a = (val == 'checked') }); jQuery.each(tv.air, function(i, h) { h.month = (val == 'checked') }) } function ResetCC(val) { jQuery.each(tv.DCarierList, function(id, f) { $('#f_3_' + f.C).attr('checked', val) }); jQuery.each(tv.air, function(i, h) { h.isC = (val == 'checked') }) } function SortByC(x, y) { if (x.N > y.N) { return 1 } else if (x.N < y.N) { return -1 } return 0 } function CreateCarier() { var html = ''; tv.DCarierList.sort(SortByC); jQuery.each(tv.DCarierList, function(i, d) { html += '<div class="field-1col clearfix">             <input class="checkbox" ' + (tv.DCarierList.length == 1 ? 'disabled="disabled"' : '') + ' type="checkbox" id="f_3_' + d.C + '" name="f_3_' + d.C + '" value="5" onclick=\"SetCC(this, \'' + d.C + '\')\" checked="checked" /> <label><a onclick=\"SetCCO(this, \'' + d.C + '\')\" href="#link">' + d.N + '</a></label>             </div>' }); $('#Carier').html(html) }; function SortByM(x, y) { if (x.y > y.y) { return 1 } else if (x.y < y.y) { return -1 } return 0 } function CreateDepartureMonth() { var html = ''; tv.DMonths.sort(SortByM); jQuery.each(tv.DMonths, function(i, d) { html += '<div class="field-1col clearfix">             <input class="checkbox" type="checkbox" id="fm_3_' + d.m + '" name="fm_3_' + d.m + '" value="5" onclick=\"SetM(this, ' + d.m + ')\" checked="checked" /> <label><a onclick=\"SetMO(this, ' + d.m + ')\" href="#link">' + monthN[d.m] + '</a></label>             </div>' }); $('#DepartureMonth').html(html) }; function SetDesynationCity(code) { jQuery.each(tv.air, function(i, h) { if (code != "null") { if (code == h.DI) h.isD = true; else h.isD = false } else h.isD = true }); tv.fn.printData() } function SetDesynation(code) { jQuery.each(tv.air, function(i, h) { if (code != "null") { if (code == h.countryCode) h.isD = true; else h.isD = false } else h.isD = true }); tv.fn.printData() } function SetDI(obj, f) { jQuery.each(tv.air, function(i, h) { if (h.apfPattern.indexOf(f) != -1) { if (obj.checked) h.apfPatternV += f; else h.apfPatternV = h.apfPatternV.replace(f, ''); h.apf = h.apfPatternV.length > 0 } }); tv.fn.printData() }; function SetDIO(obj, f) { ResetAC(''); jQuery.each(tv.air, function(i, h) { h.apfPatternV = ""; if (h.apfPattern.indexOf(f) != -1) { $('#f_2_' + f).attr('checked', 'checked'); h.apfPatternV = f; h.apf = true } }); tv.fn.printData() }; function SetM(obj, f) { jQuery.each(tv.DMonths, function(i, h) { if (f == h.m) h.a = obj.checked }); jQuery.each(tv.air, function(i, h) { var is = false; jQuery.each(tv.DMonths, function(i, dm) { if (h.monthPattern.indexOf('#' + dm.m + '#') != -1 && dm.a) is = true }); h.month = is }); tv.fn.printData() }; function SetMO(obj, f) { ResetM(''); jQuery.each(tv.DMonths, function(id, h) { if (h.m == f) h.a = true }); jQuery.each(tv.air, function(i, h) { if (h.monthPattern.indexOf('#' + f + '#') != -1) { $('#fm_3_' + f).attr('checked', 'checked'); h.month = true } else { h.month = false } }); tv.fn.printData() }; function SetCC(obj, f) { jQuery.each(tv.air, function(i, h) { if (f == h.Cr) h.isC = obj.checked }); tv.fn.printData() }; function SetCCO(obj, f) { ResetCC(''); jQuery.each(tv.air, function(i, h) { if (f == h.Cr) { $('#f_3_' + f).attr('checked', 'checked'); h.isC = true } }); tv.fn.printData() }; tv.tem = new Object(); tv.tem = tv.prototype = { TListe: function(Data) { var html = ""; if (tv.air != null) { jQuery.each(Data, function(i, pro) { if (i >= (tv.size * tv.index) && i < (tv.size * (tv.index + 1))) { var sds = null; var sde = null; if (pro.Ds != null) sds = eval("new " + pro.Ds.replace('/', '').replace('/', '')); if (pro.De != null) sde = eval("new " + pro.De.replace('/', '').replace('/', '')); var Im = eval("new " + pro.Im.replace('/', '').replace('/', '')); var wylot = ''; jQuery.each(pro.OLI, function(i, ol) { wylot += ol; if (i < pro.OLI.length - 1) wylot += ', ' }); html += '<div class="item' + (pro.S == true ? ' item-special' : '') + '">                                <div class="overview-box">                                    <div class="clearfix">                                        <div class="col-data clearfix">                                            <div class="pic col-airline">                                               <div><span></span><img src="http://tm.turigo.pl/pt/pic/' + pro.Cr + '.gif" alt="' + pro.Cr + '" /></div>                                               <p>' + tv.fn.GetCarier(pro.Cr).N + '</p>                                            </div>                                           	<div class="col-place">                                           		<h3>' + tv.fn.GetCity(pro.DI).N + '</h3>                                           		<h4>' + tv.fn.GetCountry(tv.fn.GetCity(pro.DI).C).N + '</h4>                                           		' + (pro.S == true ? '<p>' + trOferta_specjalna + ': <a href="#link"  onclick=\"openNW(' + pro.PT + ',' + pro.OI + ',\'' + tv.fn.GetCity(pro.DI).N + '\',\'' + tv.fn.GetCountry(tv.fn.GetCity(pro.DI).C).N + '\')\">' + tv.Providers[pro.PT].p + '</a></p>' : '') + '                                           	</div>                                           	<div class="col-flight-date">                                           		<p>' + (sds == null ? "" : trod + ' ' + dateFormat(sds, "dd.mm.yyyy")) + '</p>                                           		<p>' + (sde == null ? "" : trdo + ' ' + dateFormat(sde, "dd.mm.yyyy")) + '</p>                                           	</div>                                        </div>                                        <div class="col-price">                                           <p class="clearfix">                                                ' + trod + ' <strong>' + Zaok(pro.P / tv.EX) + '</strong> <em>' + tv.CUC + '</em>                                                <a href="#link" class="select-btn" onclick=\"openNW(' + pro.PT + ',' + pro.OI + ',\'' + tv.fn.GetCity(pro.DI).N + '\',\'' + tv.fn.GetCountry(tv.fn.GetCity(pro.DI).C).N + '\')\"><span class="alt">' + trSprawdz + '</span></a>                                           </p>                                        </div>                                    </div>                                </div>                                <div class="last-box last-box-min clearfix">                                   <p class="clearfix">                                   		<span class="fl-fr">' + trWylot_z + ': <strong>' + wylot + '</strong></span> <span class="val-dt">' + trWazna_do + ': <em> ' + dateFormat(Im, "dd.mm.yyyy") + '</em></span>                                   </p>                                </div>                            </div>' } }) } return html }, TProgres: function(Hotels) { var html = ""; return html } }; function openNW(prv, id, city, country) { var urlRed = tv.RURL + "?prv=" + prv + "&ofid=" + id; var newWindow = window.open(urlRed, '_blank'); newWindow.focus(); return false }; function clone(obj) { if (obj == null || typeof (obj) != 'object') return obj; var temp = new obj.constructor(); for (var key in obj) temp[key] = clone(obj[key]); return temp } function Zaok(liczba) { var pp = 1; liczba = liczba * pp; var wynik = Math.round(liczba) / pp; return wynik } function Jump() { $('html,body').animate({ scrollTop: 0 }, 1000) } $(document).ready(function() { $.facebox.settings.closeImage = 'http://www.tm.turigo.pl/pt/' + trCodeLang + '/img/facebox/closelabel.gif'; $('a[rel*=facebox]').facebox(); jQuery('#UpDate').center() }); $(document).bind('reveal.facebox', function() { init_facebox() }); function init_facebox() { $("#facebox .inp_airport_from").bind("change", function(e) { var Departure = $("#facebox .inp_airport_from").val(); $.get("ServiceCodeOkazje.aspx?Departure=" + Departure, function(data) { $("#facebox .inp_country_to").html(data) }) }); $("#facebox .inp_airport_from_lm").bind("click", function(e) { var Departure = $("#facebox .inp_airport_from_lm").val(); $.get("ServiceCodeOkazjeLm.aspx?Departure=" + Departure, function(data) { $("#facebox .inp_country_to_lm").html(data) }) }); $("#facebox .btn-promos").bind("click", function(e) { var from = $("#facebox .inp_airport_from").val(); var to = $("#facebox .inp_country_to").val(); var url = "promocje-linii.html"; if (from != 'null') url += "?airportFrom=" + from; if (to != 'null') { if (from == 'null') url += "?countryTo=" + to; else url += "&countryTo=" + to } window.location.replace(url); return false }); $("#facebox .btn-lm").bind("click", function(e) { var from = $("#facebox .inp_airport_from_lm").val(); var to = $("#facebox .inp_country_to_lm").val(); var url = "/okazje/last-minute/"; if (from != '0') url += "?airportFrom=" + from; if (to != '0') { if (from == '0') url += "?countryTo=" + to; else url += "&countryTo=" + to } window.location.replace(url); return false }) }
