try{document.execCommand('BackgroundImageCache',false,true);}catch(e){}
function $(o) {if(document.getElementById&&document.getElementById(o)){return document.getElementById(o);}else if (document.all&&document.all(o)){return document.all(o);}else if (document.layers&&document.layers[o]){return document.layers[o];}else{return false;}} 
function setCls(o,c,f){if(!o)return;var oc=o.className=o.className.replace(new RegExp('( ?|^)'+c+'\\b'),'');if(!f)o.className=oc.length>0?(oc+' '+c):c}
String.prototype.trim= function(){return this.replace(/(^\s*)|(\s*$)/g,"");}
if(!Array.prototype.indexOf)Array.prototype.indexOf=function(item,i){i||(i=0);var l=this.length;if(i<0)i=l+i;for(;i<l;i++)if(this[i]===item)return i;return -1}
function isEmail(s){var p=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;return p.test(s)}
function isUrl(s){var p=new RegExp("((^http)|(^https)):\/\/(\\w)+\.(\\w)+");return p.test(s)}
function onEvent(A,B,C){B=B.replace(/^on/,'').toLowerCase();if(A.attachEvent){A[B+C]=function(){C.call(A,window.event)};A.attachEvent('on'+B,A[B+C])}else A.addEventListener(B,C,false);return A}
function unEvent(A,B,C){B=B.replace(/^on/,'').toLowerCase();if(A.attachEvent){A.detachEvent('on'+B,A[B+C]);A[B+C]=null}else A.removeEventListener(B,C,false);return A}
function show(){this.style.display='block'}
function hide(){this.style.display='none'}
function setVisibile(A,B){if(typeof A=='string')A=$(A);if(A)A.style.display=B?'block':'none'}
function bytes(s){if(typeof(s)!="string"){s=s.value}var l=0;for(var i=0;i<s.length;i++){if(s.charCodeAt(i)>127){l++}l++}return l}
function preloadImage(){var args = preloadImage.arguments;if(!document.preloadImageArray)document.preloadImageArray=[];for(var i=0,len=args.length;i<args;i++){document.preloadImageArray.push(new Image());document.preloadImageArray[document.preloadImageArray.length].src=args[i]}}

//设为首页
function setHomepage(){if(document.all){document.body.style.behavior = 'url(#default#homepage)';document.body.setHomePage('http://'+document.domain)}else if(window.sidebar){if(window.netscape){try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")}catch(e){alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true")}}var prefs=Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);prefs.setCharPref('browser.startup.homepage','http://'+document.domain)}}

//加入收藏
function addFavorite(){if(document.all){window.external.addFavorite(window.location,document.title)}else if(window.sidebar){window.sidebar.addPanel(document.title,window.location,'')}}

//Tab 选择
function inittab(o,n,e){
	var tab = $(o);
	var ul = $(o + '-body');
	if(!tab || !ul)return;
	var tabs = tab.getElementsByTagName('li');
	if(!tabs || tabs.length == 0)return;
	tab = tabs[0].parentNode;
	tab.uls = ul.getElementsByTagName(n ? n : 'ul');
	if(!tab.uls)return;
	var cls='active';
	e = e ? e : 'onmouseover';
	tab.lis = tabs;
	for(var i=0;i<tabs.length;i++){
		tabs[i].i=i;
		tabs[i][e] = function(){
			var u = this.parentNode;
			var idx = u.act ? u.act : 0;
			setCls(u.lis[idx], cls, true);
			if(u.uls[idx])u.uls[idx].style.display = 'none';
			u.act = this.i;
			setCls(this, cls);
			if(u.uls[this.i])u.uls[this.i].style.display = '';
		}
	}
}

//排名选择
function renderRankTabPanel(o,n,e){inittab(o,n,e)}

var isGecko=(navigator.userAgent.indexOf("Gecko")>-1)&&(navigator.userAgent.indexOf("KHTML")==-1);
var isIE=!-[1,];

