$(document).ready(function() {
	
	$('form input, form textarea').each(function() {

		var default_value = this.value;
		
		$(this).focus(function(){
			
			$(this).addClass("focus");
			
			if(this.value == default_value) {
				this.value = '';
			}
		});

		$(this).blur(function(){
			
			$(this).removeClass("focus");
			
			if(this.value == '') {
				this.value = default_value;
			}
		});

	});
	
	$("form").submit(function() {
		
		var name = $("input#name");
		var email = $("input#email");
		var message = $("textarea");
		
		if(name.val() == "name:"){
			alert("Please fill out the form");
			return false;
		} else if (email.val() == "email:"){
			alert("Please fill out the form");
			return false;
		} else if (message.val() == "message:"){
			alert("Please fill out the form");
			return false;
		} else {
			return true;
		}
		
	});
	
	var urlSearch = location.search;
	
	if(urlSearch == "?form=success"){
		
		$("form").remove();
		$(".wrap").empty();
		$(".wrap").append("<h1 style='font-size: 16px; text-align: center; margin: 30px 0 30px 0;'>Thank you for submitting the form</h1>");
		
		setTimeout(function(){
			
			window.location = "http://straios.com/index.html";
			
		}, 1500);
		
	} else if(urlSearch == "?form=error") {
		
		$("form").remove();
		$(".wrap").empty();
		$(".wrap").append("<h1 style='font-size: 16px; text-align: center; margin: 30px 0 30px 0;'>There was an error</h1>");
		
		setTimeout(function(){
			
			window.location = "http://straios.com/index.html";
			
		}, 1500);
		
	}
	
});

