var trappingDialog = false;
var watchEscape = false;
function DialogOverlay(content, container) {
	// Manage arguments and assign defaults, 
	if (typeof container == 'undefined' ) container = document.body;
	if (null == (this.container = $(container))) throw("container is not valid");
	this.topOffset = ($(document.body).getHeight())+'px';
	// Assign instance variables
	this.content = content;
	this.overlay = new Element('div', { 'class': 'popupOverlay' });
	this.dialog = new Element('div', { 'class': 'popupDialog' });
	this.overlay.addClassName('popupOverlay');
	this.dialog.addClassName('popupDialog');

	// Hide the overlay when clicked. Ignore clicks on the dialog.
	Event.observe(this.dialog, 'click', this.hide2.bindAsEventListener(this));
	Event.observe(this.overlay, 'click', this.hide.bindAsEventListener(this));
	
	// Insert the elements into the DOM
	this.dialog.insert(this.content);
	this.overlay.insert(this.dialog);
	this.container.insert(this.overlay);

	// Content may have been hidden if it is embedded in the page
	watchEscape = true;
	$('overlayKeyword').focus();
	return this;
}
DialogOverlay.prototype.hide = function(event) {
	if(trappingDialog){
		trappingDialog = false;
	} else {

		if(typeof IE6 == "undefined"){
			document.body.setStyle({overflow:'auto'});
		}
		watchEscape = false;
		$(this.overlay).remove();
	}
	return this;
};
DialogOverlay.prototype.hide2 = function(event) {
	trappingDialog = true;
	return this;
};
document.observe('keyup', function(e){
	if(watchEscape && e.keyCode == Event.KEY_ESC)
		overlay.hide();
});

var overlay = false;
function searchOverlay(){
	var dialog = new Element('div');
	dialog.insert(
			'<div><h2>Search Jobs</h2><a href="#" onclick="overlay.hide();return false" style="float:right;width:36px;height:36px;display:block;cursor:pointer" title="Close Window"></a>'+
			'<form method="get" action="/search.php" onsubmit="if(!$F(\'overlayKeyword\') && !$F(\'overlayCategory\') && !$F(\'overlayLocation\')){alert(\'You must supply at least one parameter\');return false;}">'+
			'<div><label for="overlayKeyword">Keyword</label><input type="text" name="searchWord" id="overlayKeyword"/></div>'+
			'<div><label for="overlayCategory">Category</label><select name="categoryID" id="overlayCategory">'+
			'<option value="" disabled="disabled">Search by category...</option><option value="" selected="selected">All Categories</option><option value="100">Accounting / Finance</option><option value="150">Banking</option><option value="200">Business Opp / Work at Home</option><option value="275">Career Education</option><option value="300">Computers / IT</option><option value="1550">Creative Services</option><option value="400">Customer Service</option><option value="500">Dining / Restaurant</option><option value="600">Education / Training</option><option value="700">Engineering</option><option value="800">General</option><option value="850">HealthCare</option><option value="900">Hotel / Motel / Resort</option><option value="1000">Human Resources</option><option value="1100">Insurance</option><option value="1200">Job Fairs</option><option value="1350">Management</option><option value="1400">Manufacturing</option><option value="1500">Marketing / Advertising / PR</option><option value="1600">Office Administration</option><option value="1700">Professional</option><option value="1900">Retail</option><option value="2200">Sales</option><option value="2000">Science</option><option value="2100">Security / Law Enforcement</option><option value="2300">Skilled Labor / Trades</option><option value="2400">Social Services</option><option value="2450">Teachers / Instructors</option><option value="2500">Transportation</option></select></div>'+
			'<div><label for="overlayLocation">Location</label><input type="text" name="searchLocation" id="overlayLocation"/></div>'+
			'<div><input type="image" class="submitButton" src="/images/buttons/search-jobs-large.png" alt="Search Jobs"/></div>'+
			'</form></div>');
	overlay = new DialogOverlay(dialog);
	return false;
}