//js
yqread = {
	clear:null,
	sld:null,
	minCommentHeight:121,
	fixHeight:180,
	share:function(type,restype,parentid)
	{
		yqread.hideObj('fromicut');
		this.type = type;
		this.restype = restype;
		this.parentid = parentid;
		var url = g_webServer+"yqread/index.php?tab=share";
		var ajax = new Ajax.Request(
			url,
			{
				method: 'get',
				onSuccess:yqread.show
			}
		);
	},
	show:function(originalRequest)
	{
		if(trim(originalRequest.responseText)=='ok')
		{
			if(yqread.type == 'site')
				setShare_show("type=1&restype="+yqread.restype+"&other1="+encodeURIComponent(yqread.getQueryString('k')));
			else
				yqread.copyUrl();
		}
		else
		{
			yqread.shareError();
		}
	},
	shareError:function()
	{
		this.showObj('showreg');
	},
	copyUrl:function()
	{
		var url = g_webServer+"yqread/index.php?tab=copyurl&k="+encodeURIComponent(yqread.getQueryString('k'));
		var ajax = new Ajax.Request(
			url,
			{
				method: 'get',
				onSuccess:yqread.copyboard
			}
		);
	},
	copyboard:function(originalRequest)
	{
		var text = trim(originalRequest.responseText);
		if (window.clipboardData)
		{
			window.clipboardData.setData("Text",text);
		}
		else
		{
			var flashcopier = 'flashcopier';
			if (!document.getElementById(flashcopier))
			{
				var divholder = document.createElement('div');
				divholder.id = flashcopier;
				document.body.appendChild(divholder);
			}
			document.getElementById(flashcopier).innerHTML = '';
			var divinfo = '<embed src="../clipboard.swf" FlashVars="clipboard='+encodeURIComponent(text)+'"width="0" height="0"  type="application/x-shockwave-flash"></embed>';
			document.getElementById(flashcopier).innerHTML = divinfo;
		}
		
		var divOk = $('showreg').cloneNode(true);
		var oParent = $('showreg').parentNode;
		divOk.id = "copyboard";
		divOk.innerHTML = '复制链接成功';
		divOk.style.display = '';
		oParent.insertBefore(divOk,$('showreg'));
		window.setTimeout("yqread.removeNode('showreg','copyboard')",2000);
	},
	removeNode:function(pid, cid)
	{
		var oParent = $(pid).parentNode;
		var oSelf = $(cid);
		if(oParent && oSelf)
		{
			oParent.removeChild(oSelf);
		}
	},
	getSelfPop:function()
	{
		var obj=$("selfyqreadpop");
		obj.innerHTML='<div class="textc">正在加载中......</div>';
		var url = g_webServer+"yqread/index.php?tab=share";
		var ajax = new Ajax.Request(
			url,
			{
				method: 'get',
				onComplete:yqread.getYqreadPop
			}
		);
	},
	showYqreadPop:function(originalRequest)
	{
		var obj=$("selfyqreadpop");
		obj.innerHTML=originalRequest.responseText;
	},
	getYqreadPop:function(originalRequest)
	{
		if(trim(originalRequest.responseText)=='ok')
		{
			var url = g_webServer+"plaza/index.php?tab=yqreadeventpop";	
			var ajax = new Ajax.Request(
				url,
				{
					method: 'get',
					onComplete:yqread.showYqreadPop
				}
			);
		}
		else
		{
			window.location = g_webServer+"login.php?next="+g_webServer+"plaza/index.php?tab=yqreadevent";
		}
	},
	maxframe:function()
	{
		this.showObj('framemax');
		this.hideObj('framemin');
		this.showObj('sideframe');
		var nframeTop = $('yqreadframe').offsetTop;
		$('yqreadcomment').style.top = nframeTop+"px";
	},
	minframe:function()
	{
		this.showObj('framemin');
		this.hideObj('framemax');
		this.hideObj('yqreadcomment');
		this.hideObj('rightframe');
		this.hideObj('sideframe');
		
	},
	minform:function()
	{
		this.showObj('commentminform');
		this.hideObj('commentmaxform');
		var nHeight = $('commentall').clientHeight + this.pamaHeight();
		$('commentall').style.height = nHeight + "px";
		$('idslider').style.height = (nHeight-30) + "px";
		yqread.changeSliderHeight();
		yqread.setSliderPercent();
	},
	maxform:function()
	{
		this.showObj('commentmaxform');
		this.hideObj('commentminform');
		var nHeight = ($('commentall').clientHeight - this.pamaHeight())<yqread.minCommentHeight?yqread.minCommentHeight:$('commentall').clientHeight - this.pamaHeight();
		$('commentall').style.height = nHeight + "px";
		$('idslider').style.height = (nHeight-30) + "px";
		yqread.changeSliderHeight();
		yqread.setSliderPercent();
	},
	showUser:function(show)
	{
		if(show)
			this.showObj('yqreadcolusers');
		else
			this.hideObj('yqreadcolusers');
	},
	showComment:function()
	{
		this.showObj('yqreadcomment');
	},
	closeView:function()
	{
		this.hideObj('yqreadcomment');
		this.hideObj('rightframe');
	},
	closeReg:function()
	{
		this.hideObj('showreg');
	},
	showFromIcut:function()
	{
		this.showObj('fromicut');
		window.setTimeout("yqread.hideObj('fromicut')",10000);
	},
	setpos:function(height, pos, time, total)
	{
		yqread.stopScroll();
		this.clear = setTimeout("yqread.setScroll("+height+", "+pos+", "+time+","+ total+")",time);
	},
	//停止滑移
	stopScroll: function()
	{
		clearTimeout(this.clear);
	},
	setScroll:function(height, pos, time, total)
	{
		var o = $("commentall");
		o.scrollTop += pos;
		if(o.scrollTop >= (total - 5) * height)
		{
			o.scrollTop = (total - 5) * height;
			clearTimeout(this.clear);
		}
		else
		{
			if(o.scrollTop % height == 0 && (parseInt(o.style.height)<=o.scrollTop))
			{
				clearTimeout(this.clear);
			}
			else
			{
				this.clear = setTimeout("yqread.setScroll("+height+", "+pos+", "+time+","+ total+")", time);	
			}
		}
	},
	setSel:function(obj)
	{
		if(obj)
			obj.className = "clearfix selcomment";
	},
	cancelSel:function(obj)
	{
		if(obj)
			obj.className = "clearfix";
	},
	commentClick:function(event)
	{
		var ret = true;
		var target = yqread.getTarget(event)
		if(target)
		{
			if(yqread.is_node(target,'a')||(target.parentNode&&yqread.is_node(target.parentNode,'a')))
			{
				ret = false;
			}
		}
		return ret;
	},
	hideObj: function(element)
	{
		var obj = $(element);
		if(obj)
			obj.style.display = 'none';
	},
	showObj: function(element)
	{
		var obj = $(element);
		if(obj)
			obj.style.display = '';
	},
	pamaHeight:function()
	{
		return (this.isFF())?139:141;
	},
	isFF:function()
	{
		return navigator.userAgent.indexOf("Firefox") != -1;
	},
	getTarget:function(e)
	{
	    var target = window.event ? window.event.srcElement : e ? e.target : null;
	    if (!target){return false;}
	    while(target.nodeType!=1 && target.nodeName.toLowerCase()!='body'){
	        target=target.parentNode;
	    }
	    return target;
	},
	is_node:function(o,of_type)
	{
		var Node = null;
		try{if(!o||!((Node!=undefined&&o instanceof Node)||o.nodeName))
		{return false;}}
		catch(ignored){return false;}
		if(typeof(of_type)!=="undefined")
		{if(!(of_type instanceof Array)){of_type=[of_type];}
		var name;
		try{name=new String(o.nodeName).toUpperCase();}
		catch(ignored){return false;}
		for(var ii=0;ii<of_type.length;ii++)
		{try{if(name==of_type[ii].toUpperCase()){return true;}}catch(ignored){}}
		return false;
		}
		return true;
	},
	init:function(icut)
	{
		if(icut == 'icut')
			this.showFromIcut();
		var oDiv1 = $('yqreadframe');
		var oDiv2 = $('yqreadcomment');
		var oFrame1 = $('sideframe');
		var oFrame2 = $('rightframe');
		oDiv2.style.top = oDiv1.offsetTop + "px";
		oFrame1.style.width   = (oDiv1.offsetWidth-16) + "px";
		oFrame1.style.height  = (oDiv1.offsetHeight-8) + "px";
		oFrame1.style.top     = (oDiv1.offsetTop+8) + "px";
		oFrame1.style.right   = (parseInt(oDiv1.style.right)+8) + "px";
		oFrame1.style.zIndex  = oDiv1.style.zIndex - 1;
		oFrame1.style.display = "block";
		oFrame1.style.position = "absolute";
		
	},
	getPageSize:function()
	{
		if(self.innerHeight) {	// all except Explorer
				windowHeight = self.innerHeight;
			} else if(document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowHeight = document.documentElement.clientHeight;
			} else if(document.body) { // other Explorers
				windowHeight = document.body.clientHeight;
		}
		return windowHeight;
	},
	setCurClient:function()
	{
		var oMain = document.getElementById("mainframe");
		oMain.style.height = document.body.clientHeight + "px";
		var nPageHeight = yqread.getPageSize();
		var fixHeight = yqread.fixHeight;
		if($('commentmaxform').style.display != "none")
		{
			fixHeight = yqread.fixHeight + yqread.pamaHeight();
		}
		var nHeight = ( nPageHeight - fixHeight) < yqread.minCommentHeight ? yqread.minCommentHeight : nPageHeight - fixHeight;
		nHeight  = (nHeight - 30) < 1 ? 30 : nHeight;
		var nSliderHeight = (nPageHeight - fixHeight) < yqread.minCommentHeight ? (parseInt((nPageHeight - fixHeight)*70/fixHeight)<=0) ? 5 : parseInt((nPageHeight - fixHeight)*70/fixHeight) :70;
		$('idsliderbar').style.height = nSliderHeight  + "px";
		$('commentall').style.height = nHeight + "px";
		if($('idslider'))
		{
			$('idslider').style.height = (nHeight-30) + "px";
			if(yqread.sld != null)
			{
				yqread.changeSliderHeight();
				yqread.setSliderPercent();
			}
		}
	},
	initSlider:function()
	{
		yqread.sld = new Slider("idslider", "idsliderbar", {
			MaxValue: $("commentall").scrollHeight - $("commentall").clientHeight,
			onMin: function(){},
			onMax: function(){},
			onMid: function(){},
			onMove: function(){$("commentall").scrollTop = this.GetValue();}
		});
		
		yqread.sld.SetPercent(.0);
		yqread.sld.Ease = true;
		
		$("idslidertop").onmouseover = function(){yqread.sld.Run(false); }
		$("idslidertop").onmouseout = function(){ yqread.sld.Stop(); }
		
		$("idsliderbottom").onmouseover = function(){ yqread.sld.Run(true); }
		$("idsliderbottom").onmouseout = function(){ yqread.sld.Stop(); }
	},
	changeSliderHeight:function()
	{
		yqread.sld.MaxValue = $("commentall").scrollHeight - $("commentall").clientHeight;
	},
	setSliderPercent:function()
	{
		var nPercent = yqread.sld.GetPercent();
		yqread.sld.SetPercent(nPercent);
	},
	/*
    从当前URL中取出指定参数
    */
    getQueryString:function(name)
    {
        // 如果链接没有参数，或者链接中不存在我们要获取的参数，直接返回空
        if(location.href.indexOf("?")==-1 || location.href.indexOf(name+'=')==-1){
            return '';
        }
        // 获取链接中参数部分
        var queryString = location.href.substring(location.href.indexOf("?")+1);
        // 分离参数对 ?key=value&key2=value2
        var parameters = queryString.split("&");
        var pos, paraName, paraValue;
        for(var i=0; i<parameters.length; i++){
            // 获取等号位置
            pos = parameters[i].indexOf('=');
            if(pos == -1) { continue; }
            // 获取name 和 value
            paraName = parameters[i].substring(0, pos);
            paraValue = parameters[i].substring(pos + 1);
            // 如果查询的name等于当前name，就返回当前值，同时，将链接中的+号还原成空格
            if(paraName == name){
                return unescape(paraValue.replace(/\+/g, " "));
            }
        }
        return '';
    }
};

