PageSourceSearch

https://mediaupdate.co.za/js/page/master.js?v=639258777416623924

js mediaupdate.co.za collected 2026-09-24 18:16:08 UTC 72,349 bytes, 1,862 lines download raw bytes

1$(document).ready(function () {
2    setTimeout(function () {
3        $('#MasterSearchKey').val('');
4    }, 1000);
5    
6    if (QS('q') != "") {
7        $('#SearchedItems').html('<a style="height: 20px; background-color: #b6b6b6; color: #fff; padding: 2px 5px; border-radius: 2px; margin-left: 10px; cursor: default" href="/default.aspx">' + QS("q") + '&nbsp;&nbsp;<i id="SearchedItemRemove" class="fa fa-close" style="cursor: pointer"></i></a>');
8    }
9    else {
10        $('#SearchedItems').html("");
11    }
12});
13
14///////////////////////////
15// VALIDATE TOKEN
16///////////////////////////
17if (localStorage.Token == '' || localStorage.Token == null || localStorage.Token == 'undefined') {
18    $('#PPLinkOut').show();
19    $('#PPLinkIn').hide();
20
21    $.removeCookie('TokenCookie', { path: '/' })
22
23
24} else {
25    $('#PPLinkOut').hide();
26    $('#PPLinkIn').show();
27
28    NotificationsUnseenCount();
29    window.setInterval(function () {
30        NotificationsUnseenCount();
31    }, 60000);
32
33
34    //SET TOKEN COOKIE
35    setCookie('TokenCookie', localStorage.Token, 1);
36
37}
38
39
40
41//A D D  G U E S T  U S E R
42
43//function AddGuestUser() {
44//    InputData = {
45//        Device: platform.description,
46//        IsApp: false,
47//        DeviceKey: '',
48//        Platform: '',
49//        Model: '',
50//        Cordova: '',
51//        Version: '',
52//        OneSignalUserID: '',
53//        OneSignalPushToken: ''
54//    };
55//    $.ajax({
56//        type: "POST",
57//        url: APIURI + 'user/guestuseradd',
58//        data: JSON.stringify(InputData),
59//        success: function (data) {
60//            console.log(data);
61//            if (data.Success != false) {
62//                localStorage.GuestToken = data.ReferenceCode;
63//                setCookie('TokenGuestCookie', localStorage.GuestToken, 1);
64//            }
65//        },
66//        error: function (XMLHttpRequest, textStatus, errorThrown) {
67//            //$.smkAlert({ text: 'Unable to connect to service', type: 'danger', });
68//            console.log("Something went wrong");
69//        }
70//    });
71//}
72
73function ReturnOrCreateToken() {
74
75    if (localStorage.Token == '' || localStorage.Token == 'undefined' || localStorage.Token == null) {
76        if (localStorage.GuestToken == '' || localStorage.GuestToken == null || localStorage.GuestToken == 'undefined') {
77            InputData = {
78                Device: platform.description,
79                IsApp: false,
80                DeviceKey: '',
81                Platform: '',
82                Model: '',
83                Cordova: '',
84                Version: '',
85                OneSignalUserID: '',
86                OneSignalPushToken: ''
87            };
88
89            return $.ajax({
90                type: "POST",
91                url: APIURI + 'user/guestuseradd',
92                data: JSON.stringify(InputData),
93                success: function (data) {
94
95                    if (data.Success != false) {
96                        localStorage.GuestToken = data.ReferenceCode;
97                        setCookie('TokenGuestCookie', localStorage.GuestToken, 1);
98
99                        return localStorage.GuestToken
100                    }
101                },
102                error: function (XMLHttpRequest, textStatus, errorThrown) {
103                    //$.smkAlert({ text: 'Unable to connect to service', type: 'danger', });
104                    console.log("Something went wrong");
105                    return "";
106                }
107            });
108        } else {
109            return localStorage.GuestToken;
110        }
111    } else {
112        return localStorage.Token;
113    }
114
115}
116function ReturnLocalToken() {
117
118    var Token = "";
119    if (localStorage.Token == '' || localStorage.Token == 'undefined' || localStorage.Token == null) {
120        Token = localStorage.GuestToken;
121    }
122    else {
123        Token = localStorage.Token;
124    }
125    return Token;
126}
127
128ValidateGuestToken();
129function ValidateGuestToken() {
130    if (localStorage.GuestToken == '' || localStorage.GuestToken == null || localStorage.GuestToken == 'undefined') {
131        // do nothing
132    } else {
133        InputData = {
134            GuestToken: localStorage.GuestToken
135        };
136
137        return $.ajax({
138            type: "POST",
139            url: APIURI + 'user/guestuservalidate',
140            data: JSON.stringify(InputData),
141            contentType: "application/json",
142            success: function (data) {
143                console.log(data);
144                if (data == false) {
145                    localStorage.GuestToken = '';
146                }
147            },
148            error: function (XMLHttpRequest, textStatus, errorThrown) {
149
150            }
151        });
152    }
153}
154
155///////////////////////////
156// SET PROFILE PICTURE
157///////////////////////////
158if (localStorage.PP == '' || localStorage.PP == null || localStorage.PP == 'undefined') {
159    localStorage.PP = '';
160} else {
161    $('#MyMainPP').attr('src', DashURI + localStorage.PP);
162
163}
164
165///////////////////////////
166// MOBILE VISITOR ???
167///////////////////////////
168//DownloadAppNotification();
169//function DownloadAppNotification() {
170//    // if (localStorage.DownloadApp == '' || localStorage.DownloadApp == null || localStorage.DownloadApp == 'undefined') {
171//    setTimeout(
172//        function () {
173//            getMobileOperatingSystem()
174//        }, 5000);
175//    //}
176//}
177function getMobileOperatingSystem() {
178    var userAgent = navigator.userAgent || navigator.vendor || window.opera;
179
180    if (/android/i.test(userAgent)) {
181        $('#btnDownloadApp').attr('href', 'https://play.google.com/store/apps/details?id=com.newsclip.mediaupdate');
182        $('#modMobile').modal('show');
183        localStorage.DownloadApp = 'Done';
184    }
185
186    if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
187        $('#btnDownloadApp').attr('href', 'https://itunes.apple.com/us/app/media-update/id1047172718?ls=1&mt=8');
188        $('#modMobile').modal('show');
189        localStorage.DownloadApp = 'Done';
190    }
191}
192
193///////////////////////////
194// POPULATE GLOBAL TOKEN BOX
195///////////////////////////
196if (localStorage.TokenBox == null) {
197    //localStorage.TokenBox = '';
198
199} else {
200
201    // SET CURRENT TOKENS
202    //var Tokens = '';
203    //var CurrentIndex = 0;
204    //var array = localStorage.TokenBox.split(',');
205
206    //for (a in array) {
207    //    if (array[a] != '') {
208    //        CurrentIndex += 1;
209    //        var element = array[a];
210
211    //        if (element == '≡media') {
212    //            Tokens += '<span id="MainTokenEntry' + CurrentIndex + '" style="background-color: #DC4444;">' + array[a].replace('≡', '') + '&nbsp;<i class="fa fa-close" onclick="RemoveToken(' + CurrentIndex + ')"></i></span>';
213    //        } else if (element == '≡publicity') {
214    //            Tokens += '<span id="MainTokenEntry' + CurrentIndex + '" style="background-color: #A2B73A;">' + array[a].replace('≡', '') + '&nbsp;<i class="fa fa-close" onclick="RemoveToken(' + CurrentIndex + ')"></i></span>';
215    //        } else if (element == '≡marketing') {
216    //            Tokens += '<span id="MainTokenEntry' + CurrentIndex + '" style="background-color: #458CCC;">' + array[a].replace('≡', '') + '&nbsp;<i class="fa fa-close" onclick="RemoveToken(' + CurrentIndex + ')"></i></span>';
217    //        } else if (element == '≡social') {
218    //            Tokens += '<span id="MainTokenEntry' + CurrentIndex + '" style="background-color: #f39c12;">' + array[a].replace('≡', '') + '&nbsp;<i class="fa fa-close" onclick="RemoveToken(' + CurrentIndex + ')"></i></span>';
219    //        } else {
220    //            Tokens += '<span id="MainTokenEntry' + CurrentIndex + '">' + array[a] + '&nbsp;<i class="fa fa-close" onclick="RemoveToken(' + CurrentIndex + ')"></i></span>';
221    //        }
222
223    //    } else {
224    //        Tokens += "<i class='fa fa-search' style='float: left; margin-right: 3px; padding: 7px 0 7px 7px;'></i>";
225    //    }
226    //}
227
228    //Tokens += '<input id="MainTokenEntryInput" autocomplete="off" onfocus="ShowTokenSuggestions()" type="text" class="TokenBoxInput" placeholder="Search" onBlur="HideTokenSuggestions()" />';
229    //$('#TokenBox').html('');
230    //$('#TokenBox').html(Tokens);
231
232    //LOCALSTORAGE VALUE
233    //$("#ctl00_ContentPlaceHolder1_TokenBox").html(localStorage.TokenBox);
234}
235
236$(document).ready(function () {
237
238    LoadKeywordSuggestions();
239
240
241    ///////////////////////////
242    // USER INFORMARION MODALS
243    ///////////////////////////
244
245    setTimeout(function () {
246
247        if (localStorage.PageVisits == null || localStorage.PageVisits == '') {
248            localStorage.PageVisits = 1;
249        } else {
250            localStorage.PageVisits = parseInt(localStorage.PageVisits) + 1;
251        }
252        if (localStorage.PageVisits < 3) {
253            return;
254        }
255
256        if (localStorage.Token == '' || localStorage.Token == null || localStorage.Token == 'undefined') {
257            if ((localStorage.DownloadApp == '' || localStorage.DownloadApp == null || localStorage.DownloadApp == 'undefined') && (localStorage.RunRegisterOnce == null || localStorage.RunRegisterOnce == '' || localStorage.RunRegisterOnce == 'undefined')) {
258
259
260                $("#modAskRegister").modal('show');
261
262                $("#btnRegisterLater").on('click', function () {
263                    $("#modAskRegister").modal('hide');
264                });
265                $("#btnRegisterNow").on('click', function () {
266                    $("#modAskRegister").modal('hide');
267                    $('#modLogin').modal("show");
268                    $('#modLogin').on('shown.bs.modal', function (e) {
269                        $('.nav-tabs a[href="#ShowRegister"]').tab('show');
270                    });
271                });
272                localStorage.RunRegisterOnce = "Done";
273
274                return;
275            }
276        }
277        else {
278            UserInfoCheck();
279        }
280        if (localStorage.DownloadApp == '' || localStorage.DownloadApp == null || localStorage.DownloadApp == 'undefined') {
281            getMobileOperatingSystem();
282        }
283
284    }, 5000);
285
286    $('#payfast-return-url').val(window.location.href);
287    $('#payfast-cancel-return-url').val(window.location.href);
288
289});
290
291///////////////////////////
292// USER INFORMATION MODALS
293///////////////////////////
294function UserInfoCheck() {
295
296    var InputData = {
297        Token: localStorage.Token
298    };
299
300    $.ajax({
301        type: "POST",
302        url: APIURI + 'user/get',
303        data: JSON.stringify(InputData),
304        success: function (data) {
305
306            if (data == null) {
307                //alert('User not found');
308                //window.location = '/';
309            } else {
310                $('#dtModUserBirthday').datetimepicker({
311                    format: 'D MMM YYYY'
312                });
313                //CREATE LOCALSTORAGE VARIABLES
314
315
316                if (localStorage.LastCheck == null || localStorage.LastCheck == '') {
317                    localStorage.LastCheck = "";
318                    if (localStorage.CompanyAnswer == null || localStorage.CompanyAnswer == '') {
319                        localStorage.CompanyAnswer = "true";
320                        if (localStorage.NumberAnswer == null || localStorage.NumberAnswer == '') {
321                            localStorage.NumberAnswer = "true";
322                            if (localStorage.GenderAnswer == null || localStorage.GenderAnswer == '') {
323                                localStorage.GenderAnswer = "true";
324                                if (localStorage.BirthdayAnswer == null || localStorage.BirthdayAnswer == '') {
325                                    localStorage.BirthdayAnswer = "true";
326                                }
327                            }
328                        }
329                    }
330                }
331
332                //CHECK DATABASE FOR USER INFORMATION
333                var d = new Date();
334                var twodays = d.setDate(d.getDate() - 2);
335                twodays = new Date(twodays);
336
337                if ((Date.parse(localStorage.LastCheck) <= twodays) || (localStorage.LastCheck == "")) {
338
339                    if (localStorage.BirthdayAnswer == "true") {
340                        if (data.Birthday == null || data.Birthday == '') {
341                            localStorage.LastCheck = new Date();
342                            $("#modBirthday").modal('show');
343                            return;
344                        }
345                    }
346                    if (localStorage.CompanyAnswer == "true") {
347                        if (data.Company == null || data.Company == '' || data.JobTitle == null || data.JobTitle == '') {
348                            localStorage.LastCheck = new Date();
349                            $('#txtModCompany').val(data.Company);
350                            $('#txtModJobTitle').val(data.JobTitle);
351                            $("#modCompany").modal('show');
352
353                            return;
354                        }
355                    }
356                    if (localStorage.GenderAnswer == "true") {
357                        if (data.Gender == null || data.Gender == '' || data.Gender == 0) {
358                            $("#modGender").modal('show');
359                            localStorage.LastCheck = new Date();
360                            return;
361                        }
362                    }
363                    if (localStorage.NumberAnswer == "true") {
364
365                        if (data.ContactNumber == null || data.ContactNumber == '') {
366                            $("#modNumber").modal('show');
367                            localStorage.LastCheck = new Date();
368                            return;
369                        }
370                    }
371                }
372                //debugger;
373            }
374
375        },
376        error: function (XMLHttpRequest, textStatus, errorThrown) {
377            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
378        }
379    });
380}
381function SaveBirthday() {
382    InputData = {
383        Token: localStorage.Token,
384        Birthday: $('#txtModBirthday').val()
385    };
386
387    $.ajax({
388        type: "POST",
389        url: APIURI + 'user/birthday/update',
390        data: JSON.stringify(InputData),
391        success: function (data) {
392
393
394            if (data.Success == false) {
395                $.smkAlert({ text: data.Message, type: 'warning', });
396
397            } else {
398                $("#modBirthday").modal('hide');
399                $.smkAlert({ text: data.Message, type: 'success', });
400            }
401        },
402        error: function (XMLHttpRequest, textStatus, errorThrown) {
403            $.smkAlert({ text: 'Unable to connect to service', type: 'danger', });
404        }
405    });
406}
407function SaveGender() {
408    InputData = {
409        Token: localStorage.Token,
410        Gender: $('#txtModGender').val()
411    };
412
413    $.ajax({
414        type: "POST",
415        url: APIURI + 'user/gender/update',
416        data: JSON.stringify(InputData),
417        success: function (data) {
418
419
420            if (data.Success == false) {
421                $.smkAlert({ text: data.Message, type: 'warning', });
422
423            } else {
424                $("#modGender").modal('hide');
425                $.smkAlert({ text: data.Message, type: 'success', });
426            }
427        },
428        error: function (XMLHttpRequest, textStatus, errorThrown) {
429            $.smkAlert({ text: 'Unable to connect to service', type: 'danger', });
430        }
431    });
432}
433function SaveCompany() {
434
435    InputData = {
436        Token: localStorage.Token,
437        Company: $('#txtModCompany').val(),
438        JobTitle: $('#txtModJobTitle').val()
439    };
440
441    $.ajax({
442        type: "POST",
443        url: APIURI + 'user/company/update',
444        data: JSON.stringify(InputData),
445        success: function (data) {
446
447            if (data.Success == false) {
448                $.smkAlert({ text: data.Message, type: 'warning', });
449
450            } else {
451                $("#modCompany").modal('hide');
452                $.smkAlert({ text: data.Message, type: 'success', });
453            }
454        },
455        error: function (XMLHttpRequest, textStatus, errorThrown) {
456            $.smkAlert({ text: 'Unable to connect to service', type: 'danger', });
457        }
458    });
459}
460function SaveNumber() {
461
462    var Number = $("#txtModContactNumber").intlTelInput("getNumber");
463
464    InputData = {
465        Token: localStorage.Token,
466        ContactNumber: Number
467    };
468
469    $.ajax({
470        type: "POST",
471        url: APIURI + 'user/number/update',
472        data: JSON.stringify(InputData),
473        success: function (data) {
474
475
476            if (data.Success == false) {
477                $.smkAlert({ text: data.Message, type: 'warning', });
478
479            } else {
480                $("#modNumber").modal('hide');
481                $.smkAlert({ text: data.Message, type: 'success', });
482            }
483        },
484        error: function (XMLHttpRequest, textStatus, errorThrown) {
485            $.smkAlert({ text: 'Unable to connect to service', type: 'danger', });
486        }
487    });
488}
489function CountInfoLater(Answer) {
490
491    InputData = {
492        Token: localStorage.Token
493    };
494
495    $.ajax({
496        type: "POST",
497        url: APIURI + 'user/infolater/update',
498        data: JSON.stringify(InputData),
499        success: function (data) {
500
501            if (data.Success == false) {
502                $.smkAlert({ text: data.Message, type: 'warning', });
503
504            } else {
505
506                $.smkAlert({ text: data.Message, type: 'success', });
507
508                localStorage.LastCheck = new Date();
509
510                switch (Answer) {
511                    case 1: localStorage.BirthdayAnswer = 'false';
512                        $("#modBirthday").modal('hide');
513                        break;
514                    case 2: localStorage.CompanyAnswer = 'false';
515                        $("#modCompany").modal('hide');
516                        break;
517                    case 3: localstorage.GenderAnswer = 'false';
518                        $("#modGender").modal('hide');
519                        break;
520                    case 4: localStorage.NumberAnswer = 'false';
521                        $("#modNumber").modal('hide');
522                        break;
523                }
524            }
525        },
526        error: function (XMLHttpRequest, textStatus, errorThrown) {
527            $.smkAlert({ text: 'Unable to connect to service', type: 'danger', });
528        }
529    });
530}
531
532function LoadKeywordSuggestions() {
533
534    var InData = {
535        Token: localStorage.Token
536    }
537
538    $.ajax({
539        type: "POST",
540        url: APIURI + 'GetPopularKeywords',
541        data: JSON.stringify(InData),
542        success: function (data) {
543
544            if (data.length == 0) {
545                $('#TokenBoxSuggestionList').html('No Keywords Found');
546            } else {
547                var Keywords = '';
548                $.each(data, function (index, element) {
549                    if (element == '≡Media') {
550                        Keywords += '<span onclick="AddTokenFromSuggestion(\'≡Media\')" style="background-color: #DC4444;">Media</span>';
551                    } else if (element == '≡Publicity') {
552                        Keywords += '<span onclick="AddTokenFromSuggestion(\'≡Publicity\')" style="background-color: #A2B73A;">Publicity</span>';
553                    } else if (element == '≡Marketing') {
554                        Keywords += '<span onclick="AddTokenFromSuggestion(\'≡Marketing\')" style="background-color: #458CCC;">Marketing</span>';
555                    } else if (element == '≡Social') {
556                        Keywords += '<span onclick="AddTokenFromSuggestion(\'≡Social\')" style="background-color: #f39c12;">Social</span>';
557                    } else {
558                        Keywords += '<span onclick="AddTokenFromSuggestion(\'' + element + '\')" style="background-color: #a0a0a0;">' + element + '</span>';
559                    }
560                })
561
562                $('#TokenBoxSuggestionList').html(Keywords);
563            }
564
565        },
566        error: function (XMLHttpRequest, textStatus, errorThrown) {
567
568            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
569        }
570    });
571
572
573}
574
575///////////////////////////
576//  M Y   P R O F I L E
577///////////////////////////
578function GoToMyProfile() {
579    if (localStorage.Token == '' || localStorage.Token == null || localStorage.Token == 'undefined') {
580        $('#pleaseLogin').html('');
581        $('#modLogin').modal('show');
582        $('#modLogin').on('shown.bs.modal', function (e) {
583            $('.nav-tabs a[href="#ShowLogin"]').tab('show');
584        });
585    } else {
586        window.location = '/myprofile.aspx';
587    }
588
589}
590
591function Login() {
592    // DO VALIDATION
593    var Email = $('#txtLoginEmail').val().trim();
594    var Password = $('#txtLoginPassword').val().trim();
595
596    if (Email == '') {
597        $('#txtLoginEmail').focus();
598        $.smkAlert({ text: 'Please enter your email address and try again', type: 'warning', }); return;
599    }
600    if (Password == '') {
601        $('#txtLoginPassword').focus();
602        $.smkAlert({ text: 'Please enter your password and try again', type: 'warning', }); return;
603    }
604
605    // DO LOGIN
606    $.smkProgressBar({ element: 'body', status: 'start' });
607
608    var InData = {
609        Email: Email,
610        Password: Password,
611        Device: platform.description,
612        IsApp: false,
613        DeviceKey: '',
614        Platform: '',
615        Model: '',
616        Cordova: '',
617        Version: '',
618        OneSignalUserID: '',
619        OneSignalPushToken: ''
620    }
621
622    $.ajax({
623        type: "POST",
624        url: APIURI + 'user/login',
625        data: JSON.stringify(InData),
626        success: function (data) {
627            $.smkProgressBar({ element: 'body', status: 'end' });
628
629            if (data.Successful == false) {
630                $.smkAlert({ text: data.Error, type: 'warning', });
631            } else {
632
633                //SET USER INFO
634                localStorage.Token = data.Token;
635                localStorage.Name = data.Name;
636                localStorage.Email = data.Email;
637                localStorage.PP = data.ProfilePicture;
638
639                location.reload();
640                //window.location = '/myprofile.aspx';
641            }
642        },
643        error: function (XMLHttpRequest, textStatus, errorThrown) {
644            $.smkProgressBar({ element: 'body', status: 'end' });
645            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
646        }
647    });
648}
649
650function Register() {
651
652    $.when(ReturnOrCreateToken()).done(function (a1) {
653
654        // DO VALIDATION
655        var Name = $('#txtRegisterName').val().trim();
656        var Surname = $('#txtRegisterSurname').val().trim();
657        var Email = $('#txtRegisterEmail').val().trim();
658        var Password = $('#txtRegisterPassword').val().trim();
659
660        if (Name == '') {
661            $('#txtRegisterName').focus();
662            $.smkAlert({ text: 'Please enter your name and try again', type: 'warning', }); return;
663        }
664        if (Surname == '') {
665            $('#txtRegisterSurname').focus();
666            $.smkAlert({ text: 'Please enter your surname and try again', type: 'warning', }); return;
667        }
668        if (Email == '') {
669            $('#txtRegisterEmail').focus();
670            $.smkAlert({ text: 'Please enter your email address and try again', type: 'warning', }); return;
671        }
672        if (Password == '') {
673            $('#txtRegisterPassword').focus();
674            $.smkAlert({ text: 'Please enter your password and try again', type: 'warning', }); return;
675        }
676
677        $.smkProgressBar({ element: 'body', status: 'start' });
678        // DO REGISTER
679        var InData = {
680            Name: Name,
681            Surname: Surname,
682            Email: Email,
683            Password: Password,
684            Device: platform.description,
685            IsApp: false,
686            DeviceKey: '',
687            Platform: '',
688            Model: '',
689            Cordova: '',
690            Version: '',
691            OneSignalUserID: '',
692            OneSignalPushToken: ''            
693        }
694        $.ajax({
695            type: "POST",
696            url: APIURI + 'user/register',
697            data: JSON.stringify(InData),
698            success: function (data) {
699                $.smkProgressBar({ element: 'body', status: 'end' });
700
701                if (data.Successful == false) {
702                    $.smkAlert({ text: data.Error, type: 'warning', });
703                } else {
704                    alert('Thank you. An email verification mail was send to ' + Email + '. Please check your spam folder if you are unable to find the email.');
705                    localStorage.Token = data.Token;
706                    //localStorage.GuestToken = '';
707                    localStorage.Name = data.Name;
708                    localStorage.Email = data.Email;
709
710                    window.location = '/myprofile.aspx';
711                }
712            },
713            error: function (XMLHttpRequest, textStatus, errorThrown) {
714                $.smkProgressBar({ element: 'body', status: 'end' });
715                $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
716            }
717        });
718
719    });
720}
721
722function ForgotPassword() {
723    // DO VALIDATION
724    var Email = $('#txtLoginEmail').val().trim();
725
726    if (Email == '') {
727        $('#txtLoginEmail').focus();
728        $.smkAlert({ text: 'Please enter your email address and try again', type: 'warning', }); return;
729    }
730
731    $.smkProgressBar({ element: 'body', status: 'start' });
732    // DO FORGOT PASSWORD
733    var InData = {
734        Email: Email
735    }
736    $.ajax({
737        type: "POST",
738        url: APIURI + 'user/forgotpassword',
739        data: JSON.stringify(InData),
740        success: function (data) {
741            $.smkProgressBar({ element: 'body', status: 'end' });
742            console.log(data);
743
744            if (data.Successful == false) {
745                $.smkAlert({ text: data.Error, type: 'warning', });
746            } else {
747                alert('An email was send to ' + Email + ' with the password instructions. Please check your spam folder if you are unable to find the email.');
748                $('#modLogin').modal('hide');
749            }
750        },
751        error: function (XMLHttpRequest, textStatus, errorThrown) {
752            $.smkProgressBar({ element: 'body', status: 'end' });
753            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
754        }
755    });
756}
757
758function ValidateToken() {
759    var InData = {
760        Token: localStorage.Token
761    }
762    $.ajax({
763        type: "POST",
764        url: APIURI + 'user/validatetoken',
765        data: JSON.stringify(InData),
766        success: function (data) {
767            return data;
768        },
769        error: function (XMLHttpRequest, textStatus, errorThrown) {
770            $.smkAlert({ text: 'Unable to connect to the service to validate token', type: 'danger', });
771            return false;
772        }
773    });
774}
775
776function LogOut() {
777    if (confirm('Are you sure you want to log out?')) {
778        localStorage.removeItem('Token');
779        localStorage.removeItem('Email');
780        localStorage.removeItem('Name');
781
782        localStorage.removeItem('pathURL');
783        localStorage.removeItem('CurrentT');
784
785        window.location = '/default.aspx';
786    }
787}
788
789$('#txtLoginEmail').keyup(function (e) {
790    if (e.keyCode == 13) {
791        Login();
792    }
793});
794$('#txtLoginPassword').keyup(function (e) {
795    if (e.keyCode == 13) {
796        Login();
797    }
798});
799
800///////////////////////////
801// BOOKMARKING
802///////////////////////////
803function AddBookmark(IDStory) {
804    if (localStorage.Token == '' || localStorage.Token == null || localStorage.Token == 'undefined') {
805        $.smkAlert({ text: 'Please log in to add a bookmark to your profile.', type: 'success', });
806        return;
807    }
808
809    $.smkProgressBar({ element: 'body', status: 'start' });
810
811    var InData = {
812        Token: localStorage.Token,
813        IDStory: IDStory
814    }
815    $.ajax({
816        type: "POST",
817        url: APIURI + 'user/bookmark/add',
818        data: JSON.stringify(InData),
819        success: function (data) {
820            $.smkProgressBar({ element: 'body', status: 'end' });
821
822            if (data.Success == false) {
823                $.smkAlert({ text: data.Message, type: 'warning', });
824            } else {
825                $.smkAlert({ text: data.Message, type: 'success', });
826            }
827
828        },
829        error: function (XMLHttpRequest, textStatus, errorThrown) {
830            $.smkProgressBar({ element: 'body', status: 'end' });
831            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
832        }
833    });
834}
835
836function RemoveBookmark(IDStory) {
837
838    if (confirm('Are you sure you want to delete this bookmark?')) {
839        $.smkProgressBar({ element: 'body', status: 'start' });
840
841        var InData = {
842            Token: localStorage.Token,
843            IDStory: IDStory
844        }
845        $.ajax({
846            type: "POST",
847            url: APIURI + 'user/bookmark/remove',
848            data: JSON.stringify(InData),
849            success: function (data) {
850                $.smkProgressBar({ element: 'body', status: 'end' });
851
852                if (data.Success == false) {
853                    $.smkAlert({ text: data.Message, type: 'warning', });
854                } else {
855                    $.smkAlert({ text: data.Message, type: 'success', });
856                    $('#MyBookmarkContainer').html('');
857                }
858
859                LoadBookmarks(0);
860            },
861            error: function (XMLHttpRequest, textStatus, errorThrown) {
862                $.smkProgressBar({ element: 'body', status: 'end' });
863                $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
864            }
865        });
866    }
867}
868
869///////////////////////////
870// NOTIFICATIONS
871///////////////////////////
872function NotificationsUnseenCount() {
873
874    var InData = {
875        Token: localStorage.Token
876    }
877    $.ajax({
878        type: "POST",
879        url: APIURI + 'user/notification/unseencount',
880        data: JSON.stringify(InData),
881        contentType: "application/json",
882        success: function (data) {
883            if (data > 0) {
884                $('#PPLinkInNoti').html(data);
885                $('#PPLinkInNoti').show();
886            } else {
887                $('#PPLinkInNoti').html('');
888                $('#PPLinkInNoti').hide();
889            }
890        },
891        error: function (XMLHttpRequest, textStatus, errorThrown) {
892            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
893        }
894    });
895}
896
897function RemoveSearchQuery() {
898
899    ShowSmokeLoader();
900
901    var URL = '/';
902    if (QS('f') !== '') {
903        URL = '/default.aspx?f=' + QS('f');
904    }
905    window.location = URL;
906
907
908}
909function RemoveSearchFilter() {
910    ShowSmokeLoader();
911    var URL = '/';
912    if (QS('q') !== '') {
913        URL = '/default.aspx?q=' + QS('q');
914    }
915    window.location = URL;
916
917
918}
919
920function AddTokenFromSuggestion(v) {
921
922    ShowSmokeLoader();
923    var SearchFilter = QS('f');
924    var SearchQuery = QS('q');
925
926    if (SearchFilter == '') {
927
928        var uri = window.location.href;
929
930        if (SearchQuery != '') {
931            window.location = uri + "&f=" + v.trim().replace('≡', '').toLowerCase();
932        } else {
933            window.location = "/default.aspx?f=" + v.trim().replace('≡', '').toLowerCase();
934        }
935
936    } else if (SearchFilter != '') {
937        window.location = "/default.aspx?f=" + v.trim().replace('≡', '').toLowerCase();
938
939    } else if ((SearchFilter != '') && (SearchQuery != '')) {
940        window.location = "/default.aspx?f=" + v.trim().replace('≡', '').toLowerCase() + "&q=" + SearchQuery.trim().toLowerCase();
941    } else {
942        $.smkAlert({ text: 'Only one filter allowed', type: 'warning', });
943
944    }
945    HideSmokeLoader
946}
947
948function RemoveToken(url, parameter) {
949    console.log("j,asdn");
950
951    //prefer to use l.search if you have a location/link object
952    var urlparts = url.split('?');
953    if (urlparts.length >= 2) {
954
955        var prefix = encodeURIComponent(parameter) + '=';
956        var pars = urlparts[1].split(/[&;]/g);
957
958        //reverse iteration as may be destructive
959        for (var i = pars.length; i-- > 0;) {
960            //idiom for string.startsWith
961            if (pars[i].lastIndexOf(prefix, 0) !== -1) {
962                pars.splice(i, 1);
963            }
964        }
965
966        url = urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : "");
967        return url;
968    } else {
969        return url;
970    }
971}
972
973function setCookie(cname, cvalue, exdays) {
974    var d = new Date();
975    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
976    var expires = "expires=" + d.toUTCString();
977    document.cookie = cname + "=" + cvalue + "; " + expires;
978}
979
980function SetTokenStorage() {
981
982    var TokenStorageValue = '';
983
984    $('#TokenBox').children('span').each(function () {
985        CurrentValue = $(this).text().trim().toLowerCase();
986        if (CurrentValue == 'media') { CurrentValue = "≡" + CurrentValue; }
987        if (CurrentValue == 'marketing') { CurrentValue = "≡" + CurrentValue; }
988        if (CurrentValue == 'publicity') { CurrentValue = "≡" + CurrentValue; }
989        if (CurrentValue == 'social') { CurrentValue = "≡" + CurrentValue; }
990
991        if (TokenStorageValue == '') {
992            TokenStorageValue += CurrentValue
993        } else {
994            TokenStorageValue += ',' + CurrentValue
995        }
996
997    });
998
999    //localStorage.TokenBox = TokenStorageValue.toLowerCase();
1000
1001    window.location = '/';
1002}
1003
1004function RemoveAllTokens() {
1005    $('#TokenBox').children('span').each(function () {
1006        this.remove();
1007    });
1008}
1009
1010function ShowTokenSuggestions() {
1011    $('.TokenBoxSuggestions').show(300);
1012}
1013
1014function HideTokenSuggestions() {
1015    $('.TokenBoxSuggestions').hide(300);
1016}
1017
1018/////////////////////////////
1019///  A U D I O   F I L E  ///
1020/////////////////////////////
1021
1022var audio = "";
1023var category = $(".dt-category").text();
1024
1025var formatTime = function (time) {
1026    return [
1027        Math.floor((time % 3600) / 60), // minutes
1028        ('00' + Math.floor(time % 60)).slice(-2) // seconds
1029    ].join(':');
1030};
1031
1032if (category == "Social") {
1033    progressC = '#F39C12';
1034} else if (category == "Marketing") {
1035    progressC = '#458CCC';
1036} else if (category == "Media") {
1037    progressC = '#DC4444';
1038} else {
1039    progressC = '#A2B73A';
1040}
1041
1042loadcurrent();
1043function loadcurrent() {
1044    InputData = {
1045        Token: localStorage.Token,
1046    }
1047
1048    $.ajax({
1049        type: 'POST',
1050        url: APIURI + 'user/playlist/loadcurrent',
1051        data: JSON.stringify(InputData),
1052        success: function (data) {
1053            if (data.Success != false) {
1054                GetPlaylist();
1055            } else {
1056                return;
1057            }
1058        },
1059        error: function (XMLHttpRequest, textStatus, errorThrown) {
1060            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
1061        }
1062    })
1063}
1064
1065$('#playBtn').on('click', function () {
1066    $('#waveRow').slideUp(800);
1067    localStorage.CurrentT = 0;
1068
1069
1070    if (localStorage.Token == null) {
1071        //NON-LOGGED IN USERS
1072        $('#playListbtn').on('click', function () {
1073            GoToMyProfile2();
1074        });
1075
1076        $('#previousAudioDiv').remove();
1077        $('#nextAudioDiv').remove();
1078        $('#mediaButtons').removeClass('col-sm-4 col-md-3 col-lg-3');
1079        $('#mediaButtons').addClass('col-sm-4 col-md-3 col-lg-2');
1080        $('#mediaButtons').css('margin-left', '40px');
1081        $('#audioControls').css('margin-left', '-50px');
1082        $('#audioControls').removeClass('col-sm-4 col-md-5 col-lg-5');
1083        $('#audioControls').addClass('col-sm-4 col-md-5 col-lg-6');
1084
1085        InputData = {
1086            IDStory: window.location.pathname.split('/').slice(1)[1]
1087        }
1088
1089        $.ajax({
1090            type: "POST",
1091            url: APIURI + 'story/audiofile/get',
1092            data: JSON.stringify(InputData),
1093            success: function (data) {
1094                if (data.Success != false) {
1095
1096                    if (window.innerWidth <= 767) {
1097                        var html = '';
1098
1099                        html += '';
1100                        html += '<div class="row">';
1101                        html += '   <div class="col-xs-4" id="audioImg" style=""></div >';
1102                        html += '   <div class="col-xs-8">';
1103                        html += '       <div class="row" style="text-align: center; margin-left: -18%">';
1104                        html += '           <div class="col-xs-10" id="audioName" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 5px;"></div>';
1105                        html += '       </div>';
1106                        html += '       <div class="row" style="text-align: center; margin-left: -18%">';
1107                        html += '           <div class="col-xs-10" style="margin-top: 5px;">';
1108                        html += '               <div class="col-xs-3" style="display: inline; text-align: center">';
1109                        html += '                   <a id="skipBackwardBtn" onclick= "rewind()" style= "background: none; display: inline; padding: 4px;" >';
1110                        html += '                       <i class="fa fa-fast-backward fa-sm" id="skipBackIcon" style="cursor: pointer; color: #333333"></i>';
1111                        html += '                   </a>';
1112                        html += '               </div >';
1113                        html += '               <div class="col-xs-3" style="display: inline; text-align: center">';
1114                        html += '                   <a id="playBtn2" onClick="playAudio()" style="background: none; display: inline; padding: 4px; margin: auto">';
1115                        html += '                       <i class = "fa fa-play fa-lg" id="playIcon2" style="cursor: pointer; color: #333333"></i>';
1116                        html += '                   </a>';
1117                        html += '               </div >';
1118                        html += '               <div class="col-xs-3" style="display: inline; text-align: center">';
1119                        html += '                   <a id="skipForwardBtn" onclick="forward()" style="background: none; display: inline; padding: 4px; margin: auto">';
1120                        html += '                       <i class = "fa fa-fast-forward fa-sm" id="skipForwardIcon" style="cursor: pointer; color: #333333"></i>';
1121                        html += '                   </a>';
1122                        html += '               </div >';
1123                        html += '               <div class="col-xs-3" id="btnPlaylist" style="display: inline; text-align: center">';
1124                        html += '                   <a id="playlistBtn" style="background: none; display: inline;" onclick="GoToMyProfile2()">';
1125                        html += '                       <i class="fa fa-list" id="playlistIcon" style="cursor: pointer; color: #333333" title="Playlist"></i>';
1126                        html += '                   </a>';
1127                        html += '               </div>';
1128                        html += '           </div>';
1129                        html += '       </div>';
1130                        html += '       <div class="row" style="text-align: center; margin-left: -10%">';
1131                        html += '           <div class="col-xs-10" style="margin-top: 5px;">';
1132                        html += '               <div class="col-xs-1 col-sm-1" id="CurrentTime" style="display: inline-block; margin: auto">';
1133                        html += '                   <div id="currentTimeDiv">0:00</div>';
1134                        html += '               </div>';
1135                        html += '               <div class="col-xs-8" style="display: inline-block; margin: auto">';
1136                        html += '                   <div class="row" style="height: 25px;" id="audioDiv">';
1137                        html += '                       <div id="progressDiv" style="height: 5px; width: 100%; background-color: #c8c8c8; border-radius: 3px">';
1138                        html += '                           <canvas i
1138d="canvas" style="width: 100%; height: 5px; margin-bottom: 20px; border-radius: 2px;"></canvas>';
1139                        html += '                       </div>';
1140                        html += '                       <audio id="myaudio" muted preload="auto"></audio>';
1141                        html += '                   </div>';
1142                        html += '               </div>';
1143                        html += '               <div class="col-xs-1" style="display: inline-block; margin: auto">';
1144                        html += '                   <div id="durationTime"></div>';
1145                        html += '               </div>';
1146                        html += '           </div>';
1147                        html += '       </div>';
1148                        html += '   </div>';
1149                        html += '</div>';
1150
1151                        $('#audioBarContainer').html(html);
1152
1153                        $('#audioBar').css('height', '80px');
1154                        $('#audioDiv').css('margin-top', '9px');
1155                        $('#currentTimeDiv').css('margin-top', '1px');
1156                        $('#durationTime').css('margin-top', '1px');
1157                        $('#audioImg').html('<div style="background: url(' + data.ImgURL + ') no-repeat; background-size: cover; background-position: center; height: 80px; width: 80px; margin-left: 10px;" />');
1158                    } else {
1159                        $('#audioBar').css('height', '50px');
1160                        $('#audioDiv').css('margin-top', '24px');
1161                        $('#audioImg').html('<div style="background: url(' + data.ImgURL + ') no-repeat; background-size: cover; background-position: center; height: 32px; width: 32px; margin-top: 10px;" />');
1162                    }
1163
1164                    $('#audioName').html("<div style='font-size: 13px;'>" + (data.AudioName).slice(0, -4) + "</div>");
1165
1166
1167                    var audio = document.getElementById('myaudio');
1168
1169                    audio.addEventListener('loadeddata', function () {
1170                        if (audio.readyState >= 3) {
1171                            $('#playIcon2').removeClass('fa-play');
1172                            $('#playIcon2').addClass('fa-pause');
1173                        }
1174                    });
1175
1176                    audio.oncanplay = function () {
1177                        audio.play();
1178                    };
1179
1180                    audio.src = 'https://dash.mediaupdate.co.za/' + data.URLPath;
1181                    $('#progress').css("background-color", progressC);
1182                    $('#durationTime').html(formatTime(data.Duration));
1183                    audio.ontimeupdate = function () {
1184                        $('#currentTimeDiv').html(formatTime(Math.floor(audio.currentTime)));
1185                        var oAudio = document.getElementById('myaudio');
1186                        var elapsedTime = Math.round(audio.currentTime);
1187
1188                        if (canvas.getContext) {
1189                            var ctx = canvas.getContext("2d");
1190                            ctx.clearRect(0, 0, canvas.width, canvas.height);
1191                            ctx.fillStyle = data.ReadColor;
1192                            var fWidth = (elapsedTime / oAudio.duration) * (canvas.width);
1193                            if (fWidth > 0) {
1194                                ctx.fillRect(0, 0, fWidth, canvas.height);
1195                            }
1196                        }
1197                    }
1198
1199                    setTimeout(function () {
1200
1201                        if (audio.muted == true) {
1202                            audio.muted = false;
1203                        }
1204                    }, 50);
1205
1206                    canvas.addEventListener("click", function (e) {
1207                        var audio = document.getElementById('myaudio');
1208                        var canvas = document.getElementById('canvas');
1209
1210                        if (!e) {
1211                            e = window.event;
1212                        } else {
1213                            audio.currentTime = audio.duration * (e.offsetX / canvas.clientWidth);
1214                        }
1215                    }, true);
1216
1217                    $('#myaudio').on('ended', function () {
1218                        $('#playIcon2').removeClass('fa-pause');
1219                        $('#playIcon2').addClass('fa-play');
1220                    });
1221
1222                } else {
1223                    $.smkAlert({ text: 'Audio file not found', type: 'warning', });
1224                }
1225            },
1226            error: function (XMLHttpRequest, textStatus, errorThrown) {
1227                $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
1228            }
1229        })
1230    } else {
1231        InputData = {
1232            Token: localStorage.Token,
1233            IDStory: window.location.pathname.split('/').slice(1)[1]
1234        }
1235
1236        $.ajax({
1237            type: "POST",
1238            url: APIURI + "user/playlist/add",
1239            data: JSON.stringify(InputData),
1240            success: function (data) {
1241                if (data.Success != false) {
1242                    $.smkAlert({ text: data.Message, type: 'success', });
1243                    GetPlaylist();
1244                }
1245            },
1246            error: function (XMLHttpRequest, textStatus, errorThrown) {
1247                $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
1248            }
1249        })
1250    }
1251});
1252
1253
1254function GetPlaylist(ignoreCurrentPosition) {
1255    if (localStorage.Token.length <= 0) { return; }
1256
1257    var ignore = false;
1258    if (ignoreCurrentPosition == true) {
1259        ignore = true;
1260    }
1261    
1262
1263    InputData = {
1264        Token: localStorage.Token,
1265        IgnorePosition: ignore
1266    }
1267
1268    $.ajax({
1269        type: "POST",
1270        url: APIURI + "user/playlist/getall",
1271        data: JSON.stringify(InputData),
1272        success: function (data) {
1273            var html = "";
1274            if (data.length > 0) {
1275                var i = 0;
1276                $.each(data, function (index, element) {
1277                    html += "<div class='playlistItem' style='display: flex; padding-left: 10px; padding-right: 10px; margin-right: -10px;'>";
1278                    html += "   <div style='width: 35px; height: 30px; position: relative; margin-top: 5px; cursor: pointer;' onclick='loadPlaylistFile(" + element.ID + ")'>";
1279                    html += "       <div id='playlistItemImg' style='position: absolute; height: 100%; width: 30px; background: url(" + element.ImgURL + "); background-size: 30px 30px;'></div>";
1280                    html += "       <div id='playlistItemImgIcon' style='position: absolute'></div>";
1281                    html += "   </div>";
1282                    
1283                    html += "   <div class='playlistItem-Name' style='width: 90%; height: 40px;  overflow: hidden; white-space: nowrap; margin-left: 10px;'>";
1284                    html += "       <div style= 'margin-top: 10px; font-size: 15px; cursor: pointer; text-overflow: ellipsis; overflow: hidden; white-space: nowrap' onclick='loadPlaylistFile(" + element.ID + ")'>" + element.AudioName + "</div>";
1285                    html += "   </div>";
1286                    html += "   <div id='playlistItem-duration' style='height: 40px; width:70px; text-align:center;'>";
1287                    html += "       <p style='margin-top: 12px; font-size: 13px;'>" + formatTime(element.Duration) + "</p>";
1288                    html += "   </div>";
1289                    html += "   <div id='playlistItem-trash' style='height: 40px; width: 30px; text-align:center;' onclick='deleteAudio(" + element.ID + ")'>";
1290                    html += "       <i class='fa fa-trash-o fa-md' style='margin-top: 14px; cursor: pointer'></i>";
1291                    html += "   </div>";
1292                    html += "</div>";
1293                    i++;
1294                })
1295                    //
1296                $('#playlist-content').html(html);
1297                localStorage.AudioID = data[0].ID;
1298
1299                $('.playlistItem').on('mouseenter', function () {
1300                    $(this).css('background-color', '#f1f1f1');
1301                    $('#playlistItemImg', this).css("opacity", "0.4");
1302                    $('#playlistItemImgIcon', this).html("<i class='fa fa-play-circle fa-lg' style='margin-left: 7px; margin-top: 9px; color: #C1272D; background-color: #fff; border-radius: 8px;'></i>");
1303                });
1304
1305                $('.playlistItem').on('mouseleave', function () {
1306                    $(this).css('background-color', '#fff');
1307                    $('#playlistItemImg', this).css("opacity", "1");
1308                    $('#playlistItemImgIcon', this).html("");
1309                });
1310
1311                if (data[0].ImgURL == null) {
1312                    $('#audioBar').css('height', '0');
1313                }
1314
1315                if (window.innerWidth <= 767) {
1316                    var html = '';
1317
1318                    //Redesign Audio Bar for mobile screens
1319                    html += '';
1320                    html += '<div class="row">';
1321                    html += '   <div class="col-xs-4" id="audioImg" style="cursor: pointer;"></div >';
1322                    html += '   <div class="col-xs-8">';
1323                    html += '       <div class="row" style="text-align: center; margin-left: -18%">';
1324                    html += '           <div class="col-xs-10" id="audioName" style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 5px; cursor: pointer;"></div>';
1325                    html += '       </div>';
1326                    html += '       <div class="row" style="text-align: center; margin-left: -18%">';
1327                    html += '           <div class="col-xs-10" style="margin-top: 5px;">';
1328                    html += '               <div class="col-xs-2 col-md-2 col-lg-2" id="previousAudioDiv" style="display: inline; text-align: center">';
1329                    html += '                   <a href="/audiohistory.aspx" id="seekBackwardBtn" style="background: none; display: inline; padding: 4px;">';
1330                    html += '                       <i class="fa fa-history fa-sm" id="backwardIcon" style="cursor: pointer; color: #333333"></i>';
1331                    html += '                   </a>';
1332                    html += '               </div>';
1333                    html += '               <div class="col-xs-2" style="display: inline; text-align: center">';
1334                    html += '                   <a id="skipBackwardBtn" onclick= "rewind()" style= "background: none; display: inline; padding: 4px;" >';
1335                    html += '                       <i class="fa fa-fast-backward fa-sm" id="skipBackIcon" style="cursor: pointer; color: #333333"></i>';
1336                    html += '                   </a>';
1337                    html += '               </div >';
1338                    html += '               <div class="col-xs-2" style="display: inline; text-align: center">';
1339                    html += '                   <a id="playBtn2" onClick="playAudio()" style="background: none; display: inline; padding: 4px; margin: auto">';
1340                    html += '                       <i class = "fa fa-play fa-lg" id="playIcon2" style="cursor: pointer; color: #333333"></i>';
1341                    html += '                   </a>';
1342                    html += '               </div >';
1343                    html += '               <div class="col-xs-2" style="display: inline; text-align: center">';
1344                    html += '                   <a id="skipForwardBtn" onclick="forward()" style="background: none; display: inline; padding: 4px; margin: auto">';
1345                    html += '                       <i class = "fa fa-fast-forward fa-sm" id="skipForwardIcon" style="cursor: pointer; color: #333333"></i>';
1346                    html += '                   </a>';
1347                    html += '               </div >';
1348                    html += '               <div class="col-xs-2" id="nextAudioDiv" style="display: inline; text-align: center">';
1349                    html += '                   <a id="seekForwardBtn" style="background: none; display: inline; padding: 4px;">';
1350                    html += '                       <i class="fa fa-step-forward fa-sm" id="forwardIcon" style="cursor: pointer; color: #333333"></i>';
1351                    html += '                   </a>';
1352                    html += '               </div>';
1353                    html += '               <div class="col-xs-2" id="bt
1353nPlaylist" style="display: inline; text-align: center">';
1354                    html += '                   <a id="playlistBtn" style="background: none; display: inline;" onclick="GoToMyProfile2()">';
1355                    html += '                       <i class="fa fa-list" id="playlistIcon" style="cursor: pointer; color: #333333" title="Playlist"></i>';
1356                    html += '                   </a>';
1357                    html += '               </div>';
1358                    html += '           </div>';
1359                    html += '       </div>';
1360                    html += '       <div class="row" style="text-align: center; margin-left: -10%">';
1361                    html += '           <div class="col-xs-10" style="margin-top: 5px;">';
1362                    html += '               <div class="col-xs-1 col-sm-1" id="CurrentTime" style="display: inline-block; margin: auto">';
1363                    html += '                   <div id="currentTimeDiv">0:00</div>';
1364                    html += '               </div>';
1365                    html += '               <div class="col-xs-8" style="display: inline-block; margin: auto">';
1366                    html += '                   <div class="row" style="height: 25px;" id="audioDiv">';
1367                    html += '                       <div id="progressDiv" style="height: 5px; width: 100%; background-color: #c8c8c8; border-radius: 3px">';
1368                    html += '                           <canvas id="canvas" style="width: 100%; height: 5px; margin-bottom: 20px; border-radius: 2px;"></canvas>';
1369                    html += '                       </div>';
1370                    html += '                       <audio id="myaudio" muted preload="auto"></audio>';
1371                    html += '                   </div>';
1372                    html += '               </div>';
1373                    html += '               <div class="col-xs-1" style="display: inline-block; margin: auto">';
1374                    html += '                   <div id="durationTime"></div>';
1375                    html += '               </div>';
1376                    html += '           </div>';
1377                    html += '       </div>';
1378                    html += '   </div>';
1379                    html += '</div>';
1380
1381                    $('#audioBarContainer').html(html);
1382
1383
1384                    $('#audioBar').css('height', '80px');
1385                    $('#audioDiv').css('margin-top', '9px');
1386                    $('#currentTimeDiv').css('margin-top', '1px');
1387                    $('#durationTime').css('margin-top', '1px');
1388                    $('#audioImg').html('<div style="background: url(' + data[0].ImgURL + ') no-repeat; background-size: cover; background-position: center; height: 80px; width: 80px; margin-left: 10px;" />');
1389                } else {
1390                    $('#audioBar').css('height', '50px');
1391                    $('#audioDiv').css('margin-top', '24px');
1392                    $('#audioImg').html('<div style="background: url(' + data[0].ImgURL + ') no-repeat; background-size: cover; background-position: center; height: 32px; width: 32px; margin-top: 10px;" />');
1393                }
1394
1395                $('#audioName').html("<div style='font-size: 13px; overflow: hidden; text-overflow: ellipsis; whitespace: nowrap'>" + (data[0].AudioName).slice(0, -4) + "</div>");
1396
1397                $('#audioImg').on('click', function () {
1398                    window.location = data[0].storyURL;
1399                });
1400
1401                $('#audioName').on('click', function () {
1402                    window.location = data[0].storyURL;
1403                })
1404
1405                var audio = document.getElementById('myaudio');
1406                
1407                $('#currentTimeDiv').html(formatTime(data[0].Current));
1408                audio.src = 'https://dash.mediaupdate.co.za/' + data[0].URLPath;
1409                $('#progress').css("background-color", progressC);
1410                $('#durationTime').html(formatTime(data[0].Duration));
1411                audio.currentTime = data[0].Current;
1412                
1413                audio.ontimeupdate = function () {
1414                    $('#currentTimeDiv').html(formatTime(audio.currentTime));
1415                    var oAudio = document.getElementById('myaudio');
1416                    var elapsedTime = Math.round(audio.currentTime);
1417
1418                    if (canvas.getContext) {
1419                        var ctx = canvas.getContext("2d");
1420                        ctx.clearRect(0, 0, canvas.width, canvas.height);
1421                        ctx.fillStyle = data[0].ReadColor;
1422                        var fWidth = (elapsedTime / oAudio.duration) * (canvas.width);
1423                        if (fWidth > 0) {
1424                            ctx.fillRect(0, 0, fWidth, canvas.height);
1425                        }
1426                    }
1427                }
1428
1429                audio.onended = function () {
1430                    $('#playIcon2').removeClass('fa-pause');
1431                    $('#playIcon2').addClass('fa-play');
1432
1433                    InputData = {
1434                        Token: localStorage.Token,
1435                        ID: data[0].ID
1436                    }
1437
1438                    $.ajax({
1439                        type: 'POST',
1440                        url: APIURI + "user/playlist/playnext",
1441                        data: JSON.stringify(InputData),
1442                        success: function (data) {
1443                            if (data.Success != false) {
1444                                GetPlaylist(true);
1445                            }
1446                        },
1447                        error: function (XMLHttpRequest, textStatus, errorThrown) {
1448                            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
1449                        }
1450                    })
1451                }
1452
1453                setTimeout(function () {
1454                    if (audio.muted == true) {
1455                        audio.muted = false;
1456                    }
1457                }, 1);
1458
1459                if (data[0].PlayState == true) {
1460                    audio.play();
1461                    $('#playIcon2').toggleClass('fa-pause fa-play');
1462                } else {
1463                    return;
1464                }
1465
1466                canvas.addEventListener("click", function (e) {
1467                    var audio = document.getElementById('myaudio');
1468                    var canvas = document.getElementById('canvas');
1469
1470                    if (!e) {
1471                        e = window.event;
1472                    } else {
1473                        audio.currentTime = audio.duration * (e.offsetX / canvas.clientWidth);
1474                    }
1475                }, true);
1476
1477                $('#forwardIcon').on('click', function () {
1478                    InputData = {
1479                        Token: localStorage.Token,
1480                        ID: data[0].ID
1481                    }
1482
1483                    $.ajax({
1484                        type: 'POST',
1485                        url: APIURI + "user/playlist/playnext",
1486                        data: JSON.stringify(InputData),
1487                        success: function (data) {
1488                            if (data.Success != false) {
1489                                GetPlaylist(true);
1490                            }
1491                        },
1492                        error: function (XMLHttpRequest, textStatus, errorThrown) {
1493                            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
1494                        }
1495                    })
1496                });
1497
1498            } else {
1499                $('#playlistBar').css('height', '0');
1500                $('#audioBar').css('height', '0');
1501            }
1502        },
1503        error: function (XMLHttpRequest, textStatus, errorThrown) {
1504            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
1505        }
1506    })
1507}
1508
1509$('#volumeIcon').on('click', function () {
1510    $('#myRange').toggle(); 
1511    if ($('#myRange').is(':visible')) {
1512        $('#audioImg').css('margin-left', '55px');
1513    } else {
1514        $('#audioImg').css('margin-left', '-25px');
1515    }
1516    
1517})
1518
1519var oAudio = document.getElementById('myaudio');
1520
1521oAudio.onloadedmetadata = function () {
1522    $('#durationTime').html(formatTime(oAudio.duration));
1523};
1524
1525myFunction();
1526function myFunction() {
1527    setTimeout(function () {
1528        if (oAudio.muted == true) {
1529            oAudio.muted = false;
1530        }
1531    }, 1);
1532
1533    var audio = document.getElementById('myaudio');
1534}
1535
1536function rewind() {
1537    var audio = document.getElementById('myaudio');
1538
1539    audio.currentTime -= 30;
1540}
1541
1542function forward() {
1543    var audio = document.getElementById('myaudio');
1544
1545    audio.currentTime += 30;
1546}
1547
1548function playAudio() {
1549    var oAudio = document.getElementById('myaudio');
1550
1551    if (oAudio.paused) {
1552        oAudio.play();
1553        $('#playIcon2').removeClass('fa-play');
1554        $('#playIcon2').addClass('fa-pause');
1555    }
1556    else {
1557        oAudio.pause();
1558        $('#playIcon2').removeClass('fa-pause');
1559        $('#playIcon2').addClass('fa-play');
1560    }
1561}
1562
1563function initEvents() {
1564    var canvas = document.getElementById('canvas');
1565    var oAudio = document.getElementById('myaudio');
1566
1567    oAudio.addEventListener("playing", function () {
1568        $('#playIcon2').addClass('fa-pause');
1569    }, true);
1570
1571    oAudio.addEventListener("pause", function () {
1572        $('#playIcon2').addClass('fa-play');
1573    }, true);
1574
1575  
1576
1577    canvas.addEventListener("click", function (e) {
1578        var oAudio = document.getElementById('myaudio');
1579        var canvas = document.getElementById('canvas');
1580
1581        if (!e) {
1582            e = window.event;
1583        } else {
1584            oAudio.currentTime = oAudio.duration * (e.offsetX / canvas.clientWidth);
1585        }
1586    }, true);
1587}
1588
1589window.addEventListener("DOMContentLoaded", initEvents, false);
1590
1591function deleteAudio(id) {
1592    InputData = {
1593        Token: localStorage.Token,
1594        ID: id
1595    }
1596
1597    $.ajax({
1598        type: "POST",
1599        url: APIURI + "user/playlist/deletefile",
1600        data: JSON.stringify(InputData),
1601        success: function (data) {
1602            if (data.Success != false) {
1603                GetPlaylist();
1604            }
1605        },
1606        error: function (XMLHttpRequest, textStatus, errorThrown) {
1607            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
1608        }
1609    })
1610}
1611
1612function loadPlaylistFile(id) {
1613    localStorage.CurrentT = 0;
1614    
1615
1616    InputData = {
1617        Token: localStorage.Token,
1618        IDStoryAudio: id
1619    }
1620
1621    $.ajax({
1622        type: "POST",
1623        url: APIURI + "user/playlist/loadfromplaylist",
1624        data: JSON.stringify(InputData),
1625        success: function (data) {
1626            if (data.Success != false) {
1627                GetPlaylist();
1628                if ($('#playIcon2').hasClass('fa-play')) {
1629                    $('#playIcon2').addClass('fa-pause');
1630                }
1631            }
1632        },
1633        error: function (XMLHttpRequest, textStatus, errorThrown) {
1634            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
1635        }
1636    })
1637}
1638
1639$(window).on('beforeunload', function () {
1640    var oAudio = document.getElementById('myaudio');
1641
1642    if (localStorage.Token.length > 0) {
1643        if (oAudio.currentTime > 0) {
1644            var currentPlayState;
1645            if (!oAudio.paused) {
1646                currentPlayState = true;
1647            } else {
1648                currentPlayState = false;
1649            }
1650
1651            InputData = {
1652                Token: localStorage.Token,
1653                ID: localStorage.AudioID,
1654                CurrentTime: Math.floor(oAudio.currentTime),
1655                PlayState: currentPlayState
1656            }
1657
1658            $.ajax({
1659                type: 'POST',
1660                url: APIURI + 'user/playlist/saveposition',
1661                data: JSON.stringify(InputData),
1662                success: function (data) {
1663                    
1664                },
1665                error: function (XMLHttpRequest, textStatus, errorThrown) {
1666                    $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
1667                }
1668            })
1669
1670        }
1671    }
1672    
1673});
1674
1675function GoToMyProfile2() {
1676    if (localStorage.Token == '' || localStorage.Token == null || localStorage.Token == 'undefined') {
1677        $('#pleaseLogin').html('<center><h4 style="padding-bottom: 10px; ">Please log in to make use of this feature</h4></center>');
1678        $('#modLogin').modal('show');
1679        $('#modLogin').on('shown.bs.modal', function (e) {
1680            $('.nav-tabs a[href="#ShowLogin"]').tab('show');
1681        });
1682    } else {
1683        $('#playlistIcon').toggleClass('fa-list fa-times');
1684        if (($('#playlistIcon').hasClass('fa-times')) && (window.innerWidth <= 767)) {
1685            $('#playlistBar').css('height', '50%');
1686            $('#playlist-wrapper').css('width', '100vw');
1687            $('#playlist-wrapper').css('float', 'left');
1688        } else if (($('#playlistIcon').hasClass('fa-times')) && (window.innerWidth > 767)) {
1689            $('#playlistBar').css('height', '55%');
1690            $('#playlist-wrapper').css('width', '360px');
1691        } else {
1692            $('#playlistBar').css('height', '0');
1693        }
1694    }
1695}
1696
1697function clearPlaylist() {
1698    InputData = {
1699        Token: localStorage.Token
1700    }
1701
1702    $.ajax({
1703        type: 'POST',
1704        url: APIURI + 'user/playlist/clear',
1705        data: JSON.stringify(InputData),
1706        success: function (data) {
1707            GetPlaylist();
1708            var oAudio = document.getElementById('myaudio');
1709            oAudio.pause();
1710            $('#playlistBar').css('height', '0');
1711        },
1712        error: function (XMLHttpRequest, textStatus, errorThrown) {
1713            $.smkAlert({ text: 'Unable to connect to the service', type: 'danger', });
1714        }
1715    })
1716}
1717
1718function openSubMenu() {
1719    $('#contributionsSub').css('display', 'block');
1720}
1721
1722function OpenSearchBar() {
1723    $('#mobile-info-bar').slideUp(100);
1724    $('#mobile-profile-bar').slideUp(100);
1725    $('#mobile-search-bar').slideToggle(100);
1726}
1727
1728function MobileSearch() {
1729    ShowSmokeLoader();
1730    if ($('#MobileMasterSearchKey').val().length == 0) {
1731        $.smkAlert({ text: 'Please enter a search keyword or choose from one of the suggestions', type: 'warning' });
1732    } else {
1733        var html = "";
1734        var SearchTyped = $('#MobileMasterSearchKey').val().trim().toLowerCase();
1735
1736        $('#MasterSearchInput').html(html);
1737        window.location.href = "/default.aspx?q=" + SearchTyped;
1738    }
1739};
1740
1741function OpenProfile() {
1742    if (localStorage.Token == '' || localStorage.Token == null || localStorage.Token == 'undefined') {
1743        $('#pleaseLogin').html('');
1744        $('#modLogin').modal('show');
1745        $('#modLogin').on('shown.bs.modal', function (e) {
1746            $('.nav-tabs a[href="#ShowLogin"]').tab('show');
1747        });
1748    } else {
1749        $('#mobile-search-bar').slideUp(100);
1750        $('#mobile-info-bar').slideUp(100);
1751        $('#mobile-profile-bar').slideToggle(100);
1752    }
1753    
1754}
1755
1756function DownloadPWA() {
1757
1758}
1759
1760function MobileLogOut() {
1761    localStorage.removeItem('Token');
1762    localStorage.removeItem('Email');
1763    localStorage.removeItem('Name');
1764
1765    localStorage.removeItem('pathURL');
1766    localStorage.removeItem('CurrentT');
1767}
1768
1769function OpenInfo() {
1770    $('#mobile-search-bar').slideUp(100);
1771    $('#mobile-profile-bar').slideUp(100);
1772    $('#mobile-info-bar').slideToggle(100);
1773}
1774
1775function OpenSocialLinks() {
1776    $('#SocialLinks').slideToggle(200);
1777    $('#ContactUsLinks').slideUp(200);
1778    $('#TermsConditionsLinks').slideUp(200);
1779}
1780
1781function OpenContactLinks() {
1782    $('#SocialLinks').slideUp(200);
1783    $('#ContactUsLinks').slideToggle(200);
1784    $('#TermsConditionsLinks').slideUp(200);
1785}
1786
1787function OpenTermsConditionsLinks() {
1788    $('#SocialLinks').slideUp(200);
1789    $('#ContactUsLinks').slideUp(200);
1790    $('#TermsConditionsLinks').slideToggle(200);
1791}
1792
1793function OpenMobileSearchSuggestions(t) {
1794    $(t).parent().next().fadeIn();
1795}
1796
1797function OpenDonateModal() {
1798    $('#modDonationNav').modal('show');
1799    var html = '';
1800    html += '<h4 style="padding: 0 50px; line-height: 30px; text-align: center;">We keep our content free (and ad-free) thanks to donations from our supporters. Writing is hungry work, so if you’re enjoying our site, feel free to donate to our starving journalist fund.</h4>';
1801    $('#donation-text').html(html);
1802}
1803
1804function CheckUserDonations() {
1805    //if (localStorage.DonationMade == undefined || localStorage.DonationMade == null || localStorage.DonationMade == 'false') {
1806    //    var html = '';
1807    //    html += '<h4 style="text-align: center;">Thanks for the coffee.</h4>';
1808    //    html += '<h4 style="text-align: center;">How about buying us dinner as well?</h4>';
1809    //    $('#donation-text').html(html);
1810
1811    //    $('#modDonationNav').modal('show');
1812    //}
1813
1814    $('#divDonationPlease').slideDown(300);
1815}
1816
1817function CheckDonationAmount() {
1818    if ($('#donation-amount').val() == 0 || $('#donation-amount').val() == "") {
1819        $('#btn-payfast').attr('disabled', 'disabled');
1820        $('#btn-payfast').css('cursor', 'not-allowed');
1821    } else {
1822        $('#btn-payfast').attr('disabled', false);
1823        $('#btn-payfast').css('cursor', 'pointer');
1824    }
1825}
1826
1827function DeclineDonation() {
1828    localStorage.DonationMade = true;
1829    $('#modDonationNav').modal('hide');
1830}
1831
1832function ApproveDonation() {
1833    localStorage.DonationMade = true;
1834    var token = "";
1835    if (localStorage.Token == undefined || localStorage.Token == "" || localStorage.Token == null) {
1836        token = "";
1837    } else {
1838        token = localStorage.Token;
1839    }
1840    var InputData = {
1841        Token: token,
1842        IDStory: window.location.pathname.split('/').slice(1)[1],
1843        Amount: $('#donation-amount').val()
1844    }
1845
1846    $.ajax({
1847        type: "POST",
1848        url: APIURI + "user/updatedonation",
1849        data: JSON.stringify(InputData),
1850        contentType: "application/json",
1851        success: function (data) {
1852            if (data.Success == false) {
1853                localStorage.DonationMade = false;
1854            }
1855        },
1856        error: function () {
1857            console.log("Error");
1858        }
1859    })
1860}
1861
1862$("#MasterSearchKey").disableAutoFill();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.