userAccount = {
	'checkUserInfoAvailablity' : function(username, email, password){
		if(!username) {
			FormElementError.show(".username-element", message.inValidUser);
		}
		else {
			if(!email && isEmailValid) {
				FormElementError.show(".email-element", message.inValidEmail)
			} else {
				if(!password || (password.length < 6)) {
					FormElementError.show(".password-element", message.inValidPassword)
				} else {
					return true;
				}
			}
		}
	},
	'setOrganisation': function(organisation){
		if(!organisation) {
			FormElementError.show(".organisation-element", message.inValidOrganisation);
		}
		else {
			Meteor.call('createOrganisation', organisation, (err, organisationId) => {
				if (organisationId) {
					Session.set("currentOrganisation", organisationId);
					Meteor.call('setCurrentOrganisationForUser', organisationId, (err) => {
						if (!err) {
							FlowRouter.go("/");
						} else {
							FormElementError.show(".organisation-element", err)
						}
					});
				} else {
					FormElementError.show(".organisation-element", err)
				}
			});
		}
	}
}
bookmarkThis = function(type, stuffId, isbookmarked) {
	var isBookmarkPresent = Bookmark.find({"bookmarkType": type,"stuffId": stuffId}).count();
	if(isBookmarkPresent) {
		Meteor.call('updateBookmark', type, stuffId, isbookmarked , function (error, result) {});
	} else {
		Meteor.call('insertBookmark', type, stuffId, function (error, result) {});
	}
};
function isEmailValid(email) {
	var re = /^(([^<>()[]\.,;:s@"]+(.[^<>()[]\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/igm;
	if (re.test(email)) return false;
	else 
	return true;
}
FormElementError = {
	'show' : function(ele, msg){
		FormElementError.clear();
		$(ele + ".form-element-error").html(msg)
	},
	'clear' : function(){
		$(".form-element-error").html("")
	}
}
Utilities = {
	'getNumbersOfDaysFromNow': function(unFormatDate) {
		var givenDate = new Date(unFormatDate);
		var dateNow = new Date();
		var _MS_PER_DAY = 1000 * 60 * 60 * 24;
		var utc1 = Date.UTC(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate());
		var utc2 = Date.UTC(dateNow.getFullYear(), dateNow.getMonth(), dateNow.getDate());
		return (Math.floor((utc2 - utc1) / _MS_PER_DAY));
	},
	'tilt_direction': function(item) {
		var left_pos = item.position().left,
		move_handler = function (e) {
			if (e.pageX > left_pos) {
				item.addClass("right");
				item.removeClass("left");
			} else{
				if (e.pageX < left_pos) {
					item.addClass("left");
					item.removeClass("right");
				}
			}
			left_pos = e.pageX;
		};
		$("html").bind("mousemove", move_handler);
		item.data("move_handler", move_handler);
	}
}