$(document).ready(function(){

  $('input#search_keyword').focus(function(){
    if($(this).val() == 'keyword search')
      $(this).val('');
  }).keyup(function(){
    search_delay(this);
  });


  function search_delay(element) {
		// Create a function to get the search results
		var func = function() {
      $.ajax({
        type: "POST",
        url: "site/ajax/ajax_keyword_search.php",
        data: "str="+element.value,
        success: function(msg){
          returned_ajax_search_results(msg);
        }
      });
    }
		// Check to see if there is already a timeout and if so...
		// ...cancel it and create a new one
		if ( element.zid ) {
			clearTimeout(element.zid);
		}
		element.zid = setTimeout(func,500);
	}
  function returned_ajax_search_results(response){
    //response contains <html>THIS IS SOME RESPONSE</html><param_keyword>THESE ARE KEYWORD SEARCHED</param_keyword>
    var html_text = '<p>There was an error while performing the job search.</p>';
    var pos = response.indexOf('</html><param_keyword>');
    if (pos > 0){
      html_text = response.substr(6, pos-6);
      param_keyword = response.substr(pos+22).replace('</param_keyword>', '');
      if(param_keyword == '')
        $('#extra_search_info').html('&nbsp;');
      else
        $('#extra_search_info').html('Containing keyword(s): '+param_keyword);
    }
    $('#contentCover').html(html_text);
  }

});