// This function adds a load event without overwriting exising load events
function addLoadListener(fn){
	if(typeof window.addEventListener !='undefined') window.addEventListener('load',fn,false);
	else if(typeof document.addEventListener !='undefined') document.addEventListener('load',fn,false);
	else if(typeof window.attachEvent !='undefined') window.attachEvent('onload',fn);
	else{
		var oldfn=window.onload
		if(typeof window.onload !='function') window.onload=fn;
		else window.onload=function(){oldfn();fn();}
	}
}

// IE/win background image flicker fix
// http://evil.che.lu/2006/9/25/no-more-ie6-background-flicker
try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}

/* ======================================================================== */

var AAJ = new Site();


/* -- BEGIN: DHTMLMenu ---------------------------------------------------- */

var DHTMLMenu = Class.create();
Object.extend(DHTMLMenu.prototype, PageWidget.prototype);
Object.extend(DHTMLMenu.prototype, {
	initialize : function(menu_id, config) {
		this.node = $(menu_id);

		// bail out if the menu doesn't exist on this page
		if (!this.node || this.initialized) return;

		this.setOptions(config);

		this.submenus = { };

		// get all the top-level LIs in the menu and iterate over them, adding event handlers
		$(menu_id).immediateDescendants().each(function(item){
			item.observe("mouseover", this.mouseoverHandler.bindAsEventListener(this, item));
			item.observe("mouseout", this.mouseoutHandler.bindAsEventListener(this, item));
			this.submenus[item.id] = item.down().next();
		}.bind(this));

	},

	initialized : false,
	node : null,              // holds the DOM node of the menu
	menu_hide_timeout : null, // the JS timeout ID for hiding the menu
	menu_show_timeout : null, // the JS timeout ID for showing the menu
	last_menu_on : null,      // the DOM object of the waiting to close

	mouseoverHandler : function(e, item) {
		// stop the menu from closing/opening (this gets called a lot)
		clearTimeout(this.menu_hide_timeout);
		clearTimeout(this.menu_show_timeout);

		// if we're mousing over the menu for the first time, set a timeout so the menu doesn't show up accidentally.
		if (this.last_menu_on == null) {
			this.menu_show_timeout = setTimeout(this.showMenu.bind(this, item),	this.CONFIG["menu_show_time"]);

		// if there's already a menu on, then we know the user is expecting to see another one, so show it immediately.
		} else if (this.last_menu_on != item) {
			this.showMenu(item);
		}
	},

	mouseoutHandler : function(e, item) {
		// clear the existing show/hide timeouts (this gets called a lot)
		clearTimeout(this.menu_hide_timeout);
		clearTimeout(this.menu_show_timeout);

		// only "close" the menu in a little bit if we're over a menu with submenus, otherwise, close it right now
		if (this.submenus[item.id]) {
			this.menu_hide_timeout = setTimeout(this.hideMenu.bind(this, item),	this.CONFIG["menu_hide_time"]);

		} else {
			this.hideMenu(item);
		}
	},

	// shows the menu
	showMenu : function(item) {
		// hide the last menu shown
		if (this.last_menu_on != null) { this.hideMenu(this.last_menu_on); }

		// adding the "hover" class turns on the menu
		item.addClassName(this.CONFIG['hover_class']);

		// insert the IFRAME for IE
		if (Prototype.Browser.IE6) {
			// get at the submenu for dimension info
			
			var submenu = this.submenus[item.id];
			if (submenu) {
				var iframe = submenu.next();

				if (submenu && !iframe) {
					this.createIframe(item, {
						'left'   : submenu.offsetLeft + "px",
						'height' : submenu.offsetHeight + "px",
						'width'  : submenu.offsetWidth + "px"
					});
				}
			}
		}

		// store the last item on
		this.last_menu_on = item;

	}, // END: showMenu()

	// hide the menu
	hideMenu : function(item) {
		// nothing to hide
		if (item == null) return;

		// removing the "hover" class turns off the menu
		item.removeClassName(this.CONFIG['hover_class']);

		// remove the IFRAME for IE
		if (Prototype.Browser.IE6) {
			var submenu = this.submenus[item.id];
			if (submenu) {
				var iframe = submenu.next();
				if (submenu && iframe) {
					item.removeChild(iframe);
				}
			}
		}

		this.last_menu_on = null;
	}, // END: hideMenu()

	// makes an IFRAME the exact size of the menu so elements underneath it are covered
	// (IE-only)
	createIframe : function(node, style) {
		new Insertion.Bottom(node, (new Template('<iframe class="' + this.CONFIG['iframe_class'] + '" frameborder="0" scrolling="no" style="width: #{width}; height: #{height}; left: #{left};"><\/iframe>')).evaluate(style));
	}
});

