// Pop-up window

function popWin(url, width, height, options)
{
	var w = (width) ? width : 775;
	var h = (height) ? height : 500;

	var t = (screen.height) ? (screen.height - h) / 2 : 0;
	var l =	 (screen.width) ? (screen.width - w) / 2 : 0;

	var opt = (options) ? options : 'toolbar = no, location = no, directories = no, '+
		'status = yes, menubar = no, scrollbars = yes, copyhistory = no, resizable = yes';

	var popped = window.open(url, 'popupwindow',
		'top = '+t+', left = '+l+', width = '+w+', height = '+h+',' + opt);

	popped.focus();
}

// News alerts pop-up window

function newspopWin(url, width, height, options)
{
	var w = (width) ? width : 980;
	var h = (height) ? height : 600;

	var t = (screen.height) ? (screen.height - h) / 2 : 0;
	var l =	 (screen.width) ? (screen.width - w) / 2 : 0;

	var opt = (options) ? options : 'toolbar = yes, location = no, directories = no, '+
		'status = yes, menubar = no, scrollbars = yes, copyhistory = no, resizable = yes';

	var popped = window.open(url, 'popupwindow',
		'top = '+t+', left = '+l+', width = '+w+', height = '+h+',' + opt);

	popped.focus();
}

// Clear input text

var active_color = '#666'; // Colour of user provided text
var inactive_color = '#999'; // Colour of default text

$(document).ready(function() {
  $("input.search").css("color", inactive_color);
  var default_values = new Array();
  $("input.search").focus(function() {
    if (!default_values[this.id]) {
      default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
      this.value = '';
      this.style.color = active_color;
    }
    $(this).blur(function() {
      if (this.value == '') {
        this.style.color = inactive_color;
        this.value = default_values[this.id];
      }
    });
  });
});

// Auto complete

function lookup(postcode) {
	if (postcode.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		$.post("autoComplete/rpc.php", {queryString: ""+postcode+""}, function(data){
			if (data.length > 0) {
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
			} else {
				$('#suggestions').hide();
			}
		});
	}
} // lookup

function fill(thisValue) {
	$('#postcode').val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
}