/*Class NCMCollection implements functionality of collection*/
function NCMCollection() {
	this.keys = new Array();
	this.values = new Array();
	this.s = 0;
}

NCMCollection.prototype = {
	add: function(key,val) {
			if(val==null) return;
			if(this.getIndex(key)==-1) {
				this.keys[this.s] = key;
				this.values[this.s] = val;
				this.s++;
			}
		 },
	get: function(key) {
			if(key==null) return;
			return this.values[this.getIndex(key)];
		 },
	item: function(i) {
			if(i>=this.s) return;
			return this.values[i];
		  },
	size: function() {return this.s;},
	remove: function(key) {
				if(key==null) return;
				var ind = this.getIndex(key);
				var size = this.size();
				if(ind<size-1) {
					for(var i=ind;i<size-1;i++) {
						this.keys[i] = this.keys[i+1];
						this.values[i] = this.values[i+1];
					}
				}
				this.keys[size] = null;
				this.values[size] = null;
				this.s--;
			},
	getLast: function() {
				if(this.size()>0)
					return this.values[this.size()-1];
				return null;
			 },
	getFirst: function() {
				if(this.size()>0)
					return this.values[0];
				return null;
			  },
	getIndex: function(key) {
				if(key==null) return -1;
				for(var i=0;i<this.s;i++)
					if(this.keys[i]==key)
						return i;
				return -1;
			  },
	clear:  function() {
				this.keys = new Array();
				this.values = new Array();
				this.s = 0;
			},
	addAll: function(coll) {
				for(var i=0;i<coll.size();i++)
					this.add(coll.keys[i],coll.values[i]);
			}
};
/*End of NCMCollection class definition*/

/*Class NCMHash implements functionality of hash table*/
function NCMHash() {
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}

	this.removeItem = function(in_key) {
		var tmp_value;
		if (typeof(this.items[in_key]) != 'undefined') {
			this.length--;
			var tmp_value = this.items[in_key];
			delete this.items[in_key];
		}
		return tmp_value;
	}

	this.getItem = function(in_key) {
		return this.items[in_key];
	}

	this.setItem = function(in_key, in_value) {
		if (typeof(in_value) != 'undefined') {
			if (typeof(this.items[in_key]) == 'undefined') {
				this.length++;
			}
			this.items[in_key] = in_value;
		}
		return in_value;
	}

	this.hasItem = function(in_key) {
		return typeof(this.items[in_key]) != 'undefined';
	}
}
/*End of Hash class definition*/

/*Class NCMDateUtil implements functions to work with dates*/
function NCMDateUtil(params) {
	var monthdays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	
	this.d = params.day?parseInt(params.day):-1;
	this.m = params.month?parseInt(params.month):-1;
	this.y = params.year?parseInt(params.year):0;  
	
	//Check the leap year
	this.checkLeapYear = function (yyyy) {
		if(yyyy%4==0 && (yyyy%100!=0 || yyyy%400==0)) 
   			return true;
		else
			return false;
	}

	//Maximum value of days as a function of month and year
	this.getMaxDays = function(month,year) {
		if(month==1) {
	    	if(this.checkLeapYear(year))
	        	monthdays[1]=29;
	    	else
	        	monthdays[1]=28;
		}
	
		if(month<0 || month>11)
	    	return -1;
		else
	    	return monthdays[month];           
	}

	//Check if date is correct
	this.checkDateCorrect = function() {
    	if ((this.d<0 || this.d>31) || (this.m<0 || this.m>11)  || !this.y)
        	return false;
	    if (this.d > this.getMaxDays(this.m,this.y))
        	return false;

    	return true;
	}
	
	this.getDateString = function() {
		var res = "";
		if(this.checkDateCorrect()) {
			res = (this.d<10?"0":"")+this.d+"/"+(this.m+1<10?"0":"")+(this.m+1)+"/"+this.y;
		} else {
			res = "#error#";
		}
		return res;	
	}
}
/*End of NCMDateUtil class definition*/

/*Class NCMTextUtil implements functions to work with texts*/
function NCMTextUtil() {
}

NCMTextUtil.replaceBadChars = function(text) {
	var res = text.replace(/&aacute;/,"\xE1").replace(/&Aacute;/,"\xC1").replace(/&Iacute;/,"\xCD");
	res = res.replace(/&Oacute;/,"\xD3").replace(/&Uacute;/,"\xDA").replace(/&eacute;/,"\xE9");
	res = res.replace(/&iacute;/,"\xED").replace(/&oacute;/,"\xF3").replace(/&uacute;/,"\xFA").replace(/&ntilde;/,"\xF1");
	return res;
}
/*End of NCMTextUtil class definition*/
 


