/*==================================
update : 2006-06-28
===================================*/
var ajax = {};
ajax.ApmSoftNet = {};

// url : register.php, params : GET | POST, 
// callback : function name, method : id=userid&pwd=pwd, divid : out (<div id='out'></div>)
ajax.ApmSoftNet.REQ = function(url, params, callback, method, divid)
{
	this.url		= url;
	this.params		= params;
	this.callback	= callback;
	this.method		= method;
	this.divid		= divid;
	this.send();
}

ajax.ApmSoftNet.REQ.prototype = {
	getXMLHttpRequest: function()
	{
		if (window.ActiveXObject)
		{
			try {
				return new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch(e){
				try {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e1) { 
					return null; 
				}
			}
		} else if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else {
			return null;
		}
	},
	
	send: function()
	{
		this.req = this.getXMLHttpRequest();
		
		// method
		var apmMethod = this.method ? this.method : 'GET';
		if (apmMethod != 'GET' && apmMethod != 'POST') {
			apmMethod = 'GET';
		}
		
		// params
		var apmParams = (this.params == null || this.params == '') ? null : this.params;
		
		// file url
		var apmUrl = this.url;
		if (apmMethod == 'GET' && apmParams != null) {
			apmUrl = apmUrl + "?" + apmParams;
		}
		
		// run
		this.req.open(apmMethod, apmUrl, true);
		this.req.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
		
		var request = this;
		this.req.onreadystatechange = function() {
			request.processReq.call(request);
		}
		
		this.req.send(apmMethod == 'POST' ? apmParams : null);
	},

	// error msg || loading... msg Ãâ·Â
	processReq : function()
	{		
		var loadmsg = '';
		var ermsg	= '';
		var errormsg= '';
		
		// only if req shows "loaded"
		if (this.req.readyState ==1 || this.req.readyState ==2 || this.req.readyState ==3)
		{
			loadmsg += "<table border=0 width=100% height='20' cellspacing=2 cellpadding=0><tr><td>";
			loadmsg += "<font size=-1>loading ....</font><br><img src='../stylejs/ajaxjs/img/bar_loading.gif'>";
			loadmsg += "</td></tr></table>";

			this.printMsg(loadmsg);
		}
		
		else if (this.req.readyState == 4)
		{			
			// only if "OK"
			if (this.req.status == 200)
			{
				// ¿ÜºÎ ÇÔ¼ö È£Ãâ
				this.callback(this.req);
			}
			else
			{				
				if(this.req.status == 403) ermsg = 'Á¢±Ù°ÅºÎ';
				else if(this.req.status == 404) ermsg = 'ÆäÀÌÁö¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.';
				else if(this.req.status == 500) ermsg = '¼­¹ö ¿À·ù ¹ß»ý';
				
				errormsg += "There was a problem retrieving the XML data:\n" + this.req.status + " : " +ermsg +"\n";
				errormsg += "Press KEY : F5 (refresh)";

				this.printMsg(errormsg);
			}
		}

		// 0 ÀÏ¶§
		else
		{
			errormsg += "There was a problem retrieving the 'XMLHttpRequest Object' : "+this.req.status;
			this.printMsg(errormsg);
		}
	},

	// div id Ãâ·Â
	printMsg : function(msg)
	{
		var output = document.getElementById(this.divid);

		output.innerHTML = msg.replace("/\n/g",'');
	}
}