function sFormFunc (defvalue, colorIn, colorOut, delay) {
	var sForm = document.getElementById("searchForm");
	var sBtn = sForm.childNodes[sForm.childNodes.length-1];
		sBtn.onmouseover = function() { this.className += "over"; };
		sBtn.onmouseout = function() { this.className = this.className.replace("over",""); };
		sBtn.onfocus = function() { this.blur(); };
	var sInput = document.getElementById("q");

	function setTempValue (e) {
		if (e.value === null || e.value === "" || e.value == defvalue) {
			e.value = defvalue;
			e.style.color = colorOut;
		}
	}
	setTempValue(sInput);
	sForm.onsubmit = function() {
		if (sInput.value === null || sInput.value === "" || sInput.value == defvalue) {
			var nTxt = document.createTextNode("Уточните запрос, пожалуйста!");
			var nSpanTag = document.createElement("span");
				nSpanTag.appendChild(nTxt);
			var nPTag = document.createElement("p");
				nPTag.appendChild(nSpanTag);
			if (!this.getElementsByTagName("p")[0]) {
				var ePTag = this.insertBefore(nPTag, this.firstChild);
				var t = setTimeout( function() { sForm.removeChild(ePTag);clearTimeout(t); },delay*1000);
				ePTag.onclick = function() { sForm.removeChild(this);clearTimeout(t); };
			}
			return false;
		} else {
			this.submit();
		}
	};
	sInput.onfocus = function() {
		if (this.value == defvalue) {
			this.value = "";
			this.style.color = colorIn;
		}
	};
	sInput.onblur = function() {setTempValue(this);};
}
window.onload = function() {
	var delayValue  = 200;
	var closeTimer  = 0;
	var curMenuItem = 0;
	var aLinks = document.getElementById("mNav").getElementsByTagName("a");

	sFormFunc ("Что искать?", "#262626", "#cccccc", 3);

	for (var i=0; i<aLinks.length; i++) {
		if (aLinks[i].className.indexOf("mnTLA") > -1) {
			aLinks[i].onmouseover = function() {
				if (this.nextSibling) {
					cancelCloseTime();
					closeNav();
					curMenuItem = this;
					curMenuItem.className += " selected";
					curMenuItem.nextSibling.style.visibility = "visible";
				}
			};
			aLinks[i].onmouseout = function() { closeNavTime(); };
			if (aLinks[i].nextSibling) {
				aLinks[i].nextSibling.onmouseover = function() { cancelCloseTime(); };
				aLinks[i].nextSibling.onmouseout = function() { closeNavTime(); };
			}
		}
	}

	function closeNav() {
		if (curMenuItem) {
			curMenuItem.className = curMenuItem.className.replace(" selected", "");
			curMenuItem.nextSibling.style.visibility = "hidden";
		}
	}
	function closeNavTime() {
		closeTimer = window.setTimeout(closeNav, delayValue);
	}
	function cancelCloseTime() {
		if (closeTimer) {
			window.clearTimeout(closeTimer);
			closeTimer = null;
		}
	}
	document.onclick = closeNav;
	if (typeof blurSubNavLinks=="function") { blurSubNavLinks("snav"); }
};

