
var SlideShowSpeed = 2500;
var FirstSlideShowSpeed = 2500;
var SlideShowSpeed2 = 4000;
var FirstSlideShowSpeed2 = 4000;
var CrossFadeDuration = 3;
var Picture = new Array(); 
var Picture2 = new Array(); 
/*
Picture[1]  = 'images/right_side/right_side_pic_1.jpg';
Picture[2]  = 'images/right_side/right_side_pic_2.jpg';
Picture2[1]  = 'images/right_side/right_side_pic_2.jpg';
Picture2[2]  = 'images/right_side/right_side_pic_1.jpg';
*/
Picture[1]  = 'images/right_side/rs_1.jpg';
Picture[2]  = 'images/right_side/rs_2.jpg';
Picture[3]  = 'images/right_side/rs_3.jpg';
Picture[4]  = 'images/right_side/rs_4.jpg';
Picture[5]  = 'images/right_side/rs_5.jpg';

Picture2[1]  = 'images/right_side/rs_5.jpg';
Picture2[2]  = 'images/right_side/rs_3.jpg';
Picture2[3]  = 'images/right_side/rs_1.jpg';
Picture2[4]  = 'images/right_side/rs_2.jpg';
Picture2[5]  = 'images/right_side/rs_4.jpg';

var tss;
var iss;
var jss = 1;
var pss = Picture.length-1;
var preLoad = new Array();
for (iss = 1; iss < pss+1; iss++) {
	preLoad[iss] = new Image();
	preLoad[iss].src = Picture[iss];
}

var tss2;
var iss2;
var jss2 = 1;
var pss2 = Picture2.length-1;
var preLoad2 = new Array();
for (iss2 = 1; iss2 < pss2+1; iss2++) {
	preLoad2[iss2] = new Image();
	preLoad2[iss2].src = Picture2[iss2];
}

function runSlideShow(){
	if (document.all){
		document.images.PictureBox.style.filter="blendTrans(duration=2)";
		document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
		document.images.PictureBox.filters.blendTrans.Apply();
	}
	document.images.PictureBox.src = preLoad[jss].src;
	if (document.all) document.images.PictureBox.filters.blendTrans.Play();
	jss = jss + 1;
	if (jss > (pss)) jss=1;

	if (jss==2) {
		tss = setTimeout('runSlideShow()', FirstSlideShowSpeed);
	} else {
		tss = setTimeout('runSlideShow()', SlideShowSpeed);
	}
}

function runSlideShow2(){
	if (document.all){
		document.images.PictureBox2.style.filter="blendTrans(duration=2)";
		document.images.PictureBox2.style.filter="blendTrans(duration=CrossFadeDuration)";
		document.images.PictureBox2.filters.blendTrans.Apply();
	}
	document.images.PictureBox2.src = preLoad2[jss2].src;
	if (document.all) document.images.PictureBox2.filters.blendTrans.Play();
	jss2 = jss2 + 1;
	if (jss2 > (pss2)) jss2=1;

	if (jss2==2) {
		tss2 = setTimeout('runSlideShow2()', FirstSlideShowSpeed2);
	} else {
		tss2 = setTimeout('runSlideShow2()', SlideShowSpeed2);
	}
}

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"), "");
}

function display_staff(t, n) {
   var c = parseInt(document.getElementById("hcs").value);
   var n = parseInt(n);
   if (t == "right") {
      document.getElementById("div_left_arrow").style.display = "block";
	  c = c + 1;
	  document.getElementById("hcs").value = c;
	  if (c == n) {
	     document.getElementById("div_right_arrow").style.display = "none";
	  }
	  document.getElementById("td_staff").style.backgroundImage = "url(" + staff_pics[c] + ")";
   }
   else {
      document.getElementById("div_right_arrow").style.display = "block";
	  c = c - 1;
	  document.getElementById("hcs").value = c;
	  if (c == 1) {
	     document.getElementById("div_left_arrow").style.display = "none";
	  }
	  document.getElementById("td_staff").style.backgroundImage = "url(" + staff_pics[c] + ")";
   }
   
   var d = "div_staff";
   var ajaxDisplay = document.getElementById(d);
   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() + "&c=" + staff_ids[c];

   ajaxRequest.open('GET', "ajaxDisplayStaff.php" + queryString, true);
   ajaxRequest.send(null); 
}

function show (t) {
   document.getElementById(t).style.visibility = "visible";
}
function show2 (t) {
   document.getElementById(t).style.display = "block";
}
function hide (t) {
   document.getElementById(t).style.visibility = "hidden";
}
function hide2 (t) {
   document.getElementById(t).style.display = "none";
}

