function addFavorite(url, title)
{
	try
	{
		if(window.ActiveXObject)
			window.external.AddFavorite(url, title);
		else
			window.sidebar.addPanel(title, url , '');
	}
	catch (e)
	{
		return false;
	}
	return false;
}
function setHomePage(url){
	if (window.ActiveXObject)
	{
		document.links[0].style.behavior = 'url(#default#homepage)';
		document.links[0].setHomePage(url);
	}
	else
	{
		window.alert('请使用 工具->选项->主要 添加当前页为您的首页，谢谢！');
	}
	return false;
}
function select_menu()
{
	var url = window.location.pathname.split('/');
	if (url.length > 2)
	{
		url = '/'+ url[1] +'/';
		var _menu = __menus = '';
		var menus = document.getElementById('primary-menu').getElementsByTagName('A');
		for (var i = 0; i < menus.length; i++)
		{
			_menu = menus[i].getAttribute('HREF').replace(/http:\/\/[^\/]+/g, '').replace('.', '');
			if (_menu == url)
			{
				menus[i].parentNode.setAttribute('class', 'active');
				menus[i].parentNode.setAttribute('className', 'active');
				__menus += ', '+ menus[i].parentNode.nodeName;
			}
		}
	}
}
function set_form_data()
{
	var f = document.forms['reg-form'];
	if (f !== undefined)
	{
		f.onsubmit = function()
		{
			var ipts = this.getElementsByTagName('input');
			var has = false;
			for (var i = 0; i < ipts.length; i++)
			{
				if (ipts[i].getAttribute('name') == 'tel')
				{
					has = true;
					break;
				}
			}
			if (!has)
			{
				var tel = document.forms['reg-form'].tel1.value +'-'+ document.forms['reg-form'].tel2.value;
				if (document.forms['reg-form'].tel3.value.length > 0)
				{
					tel += '-'+ document.forms['reg-form'].tel3.value;
				}
				var ipt = document.createElement('input');
				ipt.setAttribute('type', 'hidden');
				ipt.setAttribute('name', 'tel');
				ipt.setAttribute('value', tel);
				document.forms['reg-form'].appendChild(ipt);
			}
			//return false;
		}
	}
}
window.onload = function()
{
	var add2fav = document.getElementById('add2fav');
	var sethp = document.getElementById('sethp');
	add2fav.onclick = function(){addFavorite(this.getAttribute('href'), document.title);return false;}
	sethp.onclick = function(){setHomePage(this.getAttribute('href'));return false;}
	select_menu();
	set_form_data();
}