DHTMLMenu.CONFIG = {
	submenu_class : "SubMenu", // the DOM class of the menu container
	hover_class : "Hover", // the class to give the top-level LI to "activate" the menu
	menu_hide_time : 500, // time to keep the menus on after mouseout; in ms
	menu_show_time : 100, // threshold o
	iframe_class : "IframeFix"
};

fixWebKitInheritanceBug(DHTMLMenu);

// ---------------------------------------------------------------------------

AAJ.addFeature('DHTMLMenus', {
	setupElements : function(scope) {
		$$S(scope, ".DHTMLMenu").each(function(menu) {
			this.storeWidgetInstance(menu.id, new DHTMLMenu(menu.id));
		}.bind(this));
	}
});

/* ------------------------------------------------------ END: DHTMLMenu -- */


/* -- BEGIN: FormFieldTitle ----------------------------------------------- */

AAJ.addFeature('FormFieldTitle', {

	CONFIG : {
		show_title_class : "ShowTitle",
		disabled_class : 'Disabled'
	},

	// FIXME: this needs some refactoring
	setupElements : function(scope) {

		// set up the INPUT tags
		$$S(scope, 'INPUT.' + this.CONFIG['show_title_class']).each(function(input_el){
			// skip this whole thing if the element is disabled or if there's no title attribute
			if ( input_el.disabled || 
			    (typeof(input_el.title) == 'undefined') || 
			    (input_el.title == '') ) {
				return;
			}

			this.restoreHelperText(input_el);

			// hook up the events
			input_el.observe('focus', this.clearHelperText.bind(this, input_el), false);
			input_el.observe('blur', this.restoreHelperText.bind(this, input_el), false);

		}.bind(this)); // END: inputs

		// set up the SELECT tags
		$$S(scope, 'SELECT.' + this.CONFIG['show_title_class']).each(function(select_el){
			// warning: kinda ugly

			// create new option and prepend it tot the options array
			var new_option = "<option value=\"\"" + ((select_el.selectedIndex == 0)	 ? " selected=\"selected\"": "") + ">" + select_el.title + "<\/option>";

			new Insertion.Top(select_el, new_option);
		}); // END: selects

		// set up the TEXTAREA tags
		// FIXME: same as INPUT tags right now... may change
		$$S(scope, 'TEXTAREA.' + this.CONFIG['show_title_class']).each(function(textarea_el){
			// skip this whole thing if the element is disabled or if there's no title attribute
			if ( textarea_el.disabled || 
			    (typeof(textarea_el.title) == 'undefined') || 
			    (textarea_el.title == '') ) {
				return;
			}

			this.restoreHelperText(textarea_el);

			// hook up the events
			textarea_el.observe('focus', this.clearHelperText.bind(this, textarea_el), false);
			textarea_el.observe('blur', this.restoreHelperText.bind(this, textarea_el), false);
		}.bind(this)); // END: textareas

		// set up the FORM to clear out our titles onsubmit
		$$S(scope, 'FORM').each(function(form_el){
			form_el.observe('submit', this.clearHelperTextOnSubmit.bindAsEventListener(this), false);
		}.bind(this));

	}, // END: setupElements

	clearHelperText : function(el) {
		if (el.value == el.title) {
			el.value = '';
			el.removeClassName(this.CONFIG['disabled_class']);
		}
	},

	restoreHelperText : function(el) {
		if (el.value == '' || el.value == el.title) {
			el.value = el.title;
			el.addClassName(this.CONFIG['disabled_class']);
		}
	},

	clearHelperTextOnSubmit : function() {
		var f = Event.element(arguments[0]);

		// loop through all of the inputs in this FORM
		$A($$S(f, 'INPUT')).each(function(input_el) {
			// only process inputs which are ShowTitle enabled
			if (!input_el.hasClassName(this.CONFIG['show_title_class'])) { return; }

			// reset the value if it's equal to the title
			if (input_el.value == input_el.title) { input_el.value = ""; }
		}.bind(this));
	} // END: clearDefaultValues()

});

