function IsArray(obj) { return obj instanceof Array; }
function IncludeLibraries(libraries) {
	libraries.each(function(library) {
		document.write('<script type="text/javascript" src="' + library + '"></script>');
	});
}
function IncludeStyles(styles) {
	styles.each(function(style) {
		document.write('<link rel="stylesheet" type="text/css" media="all" href="' + style + '" />');
	});
}
function SetNotice(content, status) {
	// :KLUDGE: having to force background colors
	//          highlight effect isn't reading new color
	//          from dynamically set classname
	// status related starting colors
	var startcolors = new Array();
	startcolors['success'] = '#bac68d';
	startcolors['error']   = '#ffde9f';
	var startbgcolor = (status) ? startcolors[status] : startcolors['success'];
	
	// status related ending colors
	var endcolors = new Array();
	endcolors['success'] = '#d8dec2';
	endcolors['error']   = '#fff3db';
	var endbgcolor = (status) ? endcolors[status] : endcolors['success'];
	
	// update notice
	var e = $('notice');
	e.update(unescape(content));
	e.className = 'notice-' + ((status) ? status : 'info');
	e.show();
	new Effect.Highlight(e, {duration:1.5, keepBackgroundImage:true, startcolor:startbgcolor, endcolor:endbgcolor, restorecolor:endbgcolor});
}
function ClearNotice() {
	if ($('notice')) {
		var e = $('notice');
		e.update('');
		e.hide();
	}
}
function PopWindow(title, url, width, height, modal) {
	var id = 'popwindow';
	if (!$(id)) {
		BuildWindow({id:id, title:title, url:url, width:width, height:height, modal:modal});
	}
}
function SafeMail(name, domain, addinfo) {
	style     = (addinfo.style)   ? ' class="' + addinfo.style + '"' : '';
	subject   = (addinfo.subject) ? '?subject=' + addinfo.subject : '';
	displayed = (addinfo.display) ? addinfo.display : name + '@' + domain;
	mailto    = name + '@' + domain + subject;
	document.write('<a href="mailto:' + mailto + '"' + style + '>' + displayed + '</a>');
}
function ToggleElement(id) {
	if ($(id)) { $(id).toggle(); }
}
function Mailto(address) {
	var url    = '/ajax_mailto.php';
	var pars   = 'address=' + address;
	new Ajax.Request(url, {
		method:'post',
		parameters:pars,
		onComplete:function(req) {
			window.location = req.responseText;
		}
	});
}
function CountCharacters(id, max_chars, countdown) {
	// testing and caption vars
	var str_text            = $(id).value
	var num_used_chars      = str_text.length;
	var num_available_chars = Math.max(0, max_chars - num_used_chars);
	var str_caption         = 'you have ' + num_available_chars + ' characters left';
	
	if (num_available_chars == 0) {
		// lock textarea
		$(id).readOnly = true;
		$(id).value    = str_text.substring(0, max_chars);
		
		// update caption and allow reset
		var str_reset = ' (<a href="#" onclick="ResetTextArea(\'' + id + '\', ' + max_chars + ', \'' + countdown + '\'); return false;">reset</a>)';
		$(countdown).update(str_caption + str_reset);
	} else {
		// update caption
		$(countdown).update(str_caption);
	}
}
function ResetTextArea(id, max_chars, countdown) {
	// update caption
	$(countdown).update('you have ' + max_chars + ' characters left');
	
	// clear text
	$(id).value = '';
	
	// allow edit
	$(id).readOnly = false;
	
	// apply focus
	$(id).focus();
}
function StripeTable(id) {
  $A($(id).immediateDescendants()).each(function(row, i) {
    row.className = (i % 2) ? 'even' : 'odd';
  });
}
function RemoveRow(id, table) {
  // remove row
  Element.remove(id);
  
  // restripe table
  StripeTable(table);
}
function ReapplyShadowBox() {
	// apply Shadowbox to links with trigger class name
	Shadowbox.setup($$('a.apply-shadowbox'), {
		assetURL:'/js/shadowbox/',
		overlayOpacity:0.5
	});
	
	// remove trigger class name
	$$('a.apply-shadowbox').each(function(e) {
		e.removeClassName('apply-shadowbox');
	});
}
function CheckSearch() {
	if ($('filters_keywords').value == 'Search') {
		$('filters_keywords').value = '';
	} else if (($('filters_keywords').value == '') || ($('filters_keywords').value == 'Search')) {
		$('filters_keywords').value = 'Search';
	}
}
