function Class_Conn()
{
   this.data       = null;
   this.url        = "";
   this.params     = "";
   this.whenDone   = null;
	var this_reffer = this;
	
   
   /**
    * @private   
    * Ajaxova zadost
    */       
   this.start = function ()
   {
      this.ready = false;
      
      this.connect(this.url, "POST", this.params, this.whenDone, this);
   };

   /**
    * @private   
    * Pozmeneny XHConn
    * Po dokonceni zavola fnDone(httpResponse, param)
    *         
    * @param {string}   sURL       url    
    * @param {string}   sMethod    POST|GET
    * @param {string}   sVars      url vars
    * @param {function} fnDone     funkce po nacteni, parametr 1 - httpResponse
    * @param {string}   param      2. parametr volane funkce     
    * @author http://xkr.us/code/javascript/XHConn/
    */
   this.connect = function (sURL, sMethod, sVars, fnDone, param) // http://xkr.us/code/javascript/XHConn/
   {
      var xmlhttp, bComplete;
   	bComplete = false;
   	
   	/**
   	 * XMLHttpRequest
   	 */          	
      xmlhttp = false;

      if (window.XMLHttpRequest)
      {
         xmlhttp = new XMLHttpRequest();
      }
      else if (window.ActiveXObject)
      {
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
 	   
   	if (!xmlhttp)
      {
         return null;
      }
      
      if (!xmlhttp)
      {
         return false;
      }
      if (!param)
      {
         param = this_reffer;
      }
      bComplete = false;
      sMethod = sMethod.toUpperCase();
      
      try
      {
         if (sMethod === "GET")
         {
            xmlhttp.open(sMethod, sURL + "?" + sVars, true);
            sVars = "";
         }
         else
         {
            xmlhttp.open(sMethod, sURL, true);
            xmlhttp.setRequestHeader("Method", "POST " + sURL + " HTTP/1.1");
            xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
         }

         /**
          * @private
          * Pri zmene stavu udalosi
          */
         xmlhttp.onreadystatechange = function ()
         {
            if (xmlhttp.readyState === 4 && !bComplete)
            {
               if (xmlhttp.status === 200)
               {
                  bComplete = true;
                  fnDone(xmlhttp, param);
               }
               else if (xmlhttp.status === 403)
               {
                  alert(403);
               }
               else if (xmlhttp.status === 404)
               {
                  alert(xmlhttp.status+':Server je v pr*eli');
               }
               else
               {
                  alert(xmlhttp.status);
               }
            }
         };
         xmlhttp.send(sVars);
      }
      catch (z)
      {
         alert('HttpRequest error Ex001');
         return false;
      }
      return true;
   };

   /**
    * @private
    * @function       
    * Vrati bezpecny json
    * @param {string} json  vstupni json
    * @return               bezpecny json  
    */   
   this.json_parse = (function () // http://www.json.org/json_parse.js
   {
      var at,     // The index of the current character
      ch,     // The current character
      escapee =
      {
         '"':  '"',
         '\\': '\\',
         '/':  '/',
         b:    '\b',
         f:    '\f',
         n:    '\n',
         r:    '\r',
         t:    '\t'
      },
      text,
      
      error = function (m)
      {
         // Call error when something is wrong.
         
         throw {
               name:    'SyntaxError',
               message: m,
               at:      at,
               text:    text
            };
      },

      
      next = function (c)
      {
         if (c && c !== ch)
         {
            error("Expected '" + c + "' instead of '" + ch + "'");
         }
         
         ch = text.charAt(at);
         at += 1;
         return ch;
      },
      
      number = function ()
      {
         var number,
         string = '';
         
         if (ch === '-')
         {
            string = '-';
            next('-');
         }
         while (ch >= '0' && ch <= '9')
         {
            string += ch;
            next();
         }
         
         if (ch === '.')
         {
            string += '.';
            while (
               next() && ch >= '0' && ch <= '9')
            {
               string += ch;
            }
         }
         
         if (ch === 'e' || ch === 'E')
         {
            string += ch;
            next();
            
            if (ch === '-' || ch === '+')
            {
               string += ch;
               next();
            }
            
            while (ch >= '0' && ch <= '9')
            {
               string += ch;
               next();
            }
         }
         
         number = +string;
         if (isNaN(number))
         {
            error("Bad number");
         }
         else
         {
            return number;
         }
      },
      
      string = function ()
      {
         var hex,
         i,
         string = '',
         uffff;
         
         if (ch === '"')
         {
            while (next())
            {
               if (ch === '"')
               {
                  next();
                  return string;
               }
               else if (ch === '\\')
               {
                  next();
                  if (ch === 'u')
                  {
                     uffff = 0;
                     for (i = 0; i < 4; i += 1)
                     {
                        hex = parseInt(next(), 16);
                        if (!isFinite(hex))
                        {
                           break;
                        }
                        uffff = uffff * 16 + hex;
                     }
                     string += String.fromCharCode(uffff);
                  }
                  else if (typeof escapee[ch] === 'string')
                  {
                     string += escapee[ch];
                  }
                  else
                  {
                     break;
                  }
               }
               else
               {
                  string += ch;
               }
            }
         }
         error("Bad string");
      },
      
      white = function ()
      {
         while (ch && ch <= ' ')
         {
            next();
         }
      },
      
      word = function ()
      {
         switch (ch)
         {
         case 't':
            next('t');
            next('r');
            next('u');
            next('e');
            return true;
         case 'f':
            next('f');
            next('a');
            next('l');
            next('s');
            next('e');
            return false;
         case 'n':
            next('n');
            next('u');
            next('l');
            next('l');
            return null;
         }
         error("Unexpected '" + ch + "'");
      },
      
      value,
      
      array = function ()
      {
         var array = [];
         
         if (ch === '[')
         {
            next('[');
            white();
            if (ch === ']')
            {
               next(']');
               return array;   // empty array
            }
            while (ch)
            {
               array.push(value());
               white();
               if (ch === ']')
               {
                  next(']');
                  return array;
               }
               next(',');
               white();
            }
         }
         error("Bad array");
      },
      
      object = function ()
      {
            
         var key,
         object = {};
         
         if (ch === '{')
         {
            next('{');
            white();
            if (ch === '}')
            {
               next('}');
               return object;   // empty object
            }
            while (ch)
            {
               key = string();
               white();
               next(':');
               if (Object.hasOwnProperty.call(object, key))
               {
                  error('Duplicate key "' + key + '"');
               }
               object[key] = value();
               white();
               if (ch === '}')
               {
                  next('}');
                  return object;
               }
               next(',');
               white();
            }
         }
         error("Bad object");
      };
      
      value = function ()
      {
         white();
         switch (ch)
         {
         case '{':
            return object();
         case '[':
            return array();
         case '"':
            return string();
         case '-':
            return number();
         default:
            return ch >= '0' && ch <= '9' ? number() : word();
         }
      };
      
      return function (source, reviver)
      {
         var result;
         
         text = source;
         at = 0;
         ch = ' ';
         result = value();
         white();
         if (ch)
         {
            error("Syntax error");
         }
         
         return typeof reviver === 'function' ? (function walk(holder, key)
         {
            var k, v, value = holder[key];
            if (value && typeof value === 'object')
            {
               for (k in value)
               {
                  if (Object.hasOwnProperty.call(value, k))
                  {
                     v = walk(value, k);
                     if (v !== undefined)
                     {
                        value[k] = v;
                     }
                     else
                     {
                        delete value[k];
                     }
                  }
               }
            }
            return reviver.call(holder, key, value);
         }({'': result}, '')) : result;
      };
   }());
}
