﻿// JScript 文件

var xmlHttp;

function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();        
	}
}

function sendData(url,params,app,id) {
    createXMLHttpRequest();
    xmlHttp.open("POST", url, false);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.onreadystatechange = function()
    {
    ge(id).innerHTML="资料载入中...";
    if (xmlHttp.readyState == 4) 
        {
	        if (xmlHttp.status == 200) {
		        ge(id).innerHTML=xmlHttp.responseText;
	        }
	        else
	        {
	            alert('网络繁忙，请稍后再试！');
	        }
        }
    	
    };
    xmlHttp.send(params);
}

function getData(url,obj ,id) {
    var params;
    createXMLHttpRequest();
    url = url + "?appid"+ obj.getAppID() +"&itemid"+ obj.getItemID() +"&apikey"+ obj.getApiKey() +"&type="+ obj.getType()+"&results="+obj.getResults();
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = function()
    {
    ge(id).innerHTML="资料载入中...";
    if (xmlHttp.readyState == 4) 
	    {
		    if (xmlHttp.status == 200) {
		        var _json = xmlHttp.responseText;
			    ge(id).innerHTML=GetJSON(_json);
		    }
	    }
    	
    };
	xmlHttp.send(null);
}

function ge(z){return document.getElementById(z)}

function TGBUS(appid, itemid, apikey, type,results) {
    this.getAppID = function() { return appid; };
    this.setAppID = function(newAppID) { appid = newAppID; };
    this.getItemID = function() { return itemid; };
    this.setItemID = function(newItemID) { itemid = newItemID; };
    this.getApiKey = function() { return apikey; };
    this.setApiKey = function(newApiKey) { apikey = newApiKey; };
    this.getType = function() { return type; };
    this.setType = function(newType) { type = newType; };
    this.getResults = function() { return results; };
    this.setResults = function(newResults) { results = newResults; }; 
}
