/*

Notes:

Relies (depends) on the main JS lib:
/js/sg_lib.js

*/

/*====================================================================
                                                            focusField
*/
function focusField( field_id )
{
	var field_elm = document.getElementById( field_id );
	if(field_elm != null) field_elm.focus();
}


/*====================================================================
                                                        displaySources
*/
// Modified from: Peter Janes http://peterjanes.ca/blog/
//
// 2004/01/11: Added title attribute support
// 2003/11/11: Added XHTML support
//
// Original at:
// Dunstan Orchard http://www.1976design.com/blog/
//
// Altered from original idea by Simon Willison at:
// http://simon.incutio.com/archive/2002/12/20/blockquoteCitations
function displaySources()
{
	displayQuotationSources( 'blockquote', 'p', '\u2014 ', '' );
	displayQuotationSources( 'q', 'span', ' (in ', ')' );
}


/*====================================================================
                                              displayBlockquoteSources
*/
function displayQuotationSources(elm, hostElm, prependTxt, appendTxt )
{
	var quotes = document.getElementsByTagName(elm);
	for (i = 0; i < quotes.length; i++)
	{
		var cite = quotes[i].getAttribute('cite');
		if ((cite) && (cite != ''))
		{
			var title = quotes[i].getAttribute('title');
			var sourceElm = createElement(XHTMLNS, hostElm);
			sourceElm.className = 'source';// IE6- bug. See Notes in main JS file.

			if (cite.match('http', 'i') || cite.match('mailto', 'i') || cite.match('^/','i'))
			{// We think the source is a URL, make it a link (http://www.w3.org/TR/html4/index/attributes.html says it ought to be a URI)
				var newlink = createElement(XHTMLNS,'a');
				newlink.setAttribute('href', cite);
				
				if ((title) && (title != ''))
				{// If there is a title, make it the text of the link
					quotes[i].setAttribute('title','');
					newlink.setAttribute('title', title);
					newlink.appendChild(document.createTextNode(title));
				}
				else
				{// There is no title, use the URL as clickable text
					newlink.setAttribute('title', (cite));
					newlink.appendChild( document.createTextNode(cite) );
				}
				sourceElm.appendChild( document.createTextNode(prependTxt) );
				sourceElm.appendChild(newlink);
				sourceElm.appendChild( document.createTextNode(appendTxt) );
			}
			else
			{// We don't know what the source is, display as plain text
				sourceElm.appendChild( document.createTextNode(prependTxt) );
				sourceElm.appendChild(document.createTextNode(cite));
				sourceElm.appendChild( document.createTextNode(appendTxt) );
			}

			if( elm == 'blockquote' )
			{
				quotes[i].appendChild(sourceElm);
			}
			else
			{
				insertAfter( sourceElm, quotes[i] );
			}
		}
	}
}


/*

function toggleDisplay(l)
{
	var oldCloneUL = document.getElementById('cloneUL');
	if (oldCloneUL) document.body.removeChild(oldCloneUL);

	var cloneUL = document.createElement('ul');
	cloneUL.setAttribute('id', 'cloneUL');
	document.body.appendChild(cloneUL);
	var lis = document.getElementById('contentPool').getElementsByTagName('li');
	var cat_class = l.href.match(/#(\w.+)/)[1];
	for (var i = 0; i < lis.length; i++)
	{
		if (lis[i].className.indexOf(cat_class) != -1)
		{
			var clone = lis[i].cloneNode(true);
			cloneUL.appendChild(clone);
		}
	}
}*/


/*====================================================================
                                                      confirmSomething
*/
function confirmSomething(msg)
{
	return confirm(msg);
}


/*====================================================================
                                                 prepareOnchangeSelect
*/
function prepareOnchangeSelect()
{
	if(document.getElementsByTagName && document.getElementById)
	{
		var selects = document.getElementsByTagName('select');
		for(var i=0; i < selects.length; i++)
		{
			if(selects[i].className.indexOf('onchange-select') > -1)
			{
				selects[i].onchange = function()
				{
					this.form.submit();
				}
			}
		}
	}
}


/*====================================================================
                                                         documentWrite
*/
function documentWrite(str)
{
	document.write(str);
}


/*====================================================================
                                                            Add events
*/
//addEvent(window, 'load', displaySources);
addEvent(window, 'load', prepareOnchangeSelect);
