var common = function() {

	return {
		
		removeArr : function(arr, action, mod, displayMessage){
			var data = new Array();
			common.doRemove(arr, action, mod, displayMessage, data)	;	
		},
	
		remove: function(id, action, mod, displayMessage){
			var data = new Array();
			var arr = new Array();
			arr[0] = id;
			common.doRemove(arr, action, mod, displayMessage, data);
		},	
	
		removeAdddata: function(id, action, mod, displayMessage, data){

			var arr = new Array();
			arr[0] = id;
			common.doRemove(arr, action, mod, displayMessage, data);
		},		
		
		doRemove : function(arr, action, mod, displayMessage, data) {
			var conf = confirm(displayMessage);
			if(!conf){
				return;
			}
			$.post("./index.php?mod=" + mod + "&xhr=1", {
				idArr : arr,
				action : action,
				data : data
			}, function(data) {
				if (data !== null) {
						if (data.result) {
							$("#content").html(data.content);
						} else {
							$("#contentError").html(data.message);
						}
					
				}
			}, "json");				
		},		

		sendData : function(url, toSendData) {
			$.post(url, toSendData, function(data) {
				if (data !== null) {
					if (data.message !== undefined) {
						if (data.result) {
							if(data.content != ""){
								$("#content").html(data.content);
							}
						} else {
							$("#contentError").html(data.message);
						}
					}
				}
			}, "json");
		},
		
		sendDataAndRedirect : function(url, toSendData, redirectUrl) {
			$.post(url, toSendData, function(data) {
				if (data !== null) {
					if (data.message !== undefined) {
						if (data.result) {
							window.location = redirectUrl;
						} else {
							$("#contentError").html(data.message);
						}
					}
				}
			}, "json");
		},
		
		checkLength : function(o,n,min,max){
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				this.updateTips(n + " mag minimaal "+min+" en maximaal "+max+" characters.");
				return false;
			} else {
				return true;
			}
		},
		
		 updateTips : function(element, value){
			$(element).html(value)
				.addClass('ui-state-highlight');
			setTimeout(function() {
				element.removeClass('ui-state-highlight', 1500);
			}, 500);
		 },

		doLogin : function(userName, passw) {
			var dataToSend = {
				name : userName,
				passw : passw,
				action : "doLogin"
			};
			$.post("./index.php?mod=Mod_login&xhr=1", dataToSend, function(data) {
				if (data !== null) {
					if (data.result) {
						window.location="./index.php?mod=Mod_cms";
					} else {
						// $("#contentError").html(data.message);
						$("#notify").show();
						
					}

				}
			}, "json");
		}
		
		
	};
}();

