

var Validation = {
	_currValue: null,
	_currObj: null,

	
	select_List : function(id, msg) {
		var obj = document.getElementById(id).options[document.getElementById(id).selectedIndex];
		if (obj.value == '-1') {
			this.alert(msg);
			document.getElementById(id).focus();
			return false; 
		} else {
			return true;
		}		
	},

	logo : function(id, msg) {
		//checks for logo's either new or existing
		var newlogo = document.getElementById(id);
		var existinglogo = document.getElementById('img_' + id);
		if ((existinglogo.value != '') || (newlogo.value != '')) {
			return true;
		} else {
			if (msg.length > 0) {this.alert(msg);}
			document.getElementById(id).focus();
			return false;
		}
		
	},

	i : function(id, msg) {
		var obj = document.getElementById(id);
		var result = this.validate_by_regexp(obj, msg, '^-?\\d+$', obj);
		return result;
	},
	
	cc : function(id, msg) {
		var obj = document.getElementById(id);
		var result = this.validate_by_regexp(obj, msg, '^[0-9 ]{10,20}$', obj);
		return result;
	},

	m : function(id, msg) {
		var obj = document.getElementById(id);
		var result = this.validate_by_regexp(obj, msg, '^-?\\d+(\\.?\\d+)?$', obj);
		return result;
	},

	s : function(id, msg) {
		//checks non empty string
		var obj = document.getElementById(id);
		var result = this.validate_by_regexp(obj, msg, '.+', obj);
		return result;
	},

	c : function(id, msg) {
		//checks for ticked checkboxes
		var result;
		var check = document.getElementById(id);
		if (check.checked == true) {
			result = true;
		} else {
			if (msg.length > 0) {this.alert(msg);}
			check.focus();
			result = false;
		}
		return result;
	},
	
	validate_by_regexp : function (obj, msg, regexp, objFocus) {
		if (obj.value.search(regexp) == -1) {
			if (msg.length > 0) {this.alert(msg);}
			objFocus.focus();
			return false; 
		} else {
			return true;
		}
	},
	
	alert: function(msg) {
		if (MessageBox != undefined) {
			MessageBox.strong();
			MessageBox.header('Error');
			MessageBox.show(msg);
		} else {
			alert(msg);
		}
		
	},
	
	numbersOnly: function(obj) {
		var _this = this;
		obj.bind('keydown', _this, function(o) {
			if (Validation._currValue == null) {
				Validation._currObj = o.data;
				Validation._currValue = this.value;
			}
			
		});

		/*
		obj.bind('keyup',  function() {
			if (!Validation.i(this.id, '')) {
				this.value = Validation._currValue;
				Validation._currValue = null;
				Validation._currObj = null;
				if (this.value == 'null') {
					this.value = '';
				}
			}
			
			
		});*/
	}
	
	


}

