function browseIt()
{
	this.ver = navigator.appVersion.toLowerCase();
	this.verNum = parseInt(this.ver);
	this.agent = navigator.userAgent.toLowerCase();
	this.dom = (document.getElementById ? 1 : 0);
	this.opera = (this.agent.indexOf("opera") > -1 && this.dom ? 1 : 0);
	this.opera7 = (this.opera && this.verNum >= 7);
	this.opera9 = (this.opera && this.verNum >= 9);
	this.ie = (this.ver.indexOf("msie") > -1 && this.dom && !this.opera ? 1 : 0);
	this.ieVer = 0;
	if (this.ie) {
		var pos = this.ver.indexOf("msie");
		if (pos != -1)
			this.ieVer = parseFloat(this.ver.substr(pos + 5));
	}
	this.ie6 = (this.ie && (this.ieVer >= 6));
	this.ie6only = (this.ie && (this.ieVer >= 6) && (this.ieVer < 7));
	this.ie7 = (this.ie && (this.ieVer >= 7));
	this.macOS = (this.agent.indexOf("mac") > -1);
	this.mac = (this.macOS && this.verNum >= 7 ? 1 : 0);
	this.moz = (this.agent.indexOf("gecko") > -1);
	this.ns6 = (this.dom && this.agent.indexOf("netscape") > -1 && this.verNum >= 5 ? 1 : 0);
	this.ff = (this.agent.indexOf("firefox") > -1);
	this.b = (this.ie || this.ns6 || this.opera7 || this.mac || this.moz || this.dom);

	return this;
}

//var px = window.opera ? "" : "px";
var b = new browseIt();

function clearValue(obj,toPwd)
{
	if (obj)
	{
		obj.value = "";
		if (toPwd)
		{
			var parent = obj.parentNode;
			var objId = obj.id;

			if (parent != null)
			{
				var oldInput = parent.innerHTML;

				oldInput = oldInput.replace('type="text"','');
				oldInput = oldInput.replace('onfocus=clearValue(this,1);','onfocus=clearValue(this,0);');
				oldInput = oldInput.replace('onclick=clearValue(this,1);','onclick=clearValue(this,0);');
				oldInput = oldInput.replace('onfocus="clearValue(this,1);"','onfocus="clearValue(this,0);"');
				oldInput = oldInput.replace('onclick="clearValue(this,1);"','onclick="clearValue(this,0);"');

				oldInput = oldInput.replace('>',' type="password">');

				if (oldInput.search(/type=password/i) == -1)
				{
					parent.removeChild(obj);
					parent.innerHTML = oldInput;

					var newObj = document.getElementById(objId)
					if (newObj)
					{
						newObj.focus();
						newObj.focus();
					}
				}
			}
		}
	}
}

function checkKey(e,withCtrl,keys,urls)
{
	var code;
	if (!e) var e = window.event;

	if (withCtrl == 1)
	{
		if (e.keyCode && e.ctrlKey) code = e.keyCode;
		else if (e.which && e.ctrlKey) code = e.which;
	}
	else
	{
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
	}

	//alert(code);
	if (keys.length>0)
	{
		for (i=0; i < keys.length; i++)
		{
			if (code == keys[i])
			{
				if (urls[i])
				{
					//alert(urls[i]);
					window.location = urls[i];
				}
			}
		}
	}
}

function checkKey2(e,id)
{
	var code;

	if (!e) var e = window.event;

	var keyPressObj = (e.srcElement)?e.srcElement:null;
	keyPressObj = (e.target)?e.target:keyPressObj;

	if (e.keyCode)
	{
		code = e.keyCode;
	}
	else if (e.which)
	{
		code = e.which;
	}

	var dontSubmit = 0;
	if (keyPressObj)
		if (keyPressObj.type == "textarea" || keyPressObj.type == "button")
			dontSubmit = 1;

	if (code == 13 && !dontSubmit)
	{
		var submitForm = document.getElementById(id);
		if (submitForm)
		{
			submitForm.submit();
		}
	}

}

function add_click (url,target) {
	if (url) {
	//alert("Debug:"+url);
	//alert("Debug:"+target);
	if (target=="_parent") {
	parent.location.href=url;
	}
	if (target=="_blank") {
	window.open(url);
	}
	if (target=="_self") {
	location.href=url;
	}
	if (target=="_top") {
	top.location.href=url;
	}
	}//end if !url
}

function rollOver(id,file)
{
	var thisObj = document.getElementById(id);
	thisObj.src = file;
}

function getContent(idContent,idMenu,url)
{
	//var SendURL = "ajax.php?p="+p+"&"+url;
	var SendURL = url;
	var linkObj = null;
	var linkObjP = null;

	StatusMessage();

	var contentObj = document.getElementById(idContent);

	var loadingM = document.getElementById('loadingSI');
	if (loadingM)
	{
		//loadingM.style.width = "px";
		loadingM.style.display = "block";
	}

	var callback = function(result)
	{
		contentObj.innerHTML = result;

		if (idMenu)
		{
			for (i=0; i<MainDivs.length;i++)
			{
				linkObj = document.getElementById(MainDivs[i]);
				linkObjP = document.getElementById('p_'+MainDivs[i]);

				if (linkObj && MainDivs[i] == idMenu)
				{
					linkObj.className = "current";
					linkObjP.style.display = "block";
				}
				else if (linkObj)
				{
					linkObj.className = "";
					linkObjP.style.display = "none";
				}
			}
		}
	}

	HTML_AJAX.onError = function(e)
	{
		if (confirm("Some errors on server\r\n Repeat request?'"))
			HTML_AJAX.grab(SendURL, callback);
	}

	HTML_AJAX.grab(SendURL, callback);


	/*
	replaceContent(idContent,SendURL);
	*/
}

