
// Copyright (C) 2009 Aaron Merriman. All rights reserved.

var wine_title = new Array("Pink Fox",
                           "Riverboat White",
                           "LaBelle 2008",
                           "Solay 2008",
                           "Chardonel 2007",
                           "Norton 2007",
                           "Rocheport Port",
                           "Riverboat Red",
                           "Jeunette Rouge",
                           "Fleur Du Vin"),
    wine_text  = new Array("Unlike an ordinary blush, this wine is made with the Native American Catawba grape, providing a bold fruit flavor and pleasantly sweet finish. Pink Fox is fun and friendly, ready for any festive occasion.",
                           "This popular sweet white wine is a bouquet of honeysuckle, with hints of honeydew and lush tropical fruit. Riverboat White is perfect for cocktail parties or as a dessert wine.",
                           "With its rich floral nose, this fresh white wine delivers a hint of sweetness with a crisp, subtle finish. LaBelle is perfectly paired with recipes from the Pacific Rim, and other light, spicy dishes.",
                           "With no oak to mask its intense tropical fruit overtones, Solay is blended with 100% of the best white varietals grown in Missouri. It's the perfect compliment to salads, pastas and lightly sweetened sauces.",
                           "Our Chardonel combines crisp pear and apple aromas with light oak to create an exquisote full-bodied dry white wine with a steely finish.",
                           "This full-bodied dry red wine showcases the unique characteristcs of our Norton, the state grape of Missouri. A bouquet of violet and spicy earth tones with rich fruit flavor, it lingers through a light tannin finish.",
                           "This sweet, silky Port offers aromas of dark confections and ripe berries, proceeding the rich, rustic flavors of the Norton grape.",
                           "Our best-selling wine, Riverboat Red is truly the showboat of Missouri red wines. A tantalizing blend of raspberry and cherry aromas, this chilled sweet red dazzles the palate with rich layers of ripe fruit.",
                           "Diversely appealing, Jeunette Rouge is a medium-bodied wine with fruity character and a soft finish, suitable for an array of occasions.",
                           "Our semi-dry red wine with soft character and light, fruit aromas, Fluer Du Vin is broadly appealing and reveals the uniqueness of Missouri's St. Vincent grape."),
    anim_busy  = false,
    anim_state = false,
    pb_pos     = "",
    panel_num  = 0,
    tour_pos   = 0,
    panel_pos  = 0;

if (document.images) {
 lbv_img_01     = new Image();
 lbv_img_01.src = "images/Our-Wines_hot.jpg";
 lbv_img_02     = new Image();
 lbv_img_02.src = "images/Our-Wines_dark.jpg";
 lbv_img_03     = new Image();
 lbv_img_03.src = "images/bkgd_wines-panel-01.gif";
 lbv_img_04     = new Image();
 lbv_img_04.src = "images/bkgd_wines-panel-02.gif";
 lbv_img_05     = new Image();
 lbv_img_05.src = "images/bkgd_wines-panel.jpg";
 lbv_img_06     = new Image();
 lbv_img_06.src = "images/bkgd_our-wines.jpg";
 lbv_img_07     = new Image();
 lbv_img_07.src = "images/bkgd_tour-panel-01.gif";
 lbv_img_08     = new Image();
 lbv_img_08.src = "images/bkgd_tour-panel-02.gif";
}

function hide_menus() {
 for (tmp_val = 1; tmp_val < 3; tmp_val++) {
  document.getElementById('dt_0' + tmp_val).style.color = "#4581ab";
  document.getElementById('dd_0' + tmp_val).style.display = "none";
 }
}

function show_menu(menu_num) {
 document.getElementById('dt_0' + menu_num).style.color = "#000000";
 document.getElementById('dd_0' + menu_num).style.display = "block";
}

function move_tour(move_val) {
 if (move_val) {
  if (tour_pos > 0) {
   clearInterval(tour_mov);
   document.getElementById('tour_video').style.backgroundPosition = "0 top";
   document.getElementById('tour_close').style.display = "block";
   document.getElementById('video_bistro').style.display = "block";
   anim_state = true;
   anim_busy = false;
  } else {
   document.getElementById('tour_video').style.backgroundPosition = tour_pos + "px top";
   tour_pos += 20;
  }
 } else {
  if (tour_pos < -250) {
   clearInterval(tour_mov);
   document.getElementById('tour_video').style.display = "none";
   anim_state = false;
   anim_busy = false;
  } else {
   document.getElementById('tour_video').style.backgroundPosition = tour_pos + "px top";
   tour_pos -= 20;
  }
 }
}

