/*
	Powered by 766.com Copyright (c) All rights reserved.
	@By GhostWei
	@Email: ghostwei#gmail.com
	@11:55 2009-8-10
*/
if(typeof(WebGame)=='undefined')var WebGame = {};
WebGame.HostName = window.location.hostname;
WebGame.$ = function(o){return document.getElementById(o);};
WebGame.addFavorite = function(){
	var Title = document.title;
	var url = window.location.href;
	try{
		window.external.addFavorite(url, Title);
		return false;
	}catch(e){
		try{
			window.sidebar.addPanel(Title, url, "");
			return false;
		}catch (e){
			alert("加入收藏失败，请使用Ctrl+D进行添加");
			return false;
		}
	}
};
WebGame.setHomepage = function(obj){
	var url = 'http://'+this.HostName+'/';
	try{
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(url);
		return false;
	}catch(e){
		if(window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}catch(e){
				alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
				return false;
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage', url);
			return false;
		}
		return false;
	}
};
WebGame.copyUrl = function(u){
	var url = u==null ? 'http://'+this.HostName+'/' : u;
	try{
		window.clipboardData.setData("text", url);
		alert('复制成功，按CTRL+V发送给好友、论坛或博客。');
	}catch(e){
		alert("此操作被浏览器拒绝！\n请从浏览器地址栏拷贝。");
	}
	return false;
};
WebGame.ZhiShu = function(v, img){
	img = img == null ? false : img;
	if(!/^[1-5]+$/i.test(v))v=0;
	var d = 5 - v;
	var s = '';
	for(var i=1;i<=v;i++){
		if(img)
		s += '<img src="/skin/2009/images/star.gif" />';
		else
		s+='<font color="#ff9900">★</font>';
	}
	for(var i=1;i<=d;i++){
		if(img)
		s += '<img src="/skin/2009/images/star1.gif" />';
		else
		s+='☆';
	}
	return s;
};
WebGame.search_type_onchange = function(o){
	var f = o.form;
	switch(o.value){
		case 'games':{
			if(f.Keywords.value=='请输入新闻关键字' || f.Keywords.value==''){
				f.Keywords.value = '请输入游戏关键字';
				this.style.color='#999';
			}
			f.Keywords.onfocus = function(){
				if(this.value=='请输入游戏关键字'){
					this.style.color='#000';
					this.value='';
				}
			};
			f.Keywords.onblur = function(){
				if(this.value==''){
					this.style.color='#999';
					this.value='请输入游戏关键字';
				}
			};
			break;
		}

		default: {
			if(f.Keywords.value=='请输入游戏关键字' || f.Keywords.value==''){
				f.Keywords.value = '请输入新闻关键字';
				this.style.color='#999';
			}
			f.Keywords.onfocus = function(){
				if(this.value=='请输入新闻关键字'){
					this.style.color='#000';
					this.value='';
				}
			};
			f.Keywords.onblur = function(){
				if(this.value==''){
					this.style.color='#999';
					this.value='请输入新闻关键字';
				}
			};
			break;
		}
	}
};
WebGame.search = function(f){
	var xtype = 'games';
	if(f.type)xtype = f.type.value;
	switch(f.type.value){
		case 'games':{
			if(f.Keywords.value=='请输入游戏关键字' || f.Keywords.value==''){
				alert('请输入游戏关键字！');
				f.Keywords.focus();
				return false;
			}
			f.action = '/publish/index.php?action=search&form[Name]=' + f.Keywords.value;
			window.location.href = f.action;
			break;
		}
		default: {
			if(f.Keywords.value=='请输入新闻关键字' || f.Keywords.value==''){
				alert('请输入新闻关键字！');
				f.Keywords.focus();
				return false;
			}
			window.open('http://www.766.com/publish/search.php?o=search&Keywords=' + f.Keywords.value + '&TableID=1&Field=Title&site=web.766.com');
			break;
		}
	}
	return false;
};
WebGame.Tab = function(id, evt){
	if(!this.$(id))return;
	evt = evt==null ? 'click' : evt;
	var self = this;
	var li = this.$(id).getElementsByTagName('li');
	if(li.length==0)return;
	for(var i=0;i<li.length;i++){
		li[i].className = '';
		eval("li[i].on"+evt+" = function(){return itab(this);};");
	}		
	itab(li[0]);		
		
	function itab(o){
		var vTab = '';
		for(var i=0;i<li.length;i++){
			li[i].className = '';
			vTab = li[i].getAttribute('tab');
			if(typeof(vTab)=='string'){
				if(self.$(vTab))
				self.$(vTab).style.display = 'none';
			}
		}
		o.className = 'current';
		vTab = o.getAttribute('tab');
		if(typeof(vTab)=='string'){
			if(self.$(vTab))
			self.$(vTab).style.display = 'block';
		}
		return false;
	}
};

