if (!document.getElementById) document.getElementById = function (id) { return document.all ? document.all[id] : eval(id); }
function $(id) { return document.getElementById(id); }

function newAjaxRequest() {
    var result = null;
	try {
		result = new XMLHttpRequest();
	} catch (e) {
		try {
			result = ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				result = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
    			//alert("Your browser does not support XMLHttpRequest !!!!");
			}
		}
	}
	return result;
}

function addEvent(obj, eventName, callback) {
	if (obj.addEventListener) {
		obj.addEventListener(eventName, callback, false);
	} else if (obj.attachEvent) {
		obj.attachEvent('on'+eventName, callback);
	} else { obj['on'+eventName] = callback; }
}

function ReplaceClass(obj, delCss, addCss) {
	if (obj && obj.className) {
		var cl = obj.className.replace(new RegExp('(\s*|^)'+delCss+'(\s*|$)', 'g'), '$2');
		if (addCss && addCss.length > 0) cl += ' ' + addCss;
		obj.className = cl;
	}
	return obj;
}

var Check = {
	IsLogin : function (str) { return str.match(/^[a-z0-9\-_]+$/i) != null; },
	IsEmail : function (str) { return str.match(/^\s*([a-z0-9\-_\.\+]+@(?:[a-z0-9\-_]+\.)+[a-z]{2,4})\s*$/i) != null; },
	IsPhone : function (str) { if(str.length > 64) return false; return str.replace(/[^0-9]+_- /g, '').match(/^(\+)?(?:38|8)(-| | - )?(?:[0-9]{3})(-| | - )?(?:[0-9]{3})(-| | - )?(?:[0-9]{2})(-| | - )?(?:[0-9]{2})$/) != null; },
	IsNotEmpty : function(str) { return str.replace(/^\s*(.*)\s*$/, '$1').length > 0; }
}

var Hint = {
	timer : null,
	current : null,
	lock : false,
	Show : function (obj, lock) {
		if (obj) {
			this.stopHide();
			if (obj != this.current) {
				if (lock || !this.lock) {
					this.doHide();
					this.current = obj;
					this.lock = lock ? true : false;
					ReplaceClass(this.current, 'hidden', '');
				}
			} else if (lock) {
				this.lock = true;
			}
		}
	},
	Hide : function (obj, lock) {
		if (this.current == obj && (lock || !this.lock)) {
			this.stopHide();
			this.timer = window.setTimeout("Hint.doHide();", 250);
		}
	},
	stopHide : function () {
		if (this.timer) {
			window.clearTimeout(this.timer);
			this.timer = null;
		}
	},
	doHide : function () {
		if (this.current) {
			this.stopHide();
			ReplaceClass(this.current, 'hidden', 'hidden');
			this.current = null;
			this.lock = false;
		}
	}
};