excmsso = {
	isuse : false,					//是否启用搜索自动完成
	action : '/su?wd=',				//自动完成动作程序
	form : 'searchform',			//搜索表单
	keywords : 'q',					//搜索关键字
	category : 'c',					//搜索分类
	category_value : '',			//默认搜索分类值
	soTypeTab : 'sotypetab',		//搜索类别TAB
	keywordsValue : '请输入搜索关键字', //搜索关键字默认值
	background :'#3366CC',			//自动完成出口背景
	textColor :'#FFFFFF',			//列表文字颜色
	selectTextColor : '#FFFFFF',	//选中列表文字颜色
	width : 0,						//提示窗口宽度,0：自动适应搜索关键字输入框宽度
	
	//初始化
	init:function(){
		this.form = $(this.form);
		//获取搜索表单，不存在时终止初始化
		if(!this.form) return ;
		this.initForm();
		
		this.keywords = this.form[this.keywords];
		//获取搜索关键字输入框，不存在时终止初始化
		if(!this.keywords) return ;
		this.initKeywords();
		
		//获取搜索分类对象
		this.category = this.form[this.category];
		if(this.category &&  this.category_value != ''){this.category.value = this.category_value}
		
		//初始化Tab
		this.setTab();
		
		if(!this.isuse) return ;
		this.sugBox = document.createElement('div');
		var tthis=this;
		with(this.sugBox.style){
			border = '1px solid #000';
			background = '#FFFFFF';
			margin = '1px 0px 0px 0px';
			display = "none";
			position = "absolute";
			fontFamily = 'Arial, Helvetica, sans-serif';
			fontSize = '12px';
			width = (tthis.width > 0 ? tthis.width : (isIE ? tthis.keywords.offsetWidth : tthis.keywords.offsetWidth - 1)) + "px";
		}
		this.keywords.onkeydown=function(e){tthis.kd(e)}
		this.keywords.onkeyup=function(e){tthis.get()}
		this.keywords.setAttribute("autocomplete","off");
		this.keywords.parentNode.appendChild(this.sugBox);
		
		document.onkeydown=function(e){if(isGecko){e=e||window.event;if(e.ctrlKey){if(e.keyCode==61||e.keyCode==107||e.keyCode==109||e.keyCode==96||e.keyCode==48){}}}};
		document.onmousedown=function(e){e=e||window.event;var el=e.target||e.srcElement;if(el==window.excmsso.keywords){return }while(el=el.parentNode){if(el==window.excmsso.sugBox||el==window.excmsso.keywords){return }}setTimeout("window.excmsso.cs()",200)};
		
	},
	setDefaultCategory:function(c){if(c)this.category_value = c;},
	initForm:function(){
		var tthis = this;
		this.form.onsubmit = function(){
			if(tthis.keywords.value.trim() == tthis.keywordsValue){tthis.keywords.value = '';}
		}
	},
	
	initKeywords:function(){
		var tthis = this;
		this.keywords.value = this.keywordsValue;
		this.keywords.onfocus = function(){
			if(this.value.trim() == tthis.keywordsValue){this.value = '';}
			setCls(this, 'keywords_focus');
		}
		
		this.keywords.onblur = function(){
			if(this.value.trim() == ''){
				this.value = tthis.keywordsValue;
				setCls(this, 'keywords_focus', true);
			}
		}
	},
	
	setTab:function(flag){
		var tab = $(this.soTypeTab);
		if(!tab) return ;
		var lis = tab.getElementsByTagName('li');
		tab.onli = lis[0];
		var f = this.form;
		var c = this.category; 
		for(var k=0;k<lis.length;k++){
			lis[k].index = k;
			lis[k].onclick = function(){
				setCls(tab.onli, 'act', true);
				tab.onli = this;
				if(c)c.value = this.attributes['value'].value;
				setCls(this, 'act');
				if(flag && this.keywords.value!=''){f.submit();}
			}
		}
	},
	
	su:function(d){
		if(this.sugBox.isclose)return ;
		if(typeof(d)=="object"&&d.s&&typeof(d.s)!="undefined"&&typeof (d.s[0])!="undefined"&&d.s.length>0){this.d=d;this.sc()}else{this.cs();this.d={}}
	},
	
	get:function(){
		if(this.keywords.value==''||(this.CS&&(this.CS.kw==this.keywords.value||this.CS.ckw==this.keywords.value)))return ;
		if(this.CS){document.body.removeChild(this.CS)}this.CS=this.C('script');
		this.CS.src=this.action + this.keywords.value +"&t="+(new Date()).getTime();
		document.body.appendChild(this.CS);
	},
	
	
	//输入框键按下动作
	kd:function(e){
		e=e||window.event;
		var cli;
		if((e.keyCode==38||e.keyCode==40)&&this.sugBox.style.display!='none'){
			var lis=this.sug.getElementsByTagName('li');
			var l=lis.length;
			var c=-1;
			for(var i=0;i<l;i++){if(lis[i]==lis[i].parentNode.ison){c=i;break}}
			var cli;
			if(e.keyCode==38){if(c==0){this.keywords.value=this.CS.kw;c=-1}else{if(c==-1){c=l}cli=lis[--c]}}
			else{if(c==l-1){this.keywords.value=this.CS.kw;c=-1}else{cli=lis[++c]}}
			for(var i=0;i<l;i++){this.lio(lis[i],false);}
			if(lis[0].parentNode.ison){this.lio(lis[0].parentNode.ison, false)}
			if(c>=0){this.lio(lis[c],true);this.CS.ckw=this.keywords.value=lis[c].innerHTML}
		}
	},
	
	//提示内容包含容器
	sc:function(){
		this.CS.kw=this.keywords.value;
		var ul=this.C('ul');
		with(ul){id='sugul';style.margin='0';style.padding='0';style.listStyle='none';style.cursor="default"}
		var li;
		var tthis=this;

		for(var i=0;i<this.d.s.length;i++){
			li=this.C('li');
			li.innerHTML=this.d.s[i];
			with(li.style){height='20px';lineHeight='20px';paddingLeft='4px';textAlign='left';overflow='hidden'}
			li.onmouseover=function(){tthis.lio(this,true)}
			li.onmouseout=function(){tthis.lio(this,false)}
			li.onclick=function(){tthis.keywords.value=this.innerHTML;tthis.keywords.form.submit();tthis.cs();}
			ul.appendChild(li);
		}
		this.sugBox.innerHTML='';
		this.sugBox.appendChild(ul);
		var csdiv=this.C('div');
		with(csdiv.style){lineHeight='20px';paddingRight='4px';textAlign='right'}
		csdiv.innerHTML='<a href="javascript:window.ican.csu();">关闭</a>';
		this.sugBox.appendChild(csdiv);
		this.sugBox.style.display='';		
	},
	cs:function(){if(this.sugBox)this.sugBox.style.display='none'},
	csu:function(){if(this.sugBox){this.sugBox.isclose=true;this.cs()}},
	C:function(e){return document.createElement(e)},
	lio:function(o,f){if(o.parentNode.ison){with(o.parentNode.ison.style){background=color=''}o.parentNode.ison=false;}o.parentNode.ison=f?o:f;with(o.style){background=f?this.background:'';color=f?this.textColor:''}}
};

