function cs(id, p){
	document.getElementById(id).value = p;
}
function highlight(id, h_color)
{
$(id).style.background=h_color;
}

function tabSelection(tab_num, num_tabs, c_active, c_inactive, id_prefix)
{
	for (i=1;i<=num_tabs;i++)
	{
		var e = $(id_prefix+"_"+i);
		if (e.className != c_inactive)
		{
			e.className=c_inactive;
		}
	}
	$(id_prefix+"_"+tab_num).className = c_active;
}
function showHideContent(id, show_inner, hide_inner, starts_out)
{
	var elem = document.getElementById(id);
    var image = document.getElementById("I" + id);
	var sh_link = document.getElementById("L" + id);
    if (elem)
    {
		if (elem.style.visibility =='')
		{
			elem.style.visibility = starts_out;
		}
		if (elem.style.visibility != 'visible')
		{
			if (sh_link != null) sh_link.innerHTML = hide_inner;
			if (image != null) image.src = "images/minus_sign.gif";
			elem.style.display = 'block';
			elem.style.visibility = 'visible';
		}
		else
		{
			if (sh_link != null) sh_link.innerHTML = show_inner;
			if (image != null) image.src = "images/plus_sign.gif";
			elem.style.display = 'none';
			elem.style.visibility = 'hidden';
		}
	}
}

function expandHideAll(but_id, id_prefix, total)
{
	var bid = $(but_id);
	if (bid.title=="show all")
	{
		var style = "visible";
		var display = "block";
		bid.title = "hide all";
		bid.innerHTML = "hide all";
	}
	else
	{
		var style = "hidden";
		var display = "none";
		bid.title = "show all";
		bid.innerHTML = "show all";

	}
	for (var i = 1; i <= total; i++)
		{
			$(id_prefix+i).style.visibility = style;
			$(id_prefix+i).style.display = display;
		}
}
/* displayFunctions */

function loading() {
  $("loading_message").style.visibility = "visible";
  $("loading_message").innerHTML = "Loading...";
}



function doneLoading() {
  $("loading_message").innerHTML = "Done.";
  $("loading_message").style.visibility = "hidden";
}

function ajaxUpdate(id, url, pars, conf_string) {
	if (conf_string !='N')
	{
		var conf=confirm(conf_string);
		if (conf)
		{
			var confirmed='1';
		}
		else
		{
			var confirmed='0';
		}
	}
	else
	{
		var confirmed='1';
	}
	if (confirmed=='1')
	{
	loading();
	$(id).innerHTML = '<img src="/images/s.gif">';
	var myAjax = new Ajax.Updater(
		  {success: id},
		  url,
		  {method: 'get', parameters: pars, onFailure: reportError, insertion: genericResp}
		);
	}
}
function ajaxWmsg(id, url, pars) {
	loading();
	$(id).innerHTML = '<img src="/images/s.gif">';
	var myAjax = new Ajax.Updater(
		  {success: id},
		  url,
		  {method: 'get', parameters: pars, onFailure: reportError, insertion: RespWmsg}
		);
}
function RespWmsg(show_hide_element,responseText) {
  var m = responseText.match(/<msg>(.*?)<\/msg>/);
  if (m[1]) {
	$('msg').innerHTML = m[1];
  }
  var r = responseText.match(/<rep>(.*?)<\/rep>/);
  if (r[1]) {
	show_hide_element.innerHTML = r[1];
  }
  else {
	show_hide_element.innerHTML = '';
  }

   doneLoading();
}

function genericResp(show_hide_element,responseText) {
   show_hide_element.innerHTML = responseText;
   doneLoading();
}
function doNoResp(show_hide_element,responseText) {
  doneLoading();
}

function reportError(request)
{
  alert('Sorry. There was an error.');
}


function showHideSingleContent(id)
  {
    var elem = document.getElementById(id);
    var image = document.getElementById(id);
    if (elem)
    {
      if (elem.style.visibility != 'visible')
      {

	if (image != null) image.src = "images/minus_sign.gif";
        elem.style.display = 'block';
        elem.style.visibility = 'visible';
      }
      else
      {
	if (image != null) image.src = "images/plus_sign.gif";
        elem.style.display = 'none';
        elem.style.visibility = 'hidden';
      }
    }
  }




/* menu */
function menuShowHideContent(id, show_inner, hide_inner, starts_out)
  {
	var elem = document.getElementById(id);
    var image = document.getElementById("I" + id);
	var sh_link = document.getElementById("L" + id);
	var left_section = document.getElementById("left_section");
	var right_section = document.getElementById("right_section");
	if (elem)
    {
	if (elem.style.visibility =='')
	{
		elem.style.visibility = starts_out;
	}
	if (elem.style.visibility != 'visible')
		  {
			if (sh_link != null) sh_link.innerHTML = hide_inner;
			if (image != null) image.src = "images/minus_sign.gif";
			elem.style.display = 'block';
			elem.style.visibility = 'visible';
			right_section.style.margin = '0px 0px 0px 220px';
		  }
		  else
		  {
			if (sh_link != null) sh_link.innerHTML = show_inner;
			if (image != null) image.src = "images/plus_sign.gif";
			elem.style.display = 'none';
			elem.style.visibility = 'hidden';
			right_section.style.margin = '0px 0px 0px 0px';
		  }
    }
	document.bsform.bsbutton.focus();
  }





