/*------------------------------------------------------------------------------
 	Module Information
 		- Writer : ÀÌÄ¡ÈÆ
 		- Write Date : 2005/05/04
 	Module Prototype
 		- HM_HTTPRequest(url, state_func, frm, method, isXml)
 	Module Description
 		- http request function.
 	Input Parameter Description
 		- url : url
 		- state_func : assign a notify function, use async mode
 		- frm : form object, use form request(get or post)
 		- method : GET, POST
 		- isXml : TEXT or XML
 	Return Value
 		- async mode : none
 		- sync mode : http response text.
 	Etc
 	Example
 		-
------------------------------------------------------------------------------*/
function ClsHttpRequest(){
	this.oHttpRequester = null;
}

ClsHttpRequest.prototype.readyState = function(){
		return this.oHttpRequester.readyState;
}

ClsHttpRequest.prototype.status = function(){
		return this.oHttpRequester.status;
}

ClsHttpRequest.prototype.responseText = function(){
		return this.oHttpRequester.responseText;
}

ClsHttpRequest.prototype.responseXML = function(){
		return this.oHttpRequester.responseXML;
}

ClsHttpRequest.prototype.request = function(url, state_func, frm, method, isXml){
	var varResult = "";
	var varMethod = "GET";
	var varAsync = false;
	var varURL = url;

	if( method != null )
		varMethod = method;

	var varBody = null;
	if( frm ) {
		varBody = this.getBodyData(frm);
	}

    // branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
        this.oHttpRequester = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try{
			this.oHttpRequester = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				this.oHttpRequester = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return null;
			}		
		}
       
    } else {
    	return -1;
    }
    
	if( state_func != null )
	{
    	this.oHttpRequester.onreadystatechange = state_func;
    	varAsync = true;
    }

	if( varMethod == "POST" && varBody != null ) {
		this.oHttpRequester.open(varMethod, varURL, varAsync);
		this.oHttpRequester.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	} else {
		if( varBody )
			varURL += "?" + varBody;
		this.oHttpRequester.open(varMethod, varURL, varAsync);
	}

	if( varBody != null && varBody != "" )
		this.oHttpRequester.send(varBody);
	else
		this.oHttpRequester.send(null);

	//not async.
	if( state_func == null ) {
		if( isXml )
     		varResult = this.oHttpRequester.responseXML;
     	else
     		varResult = this.oHttpRequester.responseText;
     		
     	this.oHttpRequester = null;
    }	

	return varResult;
}

ClsHttpRequest.prototype.getBodyData = function(frm)
{
	var strResult = new String();
	if( frm == null )
		return null;

	var oColl = frm.elements;
	var oObject;
	for( var i = 0; i < oColl.length; i++ )
	{
		oObject = oColl[i];

		if( oObject.type == "checkbox" ) {

			if( oObject.checked == true ) {
				if( strResult.length )
					strResult += "&";
				strResult += oObject.name + "=" + oObject.value;
			}
		} else {
			if( strResult.length )
				strResult += "&";
			strResult += oObject.name + "=" + oObject.value;
		}
	}
	return strResult;
}

ClsHttpRequest.prototype.canRequest = function()
{
	if( this.oHttpRequester != null ) {
		alert("´Ù¸¥ ÀÛ¾÷ÀÌ ÁøÇà ÁßÀÔ´Ï´Ù.\nÀá½Ã ÈÄ¿¡ ´Ù½Ã ½Ãµµ ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.");
		return false;
	}

	return true;
}
/*
function processReqChange()
{
    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        g_lastHTTPStatus = req.status;
        if (req.status == 200) {
            // ...processing statements go here...
        } else {
            alert("There was a problem retrieving
               the XML data:\n" + req.statusText);
        }
    }
}
*/

