/****************************************************
* @version : 1.0
* @date : 2007.07.26
* @author : Sonh Hyun Suk
*
* modified by : Sonh Hyun Suk (2007.07.26) ÁÖ¼®
****************************************************/
// for ajax
var XMLLoader = function() {
	this.request = null;
	this.onSuccess = null;
	this.onFailure = null;
	this.onTimeout = null;
	this.t = null;
}
XMLLoader.prototype.getXMLHttpRequest = function () {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try	{
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try	{
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e1) { return null; }
		}
	}
}

XMLLoader.prototype.callFailureHandler = function() {
	if (this.onFailure) this.onFailure();
}
XMLLoader.prototype.callSuccessHandler = function(objXML) {
	if (this.onSuccess) this.onSuccess(objXML);
}
XMLLoader.prototype.callTimeoutHandler = function() {
	if (this.onTimeout) this.onTimeout();
}
XMLLoader.prototype.processReqChange = function(req){
	var READY_STATE_UNINITIALIZED=0;
	var READY_STATE_LOADING=1;
	var READY_STATE_LOADED=2;
	var READY_STATE_INTERACTIVE=3;
	var READY_STATE_COMPLETE=4;

	if (this.req.readyState == READY_STATE_COMPLETE){
		document.body.style.cursor = 'auto';
		clearTimeout(this.t);
		if ( this.req.status == 200 ) {
			var objXML = null;
			//¼º°ø
			try	{
				objXML = this.req.responseXML.documentElement || this.req.responseXML;
			}
			catch (e) {
				if (typeof DOMParser != 'undefined')
				{
					var objParser = new DOMParser();
					objXML = objParser.parseFromString(this.req.responseText, "text/xml").documentElement;
				}
			}
			this.callSuccessHandler(objXML);
		} else {
			//½ÇÆÐ
			this.callFailureHandler();
		}
	}else{
		//·ÎµùÁß..
		document.body.style.cursor = 'wait';
	}
}
XMLLoader.prototype.load = function( url ) {
	this.req = this.getXMLHttpRequest();
	if(!this.req) {
		this.callFailureHandler()
		return;
	}

	var objThis = this;
	this.req.onreadystatechange = function() {
		objThis.processReqChange();
	};
	try {
		this.req.open("GET", url, true);
		this.req.send(null);
		this.t = setTimeout(function(){
			objThis.req.abort();
			objThis.callTimeoutHandler();
		}, 5000);
	} catch (e) {
		this.callFailureHandler();
	}
}

function getData(dataSet, nodeName) {
	var rtn = dataSet.getElementsByTagName(nodeName).item(0).childNodes[0].nodeValue;
	if (!rtn) return '';
	return rtn;
}
function makerDiv(obj,url,div_id){
	var div = document.createElement('div');
	var objiframe = document.createElement('iframe');
	div.id = div_id;
	div.style.position = 'absolute';
	objiframe.style.position = 'absolute';
//	objiframe.style.width='720';
//	objiframe.style.height='450';
	objiframe.frameBorder = 'no';
	var coor = obj.getBoundingClientRect();
	var ldr = new XMLLoader();
	ldr.load(url);
	ldr.onSuccess = function(objXML){
		div.innerHTML = getData(objXML,'data');
		document.body.appendChild(div);
		div.appendChild(objiframe);
	div.style.left = Math.round((document.body.offsetWidth-div.offsetWidth)/2+document.body.scrollLeft)+'px';
	div.style.top = Math.round((document.body.offsetHeight-div.offsetHeight)/2+document.body.scrollTop)+'px';
	objiframe.style.width= div.offsetWidth;
	objiframe.style.height= div.offsetHeight;
	objiframe.style.left = 0+'px';
	objiframe.style.top = 0+'px';
	objiframe.style.zIndex = -1;
	div.style.zIndex = 10000;
	}
}
function removeDiv(div_id){
	var div = document.getElementById(div_id);
	var parent = div.parentNode;
	parent.removeChild(div);
}