/* ------------------------------------------------- END: FormFieldTitle -- */


/* -- BEGIN: InfoWindow --------------------------------------------------- */

var InfoWindow = Class.create();

InfoWindow.CONFIG = { };
InfoWindow.currently_open = null;
InfoWindow.hide_timeout = null;

Object.extend(InfoWindow.prototype, PageWidget.prototype);
Object.extend(InfoWindow.prototype, {
	initialize : function(info_win) {
		this.node = $(info_win);
		
		if (!this.node) { return; }

		// hide the items upon instantiation
		this.node.setStyle({ 'position' : 'absolute' });
		this.node.moveOffscreen();

		this.nodes = {};
		this.nodes['container'] = this.node.up();
		this.nodes['prevSibling'] = this.node.previousSiblings()[0];
		this.nodes['main_column'] = $('MainColumn');

		this.node.observe('mouseover', this.mouseoverHandler.bindAsEventListener(this));
		this.node.observe('mouseout', this.mouseoutHandler.bindAsEventListener(this));

		this.nodes['prevSibling'].observe('mouseover', this.mouseoverHandler.bindAsEventListener(this));
		this.nodes['prevSibling'].observe('mouseout', this.mouseoutHandler.bindAsEventListener(this));
	},

	mouseoverHandler : function(e) {
		Event.stop(e);
		clearTimeout(this.constructor.hide_timeout);
		if (this.constructor.currently_open != this) { this.show(); }
	},
	
	mouseoutHandler : function(e) {
		Event.stop(e);
		this.constructor.hide_timeout = setTimeout(this.hide.bind(this), 500);
	},

	show : function() {
		if (this.constructor.currently_open) { this.constructor.currently_open.hide(); }

		this.nodes['main_column'].setStyle({ 'position' : 'relative' });

		this.node.setStyle({ 'visibility' : 'hidden' });
		this.moveToPosition();
		this.node.setStyle({ 'visibility' : 'visible' });
		this.constructor.currently_open = this;
	},

	hide : function() {
		this.node.setStyle({ 'visibility' : 'hidden' });
		this.node.moveOffscreen();
		this.constructor.currently_open = null;

		this.nodes['main_column'].setStyle({ 'position' : 'static' });
	},
	
	moveToPosition : function() {
		//var offset_left = this.nodes['container'].getWidth();
		var offset_left = this.nodes['prevSibling'].getWidth() + 10;
		var container_offset_left = Position.positionedOffset(this.nodes['container'])[0];
		var total_width = container_offset_left + offset_left + 345;

		if (total_width > $('PageWrapper').getWidth()) {
			this.node.addClassName('Right');
			offset_left = -345 - 10;
		
		} else {
			this.node.addClassName('Left');
		}

		Position.clone(this.nodes['container'], this.node, {
			setWidth : false,
			setHeight : false,
			offsetLeft : offset_left,
			offsetTop : -40
		});
	}

});

fixWebKitInheritanceBug(InfoWindow);

// ---------------------------------------------------------------------------

AAJ.addFeature('InfoWindows', {
	setupElements : function(scope) {
		$$S(scope, ".InfoWindow").each(function(info_win, i) {
			info_win.id = "info-window_" + (i + 1);
			this.storeWidgetInstance(info_win.id, new InfoWindow(info_win.id));
		}.bind(this));
	}
});

/* ----------------------------------------------------- END: InfoWindow -- */


/* -- BEGIN: TextSizer ---------------------------------------------------- */

var TextSizer = Class.create();

TextSizer.CONFIG = { };

