// установка домашней страницы
function setHP(obj, url)
{
	if (document.all)
	{
		obj.style.behavior='url(#default#homepage)';
		obj.setHomePage(url);
	return false;
	}
	else if(!document.layers)
	{
		netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
		navigator.preference("browser.startup.homepage", url);
		return false;
	}
	return true;
}

// меню инициализация
function expandMenuInit()
{
	var cont = document.getElementById('expandMenuCont');
	coll = cont.getElementsByTagName('DIV');
	collLength = coll.length;
	for (var i = 0; i < collLength; i++)
	{
		if (coll[i].className == 'expandMenu')
		{
			collInner = coll[i].getElementsByTagName('DIV');
			collInnerLength = collInner.length;
			for (var j = 0; j < collInnerLength; j++)
			{
				if (collInner[j].className != 'titleOpen') collInner[j].style.display = 'none';
				else collInner[j].className = 'titleClose';
			}
		}
	}
}

// меню активация
function expandMenu(what)
{
	coll = what.parentNode.getElementsByTagName('DIV');
	collLength = coll.length;
	for(var i = 1; i < collLength; i++)
	{
		coll[i].style.display = (what.className == 'titleClose') ? 'block' : 'none';
	}
	what.className = (what.className == 'titleClose') ? 'titleOpen' : 'titleClose';
}

function expandMenu2(what, cont)
{
	sign = document.getElementById(what);
	coll = document.getElementById(cont);
	coll.style.display = (sign.className == 'titleClose') ? 'block' : 'none';
	sign.className = (sign.className == 'titleClose') ? 'titleOpen' : 'titleClose';
}

function isEMailAddr(elem) {
	var str = elem.value;
    var re = /^\w+$/;
    if (!str.match(re)) {
        alert("Проверьте формат адреса");
		elem.focus();
		elem.select();
        return false;
    }
    return true;
} 

// recheck tabs 2
function overlapTabs(tabP, bigNewsC)
{
	var _this = this;
	var tabItemColl = document.getElementById(tabP).getElementsByTagName('DIV');
	var bigNewsContainer = document.getElementById(bigNewsC);
	var tabItemCollLength = tabItemColl.length;
	var activeTab = null;
	_this.bigNewsBlock = {};
	
	// initialize
	this.initialize = function(start)
	{
		var cookieStuff = unescape(readCookie('tabsId'));
		if (cookieStuff != 'null')
		{
			start = cookieStuff;
		}
		for (var i = 0; i < tabItemCollLength; i++)
		{
			tabItemColl[i].onclick = _this.activate;
			if (i != start)
			{
				document.getElementById(tabItemColl[i].id + '_').style.display = 'none';
			}
		}
		activeTab = tabItemColl[start];
		activeTab.className = 'tabItem active';
		activeTab.onclick = null;
		_this.display(tabItemColl[start].id);
	}
	
	// check active tab
	this.activate = function()
	{
		if (activeTab)
		{
			activeTab.className = 'tabItem';
			activeTab.onclick = _this.activate;
			document.getElementById(activeTab.id + '_').style.display = 'none';
		}
		activeTab = this;
		this.className = 'tabItem active';
		activeTab.onclick = null;
		_this.display(this.id);
	}
	
	// show active content
	this.display = function(what) {
		document.getElementById(what + '_').style.display = 'block';
		// show big news block
		bigNewsContainer.innerHTML = _this.bigNewsBlock[what];
		var stuffForCookie = what.slice(7);
		createCookie('tabsId', stuffForCookie, 365);
	}
	//_this.initialize();
}


function createCookie(name,value,days) {
	if (days) {
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