// 相关搜索
function initLinkSo(f){
	f = $(f);
	if(!f) return ;
	var d = f.getElementsByTagName('div');
	var c,s;
	for(var i=0;i<d.length;i++){
		if(d[i].className == 'cate_list'){
			c = d[i];
		}else if(d[i].className == 'cate_selected'){
			s = d[i];
		}
	}
	if(!c) return ;
	var a = c.getElementsByTagName('a');
	var k = f['keywords'];
	if(k){
		k.defautValue = '请输入关键字';
		k.value = k.defautValue;
		k.onfocus = function(){if(this.value == this.defautValue)this.value='';setCls(this,'focus')}
		k.onblur = function(){if(this.value=='')this.value=this.defautValue;if(this.value == this.defautValue)setCls(this,'focus',true)}
	}
	if(s && a.length){
		var cat = f['category'];
		s.onclick = function(){c.style.display='block'}
		c.onmouseover = function(){this.style.display='block'}
		c.onmouseout = function(){this.style.display='none'}
		var t = '';
		for(var i=0;i<a.length;i++){
			if(a[i].attributes['selected'] && a[i].attributes['selected'] == '1'){
				t = this.innerHTML;
			}
			if(cat){
				a[i].onclick = function(){
					s.innerHTML = this.innerHTML;
					cat.value = this.attributes['value'].value;
					c.style.display = 'none';
				}
			}
		}
		s.innerHTML = t == '' ? a[0].innerHTML : t;
	}
}

// 检查相关搜索表单
function checkLinkSo(o){
	if(o.keywords.value == '' || o.keywords.value == o.keywords.defautValue){
		o.keywords.focus();
		return false;
	}
	return true;
}

// 列表显示模式
function setContentListView(o, el, flag){
	var a = o.parentNode.getElementsByTagName('a');
	for(var i=0;i<a.length;i++){
		setCls(a[i], 'active', true);
	}
	setCls(o, 'active');
	el = $(el);
	if(el){
		if(typeof(flag) == 'string'){
			el.className = flag;
		}else{
			setCls(el, 'brief', flag!=1);
		}
	}
}

// 复制链接
function copyLink(title){
	copyToClipboard(window.location.href);
}

// 剪切板复制
function copyToClipboard(txt) { 
	if(window.clipboardData) { 
		window.clipboardData.clearData(); 
		window.clipboardData.setData("Text",txt); 
	} else if(navigator.userAgent.indexOf("Opera")!= -1) { 
		window.location = txt; 
	} else if (window.netscape) { 
		try { 
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
		} catch (e) { 
			alert("您的firefox安全限制限制您进行剪贴板操作.\n请打开'about:config'将signed.applets.codebase_principal_support'设置为true'之后重试"); 
			return false; 
		} 
		var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard); 
		if (!clip)  return; 
		var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable); 
		if (!trans)  return; 
		trans.addDataFlavor('text/unicode'); 
		var str = new Object(); 
		var len = new Object(); 
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); 
		var copytext = txt; 
		str.data = copytext; 
		trans.setTransferData("text/unicode",str,copytext.length*2); 
		var clipid = Components.interfaces.nsIClipboard; 
		if (!clip) 
		return false; 
		clip.setData(trans,null,clipid.kGlobalClipboard); 
	}
	alert('链接已经复制, 请粘贴到您的QQ/MSN上发送给您的好友.');
}

