/*==================================
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 += "<br/><br/><br/><img src='../files/loading.gif'>";

            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 = 'Access denied';
                else if(this.req.status == 404) ermsg = 'Cannot find the page.';
                else if(this.req.status == 500) ermsg = 'server Error occured';
                
                errormsg += "Sorry, couldn't read the file.:\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",'');
	}
}