var XmlHttp = {
    _objPool: [],

    _getInstance: function ()//用于检测是否有可用的连接，如果有，返回该可用连接，如果没有调用_objPool()方法，创建一个连接，并返回新创建的连接;
    {
        for (var i = 0; i < this._objPool.length; i ++)
        {
            if (this._objPool[i].readyState == 0 || this._objPool[i].readyState == 4)
            {
                return this._objPool[i];
            }
        }

        // IE5中不支持push方法
        this._objPool[this._objPool.length] = this._createObj();

        return this._objPool[this._objPool.length - 1];
    },

    _createObj: function ()//用于创建新的连接
    {
        if (window.XMLHttpRequest)
        {
            var objXMLHttp = new XMLHttpRequest();

        }
        else
        {
            var MSXML = ['MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
            for(var n = 0; n < MSXML.length; n ++)
            {
                try
                {
                    var objXMLHttp = new ActiveXObject(MSXML[n]);
                    break;
                }
                catch(e)
                {
                }
            }
         }          

        // mozilla某些版本没有readyState属性
        if (objXMLHttp.readyState == null)
        {
            objXMLHttp.readyState = 0;

            objXMLHttp.addEventListener("load", function ()
                {
                    objXMLHttp.readyState = 4;

                    if (typeof objXMLHttp.onreadystatechange == "function")
                    {
                        objXMLHttp.onreadystatechange();
                    }
                },  false);
        }

        return objXMLHttp;
    },

    // 发送请求(方法[post,get], 地址, 数据, 回调函数,载入层名称)
    sendReq: function (method, url, data, callback,divname,sel_value)
    {
		//alert('go1');
        var objXMLHttp = this._getInstance();
        with(objXMLHttp)
        {
            try
            {
                // 加随机数防止缓存
                if (url.indexOf("?") > 0)
                {
                    url += "&randnum=" + Math.random();
                }
                else
                {
                    url += "?randnum=" + Math.random();
                }
				//alert(url);
                open(method, url, true);

                // 设定请求编码方式
                
                setRequestHeader('Content-Type', 'text/xml; GB2312');
                send(data);
				
                onreadystatechange = function ()
                {
					//alert('go2');
                    if (objXMLHttp.readyState==4 || objXMLHttp.readyState=='complete')
                    {
						//alert('go3');
						//alert(objXMLHttp.responseText);
                        callback(objXMLHttp,divname,sel_value);
                    }
                }
            }
            catch(e)
            {
                alert(e);
            }
        }
    }
};   




function init_request(){
       var XmlHttpobj = this._getInstance();
       return XmlHttpobj;
    }

function imgset(id,weight)
{
//if (getobject(id))
 // {
    if (document.getElementById(id).offsetWidth>weight)
     {
       document.getElementById(id).width=weight
     }
  //}
}

		
function DoSearch(i)
{
  key=document.getElementById("key").value;
  searchtyp=document.getElementById("search").value;
  bid=document.getElementById("bid").value;
  if (key=='')
  {
   alert('请填写关键字');
   document.getElementById("key").focus();
   return false;
  }
  var querywords="?id="+bid+"&search="+searchtyp+"&key="+key;
  if(i)
  {
	  sendAJAX(querywords,i);
  }
  else
  {
      sendAJAX(querywords);
  }
  toTop();
}

function getUrl(i)
{
	if(i==1)
	{
	   return '/cmd/htmlpublic/blog_list.park'//方式1 调用博客列表，点击打开新页面
	}
	if(i==2)
	{
		return '/cmd/htmlpublic/bdetail.park'//方式2 调用博客详细页面
	}
	if(i==3)
	{
		return '/cmd/htmlpublic/detail_list.park'//方式3 调用博客博客列表，点击在本页显示
	}
	if(i=='indexset')
    {
		return '../admin/indexset.park'
	}
	if(i=='linkset')
	{
		return '../admin/linkset.park'
	}
	if(i=='addblog')
	{
		return '../admin/addblog.park'
	}
	if(i=='admwelcome')
    {
		return '../admin/admwelcome.park'
	}
	if(i=='typeset')
	{
		return '../admin/typset.park'
	}
	if(i=='bloglist')
	{
		return '../admin/bloglist.park'
	}
	if(i=='loadblog')
	{
		return '../admin/editblog.park'
	}
    if(i=='bgset')
	{
		return '../admin/bgset.park'
	}
	if(i=='chekfolder')
	{
		return '../admin/checkfolder.park'
	}
	if(i=='indexlist')
	{
		return '/cmd/htmlpublic/index_list.park'
	}
    if(i=='add_poto')
	{
		return '../admin/add_poto.park'
	}
	if(i=='indexlist')
	{
		return '../admin/add_poto.park'
	}
	if(i=='set_ptype')
	{
		return '../admin/set_ptype.park'
	}
	if(i=='album_list')
	{
		return '../admin/album_list.park'
	}
	if(i=='palbum_list')
	{
		return '/cmd/htmlpublic/album_list.park'
	}
	if(i=='poto_list')
	{
		return '../admin/poto_list.park'
	}
	if(i=='edit_poto')
	{
		return '../admin/edit_poto.park'
	}
	if(i=='pphoto_list')
	{
		return '/cmd/htmlpublic/photo_list.park'
	}
	if(i=='show_photo')
	{
		return '/cmd/htmlpublic/show_photo.park'
	}
	return '/cmd/htmlpublic/blog_list.park'//默认方式，同方式1
}



function sendAJAX(querywords,i)
{

//alert('querywords='+querywords+',i='+i);
document.getElementById("bloglist").innerHTML="&nbsp;开始载入..";
if(i)
  {
	  url=getUrl(i)+querywords;
  }
  else
  {
    url="/cmd/htmlpublic/blog_list.park"+querywords;
  }
 //alert(url);
 XmlHttp.sendReq('get', url, '',ServerProcess,'bloglist','');
}

function showDetail(querywords)
{
 document.getElementById("bloglist").innerHTML="&nbsp;开始载入..";
 url="bdetail.park"+querywords;
 //alert(url);
 XmlHttp.sendReq('post', url, '',ServerProcess,'bloglist','');
 XmlHttp.onreadyStatechange=ServerProcess;
}

function ServerProcess(obj,divname,sel_value)
{
 if (obj.readyState==4 || obj.readyState=='complete')
  {
	  //alert(obj.responseText);
      document.getElementById(divname).innerHTML =obj.responseText;
	  //alert('compelete');
  }
}

function toTop()
{
location.href="#top";
}

function getobject(obj)//判断对象obj是否已经装载.
{
	//alert("go");
	var obj=document.getElementById(obj);
	if (obj==null)
	{
		return false;
	}
	else
	{
		return true;
	}
}


function checkLogin(userName,n) {
	if (n == 0 && userName.value == "******"){userName.value="";}
	if (n == 1){
		if(userName.value == "******"){userName.value="";}
	}
	if (n == 2 && userName.value == ""){userName.value = "******";}
}

function showlogin()
{
	if(document.getElementById("isaddname").checked==true )
		{
		document.getElementById("uname").disabled=true;
        document.getElementById("pwd").disabled=true;
		}
		else
		{
        document.getElementById("uname").disabled=false;
        document.getElementById("pwd").disabled=false;
		}
	
}
		

function shownumber(bid)
{
			   if (bid<10)
			   {
			   document.write("0000"+bid)
			   }
			   else if(bid<100)
			   {
			   document.write("000"+bid)
			   }
			   else if(bid<1000)
			   {
			   document.write("00"+bid)
			   }
			   else if(bid<10000)
			   {
			   document.write("0"+bid)
			   }
			   else 
			   {
			   document.write(bid)
			   }
}

function makeArray() 
{
for (var i=0; i < arguments.length; i++)
this[i] = arguments[i];
this.length = arguments.length;
}

function ismusic(mstring)
{ 
	var strpath = mstring.toLowerCase();
	var typstr = new makeArray("rm","wma","mp3","wav","ram","ra","asf");
	for (var i=0;i<typstr.length;i++)
	{
		if(strpath.indexOf(typstr[i])>0)
		{
			return true;
		}
	}
	return false;
}

function whichtyp(mstring)
{
	var muscistr = mstring.toLowerCase();
	var rmtyp = new makeArray("rm","ram","ra");
	var wmtyp =new makeArray("wma","mp3","wav","asf");
	for (var i=0;i<wmtyp.length;i++)
	{
		if(music.indexOf(wmtyp[i])>0)
		{
			return 'wm';
		}
	}
	for (var i=0;i<rmtyp.length;i++)
	{
		if(music.indexOf(rmtyp[i])>0)
		{
			return 'rm';
		}
	}
	return 'unknow';
}

function playmusic()
{
	if(ismusic(music))
	{
		mtyp=whichtyp(music);
		if (mtyp=='rm')
		{
			playrm(music);
		}
		if (mtyp=='wm')
		{
			playwm(music);
		}
		else
		{
			//alert('unknow');
		}
	}
	else
	{
		//alert("格式不正确");
	}
}

function playwm(mstr)
{ 
	document.write("<OBJECT id=mplayer codeBase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715  type=application/x-oleobject height=68 standby='Loading Microsoft Windows Media Player components...' width=90%  align=baseline border=0  classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95><PARAM NAME='FileName' VALUE="+mstr+"><PARAM NAME='ShowControls' VALUE='1'><PARAM NAME='ShowPositionControls' VALUE='0'><PARAM NAME='ShowAudioControls' VALUE='1'><PARAM NAME='ShowTracker' VALUE='1'><PARAM NAME='ShowDisplay' VALUE='0'><PARAM NAME='ShowStatusBar' VALUE='1'><PARAM NAME='AutoSize' VALUE='0'><PARAM NAME='ShowGotoBar' VALUE='0'><PARAM NAME='ShowCaptioning' VALUE='0'><PARAM NAME='AutoStart' VALUE='1'><PARAM NAME='PlayCount' VALUE='0'><PARAM NAME='AnimationAtStart' VALUE='0'><PARAM NAME='TransparentAtStart' VALUE='0'><PARAM NAME='AllowScan' VALUE='0'><PARAM NAME='EnableContextMenu' VALUE='1'><PARAM NAME='ClickToPlay' VALUE='0'><PARAM NAME='InvokeURLs' VALUE='1'><PARAM NAME='DefaultFrame' VALUE='datawindow'></OBJECT><BR><BR>");
	document.write("<DIV align=center>如果您无法收听歌曲<br>请先安装<A  href='http://download.microsoft.com/download/9/4/0/94072943-9188-4a60-b31f-3031f18404e4/mpsetup.exe'  target=_blank>Windows media player</A>软件</DIV>");
}          

function playrm(mstr)
{ 
	document.write("<embed id='RealPlayer1' type='audio/x-pn-realaudio-plugin' src="+mstr+" controls='ControlPanel,StatusBar' width=90% height=68 border=0 autostart=true loop=true></embed><BR><BR>");
	document.write("<DIV align=center>如果您无法收听歌曲<br>请先安装<a href='http://forms.real.com/netzip/intl/intl_getrde601.html?lang=cn&h=software-dl.real.com&f=windows/RealPlayer10-5GOLD_cn.exe&p=RealPlayer&oem=rp10_cn&src=020923home_cn_cn&tagtype=ie&type=rp10_cn' target=_blank>RealPlayer</a>软件</DIV>");
}       

function checkwords()
{
var myArray = new makeArray("操!","操！","你妈的","他妈的","狗","杂种","屄","屌","王八","强奸","做爱","处女","泽民","锦涛","法伦","洪志","法轮","垃圾","你妈","SB","sb","贱","妓女","上床","傻逼","骚","婊","卖","共产党");
for( var i=0;i<myArray.length;i++)
 { if(document.getElementById("info").value.indexOf(myArray[i])!=-1)
  {
   return false;
  }
 }
return true;
}

function len(str)
{
return str.replace(/[^\x00-\xff]/g,"aa").length
}


function showm(t)//显示/隐藏菜单
{
if (document.getElementById("m"+t+"").style.display=="none"){
for(i=1;i<=3;i++){
document.getElementById("m"+i+"").style.display="none"
}
document.getElementById("m"+t+"").style.display=""
}else{
document.getElementById("m"+t+"").style.display="none"
}
}

function closem()//隐藏菜单
{
for(i=1;i<=3;i++){
document.getElementById("m"+i+"").style.display="none"
}
}

function show_welcome()
{
closem()
sendAJAX('?id=me','admwelcome')
}

function getdate(year,month,day)
{
	var restr=year+"年"+month+"月"+day+"日(日记)";
	document.getElementById("ttitle").value=restr;
}

function em(){
var arr = showModalDialog("/cmd/hinc/Emotion.htm", "", "dialogWidth:20em; dialogHeight:9.5em; status:0;help:0");
if (arr != null){
IframeID.focus()
sel=IframeID.document.selection.createRange();
sel.pasteHTML(arr);
}
}

function CleanCode(){
var body = IframeID.document.body;
var html = IframeID.document.body.innerHTML;
html = html.replace(/\<p>/gi,"[$p]");
html = html.replace(/\<\/p>/gi,"[$\/p]");
html = html.replace(/\<br>/gi,"[$br]");
html = html.replace(/\<[^>]*>/g,"");
html = html.replace(/\[\$p\]/gi,"<p>");
html = html.replace(/\[\$\/p\]/gi,"<\/p>");
html = html.replace(/\[\$br\]/gi,"<br>");
IframeID.document.body.innerHTML = html;
}


function FormatText(command,option){IframeID.focus();IframeID.document.execCommand(command,true,option);}

function CheckLength(){alert("最大字符为 "+50000+ " 字节\n您的内容已有 "+IframeID.document.body.innerHTML.length+" 字节");}

function emoticon(theSmilie){
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML("<img src=../cmd/images/Emotions/"+theSmilie+".gif>");
}


function CheckForm(form){
form.contentx.value=IframeID.document.body.innerHTML; 
MessageLength=IframeID.document.body.innerHTML.length;
if(MessageLength<2){alert("文章内容不能小于2个字符！");return false;}
if(MessageLength>50000){alert("文章内容不能超过50000个字符！");return false;}
document.yuziform.submit1.disabled = true;
}

function BlogGopreview()
{
document.preview.content.value=IframeID.document.body.innerHTML; 
document.preview.title.value=document.yuziform.ttitle.value;
window.open('', 'preview_page', 'resizable,scrollbars,width=550,height=450');
document.preview.submit()
}

function BackColor()
{
  var arr = showModalDialog("/cmd/hinc/selcolor.htm", "", "dialogWidth:18em; dialogHeight:17.5em; status:0;help:0");
  if (arr != null) FormatText('BackColor', arr);
  else IframeID.focus();
}

function foreColor()
{
  var arr = showModalDialog("/cmd/hinc/selcolor.htm", "", "dialogWidth:18em; dialogHeight:17.5em; status:0;help:0");
  if (arr != null) FormatText('forecolor', arr);
  else IframeID.focus();
}

//////替换内容
function replace()
{
  var arr = showModalDialog("/cmd/hinc/replace.html", "", "dialogWidth:22em;dialogHeight:10em;status:0;help:0");
	if (arr != null){
		var ss;
		ss = arr.split("*")
		a = ss[0];
		b = ss[1];
		i = ss[2];
		con = IframeID.document.body.innerHTML;
		if (i == 1)
		{
			con = bbsxp_rCode(con,a,b,true);
		}else{
			con = bbsxp_rCode(con,a,b);
		}
		IframeID.document.body.innerHTML = con;
	}
	else IframeID.focus();
}
function bbsxp_rCode(s,a,b,i){
	a = a.replace("?","\\?");
	if (i==null)
	{
		var r = new RegExp(a,"gi");
	}else if (i) {
		var r = new RegExp(a,"g");
	}
	else{
		var r = new RegExp(a,"gi");
	}
	return s.replace(r,b); 
}
//////替换内容结束

function img(){
url=prompt("请输入图片文件地址:","http://");
if(!url || url=="http://") return;
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML("<a href='"+url+"' target='_blank'><img src="+url+" border='0'></a>");
}

function addimg(){
url=prompt("请输入图片文件地址:","http://");
if(!url || url=="http://") return;
document.yuziform.resume.value=document.yuziform.resume.value+"[img]"+url+"[/img]";
}

function RealPlay(){
var arr = showModalDialog("/cmd/hinc/RealPlay.htm", "", "dialogWidth:22em; dialogHeight:10.5em; status:0;help:0");
if (arr != null){
IframeID.focus()
sel=IframeID.document.selection.createRange();
sel.pasteHTML(arr);
}
}

function Table(){//插入表格
var arr = showModalDialog("/cmd/hinc/Table.htm", "", "dialogWidth:20em; dialogHeight:15.5em; status:0;help:0");
if (arr != null){
IframeID.focus()
sel=IframeID.document.selection.createRange();
sel.pasteHTML(arr);
}
}

function MediaPlayer(){
var arr = showModalDialog("/cmd/hinc/MediaPlayer.htm", "", "dialogWidth:22em; dialogHeight:10.5em; status:0;help:0");
if (arr != null){
IframeID.focus()
sel=IframeID.document.selection.createRange();
sel.pasteHTML(arr);
}
}

function flash(){
var arr = showModalDialog("/cmd/hinc/flash.htm", "", "dialogWidth:22em; dialogHeight:9em; status:0;help:0");
if (arr != null){
IframeID.focus()
sel=IframeID.document.selection.createRange();
sel.pasteHTML(arr);
}
}

function turnpage(querywords)//根据条件查询结果,并移到页首
{
	sendAJAX(querywords);
	toTop();
}

function selecttyp(querywords)//根据条件查询类型详细列表,并移到页首
{
	sendAJAX(querywords,'3');
	toTop();
}

function saveType(id)
{
	type = document.getElementById("type"+id).value;
	if (type=='')
	{
		alert('类别名称不能为空');
	}
	if(confirm("确定保存修改吗?"))
    {	
		location.href="?action=savetype&id="+id+"&tname="+type;
	}
	else
		{
		return;
		}
}

function savepType(id)
{
	type = document.getElementById("type"+id).value;
	if (type=='')
	{
		alert('类别名称不能为空');
	}
	if(confirm("确定保存修改吗?"))
    {	
		location.href="?action=saveptype&id="+id+"&tname="+type;
	}
	else
		{
		return;
		}
}

function loaddiv(typ,querywords,divname)
{
	document.getElementById("todo").innerHTML="&nbsp;开始载入..";
	if (typ=="poto")
	{
		tourl="changeptyp.park";
	}
	else
	{
		tourl="changetyp.park";
	}
	url=tourl+querywords;
	//alert(url);
	XmlHttp.open("POST",url,true);
    XmlHttp.send(null);
    XmlHttp.onreadyStatechange=LoadForm;
}

function LoadForm()
{
 if (XmlHttp.readyState==4 || XmlHttp.readyState=='complete')
  {
	   //alert(XmlHttp.responseText);
      document.getElementById("todo").innerHTML =XmlHttp.responseText;
	  //alert('compelete');
  }
}

function delType(id)
{
		alert("请选择对此分类下文章的操作.");
		querywords="?tid="+id;
		divname="todo";
		typ="custom"
		document.getElementById("d1").style.display="";
		loaddiv(typ,querywords,divname);
}

function showlink(tlink)
{
    if (tlink.indexOf("|") != -1)
		{
		thelist=tlink.split("|");
        for(i=1;i<11;i++) 
			{
			ttlink=thelist[i].split(")");
			if(ttlink[0] != "" && ttlink[1] != "")
				{
				document.write("<tr><td> ·&nbsp;<a href="+ttlink[1]+" target=_blank>"+ttlink[0]+"</a></td></tr>")
				}
			}
		}
}

function delpType(id)
{
		alert("请选择对此分类下照片的操作.");
		querywords="?tid="+id;
		divname="todo";
		typ="poto";
		document.getElementById("d1").style.display="";
		loaddiv(typ,querywords,divname);
}

function hidd1()
{
	document.getElementById("d1").style.display="none";
}

function ifdel()
{
	if(confirm("确定删除吗?"))
    {	
		form1.Submit.disabled=true;
        form1.submit();
	}
	else
	{
	return;
	}
}

function delBlog(id)
{
	if(confirm("确定删除吗?"))
    {	
		location.href='?action=delblog&id='+id
	}
	else
	{
	return;
	}
}

function loadBlog(id)//读取修改文章表单
{
	//alert('loadBlog is run');
	querywords=id;
	sendAJAX(querywords,'loadblog')
	time1=window.setInterval ("init_editarea()",300);
}

function setindex()
{
	sendAJAX('?id=me','indexset')
}

function copyurl(title,folder)
{
	if (confirm("点击确定，保存本博客地址到剪贴板，就可以用QQ、MSN发送给您的朋友了。"))
	{
		clipBoardContent='推荐个博客给你瞧瞧：《'+title+'》\r\n http://blog.hoopark.cn/'+folder;	
		window.clipboardData.setData("Text",clipBoardContent)
		}
		else
		{return}
}
	
function palbum_list(querywords)
{
	sendAJAX(querywords,'palbum_list');
}

function pphoto_list(querywords)
{
	sendAJAX(querywords,'pphoto_list');
}
function show_photo(querywords)
{
	sendAJAX(querywords,'show_photo');
}
 
 function  keyborad_listen()   
  {   
  if   (window.event.ctrlKey && window.event.keyCode==37)   
    {alert("你按了Ctrl+←键");}
	 if   (window.event.ctrlKey && window.event.keyCode==39)   
    {alert("你按了Ctrl+→键");}   
  } 

  function pic_resize(obj,width,height)
  { 
	//alert('我运行了啊');
	  if(obj.width>width)
		  {
		  //alert('宽度超过了');
		  //alert('width:'+obj.width+';height='+obj.height);
		  obj.resized=true;
		  obj.style.width=width;
                  obj.style.height=obj.height/obj.width*width;
                  //alert('结果width:'+obj.style.width+';结果height='+obj.style.height);
		  }
	if(obj.height>height)
		  {
		  //alert('高度超过了');
		  obj.resized=true;
		  obj.style.height=height;
                  obj.style.width=obj.width/obj.height*height;
		  }
  }