function display_wine_list(t, w, c, s) {
   if (w == "0") {
      document.getElementById("htype").value = t;
      document.getElementById("country_varietal").style.display = "block";
      document.getElementById("div_sort_container").style.display = "block";
      document.getElementById("div_filter").innerHTML = "";
	  document.getElementById("hcid").value = "";
	  document.getElementById("hrid").value = "";
	  document.getElementById("hvid").value = "";
	  document.getElementById("hsort").value = "";

	  for (i = 1; i <= 6; i++) {
	     var dn = document.getElementById("div_sort_" + i);			   
	     if (i == 1) {
		    dn.style.fontWeight = "bold";
		 }
		 else {
		   dn.style.fontWeight = "normal";
		 }
	  }
   }
   else {
	  if (w == "5") {
         document.getElementById("country_varietal").style.display = "block";
         document.getElementById("div_sort_container").style.display = "block";
	  }
	  else {
         var t = document.getElementById(t).value;
	  }
   }
   var ajaxDisplay = document.getElementById("div_list");
   ajaxDisplay.style.height = "228px";
   ajaxDisplay.style.top = "177px";

   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();
   if (w != "5") {
      queryString += "&t=" + t;
   }
   if (c) {
	  if (w == "1") {
         queryString += "&c=" + c;
		 document.getElementById("hcid").value = c;
		 document.getElementById("hrid").value = "";
		 document.getElementById("hvid").value = "";
	  }
	  if (w == "2") {
         queryString += "&r=" + c;
		 document.getElementById("hrid").value = c;
		 document.getElementById("hcid").value = "";
		 document.getElementById("hvid").value = "";
	  }
	  if (w == "3") {
         queryString += "&v=" + c;
		 document.getElementById("hvid").value = c;
		 document.getElementById("hcid").value = "";
		 document.getElementById("hrid").value = "";
	  }
   }
   else {
	  if (w == 4) {
	     if (document.getElementById("hcid").value) {
	        queryString += "&c=" + document.getElementById("hcid").value;
		 }
	     if (document.getElementById("hrid").value) {
	        queryString += "&r=" + document.getElementById("hrid").value;
		 }
	     if (document.getElementById("hvid").value) {
	        queryString += "&v=" + document.getElementById("hvid").value;
		 }
		 if (s) {
	        queryString += "&s=" + s;
			document.getElementById("hsort").value = s;
			for (i = 1; i <= 6; i++) {
			   var dn = document.getElementById("div_sort_" + i);			   
			   if (s == "price") {
			      if (i == 1) {
				     dn.style.fontWeight = "bold";
				  }
				  else {
				     dn.style.fontWeight = "normal";
				  }
			   }
			   if (s == "country") {
			      if (i == 2) {
				     dn.style.fontWeight = "bold";
				  }
				  else {
				     dn.style.fontWeight = "normal";
				  }
			   }
			   if (s == "varietal") {
			      if (i == 3) {
				     dn.style.fontWeight = "bold";
				  }
				  else {
				     dn.style.fontWeight = "normal";
				  }
			   }
			   if (s == "year") {
			      if (i == 4) {
				     dn.style.fontWeight = "bold";
				  }
				  else {
				     dn.style.fontWeight = "normal";
				  }
			   }			   
			   if (s == "glass") {
			      if (i == 5) {
				     dn.style.fontWeight = "bold";
				  }
				  else {
				     dn.style.fontWeight = "normal";
				  }
			   }			   
			   if (s == "half") {
			      if (i == 6) {
				     dn.style.fontWeight = "bold";
				  }
				  else {
				     dn.style.fontWeight = "normal";
				  }
			   }			   
			}
		 }
	  }	   
   }
   
   if (w == "5") {
      if (document.getElementById("ahtype").value) {
	     queryString += "&t=" + document.getElementById("ahtype").value;
      }
      if (document.getElementById("ahcid").value) {
	     queryString += "&c=" + document.getElementById("ahcid").value;
      }
	  if (document.getElementById("ahrid").value) {
	     queryString += "&r=" + document.getElementById("ahrid").value;
	  }
	  if (document.getElementById("ahvid").value) {
	     queryString += "&v=" + document.getElementById("ahvid").value;
	  }
	  if (document.getElementById("ahsort").value) {
	     queryString += "&s=" + document.getElementById("ahsort").value;
	  }	  
   }
   ajaxRequest.open('GET', "ajaxDisplayWineList.php" + queryString, true);
   ajaxRequest.send(null); 

}
function display_countries(t) {
   var ajaxDisplay = document.getElementById("div_countries");
   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;
   ajaxRequest.open('GET', "ajaxDisplayCountries.php" + queryString, true);
   ajaxRequest.send(null); 
}

function display_varietals(t) {
   var ajaxDisplay = document.getElementById("div_varietals");
   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;
   ajaxRequest.open('GET', "ajaxDisplayVarietals.php" + queryString, true);
   ajaxRequest.send(null); 
}


