﻿var isIE = false;
var req;
var htmlContents;

function gb2utf8(data){
	var glbEncode = [];
	gb2utf8_data = data;
	execScript("gb2utf8_data = MidB(gb2utf8_data, 1)", "VBScript");
	var t=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2");
	t=t.split("@");
	var i=0,j=t.length,k;
	while(++i<j) {
		k=t[i].substring(0,4);
		if(!glbEncode[k]) {
			gb2utf8_char = eval("0x"+k);
			execScript("gb2utf8_char = Chr(gb2utf8_char)", "VBScript");
			glbEncode[k]=escape(gb2utf8_char).substring(1,6);
		}
		t[i]=glbEncode[k]+t[i].substring(4);
	}
	gb2utf8_data = gb2utf8_char = null;
	return unescape(t.join("%"));
}


/*
myUrl 指定的URL
*/
function loadXMLDoc(myUrl) {
  if (window.XMLHttpRequest) {
  	if (typeof(window.XMLHttpRequest) == "object") {
      isIE = true;
      req = new ActiveXObject("Microsoft.XMLHTTP");
      if (req) {
          req.onreadystatechange = processReqChange;
          req.open("GET", myUrl, true);
          req.send();
      }
     } else {
      req = new XMLHttpRequest();
      req.onreadystatechange = processReqChange;
      req.open("GET", myUrl+"&bow=noie", true);
      req.overrideMimeType("text/html;charset=utf-8");
      req.send(null);
    }
  } else if (window.ActiveXObject) {
      isIE = true;
      req = new ActiveXObject("Microsoft.XMLHTTP");
      if (req) {
          req.onreadystatechange = processReqChange;
          req.open("GET", myUrl, true);
          req.send();
      }
  }
}

//读取页面时所执行的
function processReqChange() {
  if (req.readyState == 4) {
    if (req.status == 200) {
     	if (isIE) {
     		//htmlContents = gb2utf8(req.responseBody);
     		htmlContents = req.responseText;
    	}  else {
    		htmlContents = req.responseText;
    	}
		  loadok();
     }
     
  }
  
}

//读取页面成功后执行
/*
function loadok(){

		alert(htmlContents);
	
}
*/

//要读取的网址
function getUrl(myUrl){
	var _dSt_ = new Date();
	loadXMLDoc(myUrl+"&randomStr="+""+_dSt_.getUTCDay()+""+_dSt_.getMilliseconds());
}

/*
String.prototype.toText=function() {
	var tmpDiv=document.createElement("div");
	tmpDiv.innerHTML=this;
	var tmpTxt;
	if(document.all){
		tmpTxt=tmpDiv.innerText;
	}	else {
		tmpTxt=tmpDiv.textContent;
	}
	tmpDiv=null;
	return tmpTxt;
}
*/