

/*
 * cookies.js
 * 
 * cookie_prefix  comes form the headers_inc.php file 
 * 		where it is dynamicaly set
 *
 * add comments later
 */
 
	var g_div_errors 			= 0x0001;
		
/* ** Adding notes sections variables ** */
	var g_div_notes      		= 0x0002;
	var g_div_note_add     		= 0x0004;

/* ** Associating Groups and Accounts variables ** */
	var g_div_assoc_groups 		= 0x0008;
	var g_div_assoc_accounts 	= 0x0010;
	var g_div_assoc_conferences = 0x0020;
	
/* ** Edit Account page variables  ** */
	var g_div_rates       		= 0x0040;
	var g_div_business	   		= 0x0080;
	var g_div_miscell    		= 0x0100;
	var g_div_rate_group   		= 0x0200;
	var g_div_payment 			= 0x0400;
	var g_div_invoice      		= 0x0800;
	
/* ** Edit Group page variables  ** */
	
 
/* ** Select Group page variables  ** */
	var g_div_select_filters 	= 0x1000;


var g_default_view_settings = 
	g_div_errors |
	g_div_notes |
	g_div_note_add |
	g_div_assoc_groups |
	g_div_assoc_accounts |
	g_div_assoc_conferences |
	g_div_rates |
	g_div_business |
	g_div_miscell |
	g_div_rate_group |
	g_div_payment |
	g_div_invoice | 
	g_div_select_filters;

 
/*
 * Cookie functions
 */

function GetCookie( p_cookie ) {
	var t_cookie_name = cookie_prefix + "_" + p_cookie;
	var t_cookies = document.cookie;

	t_cookies = t_cookies.split( ";" );

	var i = 0;
	while( i < t_cookies.length ) {
		var t_cookie = t_cookies[ i ];

		t_cookie = t_cookie.split( "=" );

		if ( t_cookie[ 0 ] == t_cookie_name ) {
			return( t_cookie[ 1 ] );
		}
		i++;
	}

	return -1;
}

function SetCookie( p_cookie, p_value ) {
	var t_cookie_name = cookie_prefix + "_" + p_cookie;
	var t_expires = new Date();

	t_expires.setTime( t_expires.getTime() + (365 * 24 * 60 * 60 * 1000));
	
	document.cookie = t_cookie_name + "=" + p_value + "; expires=" + t_expires.toUTCString() + ";";
}

function GetViewSettings() {
	var t_cookie = GetCookie( "VIEW_SETTINGS" );
	
	if ( -1 == t_cookie ) {
		t_cookie = 1;
	} else {
		t_cookie = parseInt( t_cookie );
	}

	return t_cookie;
}

function SetDiv( p_div, p_cookie_bit ) {
	var t_view_settings = GetViewSettings();
	
	if( t_view_settings & p_cookie_bit ) {
		document.getElementById( p_div + '_open' ).style.display = '';
		document.getElementById( p_div + '_closed' ).style.display = 'none';
	} else {
		
		document.getElementById( p_div + '_open' ).style.display = 'none';
		document.getElementById( p_div + '_closed' ).style.display = '';
	}
}

function ToggleDiv( p_div, p_cookie_bit ) {
	
	var t_view_settings = GetViewSettings();
	
	t_view_settings ^= p_cookie_bit;
	
	SetCookie( "VIEW_SETTINGS", t_view_settings );
	
	SetDiv( p_div, p_cookie_bit );
}

/*
 *  End Cookie Functions
 */