// 大幻灯图片播放器
function slidePlayer(id){
	var interv = 3000; // 切换间隔时间
	var intervSpeed = 10; // 切换速度,0不使用渐显
	// 获取幻灯图片播放器选择器
	var container = $(id);
	if(!container){return}
	// 获取幻灯选择器
	var slideSwitch = container.getElementsByTagName('li');
	if(!slideSwitch){return}
	// 获取幻灯容器
	container = container.parentNode;
	// 创建幻灯播放容器
	var slideBody = document.createElement('div');
	slideBody.className = 'fip-body';
	container.appendChild(slideBody);
	// 创建标题容器
	var titleCt = document.createElement('div');
	titleCt.className = 'fip-txt';
	slideBody.appendChild(titleCt);
	// 创建标题背景
	var titleBackground = document.createElement('div');
	titleBackground.className = 'fip-txtbg';
	slideBody.appendChild(titleBackground);
	// 创建幻灯图片容器
	var slidersCt = document.createElement('div');
	slidersCt.className = 'fip-imgs';
	slideBody.appendChild(slidersCt);
	// 创建幻灯片
	var cpic,tpic,a,cls,title,href,thumb,src,desc,sliderHtml = '';
	var timer, timer1, timer2, timer3;
	for(var i=0,slideNum=slideSwitch.length;i<slideNum;i++){
		cls = i > 0 ? 'alpha' : '';
		src = slideSwitch[i].getElementsByTagName('img')[0].getAttribute('lowsrc');
		a = slideSwitch[i].getElementsByTagName('a')[0];
		slideSwitch[i].title = a.innerHTML;
		slideSwitch[i].link = slideSwitch[i].getElementsByTagName('h3')[0].innerHTML;
		desc = slideSwitch[i].getElementsByTagName('p');
		if(desc){slideSwitch[i].link += '<p>' + desc[0].innerHTML + '</p>'}
		sliderHtml += '<div class="'+cls+'"><a href="'+a.href+'" target="_blank"><img src="'+src+'" title="'+slideSwitch[i].title+'" /></a></div>';
		preloadImage(src);
		slideSwitch[i].index = i;
		slideSwitch[i].onclick = function(){
			cpic = cpic ? cpic : 0;
			sliders[cpic].opacity = 0;
			alpha(sliders[cpic]);
			setActive(cpic?cpic:0);
			cpic = tpic = this.index;
			sliders[tpic].opacity = 100;
			alpha(sliders[tpic]);
			titleCt.innerHTML = this.link;
			setActive(tpic,true);
			tpic = tpic == (slideNum - 1) ? 0 : tpic + 1;
			window.clearInterval(timer);
			timer = window.setInterval(loop, interv + 1000);
		}
	}
	slidersCt.innerHTML = sliderHtml;
	var sliders = slidersCt.getElementsByTagName('div');
	
	var setActive = function(n,f){if(f){slideSwitch[n].className='active';titleCt.innerHTML=slideSwitch[n].link}else{slideSwitch[n].className=''}}
	setActive(0, true); 
	if(slideNum < 2){return}
	// 控制图层透明度
	var alpha = function(o){if(isIE){o.style.filter="alpha(opacity="+o.opacity+")";}else{o.style.opacity=(o.opacity/100)}o.style.display=o.opacity>0?'':'none'}
	//渐显
	var fadeon=function(){tpic=tpic>=0?tpic:1;var o=sliders[tpic];if(intervSpeed>0){if(!o.opacity){o.opacity=0}o.opacity+=5;if(o.opacity<10){setActive(tpic,true)}}else{setActive(tpic,true);o.opacity=100}alpha(o);if(o.opacity<100){window.clearTimeout(timer1);timer1=setTimeout(fadeon,intervSpeed)}else{cpic=tpic;tpic=tpic==(slideNum-1)?0:tpic+1;}}
	//渐隐
	var fadeout=function(){cpic=cpic>0?cpic:0;var o=sliders[cpic];if(intervSpeed>0){if(!o.opacity){o.opacity=100}o.opacity-=5;if(o.opacity>90){setActive(cpic);}}else{setActive(cpic);o.opacity=0}alpha(o);if(o.opacity>0){window.clearTimeout(timer2);timer2=setTimeout(fadeout,intervSpeed)}}
	//循环
	var loop = function(){fadeout();window.clearTimeout(timer3);timer3=setTimeout(fadeon,intervSpeed+40)}
	timer = window.setInterval(loop, interv);
}

