//=================================	
//基础获取类
//=================================
function $(_s){return document.getElementById(_s);}
$.tag      = function(_s,_obj){var obj=(typeof _obj == 'object')?_obj:document;return obj.getElementsByTagName(_s);};
$.name     = function(_s,_obj){var obj=(typeof _obj == 'object')?_obj:document;return obj.getElementsByName(_s);};
$.String   = function(a,b){a=a+'';b=b||'';a=(!a||a=="null"||a=="undefined")?b:a;return a;}
$.Number   = function(a,b){b=b||0;try{var n=new Number(a);return (isNaN(n)?b:n);}catch(e){return b;}}
$.Date     = function(a,_s){var d=new Date(a);d=isNaN(d)?new Date():d;var s=_s||'yyyy-MM-dd hh:mm';var o={};o["M+"]=d.getMonth()+1;o["d+"]=d.getDate();o["h+"]=d.getHours();o["m+"]=d.getMinutes();o["q+"]=Math.floor((d.getMonth()+3)/3);o["s+"]=d.getSeconds();o["S"]=d.getMilliseconds();if(/(y+)/.test(s)){s=s.replace(RegExp.$1,(d.getFullYear()+"").substr(4 - RegExp.$1.length));}for(var k in o){if(new RegExp("("+ k +")").test(s)){s = s.replace(RegExp.$1,RegExp.$1.length==1?o[k]:("00"+ o[k]).substr((""+o[k]).length));}}return s;}
$.Between  = function(n,a,b){var n=new Number(n);n=isNaN(n)?0:n;n=(a&&n<a)?a:n;n=(b&&n>b)?b:n;return n;}
$.Zip      = function(mc){var str='';for(var i in mc){str+=(typeof(mc[i])=="string"||typeof(mc[i])=="number")?('&'+i+'='+escape(mc[i])):'';}return str.substr(1);}
$.UnZip    = function(str){var mc={};var arr=(str+'').split("&");for(var i=0;i<arr.length;i++){var s=arr[i].split("=");s[0]?mc[s[0]]=unescape(s[1]):null;};return mc;}
$.Path     = function(){return document.location.href.replace(/[^\/\s]+?$/,"")}
$.Request  = function(id){var M=this.Request_Temp;M=M?M:this.Request_Temp=$.UnZip(document.location.search.substr(1));return id?M:M[id];}
$.selection= function(h){return h?document.selection.createRangeCollection()[0].htmlText:document.selection.createRangeCollection()[0].text;}


