/*  - 수신함수 동적으로 변경 가능
 *  - POST만 가능
 *  - 한글지원을 위해 XML사용
 * 범용적이지 않음
 *--------------------------------------------------------------------------*/

// request, response 함수 -----------------------------------------------------------------------------------------------------------------------------
function XMLHttpResponseEx(XMLHttpObj, FuncResponse) 
{
    if(XMLHttpObj.readyState == 4) 
    {
        if(XMLHttpObj.status == 200) 
        {
			FuncResponse(XMLHttpObj);
        }
    }
}
	
function XMLHttpRequestEx(strURL, strXML, FuncResponse)
{
	var XMLHttpObj;
	
    if (window.XMLHttpRequest) 
    {
        XMLHttpObj = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        XMLHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
		alert("에러(3247) : XMLHttpRequest 객체생성 실패");
		return;
    }
    
	XMLHttpObj.onreadystatechange = function()
	{
		XMLHttpResponseEx(XMLHttpObj, FuncResponse);
	}  
    
 
    XMLHttpObj.open("POST", strURL, true);  

	XMLHttpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); 
    XMLHttpObj.setRequestHeader("Content-length", strXML.length);
    XMLHttpObj.setRequestHeader("Connection", "close");

    XMLHttpObj.send(strXML);
}

XMLDocument = function(xmlDocument)
{
	this.xmlDocument = xmlDocument;
}

XMLDocument.prototype.GetData = function(strTagName)
{
	return this.xmlDocument.getElementsByTagName(strTagName).item(0).firstChild.nodeValue;
}

//단순 1차원 배열 ------------------------------------------------------------------------------------------------------------------------------------------------------------
SendXMLObj = function()
{
	this.strXML = "<OFDREAM>"; 
}

SendXMLObj.prototype.StartSubTag = function(strTagName)
{
	this.strXML += "<";
	this.strXML += strTagName;
	this.strXML += ">";
}

SendXMLObj.prototype.EndSubTag = function(strTagName)
{
	this.strXML += "</";
	this.strXML += strTagName;
	this.strXML += ">";
}

SendXMLObj.prototype.AddData = function(strTagName, strTagData)
{
	this.strXML += "<";
	this.strXML += strTagName;
	this.strXML += "><![CDATA[";
	this.strXML += strTagData;
	this.strXML += "]]></"
	this.strXML += strTagName;
	this.strXML += ">";
}

SendXMLObj.prototype.GetXML = function()
{
	return this.strXML + "</OFDREAM>";		
}

//xml 함수 ------------------------------------------------------------------------------------------------------------------------------------------------------------
function xmlRootDoc(xml)
{
	return (xml.firstChild.nextSibling) ? xml.firstChild.nextSibling : xml.firstChild;
}

//오브젝트의 하위 배열 얻음 //var childlist = GetArray(doc,'book');
function xmlGetArray(objElement, strName)
{
    var list = new Array();
    strName = strName.toUpperCase();
    for(var i=0; i<objElement.childNodes.length; i++)
        if (objElement.childNodes[i].nodeName.toUpperCase() == strName.toUpperCase() )
            list.push( objElement.childNodes[i] );

    return list;
}

//특정 오브젝트의 특정값을 얻음
function xmlGetValue(objElement, strName)
{
    for(var i=0; i<objElement.childNodes.length; i++)
        if (objElement.childNodes[i].nodeName.toUpperCase()==strName.toUpperCase() )
            return objElement.childNodes[i].firstChild.nodeValue;

    return '';
}

// 끝
