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

var testimonials = new Array(0,"Monica went above and beyond.~Sandy",
                               "Pharmacist was <b>very</b> helpful.~James",
                               "Cara was great.~Gail",
                               "Cara and Kem have been helpful over the years.~Richard",
                               "Pharmacy goes above and beyond to get medication needed for patient!~SC",
                               "You don't get this service at Walgreens.~Pamela",
                               "Everyone is helpful. I do most of my shopping here.~Mabel",
			       "Excellent Service.~Mary",
			       "Staff was helpful and kind while getting our equipment.~James",
			       "The nurse I worked with was very helpful and courteous.~MS",
			       "Brenda and Lynette were extremely helpful.~Anonymous",			
			       "Not sure it could get any better!~DB",		
                               "Great service.~Lynn",
			       "We know we are in good hand at D&amp;H! Thank you!.~RC",
                               "Everyone is helpful.~Anonymous",
                               "Service with a smile.~Pamela",
                               "This place is great! Thirty- two years of coming here.~Richard",
                               "New to D&amp;H on Paris Rd. and I like the &hellip; numerous other products.~Kathryn",
                               "You do a great job!~Nancy",
			       "Good to know you're open on Sunday.~KT",
			       "It sure beats using the pharmacy chains.~Julie",
                               "I like coming here and I like to support local businesses.~Diane",
                               "Great staff!~Bria",
                               "I am always very satisfied at D&amp;H.~Margaret",
                               "Alie was very courteous.~Pat",
                               "Wonderful service.~Martha",
                               "Triston and Jessica were very helpful.~Pamela"),
    tm_len = testimonials.length - 1,
    tm_pos = 0;

