/*
----------- FundSys.net(TM) Copyright SySys(R) Corp 2002 ------------
====================================================================
  Created By: BH
  Last Edited By: BH
  Inception Date: 12/18/2001
  Last Edited Date: 1/5/2002
  Description:  Cookie Management
  Function Location List: None
  File Dependencies: Manage_string.js
===================================================================''*/

/*'''---------------------------------
'' setCookie(key, item, [expires], [path]) 
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: sets a cookie on the users browser
   Parameters
     name: key reference for cookie lookup using the setCookie routine
     value: value of the cookie
     expires: (optional) Setting no expiration date on a cookie causes it to expire when 
                         the browser closes. If you set an expiration date in the future, 
                         the cookie is saved across browser sessions. If you set an 
                         expiration date in the past, the cookie is deleted. 
                         Use GMT format to specify the date.      
     path: (optional) Setting a path for the cookie allows the current document to share 
                         cookie information with other pages within the same domain—that 
                         is, if the path is set to /thispathname, all pages in 
                         /thispathname and all pages in subfolders of /thispathname 
                         can access the same cookie information. 
   Required Files: none
----------------------------------'''*/   
function setCookie(name, value, expires, path){
  //alert('name=' + name + '\nvalue=' + value);
  if(name!=null){name=replace(name,'_','%5F')}
  //if(value!=null){value=replace(value,'_','%5F')}
  //name = encode(name);
  var argv = setCookie.arguments;  
  var argc = setCookie.arguments.length;  
  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 = name + "=" + escape (value) + 
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
  ((path == null) ? "" : ("; path=" + path)) +  
  ((domain == null) ? "" : ("; domain=" + domain)) +    
  ((secure == true) ? "; secure" : "");
}
 
/*'''---------------------------------
''   getCookie(key)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: Looks up the value of a cookie on the users browser
   Parameters
     name: Key reference for cookie lookup
   Dependencies: Manage_string.js:replace
----------------------------------'''*/   
function getCookie(name){
  if(name!=null){name=replace(name,'_','%5F')}
  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 getCookieVal(j);    
    }  
    i = document.cookie.indexOf(" ", i) + 1;    
    if (i == 0){
      break;   
    }  
  }  
  return null;
}

/*'''---------------------------------
''   delCookie(name)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: removes a cookie
   Parameters
     name: Key reference for cookie lookup
   Dependencies: Manage_string.js:replace
----------------------------------'''*/ 
function delCookie(name){
  document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}


//----------------------------------------------------------------

//private - support not documented
function getCookieVal(offset) {  
  var endstr = document.cookie.indexOf (";", offset);  
  if (endstr == -1)    
  endstr = document.cookie.length;  
  return unescape(document.cookie.substring(offset, endstr));
}

//private - support not documented
function cookieCollection(){
  var cookies = split(document.cookie,';');
  this.items = new Array(0,cookies.length-1);
  for(var i=0; i < cookies.length; i++){
    this.items[this.items.length] = new cookiePairs(cookies[i]); 
  }
}

//private - support not documented  
function cookiePairs(cookie){
  this.key = '';
  this.value = '';
  var eqIndex = cookie.indexOf('=');
  if(eqIndex > 0){
    this.key = cookie.substring(0, eqIndex-1)
    this.value = cookie.substring(eqIndex+1,cookie.length);
  } 
}