$(document).ready(function(){
	//function for contact form dropdown
	function contact() {
		if ($("#contactForm").is(":hidden")){
		}
		else{
		}
	}
	 
	//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
	//Contact Form in Side Bar
  $('.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('email');
		if (!filter.test(email.value)) {
			$('.email-missing').show();
		} else {$('.email-missing').hide();}
		if (document.cform.name.value == "") {
			$('.name-missing').show();
		} else {$('.name-missing').hide();}	
		if (document.cform.phone.value == "") {
			$('.phone-missing').show();
		} else {$('.phone-missing').hide();}	
		if (document.cform.message.value == "") {
			$('.message-missing').show();
		} else {$('.message-missing').hide();}		
		if ((document.cform.name.value == "") || (!filter.test(email.value)) || (document.cform.phone.value == "") || (document.cform.message.value == "")){
			return false;
		} 
		
		if ((document.cform.name.value != "") && (filter.test(email.value)) && (document.cform.phone.value != "") && (document.cform.message.value != "")) {
			//hide the form
			$('.contactForm').hide();
		
			//show the loading bar
			$('.loader').css({display:'block'});
			$('.loader').append($('.bar'));
			$('.bar').css({display:'block'});
		
			//send the ajax request
			$.get('/contact_action.php',{i_name:$('#name').val(),
							  i_email:$('#email').val(),
							  i_phone:$('#phone').val(),
							  i_message:$('#message').val()},
		
			//return the data
			function(data){
			  //hide the graphic
			  $('.bar').css({display:'none'});
			  $('.loader').append(data);
			});
			
			//waits 2000, then closes the form and fades out
			setTimeout('$("#mail_response").hide(); $(".loader").css({display:"none"}); $(".contactForm").show(); document.getElementById("cform").reset();', 6000);
			
			//stay on the page
			return false;
		} 
  });
  
  //Contact Form on Contact Page
  $('#frm_contact_full').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('i_email');
		if (!filter.test(email.value)) {
			$('.email-missing2').show();
		} else {$('.email-missing2').hide();}
		if (document.frm_contact_full.i_name.value == "") {
			$('.name-missing2').show();
		} else {$('.name-missing2').hide();}	
		if (document.frm_contact_full.i_phone.value == "") {
			$('.phone-missing2').show();
		} else {$('.phone-missing2').hide();}	
		if (document.frm_contact_full.i_message.value == "") {
			$('.message-missing2').show();
		} else {$('.message-missing2').hide();}		
		
		if ((document.frm_contact_full.i_name.value == "") || (!filter.test(email.value)) || (document.frm_contact_full.i_phone.value == "") || (document.frm_contact_full.i_message.value == "")){
			return false;
		} 
 
		
		
		if ((document.frm_contact_full.i_name.value != "") && (filter.test(email.value)) && (document.frm_contact_full.i_phone.value != "") && (document.frm_contact_full.i_message.value != "")) {
		
			//hide the form
			//$('.contactForm').hide();
		
			//show the loading bar
			$('.loader').css({display:'block'});
			$('.loader').append($('.bar'));
			$('.bar').css({display:'block'});
		
			//send the ajax request
			$.get('/contact_action.php',{i_name:$('#i_name').val(),
				i_email:$('#i_email').val(),
				i_phone:$('#i_phone').val(),
				i_alt_phone:$('#i_alt_phone').val(),
				i_address:$('#i_address').val(),
				i_city:$('#i_city').val(),
				i_state:$('#i_state').val(),
				i_zip:$('#i_zip').val(),
				i_country:$('#i_country').val(),
				i_incident_date:$('#i_incident_date').val(),
				i_name_of_adverse_parties:$('#i_name_of_adverse_parties').val(),
				i_website_referral:$('#i_website_referral').val(),
				i_message:$('#i_message').val()},
							  
		
			//return the data
			function(data){
			  //hide the graphic
			  $('.bar').css({display:'none'});
			  $('.loader2').append(data);
			  $("#frm_contact_full").hide();
			});
			
			//waits 2000, then closes the form and fades out
			setTimeout('$("#mail_response").hide(); $(".loader2").css({display:"none"}); $("#frm_contact_full").show(); document.getElementById("frm_contact_full").reset();', 6000);
			
			//stay on the page
			return false;
		} 

  });
}); 