Object.extend(TextSizer.prototype, PageWidget.prototype);
Object.extend(TextSizer.prototype, {
	initialize : function(text_sizer_el) {
		this.node = $(text_sizer_el);

		if (!this.node) { return false; }

		this.getStylesheets();
		
		// set the appropriate stylesheet depending on cookie
		txtSze = readCookie("textsize");
		if( txtSze != "" ){ this.setStylesheet( txtSze ); }
		
		this.nodes = [];

		$$S(this.node, "UL LI IMG").each(function(img){
			img.observe("click", this.clickHandler.bindAsEventListener(this, img));
			this.nodes.push(img);
			new Image().src = img.src.replace(/\.off\.gif$/, ".on.gif");
			new Image().src = img.src.replace(/\.on\.gif$/, ".off.gif");
		}.bind(this));

	},

	clickHandler : function(e, img) {
		Event.stop(e);

		this.setStylesheet(img.alt);
		
		// set cookie to remember text size
		createCookie( "textsize",img.alt,0 );

		this.nodes.each(function(node){
			node.src = (node == img) ? node.src.replace(/\.off\.gif$/, ".on.gif") : node.src.replace(/\.on\.gif$/, ".off.gif");
		});
	},

	getStylesheets : function() {
		this.styles = [];

		$$("link").each(function(link) {
			// test for the "rel" attr containing the right stuff
			if ( (link.rel.toLowerCase().indexOf("stylesheet") != -1) && (link.rel.toLowerCase().indexOf("alternate") != -1) ) {
				this.styles.push(link);
			}
		}.bind(this));
	},

	setStylesheet : function(ss_title) {
		// bail out if the params are bad
		if (typeof ss_title != 'string') { return; }

		// loop through the alt css files and activate the correct one
		this.styles.each(function(ss){
			// first disable it
			ss.disabled = true;

			// then enable it if matches the passed title
			if (ss.title == ss_title) { ss.disabled = false; }
		});
	}

});

fixWebKitInheritanceBug(TextSizer);

// ---------------------------------------------------------------------------

AAJ.addFeature('text-sizer', {
	setupElements : function() {
		new TextSizer('TextSize');
	}
});

// ---------------------------------------------------------------------------

function TextSizeButtons( nrmOn, nrmOff, midOn, midOff, lrgOn, lrgOff){
    txtSze = readCookie("textsize");
    nrmBtn = txtSze=="normal" ? nrmOn : nrmOff;
    midBtn = txtSze=="larger" ? midOn : midOff;
    lrgBtn = txtSze=="largest" ? lrgOn : lrgOff;
    buttons = '<ul class="HorizList">';
    buttons += '<li><img src="'+nrmBtn+'" alt="normal" class="Link" title="Set text to normal size" /></li>';
    buttons += '<li><img src="'+midBtn+'" alt="larger" class="Link" title="Set text to large size" /></li>';
    buttons += '<li><img src="'+lrgBtn+'" alt="largest" class="Link" title="Set text to largest size" /></li>';
    buttons += '</ul>';
    document.write( buttons );
}

/* ------------------------------------------------------ END: TextSizer -- */