// 焦点图片播放器
function renderPicPlayer(id){
	var interv=4000; //切换间隔时间
	var intervSpeed=10; //切换速速
	var cpic=0;
	var tpic=1;
	var timer, timer1, timer2;
	
	var list=$(id + '-list');
	if(list){list=list.getElementsByTagName('li')}
	var change = $(id + '-change');
	if(!list || !list.length || list.length < 2 || !change){return}
	
	var lis = cls = '';
	var picnum = list.length;
	for(var i=0;i<picnum;i++){cls=i==0?' class="active"':'';lis+='<li'+cls+'>'+(i+1)+'</li>'}
	change.innerHTML = lis;
	change = change.getElementsByTagName('li');
	var div = list[0].getElementsByTagName('div')[0];
	var img_fit_with = div.offsetWidth, img_fit_height = div.offsetHeight;
	for(var i=0;i<picnum;i++){
		change[i].index = i;
		var img = list[i].getElementsByTagName('img');
		if(img && img[0]){
			//img[0].onload = function(){resizeImage(this, img_fit_with, img_fit_height, true)}
		}
		if(i>0){
			list[i].opacity = 0;
			alpha(list[i]);
		}else{
			list[i].opacity = 100;
		}
		change[i].onmouseover = function(){
			list[cpic].opacity = 0;
			alpha(list[cpic]);
			setActive(cpic);
			cpic = tpic = this.index;
			list[tpic].opacity = 100;
			alpha(list[tpic]);
			setActive(tpic,true);
			tpic = tpic == (picnum - 1) ? 0 : tpic + 1;
			window.clearInterval(timer);
			timer = window.setInterval(loop, interv);
		}
	}
	function setActive(n,f){change[n].className=f?'active':''}
	if(picnum < 2){return}
	//控制图层透明度
	function alpha(o){if(isIE){o.style.filter="alpha(opacity="+o.opacity+")";}else{o.style.opacity=(o.opacity/100)}o.style.display=o.opacity>0?'':'none'}
	//渐显
	var fadeon=function(){setActive(tpic,true);var o=list[tpic];o.opacity+=5;alpha(o);if(o.opacity<100){window.clearTimeout(timer1);timer1=setTimeout(fadeon,intervSpeed)}else{cpic=tpic;tpic=tpic==(picnum-1)?0:tpic+1;}}
	//渐隐
	var fadeout=function(){setActive(cpic);var o=list[cpic];o.opacity-=10;alpha(o);if(o.opacity>0){window.clearTimeout(timer2);timer2=setTimeout(fadeout,intervSpeed)}else{o.opacity=0;}}
	//循环
	var loop = function(){fadeout();setTimeout(fadeon,intervSpeed+50)}
	timer = window.setInterval(loop, interv);
}

var content_action = '/action/content.php';
function digg(id,o,action){
	var diggpage = false;
	if(typeof o == 'string'){
		o = $(o);
		diggpage = true;
	}
	if(o.title == '已顶过'){alert('您已顶过本内容，不能重复顶');return}
	if(Cookies.processCookeiIds('digg',id,20)){alert('您刚才已表决过了，不能重复表决');return}
	ajax.request('get', action ? action : content_action, {success:function(response){
		var v = ajax.jsondecode(response.responseText);
		if(diggpage){
			o.innerHTML = v['digg'];
			return ;
		}else{
			setInnerHtml('content_op_support', v['digg'] ? v['digg'] : 0);
			var digg = $('content_diggpercent');
			var trample = $('content_tramplepercent');
			if(digg){
				v['diggpercent'] = v['diggpercent'] ? v['diggpercent'] : 0;
				digg.style.width=  v['diggpercent']+'%';
			}
			if(trample) {
				v['tramplepercent'] = v['tramplepercent'] ? v['tramplepercent'] : 0;
				trample.style.width=  v['tramplepercent']+'%';
			}
		}
	}},{contentid:id,act:'digg'});
	o.title = '已顶过';
}
function trample(id,o,action){
	if(o.title != '我踩'){alert('您已踩过本内容，不能重复踩');return}
	if(Cookies.processCookeiIds('digg',id,20)){alert('您刚才已表决过了，不能重复表决');return}
	ajax.request('get', action ? action : content_action, {success:function(response){
		var v = ajax.jsondecode(response.responseText);
		setInnerHtml('content_op_oppose', v['trample'] ? v['trample'] : 0);
		
		var digg = $('content_diggpercent');
		var trample = $('content_tramplepercent');
		if(digg){
			v['diggpercent'] = v['diggpercent'] ? v['diggpercent'] : 0;
			digg.style.width=  v['diggpercent']+'%';
		}
		if(trample) {
			v['tramplepercent'] = v['tramplepercent'] ? v['tramplepercent'] : 0;
			trample.style.width=  v['tramplepercent']+'%';
		}
	}},{contentid:id,act:'trample'});
	o.title = '已踩过';
}
function processCookeiIds(){
	
}
function getContentInfo(id, action, model){
	ajax.request('get', action ? action : content_action, {success:function(response){
		var v = ajax.jsondecode(response.responseText);
		setInnerHtml('content_click', v['click'] ? v['click'] : 0);
		setInnerHtml('content_op_support', v['digg'] ? v['digg'] : 0);
		setInnerHtml('content_op_oppose', v['trample'] ? v['trample'] : 0);
		var digg = $('content_diggpercent');
		if(digg){
			v['diggpercent'] = v['diggpercent'] ? v['diggpercent'] : 0
			digg.style.width=  v['diggpercent']+'%';
		}
		var trample = $('content_tramplepercent');
		if(trample) {
			v['tramplepercent'] = v['tramplepercent'] ? v['tramplepercent'] : 0;
			trample.style.width=  v['tramplepercent']+'%';
		}
		v['comment'] =  v['comment'] ? v['comment'] : 0;
		setInnerHtml('comment_count_0',v['comment']);
		setInnerHtml('comment_count_1', v['comment']);
		setInnerHtml('comment_count_2', v['comment']);
		setInnerHtml('comment_count_3', v['comment']);
		setInnerHtml('content_download', v['download'] ? v['download'] : 0);
	}},{contentid:id, model:model});
}
function getContentSupport(ids,action){
	ajax.request('get', action ? action : content_action, {success:function(response){
		var v = ajax.jsondecode(response.responseText);
		setInnerHtml('content_click', v['click'] ? v['click'] : 0);
	}},{contentids:ids});
}

