function ajax()
{
	//---------------------
	// Private Declarations
	//---------------------
	var _request = null;
	var _this = null;
    
	//--------------------
	// Public Declarations
	//--------------------
	this.GetResponseXML = function()
	{
		return (_request) ? _request.responseXML : null;
	}
    
	this.GetResponseText = function()
	{
		return (_request) ? _request.responseText : null;
	}
    
	this.GetRequestObject = function()
	{
		return _request;
	}
    
	this.InitializeRequest = function(Method, Uri)
	{
		_InitializeRequest();
		_this = this;
        
		switch (arguments.length)
		{
        case 2:
            _request.open(Method, Uri);
            break;
            
        case 3:
            _request.open(Method, Uri, arguments[2]);
            break;
		}
        
		if (arguments.length >= 4) _request.open(Method, Uri, arguments[2], arguments[3]);
		this.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	}
    
	this.SetRequestHeader = function(Field, Value)
	{
		if (_request) _request.setRequestHeader(Field, Value);
	}
    
	this.Commit = function(Data)
	{
		if (_request) _request.send(Data);
	}
    
	this.Close = function()
	{
		if (_request) _request.abort();
	}
    
	//---------------------------
	// Public Event Declarations.
	//---------------------------
	this.OnUninitialize = function() { };
	this.OnLoading = function() { };
	this.OnLoaded = function() { };
	this.OnInteractive = function() { };
	this.OnSuccess = function() { };
	this.OnFailure = function() { };
    
	//---------------------------
	// Private Event Declarations
	//---------------------------
	function _OnUninitialize() { _this.OnUninitialize(); };
	function _OnLoading() { _this.OnLoading(); };
	function _OnLoaded() { _this.OnLoaded(); };
	function _OnInteractive() { _this.OnInteractive(); };
	function _OnSuccess() { _this.OnSuccess(); };
	function _OnFailure() { _this.OnFailure(); };

	//------------------
	// Private Functions
	//------------------
	function _InitializeRequest()
	{
		_request = _GetRequest();
		_request.onreadystatechange = _StateHandler;
	}
    
	function _StateHandler()
	{
		switch (_request.readyState)
		{
        case 0:
            window.setTimeout("void(0)", 100);
            _OnUninitialize();
            break;
            
        case 1:
            window.setTimeout("void(0)", 100);
            _OnLoading();
            break;
            
        case 2:
            window.setTimeout("void(0)", 100);
            _OnLoaded();
            break;
            
        case 3:
            window.setTimeout("void(0)", 100);
            _OnInteractive();
            break;
            
        case 4:
            if (_request.status == 200)
				_OnSuccess();
            else
				_OnFailure();
            
            return;
            break;
		}
	}
    
	function _GetRequest()
	{
		var obj;
        
		try
		{
			obj = new XMLHttpRequest();
		}
		catch (error)
		{
			try
			{
				obj = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (error)
			{
				return null;
			}
		}
        
		return obj;
	}
}

	function addCommas(nStr)
	{
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}


	var best_products = function(xdocs, ele_name) {
		var tableObj = document.getElementById(ele_name);
		var inner_str = "";

		strFilename1 = xdocs.getElementsByTagName("strFilename1");
		strFilename2 = xdocs.getElementsByTagName("strFilename2");
		strFilename3 = xdocs.getElementsByTagName("strFilename3");
		strFilename4 = xdocs.getElementsByTagName("strFilename4");
		strFilename5 = xdocs.getElementsByTagName("strFilename5");
		intSeq = xdocs.getElementsByTagName("intSeq");
		intPrice = xdocs.getElementsByTagName("intPrice");
		strGoodsCode = xdocs.getElementsByTagName("strGoodsCode");
		strGoodsName = xdocs.getElementsByTagName("strGoodsName");
		strSummary = xdocs.getElementsByTagName("strSummary");
		inner_str += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
		inner_str += "<tr> ";
		for(var i = 0; i < intSeq.length; i++) {
			filename = "";
			seq = "";
			price = "";
			goodname = "";
			summary = "";

			try {
				filename = strFilename1[i].childNodes[0].nodeValue;
				if( filename.length == 0) {
					filename = "/img/nogoods_index.jpg";
				} else {
					filename = "/updata/skinmall/goods/" + filename;
				}
			} catch(e) {}

			try {
				price = addCommas(intPrice[i].childNodes[0].nodeValue);
			} catch(e) {
				price = 0;
			}

			try {
				seq = intSeq[i].childNodes[0].nodeValue;
			} catch(e) {}
			try {
				goodname = strGoodsName[i].childNodes[0].nodeValue;
			} catch(e) {}

			try {
				summary = strSummary[i].childNodes[0].nodeValue;
			} catch(e) {}

			if(i > 0) {
				inner_str += "<td width=\"1\" bgcolor=\"D7D7D7\"> </td>";
			}
			inner_str += "<td align=\"center\" valign=\"top\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
			inner_str += "<tr> ";
			inner_str += "<td align=\"center\"><a href=\"/shop/view.asp?intSeq="+seq+"\"><img src=\""+filename+"\" border=\"0\"></a></td>";
			inner_str += "</tr>";
			inner_str += "<tr> ";
			inner_str += "<td height=\"20\"><img src=\"../new/img/bullet_1.jpg\" width=\"17\" height=\"11\"><strong><font color=\"F7941C\"><a href=\"/shop/view.asp?intSeq="+ seq + "\">" +goodname+"</a></font></strong></td>";
			inner_str += "</tr>";
			inner_str += "<tr> ";
			inner_str += "<td height=\"20\"><strong><font color=\"B50026\"><img src=\"../new/img_new/bullet_2.gif\" width=\"17\" height=\"11\"></font></strong>"+price+"¿ø</td>";
			inner_str += "</tr>";
			inner_str += "</table></td>";


		}
		inner_str += "</tr>";
		inner_str += "</table>";
		tableObj.innerHTML = inner_str;
	}

	// XML À» ÀÐ¾îµé¿©¼­ Å×ÀÌºí¿¡ Ã¤¿î´Ù.
	var FillNodes = function(xdocs, ele_name){
		var tableObj = document.getElementById(ele_name);
		var inner_str = "";

		strFilename1 = xdocs.getElementsByTagName("strFilename1");
		strFilename2 = xdocs.getElementsByTagName("strFilename2");
		strFilename3 = xdocs.getElementsByTagName("strFilename3");
		strFilename4 = xdocs.getElementsByTagName("strFilename4");
		strFilename5 = xdocs.getElementsByTagName("strFilename5");
		intSeq = xdocs.getElementsByTagName("intSeq");
		intPrice = xdocs.getElementsByTagName("intPrice");
		strGoodsCode = xdocs.getElementsByTagName("strGoodsCode");
		strGoodsName = xdocs.getElementsByTagName("strGoodsName");
		strSummary = xdocs.getElementsByTagName("strSummary");


		for(var i = 0; i < strGoodsCode.length; i++){
			filename = "";
			try {
				filename = strFilename1[i].childNodes[0].nodeValue;
				if( filename.length == 0) {
					filename = "/img/nogoods_index.jpg";
				} else {
					filename = "/updata/skinmall/goods/" + filename;
				}
			} catch(e) {}
			price = 0;
			try {
				price = addCommas(intPrice[i].childNodes[0].nodeValue);
			} catch(e) {
				price = 0;
			}
			inner_str += "<div id=\"newproduct_div_" + i +"\" style=\"display:none\">";
			inner_str += " <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
			inner_str += "<tr> ";
			inner_str += "<td width=\"150\" align=\"center\"><img src=\"" + filename +"\"></td>";
			inner_str += "<td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
			inner_str += "<tr> ";
			inner_str += "<td height=\"30\"><strong><font color=\"B50026\"><img src=\"../new/img_new/bullet_1.gif\" width=\"17\" height=\"11\"><a href=\"/shop/view.asp?intSeq=" + intSeq[i].childNodes[0].nodeValue +"\">"+ strGoodsName[i].childNodes[0].nodeValue +"</a> ";
			inner_str += "<img src=\"../new/img_new/bullet_2.gif\" width=\"17\" height=\"11\"></font>"+ price +"¿ø</strong></td>";
			inner_str += "</tr>";
			inner_str += "<tr> ";
			inner_str += "<td>"+ strSummary[i].childNodes[0].nodeValue.substring(0, 80) +"</td>";
			inner_str += "</tr>";
			inner_str += "<tr> ";
			inner_str += "<td height=\"40\"> <p> <a href=\"/shop/view.asp?intSeq=" + intSeq[i].childNodes[0].nodeValue +"\"><img src=\"../new/img_new/btn_detail.gif\" width=\"84\" height=\"17\" border=\"0\"></a> ";
			inner_str += "</p></td>";
			inner_str += "</tr>";
			inner_str += "</table></td>";
			inner_str += "</tr>";
			inner_str += "</table>";
			inner_str += "</div>";

		}

		tableObj.innerHTML = inner_str;

	}

	function setGoodTable( table_id , quant,  cateValue, tagValue, partValue, mall_tag, fill_function) {

		good_list = function() {
			
			this.OnSuccess = function() {
				fill_function( this.GetResponseXML(), table_id);
			}
			
			this.GetData = function( cate, tag ) {
				this.InitializeRequest('GET', 
									   '/util/good_search.php?quant='+ quant 
									   +'&cate=' +encodeURIComponent(cate )
									   +'&part=' +encodeURIComponent(partValue)
									   + '&mall_tag=' +encodeURIComponent(mall_tag)
									   + '&tag=' +encodeURIComponent(tagValue), true);
				this.Commit(null);
			}
		}
		
		good_list.prototype = new ajax();
		good_obj = new good_list;
		good_obj.GetData( cateValue, tagValue );
	}

	function set_tag_menu( tag_value ) {
		tagClass = function() {
			
			this.OnSuccess = function() {
				document.getElementById('tag_menu').innerHTML = this.GetResponseText();
			}

			this.GetData = function( tag ) {
				this.InitializeRequest('GET', 
									   '/util/tag_menu.php?tag='+ encodeURIComponent(tag), true);
				this.Commit(null);
			}
		}

		tagClass.prototype = new ajax();
		tagObj = new tagClass;
		tagObj.GetData(  tag_value );
	}



	function set_best_shop_img( ele_id, tag_value) {
		tagClass = function(eid) {
			
			this.OnSuccess = function() {
				document.getElementById(eid).innerHTML = this.GetResponseText();
			}

			this.GetData = function( tag ) {
				this.InitializeRequest('GET', 
									   '/util/tag_img.php?tag='+ encodeURIComponent(tag), true);
				this.Commit(null);
			}
		}

		tagClass.prototype = new ajax();
		tagObj = new tagClass( ele_id ) ;
		tagObj.GetData(  tag_value );	
	}
