/*
* Filename	: ajax.js
* Function	:
* Comment	:
* History		: 2008/05/14, jdh, setup
*
* Version	: 1.0
* Author		: Copyright (c) 2005 by JC Square Corp. All Rights Reserved.
*/

var xmlHttp = null;
function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
		catch (ex) {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
	} else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
	return xmlHttp;
}

function getXMLHttpResponse(url) {
	xmlHttp = createXMLHttpRequest();
	if(window.ActiveXObject){
		xmlHttp.onreadystatechange = checkXMLHttpStatus;
	} else {
		xmlHttp.onload = checkXMLHttpStatus;
	}
	xmlHttp.open("GET", url, false);
	xmlHttp.setRequestHeader("Content-Type", "text/html; charset=euc-kr;");
	xmlHttp.send(null);
	return xmlHttp.responseText;
}

function checkXMLHttpStatus() {
	if(xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {resultAjax = xmlHttp.responseText;}
	}
}

function chkDuplicate(val, type) {
	if (val.length > 3) {
		var url = "/common/comDuplicateChk.asp?strType=" + type + "&strVal=" + val;
		var resultAjax = getXMLHttpResponse(url);
		if (resultAjax == "0") {
			document.getElementById(type).style.display = 'none';
		} else {
			document.getElementById(type).style.display = 'block';
		}
	} else {
		document.getElementById(type).style.display = 'none';
	}
}

function getPriceText(val, nm, min_cnt) {
	if (val.length == 0 || !isNumeric(val) || !isNumeric(min_cnt) || val == 0 || parseInt(val) < parseInt(min_cnt)) {
      alert("±¸¸Å¼ö·®À» " + min_cnt + "°³ ÀÌ»óÀÇ ¼ýÀÚ·Î ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
      return;
  }
  var url = "/designbox/get_price.asp?p_count=" + val +"&item_num=" + nm;
  document.getElementById("priceLayer").innerHTML = "Àç°è»ê ÁßÀÔ´Ï´Ù.";
  var resultAjax = getXMLHttpResponse(url);
  if (resultAjax.length > 0) {
    document.getElementById("priceLayer").innerHTML = resultAjax;
  } else {
    document.getElementById("priceLayer").innerHTML = "<font color=blue>¿¡·¯!</font>";
  }
}

function goodsBuyStatus() {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var resultAjax = xmlHttp.responseText;
			if (resultAjax.length > 0) {
				var cartCount = resultAjax.split("|")[0];
				var cartPrice = resultAjax.split("|")[1];

				document.getElementById("cartCountLayer").innerHTML = "<img src=\"/images/common/basket_txt.gif\">&nbsp;(" + cartCount + "°Ç)";
				document.getElementById("cartPriceLayer").innerHTML = "\\<b>" + cartPrice + "</b>";
			}
			loadStart2();
		}
	} else {
		loadStart();
	}
}
