﻿HTTP_GET_VARS=new Array();
strGET=document.location.search.substr(1,document.location.search.length);
if(strGET!='')
    {
    gArr=strGET.split('&');
    for(i=0;i<gArr.length;++i)
        {
        v='';vArr=gArr[i].split('=');
        if(vArr.length>1){v=vArr[1];}
        HTTP_GET_VARS[unescape(vArr[0])]=unescape(v);
        }
    }

function GET(v)
{
if(!HTTP_GET_VARS[v]){return 'undefined';}
return HTTP_GET_VARS[v];
}

function AjaxSetParam(argstring)
{
	var arglist = argstring.split("&");
	for ( var arg in arglist ) {
	 var value = arglist[arg].split("=");
	 this.Param[value[0]] = value[1];
	}
	if(this.Param.length == 0)
	{
		this.method = 'POST';
	}
	else
	{
		this.method = 'GET';
	}
}

function AjaxAddParam(key, value)
{
	this.Param[key] = value;
	if(this.Param.length == 0)
	{
		this.method = 'POST';
	}
	else
	{
		this.method = 'GET';
	}
}
function AjaxClearParam()
{
	this.Param = [];
	this.method = 'POST';
}

function AjaxSetSourceFile(JSONFile)
{
	this.file = JSONFile;
}

function AjaxSetRecallFunction(name)
{
	this.RecallFunction = name;
}

function AjaxGetResult()
{
	this.http_request = false;
	if (window.XMLHttpRequest)
	{
		this.http_request = new XMLHttpRequest();
		if (this.http_request.overrideMimeType)
		{
			this.http_request.overrideMimeType('application/json');
		}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			this.http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			if(ER) alert(e);
			try
			{
				this.http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				if(ER) alert(e);
			}
		}
	}
	if (!this.http_request)
	{
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	
	this.http_request.onreadystatechange = this.RecallFunction;
	this.http_request.open(this.method, this.file, true);
	if(this.method == 'POST')
	{
		var arglist = [];
		for ( var arg in this.Param ) {
			arglist.push(arg+"="+this.Param[arg]);
		}
		var argstring = arglist.join("&");
		this.http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.http_request.setRequestHeader("Content-length", argstring.length);
		this.http_request.setRequestHeader("Connection", "close");
		this.http_request.send(argstring);
	}
	else
	{
		this.http_request.send(null);
	}
}

function AjaxSecurityHack()
{
	if (typeof netscape != 'undefined' &&
		typeof netscape.security != 'undefined' &&
		typeof netscape.security.PrivilegeManager != 'undefined') {
		try {
			netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
		}
		catch(e)
		{
			if(ER) alert(e);
		}
     }
}

function AjaxDo(JSONFile)
{
	var ER = 1;
	this.method = 'GET';
	this.Param = [];
	this.file = JSONFile;
	this.RecallFunction = null;
	this.SetParam = AjaxSetParam;
	this.AddParam = AjaxAddParam;
	this.ClearParam = AjaxClearParam;
	this.SetRecallFunction = AjaxSetRecallFunction;	
	this.GetResult = AjaxGetResult;
	this.SetSource = AjaxSetSourceFile;
	this.getJSON = function() {
		if(this.http_request.readyState == 4) {
		try { var r = eval("(" + this.http_request.responseText + ")"); } catch(e) {  }
			if(typeof r == 'object') return r;
			else return false;
		}
	};
}

function AjaxDoPoll()
{
	if(res && res.responseText) for( Function in eval("("+res.responseText+")") )
	{
		alert(Function);
	}
}

