/*
<ChangeLog>
 <Versions>
  <Version> 
   <Version>1.0</Version> 
   <DateTime>15.1.2009 00:00:00</DateTime>
   <Author>Marek Skotnica</Author> 
   <Description>Js cookies library.</Description> 
  </Version> 
 </Versions>
</ChangeLog>
*/

var KarsaCookies = {

	get : function( name) {
        ///<param name="name" type = "string" >name of the desired cookie</param>
		///<returns type="string">return string containing value of specified cookie or null if cookie does not exist.</returns>
		var start = document.cookie.indexOf( name + "=" );
		var len = start + name.length + 1;
		if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
			return null;
		}
		if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ';', len );
		if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
	} , 
	
	set : function (name, value, expires, path, domain, secure ) {
        ///<summary>set cookie function with many optional params, requied are only name and value.</summary>
        ///<param name="name" type = "string" >name of the cookie</param>
        ///<param name="value" type = "string" >value of the cookie</param>
        ///<param name="expires" type = "DateTime" >expiration date of the cookie (defaults to end of current session)</param>
        ///<param name="path" type = "string" >path for which the cookie is valid (defaults to path of calling document)</param>
        ///<param name="domain" type = "string" >domain for which the cookie is valid (defaults to domain of calling document)</param>
        ///<param name="secure" type = "bool" >Boolean value indicating if the cookie transmission requires a secure transmission</param>
		var today = new Date();
		today.setTime( today.getTime() );
		if ( expires ) {
			expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date( today.getTime() + (expires) );
		document.cookie = name+'='+escape( value ) +
			( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
			( ( path ) ? ';path=' + path : '' ) +
			( ( domain ) ? ';domain=' + domain : '' ) +
			( ( secure ) ? ';secure' : '' );
	}, 
	
	deleteCookie : function ( name, path, domain ) {
	    ///<param name="name" type = "string" >name of the cookie</param>
	    ///<param name="path" type = "string" >path for which the cookie is valid (defaults to path of calling document)</param>
        ///<param name="domain" type = "string" >path and domain default if assigned null or omitted if no explicit argument proceeds</param>
		if ( this.get( name ) ) document.cookie = name + '=' +
				( ( path ) ? ';path=' + path : '') +
				( ( domain ) ? ';domain=' + domain : '' ) +
				';expires=Thu, 01-Jan-1970 00:00:01 GMT';
	}

}