/** * Offering Javascript functions * @author Mart Mangus * @copyright Pant24 OÜ */ var userKey = ''; var req; // The request Object var postId; //////////// // TIMERS // //////////// /** Offer timer counts from 60 to 0 */ var clientTimerOn = false; function clientTimer(start, noNewsChecking) { if (start != null) { clientTimerOn = true; if (noNewsChecking == null) checkNews(true); } if (!clientTimerOn) return; // Timer not working if (null === $('offeringSeconds')) { // See element ei ole veel laetud... window.setTimeout('clientTimer()', 1000); return; } var secondsLeft = $('offeringSeconds').get('html'); secondsLeft--; $('offeringSeconds').set('html', secondsLeft) if (secondsLeft <= 0) // Time over { if ($('bestOfferer') != null) { // This client is best offerer checkNewsTimerOn = false; getBuyNowButton(); } else { // Someone else made better offer showProgress(); payingTimerOthers(true); } return; } window.setTimeout('clientTimer()', 1000); } /** * Check offering news from AJAX-Gateway * Adopts new recived HTML */ var checkNewsTimerOn = false; function checkNews(start) { if (start != null) checkNewsTimerOn = true; if (!checkNewsTimerOn) return; // No need for check at the moment... req = new Request.HTML({url:'http://pant24.ee/ajax-gateway/?action=checkNews&postId=' + postId + '&key=' + userKey, onSuccess: function(html) { if (html.length != 0) { $('ajaxResult').set('text', ''); $('ajaxResult').adopt(html); if (Browser.Engine.trident) { // IE doesn't accept Javascript from AJAX response! if ($('offerProgress25')) { $('offer25').onclick = function () { offerMore(25); }; $('offer50').onclick = function () { offerMore(50); }; $('offer100').onclick = function () { offerMore(100); }; } else if ($('buyAjaxButton')) { $('buyAjaxButton').onclick = function () { goBuy();return false; }; } } if (clientTimerOn == false && $('offerProgress25')) { // Start ticking from 60... clientTimer(true, true); } } }, onFailure: function() { $('ajaxResult').set('text', 'Süsteemi viga! (AJAX request failed (4))'); } }); req.send(); window.setTimeout('checkNews()', 5555); } /** * Paying timer * Uses PopUp window! */ var payingTimerOn = false; var closeForIe = false; function payingTimer(start) { if (start != null) payingTimerOn = true; if (!payingTimerOn) return; // Timer not working if (closeForIe || !payingWindow.contentWindow) { paymentFailure(); syncronizePaymentTimeOn = false; return; } if (payingWindow.contentWindow.frames["header"] == null || null == payingWindow.contentWindow.frames["header"].document.getElementById('headerText')) { window.setTimeout('payingTimer()', 1000); return; } var seconds = payingWindow.contentWindow.frames["header"].document.getElementById('payingSeconds'); var minutes = payingWindow.contentWindow.frames["header"].document.getElementById('payingMinutes'); secondsCount = $(seconds).get('html'); minutesCount = $(minutes).get('html'); var timeOver = false if (secondsCount <= 0) { if (minutesCount > 0) { minutesCount--; secondsCount = 59; } else // timeOver timeOver = true; } else secondsCount--; $(seconds).set('html', secondsCount); $(minutes).set('html', minutesCount); if (timeOver) { $('lbClose').onclick(); paymentFailure(); return; } window.setTimeout('payingTimer()', 1000); } /** * Timer for others then best offerer */ var payingTimerOthersOn = false; function payingTimerOthers(start) { if (start == true) payingTimerOthersOn = true; if (!payingTimerOthersOn) return; // Timer not working if (null === $('payingSeconds')) { window.setTimeout('payingTimerOthers()', 1000); return; } secondsCount = $('payingSeconds').get('html'); minutesCount = $('payingMinutes').get('html'); var timeOver = false if (secondsCount <= 0) { if (minutesCount > 0) { minutesCount--; secondsCount = 59; } else // timeOver timeOver = true; } else secondsCount--; $('payingSeconds').set('html', secondsCount); $('payingMinutes').set('html', minutesCount); if (timeOver) { showProgress(); clientTimer(true, true); return; } window.setTimeout('payingTimerOthers()', 1000); } /** * Because Javascript timer is not exact at all * Uses PopUp window! */ var syncronizePaymentTimeOn = false; function syncronizePaymentTime(start) { if (start != null) syncronizePaymentTimeOn = true; if (!syncronizePaymentTimeOn) return; if (null == payingWindow.contentWindow || null == payingWindow.contentWindow.frames["header"] || null == payingWindow.contentWindow.frames["header"].document.getElementById('headerText')) { window.setTimeout('syncronizePaymentTime()', 1000); return; } req = new Request.HTML({url:'http://pant24.ee/ajax-gateway/?action=syncronizePaymentTime&postId=' + postId, onSuccess: function(html) { if (payingWindow.contentWindow) { var headerText = payingWindow.contentWindow.frames["header"].document.getElementById('headerText'); headerText = $(headerText); headerText.set('text', ''); headerText.adopt(html); } }, onFailure: function() { $('ajaxResult').set('text', 'Süsteemi viga! (AJAX request failed (5))'); } }); req.send(); window.setTimeout('syncronizePaymentTime()', 9999); } /////////////////////// // ACTIONS ON TIMERS // /////////////////////// /** When WP timer ticks to zero */ function timeOver() { if (!$('ajaxResult')) { window.location.reload(); // Kui ei ole toote lehel return; } if ($('normalTimer')) $('normalTimer').setStyle('display', 'none'); $('ajaxResult').setStyle('display', ''); req = new Request.HTML({url:'http://pant24.ee/ajax-gateway/?action=timeOver&postId=' + postId, onSuccess: function(html) { $('ajaxResult').set('text', ''); $('ajaxResult').adopt(html); userKey = $('userKey').get('html'); clientTimer(true); // Start offering timer }, onFailure: function() { $('ajaxResult').set('text', 'Süsteemi viga! (AJAX request failed (1))'); } }); req.send(); } /** Tries to go to product payment */ function getBuyNowButton() { $('timerText').setStyle('display', 'none'); $('getBuyButton').setStyle('display', ''); clientTimerOn = false; req = new Request.HTML({url:'http://pant24.ee/ajax-gateway/?action=getBuyNowButton&postId=' + postId + '&key=' + userKey, onSuccess: function(html) { if (html.length != 0) { // Everythin okey $('ajaxResult').set('text', ''); $('ajaxResult').adopt(html); goBuy(); } else { // A new offer in last second... checkNews(true); clientTimerOn = true; clientTimer(); // Timer starts clicking again... } }, onFailure: function() { $('ajaxResult').set('text', 'Süsteemi viga! (AJAX request failed (3))'); } }); req.send(); } ////////////////////////////// // ACTIONS ON USER ACTIVITY // ////////////////////////////// /** Makes new offer trough AJAX-gateway */ function offerMore(sum) { $('offerProgress' + sum).setStyle('display', ''); req = new Request.HTML({url:'http://pant24.ee/ajax-gateway/?action=makeOffer&postId=' + postId + '&key=' + userKey + '&offer=' + sum, onSuccess: function(html) { $('ajaxResult').set('text', ''); $('ajaxResult').adopt(html); }, onFailure: function() { $('ajaxResult').set('text', 'Süsteemi viga! (AJAX request failed (2))'); } }); req.send(); } //////////////////////////////////// // FUNCTIONS CONNECTED TO PAYMENT // //////////////////////////////////// function goBuy() { if (Browser.Engine.presto && !Browser.Engine.trident) { // Opera doesn't go so good... alert("Makse sooritamiseks on aega 3 minutit!") $('buyButton').submit(); return true; } $('buyButton').set('html', ''); if (payingWindow != null) { alert('Makse aken on juba avatud!'); return; } checkNewsTimerOn = false; openPayingPopup('/home/v3758/payment_popup/?postId=' + postId + '&key=' + userKey); payingTimer(true); syncronizePaymentTime(true); } function paymentFailure() { payingTimerOn = false; syncronizePaymentTimeOn = false; $('ajaxResult').set('html', '
Makse ebaõnnestus!