var ListPager = {
	items : new Array,
	paginatedList : null,
	pager : null,
	pages : null,
	currentPage : 0,
	buildList : function() {
		// initialization
		if (!$('pageList') || !$('pager') || !$('paginatedList')) return; //TODO if no pager or paginatedList, return
		ListPager.pager = $('pager');
		ListPager.paginatedList = $('paginatedList');

		ListPager.items = $A($('pageList').getElementsBySelector('li'));

		if(document.getElementById('paginatedLength')) {
		    var lengthForPagination = Number(document.getElementById('paginatedLength').innerHTML);
		}
		else { var lengthForPagination = 10; }
		//var lengthForPagination = 10;

		if (ListPager.items.length <= lengthForPagination) {
			$('pageList').show();	
			return;
		}
		else {
		// create the tables for each letter
			for (var i=0; i<ListPager.items.length; ++i) {
			// break the list up into blocks based on "lengthForPagination" variable
			
				if (i%lengthForPagination==0) {
					ul = document.createElement("ul");
					ul = $(ul);
					ul.addClassName("NoBullet");
					//ul.setStyle({width:'375px'});
					ListPager.paginatedList.appendChild(ul);
					ul.hide();
				}
			
				//li = document.createElement("li");
				//li.innerHTML = ListPager.items[i].innerHTML;
				//ListPager.paginatedList.childElements()[ListPager.paginatedList.childElements().length-1].appendChild(li);
				ListPager.paginatedList.childElements()[ListPager.paginatedList.childElements().length-1].appendChild(ListPager.items[i]);
			}
			ListPager.pages = ListPager.paginatedList.childElements();
			ListPager.build();
		
			ListPager.paginatedList.show();
			$('pageList').remove();
			ListPager.pages[ListPager.currentPage].show();
		}
	},
	next : function() {
		if (ListPager.currentPage >= ListPager.pages.length-1) return;
		ListPager.currentPage++;
		ListPager.update();
	},
	
	previous : function() {
		if (ListPager.currentPage <= 0) return;
		ListPager.currentPage--;
		ListPager.update();

	},
	gotopage : function(e,page) {
		page = page -1;
		if ( (page >= 0) && (page <= ListPager.pages.length-1) ) {

			ListPager.currentPage = page;
			ListPager.update();
		}
	},
	
	showall : function() {
		ListPager.currentPage = 0;
		$A(ListPager.pages).each(function(p){
				p.show();
		});
		$('showpaged_link').show();
		$('showall_link').hide();
		$('pagination_controls').hide();
	},
	update : function() {
		$('showpaged_link').hide();
		$('showall_link').show();
		$('pagination_controls').show();
		$A(ListPager.pages).each(function(p){
				p.hide();
			});
		ListPager.pages[ListPager.currentPage].show();
		if (ListPager.currentPage == 0) $("link_prev").hide(); else $("link_prev").show();
		if (ListPager.currentPage == ListPager.pages.length-1) $("link_next").hide(); else $("link_next").show();
		$$("#pagination_controls span").each(function(s){s.removeClassName('link_selected')});
		$("link_"+ListPager.currentPage).addClassName('link_selected');
	},
	
	build : function() {
	var pagelinks = document.createElement('span');
	pagelinks.id = "pagination_controls";
	ListPager.pager.appendChild(pagelinks);
		pagelinks.innerHTML = "";

		// build previous
		var prev = $(document.createElement("span"));
		var prev_anch = $(document.createElement("span"));
		prev_anch.appendChild(document.createTextNode("< previous"));
		prev.id = "link_prev";
		Event.observe(prev_anch, 'click',ListPager.previous);
		prev.appendChild(prev_anch);
		prev.appendChild(document.createTextNode(" | "));
		pagelinks.appendChild(prev);

		// build page numbers
		for (var i=0; i<ListPager.pages.length; i++) {
			pagenum = i+1;
			var s = $(document.createElement("span"));
			var a = $(document.createElement("span"));
			s.id = "link_" + i;
			a.appendChild(document.createTextNode(pagenum));

			Event.observe(a, 'click', ListPager.gotopage.bindAsEventListener(ListPager,parseInt(a.innerHTML)));
			s.appendChild(a);
			s.appendChild(document.createTextNode(" | "));
			pagelinks.appendChild(s);
		}
		// build next
		var next = $(document.createElement("span"));
		var next_anch = $(document.createElement("span"));
		next_anch.appendChild(document.createTextNode("next >"));
		next.id = "link_next";
		Event.observe(next, 'click',ListPager.next);
		next.appendChild(next_anch);
		pagelinks.appendChild(next);
		
		pagelinks.appendChild(document.createTextNode("                 | "));
		// show all/show paginated
		
		var showall = $(document.createElement("span"));
		var showall_anch = $(document.createElement("span"));
		showall_anch.innerHTML = "show all";
		showall.id = "showall_link"
		Event.observe(showall,'click',ListPager.showall);
		showall.appendChild(showall_anch);
		ListPager.pager.appendChild(showall);

		var showpaged = $(document.createElement("span"));
		var showpaged_anch = $(document.createElement("span"));
		showpaged_anch.innerHTML = "show paginated";
		showpaged.id = "showpaged_link"
		Event.observe(showpaged,'click',ListPager.update);
		showpaged.appendChild(showpaged_anch);
		showpaged.hide();
		ListPager.pager.appendChild(showpaged);

		// show to the world
		ListPager.update();
	}
	
};

	Event.observe(window,'load',ListPager.buildList);
	

