

/*
ajax kérést lekezelő függvény

$ajax_file: a szerveroldali fájl amit meghívunk
$method: a lekérés tipusa, GET vagy POST
$ posts: a küldendő adatok
$targetId : az objektum azonosítója ahova be kell tölteni a választ
$loader: alapértelmezetten true, kell e loader animáció
$loaderImg: ez is alapértelemzett, a loader gif kép
*/

var global_ajax;

function ajaxQuery(ajax_file, method, posts, targetId, loader, loaderImg)
{

	if(typeof loader == "undefined" || typeof loader != "boolean")
	{
		var loader = true;
	}

	
	if(typeof loaderImg == "undefined")
	{
	var loaderImg = "ajax-loader.gif";
	}

var method = method.toUpperCase();

if(method != "GET" && method != "POST")
method = "GET";


var xmlHttp = initAjax();



  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 1)
	{	
		if(loader)
		{
		document.getElementById(targetId).innerHTML = '<img src="images/'+loaderImg+'" />';
		}
	}
	else(xmlHttp.readyState == 4)
	{
	  if(targetId == "return")
	  {
		global_ajax = xmlHttp.responseText;
	  }
	  else
	  {
		document.getElementById(targetId).innerHTML = xmlHttp.responseText;//+'<div style="clear:both;"></div>';
	  }
	}
	
  }



	if(method == "POST")
	{
	xmlHttp.open(method, ajax_file, true);
	xmlHttp.setRequestHeader('content-Type','application/x-www-form-urlencoded;');
	xmlHttp.send(posts);
	}
	else
	{
	xmlHttp.open(method, ajax_file+posts, true);
	xmlHttp.send(null);
	}
	
}



function initAjax()
{

  var xmlHttp;
  
  
	  try
	  {
	    // Firefox, Opera 8.0+, Safari
	    xmlHttp = new XMLHttpRequest();
	  }
	  catch (e)
	  {
		    // Internet Explorer
		    try
			{
		      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		    }
		    catch (e)
			{
			      try
			      {
			        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			      }
			      catch (e)
				  {
			        alert("Your browser does not support AJAX!");
			        return false;
			      }
		    }
	  }
	  return xmlHttp;
}