$(document).ready(function(){
	//function for contact form dropdown
	function contact() {
		if ($("#contactForm").is(":hidden")){
			$("#contactForm").slideDown("slow");
			$("#backgroundPopup").css({"opacity": "0.7"});
			$("#backgroundPopup").fadeIn("slow"); 
		}
		else{
			$("#contactForm").slideUp("slow");
			$("#backgroundPopup").fadeOut("slow");  
		}
	}
	 
	//run contact form when any contact link is clicked
	$(".contact").click(function(){contact()});
	
	//animation for same page links #
	$('a[href*=#]').each(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname
		&& this.hash.replace(/#/,'') ) {
		  var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
		  var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
			if ($(this.hash).length) {
				$(this).click(function(event) {
					var targetOffset = $(this.hash).offset().top;
					var target = this.hash;
					event.preventDefault();			   
					$('html, body').animate({scrollTop: targetOffset}, 500);
					return false;
				});
			}
		}
	});

   //submission scripts
  $('.contactForm').submit( function(){
		//statements to validate the form	
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
		// email
		var email = document.getElementById('e-mail');
		if (!filter.test(email.value)) {
			$('.email-missing').show();
		} else {$('.email-missing').hide();}
		
		// first name
		if (document.cform.fname.value == "") {
			$('.fname-missing').show();
		} else {$('.fname-missing').hide();}
		
		// last name
		if (document.cform.lname.value == "") {
			$('.lname-missing').show();
		} else {$('.lname-missing').hide();}
		
		// human validation
		if (document.cform.hmnVldtn.value != 'PMC') {
			$('.hmnVldtn-missing').show();
		} else {$('.hmnVldtn-missing').hide();}
		
		if ((document.cform.fname.value == "") || (document.cform.lname.value == "") || (document.cform.hmnVldtn.value != 'PMC') || (!filter.test(email.value))){
			return false;
		} else {
			document.cform.submit();
			setTimeout('$("#backgroundPopup").fadeOut("slow"); $("#contactForm").slideUp("slow")', 3000);
			return false;
		}
		
		//alert($('#recaptcha_challenge_field').val() + ' = ' + $('#hmnVldtn').val());
		
//		if ((document.cform.fname.value != "") && (document.cform.lname.value != "") && (document.cform.hmnVldtn.value != "") && (filter.test(email.value))) {
			//hide the form
//			$('.contactForm').hide();
		
			//show the loading bar
//			$('.loader').append($('.bar'));
//			$('.bar').css({display:'block'});
//		
//			document.cform.submit();
		
//			//send the ajax request
//			$.get('content/signUpConfirmation.cfm',{
//				name:$('#fname').val(),
//				name:$('#lname').val(),
//				recaptcha_challenge_field:$('#recaptcha_challenge_field').val(),
//				hmnVldtn:$('#hmnVldtn').val(),
//				email:$('#e-mail').val()},
//		
//			//return the data
//			function(data){
//			  //hide the graphic
//			  $('.bar').css({display:'none'});
//			  $('.loader').append(data);
//			});
			
			//waits three seconds, then closes the form and fades out
//			setTimeout('$("#backgroundPopup").fadeOut("slow"); $("#contactForm").slideUp("slow")', 3000);
			
			//stay on the page
//			return false;
//		} 
  });
	//only need force for IE6  
	$("#backgroundPopup").css({  
		"height": document.documentElement.clientHeight 
	});  
});
