function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
        xmlhttp = false;
        }
      }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      xmlhttp = false;
      }
    }
  return xmlhttp;
  }
var apendia_http = 0;
apendia_curent_do=0;
apendia_curent_wait=0;
apendia_array=new Array();
function apendia_in_queue(keyed)
	{
	if(keyed=='') return true;
	for(i=apendia_curent_do+1;i<apendia_curent_wait+1;i++)
		{
		if(apendia_array[i][3]==keyed) return false;
		}
	return true;
	}
apendia_http = getHTTPObject();
function apendia_ajax_get(url,function_name,params,keyed)
	{
	if(apendia_in_queue(keyed))
		{
		// alert(keyed);
		apendia_curent_wait++;
		apendia_array[apendia_curent_wait] = new Array;
		apendia_array[apendia_curent_wait][0]=url;
		apendia_array[apendia_curent_wait][1]=function_name;
		apendia_array[apendia_curent_wait][2]=params;
		apendia_array[apendia_curent_wait][3]=keyed;
		if(apendia_curent_do==apendia_curent_wait-1) apendia_launch();
		}
	}
function apendia_launch()
	{	
	cur=apendia_curent_do+1;
	// alert(apendia_array[cur][0]);
	apendia_http.open("GET", apendia_array[cur][0] ,true); 
	apendia_http.setRequestHeader("charset", "iso-8859-1");
	apendia_http.onreadystatechange = apendia_send;  
	apendia_http.send(null);			
	}

function apendia_alert(v,v2)
	{
	// this is just an exemple !
	alert(v);
	}

function apendia_send()
	{		
	if (apendia_http.readyState == 4) {
		if( apendia_http.responseText!='' )
			{
			apendia_curent_do++;
			eval(apendia_array[apendia_curent_do][1]+"(apendia_http.responseText,apendia_array[apendia_curent_do][2])");
			// still ajax in queue 
			if(apendia_curent_do<apendia_curent_wait) apendia_launch();
			// no more ajax in queue , reset
			if(apendia_curent_do==apendia_curent_wait) 
				{
				// reset when nothing to do
				apendia_curent_do=0;
				apendia_curent_wait=0;
				apendia_http = getHTTPObject();
				}
			}
		}			
	}
	
// this is just an exemple !
    function apendia_unserialize(input)
    {
        var result = apendia_unserialize_(input);
		// alert(result.length);
        return result[0];
    }


    /**
    * Function which performs the actual unserializing
    *
    * @param string input Input to parse
    */
    function apendia_unserialize_(input)
    {
        var length = 0;

        switch (input.charAt(0)) {
            /**
            * Array
            */
            case 'a':
                length = apendia_unserialize_getlength(input);
                input  = input.substr(String(length).length + 4);

                var arr   = new Array();
                var key   = null;
                var value = null;

                for (var i=0; i<length; ++i) {
                    key   = apendia_unserialize_(input);
                    input = key[1];

                    value = apendia_unserialize_(input);
                    input = value[1];

                    arr[key[0]] = value[0];
                }

                input = input.substr(1);
                return [arr, input];
                break;
            
            /**
            * Objects
            */
            case 'O':
                length = apendia_unserialize_getlength(input);
                var classname = String(input.substr(String(length).length + 4, length));
                
                input  = input.substr(String(length).length + 6 + length);
                var numProperties = Number(input.substring(0, input.indexOf(':')))
                input = input.substr(String(numProperties).length + 2);

                var obj      = new Object();
                var property = null;
                var value    = null;

                for (var i=0; i<numProperties; ++i) {
                    key   = apendia_unserialize_(input);
                    input = key[1];
                    
                    // Handle private/protected
                    key[0] = key[0].replace(new RegExp('^\x00' + classname + '\x00'), '');
                    key[0] = key[0].replace(new RegExp('^\x00\\*\x00'), '');

                    value = apendia_unserialize_(input);
                    input = value[1];

                    obj[key[0]] = value[0];
                }

                input = input.substr(1);
                return [obj, input];
                break;

            /**
            * Strings
            */
            case 's':
                length = apendia_unserialize_getlength(input);
                return [String(input.substr(String(length).length + 4, length)), input.substr(String(length).length + 6 + length)];
                break;

            /**
            * Integers and doubles
            */
            case 'i':
            case 'd':
                var num = Number(input.substring(2, input.indexOf(';')));
                return [num, input.substr(String(num).length + 3)];
                break;
            
            /**
            * Booleans
            */
            case 'b':
                var bool = (input.substr(2, 1) == 1);
                return [bool, input.substr(4)];
                break;
            
            /**
            * Null
            */
            case 'N':
                return [null, input.substr(2)];
                break;

            /**
            * Unsupported
            */
            case 'o':
            case 'r':
            case 'C':
            case 'R':
            case 'U':
                alert('Error: Unsupported PHP data type found!');

            /**
            * Error
            */
            default:
                return [null, null];
                break;
        }
    }
    

    /**
    * Returns length of strings/arrays etc
    *
    * @param string input Input to parse
    */
    function apendia_unserialize_getlength(input)
    {
        input = input.substring(2);
        var length = Number(input.substr(0, input.indexOf(':')));
        return length;
    }