//=====================================
//Ubb转换
//=====================================
$.Ubb=function(str)
{
	str=$.String(str);
	str = str.replace(/<br[^>]*>/ig,'\n');
	str = str.replace(/<p[^>\/]*\/>/ig,'\n');
	str = str.replace(/\son[\w]{3,16}\s?=\s*([\'\"]).+?\1/ig,'');

	str = str.replace(/<hr[^>]*>/ig,'[hr]');
	str = str.replace(/<(sub|sup|u|strike|b|i|pre)>/ig,'[$1]');
	str = str.replace(/<\/(sub|sup|u|strike|b|i|pre)>/ig,'[/$1]');
	str = str.replace(/<(\/)?strong>/ig,'[$1b]');
	str = str.replace(/<(\/)?em>/ig,'[$1i]');
	str = str.replace(/<(\/)?blockquote([^>]*)>/ig,'[$1blockquote]');

	str = str.replace(/<img[^>]*smile=\"(\d+)\"[^>]*>/ig,'[s:$1]');
	str = str.replace(/<img[^>]*src=[\'\"\s]*([^\s\'\"]+)[^>]*>/ig,'[img]'+'$1'+'[/img]');
	str = str.replace(/<a[^>]*href=[\'\"\s]*([^\s\'\"]*)[^>]*>(.+?)<\/a>/ig,'[url=$1]'+'$2'+'[/url]');
	
	str = str.replace(/<[^>]*?>/ig, '');
	str = str.replace(/&amp;/ig, '&');
	str = str.replace(/&lt;/ig, '<');
	str = str.replace(/&gt;/ig, '>');
	return str;
}
$.UnUbb=function(str)
{
    str=$.String(str);
	str = str.replace(/</ig,'&lt;');
	str = str.replace(/>/ig,'&gt;');
	str = str.replace(/\n/ig,'<br />');
	str = str.replace(/\[hr\]/ig,'<hr />');
	str = str.replace(/\[\/(size|color|font|backcolor)\]/ig,'</font>');
	str = str.replace(/\[(sub|sup|u|i|strike|b|blockquote|li)\]/ig,'<$1>');
	str = str.replace(/\[\/(sub|sup|u|i|strike|b|blockquote|li)\]/ig,'</$1>');
	str = str.replace(/\[\/align\]/ig,'</p>');
	str = str.replace(/\[(\/)?h([1-6])\]/ig,'<$1h$2>');
	
	str = str.replace(/\[align=(left|center|right|justify)\]/ig,'<p align="$1">');
	str = str.replace(/\[size=(\d+?)\]/ig,'<font size="$1">');
	str = str.replace(/\[color=([^\[\<]+?)\]/ig, '<font color="$1">');
	str = str.replace(/\[backcolor=([^\[\<]+?)\]/ig, '<font style="background-color:$1">');
	str = str.replace(/\[font=([^\[\<]+?)\]/ig, '<font face="$1">');
	str = str.replace(/\[list=(a|A|1)\](.+?)\[\/list\]/ig,'<ol type="$1">$2</ol>');
	str = str.replace(/\[(\/)?list\]/ig,'<$1ul>');

	str = str.replace(/\[img\]([^\[]*)\[\/img\]/ig,'<img src="$1" border="0" />');
	str = str.replace(/\[url=([^\]]+)\]([^\[]+)\[\/url\]/ig, '<a href="$1">'+'$2'+'</a>');
	str = str.replace(/\[url\]([^\[]+)\[\/url\]/ig, '<a href="$1">'+'$1'+'</a>');
	return str;
}

//=====================================
//获取干净HTML代码
//=====================================
$.ClearHTML=function(A)
{
	try
	{
	   var Tag={div:1,span:1,img:1,br:1,font:1,p:1,a:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,table:1,tbody:1,tfoot:1,thead:1,tr:1,td:1}
	   var rs=A.all;
	   for(var i=0;i<rs.length;i++)
	   {
		   var tag=rs[i].tagName.toLowerCase()
		   if(!Tag[tag]){rs[i].removeNode();i--;continue;}
		   switch(tag)
		   {
			   case "a":rs[i].outerHTML='<a href="'+rs[i].href+'">'+rs[i].innerHTML+'</a>';break;
			   case "img":rs[i].outerHTML='<img src="'+rs[i].src+'" />';break;
			   default:rs[i].clearAttributes();rs[i].removeAttribute("style");rs[i].removeAttribute("id");break;
		   }
		}
		return A.innerHTML;
	}catch(e){alert(e.description);return ''}
}

//=====================================
//获取剪贴板HTML
//=====================================
$.Clip=function(h,c)
{
	try
	{
	  if(!h) return window.clipboardData.getData("Text");
	  var Mc=$("Temp");
		  Mc.innerText=' '
	  var oTextRange=document.body.createTextRange();
		  oTextRange.moveToElementText(Mc);
		  oTextRange.execCommand("Paste");
	  var html=c?$.ClearHTML(Mc):Mc.innerHTML;
		  Mc.innerHTML='';
	      return html; 
	 }catch(e){return ''}
}

//=================================
//Cookies类
//=================================
function Cls_Cookies(name)
{
	this.name=name;
	this.Reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	this.Set=function(value,path,days){path=path?path:'/';days=days?days:7;var ExpDate=new Date();ExpDate.setTime(ExpDate.getTime()+days*34560000);document.cookie=name+"="+escape(value)+";path="+path+";expires="+ExpDate.toGMTString();}
	this.Get=function(){return this.Reg.test(document.cookie)?unescape(RegExp.$2):'';}
	this.Del=function(){this.Set('','',-1);}
}
//==============================
//窗口类
//==============================
function Cls_Window()
{
    this.dialog=function(){var sOption='scroll:'+(this.scroll?'yes':'no')+';edge:'+(this.edge?'sunken':'raised')+';help:'+(this.help?'yes':'no')+';status:'+(this.status?'yes':'no')+';resizable='+(this.resizable?'yes':'no')+';dialogWidth='+this.width+'px;dialogHeight='+this.height+'px;';return window.showModalDialog(this.url,window,sOption);}
	this.open=function(){var sOption='width='+this.width+',height='+this.height+',left='+(this.left?this.left:((screen.availWidth-this.width)/2))+',top='+(this.top?this.top:((screen.availHeight-this.height)/2))+',titlebar='+(this.titlebar?'yes':'no')+',status='+(this.status?'yes':'no')+',toolbar='+(this.toolbar?'yes':'no')+',menubar='+(this.menubar?'yes':'no')+',location='+(this.location?'yes':'no')+',fullscreen='+(this.fullscreen?'yes':'no');return window.open(this.url,null,sOption);}
	this.Dialog=function(w,h,url)
	{
	  this.width=w;
	  this.height=h;
	  this.url="/dialog.html?w="+this.width+"&h="+this.height+"&u="+escape(url);
	  return this.dialog()
	}
}

//==============================
//窗口类
//==============================
function Cls_Dialog(w,h,u)
{
try{
	var url='/Tools/dialog.html?w='+w+'&h='+h+'&u='+escape(u);
	var sOption='scroll:no;edge:raised;help:no;status:no;resizable=no;dialogWidth='+w+'px;dialogHeight='+h+'px;'
	var s=window.showModalDialog(url,window,sOption);
	return s;
}catch(e){alert(e.description)}
}

//==============================
//分页条
//==============================
function Cls_Page(Count,CurrPage,TotalPage,PageSize,Href)
{
	var p1=$.Between(CurrPage,1,TotalPage);
	var p2=$.Between(p1+6,null,TotalPage);
	var html='<li><span>'+Count+'</span></li><li><span>'+CurrPage+'/'+TotalPage+'</span></li>'
		html+=(CurrPage>1)?'<li><a href="'+Href.replace("*",1)+'"><<</a></li><li><a href="'+Href.replace("*",CurrPage-1)+'"><</a></li>':'';
		for(var i=p1;i<=p2;i++)
		{
			html+=(CurrPage==i)?'<li class="f">'+i+'</li>':'<li><a href="'+Href.replace("*",i)+'">'+i+'</a></li>';
		}	
		html+=(CurrPage<TotalPage)?'<li><a href="'+Href.replace("*",CurrPage+1)+'">></a></li><li><a href="'+Href.replace("*",TotalPage)+'">>></a></li>':'';
		html='<ul>'+html+'</ul>'
		document.write(html)
}

//==============================
//操作列表框类
//==============================
function Cls_Select(obj)
{
  this.Obj=(typeof(obj)=="string")?$(obj):obj;
  this.Update=function(value,text,index)
  {
	  var n=index?index:(this.Obj.options.length++);
	  this.Obj.options[n].value=value;
	  this.Obj.options[n].text=text;
	  return n;
  }
  this.Clear=function(){this.Obj.options.length=0;}
  this.Del=function()
  {
	 var html='';
	 var rs=this.Obj.options;
	 for(var i=0;i<rs.length;i++)
	 {
		if(rs[i].selected){html+=','+rs[i].value;rs.remove(i);i--;};
	 }
	 return html.substr(1);
  }
  this.Selected=function()
  {
	  var html='';
	  var rs=this.Obj.options;
	  for(var i=0;i<rs.length;i++){html+=rs[i].selected?(','+rs[i].value):''}
	  return html.substr(1);
  }
  this.List=function(Arr)
  {
  }
}

//==============================
//输出Flash
//==============================
$.Upfile=function()
{
	try
	{
		var url='/Tools/Upload/852198/dialog.html';
		var sOption='scroll:no;edge:raised;help:no;status:no;resizable=no;dialogWidth=480px;dialogHeight=220px;'
		var v=window.showModalDialog(url,null,sOption);
		return v?v:'';
	}catch(e){alert(e.description)}
} 
//==============================
//输出Flash
//==============================
function Echo(str){document.write(str);}
Echo.Flash=function(url,w,h)
{
  var html='\
  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+w+'" height="'+h+'">\
	  <param name="movie" value="'+url+'">\
	  <param name="quality" value="high">\
	  <embed src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed>\
  </object>'
  document.write(html);
}