function replaceContent(id,url)
{
	//ShowMessage();
	HTML_AJAX.replace(id,url);
}

function getCalendar(id,p,url)
{
	var SendURL = "ajax.php?p="+p+"&"+url;
	//alert(SendURL);
	//window.scrollTo(0,0);
	StatusMessage();

	var loadingM = document.getElementById('loadingSI');
	if (loadingM)
		loadingM.style.display = "block";

	replaceContent(id,SendURL);
}

function setupMessage()
{
	var loading = document.getElementById('HTML_AJAX_LOADING');
	if (!loading)
	{
		loading = document.createElement('div');
		loading.id = 'HTML_AJAX_LOADING';
		loading.innerHTML = '';
		loading.className = 'HTML_AJAX_Loading';
		loading.count = 0;

		document.body.insertBefore(loading,document.body.firstChild);
	}

	loading.style.display = "none";
}

function StatusMessage()
{
	setupMessage();
	return;

	//var stMessage = document.getElementById('HTML_AJAX_LOADING');
	//if (stMessage == null)
	//{
		//return;
	//}

	//var newPlace = document.getElementById(idContent);

	//if (newPlace != null)
	//{
		//var insertInParent = (newPlace.parentNode)?newPlace.parentNode:newPlace.parent;
		//insertInParent.appendChild(stMessage);
	//}

	//var parentWidth = insertInParent.offsetWidth;

	//stMessage.style.left = "auto";
	//stMessage.style.right = 40 +  "px";
	//stMessage.style.width = 100 +  "px";
	//stMessage.style.height = 20 +  "px";
	//stMessage.style.top = "149px";
	//stMessage.style.display = "block";
}

function setValueForInput(valueTxt,fieldId)
{
	var fieldObj = document.getElementById(fieldId);
	if (fieldObj)
	{
		fieldObj.value = valueTxt;
	}
}

var prevBG = new Array;
var MenuSH = new Array;
var lastId = "";

function OverOutTD(idTd, type)
{
	var tdObj = document.getElementById(idTd);
	var widthTd = tdObj.offsetWidth;
	var addWidthTd = (tdObj.offsetWidth*10)/100;
	var widthSub = widthTd + addWidthTd;

	widthSub = (widthSub<120)?120:widthSub;

	if (tdObj)
	{
		//hideAll(idTd);

		var subObj = document.getElementById('sub_'+idTd);
		var aObj = document.getElementById('a_'+idTd);

		switch (type)
		{
			case "over":
				MenuSH[idTd]=1;
				if (prevBG[idTd]=="" || !prevBG[idTd])
					prevBG[idTd] = tdObj.className;

				//if (subObj)
					//tdObj.style.background = "url('img/bg/menu_over2.gif') no-repeat center top";
				//else
					//tdObj.style.background = "url('img/bg/menu_over1.gif') no-repeat center top";

				//tdObj.style.background = "#bf2026";

				if (aObj)
				{
					aObj.className = "topMenuCurrent";
				}

				if (subObj)
				{
					subObj.style.width = widthSub + "px";
					if (lastId == idTd)
						subObj.style.marginLeft = "-"+(addWidthTd+7)+ "px";
					subObj.style.display = "block";
				}
				break;

			case "out":
				MenuSH[idTd]=0;
				setTimeout('outTD("'+idTd+'")',0);
				break;
		}
	}
}

function outTD(idTd)
{
	if (MenuSH[idTd]==0)
	{
		var tdObj = document.getElementById(idTd);
		if (prevBG[idTd])
		{
			if (tdObj.className != "level1 current") {
				tdObj.style.background = "";
			}
			tdObj.className = prevBG[idTd];
			prevBG[idTd] = "";
		}

		var subObj = document.getElementById('sub_'+idTd);
		if (subObj)
		{
			subObj.style.display = "none";
		}

		var aObj = document.getElementById('a_'+idTd);
		if (aObj && tdObj.className != "level1 current")
		{
			aObj.className = "topMenu";
		}
	}
}

function hideAll(currentTd)
{
	for (i=0; i < MainDivs.length; i++)
	{
		if (MainDivs[i])
		{
			if (MainDivs[i]!=currentTd)
			{
				var obj = document.getElementById(MainDivs[i]);
				if (obj)
				{
					if (prevBG[MainDivs[i]] && prevBG[MainDivs[i]]!="")
					{
						obj.style.background = prevBG[MainDivs[i]];
						prevBG[MainDivs[i]] = "";
					}
				}

				var subObj = document.getElementById('sub_'+MainDivs[i]);
				if (subObj)
				{
					subObj.style.display = "none";
				}

				var aObj = document.getElementById('a_'+MainDivs[i]);
				if (aObj)
				{
					aObj.className = "outMade";
				}
			}

			lastId = MainDivs[i];
		}
	}
}