function show_tour(tour_val) {
 if (tour_val) {
  document.getElementById('tour').blur();
  if (!anim_busy && !anim_state) {
   anim_busy = true;
   tour_pos = -250;
   document.getElementById('tour_video').style.display = "block";
   tour_mov = setInterval("move_tour(true)",17);
  } else {
   if (!anim_busy && anim_state) {
    show_tour(0);
   }
  }
 } else {
  document.getElementById('tour_close').blur();
  if (!anim_busy && anim_state) {
   document.getElementById('tour_close').style.display = "none";
   document.getElementById('video_bistro').style.display = "none";
   anim_busy = true;
   tour_pos = 0;
   tour_mov = setInterval("move_tour(false)",17);
  }
 }
}

function panel_bkgd(pb_val) {
 if (!anim_busy) {
  if (pb_val) {
   pb_pos = "bottom";
  } else {
   pb_pos = "top";
  }
  document.getElementById('wine_panel').style.backgroundPosition = "-11px " + pb_pos;
 }
}

function hide_frame() {
 document.getElementById('wine_frame').style.display = "none";
}

function show_wine() {
 document.getElementById('wi_title').innerHTML = "<h3>" + wine_title[panel_num - 1] + "</h3>";
 document.getElementById('wi_text').innerHTML = wine_text[panel_num - 1] + "<br /><br /><a id=\"wi_find\" href=\"Wine-Retailers.php\" onclick=\"javascript:hide_frame();\">Find your nearest " + wine_title[panel_num - 1] + " retailer&nbsp;&raquo;</a>";
 if (panel_num < 6) {
  pb_pos = "top";
 } else {
  pb_pos = "bottom";
  panel_num -= 5;
 }
 document.getElementById('wi_bottle').style.backgroundPosition = ((panel_num - 1) * -92) + "px " + pb_pos;
 document.getElementById('wine_info').style.display = "block";
}

function move_panel(move_val) {
 if (move_val) {
  if (panel_pos > -11) {
   clearInterval(panel_mov);
   document.getElementById('wine_panel').style.backgroundPosition = "-11px top";
   document.getElementById('wp_right').style.display = "block";
   anim_busy = false;
   panel_pos = 0;
   show_wine();
  } else {
   document.getElementById('wine_panel').style.backgroundPosition = panel_pos + "px top";
   panel_pos += 20;
  }
 } else {
  if (panel_pos > 397) {
   clearInterval(panel_mov);
   document.getElementById('wine_list').style.display = "block";
   document.getElementById('wine_frame').style.display = "none";
   anim_busy = false;
  } else {
   if (panel_pos > 355) {
    document.getElementById('wp_right').style.display = "none";
   }
   document.getElementById('wine_panel').style.backgroundPosition = panel_pos + "px top";
   panel_pos += 20;
  }
 }
}

function show_panel(panel_val,panel_wine) {
 if (panel_val) {
  panel_num = panel_wine;
  if (!anim_busy) {
   anim_busy = true;
   panel_pos = -397;
   document.getElementById('wine_panel').style.backgroundPosition = panel_pos + "px top";
   document.getElementById('wine_frame').style.display = "block";
   document.getElementById('wine_list').style.display = "none";
   document.getElementById('wp_left').style.display = "block";
   panel_mov = setInterval("move_panel(true)",17);
  }
 } else {
  document.getElementById('wine_panel').blur();
  if (!anim_busy) {
   document.getElementById('wine_info').style.display = "none";
   document.getElementById('wp_left').style.display = "none";
   anim_busy = true;
   panel_mov = setInterval("move_panel(false)",17);
  }
 }
}

function validate_calendar() {
 if (document.forms['lbv_calendar'].cal_data.value.replace(/^\s+|\s+$/g,'').length < 1) {
  if (confirm('You are about to save an empty calendar file.\nThis operation cannot be undone. Continue?')) {
   document.forms['lbv_calendar'].cal_data.value = "Les Bourgeois Vineyards has no calendar events at this time. Please bookmark this page or return later to stay up-to-date with our news and events.";
   document.forms['lbv_calendar'].submit();
  } else {
   document.forms.cal_data.focus();
  }
 } else {
  document.forms['lbv_calendar'].submit();
 }
}

