/*
Theme Name: Geekinit Theme
Theme URI: http://www.geekinit.com
Description: It's simple, Widget ready, SEO friendly, W3C compliant, jQuery enabled, and the ability for custom menus!
Author: Jeff Vogelpohl
Author URI: http://www.geekinit.com
Version: 1.0
License: Free to use for non-profit and commercial purposes as long as this license is in place and in its original context.
Tags: basic, seo, xhtml, w3c, two column, left sidebar, custom menu, jquery, css
*/

$(document).ready(function() {

  var templateName = "Geekinit Theme";
      
  var Requirement1 = false;
  var Requirement2 = false;
  var Requirement3 = false;
  
  $.TriggerFieldsValidation = function() {
      $("#postName").trigger("keyup");
      $("#postPhone").trigger("keyup");
      $("#postEmail").trigger("keyup");
      $("#postOtherRequirement").trigger("keyup");
  }
  
  $.TriggerRequirements = function(CheckAll) {
      switch (CheckAll) {
        case false:
          $("#postPipeThreadingServices").attr("checked" , false);
          $("#postOilfieldConsultingServices").attr("checked" , false);
          $("#postOilwellAccessories").attr("checked" , false);
          Requirement1 = false;
          Requirement2 = false;
          Requirement3 = false;
          break;
        case true:
          $("#postPipeThreadingServices").attr("checked" , true);
          $("#postOilfieldConsultingServices").attr("checked" , true);
          $("#postOilwellAccessories").attr("checked" , true);
          Requirement1 = false;
          Requirement2 = false;
          Requirement3 = false;
          break;
      }
  }
  
  $.TriggerRequirementsValidation = function() {
      if ((Requirement1 == true) | (Requirement2 == true) | (Requirement3 == true)) {
        $("#ValidateRequirementsIcon").attr("src", "jqformicons/green_icon.png");
      }
      else {
        $("#ValidateRequirementsIcon").attr("src", "jqformicons/required_icon.png");
      }
  }
  
  $.IsEmail = function(email) {
      var regex = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
      return regex.test(email);
  }
  
  $.IsPhone = function(phone) {
      var regex = new RegExp(/^[2-9]\d{2}-\d{3}-\d{4}$/);
      return regex.test(phone);
  }
  
  $("#postName").keyup(function() {
      var thisElement = $(this);
      if (thisElement.val().length > 6) {
        $("#ValidateNameIcon").attr("src", "jqformicons/green_icon.png");
      }
      else if (thisElement.val().length <= 6) {
        if (thisElement.val().length == 0) {
          $("#ValidateNameIcon").attr("src", "jqformicons/required_icon.png");
        }
        else {
          $("#ValidateNameIcon").attr("src", "jqformicons/red_icon.png");
        }
      }
  });
  
  $("#postPhone").keyup(function() {
      var thisElement = $(this);
      if (thisElement.val().length == 12) {
        if ($.IsPhone(thisElement.val())) {
          $("#ValidatePhoneIcon").attr("src", "jqformicons/green_icon.png");
        }
        else {
          $("#ValidatePhoneIcon").attr("src", "jqformicons/red_icon.png");
        }
      }
      else if (thisElement.val().length < 12) {
        if (thisElement.val().length == 0) {
          $("#ValidatePhoneIcon").attr("src", "jqformicons/required_icon.png");
        }
        else {
          $("#ValidatePhoneIcon").attr("src", "jqformicons/red_icon.png");
        }
      }
  });
  
  $("#postEmail").keyup(function() {
      var thisElement = $(this);
      if (thisElement.val().length > 6) {
        if ($.IsEmail(thisElement.val())) {
          $("#ValidateEmailIcon").attr("src", "jqformicons/green_icon.png");
        }
        else {
          $("#ValidateEmailIcon").attr("src", "jqformicons/red_icon.png");
        }
      }
      else if (thisElement.val().length <= 6) {
        if (thisElement.val().length == 0) {
          $("#ValidateEmailIcon").attr("src", "jqformicons/required_icon.png");
        }
        else {
          $("#ValidateEmailIcon").attr("src", "jqformicons/red_icon.png");
        }
      }
  });
  
  $("#postPipeThreadingServices:checkbox").click(function() {
      var thisElement = $(this);
      if ($(this).attr("checked")) {
        Requirement1 = true;
        $.TriggerRequirementsValidation();
      }
      else {
        Requirement1 = false;
        $.TriggerRequirementsValidation();
      }
  });
  
  $("#postOilfieldConsultingServices:checkbox").click(function() {
      var thisElement = $(this);
      if ($(this).attr("checked")) {
        Requirement2 = true;
        $.TriggerRequirementsValidation();
      }
      else {
        Requirement2 = false;
        $.TriggerRequirementsValidation();
      }
  });
  
  $("#postOilwellAccessories:checkbox").click(function() {
      var thisElement = $(this);
      if ($(this).attr("checked")) {
        Requirement3 = true;
        $.TriggerRequirementsValidation();
      }
      else {
        Requirement3 = false;
        $.TriggerRequirementsValidation();
      }
  });
  
  $("#postOtherRequirement").keyup(function() {
      var thisElement = $(this);
      if (thisElement.val().length > 4) {
        $("#ValidateOtherIcon").attr("src", "jqformicons/green_icon.png");
      }
      else if (thisElement.val().length <= 4) {
        if (thisElement.val().length == 0) {
          $("#ValidateOtherIcon").attr("src", "jqformicons/required_icon.png");
        }
        else {
          $("#ValidateOtherIcon").attr("src", "jqformicons/red_icon.png");
        }
      }
  });

  /* var bodyColor = "#ffffff";
  var bodyColorChanged = false;
  $("body").click(function() {
      if (bodyColorChanged == true) {
        $(this).css("background", "#333333");
        $(this).css("color", "#ffffff");
        bodyColorChanged = false
      }
      else if (bodyColorChanged == false) {
        $(this).css("background", bodyColor);
        $(this).css("color", "#000000");
        bodyColorChanged = true
      }
  }); */

});
