Event.observe(window, 'load', init, false);

var my_tabs  = null;
var cycle_id = 0;

function init(){
 if($('tournament_filter')){
 	Event.observe('buy_in_from', 'change', ajax_tournament_filter, false);
 	Event.observe('buy_in_to', 'change', ajax_tournament_filter, false);
 	Event.observe('client', 'change', ajax_tournament_filter, false);
 	Event.observe('game_type', 'change', ajax_tournament_filter, false);

 	$('default').firstChild.toggleClassName('image_down');
 }
 if($('alert')){
  new Effect.Highlight('alert');
 }

 if($('tabs')){
  my_tabs = new Control.Tabs('tabs');
  cycle_id = setInterval('cycleTab(my_tabs)', 5000);
  Event.observe('tabs', 'click', function(){
   clearInterval(cycle_id);
  });
 }
 if($('glossary_widget')){
  new Ajax.Autocompleter('glossary_search', 'glossary_results', $F('ajax_url'));
 }
}

function cycleTab(){
 if(my_tabs.activeContainer.id == 'tab_4'){
  my_tabs.first();
 }else{
  my_tabs.next();
 }
}

function ajax_tournament_filter(){
 if($('loader')){
  var myGlobalHandlers = {
   onCreate: function(){
    Element.appear('loader');
   },
   onComplete: function() {
    if(Ajax.activeRequestCount == 0){
     Element.fade('loader');
    }
   }
  };
  Ajax.Responders.register(myGlobalHandlers);
 }

 var myUrl    = $F('ajax_url');
 var myPars   = 'buy_in_from=' + escape($F('buy_in_from')) + '&buy_in_to=' + escape($F('buy_in_to')) + '&client_id=' + escape($F('client')) + '&game_type=' + escape($F('game_type'));
 var myTarget = 'tournaments';
 var myAjax   = new Ajax.Updater(myTarget, myUrl,{method: 'get', parameters: myPars});
}

function createRequestObject(){
	if(navigator.appName == 'Microsoft Internet Explorer'){
		return new ActiveXObject('Microsoft.XMLHTTP');
	}	else{
		return new XMLHttpRequest();
	}
}

function ajax(obj, source){
 var http = createRequestObject();
 http.open('get', source);

 http.onreadystatechange = function(){
 	if(http.readyState == 4){
 		obj.innerHTML = http.responseText;
 	}
 }
	http.send(null);
}

function toggleColumn(obj, table_id, column_nr){
 var cls     = (obj.checked == 'on') ? 'show_cell' : 'hide_cell' ;
	var allRows = document.getElementById(table_id).rows;
	for(var i = 0; i < allRows.length; i++){
	 for(var j = 0; j < allRows[i].cells.length; j++){
 	 if(j == column_nr){
 	  // Workaround for IE to be able to use prototype's toggleClassName
 	  allRows[i].cells[j].id = 'tmp_id';
 	  $('tmp_id').toggleClassName(cls);
 	  allRows[i].cells[j].id = '';
		 }
		}
	}
	toggleCheckboxes();
}

function toggleCheckboxes(){
	var els = $('payment_method_filter').elements;
	var j   = 0;
	for(var i = 0; i < els.length; i++){
		j += (els[i].checked == true) ? 1 : 0 ;
	}
	for(i = 0; i < els.length; i++){
		if(els[i].checked == true && j == 3){
			els[i].disabled = true;
		}else if(els[i].checked == false && j == 5){
		 els[i].disabled = true;
		}else{
		 els[i].disabled = false;
		}
	}
}

function openURL(url){
	document.location.href = url;
}

hs.registerOverlay(
	{
		thumbnailId: null,
		overlayId: 'controlbar',
		position:  'top right',
		hideOnMouseOut: true
	}
);
hs.graphicsDir = 'http://www.maxpokerbonus.nl/highslide/graphics/';
hs.outlineType = 'rounded-white';
hs.captionEval = 'this.thumb.title';
hs.showCredits = false;
window.onload  = function(){
	hs.preloadImages(5);
}

var RecaptchaOptions = {
	theme : 'white',
	lang  : 'nl'
};
