/**
 * Class for contact form box (frontend)
 *
 * @package ContactFormBoxFe
 * @category Module
 * @author Mirek Bily
 * @copyright e-invent s.r.o.
 */
function ContactFormBoxFe() {

	/** @var {object} */
	var self = this;


	/**
	 * Class init
	 *
	 * @return {void}
	 */
	self.__init = function() {
		// Form is hidden
		$('.contactBoxSpam').css('display', 'none');

		// Form button submit validate
		$('#contactBoxFormButton').click(function(){
			return self.validateBoxForm();
		});

		// Email focus / blur
		$('#contactBoxName').focus(function() {
			if (this.value == (php.lang.trans.cfmVaseJmeno)) this.value = '';
		}).blur(function() {
			if (this.value == '') this.value = php.lang.trans.cfmVaseJmeno;
		});

		// Email focus / blur
		$('#contactBoxEmail').focus(function() {
			if (this.value == (php.lang.trans.sysEmail + '/' + php.lang.trans.sysPhone)) this.value = '';
		}).blur(function() {
			if (this.value == '') this.value = php.lang.trans.sysEmail + '/' + php.lang.trans.sysPhone;
		});

		// Message focus / blur
		$('#contactBoxMessage').focus(function() {
			if (this.value == (php.lang.trans.cfmBoxMessage)) this.value = '';
		}).blur(function() {
			if (this.value == '') this.value = php.lang.trans.cfmBoxMessage;
		});
	};


	/**
	 * Validate form data and send
	 *
	 * @return {bool}
	 */
	self.validateBoxForm = function() {
		var error = new String();
		var name = $('#contactBoxName').val();
		var email = $('#contactBoxEmail').val();
		var message = $('#contactBoxMessage').val();

		if (message.length == 0 || message == php.lang.trans.cfmVaseJmeno) error += php.lang.trans.cfmNameError + '\n';
		if (email.length == 0 || email == (php.lang.trans.sysEmail + '/' + php.lang.trans.sysPhone)) error += php.lang.trans.cfmEmailPhoneError + '\n';
		if (message.length == 0 || message == php.lang.trans.cfmBoxMessage) error += php.lang.trans.cfmMessageError + '\n';

		if (error.length != 0) {
			alert(error);

			return false;
		} else {
			return true;
		}
	}

}


var contactFormBoxFe = new ContactFormBoxFe();

$(document).ready(function() {
	contactFormBoxFe.__init();
});

