(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 initManufacturers() {
	$('#searchBrand').attr('selectedIndex', 0).change(function(event) {
		$.ajax({
			'url': '/helper/manufacturers/manufacturers_' + $(this).attr('value') + '.php'
			, 'dataType': 'html'
			, 'type': 'POST'
			, 'success': function(msg){
				$('#manufacturer').html(msg);
			}
		});
	});
}

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

function initLightBox() {
	$(function() {
        $('#screenshots a').lightBox();
    });
}

$(document).ready(function() {
	initManufacturers();
	initContactForm();
	initLightBox();
});
})();
