﻿/*	@desc	: ajax 객체 처리
 *	@auth	: Jeon Jae Young
 *	@date	: 2009.05.23 
 */

function CAjax_Manager()
{
	this.m_isAjax 	= false;
	this.m_objAjax	= null;
	this.m_result	= "";
	this.m_strQuery	= "";
	
	
	if (typeof(XMLHttpRequest) == "object" || typeof(XMLHttpRequest) == "function")
		this.m_objAjax = new XMLHttpRequest();
	else if (typeof(ActiveXObject) == "function")
	{
		try 
		{
			this.m_objAjax = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (othermicrosoft)
		{
			try
			{
				this.m_objAjax = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (failed)
			{
				alert("AJAX를 지원하지 않습니다.")
				this.m_objAjax = null;
				this.m_isAjax = false;
			}
		}
	}
	else
	{
		alert("AJAX를 지원하지 않습니다.")
		this.m_objAjax = null;
		this.m_isAjax = false;
	}
	
	if (this.m_objAjax == null)
	{
		alert("AJAX를 지원하지 않습니다.");
		this.m_isAjax = false;
	}
	else
		this.m_isAjax = true;
}

CAjax_Manager.prototype.setQuery		= function(objElement)
{
	if (objElement == null)
	{
		alert("잘못된 데이터가 입력되었습니다.");
		this.m_strQuery = "";
		return false;
	}
	
	if (this.m_strQuery != "")
		this.m_strQuery += "&";
	
	this.m_strQuery += objElement.name;
	this.m_strQuery += "=" + objElement.value;
	
	return true;
}

CAjax_Manager.prototype.setQueryString	= function(strName, strData)
{
	if ((strName == "") || (strData == ""))
	{
		alert("잘못된 데이터가 입력되었습니다.");
		this.m_strQuery = "";
		return false;
	}
	
	if (this.m_strQuery != "")
		this.m_strQuery += "&";
	
	this.m_strQuery += strName;
	this.m_strQuery += "=" + strData;
	
	return true;
}

CAjax_Manager.prototype.retrieveResult	= function() 
{
	return this.m_result;
}

CAjax_Manager.prototype.sendData		= function(strURL, strData)
{
	if (this.m_objAjax == null) 
		return false;
	
	this.m_objAjax.open("post", strURL, false);
	this.m_objAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
	this.m_objAjax.send(this.m_strQuery);
	
	if (this.m_objAjax.readyState == 4 && this.m_objAjax.status == 200)
	{
		this.m_result =  this.m_objAjax.responseText;
		return true;
	}
	
	return false;
}

CAjax_Manager.prototype.isAjax			= function()
{
	return this.m_isAjax;
}
