$(document).ready(function() {
	// Get URL parameters
	$.urlParam = function(name){
	    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
	    if (!results)
	    { 
	        return 0; 
	    }
	    return results[1] || 0;
	}
	
	$("a[type='popup']").live('click', function() {
		return pop(this.href, this.text, window.location.href);
	});
	
	function pop(url, title, queryString) {
		newWindow = window.open(url + "?url=" + queryString, title, 'height=660,width=600');
		if (window.focus) { newWindow.focus() }
		return false;
	}
	
	$('#print').click(function() {
		print();
	});
	
	$("#topContact").prop("href", $("#contact").prop("href"));
	
	$('#text_subject').val($('select[name=subject] option:selected').text());
	$('select[name=subject]').live('change', function() {
		var selectedval = $('select[name=subject] option:selected').text();
		$('#text_subject').val(selectedval);
	});
	
	$('#searchForm').submit(function(event) {
		formval = $('input[name="query"]').val();
		if (formval.length > 2)
			return true;
		else {
			event.preventDefault();
			$('span.error').fadeIn().delay(2000).fadeOut();
			return false;
		}
	});
	
	if ($('#url').length) {
		$('#url').val($.urlParam('url'));
	}
});