function validate_in_the_news() {
 if (document.forms['lbv_calendar'].cal_data.value.replace(/^\s+|\s+$/g,'').length < 1) {
  if (confirm('You are about to save an empty news file.\nThis operation cannot be undone. Continue?')) {
   document.forms['lbv_calendar'].cal_data.value = "Les Bourgeois Vineyards has no news events at this time. Please bookmark this page or return later to stay up-to-date with our news and events.";
   document.forms['lbv_calendar'].submit();
  } else {
   document.forms.cal_data.focus();
  }
 } else {
  document.forms['lbv_calendar'].submit();
 }
}

function validate_private_events() {
 if (document.forms['lbv_calendar'].cal_data.value.replace(/^\s+|\s+$/g,'').length < 1) {
  if (confirm('You are about to save an empty news file.\nThis operation cannot be undone. Continue?')) {
   document.forms['lbv_calendar'].cal_data.value = "Les Bourgeois Vineyards has no private events at this time. Please bookmark this page or return later to stay up-to-date with our news and events.";
   document.forms['lbv_calendar'].submit();
  } else {
   document.forms.cal_data.focus();
  }
 } else {
  document.forms['lbv_calendar'].submit();
 }
}

function validate_bistro_menu() {
 if (document.forms['lbv_calendar'].cal_data.value.replace(/^\s+|\s+$/g,'').length < 1) {
  if (confirm('You are about to save an empty menu file.\nThis operation cannot be undone. Continue?')) {
   document.forms['lbv_calendar'].cal_data.value = "Les Bourgeois Vineyards has no private events at this time. Please bookmark this page or return later to stay up-to-date with our news and events.";
   document.forms['lbv_calendar'].submit();
  } else {
   document.forms.cal_data.focus();
  }
 } else {
  document.forms['lbv_calendar'].submit();
 }
}

function validate_contact() {
 var con_val = new Array(0,document.forms['lbv_contact'].name_first.value,
                           document.forms['lbv_contact'].name_last.value,
                           document.forms['lbv_contact'].email.value,
                           document.forms['lbv_contact'].phone.value,
                           document.forms['lbv_contact'].message.value),
     chk_pos = 0,
     chk_nam = /[^A-Za-z0-9 ]/,
     err_val = new Array();

 for (var tmp_val = 1; tmp_val < con_val.length; tmp_val++) {
  con_val[tmp_val] = con_val[tmp_val].replace(/^\s+|\s+$/g,'');
 }
 for (var tmp_val = 0; tmp_val < con_val[3].length; tmp_val++) {
  if (con_val[3].charAt(tmp_val) == "@") {
   chk_pos++;
  }
 }
 if (con_val[1].length < 1 || chk_nam.test(con_val[1])) {
  document.getElementById('lbv_01').className = "input_error";
  err_val[1] = 1;
 } else {
  document.getElementById('lbv_01').className = "";
 }
 if (con_val[2].length < 1 || chk_nam.test(con_val[2])) {
  document.getElementById('lbv_02').className = "input_error";
  err_val[2] = 1;
 } else {
  document.getElementById('lbv_02').className = "";
 }
 if (con_val[3].length < 5 || /[^A-Za-z0-9\-\.@_]|\.@|@\.|\.\.|^\.|\.$|!\./.test(con_val[3]) || chk_pos != 1 || con_val[3].lastIndexOf('@') > con_val[3].lastIndexOf('.') || con_val[3].lastIndexOf('-') > con_val[3].lastIndexOf('.') || con_val[3].lastIndexOf('_') > con_val[3].lastIndexOf('.')) {
  document.getElementById('lbv_03').className = "input_error";
  err_val[3] = 1;
 } else {
  document.getElementById('lbv_03').className = "";
 }
 if (con_val[5].length < 1) {
  document.getElementById('lbv_05').className = "input_error";
  err_val[5] = 1;
 } else {
  document.getElementById('lbv_05').className = "";
 }
 if (err_val.length > 0) {
  alert('Oops! One or more required fields are invalid or incomplete (noted in red).\nPlease revise and re-click the \'Send Now\' button.');
  if (err_val[1] == 1) {
   document.forms['lbv_contact'].name_first.focus();
  } else
   if (err_val[2] == 1) {
    document.forms['lbv_contact'].name_last.focus();
   } else
    if (err_val[3] == 1) {
     document.forms['lbv_contact'].email.focus();
    } else
     if (err_val[5] == 1) {
      document.forms['lbv_contact'].message.focus();
     }
  } else {
   document.forms['lbv_contact'].submit();
  }
}

function show_phone() {
 document.write('<b>800.690.1830</b>');
}