Probleemide korral võtke ühenust klienditeenindusega.
'); req = new Request.HTML({url:'http://pant24.ee/ajax-gateway/?action=paymentFailure&postId=' + postId + '&key=' + userKey, onFailure: function() { $('ajaxResult').set('text', 'Süsteemi viga! (AJAX request failed (7))'); } }); req.send(); } function paymentSuccess() { payingTimerOn = false; syncronizePaymentTimeOn = false; var headerText = payingWindow.contentWindow.frames["header"].document.getElementById('headerText'); headerText = $(headerText); headerText.setStyle('background-color', 'green'); headerText.set('html', 'Makse on sooritatud! Palun sisestage nüüd kontaktandmed!'); $('ajaxResult').set('html', 'See toode on nüüd müüdud!'); } ///////////////////// // OTHER FUNCTIONS // ///////////////////// var payingWindow = null; function openPayingPopup(link) { $('buyingLink').href = link; //myLytebox.start(document.getElementById('buyingLink'), false, true); return false; $('buyingLink').onclick(); //$('buyingLink').handleEvent(Event.click); //myLytebox.start($('buyingLink'), false, true); payingWindow = $('lbIframe'); payingWindow.setStyle('border', 'none'); return true; } function showProgress() { $('ajaxResult').set('html', ''); $('ajaxResult').setStyle('display', ''); }