



function FavoriteButton()
{
	if( getValue( m_ThisName ) )
	 {
		document.write("<br>");
		document.write("   <input type=\"button\" ");
		document.write("   onclick=\"delete_name_refresh('"+m_ThisName+"')\""); 
		document.write("   value=\"Remove from my bookmarks\">");
	 }
	 else
	 {
		document.write("<br>");
		document.write("   <input type=\"button\"");
		document.write("   onclick=\"setValue_refresh('"+m_ThisName+"','"+m_ThisPage+"')\"" );
		document.write("   value=\"Add to my bookmarks\">");
	 }
}


function RemoveAllBookmarksButton()
{
		document.write("   <input type=\"button\"");
		document.write("   onclick=\"RemoveAllBookmarks()\"");
		document.write("   value=\"Delete All Bookmarks\">");
}


function RefreshBookmarksButton()
{
		document.write("   <input type=\"button\"");
		document.write("   onclick=\"RefreshThis()\"");
		document.write("   value=\"Refresh Bookmarks\">");
}


function RemoveAllBookmarks()
{
	var r=confirm("Are you sure you want to delete all of your bookmarks?");
	if( r == true )
	{
		var favorites = getNames();
		for( x in favorites )
		{
			name 	= favorites[x];
			delete_name(name);
		}
		RefreshThis();
	}
}
//

function RefreshThis()
{
	location.reload(true);
}


function delete_name_refresh( name )
{
	delete_name( name );
	window.location.replace( m_ThisPage );
}

function setValue_refresh(name, value)
{
	setValue(name, value);
	window.location.replace( m_ThisPage );
}


function ListFavorites()
{
	var count = Count();
	var favorites = getNames();
	var ref = "";
	document.write( "<br>Your Bookmarked Prints:<br>");
	var linelen = 0;
	for( x in favorites )
	{
		name 	= favorites[x];
		linelen += name.length + 2; // add comma and space
		if( linelen > 70 )
		{
			document.write( "<br>");
			linelen = name.length;
		}
		ref 	= getValue( name);
		document.write( "<a href=http://www.finalimpressions.com/printindex/" + ref + ">" + name + "</a>");
		if(( count > 1 ) && ( ( count-x ) != 1 ) )
			document.write( ", " );
	}
}


function ListFavoritesText()
{
	var retval = "";
	var favorites = getNames();
	for( x in favorites )
	{
		name 	= favorites[x];
		retval += name+",";
	}
	return retval;
}


// return true if stored, else false 
function setValue(name, value) 
{
	result = get_cookie(name);
	set_cookie( name, value, 60);
	return (result != null && result != '');
}


// returns value, or empty string (not found) 
function getValue(name) 
{
	result = get_cookie(name);
	return (result == null)?'':result;
}


// return true if successful delete. 
function delete_name( name ) 
{
	delete_cookie(name);
	return true;
}

// returns number of name/value pairs in cookie 
function Count() 
{
	res = document.cookie.split(';');
	return res.length;
}

// return all cookie names
function getNames()
{
	r1 = document.cookie.split(';');
	result = new Array();
	if (r1.length > 0) 
	{
		for (i = 0; i < r1.length; i++) 
		{
			r2 = r1[i].split('=');
			result.push(r2[0]);
		};
	};
	return result;
}


function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}


function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString()+"; path=/";
  // document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}


// base functions

function set_cookie ( name, value, expiredays, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( expiredays )
  {
	var expires_msec = expiredays * 1000 * 60 * 60 * 24;
	var today = new Date();
    var expires = new Date (today.getTime() + (expires_msec));
    cookie_string += "; expires=" + expires.toGMTString();
  }

  //if ( path )
	//cookie_string += "; path=" + escape ( path );

	cookie_string += "; path=/"

  if ( domain )
	cookie_string += "; domain=" + escape ( domain );

  if ( secure )
	cookie_string += "; secure";

  document.cookie = cookie_string;

}