jQuery(document).ready(function(){
	//function for contact form dropdown
	function contact() {
		if (jQuery("#contactForm").is(":hidden")){
			jQuery("#contactForm").slideDown("slow");
			jQuery("#backgroundPopup").css({"opacity": "0.7"});
			jQuery("#backgroundPopup").fadeIn("slow"); 
		}
		else{
			jQuery("#contactForm").slideUp("slow");
			jQuery("#backgroundPopup").fadeOut("slow");  
		}
	}
	 
	//run contact form when any contact link is clicked
	jQuery(".contact").click(function(){contact()});
	
	//animation for same page links #
	jQuery('a[href*=#]').each(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname
		&& this.hash.replace(/#/,'') ) {
		  var $targetId = jQuery(this.hash), $targetAnchor = jQuery('[name=' + this.hash.slice(1) +']');
		  var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
			if (jQuery(this.hash).length) {
				jQuery(this).click(function(event) {
					var targetOffset = jQuery(this.hash).offset().top;
					var target = this.hash;
					event.preventDefault();			   
					jQuery('html, body').animate({scrollTop: targetOffset}, 500);
					return false;
				});
			}
		}
	});



   //submission scripts
  jQuery('.contactForm').submit( function(){
		//statements to validate the form	
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var email = document.getElementById('e-mail');
		if (!filter.test(email.value)) {
			jQuery('.email-missing').show();
		} else {jQuery('.email-missing').hide();}
		if (document.cform.name.value == "") {
			jQuery('.name-missing').show();
		} else {jQuery('.name-missing').hide();}	
		if (document.cform.message.value == "") {
			jQuery('.message-missing').show();
		} else {jQuery('.message-missing').hide();}		

		if (document.cform.verification_code.value == "") {
			jQuery('.verification_code-missing').show();
		} else {jQuery('.verification_code-missing').hide();}		


		if ((document.cform.name.value == "") || (!filter.test(email.value)) || (document.cform.message.value == "") || (document.cform.verification_code.value == "")){
			return false;
		} 
		
		if ((document.cform.name.value != "") && (filter.test(email.value)) && (document.cform.message.value != "")) {
			//hide the form
			jQuery('.contactForm').hide();
		
			//show the loading bar
			jQuery('.loader').append(jQuery('.bar'));
			jQuery('.bar').css({display:'block'});
		
			//send the ajax request
			jQuery.post('http://www.alphafiduciary.com/mail.php',{name:jQuery('#name').val(),
							  email:jQuery('#e-mail').val(),
							  message:jQuery('#message').val(),
							  verification_code:jQuery('#verification_code').val()},
		
			//return the data
			function(data){
			  //hide the graphic
			  if(data != "Verification code does not macth."){
				  jQuery('.bar').css({display:'none'});
				  jQuery('.loader').append(data);
			  }else{
				  alert(data);
				  jQuery('.bar').css({display:'none'});
		 		  jQuery('.contactForm').show();
			  }
			});
			
			//waits 2000, then closes the form and fades out
			//setTimeout('jQuery("#backgroundPopup").fadeOut("slow"); jQuery("#contactForm").slideUp("slow")', 2000);
			
			//stay on the page
			return false;
		} 
  });
	//only need force for IE6  
	jQuery("#backgroundPopup").css({  
		"height": document.documentElement.clientHeight 
	});  
});
document.write('');
document.write('');
document.write('');
document.write('');
