function ajaxCall(url, parameters, responseFunction, responseParameter, async) {
  
if (document.forms.searchform)
    formEnableDisable(document.forms.searchform);
  var url=url+"?"+parameters+"&sid="+Math.random();
  if (ajaxSearch != undefined && ajaxSearch != "") {
    // This is a transfersearch
    if (searchOffset > 0)
      url=url+"&o="+searchOffset;
    url=url+""+ajaxSearch;
  }

  var AC = new ajaxCom();
  AC.setCallUrl(url);
  AC.setResponseFunction(responseFunction);
  AC.setResponseParameter(responseParameter);
//  AC.setAsync(async);
  AC.run();
}

function ajaxPost(url, postdata, responseFunction, responseParameter) {
  var url=url+"?sid="+Math.random();
  var AC = new ajaxCom();
  AC.setCallUrl(url);
  AC.setPostData( postdata );
  AC.setResponseFunction(responseFunction);
  AC.setResponseParameter(responseParameter);
  AC.run("POST");
}

function ajaxCom() {
  this.callUrl           = null;
  this.responseFunction  = null;
  this.responseParameter = null;
  this.xmlHttp           = null;
  this.response          = null;
  this.async						= true;
  this.postData 	    = null;

  this.setCallUrl = function(url) {
    this.callUrl = url;
  }

  this.setResponseFunction = function(responseFunction) {
    this.responseFunction  = responseFunction;
  }

  this.setResponseParameter = function(responseParameter) {
    this.responseParameter  = responseParameter
  }
  this.setPostData = function(data){
    this.postData = data;
  }
  this.setAsync = function(async){
  	if (async != undefined)
    	this.async = async;
  }
  
  this.handleResponse = function() {
    if (this.responseFunction)
      eval(this.responseFunction)(this.xmlHttp.readyState, this.response, this.responseParameter);
  }

  this.createXmlHttpObject = function() {
    var objXMLHttp=null;
    if (window.XMLHttpRequest) {
      objXMLHttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
      objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
  }
  
  this.run = function(method) {
    this.xmlHttp = this.createXmlHttpObject();
    if (this.xmlHttp == null) {
      this.response = "Your browser does not support ajax. Content not loaded.";
      this.handleResponse();
      return;
    }
    else {
    	if (this.async) {
		      var self = this;
		    
		      this.xmlHttp.onreadystatechange = function() {
		        if (self.xmlHttp.readyState == 4 || self.xmlHttp.readyState == "complete") {
		          self.response = self.xmlHttp.responseText;
		          self.handleResponse();
		        }
		        else
		          self.handleResponse();
	    	  }
      }
      if ( typeof(method) !== undefined && method == "POST" ) {
				this.xmlHttp.open("POST", this.callUrl, this.async );
				this.xmlHttp.setRequestHeader("Method", "POST " + this.callUrl + " HTTP/1.1");
				this.xmlHttp.setRequestHeader("If-Modified-Since", "Thu, 01 Mar 2007");
				this.xmlHttp.send(this.postData);
      } else
      {
     	  this.xmlHttp.open("GET",this.callUrl,this.async);
	   		this.xmlHttp.send(null);
	   		if (this.async==false) {
					this.response = this.xmlHttp.responseText;
					this.handleResponse();
	   		}
      }
    }
  }
}

var ajaxSearch;
var searchOffset = 0;

function formEnableDisable(searchForm) {
  if (searchForm.category.selectedIndex > 0 || searchForm.u.value > 0)
    onoff = "true";
  else
    onoff = "";
  inputs = searchForm.getElementsByTagName('input');
  for(i=0;i<inputs.length; i++) {
    inp = inputs[i];
    if (inp.name != "u")
      inp.disabled = onoff;
  }
  inputs = searchForm.getElementsByTagName('select');
  for(i=0;i<inputs.length; i++) {
    inp = inputs[i];
    if (inp.name != "category")
      inp.disabled = onoff;
  }
}

function submitAjaxSearch(searchForm) {
  var str = "";
  var inputs = searchForm.getElementsByTagName('input');

  if (searchForm.category.selectedIndex == 0) {
    for(i=0;i<inputs.length; i++) {
      inp = inputs[i];
      val = encodeURIComponent(inp.value);
      if (inp.type == "checkbox") {
        if (inp.checked) {
          str += "&"+ inp.name +"="+ val;
        }
      }
      else if (inp.type == "text") {
        str += "&"+ inp.name +"="+ val;
      }
      else if (inp.type == "hidden") {
        str += "&"+ inp.name +"="+ val;
      }
    }

    inputs = searchForm.getElementsByTagName('select');
    for(i=0;i<inputs.length; i++) {
      inp = inputs[i];
      val = encodeURIComponent(inp.value);
      if (inp.type == "select-one") {
        str += "&"+inp.name +"="+ val;
      }
    }

  }
  else if (searchForm.category.selectedIndex > 0) {
    str = searchForm.category.value;
  }

  if (str.length > 0 && str.substr(0,1) == "&") {
    ajaxSearch = str;
    error_content = "";
    searchOffset = 0;
    clearTransferSearch();
    window.setTimeout("ajaxCall('ajax_com/com.php','val=getTransferSearch&sport='+ajaxSport, 'prepareTransferData', '')", 100);
  } else
    ajaxSearch = "";
}

function ajaxUpdateSearchOffset(o) {
  pagediv = document.getElementById('searchPages');
  if (pagediv) {
    pages = 10;
    current = parseInt(o/20);

    min = current-5;
    if (min < 0)
      min = 0;
    max = min+10;
    if (max > pages) {
      max = pages;
      min = max-10;
    }
    if (min < 0)
      min = 0;

    window_content = "";
    if (o > 0)
      window_content += "<a href=\"#\" onClick=\"scroll(0,0); ajaxSearchOffset("+ (o-20) +"); return false;\">"+ strPrev +"</a> &nbsp;";

    for (i = min; i < max-1; i++) {
      min_display = i+1;

      if (i == current)
        window_content += "<b>"+ min_display +"</b> &nbsp;";
      else if (thePlayers.length >= 20)
        window_content += "<a href=\"#\" onClick=\"scroll(0,0); ajaxSearchOffset("+ (i*20) +"); return false;\">"+ min_display +"</a> &nbsp;";
    }

    if (o+20 < 200 && thePlayers.length >= 20)
      window_content += "<a href=\"#\" onClick=\"scroll(0,0); ajaxSearchOffset("+ (o+20) +"); return false;\">"+ strNext +"</a>";

    pagediv.innerHTML = window_content;
  }
}

function ajaxSearchOffset(o) {
  searchOffset = o;
  clearTransferSearch();
  window.setTimeout("ajaxCall('ajax_com/com.php','val=getTransferSearch&sport='+ajaxSport, 'prepareTransferData', '')", 100);
}

function writeLayer(readyState, response, responseParameter) {
  //alert(responseParameter +":"+ response);
  if (readyState == 4) {
    document.getElementById(responseParameter).innerHTML=response;
  }
}


function prepareTransferData(readyState, response, responseParameter) {
  if (readyState == 4) {
    eval(response);
    renderPlayerAjaxHtml();
    ajaxUpdateSearchOffset(searchOffset);
  }
}


function doNothing(readyState, response, responseParameter) {}

/**
* Shows a loading animation and if responseFunction == "writeLayer" it replaces the contents of the lightbox with the reply of the ajax call.
* To avoid breaking something responseParameter has to be omitted for this to take action.
*/
function ajaxCallLightboxLoading_OLD(url, parameters, responseFunction, responseParameter) {

	var id = "";
	if(responseFunction == "writeLayer" && responseParameter == null) {
		id = "lightboxLoadingTable" + currentLightBoxid;
		responseParameter = id;
	}
	
  body = "<span id='"+id+"'><table width='435'><tr><td align=center><img src=\"img/ajax_loader.gif\" alt=\"Loading\" width=\"16\" height=\"16\"></td></tr></table></span>";
  lightboxInit();
  lightboxShow(450, ["", "closebutton", "notitle"], body, "", "", "", "", "");
  lightboxSetPosY(90);
	
  ajaxCall(url, parameters, responseFunction, responseParameter);
}

function ajaxLoaderControl(type,status)
{
  if (document.getElementById("ajax_loader_"+type)) {
    if (status == undefined)
      status = "none";
    document.getElementById("ajax_loader_"+type).style.display = status;
    return true;
  }
  return false;
}

