$(function() {  
  /* Input Items */
  $('#cForm input[title]').each(function() {
    if($(this).val() === '') {
      $(this).val($(this).attr('title'));
    }
    $(this).focus(function() {
      if($(this).val() == $(this).attr('title')) {
        $(this).val('').addClass('focused');
        $(this).css('color', '#4b7394');    
      }
    });
    $(this).blur(function() {
      if($(this).val() === '' || $(this).val() === $(this).attr('title')) {
        $(this).val($(this).attr('title')).removeClass('focused');
        $(this).css('color', 'red');  
      }
    });
  });
  /* Select Items */
  $("#cForm span.select").blur(function() {
    if($(this).val() === '' || $(this).val() === $(this).attr('title')) {
      $(this).val($(this).attr('title')).removeClass('focused');
      $(this).css('color', 'red');  
    }
  });  
    /* Validate Check */
    $("#cForm").submit(function() {
    $('#cForm input[title]').each(function() {
      if ($(this).val() == 'Full Name' || $(this).val() == 'Email' || $(this).val() == 'Phone' || $(this).val() == 'Agency Name') {
        $(this).css('color', 'red');
        returnVal = false;
      }
    });
    /* Validation */
   /* Vars */
    var email_regex=/([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})/;
    var phone_regex=/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/;
    var email_string=$("#cForm input.email").val();
    var phone_string=$("#cForm input.phone").val();
    if(!email_regex.test(email_string)){
      $("input.email").css('color','red');
      returnVal=false;
    }else{
      $("#cForm input.email").css('color', '#4b7394');
    }    
    if(!phone_regex.test(phone_string)){
      $("input.phone").css('color', 'red');
      returnVal=false;
    }else{
      $("#cForm input.phone").css('color','#4b7394');
    }
    if(email_regex.test(email_string)==true&&phone_regex.test(phone_string)==true){returnVal=true}
    $('#cForm input[title]').each(function(){
      if ($(this).val()=='Full Name'||$(this).val()=='Email'||$(this).val()=='Phone'||$(this).val()=='Agency Name'){
        $(this).css('color','red');
        returnVal=false;
      }
    });
    /* Select Val */
    $("select.select").change(function(){
      if ($('select.select option:selected').val()==""){
        $('select.select').css('color','red');
        returnVal=false;
      }else{
        $('select.select').css('color','#4b7394');
      }  
    });
    if($('select.select option:selected').val()==""){
      $('select.select').css('color','red');
      returnVal=false;
    }else{
      $('select.select').css('color','#4b7394');
    }
    return returnVal;
  });
});
