function update_config(mode, value)
	{
	var url = SITE_URL+'ajax/config/'+mode+'/';
	new Ajax.Request(url, { method: 'post', postBody: 'value='+value });
	}

function popup(url, name, height, width)
	{
	/*
	*REQUIRED*
	url = url to load 
	
	*OPTIONAL*
	name = name of the popup window
	height = height in pixels of the new window
	width = width in pixels of the new window
	*/
	if (url != '')
		{
		if (isNaN(height) || isNaN(width))
			{
			var height = 300;
			var width = 410;
			}
			
		if (name != '')
			{
			var name = 'popup';
			}

		popup_window = window.open(url, name, 'status=1,toolbar=0,location=0,menubar=0,directories=0,scrollbars=1,width='+width+',height='+height+',resizable=1');
		popup_window.focus();
		
		}
		
	return false; // always return false to ensure backup link isn't followed
	}

function toggleFilter(check, toggle, force)
	{
	if ($(check).getStyle('display') == 'block' && force != 'on')
		{
		// this click will close a filter
		//Effect.PhaseOut(check,{ duration: 0.2 });
		Effect.BlindUp(check,{ duration: 0.4 });
		$(toggle).select('img')[0].src = SITE_URL+'skins/'+SKIN_DIR+'/images/arrow_right.gif';
		//setCookie(check, 'hidden', 365);
		//setCookie(toggle, 'hidden_arrow', 365);
		setCookie2('filter', check, 1, 365);
		setCookie2('arrow', toggle, 1, 365);
		}
	else if ($(check).getStyle('display') == 'none' && force != 'off')
		{
		// this click opens a filter
		var isSubFilter = $$("#filters blockquote #"+check);
		if (isSubFilter.length)
			{
			var subFilters = $$('#filters blockquote p.filter_list');
			// close other sub filters first
			for (var i=0; i < subFilters.length; i++)
				{
				
				if (subFilters[i].id != check)
					{
					//alert("1: "+subFilters[i].id+" 2: "+check);
					var parts = subFilters[i].id.split('_'); // get the filterId
					toggleFilter(subFilters[i].id, 'filter_toggle_'+parts[2] , 'off'); // force off
					}
				}
			}
			
		//Effect.PhaseIn(check,{ duration: 0.2 });
		Effect.BlindDown(check,{ duration: 0.4 });
		$(toggle).select('img')[0].src = SITE_URL+'skins/'+SKIN_DIR+'/images/arrow_down.gif';
		//setCookie(check, '', 365);
		//setCookie(toggle, '', 365);
		setCookie2('filter', check, 0, 365);
		setCookie2('arrow', toggle, 0, 365);
		}
	}

function collapseAll()
	{
	// collapses all filters
	var filterLists = $$('p.filter_list');
	if (filterLists)
		{
		for (var i = 0; i < filterLists.length; i++)
			{
			var parts = filterLists[i].id.split('_');
			if (parts[2])
				{
				Effect.PhaseOut('filter_list_'+parts[2],{ duration: 0.4 });
				$('filter_toggle_'+parts[2]).select('img')[0].src = SITE_URL+'skins/'+SKIN_DIR+'/images/arrow_right.gif';
				setCookie2('filter', 'filter_list_'+parts[2], 1, 365);
				setCookie2('arrow', 'filter_toggle_'+parts[2], 1, 365);
				}
			}
		}
	}
	
function expandAll()
	{
	// expands all filters
	var filterLists = $$('p.filter_list');
	if (filterLists)
		{
		for (var i = 0; i < filterLists.length; i++)
			{
			var parts = filterLists[i].id.split('_');
			if (parts[2])
				{
				if ($('filter_list_'+parts[2]).getStyle('display') == 'none')
					{
					Effect.PhaseIn('filter_list_'+parts[2],{ duration: 0.4 });
					}
				$('filter_toggle_'+parts[2]).select('img')[0].src = SITE_URL+'skins/'+SKIN_DIR+'/images/arrow_down.gif';
				setCookie2('filter', 'filter_list_'+parts[2], 0, 365);
				setCookie2('arrow', 'filter_toggle_'+parts[2], 0, 365);
				}
			}
		}
	}

// set a cookie, days is optional
function setCookie(name,value,days)
	{
	if (days)
		{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
		}
	else
		{
		expires = "";
		}
	document.cookie = name+"="+value+expires+";path=/";
	}

function setCookie2(cookie, name,state,days)
	{
	if (state == 1) // set hidden, add to cookie
		{
		var found = 0;
		var cookieValue = readCookie('toggle_'+cookie);
		if (cookieValue)
			{
			var elementList = cookieValue.split('|');
			if (!Array.prototype.indexOf)
				{
				for (var i=0; i<elementList.length; i++)
					{
					if (elementList[i] == name)
						{
						found = 1;
						break;
						}
					}
				}
			else
				{
				// use indexOf if its there (more efficient)
				var idx = elementList.indexOf(name);
				if (idx != -1)
					{
					found = 1;
					}
				}
			}
		if (!found && cookieValue)
			{ // only hide the element if its not already hidden
			setCookie('toggle_'+cookie, cookieValue+'|'+name, days);
			}
		else if (!found)
			{
			// first entry to cookie
			setCookie('toggle_'+cookie, name, days);
			}
			
		}
	else // set shown, remove from cookie
		{
		var cookieValue = readCookie('toggle_'+cookie);
		if (cookieValue)
			{
			var elementList = cookieValue.split('|');
			
			if (!Array.prototype.indexOf)
				{
				for (var i=0; i<elementList.length; i++)
					{
					if (elementList[i] == name)
						{
						var idx = i;
						break;
						}
					}
				}
			else
				{
				// use indexOf if its there (more efficient)
				var idx = elementList.indexOf(name);
				}
			
			if (idx > -1)
				{
				elementList.splice(idx, 1); // remove the identified element
				setCookie('toggle_'+cookie, elementList.join('|'), days);
				}
			}
		}
	}


// returns the value of cookie 'name'
function readCookie(name)
	{
	var needle = name + "=";
	var cookieArray = document.cookie.split(';');
	for(var i=0;i <cookieArray.length;i++)
		{
		var pair = cookieArray[i];
		while (pair.charAt(0)==' ')
			{
			pair = pair.substring(1, pair.length);
			}
		if (pair.indexOf(needle) == 0)
			{
			return pair.substring(needle.length, pair.length);
			}
		}
	return null;
	}

// reads cookies and hides filters as necessary
function readFilterState()
	{
	
	var cookieValueFilter = readCookie('toggle_filter');
	var cookieValueArrow = readCookie('toggle_arrow');
	// filters
	if (cookieValueFilter)
		{
		var elementList = cookieValueFilter.split('|');
		for (var i=0;i < elementList.length;i++)
			{		
			if ($(elementList[i]) != null)
				{
				$(elementList[i]).setStyle({ display: 'none' });
				}
			}
		}
		
	// arrows
	if (cookieValueArrow)
		{
		var elementList = cookieValueArrow.split('|');
		for (var i=0;i < elementList.length;i++)
			{
			if ($(elementList[i]) != null)
				{
				$(elementList[i]).select('img')[0].src = SITE_URL+'skins/'+SKIN_DIR+'/images/arrow_right.gif';
				}
			}
		}     
	}

function confirmSubmit(message)
	{
	var confirmed=confirm(message);
	if (confirmed)
		{
		return true;
		}
	else
		{
		return false;
		}
	}