// vim: set fdm=marker encoding=utf-8 :
/**
 * NSF
 *
 * LICENSE
 *
 * Dr. Maté GmbH License ?
 *
 * @category	Nsf
 * @copyright	(c) 2007 by Dr. Maté GmbH
 * @license		http://www.netdoktor.at/license/
 * @author		Thomas Subera <thomas.subera@gmail.com>
 * @version		$Id: nsf.js 8790 2009-03-09 10:47:38Z soestreicher $
 */

/**
 * Namespace nsf
 */
var nsf = { // {{{
	Effects : {},
	Utils : {},
	/**
	 * Load other Javascript libraries, copied code from scriptaculous
	 */
	require : function (sLibrary) { // {{{
    	// inserting via DOM fails in Safari 2.0, so brute force approach
	    document.write('<script type="text/javascript" src="'+ sLibrary +'"></script>');		
	}, // }}}
	/**
	 * Load other nsf Javascript libraries, copied code from scriptaculous
	 */
	load : function () { // {{{
		$A(document.getElementsByTagName("script")).findAll( function(s) {
		  return (s.src && s.src.match(/nsf\.js(\?.*)?$/))
		}).each( function(s) {
		  var path = s.src.replace(/nsf\.js(\?.*)?$/,'');
		  var includes = s.src.match(/\?.*load=([a-z,]*)/);
		  (includes ? includes[1] : 'effects,utils').split(',').each(
		   function(include) { nsf.require(path+'nsf.'+include+'.js') });
		});
	}, // }}}
	/**
	 * Package cookie related functions
	 */
	cookie : { // {{{
		/**
		 * Retrieves the cookie by that name or returns null
		 * @param	string	Name of cookie
		 */
		get : function(sName) {
			if (document.cookie.length > 0) {
				var begin = document.cookie.indexOf(sName + "=");
				if (begin != -1) {
					begin += sName.length + 1;
					var end = document.cookie.indexOf(";", begin);
					if (end == -1) {
						end = document.cookie.length;
					}
					return unescape(document.cookie.substring(begin, end));
				}
			}
			return null;
		},
		/**
		 * Sets a cookie by name, value and days to expire
		 * @param	string	Name of cookie
		 * @param	string	Value of cookie to set
		 * @param	integer	TTL of cookie in days
		 * @param	string	Optional: Path to set the cookie to; if missing default to current page
		 * @todo	Why days?
		 */
		set : function(sName, sValue, iExpireDays, sPath) {
			var expireDate = new Date ();
			expireDate.setTime(expireDate.getTime() + (iExpireDays * 24 * 3600 * 1000));
			var sPathPart = '';
			if (typeof sPath == 'string') {
				sPathPart = '; path=' + sPath;
			}
			document.cookie = sName + "=" + escape(sValue) +
				((iExpireDays == null) ? "" : "; expires=" + expireDate.toGMTString()) +
				sPathPart;
		},
		/**
		 * Deletes the cookie by the name
		 * @param	string	Name of cookie
		 */
		del : function(sName) {
			if (nsf.cookie.get(sName)) {
				document.cookie = sName + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
			}
		}
	} // }}}
} // }}}
