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

  $(".submitbutton").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "" || name == "your name") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "" || email == "email address") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		
		
		var dataString = 'name='+ name + '&email=' + email;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "enews.php",
      data: dataString,
      success: function() {
        $('.enews').html("<div id='message'></div>");
        $('#message').html("<h3>Thankyou</h3>")
        .append("<p>You have been added to our Newsletter database.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message');
        });
      }
     });
    return false;
	});
  
  
    
    $(".button").click(function() {
								
	for (var i=0; i < document.popup.answer.length; i++)
	   {
	   if (document.popup.answer[i].checked)
		  {
		  var answer = document.popup.answer[i].value;
		  }
	   }
							
								
								
								
								
	 //var answer = $("input#answer1").val();
 	 //var answer = $("input#answer2").val();
	 //var answer = $("input#answer3").val();
	 var question_id = $("input#question_id").val();	 
	 var action = $("input#action").val();
	 
	 var dataString = 'answer='+ answer + '&question_id=' + question_id + '&action=' + action;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "question.php",
      data: dataString,
      success: function() {
        $('.popup-thanks').html("<div id='message'></div>");
        $('#message').html("<h3>Thankyou</h3>")
        .append("<p>Thankyou for answering our survey</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message');
        });
      }
     });
	 
	 
    return false;
	});
	
	
	
	
	$(".download").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	var optout = $("input#optout").val();
	
	if ($("input#optout").is(":checked")) {
		optout = "1";
	}

	var name = $("input#name").val();
	if (name == "" || name == "your name") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
	
	
	var email = $("input#email").val();
	if (email == "" || email == "email address") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		
		
	var dataString = 'name=' + name + '&email=' + email + '&optout=' + optout;
	//alert (dataString);return false;
		
	$.ajax({
      type: "POST",
      url: "download-form.php",
      data: dataString,
      success: function() {
        $('.download-form').html("<div id='message'></div>");
        $('#message').html("<h3>Thankyou</h3>")
        .append("<p>Please download the .PDF below</p><p><a href=\"FertilityTimesWinter2011.pdf\" class\"pdf\">Fertility Times Winter 2011</a>")
        .hide()
        .fadeIn(1500, function() {
          $('#message');
        });
      }
     });
    return false;
	});
  
  
  
});
//runOnLoad(function(){
 // $("input#name").select().focus();
//});

