$(function() {
  
  ///function to put google code once form has been success
  function ppcconversion() {
	var iframe = document.createElement('iframe');
	iframe.style.width = '0px';
	iframe.style.height = '0px';
	iframe.style.visibility = 'hidden';
	
	$('#contact_thanks').append(iframe);
	
	//document.body.appendChild(iframe);
	iframe.src = 'googleconverison.html';
	};	   
		   
		   
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#CCCCCC"});
  });
   $('textarea').focus(function(){
    $(this).css({backgroundColor:"#CCCCCC"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
    $('textarea').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".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();
     	 	return false;
    	}
		
	  var email = $("input#email").val();
		if (email == "") {
      		$("label#email_error").show();
      		$("input#email").focus();
      		return false;
    	}
		
	  var phone = $("input#phone").val();		
	  var usermessage = $("textarea#usermessage").val();		
		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&usermessage=' + usermessage;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
		 ppcconversion();
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

