if(document.all&&document.getElementById) isIE = true; else isIE = false;
if(document.getElementById && (navigator.appName=="Netscape")) isMZ = true; else isMZ = false;

function getTextContent(el) {
	if (el.textContent) return el.textContent;
	if (el.innerText) return (el.innerText);
}

function setTextContent(el, text) {
	if (el.textContent) el.textContent = text;
	if (el.innerText) el.innerText = text;
}

var activeTab = 1;

switchTab = function(tabH) {
	if (activeTab == 1) {
		document.getElementById('tab1').style.display = 'none';
		document.getElementById('tab2').style.display = 'block';
		activeTab = 2;
	} else {
		document.getElementById('tab1').style.display = 'block';
		document.getElementById('tab2').style.display = 'none';
		activeTab = 1;
	}
	document.getElementById('activeTab').value = activeTab;
	oldH = getTextContent(document.getElementById('h1'));
	newH = getTextContent(tabH);
	setTextContent(document.getElementById('h1'), newH); 
	setTextContent(tabH, oldH); 
}

roundIt = function () {
	divs = document.getElementsByTagName('div');
	for (i in divs) {
		if (divs[i].className) {
			if (divs[i].className.indexOf("round") == 0) { // rounded shit
				l = document.createElement("img");
				l.src = 'img/round_l.png';
				r = document.createElement("img");
				r.src = 'img/round_r.png';
				l.className = 'png imgl';
				r.className = 'png imgr';
				divs[i].appendChild(l);
				divs[i].appendChild(r);
			}
		}
	}
}

startList = function() {
	if (isIE) {
		var ieLIs = document.getElementById('menu').getElementsByTagName('LI');
		for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
			ieLIs[i].onmouseover=function() {
				this.className+=" a";
				var ieUL = this.getElementsByTagName('UL')[0];
				if (ieUL) {
					var ieMat = document.createElement('IFRAME'); 
						ieMat.style.width=ieUL.offsetWidth+"px";
						ieMat.style.height=ieUL.offsetHeight+"px";	
						ieUL.insertBefore(ieMat,ieUL.firstChild);
						ieUL.style.zIndex="99";
				}
			}
			ieLIs[i].onmouseout=function() {
				this.className=this.className.replace(' a', '');
			}
		}
	}
}

goodsList = function() {
	goodRoot = document.getElementById("goods");
	if (goodRoot) {
		for (i=0; i<goodRoot.childNodes.length; i++) {
			node = goodRoot.childNodes[i];
			if (node.nodeName=="LI") {
				hasUl = node.getElementsByTagName('UL');

				// {{{ если есть товары - то у первой ссылки класс t1
				hasTovar = false;
				hasA = node.getElementsByTagName('A');
				if (hasA.length > 0) {
					hasTovar = (hasA[0].className == 't0');
				}
				// }}}

				if (hasUl.length > 0 && hasTovar) { // обрабатываем тока те элементы, у которых есть подэлементы и товар
					node.onclick = function() { 
						for (j=0; j<node.parentNode.childNodes.length; j++) {
							if (node.parentNode.childNodes[j] !== this) {
								node.parentNode.childNodes[j].className = ""; // закроем все ноды кроме текущего
							}
						}
						this.className = (this.className == 'a') ? "" : "a";
						return false;
					}
					if (isIE) { /* IE */
					   hasUl[0].onclick = function() { return stopEvent(event);};
					} else if (isMZ) { /* MZ */
					   hasUl[0].addEventListener("click", function(ev){stopEvent(ev)}, true);
					}
				}
			}
		}
	}
}

function stopEvent(event) {
	event.cancelBubble = true;
	if (event.stopPropagation) {
		event.stopPropagation();
	}
}


/* calendar */
var cal_value = new Date();

/* открытие окна календаря */
function calendar(sel) {
	if (document.getElementById('srok').options.lengh == 3) { // был календарь
		cal_value = Date.parse(document.getElementById('srok').options[2].value);
	}

	var obj_calwindow = window.open(
		'calendar.html?datetime=' + (sel ? sel : ''),
		'Calendar', 'width=200,height=190status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

function wo(i, w, h) {
	w = w?w:500;
	h = h?h:500;
	var wcfg = "width="+w+",height="+h+",toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes";
	var wname = "nw";
	var nw = window.open('wo.php' + i, wname, wcfg);
	nw.focus();
	return false;
}

addFav = function() {
	if (isIE) {
		window.external.addFavorite('http://mladenec-shop.ru', 'Магазин детских товаров Младенец.ру'); 
	}
	return false;
}

window.onload = roundIt;