// JavaScript Document
$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  /*$('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });*/
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
	$('.error').hide();
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
	
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
	  //$('input.text-input').css({backgroundColor:"#FFB0B0"});
      return false;
    }
	
	var company = $("input#company").val();
	if (company == "") {
      $("label#company_error").show();
      $("input#company").focus();
	  //$('input.text-input').css({backgroundColor:"#FFB0B0"});
      return false;
    }
	
	
	var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
	   //$('input.text-input').css({backgroundColor:"#FFB0B0"});
      return false;
    }
	
		var email = $("input#email").val();
		if (email == "") {
      		$("label#email_error").show();
      		$("input#email").focus();
	    	//$('input.text-input').css({backgroundColor:"#FFB0B0"});
      		return false;
    	} else {
			
			var apos=$("input#email").val().indexOf("@");
			var dotpos=$("input#email").val().lastIndexOf(".");	
			if(apos < 1 || dotpos-apos < 2){
				  $("label#Email_not_valid_error").show();
				  $("input#email").focus();
				  //$('input.text-input').css({backgroundColor:"#FFB0B0"});
				  return false;
			}
		}
	
	
	   var maxLength = document.getElementById("requirement").value;
	   if(maxLength == "")
	   {
		   	
		 	$("label#requirement_error").show();
      		$("textarea#requirement").focus();
			//$('input.text-input').css({backgroundColor:"#FFB0B0"});
			return false;
	   }
	   
	   var web = $("input#web").val();
		
		var radiobutton =$("input[@name='budget']:checked").val();
		
		if(radiobutton == "radiobutton1") 
			radiobutton = "I'm ready to get started, where should I send the payment!";
		else if(radiobutton == "radiobutton2") 
			radiobutton = "I have a budget planned for this and I would like to define the scope, terms and                         dates for this project.";
		else if(radiobutton == "radiobutton3") 
			radiobutton = "I do not have the budget, but I need some help planning so I can get the right                         budget.";
		else if(radiobutton == "radiobutton4") 
			radiobutton = "I have not even thought of budget yet, but I would like to spend some time to get to                         know wakensys.";
	
	
		
	
		
		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone+ '&company=' + company + '&web=' + web + '&radiobutton='+ radiobutton + '&maxLength=' + maxLength; 
		
		
		//return false;
		
		$.ajax({
      type: "POST",
      url: "process_hire_us.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h4>Estimate  Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