function display_filter(c, r) {
   document.getElementById("div_filter").innerHTML = "FILTER: <img src=\"images/x_bullet.jpg\" /> " + c;
   if (r) {
      document.getElementById("div_filter").innerHTML += " &nbsp;<img src=\"images/x_bullet.jpg\" /> " + r;
   }
}

function display_details(id) {
   document.getElementById("country_varietal").style.display = "none";
   document.getElementById("div_sort_container").style.display = "none";
   var ajaxDisplay = document.getElementById("div_list");
   ajaxDisplay.style.height = "313px";
   ajaxDisplay.style.top = "77px";
   
   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() + "&id=" + id;
   queryString += "&t=" + document.getElementById("htype").value;

   if (document.getElementById("hcid").value) {
      queryString += "&c=" + document.getElementById("hcid").value;
   }
   if (document.getElementById("hrid").value) {
	  queryString += "&r=" + document.getElementById("hrid").value;
   }
   if (document.getElementById("hvid").value) {
      queryString += "&v=" + document.getElementById("hvid").value;
   }
   if (document.getElementById("hsort").value) {
      queryString += "&s=" + document.getElementById("hsort").value;
   }

   ajaxRequest.open('GET', "ajaxDisplayWineList.php" + queryString, true);
   ajaxRequest.send(null); 
}

function display_dropdown (v, d, f) {
   var ajaxDisplay = document.getElementById(d);

   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() + "&v=" + v;
   ajaxRequest.open('GET', f + queryString, true);
   ajaxRequest.send(null); 
}

function send_message () {
   var com = trim (document.getElementById("comments").value);
   if (com) {
	   com = com.replace(/\r\n/g, "<br>");
   }

   var ajaxDisplay = document.getElementById ("div_message");

   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();
   if (com) {
      queryString = queryString + '&com=' + com;
   }

   ajaxRequest.open('GET', "ajaxSendMessage.php" + queryString, true);
   ajaxRequest.send(null); 
}
function change_href(c, id) {
   var a = document.getElementById("del_href1");
   var b = document.getElementById("del_href2");
   if (c.checked) {
      a.href = a.href + "del_" + id + "=" + id + "&";
      b.href = b.href + "del_" + id + "=" + id + "&";
   }
   else {
      var d = "del_" + id + "=" + id + "&";
	  a.href = a.href.replace (d, "");
	  b.href = b.href.replace (d, "");
   }
}

function display_form(d) {
   var d = document.getElementById(d);
   if (d.style.display == "none") {
      d.style.display = "block";
   }
   else {
      d.style.display = "none";
   }
}

function signup () {
   var fn = trim (document.getElementById("first_name").value);
   if (!fn) {
      alert ("Please enter First Name");
	  document.getElementById("first_name").focus();
	  return false; 
   }
   var em = document.getElementById("email");
   var str = trim(em.value, " ");
   if (!str) {
      alert ("Please enter Email Address");
	  em.focus();
	  return false; 
   }
   else {
	  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.");
		 em.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.");
		 em.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.");
		 em.focus();
		 return false;
	  }
	
	  if (str.indexOf(at,(lat+1))!=-1){
		 alert("Please enter a valid Email Address.");
		 em.focus();
		 return false;
	  }
	
	  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		 alert("Please enter a valid Email Address.");
		 em.focus();
		 return false;
	  }
	
	  if (str.indexOf(dot,(lat+2))==-1){
		 alert("Please enter a valid Email Address.");
		 em.focus();
		 return false;
	  }
			
	  if (str.indexOf(" ")!=-1){
		 alert("Please enter a valid Email Address.");
		 em.focus();
		 return false;
	  }
   }
   
   var ln = trim (document.getElementById("last_name").value);

   var ajaxDisplay = document.getElementById ("div_message_sign_up");

   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() + "&em=" + str + "&fn=" + fn;
   if (ln) {
      queryString = queryString + "&ln=" + ln;
   }

   ajaxRequest.open('GET', "ajaxSignUp.php" + queryString, true);
   ajaxRequest.send(null);
   document.getElementById("div_message_sign_up").innerHTML = "<span class=\"bold_14\">Your information has been received. Thank you.</span>"; 
}

function clear_form() {
   document.getElementById("first_name").value = "";
   document.getElementById("last_name").value = "";
   document.getElementById("email").value = "";
   document.getElementById("div_message_sign_up").innerHTML = "";
}

function clear_form2() {
   document.getElementById("comments").value = "";
   document.getElementById("div_message").innerHTML = "";
}

function change_bg_image (d, i) {
   document.getElementById(d).style.backgroundImage = "url(" + i + ")";
}

function change_font_weight (d, f) {
   document.getElementById(d).style.fontWeight = f;
}


function closeKeepAlive() {
	 
	if (/AppleWebKit|MSIE/.test(navigator.userAgent)) {
	 
		new Ajax.Request("/ping/close", { asynchronous:false });
	 
	}
	 
}

