function clsCore() {
	this.objForm = new clsForm();
	this.objStatus = new clsStatus();
	this.objTool = new clsTool();
}

function clsTool() {
	this.fncFormatTime = function(varValue, varFormat) {
		if (varFormat == undefined) varFormat = "%H:%M:%S";

		var varSeconds = Math.floor(varValue/1000);
		var varHours = Math.floor(varSeconds/3600);
		varSeconds -= varHours*3600;
		var varMinutes = Math.floor(varSeconds/60);
		varSeconds -= varMinutes*60;

		var varResult = varFormat.split('%H').join(varHours < 10 ? "0" + varHours : varHours);
		varResult = varResult.split('%M').join(varMinutes < 10 ? "0" + varMinutes : varMinutes);
		varResult = varResult.split('%S').join(varSeconds < 10 ? "0" + varSeconds : varSeconds);

		return varResult;
	}

	this.fncCreateUniqueStr = function($prefix, $length) {
		if ($length == undefined) $length = 12;
		var $string = $prefix;
		for (var i=0; i<$length; i++) {
			do {
				var $number = Math.round(Math.random()*100);
			}
			while ($number > 25);
			var $offset = Math.round(Math.random()) ? 65 : 97;
			$string += String.fromCharCode($number+$offset);
		}
	return $string;
	}
}

function clsForm() {
	var _self = this;

	this.fncCheckField = function(tmpIndex, tmpRegExp) {
		var objField = $('fld'+tmpIndex);
		var objImage = $('img'+tmpIndex);
		if (!tmpRegExp.exec(objField.value)) {
			this.fncSetIcon(tmpIndex, 'bad');
			return false;
		}
		else {
			this.fncSetIcon(tmpIndex, 'ok');
			return true;
		}
	}

	this.fncCompareFields = function(tmpIndex, tmpIndex2) {
		var objField = $('fld'+tmpIndex);
		var objField2 = $('fld'+tmpIndex2);
		var objImage = $('img'+tmpIndex)
		if (objField.value != objField2.value) {
			this.fncSetIcon(tmpIndex, 'bad');
			return false;
		}
		else {
			this.fncSetIcon(tmpIndex, 'ok');
			return true;
		}
	}

	this.fncSetIcon = function(tmpField, tmpStatus) {
		var objImage = $('img'+tmpField);
		var varSource = objImage.src;
		objImage.src = varSource.replace(/(.*)(_.*)(\.[gif|jpg|png])/, '$1_'+tmpStatus+'$3');
	}
}

function clsStatus() {
	this.options = {duration: 5};

	var varTimeout;

	this.fncSet = function(varText, varLevel) {
		$('pStatus').className = varLevel;
		$('pStatus').innerHTML = varText;
		$('divStatus').style.display = 'block';
	};
}

function clsList(tmpList) {
	var _self = this;

	var objElement;
	var objNewElement;

	var varList = 'divList';

	this.setList = function(tmpList) {
		varList = tmpList;
	}

	this.fncDeactivate = function() {
		objElement.className = 'listitem';

		var objAdmin = $(objElement.id+'Admin');
		if (objAdmin) {
			objAdmin.innerHTML = null;
			objAdmin.hide();
		}
	};

	this.fncActivate = function() {
		objNewElement.className = 'listitem_active';
	};

	this.fncSelect = function(tmpElement) {
		if (typeof(tmpElement) != 'object') tmpElement = $(tmpElement);
		if (tmpElement != objElement) {
			objNewElement = tmpElement;
			if (objElement)	this.fncDeactivate();
			this.fncActivate();
			objElement = objNewElement;
			this.fncFormatList();
		}
	};

	this.onListUpdate = function() {
		this.fncFormatList();
	};

	this.fncFormatList = function() {
		var varItems = $(varList).getElementsByTagName("div");
		for(var i=0; i < varItems.length; i++) {
			var varItem = varItems[i];
			if (varItem.className.indexOf('listitem') != -1) {
				if (varItem.className.indexOf('active') != -1) {
					varItem.onmouseout = varItem.onmouseover = null;
				}
				else {
					varItem.onclick = function() {
						_self.fncSelect(this);
					};
					varItem.onmouseout = function() {
						this.className = 'listitem';
					};
					varItem.onmouseover = function() {
						this.className = 'listitem_over';
					};
				}
			}
		}
	};

	this.setList(tmpList);
}


/*
function clsMenu() {
	this.varItems = new Array();

	this.fncAddItem = function(tmpText, tmpLink) {
		this.varItems.push({text: tmpText, link: tmpLink});
	};

	this.fncCreate = function() {
		var varItems = new Array();
		for (var i=0; i < this.varItems.length; i++) {
			var varItem = this.varItems[i];
			varItems.push('<a href="'+varItem.link+'">'+varItem.text+'</a>');
		}
		var varHtml = '<p>'+varItems.join(' | ')+'</p>';
		return varHtml;
	};

	this.fncAssign = function(tmpId) {
		$(tmpId).innerHTML = this.fncCreate();
	};
}
*/
