/*
	author:panda
	time:11-01-10
*/
/*快速插入评论*/
		var c_Arr=['<a href="javascript:void(0)" title="你就是那不落的太阳，照亮了大地，拯救了苍生，世界因你而美丽！">你就是那不落的太阳，照亮了大地，拯救了苍生，世界因你而美丽！</a>',
		'<a href="javascript:void(0)" title="鄙视标题党">鄙视标题党</a>',
		'<a href="javascript:void(0)" title="我的心久久不能平静，好文啊">我的心久久不能平静，好文啊</a>',
		'<a href="javascript:void(0)" title="这就是传说中的沙发么">这就是传说中的沙发么</a>',
		'<a href="javascript:void(0)" title="在逐行逐句地看完此文后，我的心久久不能压抑的喜悦，震动了整个生命！怎会有如此精妙绝伦的好文？">在逐行逐句地看完此文后，我的心久久不能压抑的喜悦，震动了整个生命！怎会有如此精妙绝伦的好文？</a>',
		'<a href="javascript:void(0)" title="此文带给我的震撼，犹如闪电瞬间通过全身，雷得外焦里嫩">此文带给我的震撼，犹如闪电瞬间通过全身，雷得外焦里嫩</a>',
		'<a href="javascript:void(0)" title="跪求下载地址~~~">跪求下载地址~~~</a>',
		'<a href="javascript:void(0)" title="自插双目，扶墙而出">自插双目，扶墙而出</a>',
		'<a href="javascript:void(0)" title="哈哈，太搞笑了">哈哈，太搞笑了</a>',
		'<a href="javascript:void(0)" title="本人过去、现在以及将来都不认识作者">本人过去、现在以及将来都不认识作者</a>',
		'<a href="javascript:void(0)" title="小编功力不够就不要出来了">小编功力不够就不要出来了</a>',
		'<a href="javascript:void(0)" title="我是来打酱油的">我是来打酱油的</a>',
		'<a href="javascript:void(0)" title="通读全文，泪流满面，感谢作者说出了我想说而不知道怎么说的心声！">通读全文，泪流满面，感谢作者说出了我想说而不知道怎么说的心声！</a>',
		'<a href="javascript:void(0)" title="看到此文，智商上的优越感油然而生">看到此文，智商上的优越感油然而生</a>'
		];
		/*表情集合*/
		var face_Arr=[['1.哈哈大笑','2.开心','3.鼓掌','4.无语','5.大心','6.汗','7.打哈欠','8.疑问','9.hoho','10.惊讶','11.加油','12.激动','13.不同意','14.害羞','15.不是介个样子滴','16.同意','17.晕','18.寒','19.气愤','20.撒娇','21.装酷','22.仰慕','23.头晕','24.大哭','25.大笑','26.偷笑','27.嗯嗯','28.幻想']]

		/*随机产生一个值*/
		var pl_random=c_Arr[Math.floor(Math.random()*c_Arr.length)];
		var pl_title=/<a[^\/].*>(.*)<\/a>/gi.exec(pl_random)[1];

		/*类*/
     	function ue_pl(){
			if(! (this instanceof ue_pl) ){
				return new ue_pl()	
			}
			this._max=200;//字节数
		}
		//window["ue_pl"]=window["ue_pl"] || {};
		//ue_pl._max=200;
		ue_pl.prototype={
			getId:function(id){
				return (typeof id=="string")?document.getElementById(id):id;	
			},
			showHide:function(id,idcon){//快速评论与表情相关
				var that=this;
				that.getId(id).onmouseover=function(){
					that.getId(idcon).style.display="block";	
				};
				that.getId(id).onmouseout=function(){
					that.getId(idcon).style.display="none";		
				};
			},
			numLimt:function(txtId,numTxt,btnSubmit,maxLen,overclass){//maxLen为字节数,汉字为两个字节,英文为一个字节
				var that=this;
				setInterval(function(){			 
					var _value=that.getId(txtId).value.replace(/[^\x00-\xff]/g, "**");//中文两个字符，英文一个
					var _len=_value.length;
					if(_len>=1){
						if(_len>maxLen){
							that.getId(numTxt).innerHTML="您已经超出"+parseInt((_len-maxLen)/2)+"字";
							that.getId(numTxt).className=overclass;//超出提示的样式
							that.getId(btnSubmit).disabled="disable";
						}else{
							that.getId(numTxt).innerHTML="您还可以输入<em class='cff6600'>"+parseInt((maxLen-_len)/2)+"<\/em>个字";
							that.getId(btnSubmit).style.disabled="";
						}	
					}else{
							that.getId(numTxt).innerHTML="您还可以输入<em class='cff6600'>"+that._max+"<\/em>个字";
							that.getId(numTxt).className="";//超出提示的样式
							that.getId(btnSubmit).disabled="disable";	
					}				 
				},100);
			},
			plFun:function(txtId,piconId){
				var that=this;
				var _flagment=document.createDocumentFragment();
				var _html;
				for(var i=0;i<c_Arr.length;i++){
					var _dv=document.createElement("p");
					_dv.innerHTML=c_Arr[i];
					_flagment.appendChild(_dv);
				}
				that.getId(piconId).appendChild(_flagment)
				that.getId(txtId).value=pl_title;//随机赋值
				var _pl=that.getId(piconId).getElementsByTagName("a");//快速评论点击事件
				var _plsize=_pl.length;
				for(var j=0;j<_plsize;j++){
					_pl[j].onclick=function(i){
						return function(){
							(that.getId(txtId).value==pl_title)?that.getId(txtId).value=this.innerHTML:that.getId(txtId).value+=this.innerHTML;
							that.numLimt(txtId,"numTxt","btn_submit",that._max,"overclass");
							that.getId(piconId).parentNode.style.display="none";
							return false;
						}	
					}(j);
				};
			},
			getSmilies:function(source,step,width){//表情填充
				var that=this;
				var _bqHtml="";
				end = source.length;
				tdLeft = end%step;
				for (i=1; i<=end; i++){
					var tmpArr = new Array();
					tmpArr = source[i-1].split(".");
					if(i==1) {_bqHtml+="<table width=\"100%\" border=\"0\" 	<tr>";	}
					_bqHtml += "<td><img src=\"http://image.81813.com/n/images/smile/"+tmpArr[0]+".gif\" title=\""+tmpArr[1]+"\" width=\""+width+"\" height=\""+width+"\" face=\"[f="+tmpArr[0]+"]\" /></td>";
					if(i%step == 0 && i!=end){
						_bqHtml+="</tr><tr>";
					}		
				}
				if(tdLeft>0){sstr+="<td colspan="+tdLeft+"></td></tr></table>";}
				else{_bqHtml+="</tr></table>";}	
				return _bqHtml;
			},
			bqFun:function(txtId,bqId){
				var that=this;
				that.getId(bqId).innerHTML=that.getSmilies(face_Arr[0],7,23);
				that.numLimt(txtId,"numTxt","btn_submit",that._max,"overclass");
				var _img=that.getId(bqId).getElementsByTagName("img");
				var _imgLen=_img.length;
				for(var i=0;i<_imgLen;i++){
					_img[i].onclick=function(j){
						return function(){
							(that.getId(txtId).value==pl_title)?that.getId(txtId).value=_img[j].getAttribute("face"):that.getId(txtId).value+=_img[j].getAttribute("face");
							that.getId(bqId).style.display="none";
							that.numLimt(txtId,"numTxt","btn_submit",that._max,"overclass");
						};
					}(i);
				};
			},
			txtEvent:function(txtId){//文本域keyup事件
				var that=this;
				that.getId(txtId).onkeyup=that.getId(txtId).onblur=function(){
					that.numLimt(txtId,"numTxt","btn_submit",that._max,"overclass");
				};	
			},
			enterFun:function(txtId,fname){//按住ctrl+enter提交表
				var that=this;
				that.getId(txtId).onkeydown=function(e){
					var ev=(e)?e:window.event;
					if(ev.ctrlKey&&ev.keyCode==13){
						//document.forms[fname].submit();
						//document.getElementById(fId).submit();
						alert("提交表单")
					};
				}
			},
			init:function(){
				var that=this;
				that.showHide("kspl_ico","kspl_con");//快速评论
				that.showHide("face_ico","face_con");//表情
				that.plFun("comment_content","y_ck");
				that.bqFun("comment_content","face_con")
				that.txtEvent("comment_content");
				that.enterFun("comment_content","frmComment")//按住ctrl+enter提交表单
			}
		}
		
		/*addEventHandler*/
		function addEventHandler(oTarget,sEventType,fnHandle){
			if(oTarget.addEventListener){
				oTarget.addEventListener(sEventType,fnHandle,false)	
			}else if(oTarget.attachEvent){
				oTarget.attachEvent("on"+sEventType,fnHandle)
			}else{
				oTarget["on"+sEventType]=fnHandle;	
			}	
		}
