﻿function HMrequestText(u,d,r,p){
	var o=HMTry(
		function(){return new XMLHttpRequest()},
		function(){return new ActiveXObject("Microsoft.XMLHttp")},
		function(){return new ActiveXObject("Msxml2.XMLHTTP")}
	);
	if(!o)return;
	!d?o.open("get",u,true):(o.open("post",u,true),o.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8"));
	o.onreadystatechange = function(){
		if(o.readyState==4){
			if(o.status==200){
				var t=o.responseText;
				switch(p){
					case 1:r(t);break;
					case 2:r(o.responseXML);break;
					default:HMgetElement(r).innerHTML=t
				}
			}else{
				alert("请求页面失败！")
			}
		}
	}
	o.send(d)
}
function HMTry(){
	for(var i=0;i<arguments.length;i++){try{return arguments[i]()}catch(e){}}
	return null
}
function HMgetElement(e){
	return typeof(e)=="string"?document.getElementById(e):e
}
function HMGetTop(e){
	var t=e.offsetTop;
	while(e.offsetParent){e=e.offsetParent;t+=e.offsetTop}
	return t
}
function HMGetLeft(e){
	var l=e.offsetLeft;
	while(e.offsetParent){e=e.offsetParent;l+=e.offsetLeft}
	return l
}
function HMopenElement(e){
	var dis,e=HMgetElement(e);
	dis=document.all?e.currentStyle["position"]:dis=document.defaultView.getComputedStyle(e,null).getPropertyValue("position");
	e.style.display=dis=="absolute"?"block":""
}
function HMcloseElement(e){
	HMgetElement(e).style.display="none"
}
function HMinsertData(e,d){
	var o=HMgetElement(e),v=o.value,l,f="",t=0;;
	if(HMisNone(v)){o.value=d;return}
	l=v.split(",");
	for(var i=0;i<l.length;i++)l[i]==d?t=1:f+=l[i]+",";
	o.value=t?f.replace(/^(.*?),$/g,"$1"):v+","+d
}
function HMfloatDiv(eId,cId){
	var cObj=HMgetElement(cId),tObj=HMgetElement(eId),_x,_y,ds=false,st=tObj.style;
	st.position="absolute";
	cObj.onmousedown=function(e){
		e=e||event;
		document.all?(cObj.onmousemove=omm,cObj.setCapture()):
			document.addEventListener("mousemove",omm,true);
		_x=e.clientX,_y=e.clientY,ds=true,cObj.style.cursor="move"
	}
	cObj.onmouseup=function(e){
		document.all?cObj.releaseCapture():document.removeEventListener("mousemove",omm,true);
		ds=false,cObj.style.cursor=""
	}
	var omm=function(e){
		if(!ds)return;
		e=e||event;
		var dx=tObj.offsetLeft,dy=tObj.offsetTop,tx=e.clientX,ty=e.clientY;
		var fl=tx-_x+dx,ft=ty-_y+dy,db=document.body,dd=document.documentElement;
		var dw1=db.clientWidth,dw2=dd.clientWidht;
		if(isNaN(dw1))dw1=0;
		if(isNaN(dw2))dw2=0;
		var dw=dw1>dw2?dw1:dw2;
		var sh1=db.scrollHeight,sh2=dd.scrollHeight;
		if(isNaN(sh1))sh1=0;
		if(isNaN(sh2))sh2=0;
		var sh=sh1>sh2?sh1:sh2;
		if(fl>0&&(fl+tObj.clientWidth)<dw){st.left=fl+"px";_x=tx}
		if(ft>0&&(ft+tObj.clientHeight)<sh){st.top=ft+"px";_y=ty}
	}
}
function HMprint(t){document.write(t)}
function HMgetRadio(r){
	if(isNaN(r.length))return r.checked?r.value:"";
	for(var i=0;i<r.length;i++)if(r[i].checked)return r[i].value;
	return ""
}
function HMisNone(t){return !t||t.replace(/\s/g,"")==""}
function HMGetQuery(key){
	var url=window.location.toString(),space=url.indexOf("#");
	if(space>0)url=url.substr(0,space);
	space=url.indexOf("?");
	var urlVal=url.substr(space+1,url.length).split("&"),dSpace;
	for(var i=0;i<urlVal.length;i++){
		dSpace=urlVal[i].indexOf("=");
		if(dSpace>=0)if(urlVal[i].substr(0,dSpace)==key)return urlVal[i].substr(dSpace+1,urlVal[i].length)
	};
	return ""
}
function HMGetPage(){
	var p=HMGetQuery("page");
	return isNaN(p)||HMisNone(p)?1:(parseInt(p)<1?1:parseInt(p))
}
function HMCopyText(text){
	if(document.all){clipboardData.setData("text",text)}
	else{
		try{
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		}catch(e){
			alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
			return false
		};
		var clip=Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
		if(!clip)return false;
		var trans=Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
		if(!trans)return false;
		trans.addDataFlavor("text/unicode");
		var str=Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		str.data=text;
		trans.setTransferData("text/unicode",str,text.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if(!clip)return false;
		clip.setData(trans,null,clipid.kGlobalClipboard)
	};
	return true
}
function HMleachSql(t){
	return t.replace(/[\'\`\,\?\"\-\_\+\=\"\^\$\#\&\s\|\%\*\(\)\[\]\{\}\:\;\<\>\/\\\!\?\.\~\@]/g,"")
}
function HMFeedback(){
	window.open(HMSITEROOT+"core/HMFeedback.asp?url="+encodeURIComponent(window.location.toString()),"","width=400,height=240,top=150,left=200")
}
function HMTrim(t){return t.replace(/\s*(\S[\s\S]*?\S)\s*/,"$1")}
function HMisIe(){return !!document.all}
function HMEventElement(e){return document.all?event.srcElement:e.target}
function HMCreateDiv(e){HMprint("<div id='"+e+"'></div>")}
function HMCreateul(e){HMprint("<ul>"+e+"</ul>")}
function HMForm(fn,ec){
	var form=typeof(fn)=="string"?document.forms[fn]:fn;
	this.getForm=function(){return form};
	this.getValue=function(n){
		if(!form[n])return"";
		var ele,val="",pro=form[n];
		ele=pro.length?pro[0]:pro;
		switch(ele.tagName.toLowerCase()){
			case "input":
				switch(ele.type.toLowerCase()){
					case "radio":val=getRadio(n);break;
					case "checkbox":val=getCheckbox(n);break;
					default :val=getText(n);
				}
				break;
			case "textarea":val=getText(n);break;
			case "option":val=getSelect(n);break;
		};
		return ec?encodeURIComponent(val):val
	};
	var getText=function(n){return form[n].value},
	getSelect=function(n){
		var sel=form[n],val;
		if(sel.multiple){
			for(var i=0;i<sel.length;i++)if(sel[i].selected)val+=sel[i].value+",";
			return val.substr(0,val.length-1)
		}else{return sel.options[sel.selectedIndex].value}
	},
	getRadio=function(n){
		var rad=form[n];
		if(rad.length){for(var i=0;i<rad.length;i++)if(rad[i].checked)return rad[i].value}
		else{if(rad.checked)return rad.value};
		return ""
	},
	getCheckbox = function(n){
		var ckb=form[n],val;
		if(ckb.length){
			for(var i=0;i<ckb.length;i++)if(ckb[i].checked)val+=ckb[i].value+",";
			return val.substr(0,val.length-1)
		}else{return ckb.checked?ckb.value:""}
	}
}
function HMGoto(p){
	var t=p?(new HMDom()).height:0;
	document.body.scrollTop=t;
	document.documentElement.scrollTop=t
}
function HMLoadCode(){
	var o=HMgetElement("HMCode");
	if(o)o.src=HMSITEROOT+"core/HMCode.asp?"+Math.random()
}
//获取编辑器内容
function HMGetContent(){
	var editor;
	editor=!document.all?document.getElementById("HMEditor").contentWindow:document.frames["HMEditor"];
	//切换两次编辑模式保证HMTL标记完整
	editor.HESwitchMode();
	editor.HESwitchMode();
	editor.HEReturnContent();
}
function HMSubmitForm(f){
	HMGetContent();
	f.submit()
}

function HMSubmitForm_s(f){
	f.submit()
}

//纯脚本幻灯片
var HMJSlide=function(){
	if(!window.HMSlide)window.HMSlide={};
	this.width=300;
	this.height=200;
	var list=[],id="HMSlide_"+(new Date()).getTime(),ie=!!document.all,num=0;
	window.HMSlide[id]=this;
	this.add=function(){list[list.length]=arguments};
	this.show=function(){
		function CE(p){return document.createElement(p)};
		var topDiv,pLink,photo,theme,tool,tLink,st;
		HMCreateDiv(id);
		topDiv=CE("div");
		st=topDiv.style;
		st.width=this.width+"px";
		st.border="1px #000 solid";
		pLink=CE("a");
		pLink.target="_blank";
		pLink.id=id+"_link";
		photo=CE("img");
		photo.border=0;
		photo.id=id+"_photo";
		photo.width=this.width;
		photo.height=this.height;
		pLink.appendChild(photo);
		tool=CE("div");
		st=tool.style;
		st.background="#000";
		st.textAlign="right";
		st.lineHeight="20px";
		st.fontWeight="bold";
		tool.id=id+"_tool";
		for(var i=0;i<list.length;i++){
			tLink=CE("a");
			tLink.href="javascript:;";
			st=tLink.style;
			st.margin="0 5px 0 0";
			st.color="#999";
			st.textDecoration="none";
			tLink.innerHTML=i+1;
			tLink.onclick=function(){window.HMSlide[id].goto(this.innerHTML-1)};
			tool.appendChild(tLink);
		};
		theme=CE("div");
		st=theme.style;
		st.textAlign="center";
		st.fontWeight="bold";
		st.lineHeight="20px";
		theme.id=id+"_theme";
		topDiv.appendChild(pLink);
		topDiv.appendChild(tool);
		topDiv.appendChild(theme);
		HMgetElement(id).appendChild(topDiv);
		this.play();
	};
	this.play=function(){
		eval("this.goto(num)");
		num++;
		if(num==list.length)num=0;
		setTimeout("HMSlide['"+id+"'].play()",3000)
	};
	this.goto=function(n){
		var obj=HMgetElement(id+"_tool").getElementsByTagName("a"),i;
		for(i=0;i<obj.length;i++)obj[i].style.color=(obj[i].innerHTML==n+1)?"#C00":"#999";
		HMgetElement(id+"_theme").innerHTML=list[n][1];
		HMgetElement(id+"_link").href=list[n][2];
		obj=HMgetElement(id+"_photo");
		if(ie){
			obj.style.filter="revealTrans(Duration=0.6,Transition="+parseInt(Math.random()*30)+")";
			obj.filters.revealTrans.Apply();
		};
		obj.src=list[n][0];
		if(ie)obj.filters.revealTrans.Play()
	}
}
function HMLoadJumpData(e){
	HMrequestText(HMSITEROOT+"core/HMJumpData.asp?channel="+HMChannelId+"&data="+HMDataId+"&"+Math.random(),null,e,0)
}
function HMLoadJumpPicData(e){
	HMrequestText(HMSITEROOT+"core/HMJumpPicData.asp?channel="+HMChannelId+"&data="+HMDataId+"&"+Math.random(),null,e,0)
}
function HMLoadDownList(){
	HMrequestText(HMSITEROOT+"core/HMDownlist.asp?channel="+HMChannelId+"&data="+HMDataId+"&"+Math.random(),null,"HMDownAddressList",0)
}
function HMDownload(id){
	window.open(HMSITEROOT+"core/HMDownload.asp?id="+id,"","width=200,height=200,left=300,top=200")
}
var HMDig={
	element:null,
	load:function(e){
		if(e)this.element=e;
		HMrequestText(HMSITEROOT+"core/HMDigData.asp?action=load&channel="+HMChannelId+"&data="+HMDataId+"&"+Math.random(),null,this.element,0)
	},
	dispose:function(){
		function res(t){
			if(isNaN(t)){
				HMgetElement(HMDig.element).innerHTML=t
			}else{
				switch(parseInt(t,10)){
					case 1:alert("请先登录！");break;
					case 2:alert("您已经顶过了！");break;
				}
			}
		}
		HMrequestText(HMSITEROOT+"core/HMDigData.asp?action=dispose&channel="+HMChannelId+"&data="+HMDataId+"&"+Math.random(),null,res,1)
	}
}
// 设置指定元素中图片及媒体的宽度，以免使页面变形
function HMResetMediaWidth(e,w){
	var tag=["img","embed"],obj,iw,ih;
	for(var n=0;n<tag.length;n++){
		obj=HMgetElement(e).getElementsByTagName(tag[n]);
		for(var i=0;i<obj.length;i++){
			iw=obj[i].clientWidth,ih=obj[i].clientHeight;
			if(iw>w){
				obj[i].style.width=w+"px";
				obj[i].style.height=parseInt(ih*(w/iw),10)+"px"
			}
		}
	}
}
// dom类，获取页面高度、宽度、滚动条位置
function HMDom(){
	var body=document.body,element=document.documentElement;
	this.height=(function(){
		var bh=body.clientHeight,eh=element.clientHeight;
		var bsh=body.scrollHeight,esh=element.scrollHeight;
		if(isNaN(bh))bh=0;
		if(isNaN(eh))eh=0;
		if(isNaN(bsh))bsh=0;
		if(isNaN(esh))wsh=0;
		var dh=bh>eh?bh:eh;
		dh=dh>bsh?dh:bsh;
		return dh>esh?dh:esh
	})();
	this.width=(function(){
		var bw=body.clientWidth,ew=element.clientWidth;
		var bsw=body.scrollWidth,esw=element.scrollWidth;
		if(isNaN(bw))bw=0;
		if(isNaN(ew))ew=0;
		if(isNaN(bsw))bsw=0;
		if(isNaN(esw))esw=0;
		var dw=bw>ew?bw:ew;
		dw=dw>bsw?dw:bsw;
		return dw>esw?dw:esw
	})();
	this.scrollTop=(function(){
		var bst=body.scrollTop,est=element.scrollTop;
		if(isNaN(bst))bst=0;
		if(isNaN(est))est=0;
		return bst>est?bst:est
	})();
	this.scrollLeft=(function(){
		var bsl=body.scrollLeft,esl=element.scrollLeft;
		if(isNaN(bsl))bsl=0;
		if(isNaN(esl))esl=0;
		return bsl>esl?bsl:esl
	})()
}
(function(){
	try{
	var lost=function(){window.location=HMSITEROOT+HMSTOPURL};
	if(HMSITESTATE!=1){lost();return};
	if(HMCLOSETIME!=""){var t=HMCLOSETIME.split(",");
	for(var i=0;i<t.length;i++)if(parseInt(t[i])==(new Date()).getHours()){lost();return}};
	var d=new Date(document.lastModified),
	n=encodeURIComponent(d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds());
	HMrequestText(HMSITEROOT+"core/HMLoadPage.asp?"+"channel="+HMChannelId+"&sub="+HMSubId+"&id="+HMDataId+"&page=="+HMPage+"&updateTime="+n+"&file="+HMFile+"&"+Math.random(),null,function(s){s=parseInt(s);if(s==1)lost()},1)
	}catch(e){}
})();
