var alertSoundAllow=true;
var auto=60;
var timeout;
(function(){	
		var last_arb_id=0;
		var max_id=0;
		var css_style='wb_10_1';
		window.alertSoundAllowOn=function(){
			alertSoundAllow=true;
			document.getElementById('soundControl').innerHTML='<b>Alert Sound ON (<a href="#" class="wr_12_1" onclick="alertSoundAllowOff();">OFF</a>)</b>';
			return false;
		};
		window.alertSoundAllowOff=function(){
			alertSoundAllow=false;
			document.getElementById('soundControl').innerHTML='<b>Alert Sound OFF (<a href="#" class="wr_12_1" onclick="alertSoundAllowOn();">ON</a>)</b>';
			return false;
		};
		window.plsnd=function () {
			if (alertSoundAllow) {	
				alertSoundObj.play('alertSound');
			}
			return;
		};  		
		window.DataUpdate=function() {
			auto=from_radio(document.arb.auto)||60;
			combo=from_radio(document.arb.combo)||5;
			view=from_checkbox(document.arb.view)||'';
			ops=from_checkbox(document.arb.ops)||'';
			ajax({
				url:"/proc/alert.php",
				post:'combo='+(combo||'')+'&view='+(view||''),
				onStart: function(){
					document.getElementById('refresh').innerHTML='<img src="../img/upd.gif"  height="10" width="100">';
					return false;
				},
				onWait: function(){
					document.getElementById('refresh').innerHTML='<img src="../img/upd.gif"  height="10" width="100">';
					return false;
				},
				onComplete: function(){
					document.getElementById('refresh').innerHTML='<img src="../img/pix.gif"  height="10" width="100">';
					return false;
				},
				onError: function(error_msg){
					alert(error_msg);
					return false;
				},
				onSuccess: function(resp) {
					var MainResp=parseJSON(resp);
					if (MainResp['error']) {
						alert(MainResp['error']);
						window.location.href=document.URL;
					}
					var arb_array=MainResp['arb_array'];					
					var table_head='<table id="t2" width="595" border="0" cellspacing="0" cellpadding="3">';
					table_head+='<tr class="by_12_1"><td><img src="../img/pix.gif"  height="1" width="75"><br><center>Register time</center></td>'+
				    '<td><img src="../img/pix.gif"  height="1" width="75"><br><center>Startup</center></td>'+
				    '<td><img src="../img/pix.gif"  height="1" width="250"><br><center>Event</center></td>'+
				    '<td><img src="../img/pix.gif"  height="1" width="275"><br><center>Odds</center></td>'+
				    '<td><img src="../img/pix.gif"  height="1" width="30"><br><center>%</center></td>'+
				    '<td><img src="../img/pix.gif"  height="1" width="20"><br><center>&nbsp;</center></td>'+
				    '</tr>';	
					var table_footer='</table>';
					var table_inn='';
					
					var css_style='wb_10_2';
					for (var i=0;i<arb_array.length;i++) {
						var arb=new ARB(arb_array[i]);	
						if (!max_id) {
							max_id=arb.id;
						}
						else if (RoundX(max_id)<RoundX(arb.id)) {
							max_id=RoundX(arb.id);
						}
						
						if (RoundX(arb.id)>last_arb_id) {					
							css_style='yb_10_1';
						}
						else {
							css_style=(css_style=='wb_10_1') ? 'wb_10_2' : 'wb_10_1';
						}
						table_inn+=arb.draw(css_style);
					}
					
					if (last_arb_id<max_id) {
						plsnd ();
						if (ops=='y') alert('OOps-s-s!!');
					}
					
					last_arb_id=max_id;
					document.getElementById('alert').innerHTML=table_head+table_inn+table_footer;
					return;
				}
			});
		};		
})();
function doLoadARB() {
	auto=from_radio(document.arb.auto)||60;
	var interval=auto*1000;    
    if (timeout) clearTimeout(timeout);
    timeout = setTimeout("doLoadARB()", interval);
    DataUpdate();
}