/* ------------------------------------begin makeColumns Code */
//
// Use this to divide a list in to two lists (currently only for indicated IDs, should be parameterized)
//
function makeColumns(){
    if( document.getElementById("leftColumn") ){
        leftUL = document.getElementById( "leftColumn" );
        rightUL = document.getElementById( "rightColumn" );
        leftArray = leftUL.getElementsByTagName( "LI" );
        startPoint = Math.ceil( leftArray.length/2 );
        for( x=0; x<leftArray.length; x++ ){
            //alert( leftArray[startPoint].getElementsByTagName("A")[0].innerHTML );
            if( leftArray[startPoint]){
                rightUL.appendChild( leftArray[startPoint] );
            }
        }
    }
}
// ---------------------------------------------------------------------------

	
/* ------------------------------------begin Form OverLabels Code */
function initOverLabels () {
  if (!document.getElementById) return;  	

  var labels, id, field;

  // Set focus and blur handlers to hide and show 
  // LABELs with 'overlabel' class names.
  labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
	
    if (labels[i].className == 'overlabel') {

      // Skip labels that do not have a named association
      // with another field.
      id = labels[i].htmlFor || labels[i].getAttribute('for');
      if (!id || !(field = document.getElementById(id))) {
        continue;
      }

      // Change the applied class to hover the label 
      // over the form field.
      labels[i].className = 'overlabel-apply';

      // Hide any fields having an initial value.
      if (field.value !== '') {
        hideLabel(field.getAttribute('id'), true);
      }

      // Set handlers to show and hide labels.
      field.onfocus = function () {
        hideLabel(this.getAttribute('id'), true);
      };
      field.onblur = function () {
        if (this.value === '') {
          hideLabel(this.getAttribute('id'), false);
        }
      };

      // Handle clicks to LABEL elements (for Safari).
      labels[i].onclick = function () {
        var id, field;
        id = this.getAttribute('for');
        if (id && (field = document.getElementById(id))) {
          field.focus();
        }
      };

    }
  }
};

function hideLabel (field_id, hide) {
  var field_for;
  var labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    field_for = labels[i].htmlFor || labels[i].getAttribute('for');
    if (field_for == field_id) {
      labels[i].style.textIndent = (hide) ? '-10000px' : '-5000px';
      return true;
    }
  }
}

window.onload = function () {
  setTimeout(initOverLabels, 50);
};
// ---------------------------------------------------------------------------

/* ------------------------------------begin Remember Me Code */
var ca = document.cookie.split(';');
var RememberMe;

for(var i=0;i < ca.length;i++) {
    var cookie = ca[i].split('=');        
    
    if(cookie[0] == ' RememberMe'){
        if(cookie[1] == '' || cookie[1] == null){
            RememberMe = false;    
        }
    }    
}

if(RememberMe == false){
    for(var i=0;i < ca.length;i++) {
        var cookie = ca[i].split('=');
		var localCookie = false;
		
		cookie[0] = cookie[0].replace(/^\s+/,"");
        
		var updatedCookie = cookie[0];

		if(updatedCookie == 'reddot.cis.user.justice'){
			localCookie = true;
		}

	    for(var j=1;j < cookie.length;j++) {
			updatedCookie = updatedCookie + "=" + cookie[j];			
		}

		if(localCookie){
			updatedCookie = updatedCookie + "; path=/"; 			
		}
		else{
			updatedCookie = updatedCookie + "; domain=.justice.org; path=/";        
		}
		
		document.cookie = updatedCookie; 
    }
}
// ---------------------------------------------------------------------------

/* ------------------------------------begin Cookie functions */

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
// ---------------------------------------------------------------------------

/* ------------------------------------begin Search Term Validation */
function validateSearchTerm( id ){
    var s = window.location.search.substring(1).indexOf( id );
    if( s >= 0 ){
        var q = getQueryStringVariable( id );
        if ( q == undefined || q == "" || q == null ){
			document.write( "<div style='color: red;'>Please enter a search term</div>" );
        }
    }
}

// ---------------------------------------------------------------------------
function getQueryStringVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split('&');
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split('=');
		if (pair[0] == variable) {
			return pair[1];
		}
	}
}