function GES_Class() {
	this.init();
}

GES_Class.prototype.init = function() {
	this.bindElements();
	this.bindEvents();
}

GES_Class.prototype.bindElements = function() {
	this.errorMessage = $("div.errorMessage");
	this.input = $("#serviceform input[type='text']");
	this.button = $("#formSubmit");
	this.close = $("a.close");
}

GES_Class.prototype.bindEvents = function() {
	this.input.bind("blur", {self: this}, this._handleBlurError);
	this.input.bind("focus", {self: this}, this._handleFocus);
	this.button.bind("click", {self: this}, this._handleFormSubmition);
	this.close.bind("click", {self: this}, this._handleClose);
}

GES_Class.prototype._handleClose = function() {
		$("#ajaxResponse").fadeOut("slow", function() {
			$(this).empty();
			$("#pageMask").remove();
			setTimeout(function() { window.location = "contactus.php" }, 1000);
		});
}

GES_Class.prototype._handleBlurError = function(e) {
	var _self = e.data.self;
	var $currentTarget = $(this);
	if($currentTarget.val() === "")
	{
		if(!$(this).parent().next("p.errorMessage").length) {
			_self.appendError($currentTarget);
		}		
	}
	else {
		_self.removeError($currentTarget);			
	}
}

GES_Class.prototype.checkInputs = function() {
	this.input.each(function() {
		
	});
}

GES_Class.prototype.appendError = function($el) {
	$el
	.parent()
	.append(
		this.errorMessage
		.clone()
		.removeClass("none")
	);
}

GES_Class.prototype.removeError = function($el) {
	$el.siblings("div.errorMessage").remove();
}

GES_Class.prototype._handleFocus = function(e) {
	var _self = e.data.self;
	if($(this).siblings("div.errorMessage").length) {
		_self.removeError($(this));
	}
}

GES_Class.prototype._checkErrorMessage = function($el) {
	if(!$el.siblings("div.errorMessage").length) {
		this.appendError($el);
	}	
}


var GES = new GES_Class();
