function autoCheckAlertsPopupTimer(){for(var b=0;b<alertTypes.length;b++){currentEventAlerts[alertTypes[b]]=""}setAlertPopupTimer(false,"");var a=1000;setInterval(function(){setAlertPopupTimer(false,"")},a)}function setAlertPopupTimer(f,A){var y=0;var w=0;var o="";var a=new Array();var p=new Array();var m=new Array();var l=new Array();var v=new Array();var x=new Array();var q=false;if(A==""){a=alertTypes}else{a.push(A)}if(!appears_logged_in()){for(y=0;y<alertTypesLoginNeeded.length;y++){_deleteFromAlertsCookie(alertTypesLoginNeeded[y]);_hideAlertPopup(alertTypesLoginNeeded[y])}}var c="";try{c=get_cookie("ALERTS")}catch(g){}if(c==""){return}var b=c.split("|");if(alertServerTime==parseInt(b[0])&&!f){var h=new Array();var r=new Array();var k=new Array();var B=a;a=new Array();for(y=0;y<B.length;y++){h=new Array();r=new Array();k=new Array();m=_getAlertPopupData(b,B[y]);h=m[0];r=m[1];k=m[2];temp_found_alert_types=m[3];if(h[B[y]]!=currentEventAlerts[B[y]]){f=true;q=true;a.push(B[y]);if(temp_found_alert_types.length>0){p.push(B[y])}l[B[y]]=h[B[y]];v[B[y]]=r[B[y]];x[B[y]]=k[B[y]]}}if(!f){return}}if(parseInt(b[0])>alertServerTime){alertServerTime=parseInt(b[0])}else{if(parseInt(b[0])<alertServerTime){b[0]=alertServerTime;set_cookie("ALERTS",b.join("|"),"","/")}else{}}var n=_getAlertTypesWithActivePopups();for(y=0;y<n.length;y++){for(w=0;w<a.length;w++){if(a[w]==n[y]){a.splice(w,1)}}}if(a.length==0){return}_clearAlertTimeouts(a);for(y=0;y<a.length;y++){switch(a[y]){case"C":var e=parseInt(new Date().getTime()/1000);var s=parseInt(b[1])-e;if(s>0){var u=alertServerTime+(e-alertLocalTime)+s;var d=_scrapEventsBeforeActivationTime(u,a[y]);if(d){setAlertPopupTimer(f,A);return}}break;default:}}if(!q){m=_getAlertPopupData(b,a);l=m[0];v=m[1];x=m[2];p=m[3]}for(y=0;y<p.length;y++){var t=function(j,i){return function(){_queueAlertPopup(j,i)}}(l[p[y]],p[y]);var z=parseInt(x[p[y]])*1000;alertTimer[A]=setTimeout(t,z);currentEventAlerts[p[y]]=l[p[y]]}return}function addRemoveEventAlert(c,d,a,b){var e=true;switch(b){case"add":_addEventAlert(c,d,a);break;case"remove":_removeEventAlert(c,a);break;default:}return}function _addEventAlert(c,f,b){var g=get_cookie("ALERTS");var a=g.split("|");if(a.length==0){a[0]=0;a[1]=0}var d=4;var e=false;for(d=4;d<a.length;d=d+3){if(parseInt(a[d-1])>parseInt(f)){a.splice(d-2,0,c,f,b);e=true;break}}if(!e){a.push(c,f,b)}set_cookie("ALERTS",a.join("|"),"","/");return}function _removeEventAlert(c,b){var e=get_cookie("ALERTS");var a=e.split("|");var d=4;var f=false;for(d=4;d<a.length;d=d+3){if(a[d]==b&&a[d-2]==c){a.splice(d-2,3);f=true;break}}if(f){set_cookie("ALERTS",a.join("|"),"","/");setAlertPopupTimer(true,b)}return}function checkForEventInAlertCookie(d,c){var b=false;var f=get_cookie("ALERTS");var a=f.split("|");var e=4;for(e=4;e<a.length;e=e+3){if(a[e]==c&&a[e-2]==d){b=true;break}}return b}function _queueAlertPopup(c,a){var b=new Array();b.push(c,a);alertsQueue.push(b);if(alertsQueue.length<2){_queueAlertPopupPoll()}}function _queueAlertPopupPoll(){if(alertsQueue.length>0){if(alertsQueueProcessing==0){alertsQueueProcessing=1;var b=alertsQueue[0];var c=b[0];var a=b[1];_openAlertPopup(c,a);alertsQueue.shift();alertsQueueProcessing=0;_queueAlertPopupPoll()}else{setTimeout(_queueAlertPopupPoll,100)}}}function _openAlertPopup(d,b){var a={id:"alert_popup_"+b,retries:3};var c="";if(document.location.protocol=="http:"){c=alertTypeCGIUrls[b]}else{c=alertTypeSCGIUrls[b]}c=c+"?action=goAlertPopup&ev_id_list="+d+"&alert_type="+b;_getAlertMakeAjaxRequest(c,a,_getAlertGotAjaxContent)}function doAlertButtonAction(c,a,d,f,b,e){switch(c){case"Close":if(e){ntptEventTag("ev="+b+"_B2vAlert&button=B2vAlert-Close&buttonevent=click")}closeAlertPopup("Never",a,d);break;case"Never":if(e){ntptEventTag("ev="+b+"_B2vAlert&button=B2vAlert-Never&buttonevent=click")}closeAlertPopup("Never",a,d);break;case"ghShow":if(e){ntptEventTag("ev="+b+"_B2vAlert&button=B2vAlert-Watch&buttonevent=click")}closeAlertPopup("Show",a,d);open_etote_window();break;case"rpShow":if(e){ntptEventTag("ev="+b+"_B2vAlert&button=B2vAlert-Watch&buttonevent=click")}closeAlertPopup("Show",a,d);open_rp_window(f);break;case"atrShow":if(e){ntptEventTag("ev="+b+"_B2vAlert&button=B2vAlert-Watch&buttonevent=click")}closeAlertPopup("Show",a,d);open_atr_window(f);break;case"OK":if(e){ntptEventTag("ev="+b+"_B2vAlert&button=B2vAlert-OK&buttonevent=click")}closeAlertPopup("Show",a,d);break}}function closeAlertPopup(c,b,f){var e=f.split("|");currentEventAlerts[b]="";var d=document.getElementById("alert_popup_"+b);if(d){d.style.display="none"}switch(b){case"B":set_pref("B2V_ALERT_POPUP",((c=="Keephidden")?"Show":c));break;default:}var h=true;switch(c){case"Never":_deleteFromAlertsCookie(b);h=false;break;case"Deactivate":setAlertDeactivationPeriod();break;case"Keephidden":document.getElementById("start-evt-info").style.display="none";case"Show":break;default:}if(h){_markEventAsViewed(b,e)}var g=parseInt(new Date().getTime()/1000);var a=g-alertLocalTime;alertServerTime=alertServerTime+a;alertLocalTime=g;if(h){setAlertPopupTimer(true,b)}}function setAlertDeactivationPeriod(){var c=parseInt(new Date().getTime()/1000);var b=c+parseInt(alert_deactivation_time_option);var d=get_cookie("ALERTS");var a=d.split("|");a[1]=b;set_cookie("ALERTS",a.join("|"),"","/")}function _deleteFromAlertsCookie(c){var e=get_cookie("ALERTS");if(e==""){return}var a=e.split("|");var b=new Array();b.push(a[0]);b.push(a[1]);for(var d=4;d<a.length;d=d+3){if(a[d]!=c){b.push(a[d-2]);b.push(a[d-1]);b.push(a[d])}}set_cookie("ALERTS",b.join("|"),"","/")}function _clearAlertTimeouts(a){for(var b=0;b<a.length;b++){if(alertTimer[a[b]]&&alertTimer[a[b]]!=""){clearTimeout(alertTimer[a[b]])}}}function _hideAlertPopup(a){var b=document.getElementById("alert_popup_"+a);if(b){b.style.display="none"}}function _hideAllAlertPopups(){var a="";for(var b=0;b<alertTypes.length;b++){_hideAlertPopup(alertTypes[b])}}function _getAlertTypesWithActivePopups(){var c=new Array();for(var b=0;b<alertTypes.length;b++){var a=document.getElementById("alert_popup_"+alertTypes[b]);if(a&&a.style.display!="none"){c.push(alertTypes[b])}}return c}function _getAlertPreviewTime(a){var b=0;if(alertTypePreviewTime[a]){b=alertTypePreviewTime[a]}return b}function _markEventAsViewed(c,f){var b=false;var g=get_cookie("ALERTS");var a=g.split("|");var e=4;var d=0;for(e=4;e<a.length;e=e+3){if(a[e]==c&&a[e-1].indexOf("#")<0){for(d=0;d<f.length;d++){if(a[e-2]==f[d]){a[e-1]="#"+a[e-1];b=true}}}}if(b){set_cookie("ALERTS",a.join("|"),"","/")}}function _scrapEventsBeforeActivationTime(f,c){var b=false;var e=get_cookie("ALERTS");var a=e.split("|");var d=4;for(d=4;d<a.length;d=d+3){if(a[d]==c&&a[d-1].indexOf("#")<0){if(parseInt(a[d-1])<parseInt(f)){a[d-1]="#"+a[d-1];b=true}}}if(b){set_cookie("ALERTS",a.join("|"),"","/")}return b}function _getAlertPopupData(l,p){var a=new Array();var e=new Array();var s=false;var g=false;var c=false;var n=true;var h=0;var f=0;for(h=4;h<l.length;h=h+3){if(n&&a.length==p.length){break}if(l[h-1].indexOf("#")<0){s=false;for(f=0;f<p.length;f++){if(p[f]==l[h]){s=true;break}}if(!s){continue}g=false;for(f=0;f<groupable_alert_types.length;f++){if(groupable_alert_types[f]==l[h]){g=true;n=false;break}}c=false;for(f=0;f<a.length;f++){if(a[f]==l[h]){c=true;break}}if(c){if(!g){continue}else{if(parseInt(e[l[h]][1])+parseInt(alert_time_grouping)<parseInt(l[h-1])){continue}}}else{a.push(l[h]);e[l[h]]=new Array()}e[l[h]].push(l[h-2]);e[l[h]].push(parseInt(l[h-1]))}}var b=0;var m="";var k="";var r=new Array();var q=new Array();var o=new Array();var d=0;for(h=0;h<p.length;h++){r[p[h]]="";q[p[h]]=""}for(h=0;h<a.length;h++){b=alertServerTime+5+parseInt(_getAlertPreviewTime(a[h]));d=random_timeout=Math.floor(Math.random()*alertPopupTimeWindow);b=b+d;b=parseInt(e[a[h]][1])-b;if(b<=0){b=1}if(b>86400){continue}m="";k="";for(f=0;f<e[a[h]].length;f=f+2){if(m==""){m=e[a[h]][f]}else{m=m+"|"+e[a[h]][f]}if(k==""){k=e[a[h]][f+1]}else{k=k+"|"+e[a[h]][f+1]}}r[a[h]]=m;q[a[h]]=k;o[a[h]]=b}return[r,q,o,a]}function _getAlertMakeAjaxRequest(b,a,f){if(betlive_busy_sem==1){setTimeout(function(){_getAlertMakeAjaxRequest(b,a,f)},300);return}betlive_busy_sem=1;var c=null;if(window.XMLHttpRequest){c=new XMLHttpRequest()}else{if(window.ActiveXObject){c=new ActiveXObject("Microsoft.XMLHTTP")}}if(c){c.onreadystatechange=function(){if(c.readyState!=4){return}var g;try{g=c.status}catch(h){g=""}if(g!=200){betlive_busy_sem=0;f(b,a,false,"HTTP")}else{betlive_busy_sem=0;f(b,a,true,c.responseText)}};try{c.open("GET",b,true);c.send(null)}catch(d){betlive_busy_sem=0;f(b,a,false,"UNSUPPORTED")}}else{betlive_busy_sem=0;f(b,a,false,"UNSUPPORTED")}}function positionBetAlert(c){c.style.display="block";c.style.position="fixed";var b="";var d="";if(self.innerHeight){b=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){b=document.documentElement.clientHeight}else{if(document.body){b=document.body.clientHeight}}}var a=document.getElementById("start-evt-info").clientHeight;var e=(b-a)+"px";c.style.top=e}function _getAlertGotAjaxContent(c,a,d,b){var f=document.getElementById(a.id);if(d){if(b==""){return}var h=_getAlertParseScriptTags(b);if(f){f.innerHTML=h[0];if(a.id=="alert_popup_C"){positionBetAlert(f)}else{f.style.display=""}}if(a.id=="alert_popup_C"){window.onresize=function(){positionBetAlert(f)}}if(h[1].length){try{_getAlertGlobalEval(h[1])}catch(g){d=false}}}}function _getAlertParseScriptTags(g){var c="";var e="";var b=0;var d="HTML";var f=new RegExp("<(/?)script([^>]*)>","gi");while((mtch=f.exec(g))!=null){mS=mtch.index;if(d=="HTML"){c+=g.substring(b,mS)}else{e+=g.substring(b,mS)+";\n"}var h=mtch[1];var a=mtch[2];if(h=="/"){d="HTML"}else{if(a.charAt(a.length-1)!="/"&&a.indexOf("src=")==-1){d="JS"}}b=f.lastIndex}if(d=="HTML"){c+=g.substring(b)}else{e+=g.substring(b)}return[c,e]}var _getAlertGlobalEval=function(src){if(window.execScript){window.execScript(src);return}var fn=function(){window.eval.call(window,src)};fn()};
