$(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"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
		//alert("hello world");
    $('.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();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
	
			var info = $("textarea#info").val();

	
	var time = $("#time :selected").val();
	
	
	
	var selectedItems = new Array();
$("input[@name='interest[]']:checked").each(function() {selectedItems.push($(this).val());});
		
var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&info=' + info + '&selectedItems=' + selectedItems + '&time=' + time;
		//alert (dataString);//return false; 
		  
		$.ajax({
      type: "POST",
      url: "http://www.rhosmeadow.co.uk/bin/process.php",
      data: dataString,
      success: function() {
		  //alert ('worked');
		$('#contact_hide').html("<div id='message'></div>")
        $('#message').html("<h2>Thankyou for Contacting Rhos Meadows!</h2>")
        //.append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
		  $('#close-drive').trigger('click');
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});





$(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"});
  });

  $(".button-gen").click(function() {
		// validate and process form
		// first hide any error messages
		//alert("hello world");
    $('.error').hide();
		
	  var name = $("input#name-gen").val();
		if (name == "") {
      $("label#name-gen_error").show();
      $("input#name-gen").focus();
      return false;
    }
		var email = $("input#email-gen").val();
		if (email == "") {
      $("label#email-gen_error").show();
      $("input#email-gen").focus();
      return false;
    }
		var phone = $("input#phone-gen").val();
		if (phone == "") {
      $("label#phone-gen_error").show();
      $("input#phone-gen").focus();
      return false;
    }
	
			var info = $("textarea#info-gen").val();
	
	
		var reg = $("input#reg").val();
		//if (reg == "") {
     // $("label#reg_error").show();
     // $("input#reg").focus();
    //  return false;
   // }
	
		var make = $("input#make").val();
		//if (make == "") {
     // $("label#make_error").show();
     // $("input#make").focus();
     // return false;
   // }
	
		var model = $("input#model").val();
	///	if (model == "") {
     // $("label#model_error").show();
     // $("input#model").focus();
     // return false;
   // }
	
	var selectedItems2 = new Array();
$("input[@name='generic2[]']:checked").each(function() {selectedItems2.push($(this).val());});
		
var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&info=' + info + '&selectedItems2=' + selectedItems2 + '&reg=' + reg + '&make=' + make + '&model=' + model;
		//alert (dataString);//return false;
		  
		$.ajax({
      type: "POST",
      url: "http://www.rhosmeadow.co.uk/bin/generic.php",
      data: dataString,
      success: function() { 
	  //alert ('worked shop');
		$('#contact_form').html("<div id='message'></div>")
        $('#message').html("<h2>Thankyou for Contacting Rhos Meadows!</h2>")
        //.append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
		  $('#close').trigger('click');
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