function setInnerHtml(element, value){
	if(typeof element !== 'object'){element = $(element);}
	if(element){element.innerHTML = value;}
}

//按比例缩放图片
function resizeImage(img,fitWidth,fitHeight,self){
	fitWidth = fitWidth || 600;
	
	var tempImg = new Image();
	tempImg.src = img.src;
	var scale=1.0;
	var width=0,height=0;

	if(document.all){
		if(tempImg.readyState=='complete'){
			width = tempImg.width;
			height = tempImg.height;
		}
	}
	else(tempImg.complete)
	{
		width = tempImg.width;
		height = tempImg.height;
	}
	if(fitWidth < width){
		scale = width/height;
		if(width > fitWidth){
			width = fitWidth;
			height = width/scale; 
			if(height > fitHeight)
			{
			  height = fitHeight;
			  width = height*scale;
			}
		}
		if(height > fitHeight){
			height = fitHeight;
			width = height*scale;
		}
		if(width==0 || height==0){width = fitWidth;height = fitHeight;}
		img.width = width;
		img.height = height;
		img.style.width = width + 'px';
		img.style.height = height + 'px';
	}
	if(self){
		var x = parseInt((fitWidth - width) / 2);
		var y = parseInt((fitHeight - height) / 2);
		img.style.marginTop = y + 'px';
		img.style.marginLeft = x + 'px';
	}else{
		img.parentNode.style.width = width + 'px';
	}
}

function setImageView(img, width, desc){
	resizeImage(img, width);
}

// 显示当前日期，时间
function setCurrentDateTime(o){
	var d = new Date();
	var da = d.getDate();
	var mo = d.getMonth() + 1;
	var y = d.getFullYear();
	var h = d.getHours();
	if(h<10){h='0'+h}
	var m = d.getMinutes();
	if(m<10){m='0'+m}
	var s = d.getSeconds();
	if(s<10){s='0'+s}
	var week = ['天','一','二','三','四','五','六'];
	if(typeof(o) != 'object'){o=$(o)}
	o.innerHTML = y+'年'+mo+'月'+da+'日 星期'+week[d.getDay()]+'<br />'+h+':'+m+':'+s;
	window.setTimeout(function(){setCurrentDateTime(o)}, 1000);	
}

// 申请友情链接
function ApplyLink(){
	var ct = $('applylink');
	if(ct.style.display == 'block')return ;
	ct.style.display = 'block';
	var h = ct.offsetHeight;
	ct.style.height = '1px';
	var tm = window.setInterval(function(){var c_h=ct.offsetHeight;if(c_h>=h){ct.style.height=h+'px';window.clearInterval(tm);return;}var t=(h-c_h)/10;if(Math.abs(t)>.1){c_h+=t}ct.style.height=c_h+'px';},10);
}

