function display_search_results(t) {
   var ajaxDisplay = document.getElementById ("div_wine_list");
//   var r = document.getElementById("region").value;
//   var s = document.getElementById("supplier").value;
//   var b = document.getElementById("brand").value;
   var w = document.getElementById("weeks").value;
//   var sz = document.getElementById("drink_size").value;
   var a = document.getElementById("award").value;
   
   var ajaxRequest;
   try {
      ajaxRequest = new XMLHttpRequest();
   }
   catch (e){
      try {
         ajaxRequest = new ActiveXObject('Msxml2.XMLHTTP');
      }
      catch (e) {
         try {
            ajaxRequest = new ActiveXObject('Microsoft.XMLHTTP');
         }
         catch (e){
            alert('Do something about it !');
            return false;
         }
      }
   }
   ajaxRequest.onreadystatechange = function() {
      if(ajaxRequest.readyState == 4){
         ajaxDisplay.innerHTML = ajaxRequest.responseText;
      }
   }

   var queryString = '?bustcache=' + new Date().getTime() + '&t=' + t;
/*
   if (r) {
      queryString = queryString + '&r=' + r;
   }
   if (s) {
      queryString = queryString + '&s=' + s;
   }
   if (b) {
      queryString = queryString + '&b=' + b;
   }
*/
   if (w) {
      queryString = queryString + '&w=' + w;
   }
/*   
   if (sz) {
      queryString = queryString + '&sz=' + sz;
   }
*/   
   if (a) {
      queryString = queryString + '&a=' + a;
   }
   
   ajaxRequest.open('GET', "ajaxDisplaySearchResults.php" + queryString, true);
   ajaxRequest.send(null); 
}

function check_form() {

   var e = document.getElementById("email");
   var v = trim(e.value, " ");

   if (!v) {
	  alert ("Please enter Email Address");
	  e.focus();
	  return false;
   }
   else {
	  var str = e.value;
	  var at = "@";
	  var dot = ".";
	  var lat = str.indexOf(at);
	  var lstr = str.length;
	  var ldot = str.indexOf(dot); 

	  if (str.indexOf(at)==-1){
		 alert("Please enter a valid Email Address.");
		 e.focus();
		 return false;
	  }

	  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr || str.indexOf(at)==lstr - 1){
		 alert("Please enter a valid Email Address.");
		 e.focus();
		 return false;
	  }

	  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr || str.indexOf(dot)==lstr - 1){
		 alert("Please enter a valid Email Address.");
		 e.focus();
		 return false;
	  }

	  if (str.indexOf(at,(lat+1))!=-1){
		 alert("Please enter a valid Email Address.");
		 e.focus();
		 return false;
	  }

	  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		 alert("Please enter a valid Email Address.");
		 e.focus();
		 return false;
	  }

	  if (str.indexOf(dot,(lat+2))==-1){
		 alert("Please enter a valid Email Address.");
		 e.focus();
		 return false;
	  }
		
	  if (str.indexOf(" ")!=-1){
		 alert("Please enter a valid Email Address.");
		 e.focus();
		 return false;
	  }
   }

   var c = document.getElementById("comments");
   var v = trim(c.value, " ");
   if (!v) {
      alert ("Please enter Comments.");
	  c.focus();
	  return false;
   }

   return true;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