function breakout_link(link_dest,link_text) {
 document.write('<a href="javascript:parent.document.location.href=\'' + link_dest + '\'">' + link_text + '</a>');
}

function validate_subscribe() {
 var con_val = new Array(0,document.forms['lbv_opt_in'].name_first.value,
                           document.forms['lbv_opt_in'].name_last.value,
                           document.forms['lbv_opt_in'].email.value),
     chk_pos = 0,
     chk_nam = /[^A-Za-z0-9 ]/,
     err_val = new Array();

 for (var tmp_val = 1; tmp_val < con_val.length; tmp_val++) {
  con_val[tmp_val] = con_val[tmp_val].replace(/^\s+|\s+$/g,'');
 }
 for (var tmp_val = 0; tmp_val < con_val[3].length; tmp_val++) {
  if (con_val[3].charAt(tmp_val) == "@") {
   chk_pos++;
  }
 }
 if (con_val[1].length < 1 || chk_nam.test(con_val[1]) || con_val[1] == 'First Name') {
  document.getElementById('opt_01').className = "input_error";
  err_val[1] = 1;
 } else {
  document.getElementById('opt_01').className = "";
 }
 if (con_val[2].length < 1 || chk_nam.test(con_val[2]) || con_val[2] == 'Last Name') {
  document.getElementById('opt_02').className = "input_error";
  err_val[2] = 1;
 } else {
  document.getElementById('opt_02').className = "";
 }
 if (con_val[3].length < 5 || /[^A-Za-z0-9\-\.@_]|\.@|@\.|\.\.|^\.|\.$|!\./.test(con_val[3]) || chk_pos != 1 || con_val[3].lastIndexOf('@') > con_val[3].lastIndexOf('.') || con_val[3].lastIndexOf('-') > con_val[3].lastIndexOf('.') || con_val[3].lastIndexOf('_') > con_val[3].lastIndexOf('.')) {
  document.getElementById('opt_03').className = "input_error";
  err_val[3] = 1;
 } else {
  document.getElementById('opt_03').className = "";
 }
 if (err_val.length > 0) {
  alert('Oops! One or more required fields are invalid or incomplete (noted in red).\nPlease revise and re-click the \'Subscribe\' button.');
  if (err_val[1] == 1) {
   document.forms['lbv_opt_in'].name_first.focus();
  } else
   if (err_val[2] == 1) {
    document.forms['lbv_opt_in'].name_last.focus();
   } else
    if (err_val[3] == 1) {
     document.forms['lbv_opt_in'].email.focus();
    }
  } else {
   document.forms['lbv_opt_in'].submit();
  }
}

function show_phone() {
 document.write('<b>800.690.1830</b>');
}

function breakout_link(link_dest,link_text) {
 document.write('<a href="javascript:parent.document.location.href=\'' + link_dest + '\'">' + link_text + '</a>');
}

function show_photo(pic_val) {
 if (pic_val < 10) {
  pic_val = '0' + pic_val;
 }
 pic_url = 'gallery_pic.php?pv=' + pic_val;
 window.open(pic_url,'Gallery_Images','menubar=no,height=650,width=650,toolbar=no');
}

function show_label(label_number) {
 document.getElementById(label_number).style.display = "block";
}

function hide_label(label_number) {
 document.getElementById(label_number).style.display = "none";
}

function compute_total(form_id,wine_count,item_cost) {
 var all_prices = new Array(0);
 all_prices[1] = document.forms[form_id].os0.value;
 if (wine_count > 1) { all_prices[2] = document.forms[form_id].os1.value; }
 if (wine_count > 2) { all_prices[3] = document.forms[form_id].os2.value; }
 if (wine_count > 3) { all_prices[4] = document.forms[form_id].os3.value; }
 if (wine_count > 4) { all_prices[5] = document.forms[form_id].os4.value; }
 if (wine_count > 5) { all_prices[6] = document.forms[form_id].os5.value; }
 for (temp_value = 1; temp_value < all_prices.length; temp_value++) {
  var wine_adjust = all_prices[temp_value].split(' (');
  if (wine_adjust.length > 1) {
   item_cost = item_cost + parseFloat(wine_adjust[1]);
  }
 }
 item_cost = item_cost + '';
 document.forms[form_id].amount.value = item_cost;
 document.forms[form_id].submit();
}

function show_larger(this_label) {
 window.open('images/labels/' + this_label,'Personalized Label','menubar=no,height=360,width=225,toolbar=no');
}

