$(document).ready(function(){
	
	//--------------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	
	// Add check boxes to form
	$("form#contactForm div.formbox input, form#contactForm textarea").after("<span class='checked'/>");
		
	// Form Focus - remove text
	$("form#contactForm input.text, form#contactForm textarea").focus(function() {
		if (this.value == this.defaultValue) {
			$(this).val("");
		};
	});
	
	// Form Blur - Return Text
	$("form#contactForm input, form#contactForm textarea").blur(function() {
		if (this.value == ''){  
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
		
		if (this.value == this.defaultValue) {
			$(this).next("span").fadeOut(2000);
		};
		
		if (this.value != '' && this.value != this.defaultValue && this.id != 'email') {
			$(this).next("span").fadeIn(2000);
		};		
				
		this.value = trim(this.value);
	});
	
	// Trim String
	function trim(stringToTrim) {
		return(stringToTrim.replace(/^\s+|\s+$/g,""));
	}
	
	// Email Validation
	$("form#contactForm input#email").blur(function() {
		var emailToVal = this.value;
	
		if (this.value == this.defaultValue) {
			$(this).next("span").fadeOut(2000);
		};
		
		if (this.value != '' && this.value != this.defaultValue) {
			var emailPattern = /^\w+([\.\-]?\w+)*@{1}\w+([\.\-]?\w+)*(\.{1}[a-zA-Z]{2,4})+$/;
			var validation = emailPattern.test(emailToVal);
	
			if (validation) {
				$(this).next("span").fadeIn(2000);
			} else {				
				$(this).next("span").fadeOut(500);
			}
		}
	});
	
	// Clear all checked values
	$("form#contactForm input.reset").click(function() {
		$("form#contactForm input, form#contactForm textarea").next("span").fadeOut(500);
	});
	
	//-------------------------------------------
	
	$("a.external").attr({ target: "_blank"});

	$(".external a").attr({ target: "_blank"});
	
	//--------------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	
});

