var ACTIVE_COLOR = '#000';
var INACTIVE_COLOR = '#777777';
var INACTIVE_STRING = 'Search ...';

String.prototype.trim = function() {
	return this.replace(/^\s*/, '').replace(/\s*$/, '');
}

function basicCriteria_onfocus() {
	var criteria = document.getElementById('basic-criteria');
	var value = criteria.value.trim();

	if (value == '' || value == INACTIVE_STRING) {
		criteria.value = '';
		criteria.style.color = ACTIVE_COLOR;
	}
}

function basicCriteria_onblur() {
	var criteria = document.getElementById('basic-criteria');
	var value = criteria.value.trim();

	if (value == '') {
		criteria.style.color = INACTIVE_COLOR;
		criteria.value = INACTIVE_STRING;
	}
}

function basicSearch_onsubmit() {
	var criteria = document.getElementById('basic-criteria');
	var value = criteria.value.trim();

	if (value == '' || value == INACTIVE_STRING) {
		alert('Please enter some keywords.');
		criteria.style.color = ACTIVE_COLOR;
		criteria.focus();
		return false;
	}

	return true;
}

function advancedSearch_onsubmit() {
	var criteria = document.getElementById('advanced-criteria');
	var value = criteria.value.trim();

	if (value == '') {
		alert('Please enter some keywords.');
		criteria.focus();
		return false;
	}

	return true;
}

function scaledImage_onclick(img, maxWidth, maxHeight) {
	var currentMaxHeight;

	if (img.currentStyle) { /* this is IE */
		currentMaxHeight = img.currentStyle['maxHeight'];
	} else if (window.getComputedStyle) { /* this is Mozilla */
		currentMaxHeight = document.defaultView.getComputedStyle(img, null).getPropertyValue('max-height');
	}

	if (currentMaxHeight == maxHeight) {
		img.style.maxWidth = '100%';
		img.style.maxHeight = 'none';
	} else {
		img.style.maxWidth = maxWidth;
		img.style.maxHeight = maxHeight;
	}
}