// 友情链接表单检查
function checkLinkForm(f){
	if(f.sitename.value.trim().trim() == ''){
		alert('请填写您的网站名称')	;
		f.sitename.focus();
		return false;
	}
	var logo = f.logo.value.trim();
	if(logo != '' && !isUrl(logo)){
		alert("您的网站Logo地址不正确，请重新填写\n请输入您网站的Logo网址")	;
		f.logo.focus();
		return false;
	}
	var url = f.url.value.trim();
	if(url == ''){
		alert('请填写您的链接Url')	;
		f.url.focus();
		return false;
	}
	if(!isUrl(url)){
		alert('您的链接Url格式不正确，请重新填写')	;
		f.url.focus();
		return false;
	}
	if(f.name.value.trim() == ''){
		alert('请填写您的链接Url')	;
		f.name.focus();
		return false;
	}
	var email = f.email.value.trim();
	if(email == ''){
		alert('请填写您的Email')	;
		f.email.focus();
		return false;
	}
	if(!isEmail(email)){
		alert('您的Email格式不正确，请重新填写')	;
		f.email.focus();
		return false;
	}
	if(f.category && f.category.value.trim() == ''){
		alert('请选择友情链接分类')	;
		f.category.focus();
		return false;
	}
	try{
		var ct = $('linkmaskct')
		ct.style.display = 'block';
		var c = $('applylink');
		var w = c.offsetWidth;
		var h = c.offsetHeight;
		var t = $('linkmasktxt')
		var t_w = t.offsetWidth;
		var t_h = t.offsetHeight;
		t.style.left = ((w - t_w) / 2) + 'px';
		t.style.top = ((h - t_h) / 2) + 'px';
		ajax.request('post', f.action, {success:function(r){window.setTimeout(function(){ct.style.display='none';var v=ajax.jsondecode(r.responseText);if(v.success==1){f.reset();c.style.display='none';alert(v.message)}else{alert(v.message?v.message:r.responseText)}},100)},failure:function(r){ct.style.display='none';alert(r.status+"错误，请与管理员联系")}},ajax.serializeForm(f));
		return false;
	}catch(e){
		return true;
	}
}

// 友情链接点击
function doLinkClick(id,action){ajax.request('post',action,{},{id:id})}

/**
 * Cookies设置
 */