/* search bar */
//function switchs between search areas
/*
function switchSearchArea(form_id, link_id, search_input_id, count)
{
	var main_form_id = document.getElementById(form_id);
	var main_link_id = document.getElementById(link_id);
	var main_search_input_id = document.getElementById(search_input_id);
	var main_comparison = link_id;

	//for each search area link we need a form action, user search input name
	//user search input value
	/*
	if (link_id == "search_1")//my rss feeds
	{
		main_form_id.action = '/search_results.php?my=true';
		main_form_id.target = '';
		main_search_input_id.name = 'swooge_main_search';
		main_link_id.style.background = '#ffccff';
	}
	else if (link_id == "search_2")//search tag browser
	{
		main_form_id.action = '/tag_browser.php';
		main_form_id.target = '';
		main_search_input_id.name = 'browser_tag_names';
		main_link_id.style.background = '#ffccff';
	}
	if (link_id == "search_1")//search google
	{
		main_form_id.action = 'http://www.google.com/search';
		main_form_id.target = '_blank';
		main_search_input_id.name = 'q';
		main_link_id.style.background = '#ffccff';
	}
	else if (link_id == "search_2")//search yahoo
	{
		main_form_id.action = 'http://search.yahoo.com/search';
		main_search_input_id.name = 'p';
		main_link_id.style.background = '#ffccff';
	}
	else//search delecious
	{
		main_form_id.action = 'http://del.icio.us/search/';
		main_search_input_id.name = 'all';
		main_link_id.style.background = '#ffccff';
	}
	/*
	else //search_6 for wayback machine
	{
		main_form_id.action = 'http://www.archive.org';
		main_search_input_id.name = 'archive_search';
		main_search_input_id.value = "http://";
		main_link_id.style.background = '#ffccff';
	}
	for (var i = 1; i <= count; i++) {	//clear and make white background
		var comparison = "search_"+i;
		if (main_comparison != comparison)
		{
			//make all others the normal values
			var white_background_elem = document.getElementById(comparison);
			var regular_search_input = document.getElementById(search_input_id);
			white_background_elem.style.background = '#ffffff';
		}
	}
}






/* useful java */
/* Set current pic on each page */
var current_pic = 1;
function GalleryPhotoSwap(dir, num_pics) {
   	var image = document.getElementById("photo_swap");
	if (current_pic == num_pics)
	{
		current_pic = 1;
		image.src = dir + "photo_swap_" + current_pic + ".jpg";
		return true;
	}

	else
		for (var i = 1; i < num_pics; i++)
		{
			if (current_pic == i)
			{
				current_pic++;
				image.src = dir + "photo_swap_" + current_pic + ".jpg";
				return true;
			}
		}

} /* end of nextImage() function */

function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	}

function popWindow(page,DaName,w,h,scroll) {
		tempWindow = window.open(page,DaName,"scrollbars="+scroll+",resizable=no,width="+w+",height="+h+",status=no,location=no,toolbar=no,menubar=no");
		tempWindow.focus();
}



function changeToEditable(elem_id)
{
	//alert("change to editable");
	var qn = $('quick_note_' + elem_id);
	var state = qn.name;
	if (state=="n_c")
	{
		var qnt = $('quick_note_td_' + elem_id);
		var save = document.createElement('a');
		var re = document.createElement('a');
		re.id = "qn_cancel_"+elem_id;
		re.innerHTML = " cancel";
		save.innerHTML = "save ";
		re.className = "i_cancel";
		save.id = "qn_save_"+elem_id;
		re.href = "javascript: corsEdits('cancel', '"+elem_id+"');";
		save.href = "javascript: corsEdits('save', '"+elem_id+"');";
		qnt.appendChild(save);
		qnt.appendChild(re);
		re.style.textDecoration="none";
		save.style.textDecoration="none";
		re.style.fontSize=".8em";
		save.style.fontSize=".8em";
		qn.name="c";

	}
}

function addRows()
{
	at = $("add_bc_tarea");
}

