function closeModal() {
	$(".close").click();
}

$(document).ready(function() {    
	$('a[name=modal]').click(function(e) {  
		$(".notice").html(' ');
		//Cancel the link behavior  
		e.preventDefault();  
		//Get the A tag  
		var id = $(this).attr('href');  
		
		//Get the screen height and width  
		var maskHeight = $(document).height();  
		var maskWidth = $(window).width();  
		
		//Set height and width to mask to fill up the whole screen  
		$('#mask').css({'width':maskWidth,'height':maskHeight});  
		  
		//transition effect       
		//$('#mask').fadeIn(1000);      
		//$('#mask').fadeTo("slow",0.8);
		$('#mask').show();
		
		//Get the window height and width  
		var winH = $(window).height();  
		var winW = $(window).width();  
		
		//Set the popup window to center  
		$(id).css('top',  winH/2-$(id).height()/2);  
		$(id).css('left', winW/2-$(id).width()/2);
		
		//transition effect  
		//$(id).fadeIn(2000);
		$(id).show();
	});
	
	$('.window .close').click(function (e) {  
		//Cancel the link behavior  
		e.preventDefault();  
		//$('#mask, .window').fadeOut(1000);
		$('#mask, .window').hide();
	});
	
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
		//$(this).fadeOut(1000);
		//$('.window').fadeOut(1000);
	});
	
	$('#request_form').submit(function() {
		$(".notice").html('Please wait while your message is being sent');
		var required_missing	= false;
		var post_url = $('#request_form').attr('action');
		$(".notice").html('');
		$('.bordered-red').removeClass('bordered-red');
		$('.required').each(function() {
			if(this.value == '') { 
				required_missing = true; 
				$(this).addClass('bordered-red'); 
			}
		} );
		
		if(required_missing) {
			$(".notice").html("<span class='chalkport-red'>Marked fields are required</span>");
		}
		else {
			$.post(post_url, $('#request_form').serialize(), function(data){
				//console.log(data);
				if(data == 'good') {
					$(".notice").html("<span class='chalkport-green'>Application has been sent. This windows will close in 5 seconds. You may also click on the close button in the upper right</span>");
					$(".required").val('');
					$("#demo_message").val('');
					setTimeout(function() { $(".close").click(); }, 5000);
				}
				else {
					$(".notice").html("<span class='chalkport-red'>"+data+"</span>");
				}
			});
		}
		return false;
	});
});
