// Version: 05-29-2005
// FORZA STUDIOS JAVASCRIPT FUNCTIONS
//
// Author: Jeroen Mulder ( me at jeroenmulder dot com )
// Copyright: Forza Studios, unless noted otherwise

// --------------------
// Simon Willison - http://www.sitepoint.com/blog-post-view.php?id=171578
// --------------------
function addLoadEvent (func) 
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') 
		window.onload = func;
	else 
		window.onload = function() { oldonload(); func(); }
}

// --------------------
// Jeroen Mulder - Forza Studios
// --------------------
function init ()
{
	// Search Box
	handleSearch();

	// XHTML Compliant Popup Windows
	popupWindows();
}

/**
 * Create XHTML compliant popup windows
 *
 * Assigns a method to the <code>onclick</code> event handler
 * for each anchor with a relation value of <code>popup</code>.
 *
 * @author Jeroen Mulder < me (at) jeroenmulder (dot) com >
 */
function popupWindows ()
{
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName('a');
	
	// Preferences
	var prefs = new Array();	
	prefs['popup-bbcode'] = new Array(500, 600);	
	
	for (var i = 0; i < anchors.length; i++) 
	{ 
		var anchor = anchors[i]; 
		if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'popup')
		{
			anchor.onclick = function e() { createPopup(this.href, this.id); return false; };
			anchor.target = '_blank';
		}
	}
	
	/**
	 * Create Popup Window
	 *
	 * @param href		The URI to point to
	 * @param id		ID indicating type of popup
	 */
	function createPopup (href, id)
	{
		// Default Dimensions
		var width = 500;
		var height = 600;
		
		if(prefs.id)
		{
			width = prefs.id[0];
			height = prefs.id[1];
		}		
		window.open(href, 'popupwindow', 'width=' + width + ', height=' + height + ', scrollbars, resizable');
	}
}

/**
 * Handle the search form
 *
 * @author Jeroen Mulder < me (at) jeroenmulder (dot) com >
 */
function handleSearch ()
{
	if (!document.getElementById) return;
	
	var defaultValue = 'Search...';
	var form = document.getElementById('search');
	
	form['as_q'].value = defaultValue;
	form['as_q'].onfocus = function e () 
	{ 
		if(form['as_q'].value == defaultValue)
			this.value = '';
	};
}

// Load Events
addLoadEvent(init);