var http_request = false;
var callobj;
var lastScript,h_=document.getElementsByTagName("head")[0];
function makeRequest(url, functionName, httpType, sendData) {
	http_request = false;
	if (!httpType) httpType = "GET";
	if (window.XMLHttpRequest) { 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/plain');
		}
		} else if (window.ActiveXObject) {
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Cannot send an XMLHTTP request');
		return false;
	}
	var changefunc="http_request.onreadystatechange = "+functionName;
	eval (changefunc);
	http_request.open(httpType, url, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send(sendData);
}

function getReturnedText () {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var http_msg = http_request.responseText;
			if (http_msg=='0') {
				frm.submits.disabled="disabled";
				show.style.display='';
			}else{
				frm.submits.disabled="";
				show.style.display='none';
			}
		}
	}
}
function $(objname){return document.getElementById(objname);}
function ShowObj(objname){var obj = $(objname);obj.style.display = "";}
function HideObj(objname){var obj = $(objname);obj.style.display = "none";}
function s(o){var obj = $(o);obj.style.display = "";}
function h(o){var obj = $(o);obj.style.display = "none";}

// 处理图片
function zoom(zid,zimg) {
	var div = $(zid);
	div.style.position = 'absolute';
	div.innerHTML = "<img src='" + zimg + "' style='padding:1px;border:1px solid #9FD253;background-color:#fff;margin:18px 0px 0px 0px;'>"
}
// 发布内容
function ChkPost(){
	var chkok = true;
	if (chkok) {if (frm.oTitle.value.length<1) {alert('文章标题不能为空!');chkok=false;}}
	if (chkok) {if (frm.oCid.value==0) {alert('请选择栏目!');chkok=false;}}
	if (chkok) {if (frm.oCid.value==-1) {alert('大栏目不允许发布文章!');chkok=false;}}
	if (chkok) {if (frm.oCid.value==-2) {alert('你没有当前栏目的管理权限!');chkok=false;}}
	if (chkok) {if (frm.oContent.value.length<1) {alert('内容为空!');chkok=false;}}
	if (chkok) {frm.submit();}
}
// 检测标题
function ChkTitle(cid){
	var aTitle = $("oTitle").value;
	if (aTitle.length>0){makeRequest("ajax.asp?Act=ChkTitle&cid=" + cid + "&Key=" + escape(aTitle) + '&Rand=' + Math.random(),"ReturnOnlyAlert","get","");}
}
// 检测自定义文件名
function ChkDiyname(aID){
	var aDiyname = $("oDiyname").value;
	if (aDiyname.length>0){makeRequest("ajax.asp?Act=ChkDiyname&Key=" + escape(aDiyname) + '&ID=' + aID + '&Rand=' + Math.random(),"ReturnOnlyAlert","get","");}
}
// 内容推荐
function ContentCommend(ID){
	callobj = $("ContentCommend" + ID);
	makeRequest("ajax.asp?Act=ContentCommend&ID=" + ID + "&Rand=" + Math.random(),"ReturnInnerHTML","get","");
}
// 内容状态
function ContentState(ID){
	callobj = $("ContentState" + ID);
	makeRequest("ajax.asp?Act=ContentState&ID=" + ID + "&Rand=" + Math.random(),"ReturnInnerHTML","get","");
}
// 安装插件
function PlusInstall(PlusName){
	callobj = $("plus" + PlusName);
	makeRequest("ajax.asp?Act=plusinstall&plusname=" + PlusName + "&Rand=" + Math.random(),"ReturnInnerHTML","get","");
}
// 卸载插件
function PlusUnInstall(PlusName){
	callobj = $("plus" + PlusName);
	makeRequest("ajax.asp?Act=plusuninstall&plusname=" + PlusName + "&Rand=" + Math.random(),"ReturnInnerHTML","get","");
}
// 扩展字段
function modeext(cid,id){
	callobj = $('_modeindex');
	makeRequest("ajax.asp?Act=modeext&cid=" + cid + "&id=" + id + "&Rand=" + Math.random(),"ReturnInnerHTMLMODEEXT","get","");
}
// 扩展内容（编辑器）//凌陈亮添加
function modeext2(cid,id,username,password){
	var url="ajax.asp?Act=modeext2&cid=" + cid + "&id=" + id + "&Rand=" + Math.random();
	var http_request2 = false;
	if (window.XMLHttpRequest) { 
		http_request2 = new XMLHttpRequest();
		if (http_request2.overrideMimeType) {
			http_request2.overrideMimeType('text/plain');
		}
		} else if (window.ActiveXObject) {
			try {
				http_request2 = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			try {
				http_request2 = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request2) {
		alert('Cannot send an XMLHTTP request');
		return false;
	}
	http_request2.open("GET", url, false);
	http_request2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request2.send(null);
	if (http_request2.readyState == 4) {
		if (http_request2.status == 200){
			var obj = $('_modeindex2');
			obj.innerHTML=http_request2.responseText;
			if(obj.innerHTML==''){
				h('_modeindexs2');
			}else{
				var arr=obj.getElementsByTagName('span');
				var arr_js='';
				for(var i=0; i<arr.length; i++){
					if(arr[i].className == 'exteditor'){
						arr_js=arr_js+"var KE" + arr[i].innerHTML + ";KindEditor.ready(function(K) {KE"  + arr[i].innerHTML + " = K.create('#oContent"  + arr[i].innerHTML + "',{uploadJson : '../inc/editor/kindeditor/asp/upload_json.asp?username=" + username + "&password=" + password + "',fileManagerJson : '../inc/editor/kindeditor/asp/file_manager_json.asp',width : '99%',height : '500px',allowImageUpload: true,allowFileManager : true,designMode : true,filterMode : false,afterBlur: function(){this.sync();},afterCreate : function() {var self = this;K.ctrl(document, 13, function() {self.sync();K('form[name=frm]')[0].submit();});K.ctrl(self.edit.doc, 13, function() {self.sync();K('form[name=frm]')[0].submit();});}});});";
					}
				}
				//alert(arr_js);
				eval(arr_js);
				s('_modeindexs2');
			}
		}
	}
}

// 返回: 返回正常数据写入对象,返回失败就ALERT报错
function ReturnInnerHTMLMODEEXT(){
	if (http_request.readyState == 4) {
		if (http_request.status == 200){
			var vback=http_request.responseText.split('|');
			if(vback[0]=='False'){alert(vback[1]);}else{callobj.innerHTML=vback[1].replace(/\#｜\#/g,'|');}
			if(callobj.innerHTML==''){
				h('_modeindexs');
			}else{
				s('_modeindexs');
			}
		}
	}
}

// 返回操作(AJAX) ///////////////////

// 返回: 仅出错提示用
function ReturnOnlyAlert(){
	if (http_request.readyState == 4) {
		if (http_request.status == 200){
			var vback=http_request.responseText.split('|');
			if(vback[0]=='False'){alert(vback[1]);}
		}
	}
}
// 返回: 返回正常数据写入对象,返回失败就ALERT报错
function ReturnInnerHTML(){
	if (http_request.readyState == 4) {
		if (http_request.status == 200){
			var vback=http_request.responseText.split('|');
			if(vback[0]=='False'){alert(vback[1]);}else{callobj.innerHTML=vback[1];}
		}
	}
}

// 批量操作  ///////////////////

// 选择
function CheckAll(){
	var chk = $("chkall").checked;
	for(var i = 0; i < frm.ids.length; i++){frm.ids[i].checked=chk;}
}
function ContentDo(val){
	var id='';
	var runit=false;
	frm.action= 'admin_content.asp?Act=' +val;
	for(var i = 0; i < frm.ids.length; i++){
		if(frm.ids[i].checked){runit=true;}
	}
	if(runit){
		if(val=='DODelete'){
			if(confirm('您确定要删除这些记录吗?')){frm.submit();}
		} else {
			frm.submit();
		}
	}
}

//凌陈亮添加
//自动缩放图片尺寸，展示全图，不够DIV宽高的就显示图片原本的尺寸
//参数：图片对象，最大宽度，最大高度
function chgimgwh(obj,width,height){
 var image=new Image();
 image.src=obj.src; //获取图像路径
 var width1=image.width; //获取图像宽度
 var height1=image.height; //获取图像高度
 var w=width1/width;
 var h=height1/height;
 if(width1<width && height1<height){
  obj.width=width1;
  obj.height=height1;
 }else{
  if(h>w){
   obj.height=height;
   obj.width=width1*height/height1;
  }else{
   obj.width=width;
   obj.height=height1*width/width1;
  }
 }
}
