$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFF6FA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });



// textarea color
  $('textarea.text-input').css({backgroundColor:"#FFFFFF"});
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFF6FA"});
  });
  $('textarea.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  
  
  
// selection list color  
  $('select.text-input').css({backgroundColor:"#FFFFFF"});
  $('select.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFF6FA"});
  });
  $('select.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });





$(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();


	var poem_type = $("select#os2").val();
		if (poem_type == "") {
      $("label#poem_type_error").show();
      $("select#poem_type").focus();
      return false;
    }
	
	var recipient = $("input#recipient").val();
		if (recipient == "") {
      $("label#recipient_error").show();
      $("input#recipient").focus();
	return false;
    }
	
	
	var relation = $("input#relation").val();
		if (relation == "") {
      $("label#relation_error").show();
      $("input#relation").focus();
      return false;
    }
	
	
	var ocassion = $("input#ocassion").val();
		if (ocassion == "") {
      $("label#ocassion_error").show();
      $("input#ocassion").focus();
      return false;
    }
	
	
	var recipient_age = $("input#recipient_age").val();
		if (recipient_age == "") {
      $("label#recipient_age_error").show();
      $("input#recipient_age").focus();
      return false;
    }
	
	
	var line_of_work = $("input#line_of_work").val();
		if (line_of_work == "") {
      $("label#line_of_work_error").show();
      $("input#line_of_work").focus();
      return false;
    }
	
	
		var gender = $("select#gender").val();
		if (gender == "") {
      $("label#gender_error").show();
      $("select#gender").focus();
      return false;
    }
	

	var hobbies = $("textarea#hobbies").val();
		if (hobbies == "") {
      $("label#hobbies_error").show();
      $("textarea#hobbies").focus();
      return false;
    }

	var other_info = $("textarea#other_info").val();
		if (other_info == "") {
      $("label#other_info_error").show();
      $("textarea#other_info_else").focus();
      return false;
    }
		var poem_feel = $("input#poem_feel").val();
		if (poem_feel == "") {
      $("label#poem_feel_error").show();
      $("input#poem_feel").focus();
      return false;
    }
	
	var anything_else = $("textarea#anything_else").val();
		if (anything_else == "") {
      $("label#anything_else_error").show();
      $("textarea#anything_else").focus();
      return false;
    }
		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();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
		var poem_service = $("select#os3").val();
		if (poem_service == "") {
      $("label#poem_service_error").show();
      $("select#poem_service").focus();
      return false;
    }
	
	var dataString = 'poem_type=' + poem_type + '&recipient=' + recipient + '&relation=' + relation + '&ocassion=' + ocassion +  '&recipient_age=' + recipient_age + '&gender=' + gender + '&line_of_work=' + line_of_work + '&hobbies=' + hobbies + '&other_info=' + other_info + '&poem_feel=' + poem_feel + '&anything_else=' + anything_else + '&name='+ name + '&email=' + email + '&phone=' + phone + '&poem_service=' + poem_service;
	//alert (dataString);return false;
	
	
	var cmd = $("input#cmd").val();
	var redirect_cmd = $("input#redirect_cmd").val();
	var upload = $("input#upload").val();
	var business = $("input#business").val();
	var add = $("input#add").val();
	var currency_code = $("input#currency_code").val();
	var custom = $("input#custom").val();
	var no_note = $("input#no_note").val();
	var no_shipping = $("input#no_shipping").val();
	var os2 = poem_type;
	var os3 = poem_service;
	var on2 = $("input#on2").val();
	var on3 = $("input#on3").val();
	var quantity = $("input#quantity").val();
	var item_name = $("input#item_name").val();
	var amount = $("input#amount").val();
	var returnpage = $("input#returnpage").val();
	
	
	var paypalString = 'cmd=' + cmd + '&redirect_cmd=' + redirect_cmd + '&upload=' + upload + '&business=' + business +  '&add=' + add + '&currency_code=' + currency_code + '&custom=' + custom + '&no_note=' + no_note + '&on2=' + on2 + '&on3=' + on3 + '&os2=' + os2 + '&os3=' + os3 + '&quantity=' + quantity + '&item_name=' + item_name + '&amount=' + amount + '&item_name=' + item_name + '&return=' + returnpage;
	//alert (dataString);return false;
		
    var paypalURL = 'https://www.paypal.com/cgi-bin/webscr?' + paypalString;        
		
	
	
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success:
	  
		function() {
		
		$('#contact_form').html("<div id='message'></div>");
		$('#message').html("<h2>Order Form Processed</h2>")
		
		.append("<p>Redirecting to paypal...</p>")
		
		.hide()
		
		.fadeIn(1500, function() { 
				$('#message').append("<img id='checkmark' src='images/loading.gif' />");
				setTimeout(window.location = paypalURL ,4500);	
		});


	}
     });
    return false;
	});
});


runOnLoad(function(){
  $("select#poem_type").select().focus();
});