/*******************************************************

AutoSuggest - a javascript automatic text input completion component
Copyright (C) 2005 Joe Kepley, The Sling & Rock Design Group, Inc.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*******************************************************/
function AutoSuggest(id)
{

	//The 'me' variable allow you to access the AutoSuggest object
	//from the elem's event handlers defined below.
	var me = this;

	var elem =  document.getElementById(id);
	//A reference to the element we're binding the list to.
	this.elem = elem;

	//this.suggestions = suggestions;

	//Arrow to store a subset of eligible suggestions that match the user's input
	this.eligible = new Array();

	//The text input by the user.
	this.inputText = null;

	//A pointer to the index of the highlighted eligible item. -1 means nothing highlighted.
	//this.highlighted = -1;
	this.highlighted = 0;//make first item highlighted by default

	//A div to use to create the dropdown.

	this.div = document.getElementById("ac_"+id);


// A holder for prior string in cases where multiple values are used
this.preserveStr = new String();

// Add two new keycode constants
var COMMA = 188;
var SPACE = 32;


	//Do you want to remember what keycode means what? Me neither.
	var TAB = 9;
	var ESC = 27;
	var KEYUP = 38;
	var KEYDN = 40;


	//The browsers' own autocomplete feature can be problematic, since it will
	//be making suggestions from the users' past input.
	//Setting this attribute should turn it off.
	elem.setAttribute("autocomplete","off");

	//We need to be able to reference the elem by id. If it doesn't have an id, set one.
	if(!elem.id)
	{
		var id = "autosuggest" + idCounter;
		idCounter++;

		elem.id = id;
	}


	/********************************************************
	onkeydown event handler for the input elem.
	Tab key = use the highlighted suggestion, if there is one.
	Esc key = get rid of the autosuggest dropdown
	Up/down arrows = Move the highlight up and down in the suggestions.
	********************************************************/
	elem.onkeydown = function(ev)
	{
		var key = me.getKeyCode(ev);

		switch(key)
		{
			case TAB:
			
			if (me.getMatchStr(this.value).length > 1) {
				me.useSuggestion();
			}
			break;

			case ESC:
			me.hideDiv();
			break;

			case KEYUP:
			if (me.highlighted > 0)
			{
				me.highlighted--;
			}
			me.changeHighlight(key);
			break;

			case KEYDN:
			if (me.highlighted < (me.eligible.length - 1))
			{
				me.highlighted++;
			}
			me.changeHighlight(key);
			break;

			case COMMA:
            me.hideDiv();
            break;

            case SPACE:
            me.hideDiv();
            break;

		}
	};

	/********************************************************
	onkeyup handler for the elem
	If the text is of sufficient length, and has been changed,
	then display a list of eligible suggestions.
	********************************************************/
	elem.onkeyup = function(ev)
	{
		var key = me.getKeyCode(ev);
		switch(key)
		{
		//The control keys were already handled by onkeydown, so do nothing.
		case TAB:
		case ESC:
		case KEYUP:
		case KEYDN:
			return;
		default:

			if (this.value != me.inputText && me.getMatchStr(this.value).length > 1)
        {
            me.inputText = me.getMatchStr(this.value);
            me.getEligible();
			/*
            me.createDiv();
            me.positionDiv();
            me.showDiv();
			*/
        }
			else
			{
				me.hideDiv();
			}
		}
	};



/********************************************************
    Offer Suggestions for each item in a comma/space separated
    list.
    ********************************************************/
    this.getMatchStr = function(inputStr)
    {
        var regex = /[\s,]/;
        var finalStr = new String();

        if (inputStr.match(regex))
        {
            matchArray = inputStr.split(regex);
            finalStr = matchArray[matchArray.length-1];
            this.preserveStr = inputStr.substr(0,inputStr.length - finalStr.length);
            return(finalStr);
        }
        //If no special handling, the original string is good enough
        return(inputStr);
    };





	/********************************************************
	Insert the highlighted suggestion into the input box, and
	remove the suggestion dropdown.
	********************************************************/
	this.useSuggestion = function()
	{
		if (this.highlighted > -1)
		{
			this.elem.value = this.preserveStr + this.eligible[this.highlighted];
			this.hideDiv();
			//It's impossible to cancel the Tab key's default behavior.
			//So this undoes it by moving the focus back to our field right after
			//the event completes.
			setTimeout("document.getElementById('" + this.elem.id + "').focus()",0);
		}
	};

	/********************************************************
	Display the dropdown. Pretty straightforward.
	********************************************************/
	this.showDiv = function()
	{
		this.div.style.display = 'block';
	};

	/********************************************************
	Hide the dropdown and clear any highlight.
	********************************************************/
	this.hideDiv = function()
	{
		this.div.style.display = 'none';
		//this.highlighted = -1;
		this.highlighted = 0;//highlight 1st item by default
	};

	/********************************************************
	Modify the HTML in the dropdown to move the highlight.
	********************************************************/
	this.changeHighlight = function()
	{
		var lis = this.div.getElementsByTagName('LI');
		for (i in lis)
		{
			var li = lis[i];

			if (this.highlighted == i)
			{
				li.className = "selected";
			}
			else
			{
				li.className = "";
			}
		}
	};

	/********************************************************
	Position the dropdown div below the input text field.
	********************************************************/
	this.positionDiv = function()
	{
		var el = this.elem;
		var x = 0;
		var y = el.offsetHeight;

		//Walk up the DOM and add up all of the offset positions.
		while (el.offsetParent && el.tagName.toUpperCase() != 'BODY')
		{
			x += el.offsetLeft;
			y += el.offsetTop;
			el = el.offsetParent;
		}

		x += el.offsetLeft;
		y += el.offsetTop;

		this.div.style.left = x + 'px';
		this.div.style.top = y + 'px';
	};

	/********************************************************
	Build the HTML for the dropdown div
	********************************************************/
	this.createDiv = function(el)
	{
		this.eligible = el;
		var ul = document.createElement('ul');

		//Create an array of LI's for the words.
		for (i in this.eligible)
		{

		    var word = this.eligible[i];
		    if (typeof(word) == 'string')//my hack to deal with prototype interference
		    {
			var li = document.createElement('li');
			var a = document.createElement('a');
			a.href="javascript:false";
			a.innerHTML = word;
			li.appendChild(a);

			if (me.highlighted == i)
			{
				li.className = "selected";
			}

			ul.appendChild(li);
		    }
		}

		this.div.replaceChild(ul,this.div.childNodes[0]);


		/********************************************************
		mouseover handler for the dropdown ul
		move the highlighted suggestion with the mouse
		********************************************************/
		ul.onmouseover = function(ev)
		{
			//Walk up from target until you find the LI.
			var target = me.getEventSource(ev);
			while (target.parentNode && target.tagName.toUpperCase() != 'LI')
			{
				target = target.parentNode;
			}

			var lis = me.div.getElementsByTagName('LI');


			for (i in lis)
			{
				var li = lis[i];
				if(li == target)
				{
					me.highlighted = i;
					break;
				}
			}
			me.changeHighlight();
		};

		/********************************************************
		click handler for the dropdown ul
		insert the clicked suggestion into the input
		********************************************************/
		ul.onclick = function(ev)
		{
			me.useSuggestion();
			me.hideDiv();
			me.cancelEvent(ev);
			return false;
		};

		this.div.className="suggestion_list";
		this.div.style.position = 'absolute';

	};

	/********************************************************
	determine which of the suggestions matches the input
	********************************************************/
	/*
	this.getEligible = function()
	{
		this.eligible = new Array();
		for (i in this.suggestions)
		{
			var suggestion = this.suggestions[i];
		  if (typeof(suggestion) == 'string') //my hack to deal with prototype interference
		  {
			if(suggestion.toLowerCase().indexOf(this.inputText.toLowerCase()) == "0")
			{
				this.eligible[this.eligible.length]=suggestion;
			}
		  }
		}

	};
	*/
	this.getEligible = function ()
	{
		var myAjax = new Ajax.Request(
			'/ajaxResponders/auto.php',
			{
				method: 'get',
				parameters: 'i='+ this.inputText.toLowerCase(),
				onComplete: me.getEligibleResp
			});

	};
	this.getEligibleResp = function(req)
	{
	  this.eligible = req.responseText.split(',');
	  me.createDiv(this.eligible);
	  me.positionDiv();
	  me.showDiv();
	  /*
		this.eligible = new Array();
		for (i in this.suggestions)
		{
			var suggestion = this.suggestions[i];
		  if (typeof(suggestion) == 'string') //my hack to  deal with prototype interference
		  {
			if(suggestion.toLowerCase().indexOf(this.inputText.toLowerCase()) == "0")
			{
				this.eligible[this.eligible.length]=suggestion;
			}
		  }
		}
	  */
	};

	/********************************************************
	Helper function to determine the keycode pressed in a
	browser-independent manner.
	********************************************************/
	this.getKeyCode = function(ev)
	{
		if(ev)			//Moz
		{
			return ev.keyCode;
		}
		if(window.event)	//IE
		{
			return window.event.keyCode;
		}
	};

	/********************************************************
	Helper function to determine the event source element in a
	browser-independent manner.
	********************************************************/
	this.getEventSource = function(ev)
	{
		if(ev)			//Moz
		{
			return ev.target;
		}

		if(window.event)	//IE
		{
			return window.event.srcElement;
		}
	};

	/********************************************************
	Helper function to cancel an event in a
	browser-independent manner.
	(Returning false helps too).
	********************************************************/
	this.cancelEvent = function(ev)
	{
		if(ev)			//Moz
		{
			ev.preventDefault();
			ev.stopPropagation();
		}
		if(window.event)	//IE
		{
			window.event.returnValue = false;
		}
	}
}

//counter to help create unique ID's
var idCounter = 0;
