/*==============================================================================
'	Project : ItemTopia ±¸Ãà Back Office Proj.
'	Company : PSJinc Corp.
'	ÀÛ¾÷ÀÚ : ÀÌ¼º±Ô
'	ÀÛ¾÷ÀÏ½Ã : 2006-09-08
'
'	³»¿ë : Ajax Handler Class
'
'   ¼öÁ¤ÀÏ½Ã : 
'	¼öÁ¤ÀÚ   :
'=============================================================================*/

// XMLHTTPRequest Object
var Ajax_hObject;
var Ajax_pDataHandler;
var Ajax_bDebug = 0;
var Ajax_DATA;


var AJAX = function (pDataHandler)
{
	this.Ajax_hObject			= null;
	this.Ajax_pDataHandler		= pDataHandler;
	this.Ajax_bDebug			= 0;
	
	this.pParam					= null;
	
}


AJAX.prototype.Open = function(sMethod, sUrl, bAsync, sParameters, sUser, sPassword, nReturnDataType)
{
/*	
	sMethod			Required. String that specifies the HTTP method used to open the connection: such as GET, POST, or HEAD. This parameter is not case-sensitive. 
					GET
					POST
					HEAD
					PUT
					DELETE
					MOVE
					PROPFIND
					PROPPATCH
					MKCOL
					COPY
					LOCK
					UNLOCK
					OPTIONS

	sUrl			Required. String that specifies either the absolute or a relative URL of the XML data or server-side XML Web services. 
	bAsync			Optional. Variant that specifies true for asynchronous operation (the call returns immediately), or false otherwise. If true, assign a callback handler to the onreadystatechange property to determine when the 				call has completed. If not specified, the default is true.  
	sUser			Optional. Variant that specifies the name of the user for authentication. If this parameter is null ("") or missing and the site requires authentication, the component displays a logon window. 
	sPassword		Optional. Variant that specifies the password for authentication. This parameter is ignored if the user parameter is null ("") or missing. 

*/
	
	nReturnDataType = (nReturnDataType) ? nReturnDataType : "Text";

	if (window.XMLHttpRequest)
	{
		this.Ajax_hObject = new XMLHttpRequest();
	}
	else
	{
		try
		{
			this.Ajax_hObject = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e1)
		{
			try
			{
				this.Ajax_hObject = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e2)
			{
				alert("AJAX °³Ã¼¸¦ »ý¼ºÇÒ ¼ö ¾ø½À´Ï´Ù.");
			}
		}
	}
	if (this.Ajax_bDebug > 0)
	{
		location.href = sUrl;
		return;
	}
	
	if (sMethod=="GET")
	{
		var now = new Date();
		sUrl = sUrl + "&ajaxvalidation=1&nocash=" + now.getFullYear()+ "" + (now.getMonth()+1) + "" + now.getDate() + "" + now.getHours() + "" + now.getMinutes() + "" + now.getSeconds();
	}

	this.Ajax_hObject.open(sMethod, sUrl, bAsync, sUser, sPassword);
	if (sMethod=="POST")
	{
		this.Ajax_hObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		this.Ajax_hObject.setRequestHeader("Content-length", sParameters.length);
	}

	this.Ajax_hObject.setRequestHeader("Cache-Control","no-cash, must-revalidate");

	pParameters = this.pParam;
	pAjaxObject = this.Ajax_hObject;
	bDebug = this.Ajax_bDebug;
	pHandler = this.Ajax_pDataHandler;
	this.Ajax_hObject.onreadystatechange = function () {

/*
	Property				Description 
	onreadystatechange		Event handler for an event that fires at every state change 
	readyState				Object status integer:
							0 = uninitialized
							1 = loading
							2 = loaded
							3 = interactive
							4 = complete 
	responseText			String version of data returned from server process 
	responseXML				DOM-compatible document object of data returned from server process 
	status					Numeric code returned by server, such as 404 for "Not Found" or 200 for "OK" 
	statusText				String message accompanying the status code 

*/
		

		if (pAjaxObject && pAjaxObject.readyState == 4)
		{
			if (pAjaxObject.status == 200)
			{
				if (pAjaxObject.responseText.length <= 0)
					return;

				if (pHandler != null)
					eval("pHandler(pAjaxObject.response"+nReturnDataType+", pParameters);");
				
			}
		}
		
	}

	this.Ajax_hObject.send(sParameters);
}


AJAX.prototype.Close = function ()
{
	this.Ajax_hObject = null;
}





