
$(document).ready(function() {

//$("a[rel='example3']").colorbox({width:"50%", height:"60%"});




//for contact form
 $('.errorcap').hide(); //hide error messages in contact form and mailing list form
 //$('#successmessage').hide(); //hide success message


//$('.text-input').focus(function() {//when focus on a field change the class to focus
//$(this).removeClass('text-input').addClass('focus');
//});

//$('.text-input').blur(function() {//when moving away change the class back
// $(this).removeClass('focus').addClass('text-input');
//});


//clear textfields once
var nameinput = document.getElementById("namecap");
 nameinput.onfocus = function() {
   if(this.value==this.defaultValue) this.value = '';
  }
  nameinput.onblur = function() {
   if(this.value=='') this.value = this.defaultValue;
  }

var emailinput = document.getElementById("emailcap");
 emailinput.onfocus = function() {
   if(this.value==this.defaultValue) this.value = '';
  }
  emailinput.onblur = function() {
   if(this.value=='') this.value = this.defaultValue;
  }

var messageinput = document.getElementById("messagecap");
 messageinput.onfocus = function() {
   if(this.value==this.defaultValue) this.value = '';
  }
  messageinput.onblur = function() {
   if(this.value=='') this.value = this.defaultValue;
  }




$('#submitcap').click(function() {
var name = $("#namecap").val();  //variables from the contact form
	var email = $("#emailcap").val();  
	var message = $("#messagecap").val();  
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

challengeField = $("input#recaptcha_challenge_field").val();
    responseField = $("input#recaptcha_response_field").val();
 
 $("#placement").empty();  


	
            if ((name == "") || (name == "Your Name")) {  
			$("#namecap_error").fadeIn(500);  
			$("#namecap").focus();  
			 return false;  
			}  
/*
			 if ((email == "") || (email == "Your email")) {  
			$("#email_error").fadeIn(500);  
			$("#email").focus();  
			 return false;  
			}
	*/

			if (!email.match(emailExp)){		//if email is not valid
			$("#emailcap_error").fadeIn(500);  
			$("#emailcap").focus();  
			 return false;  
			}  	

			 if ((message == "") || (message == "Your Message")) {  
			$("#messagecap_error").fadeIn(500);  
			$("#messagecap").focus();  
			 return false;  
			} 
			
					

document.getElementById('submitcap').disabled=true; //disable the button
var t=setTimeout("document.getElementById('submitcap').disabled=false", 5000);// re-enable the button after 5 seconds			


var dataString = 'recaptcha_challenge_field=' + challengeField + '&recaptcha_response_field=' + responseField;


//var dataString = 'name='+ name +'&email='+ email + '&message='+ message;

$.ajax({
	type: "POST",
	url: "processmailcaptcha.php", 
		data: dataString,
		cache: false,
		success: function(html){

//$('#seeall').replaceWith(html);

//$('#successmessage').fadeIn(1000);

//$('.text-input').focus(function() { //if you focus on a field again the success message goes as do the errors
//$("#successmessage").fadeOut(1000);
//$('.error').hide();
//});
  Recaptcha.reload();
$("#placement").append(html);// the php goes whereever the placement is

//$("#fromphp").show();// comes from the php //have to hide it first for fade to work!!
//$('#newcomment').fadeOut(2000);
//$('#newcomment').empty(); //empty the div other wise any new comments are seen again

		}//html function
});//ajax
return false;

});//click function

 });//doc ready