function validate_contact() {
 var con_val = new Array(0,document.forms['dh_contact'].first_name.value,
                           document.forms['dh_contact'].last_name.value,
                           document.forms['dh_contact'].email.value,
                           document.forms['dh_contact'].phone.value,
                           document.forms['dh_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('dh_01').className = "input_error";
  err_val[1] = 1;
 } else {
  document.getElementById('dh_01').className = "";
 }
 if (con_val[2].length < 1 || chk_nam.test(con_val[2])) {
  document.getElementById('dh_02').className = "input_error";
  err_val[2] = 1;
 } else {
  document.getElementById('dh_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('dh_03').className = "input_error";
  err_val[3] = 1;
 } else {
  document.getElementById('dh_03').className = "";
 }
 if (con_val[4].length < 1) {
  document.getElementById('dh_04').className = "input_error";
  err_val[4] = 1;
 } else {
  document.getElementById('dh_04').className = "";
 }
 if (con_val[5].length < 1) {
  document.getElementById('dh_05').className = "input_error";
  err_val[5] = 1;
 } else {
  document.getElementById('dh_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['dh_contact'].first_name.focus();
  } else
   if (err_val[2] == 1) {
    document.forms['dh_contact'].last_name.focus();
   } else
    if (err_val[3] == 1) {
     document.forms['dh_contact'].email.focus();
    } else
     if (err_val[5] == 1) {
      document.forms['dh_contact'].message.focus();
     }
  } else {
   document.forms['dh_contact'].submit();
  }
}

function validate_mycard() {
 var con_val = new Array(0,document.forms['dh_contact'].first_name.value,
                           document.forms['dh_contact'].last_name.value,
                           document.forms['dh_contact'].email.value,
                           document.forms['dh_contact'].phone.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('dh_01').className = "input_error";
  err_val[1] = 1;
 } else {
  document.getElementById('dh_01').className = "";
 }
 if (con_val[2].length < 1 || chk_nam.test(con_val[2])) {
  document.getElementById('dh_02').className = "input_error";
  err_val[2] = 1;
 } else {
  document.getElementById('dh_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('dh_03').className = "input_error";
  err_val[3] = 1;
 } else {
  document.getElementById('dh_03').className = "";
 }
 if (con_val[4].length < 1) {
  document.getElementById('dh_04').className = "input_error";
  err_val[2] = 1;
 } else {
  document.getElementById('dh_04').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 \'Sign Me Up!\' button.');
  if (err_val[1] == 1) {
   document.forms['dh_contact'].first_name.focus();
  } else
   if (err_val[2] == 1) {
    document.forms['dh_contact'].last_name.focus();
   } else
    if (err_val[3] == 1) {
     document.forms['dh_contact'].email.focus();
    }
  } else {
   document.forms['dh_contact'].submit();
  }
}

function validate_admin() {
 var con_val = document.forms['dh_admin'].dest_email.value.replace(/^\s+|\s+$/g,''),
     chk_pos = 0,
     chk_nam = /[^A-Za-z0-9 ]/,
     err_val = 0;

 for (var tmp_val = 0; tmp_val < con_val.length; tmp_val++) {
  if (con_val.charAt(tmp_val) == "@") {
   chk_pos++;
  }
 }
 if (con_val.length < 5 || /[^A-Za-z0-9\-\.@_]|\.@|@\.|\.\.|^\.|\.$|!\./.test(con_val) || chk_pos != 1 || con_val.lastIndexOf('@') > con_val.lastIndexOf('.') || con_val.lastIndexOf('-') > con_val.lastIndexOf('.') || con_val.lastIndexOf('_') > con_val.lastIndexOf('.')) {
  document.getElementById('dest_email').className = "input_error";
  err_val = 1;
 } else {
  document.getElementById('dest_email').className = "";
 }
 if (err_val > 0) {
  alert('Oops! Destination Email is invalid or incomplete (noted in red).\nPlease revise and re-click the \'Save Changes\' button.');
  document.forms['dh_admin'].dest_email.focus();
 } else {
  document.forms['dh_admin'].submit();
 }
}

function validate_coupons() {
 if (document.forms['dh_coupons'].coupons_text.value.replace(/^\s+|\s+$/g,'').length < 1) {
  if (confirm('You are about to save an empty coupons file.\nAll existing coupons will be lost. Continue?')) {
   document.forms['dh_coupons'].submit();
  } else {
   document.forms['dh_coupons'].coupons_text.focus();
  }
 } else {
  document.forms['dh_coupons'].submit();
 }
}

function validate_blog() {
 if (document.forms['dh_blog'].blog_text.value.replace(/^\s+|\s+$/g,'').length < 1) {
  if (confirm('You are about to save an empty blog file.\nAll existing entries will be lost. Continue?')) {
   document.forms['dh_blog'].submit();
  } else {
   document.forms['dh_blog'].blog_text.focus();
  }
 } else {
  document.forms['dh_blog'].submit();
 }
}

function site_error(error_type,error_msg,error_val) {
 var error_sol = "";

 if (error_val == 0) {
  error_sol = "If this condition persists, please <a href=\"/Contact-Us.php\">contact us</a> to report the problem.</div>";
 } else {
  error_sol = "Contact site administrator for resolution.</div>";
 }
 document.write("<div id=\"critical_error\">\n<h1 class=\"input_error\">" + error_type + " Error</h1>\n<b>" + error_msg + "</b>\n" + error_sol);
}

function pause_testimonials() {
 setTimeout("start_testimonials()",3500);
}

function anim_testimonials() {
 tm_pos = Math.floor(Math.random()*(tm_len - 1)) * -85;
 document.getElementById('tm_content').style.top = tm_pos + "px";
 clearInterval(move_testimonials);
 pause_testimonials();
}

function start_testimonials() {
 move_testimonials = setInterval('anim_testimonials()',75);
}

function build_testimonials() {
 for (var tmp_val = 1; tmp_val <= tm_len; tmp_val++) {
  document.write("<div><p>&ldquo;" + testimonials[tmp_val].slice(0,testimonials[tmp_val].indexOf("~")) + "&rdquo;</p><i>- " + testimonials[tmp_val].slice(testimonials[tmp_val].indexOf("~") + 1) + "</i></div>");
 }
 pause_testimonials();
}
