$(document).ready(function(){
  init_form();
  init_gallery();
  init_testimonials()
});
function init_form() {
  var success;
  $("form").submit(function(){
    //alert ('submission');
    $(".error").removeClass("error");
    success=true;
    $("input").add("select").add("textarea").each(function(){
      if ($(this).hasClass('mand') && ($(this).attr("value")).length<=0) {
        $("div#div_"+$(this).attr("id")+" label").addClass("error");
        success = false;
      }
      if ($(this).hasClass('select') && $(this).attr("value")=='--') {
        $("div#div_"+$(this).attr("id")+" label").addClass("error");
        success = false;
      }
      if ($(this).hasClass('age') && (!is_numeric($(this).attr("value")) || (($(this).attr("value"))<14 || ($(this).attr("value"))>25))) {
        $("div#div_"+$(this).attr("id")+" label").addClass("error");
        success = false;
      }
    });
    if (success==false) {
      var err_string='';
      $(".error").each(function() {
        err_string+=$(this).text()+"\n";
      });
      alert ("There was a problem with the following fields:\n\n"+err_string+"\nPlease check and try again.");
      return false;
    }
  });
}
function init_gallery() {
}
function init_testimonials() {
  $("#testimonial_switcher").cycle({timeout:10000})
}
function is_numeric (mixed_var) {
    // Returns true if value is a number or a numeric string  
    // 
    // version: 1004.2311
    // discuss at: http://phpjs.org/functions/is_numeric
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: David
    // +   improved by: taith
    // +   bugfixed by: Tim de Koning
    // +   bugfixed by: WebDevHobo (http://webdevhobo.blogspot.com/)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: is_numeric(186.31);
    // *     returns 1: true
    // *     example 2: is_numeric('Kevin van Zonneveld');
    // *     returns 2: false
    // *     example 3: is_numeric('+186.31e2');
    // *     returns 3: true
    // *     example 4: is_numeric('');
    // *     returns 4: false
    // *     example 4: is_numeric([]);
    // *     returns 4: false
    return (typeof(mixed_var) === 'number' || typeof(mixed_var) === 'string') && mixed_var !== '' && !isNaN(mixed_var);
}
