﻿var Showbo={version:'1.0',author:'showbo',intro:'通用'};
//获取文件名称
Showbo.getFN=function(){var m=/\/([a-z]+\d*)(?=\.(html|aspx))/i.exec(window.location.href.replace(/(?=[\?|#]).*/,''));if(m)return m[1];else return '';}
//空函数
Showbo.emptyFN=function(){}
Showbo.queryString=location.search;//查询参数字符串
Showbo.Request=[];
//分隔成数组
Showbo.InitRequest=function(){var s=Showbo.queryString,m,reg=/([a-z\d]+)=([^&]+)/gi;s=s==''?'':s.substring(1);while(m=reg.exec(s))Showbo.Request[m[1].toLowerCase()]=m[2];}
//键值关联数组
Showbo.InitRequest();
//是否为ie浏览器
Showbo.IsIE=!!document.all;
//ie浏览器版本
Showbo.IEVersion=(function(){if(!Showbo.IsIE)return -1;try{return parseFloat(/msie ([\d\.]+)/i.exec(navigator.userAgent)[1]);}catch(e){return -1;}})();
//页面的高和宽******************************
Showbo.isStrict=document.compatMode == "CSS1Compat";
Showbo.BodyScale={x:0,y:0,tx:0,ty:0};//（x，y）：当前的浏览器容器大小  （tx，ty）：总的页面滚动宽度和高度【包括原始的】
Showbo.getClientHeight=function(){/*if(Showbo.IsIE)*/return Showbo.isStrict ? document.documentElement.clientHeight :document.body.clientHeight;/*else return self.innerHeight;*/}
Showbo.getScrollHeight=function(){var h=!Showbo.isStrict?document.body.scrollHeight:document.documentElement.scrollHeight;return Math.max(h,this.getClientHeight());}
Showbo.getHeight=function(full){return full?this.getScrollHeight():this.getClientHeight();}
Showbo.getClientWidth=function(){/*if(Showbo.IsIE)*/return Showbo.isStrict?document.documentElement.clientWidth:document.body.clientWidth;/*else return self.innerWidth;*/}
Showbo.getScrollWidth=function(){var w=!Showbo.isStrict?document.body.scrollWidth:document.documentElement.scrollWidth;return Math.max(w,this.getClientWidth());}
Showbo.getWidth=function(full){return full?this.getScrollWidth():this.getClientWidth();}
Showbo.initBodyScale=function(IsSource){Showbo.BodyScale.x=Showbo.getWidth(false);Showbo.BodyScale.y=Showbo.getHeight(false);Showbo.BodyScale.tx=Showbo.getWidth(true);Showbo.BodyScale.ty=Showbo.getHeight(true);if(IsSource){Showbo.BodyScale.otx=Showbo.getWidth(true);Showbo.BodyScale.oty=Showbo.getHeight(true);/*获取原始的高和宽*/}}
//页面的高和宽******************************
//随机数
Showbo.rnd=function(min,max){var tmp=min;if(max<min){min=max;max=tmp;}return Math.floor(Math.random()*(max-min+1)+min);}
//w3c浏览器下获取非文字节点
Showbo.DOMNode=function(o,isPre){var ref=isPre?o.previousSibling:o.nextSibling;while(ref&&ref.nodeType!=1)ref=isPre?ref.previousSibling:ref.nextSibling;return ref;}
Showbo.DOMFirstChild=function(o){var n=o.firstChild;while(n&&n.nodeType!=1)n=n.nextSibling;return n;}
Showbo.DOMLastChild=function(o){var n=o.lastChild;while(n&&n.nodeType!=1)n=n.previousSibling;return n;}
//去掉首尾空格
Showbo.Trim=function(v){return v.replace(/^\s*|\s*$/,'');}
//从字符串中还原为json对象
Showbo.GetJson=function(v){ return eval("(" + v + ')');}
//是否为数字
Showbo.IsNumeric=function(v){return /^([+-])?\d+(\.\d+)?$/.test(v);}
//带小数位的舍入
Showbo.round=function(num,radixNum){var t=Math.pow(10,radixNum);return Math.round(num*Math.pow(10,radixNum))/t;}
//求数字数组的平均值
Showbo.Average=function(arr,radixNum){if(arr.length==0)return 0;var total=eval(arr.join('+'));if(!radixNum)radixNum=2;  return Showbo.round(total/arr.length,radixNum);}
//设置cookie
Showbo.SetCookie=function(name,value,icfgTime){var cfgTime={};if("undefined"==typeof(icfgTime))cfgTime.y=1;else cfgTime=icfgTime; var d=new Date();if(Showbo.IsNumeric(cfgTime.y))d.setFullYear(d.getFullYear()+cfgTime.y);if(Showbo.IsNumeric(cfgTime.M))d.setMonth(d.getMonth()+cfgTime.M);if(Showbo.IsNumeric(cfgTime.d))d.setDate(d.getDate()+cfgTime.d);if(Showbo.IsNumeric(cfgTime.h))d.setHours(d.getHours()+cfgTime.h);if(Showbo.IsNumeric(cfgTime.m))d.setMinutes(d.getMinutes()+cfgTime.m);if(Showbo.IsNumeric(cfgTime.s))d.setSeconds(d.getSeconds()+cfgTime.s);document.cookie=name+"="+value+";expires="+d.toGMTString();}
//获取cookie
Showbo.GetCookie=function(name){var m=new RegExp(name+'=([^;]+)','i').exec(document.cookie);if(m)return unescape(m[1]);return "";}
//如果非ie浏览器，扩充原属的contains方法
if(!Showbo.IsIE&&window.Element)Element.prototype.contains=function(o){if(this==o)return true;while(o=o.parentNode)if(o==this)return true;return false;}
//移除html代码
Showbo.removeHTML=function(str){return str.replace(/<[^>]+>/g,'');}
//把html代码替换为其实体
Showbo.encode=function(str){if(typeof(str)=="string")return str.replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/\r/g,'').replace(/\n/g,'<br/>');else return '';}
//从实体还原html代码
Showbo.decode=function(str){return str.replace(/&lt;/g,'<').replace(/&gt;/ig,'>').replace(/<br\/?>/ig,'\n');}
//按id获取对象
Showbo.$=function(Id,isFrame){var o;if("string"==typeof(Id))o= document.getElementById(Id);else if("object"==typeof(Id))o= Id;else return null;return isFrame?(Showbo.IsIE?frames[Id]:o.contentWindow):o;}
//按标签名称获取对象
Showbo.$s=function(){var o,tag;if(arguments.length==1){o=document;tag=arguments[0];}else{o=arguments[0];tag=arguments[1];}return o.getElementsByTagName(tag);}
//获取某个对象的绝对位置
Showbo.getAbsPos=function(o,addXY){o=Showbo.$(o);var p=new Object();p.x=o.offsetLeft;p.y=o.offsetTop;while(o=o.offsetParent){p.x+=o.offsetLeft;p.y+=o.offsetTop;}if(addXY){if(!isNaN(addXY.x))p.x+=addXY.x;if(!isNaN(addXY.y))p.y+=addXY.y;}return p;}
//导入js文件
Showbo.Import=function(js){document.write("<script type='text/javascript' src='"+js+"'></script>");}
//从src内容中获取需要导入的js文件并且导入
Showbo.JsSrcParams=function(paramName){var src=Showbo.$s('script');src=src[src.length-1].src;var m=new RegExp(paramName+'=([^&]+)','i').exec(src);if(m)return m[1];else return "";}
//加载需要的js文件
Showbo.LoadJs=function(){var load=Showbo.JsSrcParams('import');if(load!=''){load=load.split(',');for(var i=0;i<load.length;i++)Showbo.Import('/js/'+load[i]+'.js');}}
Showbo.LoadJs();//执行
//ajax
//扩展IE下的XMLHttpRequest
if(Showbo.IsIE)window.XMLHttpRequest=function(){var acX=['msxml2.xmlhttp.5.0','msxml2.xmlhttp.4.0','msxml2.xmlhttp.3.0','msxml2.xmlhttp','microsoft.xmlhttp'],Xhr;for(var i=0;i<acX.length;i++)try{Xhr=new ActiveXObject(acX[i]);return Xhr;}catch(e){}return false;}
Showbo.Ajax={pools:[], getObject:function(){for(var i=0;i<this.pools.length;i++)if(this.pools[i].readyState==0||this.pools[i].readyState==4)return this.pools[i];this.pools[this.pools.length]=new XMLHttpRequest();return this.pools[this.pools.length-1];},send:function(cfg){if(!cfg.url)throw("url不正确！");var method=cfg.method,asy="boolean"==typeof(cfg.asy)?cfg.asy:true;if(!method)method="get";if(method.toLocaleLowerCase()=='get'){var _dc=new Date().toLocaleString().replace(/[年月日: -]/g,'');cfg.params=cfg.params?cfg.params+'&_dc='+_dc:'_dc='+_dc;if(cfg.url.indexOf("?")!=-1)cfg.url+="&"+cfg.params;else cfg.url+="?"+cfg.params;cfg.params=null;}else if(!cfg.params)cfg.params='';var o=this.getObject();if(!o)throw("未能创建ajax对象！");o.open(method,cfg.url,asy);if(method.toLocaleLowerCase()=='post')o.setRequestHeader("content-type","application/x-www-form-urlencoded");o.send(cfg.params);o.onreadystatechange=function(){if(o.readyState==4){if(o.status==200||o.status==0){ if("function"==typeof(cfg.success))cfg.success(o,cfg.otherParams);}else if("function"==typeof(cfg.failure))cfg.failure(o,cfg.otherParams);}}}}
//自动完成
Showbo.Timer=null;//计时器
Showbo.dvAuto=null;//显示完成结果的div
Showbo.focusObj=null;//获取焦点的div
Showbo.setKW=function(){document.forms[0].kw.value=Showbo.focusObj.innerHTML;Showbo.dvAuto.style.display='none';}
Showbo.docKD=function(e){if(Showbo.dvAuto==null)return false;var kc=e.keyCode;if(kc==38||kc==40||kc==13){if(e.preventDefault)e.preventDefault();else {e.returnValue=false;e.keyCode=0;}}if(Showbo.dvAuto.style.display=='none')return false;if(Showbo.focusObj&&kc==13)Showbo.setKW(Showbo.focusObj);else if(kc==38){if(Showbo.focusObj){Showbo.focusObj.className='unfocus';if(Showbo.focusObj.previousSibling)Showbo.focusObj=Showbo.focusObj.previousSibling;else Showbo.focusObj=Showbo.dvAuto.lastChild;}else Showbo.focusObj=Showbo.dvAuto.firstChild;Showbo.focusObj.className='focus';}else if(kc==40){if(Showbo.focusObj){Showbo.focusObj.className='unfocus';if(Showbo.focusObj.nextSibling)Showbo.focusObj=Showbo.focusObj.nextSibling;else Showbo.focusObj=Showbo.dvAuto.firstChild;}else Showbo.focusObj=Showbo.dvAuto.firstChild; Showbo.focusObj.className='focus';}}
Showbo.setFocus=function(o){if(Showbo.focusObj)Showbo.focusObj.className='unfocus';o.className='focus';Showbo.focusObj=o;}
Showbo.autoHanler=function(o){var dvAuto=Showbo.$('dvAuto');if(200==o.status){Showbo.focusObj=null;var arr=Showbo.GetJson(o.responseText);if(arr.length==0)Showbo.dvAuto.style.display='none';else{Showbo.dvAuto.innerHTML='';for(var i=0;i<arr.length;i++)Showbo.dvAuto.innerHTML+='<div onmouseover="Showbo.setFocus(this)" onclick="Showbo.setKW()">'+arr[i]+'</div>';Showbo.dvAuto.style.display='block';}}else Showbo.dvAuto.style.display='none';}
if(Showbo.IsIE)document.attachEvent("onkeydown",function(){Showbo.docKD(event);});else document.addEventListener('keydown',function(e){Showbo.docKD(e);},false);
Showbo.auto=function(e,o,autopage){function createdvAuto(){Showbo.dvAuto=document.createElement('div');Showbo.dvAuto.id='dvAuto';var p=Showbo.getAbsPos(o,{y:o.offsetHeight+2});Showbo.dvAuto.style.width='140px';Showbo.dvAuto.style.display='none';Showbo.dvAuto.style.left=p.x+'px'; Showbo.dvAuto.style.top=p.y+'px';document.body.appendChild(Showbo.dvAuto);}if(Showbo.dvAuto==null)createdvAuto();e=e||event;if(e.keyCode==13||(e.keyCode>=37&&e.keyCode<=40))return false;if(Showbo.Timer){clearTimeout(Showbo.Timer);Showbo.Timer=null;}Showbo.Timer=setTimeout(function(){if(Showbo.Trim(o.value)!=''&&o.value.length>1)Showbo.Ajax.send({url:'js/auto.ashx',method:'post',params:'p='+autopage+'&auto='+escape(Showbo.Trim(o.value)),success:Showbo.autoHanler,failure:Showbo.autoHanler});else Showbo.dvAuto.style.display='none';},300);}
//导航动态
Showbo.xPos=[0,-50,-100,-150,-200,-250,-300];
Showbo.yPos=[-183,-145,-34,-72,1,-220,-109];
Showbo.timers=[];
Showbo.speed=100;
Showbo.chrbg=function(e){var type=(e||event).type,o=this.span?this.span:this,timer=Showbo.timers[parseInt(o.getAttribute('objIndex'),10)],reg=/over/;timer.dir=reg.test(type)?1:-1;if(!timer.t)timer.t=setInterval(function(){timer.xIndex+=timer.dir;if(timer.xIndex<0||timer.xIndex>6){clearInterval(timer.t);timer.t=null;return;}o.style.backgroundPosition=Showbo.xPos[timer.xIndex]+'px '+timer.yPos+'px';},timer.dir==-1?Showbo.speed:Showbo.speed/3);else if(timer.xIndex<0||timer.xIndex>6){if(timer.dir=1)timer.xIndex=6;else timer.xIndex=0;clearInterval(timer.t);timer.t=null;}}
Showbo.initEvent=function (a,span,Index){span.setAttribute('objIndex',Index);a.span=span;span.style.backgroundPosition='0px '+Showbo.yPos[Index]+'px';Showbo.timers[Index]={xIndex:0,t:null,yPos:Showbo.yPos[Index],dir:1};a.onmouseover=a.onmouseout=span.onmouseover=span.onmouseout=Showbo.chrbg;}
Showbo.InitGuider=function(){var ul=document.getElementById('dvGuider').getElementsByTagName('ul');var t=document.getElementsByTagName('table')[0];var a=ul[1].getElementsByTagName('a'),span=ul[0].getElementsByTagName('a');for(var i=6;i>-1;i--)Showbo.initEvent(a[i],span[i],i);}
/*禁止右键和拷贝裁剪*/
if(/blogdetail/i.test(window.location.href))document.onkeydown=function(e){e=e||event;var o=e.srcElement||e.target;if(e.ctrlKey&&e.keyCode==67&&o.type!="textarea"&&o.type!="text")setCopy(e);}
function setCopy(e){if(Showbo.IsIE)setTimeout(function(){if(window.clipboardData.getData('text').length>300)window.clipboardData.setData('text',window.clipboardData.getData('text')+'<br/><br/><br/>本文来自<a href="http://www.code-design.cn">编程设计网</a>，转载请标明出处：<a href="'+window.location.href+'">'+window.location.href+'</a>');},100);else e.preventDefault();}


