
// Copyright (C) 2008 Aaron Merriman, AaronMerriman.com. All rights reserved.

var cap_val =  new Array(0,"Bramton Rd. at Shelbyville Rd.",
                           "Blenheim Rd. near Merriman Rd.",
                           "Blenheim Rd. at Marshall Rd.",
                           "Blenheim Rd. at Marshall Rd.",
                           "Winter 1994",
                           "Winter 1994",
                           "Winter 1994",
                           "Blenheim Rd. at Marshall Rd.",
                           "Blenheim Rd. at Ring Rd.",
                           "Summertime fun in Beechwood Village",
                           "Bramton Rd. at Cordova Rd."),
    ldr_nam = new Array("","Chris Dunn",
                           "Cherie Brewer",
                           "Steve Cooper",
                           "Sidney Eline, Jr.",
                           "Brandon Jaggers",
                           "Chad Sharber",
                           "Josh Rhodes",
                           "Jerry Davis"),
    ldr_typ = new Array("","Mayor",
                           "City Clerk",
                           "Councilman",
                           "Councilwoman"),
    con_type, con_name = 0;

function panel_title(ptt_val) {
 if (ptt_val == 0) {
  document.write('<h2 class="pt_normal">');
 } else {
  document.write('<h2 class="pt_alert">');
 }
 document.write('Website Tips</h2>');
}

function show_photo(pht_val) {
 var pht_num = pht_val;

 if (pht_num < 10) {
  pht_num = "0" + pht_num;
 }
 document.getElementById('pic').style.backgroundImage = "url('images/Beechwood-Village-" + pht_num + ".jpg')";
 document.getElementById('caption').innerHTML = cap_val[pht_val];
 document.getElementById('nav_photos').blur();
}

function show_leader(typ_val,nam_val) {
 if (nam_val < 1) {
  document.write(ldr_typ[typ_val]);
 } else {
  if (typ_val > 0) {
   document.write(ldr_typ[typ_val] + " " + ldr_nam[nam_val]);
  } else {
   document.write(ldr_nam[nam_val]);
  }
 }
}

function leader_opt(type_val,name_val) {
 for (var tmp_val = 1; tmp_val < ldr_nam.length; tmp_val++) {
  document.write('<option value=\"' + ldr_typ[(tmp_val > 3) ? 3 : tmp_val] + ' ' + ldr_nam[tmp_val] + '\"' + ((tmp_val == name_val) ? ' selected' : '') + '>' + ldr_typ[(tmp_val > 3) ? 3 : tmp_val] + ' ' + ldr_nam[tmp_val] + '&nbsp;</option>');
 }
}

function bv_phone() {
 document.write('502.381.1038');
}

function bv_validate() {
 var con_val = new Array(0,document.forms['bv_contact'].f_name.value,
                           document.forms['bv_contact'].l_name.value,
                           document.forms['bv_contact'].email.value,
                           document.forms['bv_contact'].phone.value,
                           document.forms['bv_contact'].recipient.value,
                           document.forms['bv_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('cn_01').className = "input_error";
  err_val[1] = 1;
 } else {
  document.getElementById('cn_01').className = "input_field";
 }
 if (con_val[2].length < 1 || chk_nam.test(con_val[2])) {
  document.getElementById('cn_02').className = "input_error";
  err_val[2] = 1;
 } else {
  document.getElementById('cn_02').className = "input_field";
 }
 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('.')) {
  document.getElementById('cn_03').className = "input_error";
  err_val[3] = 1;
 } else {
  document.getElementById('cn_03').className = "input_field";
 }
 if (con_val[6].length < 1) {
  document.getElementById('cn_06').className = "input_error";
  err_val[6] = 1;
 } else {
  document.getElementById('cn_06').className = "input_field";
 }
 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['bv_contact'].f_name.focus();
  } else
   if (err_val[2] == 1) {
    document.forms['bv_contact'].l_name.focus();
   } else
    if (err_val[3] == 1) {
     document.forms['bv_contact'].email.focus();
    } else
     if (err_val[6] == 1) {
      document.forms['bv_contact'].message.focus();
     }
  } else {
   document.forms['bv_contact'].submit();
  }
}
