
/*Attention dans la fct GetAspNetCookie utilisation de la librairie prototype*/
Type.registerNamespace('Utils');

Utils.CookieManager = function(element) 
{
    
}

Utils.CookieManager.prototype =
{
    GetCookie: function (name) 
   {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) 
      {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return this.getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break; 
      }
   return null;
   },
   
   GetAspNetCookie: function(name , key)
   {
        var currentCookie = this.GetCookie(name);
        if (currentCookie != null)
        {
            var allKeys = currentCookie.split('&');
            for (var i = 0; i < allKeys.size(); i++)
            {
                var currentKey = allKeys[i].split('=');
                if (currentKey[0] === key)
                    return currentKey[1];
            }
        }
        return null;
   }, 
    
    /*Argument: 'cookieName', 'value', 'expiresDate', 'path', 'domain', 'secure'*/
    SetCookie: function () 
   {
   var argv = this.SetCookie.arguments;
   var argc = this.SetCookie.arguments.length;
   var cookieName = (argc > 0) ? argv[0] : null;
   var value = (argc > 1) ? argv[1] : null;
   var expires = (argc > 2) ? argv[2] : null;
   var path = (argc > 3) ? argv[3] : null;
   var domain = (argc > 4) ? argv[4] : null;
   var secure = (argc > 5) ? argv[5] : false;
   document.cookie = cookieName + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
   },

     getCookieVal : function(offset) 
   {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
   },

 DeleteCookie: function (name) 
   {
   var exp = new Date();
   exp.setTime (exp.getTime() - 1000000000);  // This cookie is history (changed -1 to make it previous time)
   var cval = GetCookie (name);
   document.cookie = value + "=" + cval + "; expires=" + exp.toGMTString();
   }
}
Utils.CookieManager.registerClass('Utils.CookieManager');

Utils.DataManager = function(element) 
{
    
}

Utils.DataManager.prototype =
{
     createStore: function(fields, urlAndCommand) {

           var myStore = new Ext.data.Store({
                proxy: new Ext.data.HttpProxy({url:urlAndCommand}),
                reader: new Ext.data.JsonReader({
                    root: 'rows',
                    totalProperty: 'rCnt',
                    id: 'id',
                    fields: fields
                })
            });
         //  myStore.on('load',function() {Ext.MessageBox.hide();});

        return myStore;
    },
    
    MakeAjxRequest : function(urlToAsk, methode, succesHandler, failureHandler)
    {
        Ext.Ajax.request({
	    url : urlToAsk ,
		method: methode,
		success: succesHandler,
		failure: failureHandler
	});
    }
}


Utils.DataManager.registerClass('Utils.DataManager');


if (typeof(Sys) !== 'undefined') 
    Sys.Application.notifyScriptLoaded();