var Cookies = {
	// set cookies
	set : function(name, value){
		var argv = arguments;
		var argc = arguments.length;
		var expires = null;//
		if(argc > 2){
			var expires = new Date();
			expires.setDate(expires.getDate() + argv[2]);
		}
		var path = (argc > 3) ? argv[3] : '/';
		var domain = (argc > 4) ? argv[4] : null;
		var secure = (argc > 5) ? argv[5] : false;
		document.cookie = name + "=" + escape (value) +
			((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
			((path == null) ? "" : ("; path=" + path)) +
			((domain == null) ? "" : ("; domain=" + domain)) +
			((secure == true) ? "; secure" : "");
	},
	// get cookies
	get : function(name){
		var arg = name + "=";
		var alen = arg.length;
		var clen = document.cookie.length;
		var i = 0;
		var j = 0;
		while(i < clen){
			j = i + alen;
			if (document.cookie.substring(i, j) == arg)
				return Cookies.getCookieVal(j);
			i = document.cookie.indexOf(" ", i) + 1;
			if(i == 0)
				break;
		}
		return null;
	},
	// clear cookies
	clear : function(name) {
		if(this.get(name)){
			var expdate = new Date(); 
			expdate.setTime(expdate.getTime() - (86400 * 1000 * 1)); 
			this.set(name, "", expdate); 
		}
	},
	// get coolid val
	getCookieVal : function(offset){
	   var endstr = document.cookie.indexOf(";", offset);
	   if(endstr == -1){
		   endstr = document.cookie.length;
	   }
	   return unescape(document.cookie.substring(offset, endstr));
	},
	// check cookie exist
	processCookeiIds : function(type, contentid, idscount, unset){
		var savedids = this.get(type);
		if(savedids != null){
			var savedids_array = savedids.split(',');
			var saved = false;
			savedids = '';
			var j = 1;
			for(var i=savedids_array.length-1;i>=0;i--){
				if(savedids_array[i]==contentid && saved) continue;
				else {
					if(savedids_array[i]==contentid && !saved) saved = true;
					savedids += (savedids=='' ? savedids_array[i] : ','+savedids_array[i]);j++;
					if(j==idscount && saved) break;
					if(j==idscount-1 && !saved) break;
				}
			}
			if (saved) {return true;}else if(!unset){savedids += ',' + contentid;this.set(type, savedids, 1);return false;}
		}else if(!unset){
			this.set(type,contentid,1);return false;
		}
	}
};

/* Login */
Login = {
	form : new Array,
	login : false,
	// check user is login
	isLogin : function(url, form, type){
		if(!url) return ;
		var tthis = this;
		url += url.indexOf('?') < 0 ? '?' : '&';
		url += 'logintype=' + type;
		ajax.request('get', url, {success:function(r){
			var v = ajax.jsondecode(r.responseText);
			if(v && v.success == 1) tthis.logined(form, v.message);
		}});
	},
	// render login
	logined : function(form, msg){
		this.login = true;
		if(typeof form != 'object'){
			form = $(form);
		}
		var account = document.createElement('div');
		account.className = 'accountinfo';
		account.innerHTML = msg;
		form.parentNode.form = form;
		form.parentNode.insertBefore(account, form);
		form.account = account;
		setVisibile(form, false);
	},
	
	// logout
	logout : function(o, url){
		if(!url) return ;
		var tthis = this;
		ajax.request('get', url, {success:function(r){
			var v = ajax.jsondecode(r.responseText);
			if(v && v.success == 1){
				tthis.login = false;
				var account = o.parentNode;
				var form = account.parentNode.form;
				account.parentNode.removeChild(account);
				var u = form.username.value;
				form.reset();
				form.username.value = u;
				setVisibile(form, true);
			}
		}});
	},
	// submit login form
	submit : function(A){
		var flag = true;
		if(A.username.value.trim() == ''){
			A.username.focus();
			setVisibile('username_valid',true);
			flag = false;
		}
		if(A.password.value.trim() == ''){
			A.password.focus();
			setVisibile('password_valid',true);
			flag = false;
		}
		if(flag){
			var tthis = this;
			ajax.request('post', A.attributes['action'].value, {success:function(r){
				var v = ajax.jsondecode(r.responseText);
				if(v && v.success == 1){
					tthis.logined(A, v.message);
					if(A.loginforward && A.loginforward.value != '') window.location.href = A.loginforward.value;
				}else if(v.success == 0){
					alert(v.message);
				}else{
					alert('请求服务器异常，请稍候再登录')
				}
			}},ajax.serializeForm(A));
		}
		return false;
	},
	// initial forward combo
	forwardInit : function(A,B,C,D){
		if(A.render) return ;
		A.render = true;
		if(typeof B == 'string') B = $(B);
		if(!B) return ;
		A.L = B;
		B.O = A;
		A.L.eventEls = [A,A.L];
		A.L.check = function(e){
			if(!this.eventObj) return;
			var t = window.event ? window.event.srcElement : e.target;
			var d = 5;
			while(d > 0){
				if(this.eventObj.eventEls.indexOf(t) >= 0){return}
				else if(t.parentNode){t=t.parentNode}
				else break;
				d--;
			}
			this.eventObj.hide();
		}
		A.L.show = function(){document.eventObj=this;onEvent(document,'click',this.check);this.style.display='block';this.isshow=true}
		A.L.hide = function(){document.eventObj=null;onEvent(document,'click',this.check);setCls(this.O,'combo_o',1);this.style.display='none';this.isshow=false;}
		A.onclick = function(){setCls(this,'combo_o');this.L.show()}
		A.onmouseout = function(){if(!this.L.isshow)setCls(this,'combo_o',1)}
		var LI = A.L.getElementsByTagName('li');
		for(var I=0;I<LI.length;I++){
			if(LI[I].className != 'bd'){
				LI[I].onclick = function(){
					$(C).value = this.attributes['value'].value;
					A.innerHTML = this.innerHTML;
					this.parentNode.hide();
				}
			}
			LI[I].onmouseover = function(){
				if(this.className != 'bd') setCls(this,'hover');
			}
			LI[I].onmouseout = function(){
				if(this.className != 'bd') setCls(this,'hover', true);
			}
		}
	}
};

// 分享
function shareContent(app_url, url_param, title_param){
	app_url += app_url.indexOf('?') < 0 ? '?' : '&';
	app_url += url_param + '=' + encodeURIComponent(window.location.href);
	if(title_param){
		var title = $('content_title');
		title = title ? title.innerHTML : document.title;
		app_url += '&' + title_param + '=' + encodeURIComponent(title);
	}
	window.open(app_url);
}

// 收藏
var favoriteeditor;
function addToFavorite(contentid,url){
	if(!favoriteeditor){
		ajax.request('get',url,{
			success:function(r){
				var v=ajax.jsondecode(r.responseText);
				if(v && v.success && v.success == -1){
					Account.login({callback:function(){addToFavorite(contentid,url)}});
				}else{
					favoriteeditor = Account.window({id:'addfavorite', title:'添加新收藏',width:525});
					//favoriteeditor.body.style.overflow = 'auto';
					favoriteeditor.body.style.height = 'auto';
					ajax.setInnerHTML(favoriteeditor.body, r.responseText);
					var f = favoriteeditor.body.getElementsByTagName('form')[0];
					FormPanel.renderInput(f);
					var title = $('content_title');
					f.title.value = title ? title.innerHTML : document.title;
					
					var description = $('content_description');
					if(description){
						f.description.value = description.innerHTML;
					}else{
						var metas = document.getElementsByTagName('meta');
						for(var i=0,len=metas.length;i<len;i++){
							var meta_name = metas[i].getAttribute('name');
							if(meta_name && meta_name.toLowerCase() == 'description'){
								f.description.value = metas[i].getAttribute('content') ? metas[i].getAttribute('content') : '';
								break;
							}
						}
					}
					f.url.value = window.location.href;
					favoriteeditor.show();
				}
			}
		},{action:'editor'});
	}else{
		Account.hiddenAllError($('ajaxFavoriteEditor'));
		favoriteeditor.show();
	}
}
