﻿// JScript 文件

//===================================================
// CreateLiveCMS Version4.0 Ajax(By 梅傲风)
//===================================================
// Mail: support@aspoo.cn, Info@aspoo.cn
// Msn : support@aspoo.cn, Clw866@hotmail.com
// Web : http://www.aspoo.cn
// Bbs : http://bbs.aspoo.cn
// Copyright (C) 2007 Aspoo.Cn All Rights Reserved.
//===================================================
//定义公共变量
var Cl_AjaxresponseText;
var Cl_AjaxDoSuc	= 0;
var Cl_SpareVar		= 0;  //备用变量
var IsDebug			= false;
var CurrentObjName = "div_111";

App = {};(function(){App.lock = function(bFlag){var console = document.getElementById("console");if(bFlag){if (!console){var console = document.createElement('div');console.id = "console";document.body.appendChild(console);}console.style.display = "block";console.style.position = "absolute";console.style.zIndex = 20001;console.style.left = document.body.scrollLeft;console.style.top = document.body.scrollTop;console.style.width = "100%";console.style.height = document.body.scrollHeight+"px";console.style.background = "#000000";console.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=20,finishOpacity=100,style=0)";App.isLocked = true;}else{if (console) window.parent.document.body.removeChild(console);App.isLocked = false;}}})();

//生成窗口

function createWindow(gethref,title,sw,sh){
//CurrentObjName = "div_" + Math.round(Math.random()*1000);
CurrentObjName = "div_111";
if (sw==null) sw = 780;if (sh==null) sh = 620;if (title==null) title = '新窗口！';var newDiv = document.createElement('div');newDiv.id = CurrentObjName;newDiv.className = "createwindow";newDiv.style.top = (document.body.scrollTop+50) + " px";newDiv.style.left = (document.body.clientWidth-sw)/2 + "px";newDiv.style.width = sw+"px";newDiv.style.height = (sh+32)+"px";newDiv.style.position = "absolute";newDiv.style.display = "block";newDiv.style.zIndex = 1;document.body.appendChild(newDiv);var divhtml = "<div class=\"window_title\" id=\"div_111\">";divhtml += "<span class=\"window_close\" onclick=\"CloseWindow1();\" title=\"关闭\"><a href='#'>关闭</a></span>";divhtml += "<span class=\"title_font\" id=\"title_"+CurrentObjName+"\">"+title+"</span>";divhtml += "</div>";divhtml += "<iframe frameborder=\"0\" hspace=\"0\" src="+gethref+"\" id=\"iframe_"+CurrentObjName+"\" name=\"iframe"+CurrentObjName+"\" style=\"width:"+sw+"px;height:"+sh+"px;\"> </iframe>";newDiv.innerHTML = divhtml;show(false);}

//关闭窗口

function CloseWindow(reload){var obj =  window.parent.document.getElementById("div_111");var console =  window.parent.document.getElementById("console");if (obj) {parent.document.body.removeChild(console);parent.document.body.removeChild(obj);App.lock(false);}if (reload){parent.location.reload();}}
function CloseWindow1(reload){var obj =  window.document.getElementById("div_111");var console =  window.document.getElementById("console");if (obj) {document.body.removeChild(console);document.body.removeChild(obj);App.lock(false);}if (reload){location.reload();}}
function show(bCenter){var showDiv = document.getElementById(CurrentObjName);showDiv.style.zIndex = 200101;if(bCenter){showDiv.style.left = 353;showDiv.style.top =  150;}App.lock(true);}

function ShowDebug(m){
	if(IsDebug){
		alert("[Debug]:"+m);
	}
}
function Cl_CreateAjaxObj()
{
	var XmlHttp;
	//windows
	try {
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
	} catch (e) {
		try {
			XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				XmlHttp = false;
			}
		}
	}
	//other
	if (!XmlHttp)
	{
		try {
			XmlHttp = new XMLHttpRequest();
		} catch (e) {
			XmlHttp = false;
		}
	}
	return XmlHttp;
}
function Cl_Ajax()
{
	this.XmlHttp= new Cl_CreateAjaxObj();
	this.Url	= null;
	this.ContentType = "application/x-www-form-urlencoded";
	this.HttpMethod = "POST";
	this.SucDo = null;
	this.ErrDo = null;
}
/* Get */
Cl_Ajax.prototype.Get = function() {
	this.ContentType= "text/html";
	this.HttpMethod = "GET";
	if (this.Url!=null){this.SendRequest(null);}
}
/* Post */
Cl_Ajax.prototype.Post = function(PostData) {
	this.ContentType= "application/x-www-form-urlencoded" ;
	this.HttpMethod = "POST";
	if (this.Url!=null){this.SendRequest(PostData);}
}
Cl_Ajax.prototype.SendRequest = function(data){
	if ( this.XmlHttp != null )
	{
		this.XmlHttp.open(this.HttpMethod, this.Url, true);
		if (this.HttpMethod=="POST"){this.XmlHttp.setRequestHeader("content-length",data.length);}
		this.XmlHttp.setRequestHeader("content-type", this.ContentType);
		var thisAjax=this;var thisFunction;
		this.XmlHttp.onreadystatechange = function (){
			if (thisAjax.XmlHttp.readyState==4&&thisAjax.XmlHttp.status==200) {
				Cl_AjaxresponseText = thisAjax.XmlHttp.responseText;
				if (Cl_AjaxresponseText.substring(0,2)=="OK") {Cl_AjaxDoSuc = 1;thisFunction = thisAjax.SucDo;}
				else{thisFunction = thisAjax.ErrDo;}
				if (thisFunction!=null){setTimeout(thisFunction,10);}
				//Cl_AjaxresponseText = Cl_AjaxresponseText.substring(3,Cl_AjaxresponseText.length);
			}else{
				switch(thisAjax.XmlHttp.readyState){
				case 1:
					break;//正在连接服务器;
				case 2:
					break;//正在向服务器发送数据;
				case 3:
					break;//正在接收返回数据;
				default:
					break;//;
				}
			}
		}
		this.XmlHttp.send(data);
	}
}
//用户登录
function AjaxUserLogin(type) {
	Cl_SpareVar = type;
	var outObj	= document.getElementById("ShowUserLogin");
	var UserName= document.getElementById("UserLogin_Name").value;
	var UserPass= document.getElementById("UserLogin_Pass").value;
	var CookieDate= document.getElementById("SaveCookie");
	var url		= "/ShowLogin.aspx";
	var post	= "Action=chk&Ajax=1&UserName="+escape(UserName)+"&UserPass="+escape(UserPass);
	//对表单进行简单判断
	if (UserName==""){
		alert("用户名不能为空！");
		document.getElementById("UserLogin_Name").focus();
		return false;}
	if (UserPass==""){
		alert("密码不能为空！");
		document.getElementById("UserLogin_Pass").focus();
		return false;}
	if (SaveCookie.checked==true){post += "&SaceCookie=1";}
	//alert(post);
	//输出信息
	//document.getElementById("sydl").disabled=true;
	if (outObj){outObj.innerHTML="<font color=\"#0000ff\">正在验证登录信息...</font>";}
	var Ajax = new Cl_Ajax();
	Ajax.Url = url;
	Ajax.SucDo = "AjaxUserLoginSuc()";
	Ajax.ErrDo = "AjaxUserLoginErr()";
	Ajax.Post(post);
}
//用户登录/退出成功
function AjaxUserLoginSuc() {
	var Ajax = new Cl_CreateAjaxObj();
	Ajax.open("POST", "/ShowLogin.aspx", true);
	//Ajax.setRequestHeader("content-length",PostData.length); 
	Ajax.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	Ajax.onreadystatechange=function() {
		if (Ajax.readyState==4&&Ajax.status==200) {
			document.getElementById("ShowUserLogin").innerHTML=Ajax.responseText;
		}
	}
	Ajax.send("Ajax=1&Type="+Cl_SpareVar);
}
//用户登录失败
function AjaxUserLoginErr() {
	alert(Cl_AjaxresponseText);
	var Ajax = new Cl_CreateAjaxObj();
	Ajax.open("POST", "/ShowLogin.aspx", true);
	//Ajax.setRequestHeader("content-length",PostData.length); 
	Ajax.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	Ajax.onreadystatechange=function() {
		if (Ajax.readyState==4&&Ajax.status==200) {
			document.getElementById("ShowUserLogin").innerHTML=Ajax.responseText;
		}
	}
	Ajax.send("Ajax=1&Type="+Cl_SpareVar);
}
//用户退出
function AjaxUserLogout(type) {
	Cl_SpareVar = type;
	var outObj	= document.getElementById("ShowUserLogin");
	var url		= "/ShowLogin.aspx";
	var date	= "Action=logout&Ajax=1";
	if (outObj){outObj.innerHTML="<font color=\"#0000ff\">正在退出登录，请稍候...</font>";}
	var Ajax = new Cl_Ajax();
	Ajax.Url = url;
	Ajax.SucDo = "AjaxUserLoginSuc()";
	Ajax.Post(date);
}
function createAjaxObj(){
 var httprequest=false
 if (window.XMLHttpRequest){ // if Mozilla, Safari etc
  httprequest=new XMLHttpRequest()
  if (httprequest.overrideMimeType)
   httprequest.overrideMimeType('text/xml');
 }
 else if (window.ActiveXObject){ // if IE
  try 
  {
   httprequest=new ActiveXObject("Msxml2.XMLHTTP");
  } 
  catch (e)
  {
   try
   {
    httprequest=new ActiveXObject("Microsoft.XMLHTTP");
   }
   catch (e){}
  }
 }
 return httprequest;
}


function load_Hits(iroot,arrID){
 var xmlhttp = createAjaxObj();
 var siteroot;
  if(iroot == ''){
        siteroot="/";
    }else{
        siteroot=iroot;
    }
 try
 {

  var params="HitsType=0&SoftID="+arrID;
  xmlhttp.abort(); 
  
  xmlhttp.open("get",siteroot+"/Soft/GetHits.asp?"+params,true);
 
  xmlhttp.setRequestHeader("Content-type", "text/html;charset=gb2312"); 
  
  xmlhttp.setRequestHeader("If-Modified-Since","0"); 
 
  xmlhttp.setRequestHeader("Content-length", params.length);
  
  xmlhttp.setRequestHeader("Connection", "close");
 
  xmlhttp.onreadystatechange=f

  xmlhttp.send(null); 
 
 }catch(ex){alert(ex)}
 function f()
 {
  
   if(xmlhttp.readyState!= 4 || xmlhttp.status!=200 )
    return ;
   var b= xmlhttp.responseText;
   document.getElementById('Hits').innerHTML="";
   document.getElementById('Hits').innerHTML=b;
 }
}

