
g_helptexts = new Array();


function ajaxObject(url, callbackFunction) 
{
  var that=this;   
  this.updating = false;
  this.abort = function() 
  {
    if (that.updating) {
      that.updating=false;
      that.AJAX.abort();
      that.AJAX=null;
    }
  }
  this.update = function(passData,postMethod) 
  { 
    if (that.updating) { return false; }
    that.AJAX = null;                          
    if (window.XMLHttpRequest) 
	{              
      that.AJAX=new XMLHttpRequest();              
    } 
	else 
	{                                  
      that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
    }                                             
    if (that.AJAX==null) 
	{
      return false;                               
    }
	else 
	{
      that.AJAX.onreadystatechange = function() 
	  {  
        if (that.AJAX.readyState==4) 
		{             
          that.updating=false;                
          that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
          that.AJAX=null;                                         
        }                                                      
      }                                                        
      that.updating = new Date();                              
      if (/post/i.test(postMethod)) 
	  {
        var uri=urlCall+'?'+that.updating.getTime();
        that.AJAX.open("POST", uri, true);
        that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        that.AJAX.setRequestHeader("Content-Length", passData.length);
        that.AJAX.send(passData);
      } 
	  else 
	  {
        var uri=urlCall+'?'+passData; //+'&timestamp='+(that.updating.getTime()); 
        that.AJAX.open("GET", uri, true);                             
        that.AJAX.send(null);                                         
      }              
      return true;                                             
    }                                                                           
  }
  var urlCall = url;        
  this.callback = callbackFunction || function () { };
}

function createIndex(help_category, help_title)
{
	return help_category + help_title;
}

function loadHelp(object_id, help_category, help_title)
{
	if(help_category == "unit_def_id")
	{
		var newRequest = new ajaxObject('./unitinfo.php');
		var requestString = 'unit_def_id=' + help_title;
	}
	else
	{
		var newRequest = new ajaxObject('./help.php');
		var requestString = 'help_category=' + help_category + '&help_title=' + help_title;
	}
	newRequest.request_object_id = object_id;

	newRequest.callback = function(responseText) 
	{
		var index = createIndex(help_category, help_title);
		g_helptexts[index] = "<br/>" + responseText;
		
		document.getElementById(this.request_object_id).innerHTML = "<br/>" + responseText;
	}
	
	working = newRequest.update(requestString, 'POST');
	
	if(!working)
		document.getElementById(this.request_object_id).innerHTML="<br/>Error: Can't load item.";
}

function showHelpText(object_id, help_category, help_title)
{
	var index = createIndex(help_category, help_title);
	if(! g_helptexts[index])
	{
		document.getElementById(object_id).innerHTML="<br/><img src='./images/loading.gif'>";
		loadHelp(object_id, help_category, help_title);		
	}
	else
	{
		document.getElementById(object_id).innerHTML=g_helptexts[index];
	}
}

function showHideHelp(object_id, help_category, help_title)
{
	if(document.getElementById(object_id).innerHTML=="")
	{
		showHelpText(object_id, help_category, help_title);
	}
	else
	{
		document.getElementById(object_id).innerHTML="";
		
		if(tooltip != null)
			tooltip.hide();
	}
}
/*
function mse_over(obj)
{
	obj.style.color="#8556C4";
}
function mse_out(obj)
{
	obj.style.color="#ffffff";
}



function addStuff(object_id)
{	
	document.getElementById(object_id).innerHTML = "<br/><br/>bla bla bla <br/> und mehr bla";
	
}

function test()
{
	alert("test");
}
*/

