/**
AJAX
*/

/*

/**/
function urlEncode(str)
{
	if (typeof str != "string") return str;

	var ret = "";
	var code, hexcode;

	for (i = 0; i < str.length; i++)
	{
		code = str.charCodeAt(i);

		// ¼ýÀÚ, ¿µ¹®ÀÚ, ÇÑ±Û »©°í ½Ï´Ù
		if ((code >= 97 && code <= 122) || (code >= 65 && code <= 90) || (code >= 48 && code <= 57) || code >= 256)
		{
			ret += str.charAt(i);
		}
		else
		{
			hexcode = code.toString(16);
			if (hexcode.length == 1) hexcode = "0" + hexcode;

			ret += "%" + hexcode;
		}
	}

	return ret;
}

function urlDecode(str)
{
	if (typeof str != "string") return str;
	return unescape(str);
}


/** 
AJAX 
*/
/*
ajax_iframe = document.createElement("IFRAME");
with(ajax_iframe.style)
{
	position = "absolute";
	//display = "none";	
	width = 500;
	height = 500;
}
window.attachEvent("onload",function() {document.body.appendChild(ajax_iframe)} );
*/

function AJAX(_method)
{
	var self = this;

	var method;
	var xmlhttp = null;

	var oncomplete;
	var onerror;

	self.getHttpRequest = function()
	{
		if(xmlhttp)
		{
			xmlhttp.abort();

			delete xmlhttp;
			xmlhttp = null;
		}

		try { xmlhttp = new XMLHttpRequest(); }
		catch(e)
		{
			try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch(e)
			{
				try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
				catch(e) { }
			}
		}

		return xmlhttp;
	}

	self.setMethod = function(_method)
	{
		method = (_method && _method.toUpperCase() == "POST" ? "POST" : "GET");
	}

	self.requestURL = function(_url, _query, _oncomplete, _onerror)
	{
		xmlhttp = self.getHttpRequest();
		
		oncomplete = _oncomplete;
		//onerror = _onerror;
		onerror = ajax_error;

		if (typeof _query == "object")
		{
			var query = "";

			for (var i in _query)
				query += urlEncode(i) + "=" + urlEncode(_query[i]) + "&";

			_query = query;
		}

		if (method == "GET")
		{
			_url += "?" + _query;
			_query = "";
		}

		// alert(_url);

		xmlhttp.open(method, _url, _oncomplete || _onerror ? true : false);

		if (_oncomplete || _onerror)
			xmlhttp.onreadystatechange = function() { self.onComplete(xmlhttp); }

		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send(_query);
		
		return xmlhttp;
	}

	self.onComplete = function(xmlhttp)
	{
		if (xmlhttp.readyState == 4)
		{
			 //alert(xmlhttp.responseText);

			try
			{
				var error = (xmlhttp.status != 200);

				if (error && onerror)
					onerror(xmlhttp.status + " " + xmlhttp.statusText);
				else
				{
					oncomplete(error ? xmlhttp.status + " " + xmlhttp.statusText : xmlhttp);
				}
			}
			catch(e)
			{

			}

			xmlhttp = null;
		}
	}

	self.setMethod(_method);
}

function randomKey(prefix)
{
	return (prefix ? prefix : "") + parseInt(Math.random(1) * 10000000);
}


function isNumber(v)
{
	if (typeof v == "number") return true;
	return !isNaN(parseInt(v));
}

/*ajax_alert */
	
var _bottom = -80;
var _tid = false;
var _tid2 = false;

function ajax_alert(str)
{
	ajax_alert_close();
	$("div_ajaxmsg").style.display = "block";
	$("td_ajaxmsg").innerHTML = str;
	
	_tid=setInterval(ajax_alert_open,10);
}
function ajax_alert_open()
{
	_bottom += 5;	
	
	if(_bottom>=0) 
	{
		_bottom = 0;
		clearTimeout(_tid2)
		_tid2=setTimeout(ajax_alert_close,1000);
		clearInterval(_tid);		
	}

	$("div_ajaxmsg").style.bottom = _bottom + "px";

}
function ajax_alert_close()
{
	$("div_ajaxmsg").style.display = "none";
	$("div_ajaxmsg").style.bottom = "-80px";
	_bottom  = -80;	
}

function ajax_error(msg)
{
	if(msg) msg = "\n\n"+msg;
	else msg = "";

//	alert("AJAX:¼­¹ö¿Í Åë½ÅÁß ¿¡·¯°¡ ¹ß»ýÇß½À´Ï´Ù!"+msg);
}


function dirView(cname,ctype,dir)
{
    window.open("dir_view.php?cname="+cname+"&ctype="+ctype+"&dir="+dir,"dirview","width=300,height=400,scrollbars=no,top=100,left=200");
}
