/*
* 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 loadStart(){
	Lightview.show({
	  href: '/images/common/cart_save.swf',
	  rel: 'flash',
    options: {
      width: 320,
      height: 160
    }
	});
}

function loadStart2(){
	Lightview.show({
	  href: '/images/common/cart_end.swf',
	  rel: 'flash',
    options: {
      width: 320,
      height: 160
    }
  });
}

function loadEnd() {
	Lightview.hide();
}

function loadEnd2() {
	Lightview.hide();
}

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 showCartList() {
  if (document.getElementById("shopping_basket").style.display == "") {
    document.getElementById("shopping_basket").style.display = "none";
  } else {
    var url = "/common/comCartList.asp";
    var resultAjax = getXMLHttpResponse(url);
    if (resultAjax == "0") {
      document.getElementById("shopping_basket").style.display = 'none';
    } else {
      document.getElementById("shopping_basket").innerHTML = resultAjax;
      document.getElementById("shopping_basket").style.display = '';
    }
  }
  window.status = "";
}

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();
	}
}
