(function() {

function isBlank(str){
    return (typeof(str) == 'undefined' || str == null || $.trim(str) == '');
}
 
function isEmail(str){
    var re = new RegExp('^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]{2,4}$');
    return (str.search(re) != -1);
}

function initZebraTable(id) {
	$(id + ' tbody tr:odd').removeClass('even').addClass('odd');
	$(id + ' tbody tr:even').removeClass('odd').addClass('even');
}

function initRegisterForm() {
	$('#registerForm').submit(function(event) {
		if (isBlank(this.firstname.value)) {
			event.preventDefault();
			alert('Please enter you first name!');
			this.firstname.focus();
			return;
		}
		if (isBlank(this.lastname.value)) {
			event.preventDefault();
			alert('Please enter you last name!');
			this.lastname.focus();
			return;
		}
		if (isBlank(this.email.value)) {
			event.preventDefault();
			alert('Please enter you email address!');
			this.email.focus();
			return;
		}
		if (!isEmail(this.email.value)) {
			event.preventDefault();
			alert('The email you entered is not valid!');
			this.email.focus();
			return;
		}
		if (isBlank(this.email2.value)) {
			event.preventDefault();
			alert('Please confirm you email address!');
			this.email2.focus();
			return;
		}
		if (this.email2.value != this.email.value) {
			event.preventDefault();
			alert('Your email does not match!');
			this.email2.focus();
			return;
		}
		if (isBlank(this.securityCode.value)) {
			event.preventDefault();
			alert('Please enter security code!');
			this.securityCode.focus();
			return;
		}
	});
}

function initContactForm() {
	$('#contactForm').submit(function(event) {
		if (isBlank(this.visitorName.value)) {
			event.preventDefault();
			alert('Please enter you name!');
			this.visitorName.focus();
			return;
		}
		if (isBlank(this.visitorEmail.value)) {
			event.preventDefault();
			alert('Please enter you email address!');
			this.visitorEmail.focus();
			return;
		}
		if (!isEmail(this.visitorEmail.value)) {
			event.preventDefault();
			alert('The email you entered is not valid!');
			this.visitorEmail.focus();
			return;
		}
		if (isBlank(this.securityCode.value)) {
			event.preventDefault();
			alert('Please enter security code!');
			this.securityCode.focus();
			return;
		}
	});
}

function initUninstallForm() {
	$('#uninstallForm').submit(function(event) {
		if (isBlank(this.comment.value)) {
			event.preventDefault();
			alert('Please enter you message!');
			this.comment.focus();
			return;
		}
		if (isBlank(this.email.value)) {
			event.preventDefault();
			alert('Please enter you email address!');
			this.email.focus();
			return;
		}
		if (!isEmail(this.email.value)) {
			event.preventDefault();
			alert('The email you entered is not valid!');
			this.email.focus();
			return;
		}
	});
}

function initTestimonials () {
	var words = $('#tesimonials li');
	if (words.length <= 1) {
		return;
	}
	var index = 0;
	setInterval(function() {
		$(words[index]).hide('long');
		index++;
		if (index >= words.length) {
			index = 0;
		}
		$(words[index]).show('long');
	}, 8000);
}

function initCarousel() {
	$("#carousel").CloudCarousel({			
		'xPos': 475
		, 'yPos': 70
		, 'reflHeight': 50
		, 'reflGap': 2
		, 'reflOpacity': 0.5
		, 'mouseWheel': true
		, 'buttonLeft': $("#leftBtn")
		, 'buttonRight': $("#rightBtn")
		, 'altBox': $("#altText")
		, 'titleBox': $("#titleText")
	});
	$("#carousel a").lightBox();
}

$(document).ready(function() {
	initRegisterForm();
	initContactForm();
	initUninstallForm();
	initTestimonials();
	initCarousel();
});
})();
